Skip to content

Commit

Permalink
x86: convert cpuinfo_x86 array to a per_cpu array
Browse files Browse the repository at this point in the history
cpu_data is currently an array defined using NR_CPUS.  This means that
we overallocate since we will rarely really use maximum configured cpus.
When NR_CPU count is raised to 4096 the size of cpu_data becomes
3,145,728 bytes.

These changes were adopted from the sparc64 (and ia64) code.  An
additional field was added to cpuinfo_x86 to be a non-ambiguous cpu
index.  This corresponds to the index into a cpumask_t as well as the
per_cpu index.  It's used in various places like show_cpuinfo().

cpu_data is defined to be the boot_cpu_data structure for the NON-SMP
case.

Signed-off-by: Mike Travis <travis@sgi.com>
Acked-by: Christoph Lameter <clameter@sgi.com>
Cc: Andi Kleen <ak@suse.de>
Cc: James Bottomley <James.Bottomley@steeleye.com>
Cc: Dmitry Torokhov <dtor@mail.ru>
Cc: "Antonino A. Daplas" <adaplas@pol.net>
Cc: Mark M. Hoffman <mhoffman@lightlink.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
  • Loading branch information
Mike Travis authored and Thomas Gleixner committed Oct 19, 2007
1 parent f1df280 commit 92cb761
Show file tree
Hide file tree
Showing 39 changed files with 148 additions and 128 deletions.
4 changes: 2 additions & 2 deletions arch/x86/kernel/acpi/cstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
void acpi_processor_power_init_bm_check(struct acpi_processor_flags *flags,
unsigned int cpu)
{
struct cpuinfo_x86 *c = cpu_data + cpu;
struct cpuinfo_x86 *c = &cpu_data(cpu);

flags->bm_check = 0;
if (num_online_cpus() == 1)
Expand Down Expand Up @@ -72,7 +72,7 @@ int acpi_processor_ffh_cstate_probe(unsigned int cpu,
struct acpi_processor_cx *cx, struct acpi_power_register *reg)
{
struct cstate_entry *percpu_entry;
struct cpuinfo_x86 *c = cpu_data + cpu;
struct cpuinfo_x86 *c = &cpu_data(cpu);

cpumask_t saved_mask;
int retval;
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/acpi/processor.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static void init_intel_pdc(struct acpi_processor *pr, struct cpuinfo_x86 *c)
void arch_acpi_processor_init_pdc(struct acpi_processor *pr)
{
unsigned int cpu = pr->id;
struct cpuinfo_x86 *c = cpu_data + cpu;
struct cpuinfo_x86 *c = &cpu_data(cpu);

pr->pdc = NULL;
if (c->x86_vendor == X86_VENDOR_INTEL)
Expand Down
6 changes: 3 additions & 3 deletions arch/x86/kernel/alternative.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,14 +357,14 @@ void alternatives_smp_switch(int smp)
if (smp) {
printk(KERN_INFO "SMP alternatives: switching to SMP code\n");
clear_bit(X86_FEATURE_UP, boot_cpu_data.x86_capability);
clear_bit(X86_FEATURE_UP, cpu_data[0].x86_capability);
clear_bit(X86_FEATURE_UP, cpu_data(0).x86_capability);
list_for_each_entry(mod, &smp_alt_modules, next)
alternatives_smp_lock(mod->locks, mod->locks_end,
mod->text, mod->text_end);
} else {
printk(KERN_INFO "SMP alternatives: switching to UP code\n");
set_bit(X86_FEATURE_UP, boot_cpu_data.x86_capability);
set_bit(X86_FEATURE_UP, cpu_data[0].x86_capability);
set_bit(X86_FEATURE_UP, cpu_data(0).x86_capability);
list_for_each_entry(mod, &smp_alt_modules, next)
alternatives_smp_unlock(mod->locks, mod->locks_end,
mod->text, mod->text_end);
Expand Down Expand Up @@ -432,7 +432,7 @@ void __init alternative_instructions(void)
if (1 == num_possible_cpus()) {
printk(KERN_INFO "SMP alternatives: switching to UP code\n");
set_bit(X86_FEATURE_UP, boot_cpu_data.x86_capability);
set_bit(X86_FEATURE_UP, cpu_data[0].x86_capability);
set_bit(X86_FEATURE_UP, cpu_data(0).x86_capability);
alternatives_smp_unlock(__smp_locks, __smp_locks_end,
_text, _etext);
}
Expand Down
4 changes: 2 additions & 2 deletions arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static unsigned int acpi_pstate_strict;

static int check_est_cpu(unsigned int cpuid)
{
struct cpuinfo_x86 *cpu = &cpu_data[cpuid];
struct cpuinfo_x86 *cpu = &cpu_data(cpuid);

if (cpu->x86_vendor != X86_VENDOR_INTEL ||
!cpu_has(cpu, X86_FEATURE_EST))
Expand Down Expand Up @@ -560,7 +560,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
unsigned int cpu = policy->cpu;
struct acpi_cpufreq_data *data;
unsigned int result = 0;
struct cpuinfo_x86 *c = &cpu_data[policy->cpu];
struct cpuinfo_x86 *c = &cpu_data(policy->cpu);
struct acpi_processor_performance *perf;

dprintk("acpi_cpufreq_cpu_init\n");
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/cpu/cpufreq/e_powersaver.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ static struct cpufreq_driver eps_driver = {

static int __init eps_init(void)
{
struct cpuinfo_x86 *c = cpu_data;
struct cpuinfo_x86 *c = &cpu_data(0);

/* This driver will work only on Centaur C7 processors with
* Enhanced SpeedStep/PowerSaver registers */
Expand Down
4 changes: 2 additions & 2 deletions arch/x86/kernel/cpu/cpufreq/elanfreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ static int elanfreq_target (struct cpufreq_policy *policy,

static int elanfreq_cpu_init(struct cpufreq_policy *policy)
{
struct cpuinfo_x86 *c = cpu_data;
struct cpuinfo_x86 *c = &cpu_data(0);
unsigned int i;
int result;

Expand Down Expand Up @@ -280,7 +280,7 @@ static struct cpufreq_driver elanfreq_driver = {

static int __init elanfreq_init(void)
{
struct cpuinfo_x86 *c = cpu_data;
struct cpuinfo_x86 *c = &cpu_data(0);

/* Test if we have the right hardware */
if ((c->x86_vendor != X86_VENDOR_AMD) ||
Expand Down
4 changes: 2 additions & 2 deletions arch/x86/kernel/cpu/cpufreq/longhaul.c
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ static int longhaul_setup_southbridge(void)

static int __init longhaul_cpu_init(struct cpufreq_policy *policy)
{
struct cpuinfo_x86 *c = cpu_data;
struct cpuinfo_x86 *c = &cpu_data(0);
char *cpuname=NULL;
int ret;
u32 lo, hi;
Expand Down Expand Up @@ -959,7 +959,7 @@ static struct cpufreq_driver longhaul_driver = {

static int __init longhaul_init(void)
{
struct cpuinfo_x86 *c = cpu_data;
struct cpuinfo_x86 *c = &cpu_data(0);

if (c->x86_vendor != X86_VENDOR_CENTAUR || c->x86 != 6)
return -ENODEV;
Expand Down
4 changes: 2 additions & 2 deletions arch/x86/kernel/cpu/cpufreq/longrun.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ static unsigned int __init longrun_determine_freqs(unsigned int *low_freq,
u32 save_lo, save_hi;
u32 eax, ebx, ecx, edx;
u32 try_hi;
struct cpuinfo_x86 *c = cpu_data;
struct cpuinfo_x86 *c = &cpu_data(0);

if (!low_freq || !high_freq)
return -EINVAL;
Expand Down Expand Up @@ -298,7 +298,7 @@ static struct cpufreq_driver longrun_driver = {
*/
static int __init longrun_init(void)
{
struct cpuinfo_x86 *c = cpu_data;
struct cpuinfo_x86 *c = &cpu_data(0);

if (c->x86_vendor != X86_VENDOR_TRANSMETA ||
!cpu_has(c, X86_FEATURE_LONGRUN))
Expand Down
4 changes: 2 additions & 2 deletions arch/x86/kernel/cpu/cpufreq/p4-clockmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)

static int cpufreq_p4_cpu_init(struct cpufreq_policy *policy)
{
struct cpuinfo_x86 *c = &cpu_data[policy->cpu];
struct cpuinfo_x86 *c = &cpu_data(policy->cpu);
int cpuid = 0;
unsigned int i;

Expand Down Expand Up @@ -279,7 +279,7 @@ static struct cpufreq_driver p4clockmod_driver = {

static int __init cpufreq_p4_init(void)
{
struct cpuinfo_x86 *c = cpu_data;
struct cpuinfo_x86 *c = &cpu_data(0);
int ret;

/*
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/cpu/cpufreq/powernow-k6.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ static struct cpufreq_driver powernow_k6_driver = {
*/
static int __init powernow_k6_init(void)
{
struct cpuinfo_x86 *c = cpu_data;
struct cpuinfo_x86 *c = &cpu_data(0);

if ((c->x86_vendor != X86_VENDOR_AMD) || (c->x86 != 5) ||
((c->x86_model != 12) && (c->x86_model != 13)))
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/cpu/cpufreq/powernow-k7.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static int check_fsb(unsigned int fsbspeed)

static int check_powernow(void)
{
struct cpuinfo_x86 *c = cpu_data;
struct cpuinfo_x86 *c = &cpu_data(0);
unsigned int maxei, eax, ebx, ecx, edx;

if ((c->x86_vendor != X86_VENDOR_AMD) || (c->x86 !=6)) {
Expand Down
4 changes: 2 additions & 2 deletions arch/x86/kernel/cpu/cpufreq/sc520_freq.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ static int sc520_freq_target (struct cpufreq_policy *policy,

static int sc520_freq_cpu_init(struct cpufreq_policy *policy)
{
struct cpuinfo_x86 *c = cpu_data;
struct cpuinfo_x86 *c = &cpu_data(0);
int result;

/* capability check */
Expand Down Expand Up @@ -151,7 +151,7 @@ static struct cpufreq_driver sc520_freq_driver = {

static int __init sc520_freq_init(void)
{
struct cpuinfo_x86 *c = cpu_data;
struct cpuinfo_x86 *c = &cpu_data(0);
int err;

/* Test if we have the right hardware */
Expand Down
6 changes: 3 additions & 3 deletions arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ static struct cpu_model models[] =

static int centrino_cpu_init_table(struct cpufreq_policy *policy)
{
struct cpuinfo_x86 *cpu = &cpu_data[policy->cpu];
struct cpuinfo_x86 *cpu = &cpu_data(policy->cpu);
struct cpu_model *model;

for(model = models; model->cpu_id != NULL; model++)
Expand Down Expand Up @@ -340,7 +340,7 @@ static unsigned int get_cur_freq(unsigned int cpu)

static int centrino_cpu_init(struct cpufreq_policy *policy)
{
struct cpuinfo_x86 *cpu = &cpu_data[policy->cpu];
struct cpuinfo_x86 *cpu = &cpu_data(policy->cpu);
unsigned freq;
unsigned l, h;
int ret;
Expand Down Expand Up @@ -612,7 +612,7 @@ static struct cpufreq_driver centrino_driver = {
*/
static int __init centrino_init(void)
{
struct cpuinfo_x86 *cpu = cpu_data;
struct cpuinfo_x86 *cpu = &cpu_data(0);

if (!cpu_has(cpu, X86_FEATURE_EST))
return -ENODEV;
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/cpu/cpufreq/speedstep-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ EXPORT_SYMBOL_GPL(speedstep_get_processor_frequency);

unsigned int speedstep_detect_processor (void)
{
struct cpuinfo_x86 *c = cpu_data;
struct cpuinfo_x86 *c = &cpu_data(0);
u32 ebx, msr_lo, msr_hi;

dprintk("x86: %x, model: %x\n", c->x86, c->x86_model);
Expand Down
8 changes: 4 additions & 4 deletions arch/x86/kernel/cpu/intel_cacheinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ unsigned int __cpuinit init_intel_cacheinfo(struct cpuinfo_x86 *c)
unsigned int new_l2 = 0, new_l3 = 0, i; /* Cache sizes from cpuid(4) */
unsigned int l2_id = 0, l3_id = 0, num_threads_sharing, index_msb;
#ifdef CONFIG_X86_HT
unsigned int cpu = (c == &boot_cpu_data) ? 0 : (c - cpu_data);
unsigned int cpu = c->cpu_index;
#endif

if (c->cpuid_level > 3) {
Expand Down Expand Up @@ -459,7 +459,7 @@ static void __cpuinit cache_shared_cpu_map_setup(unsigned int cpu, int index)
struct _cpuid4_info *this_leaf, *sibling_leaf;
unsigned long num_threads_sharing;
int index_msb, i;
struct cpuinfo_x86 *c = cpu_data;
struct cpuinfo_x86 *c = &cpu_data(cpu);

this_leaf = CPUID4_INFO_IDX(cpu, index);
num_threads_sharing = 1 + this_leaf->eax.split.num_threads_sharing;
Expand All @@ -470,8 +470,8 @@ static void __cpuinit cache_shared_cpu_map_setup(unsigned int cpu, int index)
index_msb = get_count_order(num_threads_sharing);

for_each_online_cpu(i) {
if (c[i].apicid >> index_msb ==
c[cpu].apicid >> index_msb) {
if (cpu_data(i).apicid >> index_msb ==
c->apicid >> index_msb) {
cpu_set(i, this_leaf->shared_cpu_map);
if (i != cpu && cpuid4_info[i]) {
sibling_leaf = CPUID4_INFO_IDX(i, index);
Expand Down
11 changes: 8 additions & 3 deletions arch/x86/kernel/cpu/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,13 @@ static int show_cpuinfo(struct seq_file *m, void *v)
/* nothing */
};
struct cpuinfo_x86 *c = v;
int i, n = c - cpu_data;
int i, n = 0;
int fpu_exception;

#ifdef CONFIG_SMP
if (!cpu_online(n))
return 0;
n = c->cpu_index;
#endif
seq_printf(m, "processor\t: %d\n"
"vendor_id\t: %s\n"
Expand Down Expand Up @@ -175,11 +176,15 @@ static int show_cpuinfo(struct seq_file *m, void *v)

static void *c_start(struct seq_file *m, loff_t *pos)
{
return *pos < NR_CPUS ? cpu_data + *pos : NULL;
if (*pos == 0) /* just in case, cpu 0 is not the first */
*pos = first_cpu(cpu_possible_map);
if ((*pos) < NR_CPUS && cpu_possible(*pos))
return &cpu_data(*pos);
return NULL;
}
static void *c_next(struct seq_file *m, void *v, loff_t *pos)
{
++*pos;
*pos = next_cpu(*pos, cpu_possible_map);
return c_start(m, pos);
}
static void c_stop(struct seq_file *m, void *v)
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/cpuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static ssize_t cpuid_read(struct file *file, char __user *buf,
static int cpuid_open(struct inode *inode, struct file *file)
{
unsigned int cpu = iminor(file->f_path.dentry->d_inode);
struct cpuinfo_x86 *c = &(cpu_data)[cpu];
struct cpuinfo_x86 *c = &cpu_data(cpu);

if (cpu >= NR_CPUS || !cpu_online(cpu))
return -ENXIO; /* No such CPU */
Expand Down
3 changes: 2 additions & 1 deletion arch/x86/kernel/mce_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,8 @@ static __cpuinit int mce_create_device(unsigned int cpu)
{
int err;
int i;
if (!mce_available(&cpu_data[cpu]))

if (!mce_available(&cpu_data(cpu)))
return -EIO;

memset(&per_cpu(device_mce, cpu).kobj, 0, sizeof(struct kobject));
Expand Down
4 changes: 2 additions & 2 deletions arch/x86/kernel/mce_amd_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,11 +472,11 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank)
sprintf(name, "threshold_bank%i", bank);

#ifdef CONFIG_SMP
if (cpu_data[cpu].cpu_core_id && shared_bank[bank]) { /* symlink */
if (cpu_data(cpu).cpu_core_id && shared_bank[bank]) { /* symlink */
i = first_cpu(per_cpu(cpu_core_map, cpu));

/* first core not up yet */
if (cpu_data[i].cpu_core_id)
if (cpu_data(i).cpu_core_id)
goto out;

/* already linked */
Expand Down
6 changes: 3 additions & 3 deletions arch/x86/kernel/microcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ static struct ucode_cpu_info {

static void collect_cpu_info(int cpu_num)
{
struct cpuinfo_x86 *c = cpu_data + cpu_num;
struct cpuinfo_x86 *c = &cpu_data(cpu_num);
struct ucode_cpu_info *uci = ucode_cpu_info + cpu_num;
unsigned int val[2];

Expand Down Expand Up @@ -522,7 +522,7 @@ static struct platform_device *microcode_pdev;
static int cpu_request_microcode(int cpu)
{
char name[30];
struct cpuinfo_x86 *c = cpu_data + cpu;
struct cpuinfo_x86 *c = &cpu_data(cpu);
const struct firmware *firmware;
void *buf;
unsigned long size;
Expand Down Expand Up @@ -570,7 +570,7 @@ static int cpu_request_microcode(int cpu)

static int apply_microcode_check_cpu(int cpu)
{
struct cpuinfo_x86 *c = cpu_data + cpu;
struct cpuinfo_x86 *c = &cpu_data(cpu);
struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
cpumask_t old;
unsigned int val[2];
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/msr.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
static int msr_open(struct inode *inode, struct file *file)
{
unsigned int cpu = iminor(file->f_path.dentry->d_inode);
struct cpuinfo_x86 *c = &(cpu_data)[cpu];
struct cpuinfo_x86 *c = &cpu_data(cpu);

if (cpu >= NR_CPUS || !cpu_online(cpu))
return -ENXIO; /* No such CPU */
Expand Down
Loading

0 comments on commit 92cb761

Please sign in to comment.