ia64/xen-unstable

changeset 18448:06ab9cb9578e

x86: fix cpufreq_dom_mask

cpufreq_dom_mask must not be confined to the number of CPUs in the
system - there's nothing disallowing e.g. 1-based domain identifiers
to be used in _PSD. It still remains risky to assume that these
numbers are 'small' and/or not allocated sparsely.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Sep 08 14:01:17 2008 +0100 (2008-09-08)
parents f2bd9bbb0593
children 10c630645d13
files xen/arch/x86/acpi/cpufreq/cpufreq.c
line diff
     1.1 --- a/xen/arch/x86/acpi/cpufreq/cpufreq.c	Mon Sep 08 11:16:23 2008 +0100
     1.2 +++ b/xen/arch/x86/acpi/cpufreq/cpufreq.c	Mon Sep 08 14:01:17 2008 +0100
     1.3 @@ -48,7 +48,7 @@ struct processor_pminfo processor_pminfo
     1.4  struct cpufreq_policy xen_px_policy[NR_CPUS];
     1.5  
     1.6  static cpumask_t *cpufreq_dom_pt;
     1.7 -static cpumask_t cpufreq_dom_mask;
     1.8 +static unsigned long *cpufreq_dom_mask;
     1.9  static unsigned int cpufreq_dom_max;
    1.10  
    1.11  enum {
    1.12 @@ -562,7 +562,8 @@ static struct cpufreq_driver acpi_cpufre
    1.13  void cpufreq_dom_exit(void)
    1.14  {
    1.15      cpufreq_dom_max = 0;
    1.16 -    cpus_clear(cpufreq_dom_mask);
    1.17 +    if (cpufreq_dom_mask)
    1.18 +        xfree(cpufreq_dom_mask);
    1.19      if (cpufreq_dom_pt)
    1.20          xfree(cpufreq_dom_pt);
    1.21  }
    1.22 @@ -572,22 +573,28 @@ int cpufreq_dom_init(void)
    1.23      unsigned int i;
    1.24  
    1.25      cpufreq_dom_max = 0;
    1.26 -    cpus_clear(cpufreq_dom_mask);
    1.27  
    1.28      for_each_online_cpu(i) {
    1.29 -        cpu_set(processor_pminfo[i].perf.domain_info.domain, cpufreq_dom_mask);
    1.30          if (cpufreq_dom_max < processor_pminfo[i].perf.domain_info.domain)
    1.31              cpufreq_dom_max = processor_pminfo[i].perf.domain_info.domain;
    1.32      }
    1.33      cpufreq_dom_max++;
    1.34  
    1.35 +    cpufreq_dom_mask = xmalloc_array(unsigned long,
    1.36 +                                     BITS_TO_LONGS(cpufreq_dom_max));
    1.37 +    if (!cpufreq_dom_mask)
    1.38 +        return -ENOMEM;
    1.39 +    bitmap_zero(cpufreq_dom_mask, cpufreq_dom_max);
    1.40 +
    1.41      cpufreq_dom_pt = xmalloc_array(cpumask_t, cpufreq_dom_max);
    1.42      if (!cpufreq_dom_pt)
    1.43          return -ENOMEM;
    1.44      memset(cpufreq_dom_pt, 0, cpufreq_dom_max * sizeof(cpumask_t));
    1.45  
    1.46 -    for_each_online_cpu(i)
    1.47 +    for_each_online_cpu(i) {
    1.48 +        __set_bit(processor_pminfo[i].perf.domain_info.domain, cpufreq_dom_mask);
    1.49          cpu_set(i, cpufreq_dom_pt[processor_pminfo[i].perf.domain_info.domain]);
    1.50 +    }
    1.51  
    1.52      for_each_online_cpu(i)
    1.53          processor_pminfo[i].perf.shared_cpu_map =
    1.54 @@ -616,10 +623,11 @@ static int cpufreq_cpu_init(void)
    1.55  
    1.56  int cpufreq_dom_dbs(unsigned int event)
    1.57  {
    1.58 -    int cpu, dom, ret = 0;
    1.59 +    unsigned int cpu, dom;
    1.60 +    int ret = 0;
    1.61  
    1.62 -    for (dom=0; dom<cpufreq_dom_max; dom++) {
    1.63 -        if (!cpu_isset(dom, cpufreq_dom_mask))
    1.64 +    for (dom = 0; dom < cpufreq_dom_max; dom++) {
    1.65 +        if (!test_bit(dom, cpufreq_dom_mask))
    1.66              continue;
    1.67          cpu = first_cpu(cpufreq_dom_pt[dom]);
    1.68          ret = cpufreq_governor_dbs(&xen_px_policy[cpu], event);