WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] cpufreq: eliminate unnecessary NR_CPUS-sized arrays

To: "xen-devel@xxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH] cpufreq: eliminate unnecessary NR_CPUS-sized arrays
From: "Jan Beulich" <JBeulich@xxxxxxxxxx>
Date: Thu, 08 Jul 2010 16:35:15 +0100
Delivery-date: Thu, 08 Jul 2010 08:36:14 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
Replace them with per-CPU data.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxxxx>

--- 2010-06-15.orig/xen/arch/x86/acpi/cpufreq/cpufreq.c 2010-07-06 
16:11:48.000000000 +0200
+++ 2010-06-15/xen/arch/x86/acpi/cpufreq/cpufreq.c      2010-07-06 
17:07:34.000000000 +0200
@@ -210,10 +210,10 @@ static u32 get_cur_val(cpumask_t mask)
 
     if (!cpu_isset(cpu, mask))
         cpu = first_cpu(mask);
-    if (cpu >= NR_CPUS)
+    if (cpu >= NR_CPUS || !cpu_online(cpu))
         return 0;
 
-    policy = cpufreq_cpu_policy[cpu];
+    policy = per_cpu(cpufreq_cpu_policy, cpu);
     if (!policy || !drv_data[policy->cpu])
         return 0;    
 
