kobject_add: use constant strings directly as fmt strings
PATCH 1/1 kobject_add: use constant strings directly as fmt strings
From: Cheng Renquan <[email protected]>
--- block/blk-sysfs.c | 2 +- block/elevator.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
block/blk-sysfs.c +1 -1
@@ -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;
block/elevator.c +1 -1
@@ -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) {
Signature · 1 line
1.6.0.4.758.g36c05
Quoted 13 lines · 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(-)block/blk-sysfs.c +0
-0
block/blk-sysfs.c int blk_register_queue(struct gendisk *disk) · line 345
Quoted 5 lines
block/blk-sysfs.c +1
-1@@ -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
Quoted 5 lines · Greg KH
block/blk-sysfs.c int blk_register_queue(struct gendisk *disk) · line 345
Quoted 3 lines
ret = kobject_add(&q->kobj, kobject_get(&disk_to_dev(disk)->kobj),block/blk-sysfs.c +1
-1- "%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.
Quoted 4 lines
thanks,
greg k-h
Signature · 3 lines
Cheng Renquan, Shenzhen, China Lily Tomlin - "The trouble with the rat race is that even if you win, you're still a rat."
Quoted 10 lines · rae l
Quoted 5 lines · Greg KH
block/blk-sysfs.c int blk_register_queue(struct gendisk *disk) · line 345
Quoted 3 lines
ret = kobject_add(&q->kobj, kobject_get(&disk_to_dev(disk)->kobj),block/blk-sysfs.c +1
-1- "%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.
Quoted 1 line
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
Quoted 3 lines · Kay Sievers
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"))
Quoted 4 lines
Quoted 1 line
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.
Quoted 3 lines
Thanks,
Kay
Signature · 3 lines
Cheng Renquan, Shenzhen, China Fred Allen - "An associate producer is the only guy in Hollywood who will associate with a producer."