Skip to content

Commit 6065a24

Browse files
Christoph Lameterhtejun
authored andcommitted
ia64: Replace __get_cpu_var uses
__get_cpu_var() is used for multiple purposes in the kernel source. One of them is address calculation via the form &__get_cpu_var(x). This calculates the address for the instance of the percpu variable of the current processor based on an offset. Other use cases are for storing and retrieving data from the current processors percpu area. __get_cpu_var() can be used as an lvalue when writing data or on the right side of an assignment. __get_cpu_var() is defined as : #define __get_cpu_var(var) (*this_cpu_ptr(&(var))) __get_cpu_var() always only does an address determination. However, store and retrieve operations could use a segment prefix (or global register on other platforms) to avoid the address calculation. this_cpu_write() and this_cpu_read() can directly take an offset into a percpu area and use optimized assembly code to read and write per cpu variables. This patch converts __get_cpu_var into either an explicit address calculation using this_cpu_ptr() or into a use of this_cpu operations that use the offset. Thereby address calculations are avoided and less registers are used when code is generated. At the end of the patch set all uses of __get_cpu_var have been removed so the macro is removed too. The patch set includes passes over all arches as well. Once these operations are used throughout then specialized macros can be defined in non -x86 arches as well in order to optimize per cpu access by f.e. using a global register that may be set to the per cpu base. Transformations done to __get_cpu_var() 1. Determine the address of the percpu instance of the current processor. DEFINE_PER_CPU(int, y); int *x = &__get_cpu_var(y); Converts to int *x = this_cpu_ptr(&y); 2. Same as raspberrypi#1 but this time an array structure is involved. DEFINE_PER_CPU(int, y[20]); int *x = __get_cpu_var(y); Converts to int *x = this_cpu_ptr(y); 3. Retrieve the content of the current processors instance of a per cpu variable. DEFINE_PER_CPU(int, y); int x = __get_cpu_var(y) Converts to int x = __this_cpu_read(y); 4. Retrieve the content of a percpu struct DEFINE_PER_CPU(struct mystruct, y); struct mystruct x = __get_cpu_var(y); Converts to memcpy(&x, this_cpu_ptr(&y), sizeof(x)); 5. Assignment to a per cpu variable DEFINE_PER_CPU(int, y) __get_cpu_var(y) = x; Converts to __this_cpu_write(y, x); 6. Increment/Decrement etc of a per cpu variable DEFINE_PER_CPU(int, y); __get_cpu_var(y)++ Converts to __this_cpu_inc(y) Cc: Tony Luck <tony.luck@intel.com> Cc: Fenghua Yu <fenghua.yu@intel.com> Cc: linux-ia64@vger.kernel.org Signed-off-by: Christoph Lameter <cl@linux.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent 0bf7fcf commit 6065a24

12 files changed

Lines changed: 38 additions & 38 deletions

File tree

‎arch/ia64/include/asm/hw_irq.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ static inline ia64_vector __ia64_irq_to_vector(int irq)
159159
static inline unsigned int
160160
__ia64_local_vector_to_irq (ia64_vector vec)
161161
{
162-
return __get_cpu_var(vector_irq)[vec];
162+
return __this_cpu_read(vector_irq[vec]);
163163
}
164164
#endif
165165

‎arch/ia64/include/asm/sn/arch.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ struct sn_hub_info_s {
5757
u16 nasid_bitmask;
5858
};
5959
DECLARE_PER_CPU(struct sn_hub_info_s, __sn_hub_info);
60-
#define sn_hub_info (&__get_cpu_var(__sn_hub_info))
60+
#define sn_hub_info this_cpu_ptr(&__sn_hub_info)
6161
#define is_shub2() (sn_hub_info->shub2)
6262
#define is_shub1() (sn_hub_info->shub2 == 0)
6363

@@ -72,7 +72,7 @@ DECLARE_PER_CPU(struct sn_hub_info_s, __sn_hub_info);
7272
* cpu.
7373
*/
7474
DECLARE_PER_CPU(short, __sn_cnodeid_to_nasid[MAX_COMPACT_NODES]);
75-
#define sn_cnodeid_to_nasid (&__get_cpu_var(__sn_cnodeid_to_nasid[0]))
75+
#define sn_cnodeid_to_nasid this_cpu_ptr(&__sn_cnodeid_to_nasid[0])
7676

