[PATCH 0/8] NR_CPUS: Various replacements for NR_CPUS - Kernel

This is a discussion on [PATCH 0/8] NR_CPUS: Various replacements for NR_CPUS - Kernel ; I've found one old patch that seems to have been misplaced and a few minor new instances where usage of NR_CPUS may be incorrect. Also a fixup for CPUMASK_ALLOC is included. Signed-off-by: Mike Travis --- -- -- To unsubscribe from ...

+ Reply to Thread
Results 1 to 8 of 8

Thread: [PATCH 0/8] NR_CPUS: Various replacements for NR_CPUS

  1. [PATCH 0/8] NR_CPUS: Various replacements for NR_CPUS


    I've found one old patch that seems to have been misplaced and
    a few minor new instances where usage of NR_CPUS may be incorrect.

    Also a fixup for CPUMASK_ALLOC is included.

    Signed-off-by: Mike Travis
    ---

    --
    --
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

  2. [PATCH 4/8] NR_CPUS: Replace NR_CPUS in arch/x86/kernel/genapic_flat_64.c

    * 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
    Cc: Andi Kleen
    ---
    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;

    --
    --
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

  3. [PATCH 5/8] NR_CPUS: Replace per_cpu(..., smp_processor_id()) with __get_cpu_var

    * Slight optimization when getting one's own cpu_info percpu data.

    Applies to both tip/master and linux-next.

    Signed-off-by: Mike Travis
    ---
    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

    --
    --
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

  4. [PATCH 1/8] NR_CPUS: Replace NR_CPUS in arch/x86/kernel/cpu/mcheck/mce_64.c

    * 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
    Cc: Cc: Eric W. Biederman
    ---
    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;


    --
    --
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

  5. [PATCH 6/8] NR_CPUS: Replace NR_CPUS in cpufreq userspace routines

    * 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
    Date: 2008-02-08 23:37:39

    Applies to both tip/master and linux-next.

    Signed-off-by: Mike Travis
    Cc: Jason Baron
    Cc: Dave Jones
    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;
    }

    --
    --
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

  6. Re: [PATCH 0/8] NR_CPUS: Various replacements for NR_CPUS


    * Mike Travis 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
    --
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

  7. Re: [PATCH 0/8] NR_CPUS: Various replacements for NR_CPUS

    Ingo Molnar wrote:
    > * Mike Travis 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
    --
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

  8. Re: [PATCH 0/8] NR_CPUS: Various replacements for NR_CPUS

    Mike Travis wrote:
    ....
    > I have three more cases that can be changed coming real soon now.


    Turns out the changes I was going to make are in linux-next already.

    Thanks,
    Mike
    --
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

+ Reply to Thread