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

Commit 909ea964 authored by Christoph Lameter's avatar Christoph Lameter Committed by Tejun Heo
Browse files

core: Replace __get_cpu_var with __this_cpu_read if not used for an address.



__get_cpu_var() can be replaced with this_cpu_read and will then use a
single read instruction with implied address calculation to access the
correct per cpu instance.

However, the address of a per cpu variable passed to __this_cpu_read()
cannot be determined (since it's an implied address conversion through
segment prefixes).  Therefore apply this only to uses of __get_cpu_var
where the address of the variable is not used.

Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Hugh Dickins <hughd@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Acked-by: default avatarH. Peter Anvin <hpa@zytor.com>
Signed-off-by: default avatarChristoph Lameter <cl@linux.com>
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
parent 780f36d8
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -22,15 +22,15 @@ DECLARE_PER_CPU(struct pt_regs *, __irq_regs);

static inline struct pt_regs *get_irq_regs(void)
{
	return __get_cpu_var(__irq_regs);
	return __this_cpu_read(__irq_regs);
}

static inline struct pt_regs *set_irq_regs(struct pt_regs *new_regs)
{
	struct pt_regs *old_regs, **pp_regs = &__get_cpu_var(__irq_regs);
	struct pt_regs *old_regs;

	old_regs = *pp_regs;
	*pp_regs = new_regs;
	old_regs = __this_cpu_read(__irq_regs);
	__this_cpu_write(__irq_regs, new_regs);
	return old_regs;
}

+3 −9
Original line number Diff line number Diff line
@@ -195,15 +195,9 @@ enum {
/*
 * io context count accounting
 */
#define elv_ioc_count_mod(name, __val)				\
	do {							\
		preempt_disable();				\
		__get_cpu_var(name) += (__val);			\
		preempt_enable();				\
	} while (0)

#define elv_ioc_count_inc(name)	elv_ioc_count_mod(name, 1)
#define elv_ioc_count_dec(name)	elv_ioc_count_mod(name, -1)
#define elv_ioc_count_mod(name, __val) this_cpu_add(name, __val)
#define elv_ioc_count_inc(name)	this_cpu_inc(name)
#define elv_ioc_count_dec(name)	this_cpu_dec(name)

#define elv_ioc_count_read(name)				\
({								\
+1 −1
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ extern unsigned long long nr_context_switches(void);

#ifndef CONFIG_GENERIC_HARDIRQS
#define kstat_irqs_this_cpu(irq) \
	(kstat_this_cpu.irqs[irq])
	(this_cpu_read(kstat.irqs[irq])

struct irq_desc;

+1 −1
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ static void __unhash_process(struct task_struct *p, bool group_dead)

		list_del_rcu(&p->tasks);
		list_del_init(&p->sibling);
		__get_cpu_var(process_counts)--;
		__this_cpu_dec(process_counts);
	}
	list_del_rcu(&p->thread_group);
}
+1 −1
Original line number Diff line number Diff line
@@ -1282,7 +1282,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
			attach_pid(p, PIDTYPE_SID, task_session(current));
			list_add_tail(&p->sibling, &p->real_parent->children);
			list_add_tail_rcu(&p->tasks, &init_task.tasks);
			__get_cpu_var(process_counts)++;
			__this_cpu_inc(process_counts);
		}
		attach_pid(p, PIDTYPE_PID, pid);
		nr_threads++;
Loading