All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andi Kleen <ak@muc.de>
To: Tom Zanussi <zanussi@us.ibm.com>
Cc: linux-kernel <linux-kernel@vger.kernel.org>,
	Greg KH <greg@kroah.com>, Andrew Morton <akpm@osdl.org>,
	Roman Zippel <zippel@linux-m68k.org>,
	Robert Wisniewski <bob@watson.ibm.com>,
	Tim Bird <tim.bird@AM.SONY.COM>,
	karim@opersys.com
Subject: Re: [PATCH] relayfs redux, part 3 II - another comment
Date: 5 Feb 2005 10:54:16 +0100
Date: Sat, 5 Feb 2005 10:54:16 +0100	[thread overview]
Message-ID: <20050205095416.GA2187@muc.de> (raw)
In-Reply-To: <16899.55393.651042.627079@tut.ibm.com>

Another comment on relay_write fast pathing

> +static inline unsigned relay_write(struct rchan *chan,
> +				   const void *data,
> +				   unsigned length)
> +{
> +	unsigned long flags;
> +	struct rchan_buf *buf = relay_get_buf(chan, smp_processor_id());
> +
> +	local_irq_save(flags);
> +	if (unlikely(buf->offset + length > chan->subbuf_size))
> +		length = relay_switch_subbuf(buf, length);
> +	memcpy(buf->data + buf->offset, data, length);

I said earlier gcc would optimize the memcpy, but thinking about
this again I'm not so sure anymore. The problem is that with variable 
buf->offset gcc cannot prove the alignment of the destination, and with 
unknown alignment it tends to generate a out of line call to memcpy, which
is quite typically slow. 

You can take a look at the generated assembly if that's true
or not, but I suspect it is.

To avoid this it may be needed to play 

if (__builtin_constant_p(length)) 
	switch (length) { 
	case 1: /* optimized version for 1 byte */ break;
	case 2: ...
	case 4: ...
	case 8:  ...
	}
else
	memcpy(...); 

games like e.g. uaccess.h does. Problem is that sometimes gcc seems
to break __builtin_constant_p inside inlines, so it may be needed
to move it into a macro (i would double check if that is really needed
though for this case, the code is much nicer with a inline) 

-Andi			

      parent reply	other threads:[~2005-02-05  9:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-04 20:17 [PATCH] relayfs redux, part 3 Tom Zanussi
2005-02-04 21:10 ` Christoph Hellwig
2005-02-04 22:00   ` Tom Zanussi
2005-02-04 21:39 ` Christoph Hellwig
2005-02-04 22:06   ` Tom Zanussi
2005-02-04 22:12 ` Andi Kleen
2005-02-04 22:22   ` Tom Zanussi
2005-02-05  6:57     ` Andi Kleen
2005-02-05  9:54 ` Andi Kleen [this message]

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=20050205095416.GA2187@muc.de \
    --to=ak@muc.de \
    --cc=akpm@osdl.org \
    --cc=bob@watson.ibm.com \
    --cc=greg@kroah.com \
    --cc=karim@opersys.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tim.bird@AM.SONY.COM \
    --cc=zanussi@us.ibm.com \
    --cc=zippel@linux-m68k.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.