All of lore.kernel.org
 help / color / mirror / Atom feed
From: Brian Gerst <bgerst@didntduck.org>
To: Jesper Juhl <juhl-lkml@dif.dk>
Cc: "Paul `Rusty' Russell" <rusty@rustcorp.com.au>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] micro optimization in kernel/params.c; don't call to_module_kobject before we really have to.
Date: Sat, 29 Jan 2005 19:13:07 -0500	[thread overview]
Message-ID: <41FC2693.6060601@didntduck.org> (raw)
In-Reply-To: <Pine.LNX.4.62.0501300024110.2829@dragon.hygekrogen.localhost>

Jesper Juhl wrote:
> In kernel/params.c::module_attr_show and 
> kernel/params.c::module_attr_store we call to_module_kobject() and save 
> the result in a local variable right before a conditional statement that 
> does not depend on the call to to_module_kobject() and may cause the 
> function to return. If the function returns before we use the result of 
> to_module_kobject() then the call is just a waste of time. 
> The patch moves the call to to_module_kobject() down just before it is 
> actually used, thus we save a call to the function in a few cases. I doubt 
> this is in any way measurable, but I see no reason to not move the call - 
> it should be an infinitesimal improvement with no ill sideeffects.
> Please consider applying.
> 
> 
> Signed-off-by: Jesper Juhl <juhl-lkml@dif.dk>
> 
> diff -up linux-2.6.11-rc2-bk7-orig/kernel/params.c linux-2.6.11-rc2-bk7/kernel/params.c
> --- linux-2.6.11-rc2-bk7-orig/kernel/params.c	2005-01-29 23:54:53.000000000 +0100
> +++ linux-2.6.11-rc2-bk7/kernel/params.c	2005-01-30 00:27:08.000000000 +0100
> @@ -625,11 +625,12 @@ static ssize_t module_attr_show(struct k
>  	int ret;
>  
>  	attribute = to_module_attr(attr);
> -	mk = to_module_kobject(kobj);
>  
>  	if (!attribute->show)
>  		return -EPERM;
>  
> +	mk = to_module_kobject(kobj);
> +
>  	if (!try_module_get(mk->mod))
>  		return -ENODEV;
>  
> @@ -649,11 +650,12 @@ static ssize_t module_attr_store(struct 
>  	int ret;
>  
>  	attribute = to_module_attr(attr);
> -	mk = to_module_kobject(kobj);
>  
>  	if (!attribute->store)
>  		return -EPERM;
>  
> +	mk = to_module_kobject(kobj);
> +
>  	if (!try_module_get(mk->mod))
>  		return -ENODEV;
>  
> 
> 
> 

I'd bet that the compiler already reorders the assignment since there is 
no side effect to to_module_kobject().  Even with a patch like this you 
can't control exactly when the assignment is done.  There may not even 
be an assignment, since mk is a constant offset of kobj.

--
				Brian Gerst

  reply	other threads:[~2005-01-30  0:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-29 23:45 [PATCH] micro optimization in kernel/params.c; don't call to_module_kobject before we really have to Jesper Juhl
2005-01-30  0:13 ` Brian Gerst [this message]
2005-01-30 12:43   ` Jesper Juhl
2005-01-31  3:43     ` 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=41FC2693.6060601@didntduck.org \
    --to=bgerst@didntduck.org \
    --cc=juhl-lkml@dif.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    /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.