Skip to content

Commit eb7e7d7

Browse files
Christoph Lameterhtejun
authored andcommitted
s390: 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: Martin Schwidefsky <schwidefsky@de.ibm.com> CC: linux390@de.ibm.com Acked-by: Heiko Carstens <heiko.carstens@de.ibm.com> Signed-off-by: Christoph Lameter <cl@linux.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent 3589871 commit eb7e7d7

12 files changed

Lines changed: 48 additions & 44 deletions

File tree

‎arch/s390/include/asm/cputime.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ cputime64_t s390_get_idle_time(int cpu);
184184

185185
static inline int s390_nohz_delay(int cpu)
186186
{
187-
return __get_cpu_var(s390_idle).nohz_delay != 0;
187+
return __this_cpu_read(s390_idle.nohz_delay) != 0;
188188
}
189189

190190
#define arch_needs_cpu(cpu) s390_nohz_delay(cpu)

‎arch/s390/include/asm/irq.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ DECLARE_PER_CPU_SHARED_ALIGNED(struct irq_stat, irq_stat);
8181

8282
static __always_inline void inc_irq_stat(enum interruption_class irq)
8383
{
84-
__get_cpu_var(irq_stat).irqs[irq]++;
84+
__this_cpu_inc(irq_stat.irqs[irq]);
8585
}
8686

