* [PATCH 1/8] NR_CPUS: Replace NR_CPUS in arch/x86/kernel/cpu/mcheck/mce_64.c
2008-07-19 1:11 [PATCH 0/8] NR_CPUS: Various replacements for NR_CPUS Mike Travis
@ 2008-07-19 1:11 ` Mike Travis
2008-07-19 1:11 ` [PATCH 2/8] NR_CPUS: Replace NR_CPUS in arch/x86/kernel/cpu/proc.c Mike Travis
` (7 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Mike Travis @ 2008-07-19 1:11 UTC (permalink / raw)
To: Ingo Molnar, Andrew Morton
Cc: H. Peter Anvin, Jack Steiner, linux-kernel, Cc: Eric W. Biederman
[-- Attachment #1: repl-NR_CPUS-in-arch_x86_kernel_cpu_mcheck_mce_64_c --]
[-- Type: text/plain, Size: 705 bytes --]
* nr_cpu_ids should be used to allocate arrays based on the number of
cpu's present.
Applies to both tip/master and linux-next.
Signed-off-by: Mike Travis <travis@sgi.com>
Cc: Cc: Eric W. Biederman <ebiederm@xmission.com>
---
arch/x86/kernel/cpu/mcheck/mce_64.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- linux-2.6.tip.orig/arch/x86/kernel/cpu/mcheck/mce_64.c
+++ linux-2.6.tip/arch/x86/kernel/cpu/mcheck/mce_64.c
@@ -580,7 +580,7 @@ static ssize_t mce_read(struct file *fil
char __user *buf = ubuf;
int i, err;
- cpu_tsc = kmalloc(NR_CPUS * sizeof(long), GFP_KERNEL);
+ cpu_tsc = kmalloc(nr_cpu_ids * sizeof(long), GFP_KERNEL);
if (!cpu_tsc)
return -ENOMEM;
--
^ permalink raw reply [flat|nested] 12+ messages in thread* [PATCH 2/8] NR_CPUS: Replace NR_CPUS in arch/x86/kernel/cpu/proc.c
2008-07-19 1:11 [PATCH 0/8] NR_CPUS: Various replacements for NR_CPUS Mike Travis
2008-07-19 1:11 ` [PATCH 1/8] NR_CPUS: Replace NR_CPUS in arch/x86/kernel/cpu/mcheck/mce_64.c Mike Travis
@ 2008-07-19 1:11 ` Mike Travis
2008-07-19 1:11 ` [PATCH 3/8] NR_CPUS: Replace NR_CPUS in arch/x86/kernel/genx2apic_uv_x.c Mike Travis
` (6 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Mike Travis @ 2008-07-19 1:11 UTC (permalink / raw)
To: Ingo Molnar, Andrew Morton
Cc: H. Peter Anvin, Jack Steiner, linux-kernel, Andi Kleen,
Hiroshi Shimamoto
[-- Attachment #1: repl-NR_CPUS-in-arch_x86_kernel_cpu_proc_c --]
[-- Type: text/plain, Size: 739 bytes --]
* Use nr_cpu_ids instead of NR_CPUS to limit traversal of cpu online map.
Applies to both tip/master and linux-next.
Signed-off-by: Mike Travis <travis@sgi.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>
---
arch/x86/kernel/cpu/proc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- linux-2.6.tip.orig/arch/x86/kernel/cpu/proc.c
+++ linux-2.6.tip/arch/x86/kernel/cpu/proc.c
@@ -160,7 +160,7 @@ static void *c_start(struct seq_file *m,
{
if (*pos == 0) /* just in case, cpu 0 is not the first */
*pos = first_cpu(cpu_online_map);
- if ((*pos) < NR_CPUS && cpu_online(*pos))
+ if ((*pos) < nr_cpu_ids && cpu_online(*pos))
return &cpu_data(*pos);
return NULL;
}
--
^ permalink raw reply [flat|nested] 12+ messages in thread* [PATCH 3/8] NR_CPUS: Replace NR_CPUS in arch/x86/kernel/genx2apic_uv_x.c
2008-07-19 1:11 [PATCH 0/8] NR_CPUS: Various replacements for NR_CPUS Mike Travis
2008-07-19 1:11 ` [PATCH 1/8] NR_CPUS: Replace NR_CPUS in arch/x86/kernel/cpu/mcheck/mce_64.c Mike Travis
2008-07-19 1:11 ` [PATCH 2/8] NR_CPUS: Replace NR_CPUS in arch/x86/kernel/cpu/proc.c Mike Travis
@ 2008-07-19 1:11 ` Mike Travis
2008-07-19 1:11 ` [PATCH 4/8] NR_CPUS: Replace NR_CPUS in arch/x86/kernel/genapic_flat_64.c Mike Travis
` (5 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Mike Travis @ 2008-07-19 1:11 UTC (permalink / raw)
To: Ingo Molnar, Andrew Morton; +Cc: H. Peter Anvin, Jack Steiner, linux-kernel
[-- Attachment #1: repl-NR_CPUS-in-arch_x86_kernel_genx2apic_uv_x_c --]
[-- Type: text/plain, Size: 966 bytes --]
* Replace NR_CPUS loop with for_each_possible_cpu().
* nr_cpu_ids should be used to determine if a percpu area is
available for a given cpu.
Applies to both tip/master and linux-next.
Signed-off-by: Mike Travis <travis@sgi.com>
Cc: Jack Steiner <steiner@sgi.com>
---
arch/x86/kernel/genx2apic_uv_x.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
--- linux-2.6.tip.orig/arch/x86/kernel/genx2apic_uv_x.c
+++ linux-2.6.tip/arch/x86/kernel/genx2apic_uv_x.c
@@ -98,7 +98,7 @@ static void uv_send_IPI_mask(cpumask_t m
{
unsigned int cpu;
- for (cpu = 0; cpu < NR_CPUS; ++cpu)
+ for_each_possible_cpu(cpu)
if (cpu_isset(cpu, mask))
uv_send_IPI_one(cpu, vector);
}
@@ -132,7 +132,7 @@ static unsigned int uv_cpu_mask_to_apici
* May as well be the first.
*/
cpu = first_cpu(cpumask);
- if ((unsigned)cpu < NR_CPUS)
+ if ((unsigned)cpu < nr_cpu_ids)
return per_cpu(x86_cpu_to_apicid, cpu);
else
return BAD_APICID;
--
^ permalink raw reply [flat|nested] 12+ messages in thread* [PATCH 4/8] NR_CPUS: Replace NR_CPUS in arch/x86/kernel/genapic_flat_64.c
2008-07-19 1:11 [PATCH 0/8] NR_CPUS: Various replacements for NR_CPUS Mike Travis
` (2 preceding siblings ...)
2008-07-19 1:11 ` [PATCH 3/8] NR_CPUS: Replace NR_CPUS in arch/x86/kernel/genx2apic_uv_x.c Mike Travis
@ 2008-07-19 1:11 ` Mike Travis
2008-07-19 1:11 ` [PATCH 5/8] NR_CPUS: Replace per_cpu(..., smp_processor_id()) with __get_cpu_var Mike Travis
` (4 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Mike Travis @ 2008-07-19 1:11 UTC (permalink / raw)
To: Ingo Molnar, Andrew Morton
Cc: H. Peter Anvin, Jack Steiner, linux-kernel, Andi Kleen
[-- Attachment #1: repl-NR_CPUS-in-arch_x86_kernel_genapic_flat_64_c --]
[-- Type: text/plain, Size: 694 bytes --]
* nr_cpu_ids should be used to determine if a percpu area is
available for a given cpu.
Applies to both tip/master and linux-next.
Signed-off-by: Mike Travis <travis@sgi.com>
Cc: Andi Kleen <andi@firstfloor.org>
---
arch/x86/kernel/genapic_flat_64.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- linux-2.6.tip.orig/arch/x86/kernel/genapic_flat_64.c
+++ linux-2.6.tip/arch/x86/kernel/genapic_flat_64.c
@@ -168,7 +168,7 @@ static unsigned int physflat_cpu_mask_to
* May as well be the first.
*/
cpu = first_cpu(cpumask);
- if ((unsigned)cpu < NR_CPUS)
+ if ((unsigned)cpu < nr_cpu_ids)
return per_cpu(x86_cpu_to_apicid, cpu);
else
return BAD_APICID;
--
^ permalink raw reply [flat|nested] 12+ messages in thread* [PATCH 5/8] NR_CPUS: Replace per_cpu(..., smp_processor_id()) with __get_cpu_var
2008-07-19 1:11 [PATCH 0/8] NR_CPUS: Various replacements for NR_CPUS Mike Travis
` (3 preceding siblings ...)
2008-07-19 1:11 ` [PATCH 4/8] NR_CPUS: Replace NR_CPUS in arch/x86/kernel/genapic_flat_64.c Mike Travis
@ 2008-07-19 1:11 ` Mike Travis
2008-07-19 1:11 ` [PATCH 6/8] NR_CPUS: Replace NR_CPUS in cpufreq userspace routines Mike Travis
` (3 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Mike Travis @ 2008-07-19 1:11 UTC (permalink / raw)
To: Ingo Molnar, Andrew Morton; +Cc: H. Peter Anvin, Jack Steiner, linux-kernel
[-- Attachment #1: repl-NR_CPUS-in-include_asm-x86_processor_h --]
[-- Type: text/plain, Size: 716 bytes --]
* Slight optimization when getting one's own cpu_info percpu data.
Applies to both tip/master and linux-next.
Signed-off-by: Mike Travis <travis@sgi.com>
---
include/asm-x86/processor.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- linux-2.6.tip.orig/include/asm-x86/processor.h
+++ linux-2.6.tip/include/asm-x86/processor.h
@@ -135,7 +135,7 @@ extern __u32 cleared_cpu_caps[NCAPINTS
#ifdef CONFIG_SMP
DECLARE_PER_CPU(struct cpuinfo_x86, cpu_info);
#define cpu_data(cpu) per_cpu(cpu_info, cpu)
-#define current_cpu_data cpu_data(smp_processor_id())
+#define current_cpu_data __get_cpu_var(cpu_info)
#else
#define cpu_data(cpu) boot_cpu_data
#define current_cpu_data boot_cpu_data
--
^ permalink raw reply [flat|nested] 12+ messages in thread* [PATCH 6/8] NR_CPUS: Replace NR_CPUS in cpufreq userspace routines
2008-07-19 1:11 [PATCH 0/8] NR_CPUS: Various replacements for NR_CPUS Mike Travis
` (4 preceding siblings ...)
2008-07-19 1:11 ` [PATCH 5/8] NR_CPUS: Replace per_cpu(..., smp_processor_id()) with __get_cpu_var Mike Travis
@ 2008-07-19 1:11 ` Mike Travis
2008-07-19 1:11 ` [PATCH 7/8] cpumask: Provide a generic set of CPUMASK_ALLOC macros, FIXUP Mike Travis
` (2 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Mike Travis @ 2008-07-19 1:11 UTC (permalink / raw)
To: Ingo Molnar, Andrew Morton
Cc: H. Peter Anvin, Jack Steiner, linux-kernel, Jason Baron,
Dave Jones, cpufreq
[-- Attachment #1: repl-NR_CPUS-in-cpufreq_userspace --]
[-- Type: text/plain, Size: 5797 bytes --]
* This patch seems to have been misplaced. Replace arrays sized by NR_CPUS
with percpu variables.
Prior reference: http://marc.info/?l=linux-kernel&m=120251421825989&w=4
Subject: [PATCH 1/4] cpufreq: change cpu freq tables to per_cpu variables
From: Mike Travis <travis () sgi ! com>
Date: 2008-02-08 23:37:39
Applies to both tip/master and linux-next.
Signed-off-by: Mike Travis <travis@sgi.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: Dave Jones <davej@codemonkey.org.uk>
Cc: cpufreq@lists.linux.org.uk
---
drivers/cpufreq/cpufreq_userspace.c | 79 +++++++++++++++++++-----------------
1 file changed, 43 insertions(+), 36 deletions(-)
--- linux-2.6.tip.orig/drivers/cpufreq/cpufreq_userspace.c
+++ linux-2.6.tip/drivers/cpufreq/cpufreq_userspace.c
@@ -30,16 +30,18 @@
/**
* A few values needed by the userspace governor
*/
-static unsigned int cpu_max_freq[NR_CPUS];
-static unsigned int cpu_min_freq[NR_CPUS];
-static unsigned int cpu_cur_freq[NR_CPUS]; /* current CPU freq */
-static unsigned int cpu_set_freq[NR_CPUS]; /* CPU freq desired by userspace */
-static unsigned int cpu_is_managed[NR_CPUS];
+static DEFINE_PER_CPU(unsigned int, cpu_max_freq);
+static DEFINE_PER_CPU(unsigned int, cpu_min_freq);
+static DEFINE_PER_CPU(unsigned int, cpu_cur_freq); /* current CPU freq */
+static DEFINE_PER_CPU(unsigned int, cpu_set_freq); /* CPU freq desired by
+ userspace */
+static DEFINE_PER_CPU(unsigned int, cpu_is_managed);
static DEFINE_MUTEX (userspace_mutex);
static int cpus_using_userspace_governor;
-#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_GOVERNOR, "userspace", msg)
+#define dprintk(msg...) \
+ cpufreq_debug_printk(CPUFREQ_DEBUG_GOVERNOR, "userspace", msg)
/* keep track of frequency transitions */
static int
@@ -48,12 +50,12 @@ userspace_cpufreq_notifier(struct notifi
{
struct cpufreq_freqs *freq = data;
- if (!cpu_is_managed[freq->cpu])
+ if (!per_cpu(cpu_is_managed, freq->cpu))
return 0;
dprintk("saving cpu_cur_freq of cpu %u to be %u kHz\n",
freq->cpu, freq->new);
- cpu_cur_freq[freq->cpu] = freq->new;
+ per_cpu(cpu_cur_freq, freq->cpu) = freq->new;
return 0;
}
@@ -77,15 +79,15 @@ static int cpufreq_set(struct cpufreq_po
dprintk("cpufreq_set for cpu %u, freq %u kHz\n", policy->cpu, freq);
mutex_lock(&userspace_mutex);
- if (!cpu_is_managed[policy->cpu])
+ if (!per_cpu(cpu_is_managed, policy->cpu))
goto err;
- cpu_set_freq[policy->cpu] = freq;
+ per_cpu(cpu_set_freq, policy->cpu) = freq;
- if (freq < cpu_min_freq[policy->cpu])
- freq = cpu_min_freq[policy->cpu];
- if (freq > cpu_max_freq[policy->cpu])
- freq = cpu_max_freq[policy->cpu];
+ if (freq < per_cpu(cpu_min_freq, policy->cpu))
+ freq = per_cpu(cpu_min_freq, policy->cpu);
+ if (freq > per_cpu(cpu_max_freq, policy->cpu))
+ freq = per_cpu(cpu_max_freq, policy->cpu);
/*
* We're safe from concurrent calls to ->target() here
@@ -104,7 +106,7 @@ static int cpufreq_set(struct cpufreq_po
static ssize_t show_speed(struct cpufreq_policy *policy, char *buf)
{
- return sprintf(buf, "%u\n", cpu_cur_freq[policy->cpu]);
+ return sprintf(buf, "%u\n", per_cpu(cpu_cur_freq, policy->cpu));
}
static int cpufreq_governor_userspace(struct cpufreq_policy *policy,
@@ -127,12 +129,17 @@ static int cpufreq_governor_userspace(st
}
cpus_using_userspace_governor++;
- cpu_is_managed[cpu] = 1;
- cpu_min_freq[cpu] = policy->min;
- cpu_max_freq[cpu] = policy->max;
- cpu_cur_freq[cpu] = policy->cur;
- cpu_set_freq[cpu] = policy->cur;
- dprintk("managing cpu %u started (%u - %u kHz, currently %u kHz)\n", cpu, cpu_min_freq[cpu], cpu_max_freq[cpu], cpu_cur_freq[cpu]);
+ per_cpu(cpu_is_managed, cpu) = 1;
+ per_cpu(cpu_min_freq, cpu) = policy->min;
+ per_cpu(cpu_max_freq, cpu) = policy->max;
+ per_cpu(cpu_cur_freq, cpu) = policy->cur;
+ per_cpu(cpu_set_freq, cpu) = policy->cur;
+ dprintk("managing cpu %u started "
+ "(%u - %u kHz, currently %u kHz)\n",
+ cpu,
+ per_cpu(cpu_min_freq, cpu),
+ per_cpu(cpu_max_freq, cpu),
+ per_cpu(cpu_cur_freq, cpu));
mutex_unlock(&userspace_mutex);
break;
@@ -145,34 +152,34 @@ static int cpufreq_governor_userspace(st
CPUFREQ_TRANSITION_NOTIFIER);
}
- cpu_is_managed[cpu] = 0;
- cpu_min_freq[cpu] = 0;
- cpu_max_freq[cpu] = 0;
- cpu_set_freq[cpu] = 0;
+ per_cpu(cpu_is_managed, cpu) = 0;
+ per_cpu(cpu_min_freq, cpu) = 0;
+ per_cpu(cpu_max_freq, cpu) = 0;
+ per_cpu(cpu_set_freq, cpu) = 0;
dprintk("managing cpu %u stopped\n", cpu);
mutex_unlock(&userspace_mutex);
break;
case CPUFREQ_GOV_LIMITS:
mutex_lock(&userspace_mutex);
- dprintk("limit event for cpu %u: %u - %u kHz,"
+ dprintk("limit event for cpu %u: %u - %u kHz, "
"currently %u kHz, last set to %u kHz\n",
cpu, policy->min, policy->max,
- cpu_cur_freq[cpu], cpu_set_freq[cpu]);
- if (policy->max < cpu_set_freq[cpu]) {
+ per_cpu(cpu_cur_freq, cpu),
+ per_cpu(cpu_set_freq, cpu));
+ if (policy->max < per_cpu(cpu_set_freq, cpu)) {
__cpufreq_driver_target(policy, policy->max,
CPUFREQ_RELATION_H);
- }
- else if (policy->min > cpu_set_freq[cpu]) {
+ } else if (policy->min > per_cpu(cpu_set_freq, cpu)) {
__cpufreq_driver_target(policy, policy->min,
CPUFREQ_RELATION_L);
- }
- else {
- __cpufreq_driver_target(policy, cpu_set_freq[cpu],
+ } else {
+ __cpufreq_driver_target(policy,
+ per_cpu(cpu_set_freq, cpu),
CPUFREQ_RELATION_L);
}
- cpu_min_freq[cpu] = policy->min;
- cpu_max_freq[cpu] = policy->max;
- cpu_cur_freq[cpu] = policy->cur;
+ per_cpu(cpu_min_freq, cpu) = policy->min;
+ per_cpu(cpu_max_freq, cpu) = policy->max;
+ per_cpu(cpu_cur_freq, cpu) = policy->cur;
mutex_unlock(&userspace_mutex);
break;
}
--
^ permalink raw reply [flat|nested] 12+ messages in thread* [PATCH 7/8] cpumask: Provide a generic set of CPUMASK_ALLOC macros, FIXUP
2008-07-19 1:11 [PATCH 0/8] NR_CPUS: Various replacements for NR_CPUS Mike Travis
` (5 preceding siblings ...)
2008-07-19 1:11 ` [PATCH 6/8] NR_CPUS: Replace NR_CPUS in cpufreq userspace routines Mike Travis
@ 2008-07-19 1:11 ` Mike Travis
2008-07-19 1:11 ` [PATCH 8/8] NR_CPUS: Replace NR_CPUS in speedstep-centrino.c Mike Travis
2008-07-20 8:23 ` [PATCH 0/8] NR_CPUS: Various replacements for NR_CPUS Ingo Molnar
8 siblings, 0 replies; 12+ messages in thread
From: Mike Travis @ 2008-07-19 1:11 UTC (permalink / raw)
To: Ingo Molnar, Andrew Morton
Cc: H. Peter Anvin, Jack Steiner, linux-kernel, Paul Jackson,
Bert Wesarg
[-- Attachment #1: fix-CPUMASK_ALLOC --]
[-- Type: text/plain, Size: 3204 bytes --]
* Rename CPUMASK_VAR --> CPUMASK_PTR (and simplify)
* Fix a semantic error in CPUMASK_ALLOC
* Add a bit of commentry to cpumask.h
Based on linux-2.6.tip/master with the following commit:
commit 77586c2bdad0798cb24e35de5a878e7c6b200574
Author: Mike Travis <travis@sgi.com> 2008-07-15 14:14:37
Committer: Ingo Molnar <mingo@elte.hu> 2008-07-18 13:03:00
Parent: 77586c2bdad0798cb24e35de5a878e7c6b200574 (cpumask: Provide a generic set of CPUMASK_ALLOC macros)
Child: 06f8d00e9eecb738c99b737ac38a585ea7583ad5 (cpumask: Optimize cpumask_of_cpu in lib/smp_processor_id.c, fix)
Child: 32650cb6a8665a7635d025e52d9bf1905981ed11 (Merge branch 'cpus4096')
Branches: -, devel, remotes/tip/cpus4096, remotes/tip/master, tip-latest
cpumask: Provide a generic set of CPUMASK_ALLOC macros
Signed-off-by: Mike Travis <travis@sgi.com>
Cc: Paul Jackson <pj@sgi.com>
Cc: Bert Wesarg <bert.wesarg@googlemail.com>
---
include/linux/cpumask.h | 33 ++++++++++++++++++++++++++-------
1 file changed, 26 insertions(+), 7 deletions(-)
--- linux-2.6.tip.orig/include/linux/cpumask.h
+++ linux-2.6.tip/include/linux/cpumask.h
@@ -75,16 +75,36 @@
* CPU_MASK_NONE Initializer - no bits set
* unsigned long *cpus_addr(mask) Array of unsigned long's in mask
*
+ * CPUMASK_ALLOC kmalloc's a structure that is a composite of many cpumask_t
+ * variables, and CPUMASK_PTR provides pointers to each field.
+ *
+ * The structure should be defined something like this:
+ * struct my_cpumasks {
+ * cpumask_t mask1;
+ * cpumask_t mask2;
+ * };
+ *
+ * Usage is then:
+ * CPUMASK_ALLOC(my_cpumasks);
+ * CPUMASK_PTR(mask1, my_cpumasks);
+ * CPUMASK_PTR(mask2, my_cpumasks);
+ *
+ * --- DO NOT reference cpumask_t pointers until this check ---
+ * if (my_cpumasks == NULL)
+ * "kmalloc failed"...
+ *
+ * References are now pointers to the cpumask_t variables (*mask1, ...)
+ *
*if NR_CPUS > BITS_PER_LONG
* CPUMASK_ALLOC(m) Declares and allocates struct m *m =
- * (struct m *)kmalloc(sizeof(*m), ...)
- * CPUMASK_FREE(m) Macro for kfree(v)
+ * kmalloc(sizeof(*m), GFP_KERNEL)
+ * CPUMASK_FREE(m) Macro for kfree(m)
*else
* CPUMASK_ALLOC(m) Declares struct m _m, *m = &_m
* CPUMASK_FREE(m) Nop
*endif
- * CPUMASK_VAR(v, m) Declares cpumask_t *v =
- * m + offset(struct m, v)
+ * CPUMASK_PTR(v, m) Declares cpumask_t *v = &(m->v)
+ * ------------------------------------------------------------------------
*
* int cpumask_scnprintf(buf, len, mask) Format cpumask for printing
* int cpumask_parse_user(ubuf, ulen, mask) Parse ascii string as cpumask
@@ -326,11 +346,10 @@ extern cpumask_t cpu_mask_all;
#define CPUMASK_ALLOC(m) struct m *m = kmalloc(sizeof(*m), GFP_KERNEL)
#define CPUMASK_FREE(m) kfree(m)
#else
-#define CPUMASK_ALLOC(m) struct allmasks _m, *m = &_m
+#define CPUMASK_ALLOC(m) struct m _m, *m = &_m
#define CPUMASK_FREE(m)
#endif
-#define CPUMASK_VAR(v, m) cpumask_t *v = (cpumask_t *) \
- ((unsigned long)(m) + offsetof(struct m, v))
+#define CPUMASK_PTR(v, m) cpumask_t *v = &(m->v)
#define cpumask_scnprintf(buf, len, src) \
__cpumask_scnprintf((buf), (len), &(src), NR_CPUS)
--
^ permalink raw reply [flat|nested] 12+ messages in thread* [PATCH 8/8] NR_CPUS: Replace NR_CPUS in speedstep-centrino.c
2008-07-19 1:11 [PATCH 0/8] NR_CPUS: Various replacements for NR_CPUS Mike Travis
` (6 preceding siblings ...)
2008-07-19 1:11 ` [PATCH 7/8] cpumask: Provide a generic set of CPUMASK_ALLOC macros, FIXUP Mike Travis
@ 2008-07-19 1:11 ` Mike Travis
2008-07-20 8:23 ` [PATCH 0/8] NR_CPUS: Various replacements for NR_CPUS Ingo Molnar
8 siblings, 0 replies; 12+ messages in thread
From: Mike Travis @ 2008-07-19 1:11 UTC (permalink / raw)
To: Ingo Molnar, Andrew Morton
Cc: H. Peter Anvin, Jack Steiner, linux-kernel, Venki Pallipadi,
Dave Jones, cpufreq
[-- Attachment #1: repl-NR_CPUS-in-arch_x86_kernel_cpu_cpufreq_speedstep-centrino_c --]
[-- Type: text/plain, Size: 8472 bytes --]
Some cleanups in speedstep-centrino.c for NR_CPUS=4096.
* Use new CPUMASK_PTR (instead of old CPUMASK_VAR).
* Replace arrays sized by NR_CPUS with percpu variables.
* Cleanup some formatting problems (>80 chars per line)
and other checkpatch complaints.
Applies to tip/master with following commit:
commit 06f8d00e9eecb738c99b737ac38a585ea7583ad5
Author: Mike Travis <travis@sgi.com> 2008-07-15 14:14:37
Committer: Ingo Molnar <mingo@elte.hu> 2008-07-18 13:03:00
Parent: 77586c2bdad0798cb24e35de5a878e7c6b200574 (cpumask: Provide a generic set of CPUMASK_ALLOC macros)
Child: 06f8d00e9eecb738c99b737ac38a585ea7583ad5 (cpumask: Optimize cpumask_of_cpu in lib/smp_processor_id.c, fix)
Child: 32650cb6a8665a7635d025e52d9bf1905981ed11 (Merge branch 'cpus4096')
Branches: -, devel, remotes/tip/cpus4096, remotes/tip/master, tip-latest
cpumask: Use optimized CPUMASK_ALLOC macros in the centrino_target
Signed-off-by: Mike Travis <travis@sgi.com>
Cc: Venki Pallipadi <venkatesh.pallipadi@intel.com>
Cc: Dave Jones <davej@codemonkey.org.uk>
Cc: cpufreq@lists.linux.org.uk
---
arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c | 85 +++++++++++++----------
1 file changed, 51 insertions(+), 34 deletions(-)
--- linux-2.6.tip.orig/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c
+++ linux-2.6.tip/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c
@@ -28,7 +28,8 @@
#define PFX "speedstep-centrino: "
#define MAINTAINER "cpufreq@lists.linux.org.uk"
-#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "speedstep-centrino", msg)
+#define dprintk(msg...) \
+ cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "speedstep-centrino", msg)
#define INTEL_MSR_RANGE (0xffff)
@@ -68,11 +69,12 @@ struct cpu_model
struct cpufreq_frequency_table *op_points; /* clock/voltage pairs */
};
-static int centrino_verify_cpu_id(const struct cpuinfo_x86 *c, const struct cpu_id *x);
+static int centrino_verify_cpu_id(const struct cpuinfo_x86 *c,
+ const struct cpu_id *x);
/* Operating points for current CPU */
-static struct cpu_model *centrino_model[NR_CPUS];
-static const struct cpu_id *centrino_cpu[NR_CPUS];
+static DEFINE_PER_CPU(struct cpu_model *, centrino_model);
+static DEFINE_PER_CPU(const struct cpu_id *, centrino_cpu);
static struct cpufreq_driver centrino_driver;
@@ -348,7 +350,7 @@ static int centrino_cpu_init_table(struc
return -ENOENT;
}
- centrino_model[policy->cpu] = model;
+ per_cpu(centrino_model, policy->cpu) = model;
dprintk("found \"%s\": max frequency: %dkHz\n",
model->model_name, model->max_freq);
@@ -357,10 +359,14 @@ static int centrino_cpu_init_table(struc
}
#else
-static inline int centrino_cpu_init_table(struct cpufreq_policy *policy) { return -ENODEV; }
+static inline int centrino_cpu_init_table(struct cpufreq_policy *policy)
+{
+ return -ENODEV;
+}
#endif /* CONFIG_X86_SPEEDSTEP_CENTRINO_TABLE */
-static int centrino_verify_cpu_id(const struct cpuinfo_x86 *c, const struct cpu_id *x)
+static int centrino_verify_cpu_id(const struct cpuinfo_x86 *c,
+ const struct cpu_id *x)
{
if ((c->x86 == x->x86) &&
(c->x86_model == x->x86_model) &&
@@ -379,23 +385,28 @@ static unsigned extract_clock(unsigned m
* for centrino, as some DSDTs are buggy.
* Ideally, this can be done using the acpi_data structure.
*/
- if ((centrino_cpu[cpu] == &cpu_ids[CPU_BANIAS]) ||
- (centrino_cpu[cpu] == &cpu_ids[CPU_DOTHAN_A1]) ||
- (centrino_cpu[cpu] == &cpu_ids[CPU_DOTHAN_B0])) {
+ if ((per_cpu(centrino_cpu, cpu) == &cpu_ids[CPU_BANIAS]) ||
+ (per_cpu(centrino_cpu, cpu) == &cpu_ids[CPU_DOTHAN_A1]) ||
+ (per_cpu(centrino_cpu, cpu) == &cpu_ids[CPU_DOTHAN_B0])) {
msr = (msr >> 8) & 0xff;
return msr * 100000;
}
- if ((!centrino_model[cpu]) || (!centrino_model[cpu]->op_points))
+ if ((!per_cpu(centrino_model, cpu)) ||
+ (!per_cpu(centrino_model, cpu)->op_points))
return 0;
msr &= 0xffff;
- for (i=0;centrino_model[cpu]->op_points[i].frequency != CPUFREQ_TABLE_END; i++) {
- if (msr == centrino_model[cpu]->op_points[i].index)
- return centrino_model[cpu]->op_points[i].frequency;
+ for (i = 0;
+ per_cpu(centrino_model, cpu)->op_points[i].frequency
+ != CPUFREQ_TABLE_END;
+ i++) {
+ if (msr == per_cpu(centrino_model, cpu)->op_points[i].index)
+ return per_cpu(centrino_model, cpu)->
+ op_points[i].frequency;
}
if (failsafe)
- return centrino_model[cpu]->op_points[i-1].frequency;
+ return per_cpu(centrino_model, cpu)->op_points[i-1].frequency;
else
return 0;
}
@@ -441,7 +452,8 @@ static int centrino_cpu_init(struct cpuf
int i;
/* Only Intel makes Enhanced Speedstep-capable CPUs */
- if (cpu->x86_vendor != X86_VENDOR_INTEL || !cpu_has(cpu, X86_FEATURE_EST))
+ if (cpu->x86_vendor != X86_VENDOR_INTEL ||
+ !cpu_has(cpu, X86_FEATURE_EST))
return -ENODEV;
if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
@@ -455,9 +467,9 @@ static int centrino_cpu_init(struct cpuf
break;
if (i != N_IDS)
- centrino_cpu[policy->cpu] = &cpu_ids[i];
+ per_cpu(centrino_cpu, policy->cpu) = &cpu_ids[i];
- if (!centrino_cpu[policy->cpu]) {
+ if (!per_cpu(centrino_cpu, policy->cpu)) {
dprintk("found unsupported CPU with "
"Enhanced SpeedStep: send /proc/cpuinfo to "
MAINTAINER "\n");
@@ -480,23 +492,26 @@ static int centrino_cpu_init(struct cpuf
/* check to see if it stuck */
rdmsr(MSR_IA32_MISC_ENABLE, l, h);
if (!(l & (1<<16))) {
- printk(KERN_INFO PFX "couldn't enable Enhanced SpeedStep\n");
+ printk(KERN_INFO PFX
+ "couldn't enable Enhanced SpeedStep\n");
return -ENODEV;
}
}
freq = get_cur_freq(policy->cpu);
-
- policy->cpuinfo.transition_latency = 10000; /* 10uS transition latency */
+ policy->cpuinfo.transition_latency = 10000;
+ /* 10uS transition latency */
policy->cur = freq;
dprintk("centrino_cpu_init: cur=%dkHz\n", policy->cur);
- ret = cpufreq_frequency_table_cpuinfo(policy, centrino_model[policy->cpu]->op_points);
+ ret = cpufreq_frequency_table_cpuinfo(policy,
+ per_cpu(centrino_model, policy->cpu)->op_points);
if (ret)
return (ret);
- cpufreq_frequency_table_get_attr(centrino_model[policy->cpu]->op_points, policy->cpu);
+ cpufreq_frequency_table_get_attr(
+ per_cpu(centrino_model, policy->cpu)->op_points, policy->cpu);
return 0;
}
@@ -505,12 +520,12 @@ static int centrino_cpu_exit(struct cpuf
{
unsigned int cpu = policy->cpu;
- if (!centrino_model[cpu])
+ if (!per_cpu(centrino_model, cpu))
return -ENODEV;
cpufreq_frequency_table_put_attr(cpu);
- centrino_model[cpu] = NULL;
+ per_cpu(centrino_model, cpu) = NULL;
return 0;
}
@@ -524,14 +539,16 @@ static int centrino_cpu_exit(struct cpuf
*/
static int centrino_verify (struct cpufreq_policy *policy)
{
- return cpufreq_frequency_table_verify(policy, centrino_model[policy->cpu]->op_points);
+ return cpufreq_frequency_table_verify(policy,
+ per_cpu(centrino_model, policy->cpu)->op_points);
}
/**
* centrino_setpolicy - set a new CPUFreq policy
* @policy: new policy
* @target_freq: the target frequency
- * @relation: how that frequency relates to achieved frequency (CPUFREQ_RELATION_L or CPUFREQ_RELATION_H)
+ * @relation: how that frequency relates to achieved frequency
+ * (CPUFREQ_RELATION_L or CPUFREQ_RELATION_H)
*
* Sets a new CPUFreq policy.
*/
@@ -552,21 +569,21 @@ static int centrino_target (struct cpufr
int retval = 0;
unsigned int j, k, first_cpu, tmp;
CPUMASK_ALLOC(allmasks);
- CPUMASK_VAR(online_policy_cpus, allmasks);
- CPUMASK_VAR(saved_mask, allmasks);
- CPUMASK_VAR(set_mask, allmasks);
- CPUMASK_VAR(covered_cpus, allmasks);
+ CPUMASK_PTR(online_policy_cpus, allmasks);
+ CPUMASK_PTR(saved_mask, allmasks);
+ CPUMASK_PTR(set_mask, allmasks);
+ CPUMASK_PTR(covered_cpus, allmasks);
if (unlikely(allmasks == NULL))
return -ENOMEM;
- if (unlikely(centrino_model[cpu] == NULL)) {
+ if (unlikely(per_cpu(centrino_model, cpu) == NULL)) {
retval = -ENODEV;
goto out;
}
if (unlikely(cpufreq_frequency_table_target(policy,
- centrino_model[cpu]->op_points,
+ per_cpu(centrino_model, cpu)->op_points,
target_freq,
relation,
&newstate))) {
@@ -608,7 +625,7 @@ static int centrino_target (struct cpufr
break;
}
- msr = centrino_model[cpu]->op_points[newstate].index;
+ msr = per_cpu(centrino_model, cpu)->op_points[newstate].index;
if (first_cpu) {
rdmsr(MSR_IA32_PERF_CTL, oldmsr, h);
--
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH 0/8] NR_CPUS: Various replacements for NR_CPUS
2008-07-19 1:11 [PATCH 0/8] NR_CPUS: Various replacements for NR_CPUS Mike Travis
` (7 preceding siblings ...)
2008-07-19 1:11 ` [PATCH 8/8] NR_CPUS: Replace NR_CPUS in speedstep-centrino.c Mike Travis
@ 2008-07-20 8:23 ` Ingo Molnar
2008-07-21 17:17 ` Mike Travis
8 siblings, 1 reply; 12+ messages in thread
From: Ingo Molnar @ 2008-07-20 8:23 UTC (permalink / raw)
To: Mike Travis; +Cc: Andrew Morton, H. Peter Anvin, Jack Steiner, linux-kernel
* Mike Travis <travis@sgi.com> wrote:
> I've found one old patch that seems to have been misplaced [...]
How did you notice that i missed them - actual crashes, or measurable
performance impact?
> [...] and a few minor new instances where usage of NR_CPUS may be
> incorrect.
>
> Also a fixup for CPUMASK_ALLOC is included.
applied to tip/cpus4096, thanks Mike.
Ingo
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH 0/8] NR_CPUS: Various replacements for NR_CPUS
2008-07-20 8:23 ` [PATCH 0/8] NR_CPUS: Various replacements for NR_CPUS Ingo Molnar
@ 2008-07-21 17:17 ` Mike Travis
2008-07-21 21:01 ` Mike Travis
0 siblings, 1 reply; 12+ messages in thread
From: Mike Travis @ 2008-07-21 17:17 UTC (permalink / raw)
To: Ingo Molnar; +Cc: Andrew Morton, H. Peter Anvin, Jack Steiner, linux-kernel
Ingo Molnar wrote:
> * Mike Travis <travis@sgi.com> wrote:
>
>> I've found one old patch that seems to have been misplaced [...]
>
> How did you notice that i missed them - actual crashes, or measurable
> performance impact?
It might not have been you. I was just doing a survey again of NR_CPUS
usages and noticed something that looked familiar. (In fact there were
two patches missing but when I updated the source one of them *magically*
appeared... ;-)
I have three more cases that can be changed coming real soon now.
>
>> [...] and a few minor new instances where usage of NR_CPUS may be
>> incorrect.
>>
>> Also a fixup for CPUMASK_ALLOC is included.
>
> applied to tip/cpus4096, thanks Mike.
No, no, thank you! ;-)
Mike
^ permalink raw reply [flat|nested] 12+ messages in thread