All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Roger Pau Monné" <roger.pau@citrix.com>
To: dmukhin@ford.com
Cc: xen-devel@lists.xenproject.org, andrew.cooper3@citrix.com,
	anthony.perard@vates.tech, jbeulich@suse.com, julien@xen.org,
	michal.orzel@amd.com, sstabellini@kernel.org
Subject: Re: [PATCH v6 3/4] xen/console: use memcpy() in console_init_ring()
Date: Tue, 2 Jun 2026 11:05:39 +0200	[thread overview]
Message-ID: <ah6c40-TkdJcFggM@macbook.local> (raw)
In-Reply-To: <20260509005714.892018-4-dmukhin@ford.com>

On Fri, May 08, 2026 at 05:57:13PM -0700, dmukhin@ford.com wrote:
> From: Denis Mukhin <dmukhin@ford.com> 
> 
> 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@citrix.com>
> Signed-off-by: Denis Mukhin <dmukhin@ford.com>

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

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.


  reply	other threads:[~2026-06-02  9:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-09  0:57 [PATCH v6 0/4] xen/console: configurable conring size dmukhin
2026-05-09  0:57 ` [PATCH v6 1/4] xen/console: make console buffer size configurable dmukhin
2026-06-02  8:34   ` Roger Pau Monné
2026-05-09  0:57 ` [PATCH v6 2/4] xen/console: promote conring{,_size} to __ro_after_init dmukhin
2026-05-09  0:57 ` [PATCH v6 3/4] xen/console: use memcpy() in console_init_ring() dmukhin
2026-06-02  9:05   ` Roger Pau Monné [this message]
2026-05-09  0:57 ` [PATCH v6 4/4] xen/console: switch conring runtime allocation to xvmalloc dmukhin
2026-06-02  9:49   ` Roger Pau Monné
2026-06-02  9:54     ` Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ah6c40-TkdJcFggM@macbook.local \
    --to=roger.pau@citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=anthony.perard@vates.tech \
    --cc=dmukhin@ford.com \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=michal.orzel@amd.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.