public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Rusty Russell <rusty@rustcorp.com.au>
To: Jeff Garzik <jgarzik@pobox.com>
Cc: Linus Torvalds <torvalds@transmeta.com>, linux-kernel@vger.kernel.org
Subject: Re: [TRIVIAL] kstrdup
Date: Sat, 19 Apr 2003 18:28:24 +1000	[thread overview]
Message-ID: <20030419083116.668DB2C003@lists.samba.org> (raw)
In-Reply-To: Your message of "Sat, 19 Apr 2003 00:48:36 -0400." <3EA0D524.7010309@pobox.com>

In message <3EA0D524.7010309@pobox.com> you write:
> Since the kernel does its own string ops, the compiler does not have 
> enough information to deduce that further optimization is possible.

You're right, I was measuring without the kernel string ops.
> > Case in point: gcc-3.2 on -O2 on Intel is one instruction longer for
> > your version.
> 
> And?  It's still slower.

Who gives a flying fuck?  You're doing an allocation in there
ferchissakes.  Choose the simplest option.  Jeff, if you have time to
post on this, I think you need a hobby 8)

char *__constant_kstrdup(const char *s, unsigned int size, int gfp)
{
	char *buf = kmalloc(size, gfp);
	if (likely(buf))
		memcpy(buf, s, size);
	return buf;
}

char *__kstrdup(const char *s, int gfp)
{
	return __constant_kstrdup(s, strlen(s)+1, gfp);
}

#define kstrdup(str, gfp)						\
	(__builtin_constant_p(str) && sizeof(str) != sizeof(char *) ?	\
		__constant_kstrdup(str, sizeof(str), gfp)		\
	: __kstrdup(str, gfp))

Feature list:
1) Optimizes the constant kstrdup case,
2) Doesn't multi-evaluate args (except if constant string),
3) Uses likely() to bias against the case of kmalloc failing.

OK, so I guess I need a hobby, too..
Rusty.
--
  Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

  reply	other threads:[~2003-04-19  8:19 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-18  7:58 [TRIVIAL] kstrdup Rusty Trivial Russell
2003-04-18  8:10 ` Jeff Garzik
2003-04-18 16:20   ` Linus Torvalds
2003-04-18 16:56     ` Jeff Garzik
2003-04-18 18:00       ` Linus Torvalds
2003-04-18 18:44         ` Jeff Garzik
2003-04-19  4:52         ` Rusty Russell
2003-04-18 18:00       ` Richard B. Johnson
2003-04-18 18:40         ` Jeff Garzik
2003-04-18 19:24           ` H. Peter Anvin
2003-04-18 23:37             ` Alan Cox
2003-04-18 19:29           ` Richard B. Johnson
2003-04-19 11:45             ` Kai Henningsen
2003-04-19 20:16             ` Ruth Ivimey-Cook
2003-04-19  4:14   ` Rusty Russell
2003-04-19  4:48     ` Jeff Garzik
2003-04-19  8:28       ` Rusty Russell [this message]
2003-04-19 12:27       ` Alan Cox
2003-04-19 14:44         ` Bernd Eckenfels
2003-04-20  8:05         ` Rusty Russell

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=20030419083116.668DB2C003@lists.samba.org \
    --to=rusty@rustcorp.com.au \
    --cc=jgarzik@pobox.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox