Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 65c01184 authored by Mike Travis's avatar Mike Travis Committed by Ingo Molnar
Browse files

cpumask: Replace cpumask_of_cpu with cpumask_of_cpu_ptr



  * This patch replaces the dangerous lvalue version of cpumask_of_cpu
    with new cpumask_of_cpu_ptr macros.  These are patterned after the
    node_to_cpumask_ptr macros.

    In general terms, if there is a cpumask_of_cpu_map[] then a pointer to
    the cpumask_of_cpu_map[cpu] entry is used.  The cpumask_of_cpu_map
    is provided when there is a large NR_CPUS count, reducing
    greatly the amount of code generated and stack space used for
    cpumask_of_cpu().  The pointer to the cpumask_t value is needed for
    calling set_cpus_allowed_ptr() to reduce the amount of stack space
    needed to pass the cpumask_t value.

    If there isn't a cpumask_of_cpu_map[], then a temporary variable is
    declared and filled in with value from cpumask_of_cpu(cpu) as well as
    a pointer variable pointing to this temporary variable.  Afterwards,
    the pointer is used to reference the cpumask value.  The compiler
    will optimize out the extra dereference through the pointer as well
    as the stack space used for the pointer, resulting in identical code.

    A good example of the orthogonal usages is in net/sunrpc/svc.c:

	case SVC_POOL_PERCPU:
	{
		unsigned int cpu = m->pool_to[pidx];
		cpumask_of_cpu_ptr(cpumask, cpu);

		*oldmask = current->cpus_allowed;
		set_cpus_allowed_ptr(current, cpumask);
		return 1;
	}
	case SVC_POOL_PERNODE:
	{
		unsigned int node = m->pool_to[pidx];
		node_to_cpumask_ptr(nodecpumask, node);

		*oldmask = current->cpus_allowed;
		set_cpus_allowed_ptr(current, nodecpumask);
		return 1;
	}

