genetlink: Optimize genl_register_family()
Subsystems (2)
PATCH 1/1 genetlink: Optimize genl_register_family()
From: Krishna Kumar <[email protected]>
genl_register_family() doesn't need to call genl_family_find_byid when GENL_ID_GENERATE is passed during register.
Patch on net-next-2.6, compile and reboot testing only.
---
net/netlink/genetlink.c +3 -5
@@ -374,11 +374,6 @@ int genl_register_family(struct genl_fam goto errout_locked; } -if (genl_family_find_byid (family->id)) { - err = -EEXIST ; - goto errout_locked; - } -if (family->id ==GENL_ID_GENERATE ) {u16 newid =genl_generate_id ();
@@ -388,6 +383,9 @@ int genl_register_family(struct genl_fam } family->id = newid; + }else if (genl_family_find_byid (family->id)) { + err = -EEXIST ; + goto errout_locked; }if (family->maxattr) {
PATCH 1/1 genetlink: Optimize and one bug fix in genl_generate_id()
From: Krishna Kumar <[email protected]>
1. GENL_MIN_ID is a valid id -> no need to start at GENL_MIN_ID + 1.
2. Avoid going through the ids two times: If we start at GENL_MIN_ID+1 (*or bigger*) and all ids are over!, the code iterates through the list twice (*or lesser*).
3. Simplify code - no need to start at idx=0 which gets reset to GENL_MIN_ID.
Patch on net-next-2.6. Reboot test shows that first id passed to genl_register_family was 16, next two were GENL_ID_GENERATE and genl_generate_id returned 17 & 18 (user level testing of same code shows expected values across entire range of MIN/MAX).
---
net/netlink/genetlink.c +8 -16
@@ -97,25 +97,17 @@ static struct genl_ops *genl_get_cmd(u8*/ static inline u16 genl_generate_id (void ) { -static u16 id_gen_idx; -int overflowed =0 ; +static u16 id_gen_idx =GENL_MIN_ID ; +int i; -do { -if (id_gen_idx ==0 ) +for (i =0 ; i <=GENL_MAX_ID -GENL_MIN_ID ; i++) { +if (!genl_family_find_byid (id_gen_idx)) +return id_gen_idx; +if (++id_gen_idx >GENL_MAX_ID ) id_gen_idx =GENL_MIN_ID ; + } -if (++id_gen_idx >GENL_MAX_ID ) { -if (!overflowed) { - overflowed =1 ; - id_gen_idx =0 ; -continue ; - }else -return 0 ; - } - - }while (genl_family_find_byid (id_gen_idx)); - -return id_gen_idx; +return 0 ; }static struct genl_multicast_group notify_grp;
Re: [PATCH] genetlink: Optimize and one bug fix in genl_generate_id()
From: Krishna Kumar <[email protected]>
Date: Thu, 15 Oct 2009 11:25:07 +0530
Quoted 10 lines
From: Krishna Kumar <[email protected]>
1.
GENL_MIN_IDis a valid id -> no need to start atGENL_MIN_ID+ 1.
2. Avoid going through the ids two times: If we start at GENL_MIN_ID+1 (*or bigger*) and all ids are over!, the code iterates through the list twice (*or lesser*).
3. Simplify code - no need to start at idx=0 which gets reset toGENL_MIN_ID.
Quoted 7 lines
Patch on net-next-2.6. Reboot test shows that first id passed to
genl_register_familywas 16, next two wereGENL_ID_GENERATEandgenl_generate_idreturned 17 & 18 (user level testing of same code shows expected values across entire range of MIN/MAX).Signed-off-by Krishna Kumar <[email protected]>
Applied, thanks.
From: Krishna Kumar <[email protected]>
Date: Thu, 15 Oct 2009 11:24:53 +0530
Quoted 8 lines
From: Krishna Kumar <[email protected]>
genl_register_family()doesn't need to callgenl_family_find_byidwhenGENL_ID_GENERATEis passed during register.Patch on net-next-2.6, compile and reboot testing only.
Signed-off-by Krishna Kumar <[email protected]>
Applied.