[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v6 3/4] xen/console: use memcpy() in console_init_ring()


  • To: dmukhin@xxxxxxxx
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Tue, 2 Jun 2026 11:05:39 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=t8HkXfuT5L+CYtuDLYF34Pm7Z96QNdCQBCWOoJi+drc=; b=ajMwfCzdTrmlUZX7CKcbbh3wDXDLk3BfVn0U3VfVyvNwPgGcblVcGdc/4n69AP5tOrFt7eJE31gHfSTcBstUZt1WvL2YoLqqZFZny7UBcZFtNFJ7nbmZGVXU796CHbBV34iBu3q63FItmdNxZsa/mWVJm+twJvw9q2Tf+EYC3R3peiY8RVOcHGQ+X2F5D4lQ32uKW183LIUOWc1dykyGGWfqGBvYkvoDIRw5P6tnwtfqbIGZimaEWQzmUqss+dmEVdunicGib8/jEsKkQS4VAkHGtRhlKMn25zVNoKndfi/KQRHE/T9j6DDIgt5vjIw8VlVlF0ESH0ENwYGvBw2k/A==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=FaNdL00GVkpqDPBZTu0iJEjdwJdDpcGjUwnRMHUTfjmJGA2pOj5ORNgvWJu58bZRH3j2NG09LVFsBEaXBb/v5JN5Eu1Y/nrQqWmRbmCy9RsDsZqg15Kj7eUlLs8uSCrjUgP63ry1Jf7A5oBvS6zPYWrMTo/7ORQ7zBv3AYbGw4FDHiLwXJjjRzUEPqRVdwfSAPfhwelAjxJ6us6x0lNpM7k3EtxxXU1aWd3ap+oNmD/YIys1Tzo+Okk9HWzcATRwIOnvg0XK1y9lnzrQaNcVplfoGC7NA8igEzZGvUNBfXjZ6B4qsuP5P5vJVXMzqudHVZ+NpieK9u9PzuLKzc/n8Q==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=citrix.com header.i="@citrix.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx, andrew.cooper3@xxxxxxxxxx, anthony.perard@xxxxxxxxxx, jbeulich@xxxxxxxx, julien@xxxxxxx, michal.orzel@xxxxxxx, sstabellini@xxxxxxxxxx
  • Delivery-date: Tue, 02 Jun 2026 09:05:57 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Fri, May 08, 2026 at 05:57:13PM -0700, dmukhin@xxxxxxxx wrote:
> From: Denis Mukhin <dmukhin@xxxxxxxx> 
> 
> Make console_init_ring() more efficient by using memcpy()'s, rather than
> copying the ring a byte at a time.
> 
> Suggested-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
> Signed-off-by: Denis Mukhin <dmukhin@xxxxxxxx>

Acked-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>

A couple of notes below.

> ---
> Changes since v5:
> - fixed memcpy() logic
> ---
>  xen/drivers/char/console.c | 21 ++++++++++++++++++---
>  1 file changed, 18 insertions(+), 3 deletions(-)
> 
> diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c
> index 5ab3b0de12d8..5cac87d052b9 100644
> --- a/xen/drivers/char/console.c
> +++ b/xen/drivers/char/console.c
> @@ -463,7 +463,8 @@ static void cf_check conring_dump_keyhandler(unsigned 
> char key)
>  void __init console_init_ring(void)
>  {
>      char *ring;
> -    unsigned int i, order, memflags;
> +    XENCONS_RING_IDX i, size;
> +    unsigned int order, memflags;
>      unsigned long flags;
>  
>      if ( !opt_conring_size )
> @@ -479,8 +480,22 @@ void __init console_init_ring(void)
>      opt_conring_size = PAGE_SIZE << order;
>  
>      nrspin_lock_irqsave(&console_lock, flags);
> -    for ( i = conringc ; i != conringp; i++ )
> -        ring[i & (opt_conring_size - 1)] = conring[i & (conring_size - 1)];
> +
> +    i = 0;
> +    size = conringp - conringc;
> +    while ( i < size )
> +    {
> +        XENCONS_RING_IDX src = (conringc + i) & (conring_size - 1);
> +        XENCONS_RING_IDX dst = (conringc + i) & (opt_conring_size - 1);
> +        XENCONS_RING_IDX n;
> +
> +        n = min(opt_conring_size - dst, conring_size - src);
> +        n = min(size - i, n);
> +
> +        memcpy(&ring[dst], &conring[src], n);
> +        i += n;
> +    }

It's a bit more complex logic for not much gain IMO: this will only be
used once to move from the init buffer to the dynamically allocated
one.  A couple of notes, feel free to ignore if you don't think it's
an improvement: I would rename `i` to `done`, as `i` is usually
associated with an index, and here it's just an accumulator of the
amount of characters processed.  I would also consider making this a
for loop, by pulling n to the outer context, ie:

XENCONS_RING_IDX done, size, n;
[...]

for ( done = 0; done < size; done += n )
{
    XENCONS_RING_IDX src = (conringc + done) & (conring_size - 1);
    XENCONS_RING_IDX dst = (conringc + done) & (opt_conring_size - 1);

    n = min(opt_conring_size - dst, conring_size - src);
    n = min(size - done, n);

    memcpy(&ring[dst], &conring[src], n);
}

Thanks, Roger.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.