From: "Jan Beulich" Subject: [PATCH] consolidate cpufreq cmdline handling Date: Tue, 03 Feb 2009 15:50:11 +0000 Message-ID: <498875C3.76E4.0078.0@novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Return-path: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org ... by moving as much of the option processing into cpufreq code as is possible, by folding the cpufreq_governor option into the cpufreq one (the governor name, if any, must be specified as the first thing after the separator following "cpufreq=3Dxen"), and by allowing each governor to have an option processing routine. Signed-off-by: Jan Beulich --- 2009-01-30.orig/xen/common/domain.c 2009-01-30 10:13:53.000000000 = +0100 +++ 2009-01-30/xen/common/domain.c 2009-01-30 13:36:18.000000000 = +0100 @@ -41,7 +41,6 @@ boolean_param("dom0_vcpus_pin", opt_dom0 =20 /* set xen as default cpufreq */ enum cpufreq_controller cpufreq_controller =3D FREQCTL_xen; -struct cpufreq_governor *cpufreq_opt_governor; =20 static void __init setup_cpufreq_option(char *str) { @@ -71,19 +70,6 @@ static void __init setup_cpufreq_option( } custom_param("cpufreq", setup_cpufreq_option); =20 -static void __init setup_cpufreq_gov_option(char *str) -{ - if ( !strcmp(str, "userspace") ) - cpufreq_opt_governor =3D &cpufreq_gov_userspace; - else if ( !strcmp(str, "performance") ) - cpufreq_opt_governor =3D &cpufreq_gov_performance; - else if ( !strcmp(str, "powersave") ) - cpufreq_opt_governor =3D &cpufreq_gov_powersave; - else if ( !strcmp(str, "ondemand") ) - cpufreq_opt_governor =3D &cpufreq_gov_dbs; -} -custom_param("cpufreq_governor", setup_cpufreq_gov_option); - /* Protect updates/reads (resp.) of domain_list and domain_hash. */ DEFINE_SPINLOCK(domlist_update_lock); DEFINE_RCU_READ_LOCK(domlist_read_lock); --- 2009-01-30.orig/xen/drivers/cpufreq/cpufreq.c 2009-01-08 = 10:30:05.000000000 +0100 +++ 2009-01-30/xen/drivers/cpufreq/cpufreq.c 2009-01-30 13:59:00.0000000= 00 +0100 @@ -53,6 +53,7 @@ struct cpufreq_dom { }; static LIST_HEAD(cpufreq_dom_list_head); =20 +struct cpufreq_governor *cpufreq_opt_governor; LIST_HEAD(cpufreq_governor_list); =20 struct cpufreq_governor *__find_governor(const char *governor) @@ -467,3 +468,47 @@ out: return ret; } =20 +void __init cpufreq_cmdline_parse(char *str) +{ + static struct cpufreq_governor *__initdata cpufreq_governors[] =3D + { + &cpufreq_gov_userspace, + &cpufreq_gov_dbs, + &cpufreq_gov_performance, + &cpufreq_gov_powersave + }; + + do { + char *val, *end =3D strchr(str, ','); + unsigned int i; + + if ( end ) + *end++ =3D '\0'; + val =3D strchr(str, '=3D'); + if ( val ) + *val++ =3D '\0'; + + if ( !cpufreq_opt_governor ) + { + if ( !val ) + { + for ( i =3D 0; i < ARRAY_SIZE(cpufreq_governors); ++i ) + if ( !strcmp(str, cpufreq_governors[i]->name) ) + { + cpufreq_opt_governor =3D cpufreq_governors[i]; + str =3D NULL; + break; + } + } + else + cpufreq_opt_governor =3D CPUFREQ_DEFAULT_GOVERNOR; + } + + if ( str ) + for ( i =3D 0; i < ARRAY_SIZE(cpufreq_governors); ++i ) + if ( cpufreq_governors[i]->handle_option ) + cpufreq_governors[i]->handle_option(str, val); + + str =3D end; + } while ( str ); +} --- 2009-01-30.orig/xen/drivers/cpufreq/cpufreq_ondemand.c 2009-01-08 = 10:30:05.000000000 +0100 +++ 2009-01-30/xen/drivers/cpufreq/cpufreq_ondemand.c 2009-01-30 = 13:54:16.000000000 +0100 @@ -281,9 +281,50 @@ int cpufreq_governor_dbs(struct cpufreq_ return 0; } =20 +static void __init cpufreq_dbs_handle_option(const char *name, const char = *val) +{ + if ( !strcmp(name, "rate") && val ) + { + usr_sampling_rate =3D simple_strtoull(val, NULL, 0) * MICROSECS(1)= ; + } + else if ( !strcmp(name, "threshold") && val ) + { + unsigned long tmp =3D simple_strtoul(val, NULL, 0); + + if ( tmp < MIN_FREQUENCY_UP_THRESHOLD ) + { + printk(XENLOG_WARNING "cpufreq/ondemand: " + "specified threshold too low, using %d\n", + MIN_FREQUENCY_UP_THRESHOLD); + tmp =3D MIN_FREQUENCY_UP_THRESHOLD; + } + else if ( tmp > MAX_FREQUENCY_UP_THRESHOLD ) + { + printk(XENLOG_WARNING "cpufreq/ondemand: " + "specified threshold too high, using %d\n", + MAX_FREQUENCY_UP_THRESHOLD); + tmp =3D MAX_FREQUENCY_UP_THRESHOLD; + } + dbs_tuners_ins.up_threshold =3D tmp; + } + else if ( !strcmp(name, "bias") && val ) + { + unsigned long tmp =3D simple_strtoul(val, NULL, 0); + + if ( tmp > 1000 ) + { + printk(XENLOG_WARNING "cpufreq/ondemand: " + "specified bias too high, using 1000\n"); + tmp =3D 1000; + } + dbs_tuners_ins.powersave_bias =3D tmp; + } +} + struct cpufreq_governor cpufreq_gov_dbs =3D { .name =3D "ondemand", .governor =3D cpufreq_governor_dbs, + .handle_option =3D cpufreq_dbs_handle_option }; =20 static int __init cpufreq_gov_dbs_init(void) @@ -297,55 +338,3 @@ static void cpufreq_gov_dbs_exit(void) cpufreq_unregister_governor(&cpufreq_gov_dbs); } __exitcall(cpufreq_gov_dbs_exit); - -void __init cpufreq_cmdline_parse(char *str) -{ - do { - char *val, *end =3D strchr(str, ','); - - if ( end ) - *end++ =3D '\0'; - val =3D strchr(str, '=3D'); - if ( val ) - *val++ =3D '\0'; - - if ( !strcmp(str, "rate") && val ) - { - usr_sampling_rate =3D simple_strtoull(val, NULL, 0) * = MICROSECS(1); - } - else if ( !strcmp(str, "threshold") && val ) - { - unsigned long tmp =3D simple_strtoul(val, NULL, 0); - - if ( tmp < MIN_FREQUENCY_UP_THRESHOLD ) - { - printk(XENLOG_WARNING "cpufreq/ondemand: " - "specified threshold too low, using %d\n", - MIN_FREQUENCY_UP_THRESHOLD); - tmp =3D MIN_FREQUENCY_UP_THRESHOLD; - } - else if ( tmp > MAX_FREQUENCY_UP_THRESHOLD ) - { - printk(XENLOG_WARNING "cpufreq/ondemand: " - "specified threshold too high, using %d\n", - MAX_FREQUENCY_UP_THRESHOLD); - tmp =3D MAX_FREQUENCY_UP_THRESHOLD; - } - dbs_tuners_ins.up_threshold =3D tmp; - } - else if ( !strcmp(str, "bias") && val ) - { - unsigned long tmp =3D simple_strtoul(val, NULL, 0); - - if ( tmp > 1000 ) - { - printk(XENLOG_WARNING "cpufreq/ondemand: " - "specified bias too high, using 1000\n"); - tmp =3D 1000; - } - dbs_tuners_ins.powersave_bias =3D tmp; - } - - str =3D end; - } while ( str ); -} --- 2009-01-30.orig/xen/include/acpi/cpufreq/cpufreq.h 2009-01-08 = 10:30:05.000000000 +0100 +++ 2009-01-30/xen/include/acpi/cpufreq/cpufreq.h 2009-01-30 = 13:53:08.000000000 +0100 @@ -87,6 +87,7 @@ struct cpufreq_governor { char name[CPUFREQ_NAME_LEN]; int (*governor)(struct cpufreq_policy *policy, unsigned int event); + void (*handle_option)(const char *name, const char *value); struct list_head governor_list; }; =20