Signed-off-by: default avatarMike Travis <travis@sgi.com>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent bb2c018b
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ int acpi_processor_ffh_cstate_probe(unsigned int cpu,
	struct cpuinfo_x86 *c = &cpu_data(cpu);

	cpumask_t saved_mask;
	cpumask_of_cpu_ptr(new_mask, cpu);
	int retval;
	unsigned int eax, ebx, ecx, edx;
	unsigned int edx_part;
@@ -91,7 +92,7 @@ int acpi_processor_ffh_cstate_probe(unsigned int cpu,

	/* Make sure we are running on right CPU */
	saved_mask = current->cpus_allowed;
	retval = set_cpus_allowed_ptr(current, &cpumask_of_cpu(cpu));
	retval = set_cpus_allowed_ptr(current, new_mask);
	if (retval)
		return -1;

+7 −3
Original line number Diff line number Diff line
@@ -200,10 +200,12 @@ static void drv_read(struct drv_cmd *cmd)
static void drv_write(struct drv_cmd *cmd)
{
	cpumask_t saved_mask = current->cpus_allowed;
	cpumask_of_cpu_ptr_declare(cpu_mask);
	unsigned int i;

	for_each_cpu_mask_nr(i, cmd->mask) {
		set_cpus_allowed_ptr(current, &cpumask_of_cpu(i));
		cpumask_of_cpu_ptr_next(cpu_mask, i);
		set_cpus_allowed_ptr(current, cpu_mask);
		do_drv_write(cmd);
	}

@@ -267,11 +269,12 @@ static unsigned int get_measured_perf(unsigned int cpu)
	} aperf_cur, mperf_cur;

	cpumask_t saved_mask;
	cpumask_of_cpu_ptr(cpu_mask, cpu);
	unsigned int perf_percent;
	unsigned int retval;

	saved_mask = current->cpus_allowed;
	set_cpus_allowed_ptr(current, &cpumask_of_cpu(cpu));
	set_cpus_allowed_ptr(current, cpu_mask);
	if (get_cpu() != cpu) {
		/* We were not able to run on requested processor */
		put_cpu();
@@ -337,6 +340,7 @@ static unsigned int get_measured_perf(unsigned int cpu)

static unsigned int get_cur_freq_on_cpu(unsigned int cpu)
{
	cpumask_of_cpu_ptr(cpu_mask, cpu);
	struct acpi_cpufreq_data *data = per_cpu(drv_data, cpu);
	unsigned int freq;
	unsigned int cached_freq;
@@ -349,7 +353,7 @@ static unsigned int get_cur_freq_on_cpu(unsigned int cpu)
	}

	cached_freq = data->freq_table[data->acpi_data->state].frequency;
	freq = extract_freq(get_cur_val(&cpumask_of_cpu(cpu)), data);
	freq = extract_freq(get_cur_val(cpu_mask), data);
	if (freq != cached_freq) {
		/*
		 * The dreaded BIOS frequency change behind our back.
+10 −5
Original line number Diff line number Diff line
@@ -479,11 +479,12 @@ static int core_voltage_post_transition(struct powernow_k8_data *data, u32 reqvi
static int check_supported_cpu(unsigned int cpu)
{
	cpumask_t oldmask;
	cpumask_of_cpu_ptr(cpu_mask, cpu);
	u32 eax, ebx, ecx, edx;
	unsigned int rc = 0;

	oldmask = current->cpus_allowed;
	set_cpus_allowed_ptr(current, &cpumask_of_cpu(cpu));
	set_cpus_allowed_ptr(current, cpu_mask);

	if (smp_processor_id() != cpu) {
		printk(KERN_ERR PFX "limiting to cpu %u failed\n", cpu);
@@ -1016,6 +1017,7 @@ static int transition_frequency_pstate(struct powernow_k8_data *data, unsigned i
static int powernowk8_target(struct cpufreq_policy *pol, unsigned targfreq, unsigned relation)
{
	cpumask_t oldmask;
	cpumask_of_cpu_ptr(cpu_mask, pol->cpu);
	struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu);
	u32 checkfid;
	u32 checkvid;
@@ -1030,7 +1032,7 @@ static int powernowk8_target(struct cpufreq_policy *pol, unsigned targfreq, unsi

	/* only run on specific CPU from here on */
	oldmask = current->cpus_allowed;
	set_cpus_allowed_ptr(current, &cpumask_of_cpu(pol->cpu));
	set_cpus_allowed_ptr(current, cpu_mask);

	if (smp_processor_id() != pol->cpu) {
		printk(KERN_ERR PFX "limiting to cpu %u failed\n", pol->cpu);
@@ -1105,6 +1107,7 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol)
{
	struct powernow_k8_data *data;
	cpumask_t oldmask;
	cpumask_of_cpu_ptr_declare(newmask);
	int rc;

	if (!cpu_online(pol->cpu))
@@ -1156,7 +1159,8 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol)

	/* only run on specific CPU from here on */
	oldmask = current->cpus_allowed;
	set_cpus_allowed_ptr(current, &cpumask_of_cpu(pol->cpu));
	cpumask_of_cpu_ptr_next(newmask, pol->cpu);
	set_cpus_allowed_ptr(current, newmask);

	if (smp_processor_id() != pol->cpu) {
		printk(KERN_ERR PFX "limiting to cpu %u failed\n", pol->cpu);
@@ -1178,7 +1182,7 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol)
	set_cpus_allowed_ptr(current, &oldmask);

	if (cpu_family == CPU_HW_PSTATE)
		pol->cpus = cpumask_of_cpu(pol->cpu);
		pol->cpus = *newmask;
	else
		pol->cpus = per_cpu(cpu_core_map, pol->cpu);
	data->available_cores = &(pol->cpus);
@@ -1244,6 +1248,7 @@ static unsigned int powernowk8_get (unsigned int cpu)
{
	struct powernow_k8_data *data;
	cpumask_t oldmask = current->cpus_allowed;
	cpumask_of_cpu_ptr(newmask, cpu);
	unsigned int khz = 0;
	unsigned int first;

@@ -1253,7 +1258,7 @@ static unsigned int powernowk8_get (unsigned int cpu)
	if (!data)
		return -EINVAL;

	set_cpus_allowed_ptr(current, &cpumask_of_cpu(cpu));
	set_cpus_allowed_ptr(current, newmask);
	if (smp_processor_id() != cpu) {
		printk(KERN_ERR PFX
			"limiting to CPU %d failed in powernowk8_get\n", cpu);
+6 −3
Original line number Diff line number Diff line
@@ -313,9 +313,10 @@ static unsigned int get_cur_freq(unsigned int cpu)
	unsigned l, h;
	unsigned clock_freq;
	cpumask_t saved_mask;
	cpumask_of_cpu_ptr(new_mask, cpu);

	saved_mask = current->cpus_allowed;
	set_cpus_allowed_ptr(current, &cpumask_of_cpu(cpu));
	set_cpus_allowed_ptr(current, new_mask);
	if (smp_processor_id() != cpu)
		return 0;

@@ -554,9 +555,11 @@ static int centrino_target (struct cpufreq_policy *policy,
		 */

		if (!cpus_empty(covered_cpus)) {
			cpumask_of_cpu_ptr_declare(new_mask);

			for_each_cpu_mask_nr(j, covered_cpus) {
				set_cpus_allowed_ptr(current,
						     &cpumask_of_cpu(j));
				cpumask_of_cpu_ptr_next(new_mask, j);
				set_cpus_allowed_ptr(current, new_mask);
				wrmsr(MSR_IA32_PERF_CTL, oldmsr, h);
			}
		}
+2 −1
Original line number Diff line number Diff line
@@ -244,7 +244,8 @@ static unsigned int _speedstep_get(const cpumask_t *cpus)

static unsigned int speedstep_get(unsigned int cpu)
{
	return _speedstep_get(&cpumask_of_cpu(cpu));
	cpumask_of_cpu_ptr(newmask, cpu);
	return _speedstep_get(newmask);
}

/**
Loading