cpuidle: Minor optimization in cpuidle governor finding.
PATCH 1/1 cpuidle: Minor optimization in cpuidle governor finding.
Currently in __cpuidle_find_governor(), strnicmp() is used to
find which governor (menu or ladder) to register where CPUIDLE_NAME_LEN is passed strnicmp()'s comparision max limit. But, "menu" or "ladder" these strings are much smaller than CPUIDLE_NAME_LEN. To avoid it this patch introduces len field on cpuidle_governor structure, which is statically initialized to the size of length of governor name. Later on this size has been passed as strnicmp()'s length param. Another advantage this patch introduces, before calling strnicmp() by checking the size of governor name length we can determine whether to call strnicmp() i.e a shortcut.
Signed-off-by Rakib Mullick <[email protected]>
---
drivers/cpuidle/governor.c +9 -4
@@ -20,16 +20,21 @@ struct cpuidle_governor *cpuidle_curr_governor;/** * __cpuidle_find_governor - finds a governor of the specified name * @str: the name +* @size: length of str * * Must be called with cpuidle_lock acquired. */ -static struct cpuidle_governor *__cpuidle_find_governor (const char *str) +static struct cpuidle_governor *__cpuidle_find_governor (const char *str, +size_t size) {struct cpuidle_governor *gov; -list_for_each_entry (gov, &cpuidle_governors, governor_list) -if (!strnicmp (str, gov->name,CPUIDLE_NAME_LEN )) +list_for_each_entry (gov, &cpuidle_governors, governor_list) { +if (size != gov->len) +continue ; +if (!strnicmp (str, gov->name, gov->len))return gov; + }return NULL ; }
@@ -85,7 +90,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)return -ENODEV ;mutex_lock (&cpuidle_lock); -if (__cpuidle_find_governor (gov->name) ==NULL ) { +if (__cpuidle_find_governor (gov->name, gov->len) ==NULL ) { ret =0 ;list_add_tail (&gov->governor_list, &cpuidle_governors); if (!cpuidle_curr_governor ||
drivers/cpuidle/governors/ladder.c +1 -0
@@ -177,6 +177,7 @@ static void ladder_reflect(struct cpuidle_device *dev, int index)static struct cpuidle_governor ladder_governor = { .name ="ladder" , + .len =6 , .rating =10 , .enable = ladder_enable_device, .select = ladder_select_state,
drivers/cpuidle/governors/menu.c +1 -0
@@ -477,6 +477,7 @@ static int menu_enable_device(struct cpuidle_driver *drv,static struct cpuidle_governor menu_governor = { .name ="menu" , + .len =4 , .rating =20 , .enable = menu_enable_device, .select = menu_select,
include/linux/cpuidle.h +1 -0
@@ -198,6 +198,7 @@ struct cpuidle_governor {char name[CPUIDLE_NAME_LEN ];struct list_head governor_list;unsigned int rating; +size_t len;int (*enable) (struct cpuidle_driver *drv,struct cpuidle_device *dev);