ia64/xen-unstable

changeset 19194:ce391986ce35

cpufreq cmdline handling

c/s 19147 adjust cpufreq cmdline handling, this patch is a complement
to c/s 19147.

In this patch:
1. add common para (governor independent para) handling;
2. change governor dependent para handling method, governor dependent
para will only be handled by the handler of that governor (not by all
governors);
3. add userspace governor dependent para handling;
4. change para name 'threshold' of ondemand governor to 'up_threshold'
since ondemand has only 'up_threshold', and conservative governor (will be
implemented later) has both 'up_threshold' and 'down_threshold';
5. change some coding style (c/s 19147, drivers/cpufreq/cpufreq.c) to
keep coordination with original drivers/cpufreq/cpufreq.c coding style;
(originally this file is ported from linux, we partly use linux coding style)

Signed-off-by: Liu, Jinsong <jinsong.liu@intel.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Feb 11 10:47:24 2009 +0000 (2009-02-11)
parents 1a786ec606e4
children 999c465f94f9
files xen/drivers/cpufreq/cpufreq.c xen/drivers/cpufreq/cpufreq_misc_governors.c xen/drivers/cpufreq/cpufreq_ondemand.c
line diff
     1.1 --- a/xen/drivers/cpufreq/cpufreq.c	Wed Feb 11 10:45:34 2009 +0000
     1.2 +++ b/xen/drivers/cpufreq/cpufreq.c	Wed Feb 11 10:47:24 2009 +0000
     1.3 @@ -46,6 +46,9 @@
     1.4  #include <acpi/acpi.h>
     1.5  #include <acpi/cpufreq/cpufreq.h>
     1.6  
     1.7 +static unsigned int usr_max_freq, usr_min_freq;
     1.8 +static void cpufreq_cmdline_common_para(struct cpufreq_policy *new_policy);
     1.9 +
    1.10  struct cpufreq_dom {
    1.11      unsigned int	dom;
    1.12      cpumask_t		map;
    1.13 @@ -214,6 +217,9 @@ int cpufreq_add_cpu(unsigned int cpu)
    1.14          perf->domain_info.num_processors) {
    1.15          memcpy(&new_policy, policy, sizeof(struct cpufreq_policy));
    1.16          policy->governor = NULL;
    1.17 +
    1.18 +        cpufreq_cmdline_common_para(&new_policy);
    1.19 +
    1.20          ret = __cpufreq_set_policy(policy, &new_policy);
    1.21          if (ret) {
    1.22              if (new_policy.governor == CPUFREQ_DEFAULT_GOVERNOR)
    1.23 @@ -468,47 +474,71 @@ out:
    1.24      return ret;
    1.25  }
    1.26  
    1.27 +static void cpufreq_cmdline_common_para(struct cpufreq_policy *new_policy)
    1.28 +{
    1.29 +    if (usr_max_freq)
    1.30 +        new_policy->max = usr_max_freq;
    1.31 +    if (usr_min_freq)
    1.32 +        new_policy->min = usr_min_freq;
    1.33 +}
    1.34 +
    1.35 +static int __init cpufreq_handle_common_option(const char *name, const char *val)
    1.36 +{
    1.37 +    if (!strcmp(name, "maxfreq") && val) {
    1.38 +        usr_max_freq = simple_strtoul(val, NULL, 0);
    1.39 +        return 1;
    1.40 +    }
    1.41 +
    1.42 +    if (!strcmp(name, "minfreq") && val) {
    1.43 +        usr_min_freq = simple_strtoul(val, NULL, 0);
    1.44 +        return 1;
    1.45 +    }
    1.46 +
    1.47 +    return 0;
    1.48 +}
    1.49 +
    1.50  void __init cpufreq_cmdline_parse(char *str)
    1.51  {
    1.52      static struct cpufreq_governor *__initdata cpufreq_governors[] =
    1.53      {
    1.54 +        #define CPUFREQ_DEFAULT_GOVERNOR_INDEX 0;
    1.55          &cpufreq_gov_userspace,
    1.56          &cpufreq_gov_dbs,
    1.57          &cpufreq_gov_performance,
    1.58          &cpufreq_gov_powersave
    1.59      };
    1.60 +    unsigned int gov_index = CPUFREQ_DEFAULT_GOVERNOR_INDEX;
    1.61  
    1.62      do {
    1.63          char *val, *end = strchr(str, ',');
    1.64          unsigned int i;
    1.65  
    1.66 -        if ( end )
    1.67 +        if (end)
    1.68              *end++ = '\0';
    1.69          val = strchr(str, '=');
    1.70 -        if ( val )
    1.71 +        if (val)
    1.72              *val++ = '\0';
    1.73  
    1.74 -        if ( !cpufreq_opt_governor )
    1.75 -        {
    1.76 -            if ( !val )
    1.77 -            {
    1.78 -                for ( i = 0; i < ARRAY_SIZE(cpufreq_governors); ++i )
    1.79 -                    if ( !strcmp(str, cpufreq_governors[i]->name) )
    1.80 -                    {
    1.81 +        if (!cpufreq_opt_governor) {
    1.82 +            if (!val)
    1.83 +                for (i = 0; i < ARRAY_SIZE(cpufreq_governors); ++i)
    1.84 +                    if (!strcmp(str, cpufreq_governors[i]->name)) {
    1.85                          cpufreq_opt_governor = cpufreq_governors[i];
    1.86 +                        gov_index = i;
    1.87                          str = NULL;
    1.88                          break;
    1.89                      }
    1.90 -            }
    1.91              else
    1.92                  cpufreq_opt_governor = CPUFREQ_DEFAULT_GOVERNOR;
    1.93          }
    1.94  
    1.95 -        if ( str )
    1.96 -            for ( i = 0; i < ARRAY_SIZE(cpufreq_governors); ++i )
    1.97 -                if ( cpufreq_governors[i]->handle_option )
    1.98 -                    cpufreq_governors[i]->handle_option(str, val);
    1.99 +        if (str) {
   1.100 +            if (cpufreq_handle_common_option(str, val))
   1.101 +                ;
   1.102 +            else if (cpufreq_governors[gov_index]->handle_option)
   1.103 +                cpufreq_governors[gov_index]->handle_option(str, val);
   1.104 +        }
   1.105  
   1.106          str = end;
   1.107 -    } while ( str );
   1.108 +    } while (str);
   1.109  }
     2.1 --- a/xen/drivers/cpufreq/cpufreq_misc_governors.c	Wed Feb 11 10:45:34 2009 +0000
     2.2 +++ b/xen/drivers/cpufreq/cpufreq_misc_governors.c	Wed Feb 11 10:47:24 2009 +0000
     2.3 @@ -18,6 +18,7 @@
     2.4  #include <xen/sched.h>
     2.5  #include <acpi/cpufreq/cpufreq.h>
     2.6  
     2.7 +static unsigned int usr_speed;
     2.8  
     2.9  /*
    2.10   * cpufreq userspace governor
    2.11 @@ -26,6 +27,7 @@ static int cpufreq_governor_userspace(st
    2.12                                        unsigned int event)
    2.13  {
    2.14      int ret = 0;
    2.15 +    unsigned int freq;
    2.16  
    2.17      if (!policy)
    2.18          return -EINVAL;
    2.19 @@ -35,12 +37,17 @@ static int cpufreq_governor_userspace(st
    2.20      case CPUFREQ_GOV_STOP:
    2.21          break;
    2.22      case CPUFREQ_GOV_LIMITS:
    2.23 -        if (policy->max < policy->cur)
    2.24 +        freq = usr_speed ? : policy->cur;
    2.25 +        if (policy->max < freq)
    2.26              ret = __cpufreq_driver_target(policy, policy->max,
    2.27                          CPUFREQ_RELATION_H);
    2.28 -        else if (policy->min > policy->cur)
    2.29 +        else if (policy->min > freq)
    2.30              ret = __cpufreq_driver_target(policy, policy->min,
    2.31                          CPUFREQ_RELATION_L);
    2.32 +        else if (usr_speed)
    2.33 +            ret = __cpufreq_driver_target(policy, freq,
    2.34 +                        CPUFREQ_RELATION_L);
    2.35 +
    2.36          break;
    2.37      default:
    2.38          ret = -EINVAL;
    2.39 @@ -50,9 +57,17 @@ static int cpufreq_governor_userspace(st
    2.40      return ret;
    2.41  }
    2.42  
    2.43 +static void __init 
    2.44 +cpufreq_userspace_handle_option(const char *name, const char *val)
    2.45 +{
    2.46 +    if (!strcmp(name, "speed") && val)
    2.47 +        usr_speed = simple_strtoul(val, NULL, 0);
    2.48 +}
    2.49 +
    2.50  struct cpufreq_governor cpufreq_gov_userspace = {
    2.51      .name = "userspace",
    2.52      .governor = cpufreq_governor_userspace,
    2.53 +    .handle_option = cpufreq_userspace_handle_option
    2.54  };
    2.55  
    2.56  static int __init cpufreq_gov_userspace_init(void)
     3.1 --- a/xen/drivers/cpufreq/cpufreq_ondemand.c	Wed Feb 11 10:45:34 2009 +0000
     3.2 +++ b/xen/drivers/cpufreq/cpufreq_ondemand.c	Wed Feb 11 10:47:24 2009 +0000
     3.3 @@ -287,7 +287,7 @@ static void __init cpufreq_dbs_handle_op
     3.4      {
     3.5          usr_sampling_rate = simple_strtoull(val, NULL, 0) * MICROSECS(1);
     3.6      }
     3.7 -    else if ( !strcmp(name, "threshold") && val )
     3.8 +    else if ( !strcmp(name, "up_threshold") && val )
     3.9      {
    3.10          unsigned long tmp = simple_strtoul(val, NULL, 0);
    3.11