7777

7878
extern u8 sn_partition_id;

‎arch/ia64/include/asm/sn/nodepda.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ typedef struct nodepda_s nodepda_t;
7070
*/
7171

7272
DECLARE_PER_CPU(struct nodepda_s *, __sn_nodepda);
73-
#define sn_nodepda (__get_cpu_var(__sn_nodepda))
73+
#define sn_nodepda __this_cpu_read(__sn_nodepda)
7474
#define NODEPDA(cnodeid) (sn_nodepda->pernode_pdaindr[cnodeid])
7575

7676
/*

‎arch/ia64/include/asm/switch_to.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ extern void ia64_load_extra (struct task_struct *task);
3232

3333
#ifdef CONFIG_PERFMON
3434
DECLARE_PER_CPU(unsigned long, pfm_syst_info);
35-
# define PERFMON_IS_SYSWIDE() (__get_cpu_var(pfm_syst_info) & 0x1)
35+
# define PERFMON_IS_SYSWIDE() (__this_cpu_read(pfm_syst_info) & 0x1)
3636
#else
3737
# define PERFMON_IS_SYSWIDE() (0)
3838
#endif

‎arch/ia64/include/asm/uv/uv_hub.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ struct uv_hub_info_s {
108108
unsigned char n_val;
109109
};
110110
DECLARE_PER_CPU(struct uv_hub_info_s, __uv_hub_info);
111-
#define uv_hub_info (&__get_cpu_var(__uv_hub_info))
111+
#define uv_hub_info this_cpu_ptr(&__uv_hub_info)
112112
#define uv_cpu_hub_info(cpu) (&per_cpu(__uv_hub_info, cpu))
113113

114114
/*

‎arch/ia64/kernel/irq.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ ia64_vector __ia64_irq_to_vector(int irq)
4242

4343
unsigned int __ia64_local_vector_to_irq (ia64_vector vec)
4444
{
45-
return __get_cpu_var(vector_irq)[vec];
45+
return __this_cpu_read(vector_irq[vec]);
4646
}
4747
#endif
4848

‎arch/ia64/kernel/irq_ia64.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ static irqreturn_t smp_irq_move_cleanup_interrupt(int irq, void *dev_id)
330330
int irq;
331331
struct irq_desc *desc;
332332
struct irq_cfg *cfg;
333-
irq = __get_cpu_var(vector_irq)[vector];
333+
irq = __this_cpu_read(vector_irq[vector]);
334334
if (irq < 0)
335335
continue;
336336

@@ -344,7 +344,7 @@ static irqreturn_t smp_irq_move_cleanup_interrupt(int irq, void *dev_id)
344344
goto unlock;
345345

346346
spin_lock_irqsave(&vector_lock, flags);
347-
__get_cpu_var(vector_irq)[vector] = -1;
347+
__this_cpu_write(vector_irq[vector], -1);
348348
cpu_clear(me, vector_table[vector]);
349349
spin_unlock_irqrestore(&vector_lock, flags);
350350
cfg->move_cleanup_count--;

‎arch/ia64/kernel/kprobes.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,15 +396,15 @@ static void __kprobes restore_previous_kprobe(struct kprobe_ctlblk *kcb)
396396
{
397397
unsigned int i;
398398
i = atomic_read(&kcb->prev_kprobe_index);
399-
__get_cpu_var(current_kprobe) = kcb->prev_kprobe[i-1].kp;
399+
__this_cpu_write(current_kprobe, kcb->prev_kprobe[i-1].kp);
400400
kcb->kprobe_status = kcb->prev_kprobe[i-1].status;
401401
atomic_sub(1, &kcb->prev_kprobe_index);
402402
}
403403

404404
static void __kprobes set_current_kprobe(struct kprobe *p,
405405
struct kprobe_ctlblk *kcb)
406406
{
407-
__get_cpu_var(current_kprobe) = p;
407+
__this_cpu_write(current_kprobe, p);
408408
}
409409

410410
static void kretprobe_trampoline(void)
@@ -823,7 +823,7 @@ static int __kprobes pre_kprobes_handler(struct die_args *args)
823823
/*
824824
* jprobe instrumented function just completed
825825
*/
826-
p = __get_cpu_var(current_kprobe);
826+
p = __this_cpu_read(current_kprobe);
827827
if (p->break_handler && p->break_handler(p, regs)) {
828828
goto ss_probe;
829829
}

