2008-11-19 15:54:47

by cheng renquan

[permalink] [raw]
Subject: [PATCH] kobject_add: use constant strings directly as fmt strings

From: Cheng Renquan <[email protected]>

Signed-off-by: Cheng Renquan <[email protected]>
---
block/blk-sysfs.c | 2 +-
block/elevator.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index 21e275d..0b189e9 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -342,7 +342,7 @@ int blk_register_queue(struct gendisk *disk)
return 0;

ret = kobject_add(&q->kobj, kobject_get(&disk_to_dev(disk)->kobj),
- "%s", "queue");
+ "queue");
if (ret < 0)
return ret;

diff --git a/block/elevator.c b/block/elevator.c
index 9ac82dd..9a39f27 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -1005,7 +1005,7 @@ int elv_register_queue(struct request_queue *q)
elevator_t *e = q->elevator;
int error;

- error = kobject_add(&e->kobj, &q->kobj, "%s", "iosched");
+ error = kobject_add(&e->kobj, &q->kobj, "iosched");
if (!error) {
struct elv_fs_entry *attr = e->elevator_type->elevator_attrs;
if (attr) {
--
1.6.0.4.758.g36c05


2008-11-19 16:01:19

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH] kobject_add: use constant strings directly as fmt strings

On Wed, Nov 19, 2008 at 11:54:19PM +0800, [email protected] wrote:
> From: Cheng Renquan <[email protected]>
>
> Signed-off-by: Cheng Renquan <[email protected]>
> ---
> block/blk-sysfs.c | 2 +-
> block/elevator.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
> index 21e275d..0b189e9 100644
> --- a/block/blk-sysfs.c
> +++ b/block/blk-sysfs.c
> @@ -342,7 +342,7 @@ int blk_register_queue(struct gendisk *disk)
> return 0;
>
> ret = kobject_add(&q->kobj, kobject_get(&disk_to_dev(disk)->kobj),
> - "%s", "queue");
> + "queue");

Why? What does this change buy us?

thanks,

greg k-h

2008-11-19 16:17:18

by cheng renquan

[permalink] [raw]
Subject: Re: [PATCH] kobject_add: use constant strings directly as fmt strings

On Wed, Nov 19, 2008 at 11:57 PM, Greg KH <[email protected]> wrote:
>> ret = kobject_add(&q->kobj, kobject_get(&disk_to_dev(disk)->kobj),
>> - "%s", "queue");
>> + "queue");
>
> Why? What does this change buy us?

Dropping one parameter makes the function call a little faster, doesn't it?

The results are the same,

so if the string is constant, why not use it directly as the fmt string?

Thanks.

>
> thanks,
>
> greg k-h

--
Cheng Renquan, Shenzhen, China
Lily Tomlin - "The trouble with the rat race is that even if you win,
you're still a rat."

2008-11-19 17:00:48

by Kay Sievers

[permalink] [raw]
Subject: Re: [PATCH] kobject_add: use constant strings directly as fmt strings

On Wed, Nov 19, 2008 at 17:17, rae l <[email protected]> wrote:
> On Wed, Nov 19, 2008 at 11:57 PM, Greg KH <[email protected]> wrote:
>>> ret = kobject_add(&q->kobj, kobject_get(&disk_to_dev(disk)->kobj),
>>> - "%s", "queue");
>>> + "queue");
>>
>> Why? What does this change buy us?
>
> Dropping one parameter makes the function call a little faster, doesn't it?
>
> The results are the same,

Not that we should be able to measure it, but it should save some
cycles parsing the format character and retrieving the string pointer
from the stack, yes.

> so if the string is constant, why not use it directly as the fmt string?

It should be fine for strings, where you can be sure they can never
contain a '%', sure.

Thanks,
Kay

2008-11-19 17:37:48

by cheng renquan

[permalink] [raw]
Subject: Re: [PATCH] kobject_add: use constant strings directly as fmt strings

On Thu, Nov 20, 2008 at 1:00 AM, Kay Sievers <[email protected]> wrote:
> Not that we should be able to measure it, but it should save some
> cycles parsing the format character and retrieving the string pointer
> from the stack, yes.

I'm sure it does work, one another as:

*** drivers/net/iseries_veth.c:
veth_probe_one[1088] if (0 != kobject_add(&port->kobject,
&dev->dev.kobj, "veth_port"))

>> so if the string is constant, why not use it directly as the fmt string?
>
> It should be fine for strings, where you can be sure they can never
> contain a '%', sure.
And I have searched all places kobject_add called, only these two
places in block/blk-sysfs.c
and block/elevator.c have constant strings. So this patch is the whole
kobject_add constant string
optmization patch.

>
> Thanks,
> Kay

--
Cheng Renquan, Shenzhen, China
Fred Allen - "An associate producer is the only guy in Hollywood who
will associate with a producer."