replace percpu_ops function with this_cpu_ops
Subsystems (7)
cover replace percpu_ops function with this_cpu_ops
I am sorry for mess commit log previous patchset.
As Andrew Morton's request, I combind and clean up the patchset.
According to Ingo's complain. I use the same and short 'this_cpu_ops' functions in x86 part code.
Thanks for all comments!
[PATCH 1/3] net: replace percpu_xxx funcs with this_cpu_xxx or [PATCH 2/3] x86: replace percpu_xxx funcs with this_cpu_xxx [PATCH 3/3] percpu: remove percpu_xxx() functions
PATCH 1/3 net: replace percpu_xxx funcs with this_cpu_xxx or __this_cpu_xxx
percpu_xxx funcs are duplicated with this_cpu_xxx funcs, so replace them for further code clean up.
And in preempt safe scenario, __this_cpu_xxx funcs may has a bit better performance since __this_cpu_xxx has no redundant preempt_enable/preempt_disable on some architectures.
--- net/netfilter/xt_TEE.c | 12 ++++++------ net/socket.c | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-)
net/netfilter/xt_TEE.c +6 -6
@@ -87,7 +87,7 @@ tee_tg4(struct sk_buff *skb, const struct xt_action_param *par)const struct xt_tee_tginfo *info = par->targinfo;struct iphdr *iph; -if (percpu_read (tee_active)) +if (__this_cpu_read (tee_active))return XT_CONTINUE ;/* * Copy the skb, and route the copy. Will later return %XT_CONTINUE for
@@ -124,9 +124,9 @@ tee_tg4(struct sk_buff *skb, const struct xt_action_param *par)ip_send_check (iph);if (tee_tg_route4 (skb, info)) { -percpu_write (tee_active, true); +__this_cpu_write (tee_active, true);ip_local_out (skb); -percpu_write (tee_active, false); +__this_cpu_write (tee_active, false); }else {kfree_skb (skb); }
@@ -168,7 +168,7 @@ tee_tg6(struct sk_buff *skb, const struct xt_action_param *par) {const struct xt_tee_tginfo *info = par->targinfo; -if (percpu_read (tee_active)) +if (__this_cpu_read (tee_active))return XT_CONTINUE ; skb =pskb_copy (skb,GFP_ATOMIC );if (skb ==NULL )
@@ -186,9 +186,9 @@ tee_tg6(struct sk_buff *skb, const struct xt_action_param *par) --iph->hop_limit; }if (tee_tg_route6 (skb, info)) { -percpu_write (tee_active, true); +__this_cpu_write (tee_active, true);ip6_local_out (skb); -percpu_write (tee_active, false); +__this_cpu_write (tee_active, false); }else {kfree_skb (skb); }
net/socket.c +2 -2
@@ -479,7 +479,7 @@ static struct socket *sock_alloc(void) inode->i_uid =current_fsuid (); inode->i_gid =current_fsgid (); -percpu_add (sockets_in_use,1 ); +this_cpu_add (sockets_in_use,1 );return sock; }
@@ -522,7 +522,7 @@ void sock_release(struct socket *sock)if (rcu_dereference_protected (sock->wq,1 )->fasync_list)printk (KERN_ERR "sock_release: fasync list not empty!\n" ); -percpu_sub (sockets_in_use,1 ); +this_cpu_sub (sockets_in_use,1 );if (!sock->file) {iput (SOCK_INODE (sock));return ;
Signature · 1 line
1.7.5.4
PATCH 2/3 x86: replace percpu_xxx funcs with this_cpu_xxx
In reply to Alex ShiSince percpu_xxx() serial functions are duplicated with this_cpu_xxx(). Removing percpu_xxx() definition and replacing them by this_cpu_xxx() in code. There is no function change in this patch, just preparation for later percpu_xxx serial function removing.
On x86 machine the this_cpu_xxx() serial functions are same as __this_cpu_xxx() without no unnecessary premmpt enable/disable.
Thanks for Stephen Rothwell, he found and fixed a i386 build error in the patch.
Also thanks for Andrew Morton, he kept updating the patchset in Linus' tree.
--- arch/x86/include/asm/compat.h | 2 +- arch/x86/include/asm/current.h | 2 +- arch/x86/include/asm/desc.h | 1 + arch/x86/include/asm/fpu-internal.h | 6 +++--- arch/x86/include/asm/hardirq.h | 9 +++++---- arch/x86/include/asm/irq_regs.h | 4 ++-- arch/x86/include/asm/mmu_context.h | 12 ++++++------ arch/x86/include/asm/percpu.h | 8 ++++---- arch/x86/include/asm/smp.h | 4 ++-- arch/x86/include/asm/stackprotector.h | 4 ++-- arch/x86/include/asm/thread_info.h | 2 +- arch/x86/include/asm/tlbflush.h | 4 ++-- arch/x86/kernel/cpu/common.c | 2 +- arch/x86/kernel/cpu/mcheck/mce.c | 4 ++-- arch/x86/kernel/i387.c | 2 +- arch/x86/kernel/nmi_selftest.c | 1 + arch/x86/kernel/paravirt.c | 12 ++++++------ arch/x86/kernel/process.c | 2 +- arch/x86/kernel/process_32.c | 2 +- arch/x86/kernel/process_64.c | 10 +++++----- arch/x86/mm/tlb.c | 10 +++++----- include/linux/topology.h | 4 ++-- 22 files changed, 55 insertions(+), 52 deletions(-)
arch/x86/include/asm/compat.h +1 -1
@@ -229,7 +229,7 @@ static inline void __user *arch_compat_alloc_user_space(long len) sp =task_pt_regs (current)->sp; }else {/* -128 for the x32 ABI redzone */ - sp =percpu_read (old_rsp) -128 ; + sp =__this_cpu_read (old_rsp) -128 ; }return (void __user *)round_down (sp - len,16 );
arch/x86/include/asm/current.h +1 -1
@@ -11,7 +11,7 @@ DECLARE_PER_CPU(struct task_struct *, current_task); static __always_inline struct task_struct *get_current(void) { -return percpu_read_stable (current_task); +return this_cpu_read_stable (current_task); }#define current get_current()
arch/x86/include/asm/desc.h +1 -0
@@ -6,6 +6,7 @@#include <asm/mmu.h> #include <linux/smp.h> +#include <linux/percpu.h> static inline void fill_ldt (struct desc_struct *desc,const struct user_desc *info) {
arch/x86/include/asm/fpu-internal.h +3 -3
@@ -290,14 +290,14 @@ static inline int __thread_has_fpu(struct task_struct *tsk)static inline void __thread_clear_has_fpu (struct task_struct *tsk) { tsk->thread.fpu.has_fpu =0 ; -percpu_write (fpu_owner_task,NULL ); +this_cpu_write (fpu_owner_task,NULL ); }/* Must be paired with a 'clts' before! */ static inline void __thread_set_has_fpu (struct task_struct *tsk) { tsk->thread.fpu.has_fpu =1 ; -percpu_write (fpu_owner_task, tsk); +this_cpu_write (fpu_owner_task, tsk); }/*
@@ -344,7 +344,7 @@ typedef struct { int preload; } fpu_switch_t;*/ static inline int fpu_lazy_restore (struct task_struct *new,unsigned int cpu) { -return new ==percpu_read_stable (fpu_owner_task) && +return new ==this_cpu_read_stable (fpu_owner_task) && cpu == new->thread.fpu.last_cpu; }
arch/x86/include/asm/hardirq.h +5 -4
@@ -35,14 +35,15 @@ DECLARE_PER_CPU_SHARED_ALIGNED(irq_cpustat_t, irq_stat);#define __ARCH_IRQ_STAT -#define inc_irq_stat (member) percpu_inc(irq_stat.member) +#define inc_irq_stat (member) this_cpu_inc(irq_stat.member) -#define local_softirq_pending () percpu_read(irq_stat.__softirq_pending) +#define local_softirq_pending () this_cpu_read(irq_stat.__softirq_pending)#define __ARCH_SET_SOFTIRQ_PENDING -#define set_softirq_pending (x) percpu_write(irq_stat.__softirq_pending, (x)) -#define or_softirq_pending (x) percpu_or(irq_stat.__softirq_pending, (x)) +#define set_softirq_pending (x) \ + this_cpu_write(irq_stat.__softirq_pending, (x)) +#define or_softirq_pending (x) this_cpu_or(irq_stat.__softirq_pending, (x))extern void ack_bad_irq (unsigned int irq);
arch/x86/include/asm/irq_regs.h +2 -2
@@ -15,7 +15,7 @@ DECLARE_PER_CPU(struct pt_regs *, irq_regs);static inline struct pt_regs *get_irq_regs (void ) { -return percpu_read (irq_regs); +return this_cpu_read (irq_regs); }static inline struct pt_regs *set_irq_regs (struct pt_regs *new_regs)
@@ -23,7 +23,7 @@ static inline struct pt_regs *set_irq_regs(struct pt_regs *new_regs)struct pt_regs *old_regs; old_regs =get_irq_regs (); -percpu_write (irq_regs, new_regs); +this_cpu_write (irq_regs, new_regs);return old_regs; }
arch/x86/include/asm/mmu_context.h +6 -6
@@ -25,8 +25,8 @@ void destroy_context(struct mm_struct *mm);static inline void enter_lazy_tlb (struct mm_struct *mm,struct task_struct *tsk) {#ifdef CONFIG_SMP -if (percpu_read (cpu_tlbstate.state) ==TLBSTATE_OK ) -percpu_write (cpu_tlbstate.state,TLBSTATE_LAZY ); +if (this_cpu_read (cpu_tlbstate.state) ==TLBSTATE_OK ) +this_cpu_write (cpu_tlbstate.state,TLBSTATE_LAZY );#endif }
@@ -37,8 +37,8 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,if (likely (prev != next)) {#ifdef CONFIG_SMP -percpu_write (cpu_tlbstate.state,TLBSTATE_OK ); -percpu_write (cpu_tlbstate.active_mm, next); +this_cpu_write (cpu_tlbstate.state,TLBSTATE_OK ); +this_cpu_write (cpu_tlbstate.active_mm, next);#endif cpumask_set_cpu (cpu,mm_cpumask (next));
@@ -56,8 +56,8 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next, }#ifdef CONFIG_SMP else { -percpu_write (cpu_tlbstate.state,TLBSTATE_OK ); -BUG_ON (percpu_read (cpu_tlbstate.active_mm) != next); +this_cpu_write (cpu_tlbstate.state,TLBSTATE_OK ); +BUG_ON (this_cpu_read (cpu_tlbstate.active_mm) != next);if (!cpumask_test_and_set_cpu (cpu,mm_cpumask (next))) {/* We were in lazy tlb mode and leave_mm disabled
arch/x86/include/asm/percpu.h +4 -4
@@ -46,7 +46,7 @@#ifdef CONFIG_SMP #define __percpu_prefix "%%"__stringify(__percpu_seg)":" -#define __my_cpu_offset percpu_read(this_cpu_off) +#define __my_cpu_offset this_cpu_read(this_cpu_off)/* * Compared to the generic __my_cpu_offset version, the following
@@ -352,15 +352,15 @@ do { \/* * percpu_read() makes gcc load the percpu variable every time it is -* accessed while percpu_read_stable() allows the value to be cached. -* percpu_read_stable() is more efficient and can be used if its value +* accessed while this_cpu_read_stable() allows the value to be cached. +* this_cpu_read_stable() is more efficient and can be used if its value * is guaranteed to be valid across cpus. The current users include * get_current() and get_thread_info() both of which are actually * per-thread variables implemented as per-cpu variables and thus * stable for the duration of the respective task. */ #define percpu_read (var) percpu_from_op("mov", var, "m" (var)) -#define percpu_read_stable (var) percpu_from_op("mov", var, "p" (&(var))) +#define this_cpu_read_stable (var) percpu_from_op("mov", var, "p" (&(var)))#define percpu_write (var, val) percpu_to_op("mov", var, val)#define percpu_add (var, val) percpu_add_op(var, val)#define percpu_sub (var, val) percpu_add_op(var, -(val))
arch/x86/include/asm/smp.h +2 -2
@@ -188,11 +188,11 @@ extern unsigned disabled_cpus __cpuinitdata;* from the initial startup. We map APIC_BASE very early in page_setup(), * so this is correct in the x86 case. */ -#define raw_smp_processor_id () (percpu_read(cpu_number)) +#define raw_smp_processor_id () (this_cpu_read(cpu_number))extern int safe_smp_processor_id (void );#elif defined(CONFIG_X86_64_SMP ) -#define raw_smp_processor_id () (percpu_read(cpu_number)) +#define raw_smp_processor_id () (this_cpu_read(cpu_number))#define stack_smp_processor_id () \ ({ \
arch/x86/include/asm/stackprotector.h +2 -2
@@ -75,9 +75,9 @@ static __always_inline void boot_init_stack_canary(void) current->stack_canary = canary;#ifdef CONFIG_X86_64 -percpu_write (irq_stack_union.stack_canary, canary); +this_cpu_write (irq_stack_union.stack_canary, canary);#else -percpu_write (stack_canary.canary, canary); +this_cpu_write (stack_canary.canary, canary);#endif }
arch/x86/include/asm/thread_info.h +1 -1
@@ -222,7 +222,7 @@ DECLARE_PER_CPU(unsigned long, kernel_stack);static inline struct thread_info *current_thread_info (void ) {struct thread_info *ti; - ti = (void *)(percpu_read_stable (kernel_stack) + + ti = (void *)(this_cpu_read_stable (kernel_stack) +KERNEL_STACK_OFFSET -THREAD_SIZE );return ti; }
arch/x86/include/asm/tlbflush.h +2 -2
@@ -156,8 +156,8 @@ DECLARE_PER_CPU_SHARED_ALIGNED(struct tlb_state, cpu_tlbstate);static inline void reset_lazy_tlbstate (void ) { -percpu_write (cpu_tlbstate.state,0 ); -percpu_write (cpu_tlbstate.active_mm, &init_mm); +this_cpu_write (cpu_tlbstate.state,0 ); +this_cpu_write (cpu_tlbstate.active_mm, &init_mm); }#endif /* SMP */
arch/x86/kernel/cpu/common.c +1 -1
@@ -1185,7 +1185,7 @@ void __cpuinit cpu_init(void) oist = &per_cpu (orig_ist, cpu);#ifdef CONFIG_NUMA -if (cpu !=0 &&percpu_read (numa_node) ==0 && +if (cpu !=0 &&this_cpu_read (numa_node) ==0 &&early_cpu_to_node (cpu) !=NUMA_NO_NODE )set_numa_node (early_cpu_to_node (cpu));#endif
arch/x86/kernel/cpu/mcheck/mce.c +2 -2
@@ -583,7 +583,7 @@ void machine_check_poll(enum mcp_flags flags, mce_banks_t *b)struct mce m;int i; -percpu_inc (mce_poll_count); +this_cpu_inc (mce_poll_count);mce_gather_info (&m,NULL );
@@ -1015,7 +1015,7 @@ void do_machine_check(struct pt_regs *regs, long error_code)atomic_inc (&mce_entry); -percpu_inc (mce_exception_count); +this_cpu_inc (mce_exception_count);if (!banks) goto out;
arch/x86/kernel/i387.c +1 -1
@@ -88,7 +88,7 @@ void kernel_fpu_begin(void)__thread_clear_has_fpu (me);/* We do 'stts()' in kernel_fpu_end() */ }else { -percpu_write (fpu_owner_task,NULL ); +this_cpu_write (fpu_owner_task,NULL );clts (); } }
arch/x86/kernel/nmi_selftest.c +1 -0
@@ -13,6 +13,7 @@#include <linux/cpumask.h> #include <linux/delay.h> #include <linux/init.h> +#include <linux/percpu.h> #include <asm/apic.h> #include <asm/nmi.h>
arch/x86/kernel/paravirt.c +6 -6
@@ -241,16 +241,16 @@ static DEFINE_PER_CPU(enum paravirt_lazy_mode, paravirt_lazy_mode) = PARAVIRT_LAstatic inline void enter_lazy (enum paravirt_lazy_mode mode) { -BUG_ON (percpu_read (paravirt_lazy_mode) !=PARAVIRT_LAZY_NONE ); +BUG_ON (this_cpu_read (paravirt_lazy_mode) !=PARAVIRT_LAZY_NONE ); -percpu_write (paravirt_lazy_mode, mode); +this_cpu_write (paravirt_lazy_mode, mode); }static void leave_lazy (enum paravirt_lazy_mode mode) { -BUG_ON (percpu_read (paravirt_lazy_mode) != mode); +BUG_ON (this_cpu_read (paravirt_lazy_mode) != mode); -percpu_write (paravirt_lazy_mode,PARAVIRT_LAZY_NONE ); +this_cpu_write (paravirt_lazy_mode,PARAVIRT_LAZY_NONE ); }void paravirt_enter_lazy_mmu (void )
@@ -267,7 +267,7 @@ void paravirt_start_context_switch(struct task_struct *prev) {BUG_ON (preemptible ()); -if (percpu_read (paravirt_lazy_mode) ==PARAVIRT_LAZY_MMU ) { +if (this_cpu_read (paravirt_lazy_mode) ==PARAVIRT_LAZY_MMU ) {arch_leave_lazy_mmu_mode ();set_ti_thread_flag (task_thread_info (prev),TIF_LAZY_MMU_UPDATES ); }
@@ -289,7 +289,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)if (in_interrupt ())return PARAVIRT_LAZY_NONE ; -return percpu_read (paravirt_lazy_mode); +return this_cpu_read (paravirt_lazy_mode); }void arch_flush_lazy_mmu_mode (void )
arch/x86/kernel/process.c +1 -1
@@ -377,7 +377,7 @@ static inline void play_dead(void)#ifdef CONFIG_X86_64 void enter_idle (void ) { -percpu_write (is_idle,1 ); +this_cpu_write (is_idle,1 );atomic_notifier_call_chain (&idle_notifier,IDLE_START ,NULL ); }
arch/x86/kernel/process_32.c +1 -1
@@ -302,7 +302,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)switch_fpu_finish (next_p, fpu); -percpu_write (current_task, next_p); +this_cpu_write (current_task, next_p);return prev_p; }
arch/x86/kernel/process_64.c +5 -5
@@ -237,7 +237,7 @@ start_thread_common(struct pt_regs *regs, unsigned long new_ip, current->thread.usersp = new_sp; regs->ip = new_ip; regs->sp = new_sp; -percpu_write (old_rsp, new_sp); +this_cpu_write (old_rsp, new_sp); regs->cs = _cs; regs->ss = _ss; regs->flags =X86_EFLAGS_IF ;
@@ -359,11 +359,11 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)/* * Switch the PDA and FPU contexts. */ - prev->usersp =percpu_read (old_rsp); -percpu_write (old_rsp, next->usersp); -percpu_write (current_task, next_p); + prev->usersp =this_cpu_read (old_rsp); +this_cpu_write (old_rsp, next->usersp); +this_cpu_write (current_task, next_p); -percpu_write (kernel_stack, +this_cpu_write (kernel_stack, (unsigned long )task_stack_page (next_p) +THREAD_SIZE -KERNEL_STACK_OFFSET );
arch/x86/mm/tlb.c +5 -5
@@ -61,10 +61,10 @@ static DEFINE_PER_CPU_READ_MOSTLY(int, tlb_vector_offset);*/ void leave_mm (int cpu) { -if (percpu_read (cpu_tlbstate.state) ==TLBSTATE_OK ) +if (this_cpu_read (cpu_tlbstate.state) ==TLBSTATE_OK )BUG ();cpumask_clear_cpu (cpu, -mm_cpumask (percpu_read (cpu_tlbstate.active_mm))); +mm_cpumask (this_cpu_read (cpu_tlbstate.active_mm)));load_cr3 (swapper_pg_dir); }EXPORT_SYMBOL_GPL (leave_mm);
@@ -152,8 +152,8 @@ void smp_invalidate_interrupt(struct pt_regs *regs)* BUG(); */ -if (f->flush_mm ==percpu_read (cpu_tlbstate.active_mm)) { -if (percpu_read (cpu_tlbstate.state) ==TLBSTATE_OK ) { +if (f->flush_mm ==this_cpu_read (cpu_tlbstate.active_mm)) { +if (this_cpu_read (cpu_tlbstate.state) ==TLBSTATE_OK ) {if (f->flush_va ==TLB_FLUSH_ALL )local_flush_tlb ();else
@@ -322,7 +322,7 @@ void flush_tlb_page(struct vm_area_struct *vma, unsigned long va)static void do_flush_tlb_all (void *info) {__flush_tlb_all (); -if (percpu_read (cpu_tlbstate.state) ==TLBSTATE_LAZY ) +if (this_cpu_read (cpu_tlbstate.state) ==TLBSTATE_LAZY )leave_mm (smp_processor_id ()); }
include/linux/topology.h +2 -2
@@ -239,7 +239,7 @@ static inline int cpu_to_node(int cpu)#ifndef set_numa_nodestatic inline void set_numa_node (int node) { -percpu_write (numa_node, node); +this_cpu_write (numa_node, node); }#endif
@@ -274,7 +274,7 @@ DECLARE_PER_CPU(int, _numa_mem_);#ifndef set_numa_memstatic inline void set_numa_mem (int node) { -percpu_write (_numa_mem_, node); +this_cpu_write (_numa_mem_, node); }#endif
Signature · 1 line
1.7.5.4
PATCH 3/3 percpu: remove percpu_xxx() functions
In reply to Alex ShiRemove percpu_xxx serial functions, all of them were replaced by this_cpu_xxx or __this_cpu_xxx serial functions
--- arch/x86/include/asm/percpu.h | 16 ++++------- include/linux/percpu.h | 54 ----------------------------------------- 2 files changed, 6 insertions(+), 64 deletions(-)
arch/x86/include/asm/percpu.h +6 -10
@@ -351,7 +351,7 @@ do { \ })/* -* percpu_read() makes gcc load the percpu variable every time it is +* this_cpu_read() makes gcc load the percpu variable every time it is * accessed while this_cpu_read_stable() allows the value to be cached. * this_cpu_read_stable() is more efficient and can be used if its value * is guaranteed to be valid across cpus. The current users include
@@ -359,15 +359,7 @@ do { \* per-thread variables implemented as per-cpu variables and thus * stable for the duration of the respective task. */ -#define percpu_read (var) percpu_from_op("mov", var, "m" (var))#define this_cpu_read_stable (var) percpu_from_op("mov", var, "p" (&(var))) -#define percpu_write (var, val) percpu_to_op("mov", var, val) -#define percpu_add (var, val) percpu_add_op(var, val) -#define percpu_sub (var, val) percpu_add_op(var, -(val)) -#define percpu_and (var, val) percpu_to_op("and", var, val) -#define percpu_or (var, val) percpu_to_op("or", var, val) -#define percpu_xor (var, val) percpu_to_op("xor", var, val) -#define percpu_inc (var) percpu_unary_op("inc", var)#define __this_cpu_read_1 (pcp) percpu_from_op("mov", (pcp), "m"(pcp))#define __this_cpu_read_2 (pcp) percpu_from_op("mov", (pcp), "m"(pcp))
@@ -512,7 +504,11 @@ static __always_inline int x86_this_cpu_constant_test_bit(unsigned int nr, {unsigned long __percpu *a = (unsigned long *)addr + nr /BITS_PER_LONG ; -return ((1UL << (nr %BITS_PER_LONG )) &percpu_read (*a)) !=0 ; +#ifdef CONFIG_X86_64 +return ((1UL << (nr %BITS_PER_LONG )) &__this_cpu_read_8 (*a)) !=0 ; +#else +return ((1UL << (nr %BITS_PER_LONG )) &__this_cpu_read_4 (*a)) !=0 ; +#endif } static inline int x86_this_cpu_variable_test_bit(int nr,
include/linux/percpu.h +0 -54
60 lines not on this page · raw message
Signature · 1 line
1.7.5.4
Re: [PATCH 2/3] x86: replace percpu_xxx funcs with this_cpu_xxx
In reply to Alex Shiarch/x86/include/asm/compat.h static inline void __user *arch_compat_alloc_user_space(long len) · line 234
Quoted 12 lines · Alex Shi
arch/x86/include/asm/compat.h +1
-1@@ -229,7 +229,7 @@ static inline void __user *arch_compat_alloc_user_space(long len) sp =task_pt_regs (current)->sp; }else {/* -128 for the x32 ABI redzone */ - sp =percpu_read (old_rsp) -128 ; + sp =__this_cpu_read (old_rsp) -128 ; }
oh, sorry, this line is better to change as this_cpu_read(), so, update the patch
---
Quoted 1 line
From
ed2c041b7e4e76a7ad48bfcf6b9fdc32ed2b7d7eMon Sep 17 00:00:00 2001
From: Alex Shi <[email protected]>
Date: Fri, 11 May 2012 15:35:27 +0800
Subject: [PATCH 2/3] x86: replace percpu_xxx funcs with this_cpu_xxx
Since percpu_xxx() serial functions are duplicated with this_cpu_xxx(). Removing percpu_xxx() definition and replacing them by this_cpu_xxx() in code. There is no function change in this patch, just preparation for later percpu_xxx serial function removing.
On x86 machine the this_cpu_xxx() serial functions are same as __this_cpu_xxx() without no unnecessary premmpt enable/disable.
Thanks for Stephen Rothwell, he found and fixed a i386 build error in the patch.
Also thanks for Andrew Morton, he kept updating the patchset in Linus' tree.
--- arch/x86/include/asm/compat.h | 2 +- arch/x86/include/asm/current.h | 2 +- arch/x86/include/asm/desc.h | 1 + arch/x86/include/asm/fpu-internal.h | 6 +++--- arch/x86/include/asm/hardirq.h | 9 +++++---- arch/x86/include/asm/irq_regs.h | 4 ++-- arch/x86/include/asm/mmu_context.h | 12 ++++++------ arch/x86/include/asm/percpu.h | 8 ++++---- arch/x86/include/asm/smp.h | 4 ++-- arch/x86/include/asm/stackprotector.h | 4 ++-- arch/x86/include/asm/thread_info.h | 2 +- arch/x86/include/asm/tlbflush.h | 4 ++-- arch/x86/kernel/cpu/common.c | 2 +- arch/x86/kernel/cpu/mcheck/mce.c | 4 ++-- arch/x86/kernel/i387.c | 2 +- arch/x86/kernel/nmi_selftest.c | 1 + arch/x86/kernel/paravirt.c | 12 ++++++------ arch/x86/kernel/process.c | 2 +- arch/x86/kernel/process_32.c | 2 +- arch/x86/kernel/process_64.c | 10 +++++----- arch/x86/mm/tlb.c | 10 +++++----- include/linux/topology.h | 4 ++-- 22 files changed, 55 insertions(+), 52 deletions(-)
arch/x86/include/asm/compat.h +1 -1
@@ -229,7 +229,7 @@ static inline void __user *arch_compat_alloc_user_space(long len) sp =task_pt_regs (current)->sp; }else {/* -128 for the x32 ABI redzone */ - sp =percpu_read (old_rsp) -128 ; + sp =this_cpu_read (old_rsp) -128 ; }return (void __user *)round_down (sp - len,16 );
arch/x86/include/asm/current.h +1 -1
@@ -11,7 +11,7 @@ DECLARE_PER_CPU(struct task_struct *, current_task); static __always_inline struct task_struct *get_current(void) { -return percpu_read_stable (current_task); +return this_cpu_read_stable (current_task); }#define current get_current()
arch/x86/include/asm/desc.h +1 -0
@@ -6,6 +6,7 @@#include <asm/mmu.h> #include <linux/smp.h> +#include <linux/percpu.h> static inline void fill_ldt (struct desc_struct *desc,const struct user_desc *info) {
arch/x86/include/asm/fpu-internal.h +3 -3
@@ -290,14 +290,14 @@ static inline int __thread_has_fpu(struct task_struct *tsk)static inline void __thread_clear_has_fpu (struct task_struct *tsk) { tsk->thread.fpu.has_fpu =0 ; -percpu_write (fpu_owner_task,NULL ); +this_cpu_write (fpu_owner_task,NULL ); }/* Must be paired with a 'clts' before! */ static inline void __thread_set_has_fpu (struct task_struct *tsk) { tsk->thread.fpu.has_fpu =1 ; -percpu_write (fpu_owner_task, tsk); +this_cpu_write (fpu_owner_task, tsk); }/*
@@ -344,7 +344,7 @@ typedef struct { int preload; } fpu_switch_t;*/ static inline int fpu_lazy_restore (struct task_struct *new,unsigned int cpu) { -return new ==percpu_read_stable (fpu_owner_task) && +return new ==this_cpu_read_stable (fpu_owner_task) && cpu == new->thread.fpu.last_cpu; }
arch/x86/include/asm/hardirq.h +5 -4
@@ -35,14 +35,15 @@ DECLARE_PER_CPU_SHARED_ALIGNED(irq_cpustat_t, irq_stat);#define __ARCH_IRQ_STAT -#define inc_irq_stat (member) percpu_inc(irq_stat.member) +#define inc_irq_stat (member) this_cpu_inc(irq_stat.member) -#define local_softirq_pending () percpu_read(irq_stat.__softirq_pending) +#define local_softirq_pending () this_cpu_read(irq_stat.__softirq_pending)#define __ARCH_SET_SOFTIRQ_PENDING -#define set_softirq_pending (x) percpu_write(irq_stat.__softirq_pending, (x)) -#define or_softirq_pending (x) percpu_or(irq_stat.__softirq_pending, (x)) +#define set_softirq_pending (x) \ + this_cpu_write(irq_stat.__softirq_pending, (x)) +#define or_softirq_pending (x) this_cpu_or(irq_stat.__softirq_pending, (x))extern void ack_bad_irq (unsigned int irq);
arch/x86/include/asm/irq_regs.h +2 -2
@@ -15,7 +15,7 @@ DECLARE_PER_CPU(struct pt_regs *, irq_regs);static inline struct pt_regs *get_irq_regs (void ) { -return percpu_read (irq_regs); +return this_cpu_read (irq_regs); }static inline struct pt_regs *set_irq_regs (struct pt_regs *new_regs)
@@ -23,7 +23,7 @@ static inline struct pt_regs *set_irq_regs(struct pt_regs *new_regs)struct pt_regs *old_regs; old_regs =get_irq_regs (); -percpu_write (irq_regs, new_regs); +this_cpu_write (irq_regs, new_regs);return old_regs; }
arch/x86/include/asm/mmu_context.h +6 -6
@@ -25,8 +25,8 @@ void destroy_context(struct mm_struct *mm);static inline void enter_lazy_tlb (struct mm_struct *mm,struct task_struct *tsk) {#ifdef CONFIG_SMP -if (percpu_read (cpu_tlbstate.state) ==TLBSTATE_OK ) -percpu_write (cpu_tlbstate.state,TLBSTATE_LAZY ); +if (this_cpu_read (cpu_tlbstate.state) ==TLBSTATE_OK ) +this_cpu_write (cpu_tlbstate.state,TLBSTATE_LAZY );#endif }
@@ -37,8 +37,8 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,if (likely (prev != next)) {#ifdef CONFIG_SMP -percpu_write (cpu_tlbstate.state,TLBSTATE_OK ); -percpu_write (cpu_tlbstate.active_mm, next); +this_cpu_write (cpu_tlbstate.state,TLBSTATE_OK ); +this_cpu_write (cpu_tlbstate.active_mm, next);#endif cpumask_set_cpu (cpu,mm_cpumask (next));
@@ -56,8 +56,8 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next, }#ifdef CONFIG_SMP else { -percpu_write (cpu_tlbstate.state,TLBSTATE_OK ); -BUG_ON (percpu_read (cpu_tlbstate.active_mm) != next); +this_cpu_write (cpu_tlbstate.state,TLBSTATE_OK ); +BUG_ON (this_cpu_read (cpu_tlbstate.active_mm) != next);if (!cpumask_test_and_set_cpu (cpu,mm_cpumask (next))) {/* We were in lazy tlb mode and leave_mm disabled
arch/x86/include/asm/percpu.h +4 -4
@@ -46,7 +46,7 @@#ifdef CONFIG_SMP #define __percpu_prefix "%%"__stringify(__percpu_seg)":" -#define __my_cpu_offset percpu_read(this_cpu_off) +#define __my_cpu_offset this_cpu_read(this_cpu_off)/* * Compared to the generic __my_cpu_offset version, the following
@@ -352,15 +352,15 @@ do { \/* * percpu_read() makes gcc load the percpu variable every time it is -* accessed while percpu_read_stable() allows the value to be cached. -* percpu_read_stable() is more efficient and can be used if its value +* accessed while this_cpu_read_stable() allows the value to be cached. +* this_cpu_read_stable() is more efficient and can be used if its value * is guaranteed to be valid across cpus. The current users include * get_current() and get_thread_info() both of which are actually * per-thread variables implemented as per-cpu variables and thus * stable for the duration of the respective task. */ #define percpu_read (var) percpu_from_op("mov", var, "m" (var)) -#define percpu_read_stable (var) percpu_from_op("mov", var, "p" (&(var))) +#define this_cpu_read_stable (var) percpu_from_op("mov", var, "p" (&(var)))#define percpu_write (var, val) percpu_to_op("mov", var, val)#define percpu_add (var, val) percpu_add_op(var, val)#define percpu_sub (var, val) percpu_add_op(var, -(val))
arch/x86/include/asm/smp.h +2 -2
@@ -188,11 +188,11 @@ extern unsigned disabled_cpus __cpuinitdata;* from the initial startup. We map APIC_BASE very early in page_setup(), * so this is correct in the x86 case. */ -#define raw_smp_processor_id () (percpu_read(cpu_number)) +#define raw_smp_processor_id () (this_cpu_read(cpu_number))extern int safe_smp_processor_id (void );#elif defined(CONFIG_X86_64_SMP ) -#define raw_smp_processor_id () (percpu_read(cpu_number)) +#define raw_smp_processor_id () (this_cpu_read(cpu_number))#define stack_smp_processor_id () \ ({ \
arch/x86/include/asm/stackprotector.h +2 -2
@@ -75,9 +75,9 @@ static __always_inline void boot_init_stack_canary(void) current->stack_canary = canary;#ifdef CONFIG_X86_64 -percpu_write (irq_stack_union.stack_canary, canary); +this_cpu_write (irq_stack_union.stack_canary, canary);#else -percpu_write (stack_canary.canary, canary); +this_cpu_write (stack_canary.canary, canary);#endif }
arch/x86/include/asm/thread_info.h +1 -1
@@ -222,7 +222,7 @@ DECLARE_PER_CPU(unsigned long, kernel_stack);static inline struct thread_info *current_thread_info (void ) {struct thread_info *ti; - ti = (void *)(percpu_read_stable (kernel_stack) + + ti = (void *)(this_cpu_read_stable (kernel_stack) +KERNEL_STACK_OFFSET -THREAD_SIZE );return ti; }
arch/x86/include/asm/tlbflush.h +2 -2
@@ -156,8 +156,8 @@ DECLARE_PER_CPU_SHARED_ALIGNED(struct tlb_state, cpu_tlbstate);static inline void reset_lazy_tlbstate (void ) { -percpu_write (cpu_tlbstate.state,0 ); -percpu_write (cpu_tlbstate.active_mm, &init_mm); +this_cpu_write (cpu_tlbstate.state,0 ); +this_cpu_write (cpu_tlbstate.active_mm, &init_mm); }#endif /* SMP */
arch/x86/kernel/cpu/common.c +1 -1
@@ -1185,7 +1185,7 @@ void __cpuinit cpu_init(void) oist = &per_cpu (orig_ist, cpu);#ifdef CONFIG_NUMA -if (cpu !=0 &&percpu_read (numa_node) ==0 && +if (cpu !=0 &&this_cpu_read (numa_node) ==0 &&early_cpu_to_node (cpu) !=NUMA_NO_NODE )set_numa_node (early_cpu_to_node (cpu));#endif
arch/x86/kernel/cpu/mcheck/mce.c +2 -2
@@ -583,7 +583,7 @@ void machine_check_poll(enum mcp_flags flags, mce_banks_t *b)struct mce m;int i; -percpu_inc (mce_poll_count); +this_cpu_inc (mce_poll_count);mce_gather_info (&m,NULL );
@@ -1015,7 +1015,7 @@ void do_machine_check(struct pt_regs *regs, long error_code)atomic_inc (&mce_entry); -percpu_inc (mce_exception_count); +this_cpu_inc (mce_exception_count);if (!banks) goto out;
arch/x86/kernel/i387.c +1 -1
@@ -88,7 +88,7 @@ void kernel_fpu_begin(void)__thread_clear_has_fpu (me);/* We do 'stts()' in kernel_fpu_end() */ }else { -percpu_write (fpu_owner_task,NULL ); +this_cpu_write (fpu_owner_task,NULL );clts (); } }
arch/x86/kernel/nmi_selftest.c +1 -0
@@ -13,6 +13,7 @@#include <linux/cpumask.h> #include <linux/delay.h> #include <linux/init.h> +#include <linux/percpu.h> #include <asm/apic.h> #include <asm/nmi.h>
arch/x86/kernel/paravirt.c +6 -6
@@ -241,16 +241,16 @@ static DEFINE_PER_CPU(enum paravirt_lazy_mode, paravirt_lazy_mode) = PARAVIRT_LAstatic inline void enter_lazy (enum paravirt_lazy_mode mode) { -BUG_ON (percpu_read (paravirt_lazy_mode) !=PARAVIRT_LAZY_NONE ); +BUG_ON (this_cpu_read (paravirt_lazy_mode) !=PARAVIRT_LAZY_NONE ); -percpu_write (paravirt_lazy_mode, mode); +this_cpu_write (paravirt_lazy_mode, mode); }static void leave_lazy (enum paravirt_lazy_mode mode) { -BUG_ON (percpu_read (paravirt_lazy_mode) != mode); +BUG_ON (this_cpu_read (paravirt_lazy_mode) != mode); -percpu_write (paravirt_lazy_mode,PARAVIRT_LAZY_NONE ); +this_cpu_write (paravirt_lazy_mode,PARAVIRT_LAZY_NONE ); }void paravirt_enter_lazy_mmu (void )
@@ -267,7 +267,7 @@ void paravirt_start_context_switch(struct task_struct *prev) {BUG_ON (preemptible ()); -if (percpu_read (paravirt_lazy_mode) ==PARAVIRT_LAZY_MMU ) { +if (this_cpu_read (paravirt_lazy_mode) ==PARAVIRT_LAZY_MMU ) {arch_leave_lazy_mmu_mode ();set_ti_thread_flag (task_thread_info (prev),TIF_LAZY_MMU_UPDATES ); }
@@ -289,7 +289,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)if (in_interrupt ())return PARAVIRT_LAZY_NONE ; -return percpu_read (paravirt_lazy_mode); +return this_cpu_read (paravirt_lazy_mode); }void arch_flush_lazy_mmu_mode (void )
arch/x86/kernel/process.c +1 -1
@@ -377,7 +377,7 @@ static inline void play_dead(void)#ifdef CONFIG_X86_64 void enter_idle (void ) { -percpu_write (is_idle,1 ); +this_cpu_write (is_idle,1 );atomic_notifier_call_chain (&idle_notifier,IDLE_START ,NULL ); }
arch/x86/kernel/process_32.c +1 -1
@@ -302,7 +302,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)switch_fpu_finish (next_p, fpu); -percpu_write (current_task, next_p); +this_cpu_write (current_task, next_p);return prev_p; }
arch/x86/kernel/process_64.c +5 -5
@@ -237,7 +237,7 @@ start_thread_common(struct pt_regs *regs, unsigned long new_ip, current->thread.usersp = new_sp; regs->ip = new_ip; regs->sp = new_sp; -percpu_write (old_rsp, new_sp); +this_cpu_write (old_rsp, new_sp); regs->cs = _cs; regs->ss = _ss; regs->flags =X86_EFLAGS_IF ;
@@ -359,11 +359,11 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)/* * Switch the PDA and FPU contexts. */ - prev->usersp =percpu_read (old_rsp); -percpu_write (old_rsp, next->usersp); -percpu_write (current_task, next_p); + prev->usersp =this_cpu_read (old_rsp); +this_cpu_write (old_rsp, next->usersp); +this_cpu_write (current_task, next_p); -percpu_write (kernel_stack, +this_cpu_write (kernel_stack, (unsigned long )task_stack_page (next_p) +THREAD_SIZE -KERNEL_STACK_OFFSET );
arch/x86/mm/tlb.c +5 -5
@@ -61,10 +61,10 @@ static DEFINE_PER_CPU_READ_MOSTLY(int, tlb_vector_offset);*/ void leave_mm (int cpu) { -if (percpu_read (cpu_tlbstate.state) ==TLBSTATE_OK ) +if (this_cpu_read (cpu_tlbstate.state) ==TLBSTATE_OK )BUG ();cpumask_clear_cpu (cpu, -mm_cpumask (percpu_read (cpu_tlbstate.active_mm))); +mm_cpumask (this_cpu_read (cpu_tlbstate.active_mm)));load_cr3 (swapper_pg_dir); }EXPORT_SYMBOL_GPL (leave_mm);
@@ -152,8 +152,8 @@ void smp_invalidate_interrupt(struct pt_regs *regs)* BUG(); */ -if (f->flush_mm ==percpu_read (cpu_tlbstate.active_mm)) { -if (percpu_read (cpu_tlbstate.state) ==TLBSTATE_OK ) { +if (f->flush_mm ==this_cpu_read (cpu_tlbstate.active_mm)) { +if (this_cpu_read (cpu_tlbstate.state) ==TLBSTATE_OK ) {if (f->flush_va ==TLB_FLUSH_ALL )local_flush_tlb ();else
@@ -322,7 +322,7 @@ void flush_tlb_page(struct vm_area_struct *vma, unsigned long va)static void do_flush_tlb_all (void *info) {__flush_tlb_all (); -if (percpu_read (cpu_tlbstate.state) ==TLBSTATE_LAZY ) +if (this_cpu_read (cpu_tlbstate.state) ==TLBSTATE_LAZY )leave_mm (smp_processor_id ()); }
include/linux/topology.h +2 -2
@@ -239,7 +239,7 @@ static inline int cpu_to_node(int cpu)#ifndef set_numa_nodestatic inline void set_numa_node (int node) { -percpu_write (numa_node, node); +this_cpu_write (numa_node, node); }#endif
@@ -274,7 +274,7 @@ DECLARE_PER_CPU(int, _numa_mem_);#ifndef set_numa_memstatic inline void set_numa_mem (int node) { -percpu_write (_numa_mem_, node); +this_cpu_write (_numa_mem_, node); }#endif
Signature · 1 line
1.7.5.4
Quoted 4 lines · Alex Shi
I am sorry for mess commit log previous patchset.
As Andrew Morton's request, I combind and clean up the patchset.
Quoted 8 lines
According to Ingo's complain. I use the same and short '
this_cpu_ops' functions in x86 part code.Thanks for all comments!
[PATCH 1/3] net: replace
percpu_xxxfuncs withthis_cpu_xxxor [PATCH 2/3] x86: replacepercpu_xxxfuncs withthis_cpu_xxx[PATCH 3/3] percpu: removepercpu_xxx()functions
All three patches look good to me.
I guess 0001 can go through net, 0002 through x86 and I can merge the third one once both are in mainline. David, hpa, can you guys please take the respective patch?
Thank you.
Signature · 1 line
tejun
Quoted 14 lines · Tejun Heo
Quoted 4 lines · Alex Shi
I am sorry for mess commit log previous patchset.
As Andrew Morton's request, I combind and clean up the patchset.
Quoted 8 lines
According to Ingo's complain. I use the same and short '
this_cpu_ops' functions in x86 part code.Thanks for all comments!
[PATCH 1/3] net: replace
percpu_xxxfuncs withthis_cpu_xxxor [PATCH 2/3] x86: replacepercpu_xxxfuncs withthis_cpu_xxx[PATCH 3/3] percpu: removepercpu_xxx()functions
Quoted 8 lines
All three patches look good to me.
Acked-by Tejun Heo <[email protected]>I guess 0001 can go through net, 0002 through x86 and I can merge the third one once both are in mainline. David, hpa, can you guys please take the respective patch?
I would be happier if we kept the patchset together.
So I would greatly prefer if you'd take the whole patchset with my:
Tejun Heo
maintainerQuoted 5 lines · H. Peter Anvin
I would be happier if we kept the patchset together.
So I would greatly prefer if you'd take the whole patchset with my:
Acked-by H. Peter Anvin <[email protected]>
Yeap, that works too. David, can I route the network part too with your ack?
Thanks.
Signature · 1 line
tejun
From: Tejun Heo <[email protected]>
Date: Mon, 14 May 2012 11:01:28 -0700
Quoted 9 lines · H. Peter Anvin
Quoted 5 lines
I would be happier if we kept the patchset together.
So I would greatly prefer if you'd take the whole patchset with my:
Acked-by H. Peter Anvin <[email protected]>Yeap, that works too. David, can I route the network part too with your ack?
Sure:
Quoted 4 lines · Alex Shi
I am sorry for mess commit log previous patchset.
As Andrew Morton's request, I combind and clean up the patchset.
Quoted 8 lines
According to Ingo's complain. I use the same and short '
this_cpu_ops' functions in x86 part code.Thanks for all comments!
[PATCH 1/3] net: replace
percpu_xxxfuncs withthis_cpu_xxxor [PATCH 2/3] x86: replacepercpu_xxxfuncs withthis_cpu_xxx[PATCH 3/3] percpu: removepercpu_xxx()functions
Applied to percpu/for-3.5. Thanks.
Signature · 1 line
tejun