@@ -281,7 +281,7 @@ unsigned int get_measured_perf(unsigned 
     if (!cpu_online(cpu))
         return 0;
 
-    policy = cpufreq_cpu_policy[cpu];
+    policy = per_cpu(cpufreq_cpu_policy, cpu);
     if (!policy || !policy->aperf_mperf)
         return 0;
 
@@ -366,7 +366,10 @@ static unsigned int get_cur_freq_on_cpu(
     struct acpi_cpufreq_data *data;
     unsigned int freq;
 
-    policy = cpufreq_cpu_policy[cpu];
+    if (!cpu_online(cpu))
+        return 0;
+
+    policy = per_cpu(cpufreq_cpu_policy, cpu);
     if (!policy)
         return 0;
 
--- 2010-06-15.orig/xen/drivers/acpi/pmstat.c   2010-07-06 16:49:48.000000000 
+0200
+++ 2010-06-15/xen/drivers/acpi/pmstat.c        2010-07-06 16:40:24.000000000 
+0200
@@ -43,7 +43,7 @@
 #include <acpi/cpufreq/cpufreq.h>
 #include <xen/pmstat.h>
 
-struct pm_px *__read_mostly cpufreq_statistic_data[NR_CPUS];
+DEFINE_PER_CPU_READ_MOSTLY(struct pm_px *, cpufreq_statistic_data);
 
 extern struct list_head cpufreq_governor_list;
 
@@ -92,7 +92,7 @@ int do_get_pm_info(struct xen_sysctl_get
 
         spin_lock(cpufreq_statistic_lock);
 
-        pxpt = cpufreq_statistic_data[op->cpuid];
+        pxpt = per_cpu(cpufreq_statistic_data, op->cpuid);
         if ( !pxpt || !pxpt->u.pt || !pxpt->u.trans_pt )
         {
             spin_unlock(cpufreq_statistic_lock);
@@ -204,7 +204,7 @@ static int get_cpufreq_para(struct xen_s
     if ( !op || !cpu_online(op->cpuid) )
         return -EINVAL;
     pmpt = processor_pminfo[op->cpuid];
-    policy = cpufreq_cpu_policy[op->cpuid];
+    policy = per_cpu(cpufreq_cpu_policy, op->cpuid);
 
     if ( !pmpt || !pmpt->perf.states ||
          !policy || !policy->governor )
@@ -313,7 +313,7 @@ static int set_cpufreq_gov(struct xen_sy
     if ( !op || !cpu_online(op->cpuid) )
         return -EINVAL;
 
-    old_policy = cpufreq_cpu_policy[op->cpuid];
+    old_policy = per_cpu(cpufreq_cpu_policy, op->cpuid);
     if ( !old_policy )
         return -EINVAL;
 
@@ -333,7 +333,7 @@ static int set_cpufreq_para(struct xen_s
 
     if ( !op || !cpu_online(op->cpuid) )
         return -EINVAL;
-    policy = cpufreq_cpu_policy[op->cpuid];
+    policy = per_cpu(cpufreq_cpu_policy, op->cpuid);
 
     if ( !policy || !policy->governor )
         return -EINVAL;
--- 2010-06-15.orig/xen/drivers/cpufreq/cpufreq.c       2010-07-06 
16:49:48.000000000 +0200
+++ 2010-06-15/xen/drivers/cpufreq/cpufreq.c    2010-07-06 16:48:47.000000000 
+0200
@@ -90,8 +90,7 @@ int cpufreq_register_governor(struct cpu
 
 int cpufreq_unregister_governor(struct cpufreq_governor *governor)
 {
-    int cpu = smp_processor_id();
-    struct cpufreq_policy *policy = cpufreq_cpu_policy[cpu];
+    struct cpufreq_policy *policy = this_cpu(cpufreq_cpu_policy);
 
     if (!governor || !policy)
         return -EINVAL;
@@ -110,10 +109,11 @@ int cpufreq_unregister_governor(struct c
 int cpufreq_limit_change(unsigned int cpu)
 {
     struct processor_performance *perf = &processor_pminfo[cpu]->perf;
-    struct cpufreq_policy *data = cpufreq_cpu_policy[cpu];
+    struct cpufreq_policy *data;
     struct cpufreq_policy policy;
 
-    if (!cpu_online(cpu) || !data || !processor_pminfo[cpu])
+    if (!cpu_online(cpu) || !(data = per_cpu(cpufreq_cpu_policy, cpu)) ||
+        !processor_pminfo[cpu])
         return -ENODEV;
 
     if ((perf->platform_limit < 0) || 
@@ -149,7 +149,7 @@ int cpufreq_add_cpu(unsigned int cpu)
     if (!cpufreq_driver)
         return 0;
 
-    if (cpufreq_cpu_policy[cpu])
+    if (per_cpu(cpufreq_cpu_policy, cpu))
         return 0;
 
     if (perf->shared_type == CPUFREQ_SHARED_TYPE_HW)
@@ -200,21 +200,21 @@ int cpufreq_add_cpu(unsigned int cpu)
 
         memset(policy, 0, sizeof(struct cpufreq_policy));
         policy->cpu = cpu;
-        cpufreq_cpu_policy[cpu] = policy;
+        per_cpu(cpufreq_cpu_policy, cpu) = policy;
 
         ret = cpufreq_driver->init(policy);
         if (ret) {
             xfree(policy);
-            cpufreq_cpu_policy[cpu] = NULL;
+            per_cpu(cpufreq_cpu_policy, cpu) = NULL;
             return ret;
         }
         if (cpufreq_verbose)
             printk("CPU %u initialization completed\n", cpu);
     } else {
         firstcpu = first_cpu(cpufreq_dom->map);
-        policy = cpufreq_cpu_policy[firstcpu];
+        policy = per_cpu(cpufreq_cpu_policy, firstcpu);
 
-        cpufreq_cpu_policy[cpu] = policy;
+        per_cpu(cpufreq_cpu_policy, cpu) = policy;
         if (cpufreq_verbose)
             printk("adding CPU %u\n", cpu);
     }
@@ -255,7 +255,7 @@ int cpufreq_add_cpu(unsigned int cpu)
 err2:
     cpufreq_statistic_exit(cpu);
 err1:
-    cpufreq_cpu_policy[cpu] = NULL;
+    per_cpu(cpufreq_cpu_policy, cpu) = NULL;
     cpu_clear(cpu, policy->cpus);
     cpu_clear(cpu, cpufreq_dom->map);
 
@@ -287,14 +287,14 @@ int cpufreq_del_cpu(unsigned int cpu)
         !cpu_online(cpu))
         return -EINVAL;
 
-    if (!cpufreq_cpu_policy[cpu])
+    if (!per_cpu(cpufreq_cpu_policy, cpu))
         return 0;
 
     if (perf->shared_type == CPUFREQ_SHARED_TYPE_HW)
         hw_all = 1;
 
     dom = perf->domain_info.domain;
-    policy = cpufreq_cpu_policy[cpu];
+    policy = per_cpu(cpufreq_cpu_policy, cpu);
 
     list_for_each(pos, &cpufreq_dom_list_head) {
         cpufreq_dom = list_entry(pos, struct cpufreq_dom, node);
@@ -314,7 +314,7 @@ int cpufreq_del_cpu(unsigned int cpu)
         __cpufreq_governor(policy, CPUFREQ_GOV_STOP);
 
     cpufreq_statistic_exit(cpu);
-    cpufreq_cpu_policy[cpu] = NULL;
+    per_cpu(cpufreq_cpu_policy, cpu) = NULL;
     cpu_clear(cpu, policy->cpus);
     cpu_clear(cpu, cpufreq_dom->map);
 
--- 2010-06-15.orig/xen/drivers/cpufreq/cpufreq_misc_governors.c        
2010-07-06 16:49:48.000000000 +0200
+++ 2010-06-15/xen/drivers/cpufreq/cpufreq_misc_governors.c     2010-07-06 
16:40:55.000000000 +0200
@@ -63,9 +63,9 @@ static int cpufreq_governor_userspace(st
 
 int write_userspace_scaling_setspeed(unsigned int cpu, unsigned int freq)
 {
-    struct cpufreq_policy *policy = cpufreq_cpu_policy[cpu];
+    struct cpufreq_policy *policy;
 
-    if (!cpu_online(cpu) || !policy)
+    if (!cpu_online(cpu) || !(policy = per_cpu(cpufreq_cpu_policy, cpu)))
         return -EINVAL;
 
     cpu_set_freq[cpu] = freq;
--- 2010-06-15.orig/xen/drivers/cpufreq/cpufreq_ondemand.c      2010-04-14 
14:05:15.000000000 +0200
+++ 2010-06-15/xen/drivers/cpufreq/cpufreq_ondemand.c   2010-07-06 
17:09:29.000000000 +0200
@@ -56,7 +56,7 @@ static struct dbs_tuners {
     .powersave_bias = 0,
 };
 
-static struct timer dbs_timer[NR_CPUS];
+static DEFINE_PER_CPU(struct timer, dbs_timer);
 
 int write_ondemand_sampling_rate(unsigned int sampling_rate)
 {
@@ -181,7 +181,7 @@ static void do_dbs_timer(void *dbs)
 
     dbs_check_cpu(dbs_info);
 
-    set_timer(&dbs_timer[dbs_info->cpu],
+    set_timer(&per_cpu(dbs_timer, dbs_info->cpu),
             align_timer(NOW() , dbs_tuners_ins.sampling_rate));
 }
 
@@ -189,10 +189,10 @@ static void dbs_timer_init(struct cpu_db
 {
     dbs_info->enable = 1;
 
-    init_timer(&dbs_timer[dbs_info->cpu], do_dbs_timer, 
+    init_timer(&per_cpu(dbs_timer, dbs_info->cpu), do_dbs_timer,
         (void *)dbs_info, dbs_info->cpu);
 
-    set_timer(&dbs_timer[dbs_info->cpu], NOW()+dbs_tuners_ins.sampling_rate);
+    set_timer(&per_cpu(dbs_timer, dbs_info->cpu), 
NOW()+dbs_tuners_ins.sampling_rate);
 
     if ( processor_pminfo[dbs_info->cpu]->perf.shared_type
             == CPUFREQ_SHARED_TYPE_HW )
@@ -205,7 +205,7 @@ static void dbs_timer_exit(struct cpu_db
 {
     dbs_info->enable = 0;
     dbs_info->stoppable = 0;
-    kill_timer(&dbs_timer[dbs_info->cpu]);
+    kill_timer(&per_cpu(dbs_timer, dbs_info->cpu));
 }
 
 int cpufreq_governor_dbs(struct cpufreq_policy *policy, unsigned int event)
@@ -362,7 +362,7 @@ void cpufreq_dbs_timer_suspend(void)
 
     if ( per_cpu(cpu_dbs_info,cpu).stoppable )
     {
-        stop_timer( &dbs_timer[cpu] );
+        stop_timer( &per_cpu(dbs_timer, cpu) );
     }
 }
 
@@ -377,7 +377,7 @@ void cpufreq_dbs_timer_resume(void)
     if ( per_cpu(cpu_dbs_info,cpu).stoppable )
     {
         now = NOW();
-        t = &dbs_timer[cpu];
+        t = &per_cpu(dbs_timer, cpu);
         if (t->expires <= now)
         {
             t->function(t->data);
--- 2010-06-15.orig/xen/drivers/cpufreq/utility.c       2010-07-06 
16:49:48.000000000 +0200
+++ 2010-06-15/xen/drivers/cpufreq/utility.c    2010-07-06 16:45:36.000000000 
+0200
@@ -34,7 +34,7 @@
 
 struct cpufreq_driver   *cpufreq_driver;
 struct processor_pminfo *__read_mostly processor_pminfo[NR_CPUS];
-struct cpufreq_policy   *__read_mostly cpufreq_cpu_policy[NR_CPUS];
+DEFINE_PER_CPU_READ_MOSTLY(struct cpufreq_policy *, cpufreq_cpu_policy);
 
 DEFINE_PER_CPU(spinlock_t, cpufreq_statistic_lock);
 
@@ -46,7 +46,7 @@ void cpufreq_residency_update(unsigned i
 {
     uint64_t now, total_idle_ns;
     int64_t delta;
-    struct pm_px *pxpt = cpufreq_statistic_data[cpu];
+    struct pm_px *pxpt = per_cpu(cpufreq_statistic_data, cpu);
 
     total_idle_ns = get_cpu_idle_time(cpu);
     now = NOW();
@@ -70,7 +70,7 @@ void cpufreq_statistic_update(unsigned i
 
     spin_lock(cpufreq_statistic_lock);
 
-    pxpt = cpufreq_statistic_data[cpu];
+    pxpt = per_cpu(cpufreq_statistic_data, cpu);
     if ( !pxpt || !pmpt ) {
         spin_unlock(cpufreq_statistic_lock);
         return;
@@ -102,7 +102,7 @@ int cpufreq_statistic_init(unsigned int 
 
     spin_lock(cpufreq_statistic_lock);
 
-    pxpt = cpufreq_statistic_data[cpuid];
+    pxpt = per_cpu(cpufreq_statistic_data, cpuid);
     if ( pxpt ) {
         spin_unlock(cpufreq_statistic_lock);
         return 0;
@@ -116,7 +116,7 @@ int cpufreq_statistic_init(unsigned int 
         return -ENOMEM;
     }
     memset(pxpt, 0, sizeof(*pxpt));
-    cpufreq_statistic_data[cpuid] = pxpt;
+    per_cpu(cpufreq_statistic_data, cpuid) = pxpt;
 
     pxpt->u.trans_pt = xmalloc_array(uint64_t, count * count);
     if (!pxpt->u.trans_pt) {
@@ -158,7 +158,7 @@ void cpufreq_statistic_exit(unsigned int
 
     spin_lock(cpufreq_statistic_lock);
 
-    pxpt = cpufreq_statistic_data[cpuid];
+    pxpt = per_cpu(cpufreq_statistic_data, cpuid);
     if (!pxpt) {
         spin_unlock(cpufreq_statistic_lock);
         return;
@@ -167,7 +167,7 @@ void cpufreq_statistic_exit(unsigned int
     xfree(pxpt->u.trans_pt);
     xfree(pxpt->u.pt);
     xfree(pxpt);
-    cpufreq_statistic_data[cpuid] = NULL;
+    per_cpu(cpufreq_statistic_data, cpuid) = NULL;
 
     spin_unlock(cpufreq_statistic_lock);
 }
@@ -182,7 +182,7 @@ void cpufreq_statistic_reset(unsigned in
 
     spin_lock(cpufreq_statistic_lock);
 
-    pxpt = cpufreq_statistic_data[cpuid];
+    pxpt = per_cpu(cpufreq_statistic_data, cpuid);
     if ( !pmpt || !pxpt || !pxpt->u.pt || !pxpt->u.trans_pt ) {
         spin_unlock(cpufreq_statistic_lock);
         return;
@@ -382,8 +382,7 @@ int cpufreq_driver_getavg(unsigned int c
     struct cpufreq_policy *policy;
     int freq_avg;
 
-    policy = cpufreq_cpu_policy[cpu];
-    if (!cpu_online(cpu) || !policy)
+    if (!cpu_online(cpu) || !(policy = per_cpu(cpufreq_cpu_policy, cpu)))
         return 0;
 
     if (cpufreq_driver->getavg)
@@ -400,7 +399,7 @@ void cpufreq_enable_turbo(int cpuid)
 {
     struct cpufreq_policy *policy;
 
-    policy = cpufreq_cpu_policy[cpuid];
+    policy = per_cpu(cpufreq_cpu_policy, cpuid);
     if (policy->turbo != CPUFREQ_TURBO_UNSUPPORTED)
         policy->turbo = CPUFREQ_TURBO_ENABLED;
 }
@@ -409,7 +408,7 @@ void cpufreq_disable_turbo(int cpuid)
 {
     struct cpufreq_policy *policy;
 
-    policy = cpufreq_cpu_policy[cpuid];
+    policy = per_cpu(cpufreq_cpu_policy, cpuid);
     if (policy->turbo != CPUFREQ_TURBO_UNSUPPORTED)
         policy->turbo = CPUFREQ_TURBO_DISABLED;
 }
@@ -418,7 +417,7 @@ int cpufreq_get_turbo_status(int cpuid)
 {
     struct cpufreq_policy *policy;
 
-    policy = cpufreq_cpu_policy[cpuid];
+    policy = per_cpu(cpufreq_cpu_policy, cpuid);
     return policy->turbo;
 }
 
--- 2010-06-15.orig/xen/include/acpi/cpufreq/cpufreq.h  2010-07-06 
16:49:48.000000000 +0200
+++ 2010-06-15/xen/include/acpi/cpufreq/cpufreq.h       2010-07-06 
16:36:16.000000000 +0200
@@ -59,7 +59,7 @@ struct cpufreq_policy {
                                  * See CPUFREQ_TURBO_* below for defines */
     bool_t              aperf_mperf; /* CPU has APERF/MPERF MSRs */
 };
-extern struct cpufreq_policy *cpufreq_cpu_policy[NR_CPUS];
+DECLARE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_policy);
 
 extern int __cpufreq_set_policy(struct cpufreq_policy *data,
                                 struct cpufreq_policy *policy);
--- 2010-06-15.orig/xen/include/acpi/cpufreq/processor_perf.h   2010-07-06 
16:49:48.000000000 +0200
+++ 2010-06-15/xen/include/acpi/cpufreq/processor_perf.h        2010-07-06 
16:25:45.000000000 +0200
@@ -58,7 +58,7 @@ struct pm_px {
     uint64_t prev_idle_wall;
 };
 
-extern struct pm_px *cpufreq_statistic_data[NR_CPUS];
+DECLARE_PER_CPU(struct pm_px *, cpufreq_statistic_data);
 
 int cpufreq_cpu_init(unsigned int cpuid);
 #endif /* __XEN_PROCESSOR_PM_H__ */


Attachment: cpufreq-no-NR_CPUS.patch
Description: Text document

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH] cpufreq: eliminate unnecessary NR_CPUS-sized arrays, Jan Beulich <=