8787
struct ext_code {

‎arch/s390/include/asm/percpu.h‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
pcp_op_T__ old__, new__, prev__; \
3232
pcp_op_T__ *ptr__; \
3333
preempt_disable(); \
34-
ptr__ = __this_cpu_ptr(&(pcp)); \
34+
ptr__ = raw_cpu_ptr(&(pcp)); \
3535
prev__ = *ptr__; \
3636
do { \
3737
old__ = prev__; \
@@ -70,7 +70,7 @@
7070
pcp_op_T__ val__ = (val); \
7171
pcp_op_T__ old__, *ptr__; \
7272
preempt_disable(); \
73-
ptr__ = __this_cpu_ptr(&(pcp)); \
73+
ptr__ = raw_cpu_ptr(&(pcp)); \
7474
if (__builtin_constant_p(val__) && \
7575
((szcast)val__ > -129) && ((szcast)val__ < 128)) { \
7676
asm volatile( \
@@ -97,7 +97,7 @@
9797
pcp_op_T__ val__ = (val); \
9898
pcp_op_T__ old__, *ptr__; \
9999
preempt_disable(); \
100-
ptr__ = __this_cpu_ptr(&(pcp)); \
100+
ptr__ = raw_cpu_ptr(&(pcp)); \
101101
asm volatile( \
102102
op " %[old__],%[val__],%[ptr__]\n" \
103103
: [old__] "=d" (old__), [ptr__] "+Q" (*ptr__) \
@@ -116,7 +116,7 @@
116116
pcp_op_T__ val__ = (val); \
117117
pcp_op_T__ old__, *ptr__; \
118118
preempt_disable(); \
119-
ptr__ = __this_cpu_ptr(&(pcp)); \
119+
ptr__ = raw_cpu_ptr(&(pcp)); \
120120
asm volatile( \
121121
op " %[old__],%[val__],%[ptr__]\n" \
122122
: [old__] "=d" (old__), [ptr__] "+Q" (*ptr__) \
@@ -138,7 +138,7 @@
138138
pcp_op_T__ ret__; \
139139
pcp_op_T__ *ptr__; \
140140
preempt_disable(); \
141-
ptr__ = __this_cpu_ptr(&(pcp)); \
141+
ptr__ = raw_cpu_ptr(&(pcp)); \
142142
ret__ = cmpxchg(ptr__, oval, nval); \
143143
preempt_enable(); \
144144
ret__; \
@@ -154,7 +154,7 @@
154154
typeof(pcp) *ptr__; \
155155
typeof(pcp) ret__; \
156156
preempt_disable(); \
157-
ptr__ = __this_cpu_ptr(&(pcp)); \
157+
ptr__ = raw_cpu_ptr(&(pcp)); \
158158
ret__ = xchg(ptr__, nval); \
159159
preempt_enable(); \
160160
ret__; \
@@ -173,8 +173,8 @@
173173
typeof(pcp2) *p2__; \
174174
int ret__; \
175175
preempt_disable(); \
176-
p1__ = __this_cpu_ptr(&(pcp1)); \
177-
p2__ = __this_cpu_ptr(&(pcp2)); \
176+
p1__ = raw_cpu_ptr(&(pcp1)); \
177+
p2__ = raw_cpu_ptr(&(pcp2)); \
178178
ret__ = __cmpxchg_double(p1__, p2__, o1__, o2__, n1__, n2__); \
179179
preempt_enable(); \
180180
ret__; \

‎arch/s390/kernel/irq.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ static irqreturn_t do_ext_interrupt(int irq, void *dummy)
258258

259259
ext_code = *(struct ext_code *) &regs->int_code;
260260
if (ext_code.code != EXT_IRQ_CLK_COMP)
261-
__get_cpu_var(s390_idle).nohz_delay = 1;
261+
__this_cpu_write(s390_idle.nohz_delay, 1);
262262

263263
index = ext_hash(ext_code.code);
264264
rcu_read_lock();

‎arch/s390/kernel/kprobes.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,9 @@ static void __kprobes disable_singlestep(struct kprobe_ctlblk *kcb,
366366
*/
367367
static void __kprobes push_kprobe(struct kprobe_ctlblk *kcb, struct kprobe *p)
368368
{
369-
kcb->prev_kprobe.kp = __get_cpu_var(current_kprobe);
369+
kcb->prev_kprobe.kp = __this_cpu_read(current_kprobe);
370370
kcb->prev_kprobe.status = kcb->kprobe_status;
371-
__get_cpu_var(current_kprobe) = p;
371+
__this_cpu_write(current_kprobe, p);
372372
}
373373

374374
/*
@@ -378,7 +378,7 @@ static void __kprobes push_kprobe(struct kprobe_ctlblk *kcb, struct kprobe *p)
378378
*/
379379
static void __kprobes pop_kprobe(struct kprobe_ctlblk *kcb)
380380
{
381-
__get_cpu_var(current_kprobe) = kcb->prev_kprobe.kp;
381+
__this_cpu_write(current_kprobe, kcb->prev_kprobe.kp);
382382
kcb->kprobe_status = kcb->prev_kprobe.status;
383383
}
384384

@@ -459,7 +459,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
459459
enable_singlestep(kcb, regs, (unsigned long) p->ainsn.insn);
460460
return 1;
461461
} else if (kprobe_running()) {
462-
p = __get_cpu_var(current_kprobe);
462+
p = __this_cpu_read(current_kprobe);
463463
if (p->break_handler && p->break_handler(p, regs)) {
464464
/*
465465
* Continuation after the jprobe completed and

‎arch/s390/kernel/nmi.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,12 @@ void s390_handle_mcck(void)
5353
*/
5454
local_irq_save(flags);
5555
local_mcck_disable();
56-
mcck = __get_cpu_var(cpu_mcck);
57-
memset(&__get_cpu_var(cpu_mcck), 0, sizeof(struct mcck_struct));
56+
/*
57+
* Ummm... Does this make sense at all? Copying the percpu struct
58+
* and then zapping it one statement later?
59+
*/
60+
memcpy(&mcck, this_cpu_ptr(&cpu_mcck), sizeof(mcck));
61+
memset(&mcck, 0, sizeof(struct mcck_struct));
5862
clear_cpu_flag(CIF_MCCK_PENDING);
5963
local_mcck_enable();
6064
local_irq_restore(flags);
@@ -253,7 +257,7 @@ void notrace s390_do_machine_check(struct pt_regs *regs)
253257
nmi_enter();
254258
inc_irq_stat(NMI_NMI);
255259
mci = (struct mci *) &S390_lowcore.mcck_interruption_code;
256-
mcck = &__get_cpu_var(cpu_mcck);
260+
mcck = this_cpu_ptr(&cpu_mcck);
257261
umode = user_mode(regs);
258262

259263
if (mci->sd) {

‎arch/s390/kernel/perf_cpum_cf.c‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ static int validate_ctr_auth(const struct hw_perf_event *hwc)
173173
*/
174174
static void cpumf_pmu_enable(struct pmu *pmu)
175175
{
176-
struct cpu_hw_events *cpuhw = &__get_cpu_var(cpu_hw_events);
176+
struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events);
177177
int err;
178178

179179
if (cpuhw->flags & PMU_F_ENABLED)
@@ -196,7 +196,7 @@ static void cpumf_pmu_enable(struct pmu *pmu)
196196
*/
197197
static void cpumf_pmu_disable(struct pmu *pmu)
198198
{
199-
struct cpu_hw_events *cpuhw = &__get_cpu_var(cpu_hw_events);
199+
struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events);
200200
int err;
201201
u64 inactive;
202202

@@ -230,7 +230,7 @@ static void cpumf_measurement_alert(struct ext_code ext_code,
230230
return;
231231

232232
inc_irq_stat(IRQEXT_CMC);
233-
cpuhw = &__get_cpu_var(cpu_hw_events);
233+
cpuhw = this_cpu_ptr(&cpu_hw_events);
234234

235235
/* Measurement alerts are shared and might happen when the PMU
236236
* is not reserved. Ignore these alerts in this case. */
@@ -250,7 +250,7 @@ static void cpumf_measurement_alert(struct ext_code ext_code,
250250
#define PMC_RELEASE 1
251251
static void setup_pmc_cpu(void *flags)
252252
{
253-
struct cpu_hw_events *cpuhw = &__get_cpu_var(cpu_hw_events);
253+
struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events);
254254

255255
switch (*((int *) flags)) {
256256
case PMC_INIT:
@@ -475,7 +475,7 @@ static void cpumf_pmu_read(struct perf_event *event)
475475

476476
static void cpumf_pmu_start(struct perf_event *event, int flags)
477477
{
478-
struct cpu_hw_events *cpuhw = &__get_cpu_var(cpu_hw_events);
478+
struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events);
479479
struct hw_perf_event *hwc = &event->hw;
480480

481481
if (WARN_ON_ONCE(!(hwc->state & PERF_HES_STOPPED)))
@@ -506,7 +506,7 @@ static void cpumf_pmu_start(struct perf_event *event, int flags)
506506

507507
static void cpumf_pmu_stop(struct perf_event *event, int flags)
508508
{
509-
struct cpu_hw_events *cpuhw = &__get_cpu_var(cpu_hw_events);
509+
struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events);
510510
struct hw_perf_event *hwc = &event->hw;
511511

512512
if (!(hwc->state & PERF_HES_STOPPED)) {
@@ -527,7 +527,7 @@ static void cpumf_pmu_stop(struct perf_event *event, int flags)
527527

528528
static int cpumf_pmu_add(struct perf_event *event, int flags)
529529
{
530-
struct cpu_hw_events *cpuhw = &__get_cpu_var(cpu_hw_events);
530+
struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events);
531531

532532
/* Check authorization for the counter set to which this
533533
* counter belongs.
@@ -551,7 +551,7 @@ static int cpumf_pmu_add(struct perf_event *event, int flags)
551551

552552
static void cpumf_pmu_del(struct perf_event *event, int flags)
553553
{
554-
struct cpu_hw_events *cpuhw = &__get_cpu_var(cpu_hw_events);
554+
struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events);
555555

556556
cpumf_pmu_stop(event, PERF_EF_UPDATE);
557557

@@ -575,7 +575,7 @@ static void cpumf_pmu_del(struct perf_event *event, int flags)
575575
*/
576576
static void cpumf_pmu_start_txn(struct pmu *pmu)
577577
{
578-
struct cpu_hw_events *cpuhw = &__get_cpu_var(cpu_hw_events);
578+
struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events);
579579

580580
perf_pmu_disable(pmu);
581581
cpuhw->flags |= PERF_EVENT_TXN;
@@ -589,7 +589,7 @@ static void cpumf_pmu_start_txn(struct pmu *pmu)
589589
*/
590590
static void cpumf_pmu_cancel_txn(struct pmu *pmu)
591591
{
592-
struct cpu_hw_events *cpuhw = &__get_cpu_var(cpu_hw_events);
592+
struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events);
593593

594594
WARN_ON(cpuhw->tx_state != cpuhw->state);
595595

@@ -604,7 +604,7 @@ static void cpumf_pmu_cancel_txn(struct pmu *pmu)
604604
*/
605605
static int cpumf_pmu_commit_txn(struct pmu *pmu)
606606
{
607-
struct cpu_hw_events *cpuhw = &__get_cpu_var(cpu_hw_events);
607+
struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events);
608608
u64 state;
609609

610610
/* check if the updated state can be scheduled */

‎arch/s390/kernel/perf_cpum_sf.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ static DEFINE_MUTEX(pmc_reserve_mutex);
562562
static void setup_pmc_cpu(void *flags)
563563
{
564564
int err;
565-
struct cpu_hw_sf *cpusf = &__get_cpu_var(cpu_hw_sf);
565+
struct cpu_hw_sf *cpusf = this_cpu_ptr(&cpu_hw_sf);
566566

567567
err = 0;
568568
switch (*((int *) flags)) {
@@ -849,7 +849,7 @@ static int cpumsf_pmu_event_init(struct perf_event *event)
849849

850850
static void cpumsf_pmu_enable(struct pmu *pmu)
851851
{
852-
struct cpu_hw_sf *cpuhw = &__get_cpu_var(cpu_hw_sf);
852+
struct cpu_hw_sf *cpuhw = this_cpu_ptr(&cpu_hw_sf);
853853
struct hw_perf_event *hwc;
854854
int err;
855855

@@ -898,7 +898,7 @@ static void cpumsf_pmu_enable(struct pmu *pmu)
898898

899899
static void cpumsf_pmu_disable(struct pmu *pmu)
900900
{
901-
struct cpu_hw_sf *cpuhw = &__get_cpu_var(cpu_hw_sf);
901+
struct cpu_hw_sf *cpuhw = this_cpu_ptr(&cpu_hw_sf);
902902
struct hws_lsctl_request_block inactive;
903903
struct hws_qsi_info_block si;
904904
int err;
@@ -1306,7 +1306,7 @@ static void cpumsf_pmu_read(struct perf_event *event)
13061306
*/
13071307
static void cpumsf_pmu_start(struct perf_event *event, int flags)
13081308
{
1309-
struct cpu_hw_sf *cpuhw = &__get_cpu_var(cpu_hw_sf);
1309+
struct cpu_hw_sf *cpuhw = this_cpu_ptr(&cpu_hw_sf);
13101310

13111311
if (WARN_ON_ONCE(!(event->hw.state & PERF_HES_STOPPED)))
13121312
return;
@@ -1327,7 +1327,7 @@ static void cpumsf_pmu_start(struct perf_event *event, int flags)
13271327
*/
13281328
static void cpumsf_pmu_stop(struct perf_event *event, int flags)
13291329
{
1330-
struct cpu_hw_sf *cpuhw = &__get_cpu_var(cpu_hw_sf);
1330+
struct cpu_hw_sf *cpuhw = this_cpu_ptr(&cpu_hw_sf);
13311331

13321332
if (event->hw.state & PERF_HES_STOPPED)
13331333
return;
@@ -1346,7 +1346,7 @@ static void cpumsf_pmu_stop(struct perf_event *event, int flags)
13461346

13471347
static int cpumsf_pmu_add(struct perf_event *event, int flags)
13481348
{
1349-
struct cpu_hw_sf *cpuhw = &__get_cpu_var(cpu_hw_sf);
1349+
struct cpu_hw_sf *cpuhw = this_cpu_ptr(&cpu_hw_sf);
13501350
int err;
13511351

13521352
if (cpuhw->flags & PMU_F_IN_USE)
@@ -1397,7 +1397,7 @@ static int cpumsf_pmu_add(struct perf_event *event, int flags)
13971397

13981398
static void cpumsf_pmu_del(struct perf_event *event, int flags)
13991399
{
1400-
struct cpu_hw_sf *cpuhw = &__get_cpu_var(cpu_hw_sf);
1400+
struct cpu_hw_sf *cpuhw = this_cpu_ptr(&cpu_hw_sf);
14011401

14021402
perf_pmu_disable(event->pmu);
14031403
cpumsf_pmu_stop(event, PERF_EF_UPDATE);
@@ -1470,7 +1470,7 @@ static void cpumf_measurement_alert(struct ext_code ext_code,
14701470
if (!(alert & CPU_MF_INT_SF_MASK))
14711471
return;
14721472
inc_irq_stat(IRQEXT_CMS);
1473-
cpuhw = &__get_cpu_var(cpu_hw_sf);
1473+
cpuhw = this_cpu_ptr(&cpu_hw_sf);
14741474

14751475
/* Measurement alerts are shared and might happen when the PMU
14761476
* is not reserved. Ignore these alerts in this case. */

‎arch/s390/kernel/processor.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ static DEFINE_PER_CPU(struct cpuid, cpu_id);
2323
*/
2424
void cpu_init(void)
2525
{
26-
struct s390_idle_data *idle = &__get_cpu_var(s390_idle);
27-
struct cpuid *id = &__get_cpu_var(cpu_id);
26+
struct s390_idle_data *idle = this_cpu_ptr(&s390_idle);
27+
struct cpuid *id = this_cpu_ptr(&cpu_id);
2828

2929
get_cpu_id(id);
3030
atomic_inc(&init_mm.mm_count);

‎arch/s390/kernel/time.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void clock_comparator_work(void)
9292
struct clock_event_device *cd;
9393

9494
S390_lowcore.clock_comparator = -1ULL;
95-
cd = &__get_cpu_var(comparators);
95+
cd = this_cpu_ptr(&comparators);
9696
cd->event_handler(cd);
9797
}
9898

@@ -360,7 +360,7 @@ EXPORT_SYMBOL(get_sync_clock);
360360
*/
361361
static void disable_sync_clock(void *dummy)
362362
{
363-
atomic_t *sw_ptr = &__get_cpu_var(clock_sync_word);
363+
atomic_t *sw_ptr = this_cpu_ptr(&clock_sync_word);
364364
/*
365365
* Clear the in-sync bit 2^31. All get_sync_clock calls will
366366
* fail until the sync bit is turned back on. In addition
@@ -377,7 +377,7 @@ static void disable_sync_clock(void *dummy)
377377
*/
378378
static void enable_sync_clock(void)
379379
{
380-
atomic_t *sw_ptr = &__get_cpu_var(clock_sync_word);
380+
atomic_t *sw_ptr = this_cpu_ptr(&clock_sync_word);
381381
atomic_set_mask(0x80000000, sw_ptr);
382382
}
383383

0 commit comments

Comments
 (0)