‎arch/ia64/kernel/mca.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,7 @@ ia64_mca_handler(struct pt_regs *regs, struct switch_stack *sw,
13411341
ia64_mlogbuf_finish(1);
13421342
}
13431343

1344-
if (__get_cpu_var(ia64_mca_tr_reload)) {
1344+
if (__this_cpu_read(ia64_mca_tr_reload)) {
13451345
mca_insert_tr(0x1); /*Reload dynamic itrs*/
13461346
mca_insert_tr(0x2); /*Reload dynamic itrs*/
13471347
}
@@ -1868,14 +1868,14 @@ ia64_mca_cpu_init(void *cpu_data)
18681868
"MCA", cpu);
18691869
format_mca_init_stack(data, offsetof(struct ia64_mca_cpu, init_stack),
18701870
"INIT", cpu);
1871-
__get_cpu_var(ia64_mca_data) = __per_cpu_mca[cpu] = __pa(data);
1871+
__this_cpu_write(ia64_mca_data, (__per_cpu_mca[cpu] = __pa(data)));
18721872

18731873
/*
18741874
* Stash away a copy of the PTE needed to map the per-CPU page.
18751875
* We may need it during MCA recovery.
18761876
*/
1877-
__get_cpu_var(ia64_mca_per_cpu_pte) =
1878-
pte_val(mk_pte_phys(__pa(cpu_data), PAGE_KERNEL));
1877+
__this_cpu_write(ia64_mca_per_cpu_pte,
1878+
pte_val(mk_pte_phys(__pa(cpu_data), PAGE_KERNEL)));
18791879

18801880
/*
18811881
* Also, stash away a copy of the PAL address and the PTE
@@ -1884,10 +1884,10 @@ ia64_mca_cpu_init(void *cpu_data)
18841884
pal_vaddr = efi_get_pal_addr();
18851885
if (!pal_vaddr)
18861886
return;
1887-
__get_cpu_var(ia64_mca_pal_base) =
1888-
GRANULEROUNDDOWN((unsigned long) pal_vaddr);
1889-
__get_cpu_var(ia64_mca_pal_pte) = pte_val(mk_pte_phys(__pa(pal_vaddr),
1890-
PAGE_KERNEL));
1887+
__this_cpu_write(ia64_mca_pal_base,
1888+
GRANULEROUNDDOWN((unsigned long) pal_vaddr));
1889+
__this_cpu_write(ia64_mca_pal_pte, pte_val(mk_pte_phys(__pa(pal_vaddr),
1890+
PAGE_KERNEL)));
18911891
}
18921892

18931893
static void ia64_mca_cmc_vector_adjust(void *dummy)

‎arch/ia64/kernel/process.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ static inline void play_dead(void)
215215
unsigned int this_cpu = smp_processor_id();
216216

217217
/* Ack it */
218-
__get_cpu_var(cpu_state) = CPU_DEAD;
218+
__this_cpu_write(cpu_state, CPU_DEAD);
219219

220220
max_xtp();
221221
local_irq_disable();
@@ -273,7 +273,7 @@ ia64_save_extra (struct task_struct *task)
273273
if ((task->thread.flags & IA64_THREAD_PM_VALID) != 0)
274274
pfm_save_regs(task);
275275

276-
info = __get_cpu_var(pfm_syst_info);
276+
info = __this_cpu_read(pfm_syst_info);
277277
if (info & PFM_CPUINFO_SYST_WIDE)
278278
pfm_syst_wide_update_task(task, info, 0);
279279
#endif
@@ -293,7 +293,7 @@ ia64_load_extra (struct task_struct *task)
293293
if ((task->thread.flags & IA64_THREAD_PM_VALID) != 0)
294294
pfm_load_regs(task);
295295

296-
info = __get_cpu_var(pfm_syst_info);
296+
info = __this_cpu_read(pfm_syst_info);
297297
if (info & PFM_CPUINFO_SYST_WIDE)
298298
pfm_syst_wide_update_task(task, info, 1);
299299
#endif

0 commit comments

Comments
 (0)