Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86: Use this_cpu_ops to optimize code

Go through x86 code and replace __get_cpu_var and get_cpu_var
instances that refer to a scalar and are not used for address
determinations.

Cc: Yinghai Lu <yinghai@kernel.org>
Cc: Ingo Molnar <mingo@elte.hu>
Acked-by: Tejun Heo <tj@kernel.org>
Acked-by: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Tejun Heo <tj@kernel.org>

Tejun Heo 0a3aee0d 7c839120

+57 -62
+1 -1
arch/x86/include/asm/debugreg.h
··· 94 94 95 95 static inline int hw_breakpoint_active(void) 96 96 { 97 - return __get_cpu_var(cpu_dr7) & DR_GLOBAL_ENABLE_MASK; 97 + return __this_cpu_read(cpu_dr7) & DR_GLOBAL_ENABLE_MASK; 98 98 } 99 99 100 100 extern void aout_dump_debugregs(struct user *dump);
+2 -2
arch/x86/kernel/apic/io_apic.c
··· 2302 2302 unsigned int irr; 2303 2303 struct irq_desc *desc; 2304 2304 struct irq_cfg *cfg; 2305 - irq = __get_cpu_var(vector_irq)[vector]; 2305 + irq = __this_cpu_read(vector_irq[vector]); 2306 2306 2307 2307 if (irq == -1) 2308 2308 continue; ··· 2336 2336 apic->send_IPI_self(IRQ_MOVE_CLEANUP_VECTOR); 2337 2337 goto unlock; 2338 2338 } 2339 - __get_cpu_var(vector_irq)[vector] = -1; 2339 + __this_cpu_write(vector_irq[vector], -1); 2340 2340 unlock: 2341 2341 raw_spin_unlock(&desc->lock); 2342 2342 }
+12 -12
arch/x86/kernel/apic/nmi.c
··· 306 306 */ 307 307 void cpu_nmi_set_wd_enabled(void) 308 308 { 309 - __get_cpu_var(wd_enabled) = 1; 309 + __this_cpu_write(wd_enabled, 1); 310 310 } 311 311 312 312 void setup_apic_nmi_watchdog(void *unused) 313 313 { 314 - if (__get_cpu_var(wd_enabled)) 314 + if (__this_cpu_read(wd_enabled)) 315 315 return; 316 316 317 317 /* cheap hack to support suspend/resume */ ··· 322 322 switch (nmi_watchdog) { 323 323 case NMI_LOCAL_APIC: 324 324 if (lapic_watchdog_init(nmi_hz) < 0) { 325 - __get_cpu_var(wd_enabled) = 0; 325 + __this_cpu_write(wd_enabled, 0); 326 326 return; 327 327 } 328 328 /* FALL THROUGH */ 329 329 case NMI_IO_APIC: 330 - __get_cpu_var(wd_enabled) = 1; 330 + __this_cpu_write(wd_enabled, 1); 331 331 atomic_inc(&nmi_active); 332 332 } 333 333 } ··· 337 337 /* only support LOCAL and IO APICs for now */ 338 338 if (!nmi_watchdog_active()) 339 339 return; 340 - if (__get_cpu_var(wd_enabled) == 0) 340 + if (__this_cpu_read(wd_enabled) == 0) 341 341 return; 342 342 if (nmi_watchdog == NMI_LOCAL_APIC) 343 343 lapic_watchdog_stop(); 344 344 else 345 345 __acpi_nmi_disable(NULL); 346 - __get_cpu_var(wd_enabled) = 0; 346 + __this_cpu_write(wd_enabled, 0); 347 347 atomic_dec(&nmi_active); 348 348 } 349 349 ··· 403 403 404 404 sum = get_timer_irqs(cpu); 405 405 406 - if (__get_cpu_var(nmi_touch)) { 407 - __get_cpu_var(nmi_touch) = 0; 406 + if (__this_cpu_read(nmi_touch)) { 407 + __this_cpu_write(nmi_touch, 0); 408 408 touched = 1; 409 409 } 410 410 ··· 427 427 touched = 1; 428 428 429 429 /* if the none of the timers isn't firing, this cpu isn't doing much */ 430 - if (!touched && __get_cpu_var(last_irq_sum) == sum) { 430 + if (!touched && __this_cpu_read(last_irq_sum) == sum) { 431 431 /* 432 432 * Ayiee, looks like this CPU is stuck ... 433 433 * wait a few IRQs (5 seconds) before doing the oops ... ··· 440 440 die_nmi("BUG: NMI Watchdog detected LOCKUP", 441 441 regs, panic_on_timeout); 442 442 } else { 443 - __get_cpu_var(last_irq_sum) = sum; 443 + __this_cpu_write(last_irq_sum, sum); 444 444 __this_cpu_write(alert_counter, 0); 445 445 } 446 446 447 447 /* see if the nmi watchdog went off */ 448 - if (!__get_cpu_var(wd_enabled)) 448 + if (!__this_cpu_read(wd_enabled)) 449 449 return rc; 450 450 switch (nmi_watchdog) { 451 451 case NMI_LOCAL_APIC: ··· 467 467 468 468 static void enable_ioapic_nmi_watchdog_single(void *unused) 469 469 { 470 - __get_cpu_var(wd_enabled) = 1; 470 + __this_cpu_write(wd_enabled, 1); 471 471 atomic_inc(&nmi_active); 472 472 __acpi_nmi_enable(NULL); 473 473 }
+4 -4
arch/x86/kernel/apic/x2apic_uv_x.c
··· 118 118 else if (!strcmp(oem_table_id, "UVX")) 119 119 uv_system_type = UV_X2APIC; 120 120 else if (!strcmp(oem_table_id, "UVH")) { 121 - __get_cpu_var(x2apic_extra_bits) = 122 - nodeid << (uvh_apicid.s.pnode_shift - 1); 121 + __this_cpu_write(x2apic_extra_bits, 122 + nodeid << (uvh_apicid.s.pnode_shift - 1)); 123 123 uv_system_type = UV_NON_UNIQUE_APIC; 124 124 uv_set_apicid_hibit(); 125 125 return 1; ··· 284 284 unsigned int id; 285 285 286 286 WARN_ON(preemptible() && num_online_cpus() > 1); 287 - id = x | __get_cpu_var(x2apic_extra_bits); 287 + id = x | __this_cpu_read(x2apic_extra_bits); 288 288 289 289 return id; 290 290 } ··· 376 376 377 377 static __cpuinit void set_x2apic_extra_bits(int pnode) 378 378 { 379 - __get_cpu_var(x2apic_extra_bits) = (pnode << 6); 379 + __this_cpu_write(x2apic_extra_bits, (pnode << 6)); 380 380 } 381 381 382 382 /*
+1 -1
arch/x86/kernel/cpu/cpufreq/powernow-k8.c
··· 1377 1377 static void query_values_on_cpu(void *_err) 1378 1378 { 1379 1379 int *err = _err; 1380 - struct powernow_k8_data *data = __get_cpu_var(powernow_data); 1380 + struct powernow_k8_data *data = __this_cpu_read(powernow_data); 1381 1381 1382 1382 *err = query_current_values_with_pending_wait(data); 1383 1383 }
+3 -3
arch/x86/kernel/cpu/mcheck/mce.c
··· 326 326 327 327 static int msr_to_offset(u32 msr) 328 328 { 329 - unsigned bank = __get_cpu_var(injectm.bank); 329 + unsigned bank = __this_cpu_read(injectm.bank); 330 330 331 331 if (msr == rip_msr) 332 332 return offsetof(struct mce, ip); ··· 346 346 { 347 347 u64 v; 348 348 349 - if (__get_cpu_var(injectm).finished) { 349 + if (__this_cpu_read(injectm.finished)) { 350 350 int offset = msr_to_offset(msr); 351 351 352 352 if (offset < 0) ··· 369 369 370 370 static void mce_wrmsrl(u32 msr, u64 v) 371 371 { 372 - if (__get_cpu_var(injectm).finished) { 372 + if (__this_cpu_read(injectm.finished)) { 373 373 int offset = msr_to_offset(msr); 374 374 375 375 if (offset >= 0)
+11 -16
arch/x86/kernel/cpu/perf_event.c
··· 968 968 969 969 static void x86_pmu_enable_event(struct perf_event *event) 970 970 { 971 - struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); 972 - if (cpuc->enabled) 971 + if (__this_cpu_read(cpu_hw_events.enabled)) 973 972 __x86_pmu_enable_event(&event->hw, 974 973 ARCH_PERFMON_EVENTSEL_ENABLE); 975 974 } ··· 1242 1243 break; 1243 1244 case DIE_NMIUNKNOWN: 1244 1245 this_nmi = percpu_read(irq_stat.__nmi_count); 1245 - if (this_nmi != __get_cpu_var(pmu_nmi).marked) 1246 + if (this_nmi != __this_cpu_read(pmu_nmi.marked)) 1246 1247 /* let the kernel handle the unknown nmi */ 1247 1248 return NOTIFY_DONE; 1248 1249 /* ··· 1266 1267 this_nmi = percpu_read(irq_stat.__nmi_count); 1267 1268 if ((handled > 1) || 1268 1269 /* the next nmi could be a back-to-back nmi */ 1269 - ((__get_cpu_var(pmu_nmi).marked == this_nmi) && 1270 - (__get_cpu_var(pmu_nmi).handled > 1))) { 1270 + ((__this_cpu_read(pmu_nmi.marked) == this_nmi) && 1271 + (__this_cpu_read(pmu_nmi.handled) > 1))) { 1271 1272 /* 1272 1273 * We could have two subsequent back-to-back nmis: The 1273 1274 * first handles more than one counter, the 2nd ··· 1278 1279 * handling more than one counter. We will mark the 1279 1280 * next (3rd) and then drop it if unhandled. 1280 1281 */ 1281 - __get_cpu_var(pmu_nmi).marked = this_nmi + 1; 1282 - __get_cpu_var(pmu_nmi).handled = handled; 1282 + __this_cpu_write(pmu_nmi.marked, this_nmi + 1); 1283 + __this_cpu_write(pmu_nmi.handled, handled); 1283 1284 } 1284 1285 1285 1286 return NOTIFY_STOP; ··· 1453 1454 */ 1454 1455 static void x86_pmu_start_txn(struct pmu *pmu) 1455 1456 { 1456 - struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); 1457 - 1458 1457 perf_pmu_disable(pmu); 1459 - cpuc->group_flag |= PERF_EVENT_TXN; 1460 - cpuc->n_txn = 0; 1458 + __this_cpu_or(cpu_hw_events.group_flag, PERF_EVENT_TXN); 1459 + __this_cpu_write(cpu_hw_events.n_txn, 0); 1461 1460 } 1462 1461 1463 1462 /* ··· 1465 1468 */ 1466 1469 static void x86_pmu_cancel_txn(struct pmu *pmu) 1467 1470 { 1468 - struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); 1469 - 1470 - cpuc->group_flag &= ~PERF_EVENT_TXN; 1471 + __this_cpu_and(cpu_hw_events.group_flag, ~PERF_EVENT_TXN); 1471 1472 /* 1472 1473 * Truncate the collected events. 1473 1474 */ 1474 - cpuc->n_added -= cpuc->n_txn; 1475 - cpuc->n_events -= cpuc->n_txn; 1475 + __this_cpu_sub(cpu_hw_events.n_added, __this_cpu_read(cpu_hw_events.n_txn)); 1476 + __this_cpu_sub(cpu_hw_events.n_events, __this_cpu_read(cpu_hw_events.n_txn)); 1476 1477 perf_pmu_enable(pmu); 1477 1478 } 1478 1479
+2 -2
arch/x86/kernel/cpu/perf_event_intel.c
··· 649 649 struct hw_perf_event *hwc = &event->hw; 650 650 651 651 if (unlikely(hwc->idx == X86_PMC_IDX_FIXED_BTS)) { 652 - if (!__get_cpu_var(cpu_hw_events).enabled) 652 + if (!__this_cpu_read(cpu_hw_events.enabled)) 653 653 return; 654 654 655 655 intel_pmu_enable_bts(hwc->config); ··· 679 679 680 680 static void intel_pmu_reset(void) 681 681 { 682 - struct debug_store *ds = __get_cpu_var(cpu_hw_events).ds; 682 + struct debug_store *ds = __this_cpu_read(cpu_hw_events.ds); 683 683 unsigned long flags; 684 684 int idx; 685 685
+3 -3
arch/x86/kernel/ftrace.c
··· 167 167 168 168 void ftrace_nmi_enter(void) 169 169 { 170 - __get_cpu_var(save_modifying_code) = modifying_code; 170 + __this_cpu_write(save_modifying_code, modifying_code); 171 171 172 - if (!__get_cpu_var(save_modifying_code)) 172 + if (!__this_cpu_read(save_modifying_code)) 173 173 return; 174 174 175 175 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) { ··· 183 183 184 184 void ftrace_nmi_exit(void) 185 185 { 186 - if (!__get_cpu_var(save_modifying_code)) 186 + if (!__this_cpu_read(save_modifying_code)) 187 187 return; 188 188 189 189 /* Finish all executions before clearing nmi_running */
+6 -6
arch/x86/kernel/hw_breakpoint.c
··· 122 122 return -EBUSY; 123 123 124 124 set_debugreg(info->address, i); 125 - __get_cpu_var(cpu_debugreg[i]) = info->address; 125 + __this_cpu_write(cpu_debugreg[i], info->address); 126 126 127 127 dr7 = &__get_cpu_var(cpu_dr7); 128 128 *dr7 |= encode_dr7(i, info->len, info->type); ··· 397 397 398 398 void hw_breakpoint_restore(void) 399 399 { 400 - set_debugreg(__get_cpu_var(cpu_debugreg[0]), 0); 401 - set_debugreg(__get_cpu_var(cpu_debugreg[1]), 1); 402 - set_debugreg(__get_cpu_var(cpu_debugreg[2]), 2); 403 - set_debugreg(__get_cpu_var(cpu_debugreg[3]), 3); 400 + set_debugreg(__this_cpu_read(cpu_debugreg[0]), 0); 401 + set_debugreg(__this_cpu_read(cpu_debugreg[1]), 1); 402 + set_debugreg(__this_cpu_read(cpu_debugreg[2]), 2); 403 + set_debugreg(__this_cpu_read(cpu_debugreg[3]), 3); 404 404 set_debugreg(current->thread.debugreg6, 6); 405 - set_debugreg(__get_cpu_var(cpu_dr7), 7); 405 + set_debugreg(__this_cpu_read(cpu_dr7), 7); 406 406 } 407 407 EXPORT_SYMBOL_GPL(hw_breakpoint_restore); 408 408
+3 -3
arch/x86/kernel/irq.c
··· 234 234 exit_idle(); 235 235 irq_enter(); 236 236 237 - irq = __get_cpu_var(vector_irq)[vector]; 237 + irq = __this_cpu_read(vector_irq[vector]); 238 238 239 239 if (!handle_irq(irq, regs)) { 240 240 ack_APIC_irq(); ··· 350 350 for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS; vector++) { 351 351 unsigned int irr; 352 352 353 - if (__get_cpu_var(vector_irq)[vector] < 0) 353 + if (__this_cpu_read(vector_irq[vector]) < 0) 354 354 continue; 355 355 356 356 irr = apic_read(APIC_IRR + (vector / 32 * 0x10)); 357 357 if (irr & (1 << (vector % 32))) { 358 - irq = __get_cpu_var(vector_irq)[vector]; 358 + irq = __this_cpu_read(vector_irq[vector]); 359 359 360 360 data = irq_get_irq_data(irq); 361 361 raw_spin_lock(&desc->lock);
+2 -2
arch/x86/kernel/irq_32.c
··· 79 79 u32 *isp, arg1, arg2; 80 80 81 81 curctx = (union irq_ctx *) current_thread_info(); 82 - irqctx = __get_cpu_var(hardirq_ctx); 82 + irqctx = __this_cpu_read(hardirq_ctx); 83 83 84 84 /* 85 85 * this is where we switch to the IRQ stack. However, if we are ··· 166 166 167 167 if (local_softirq_pending()) { 168 168 curctx = current_thread_info(); 169 - irqctx = __get_cpu_var(softirq_ctx); 169 + irqctx = __this_cpu_read(softirq_ctx); 170 170 irqctx->tinfo.task = curctx->task; 171 171 irqctx->tinfo.previous_esp = current_stack_pointer; 172 172
+1 -1
arch/x86/kernel/smpboot.c
··· 1377 1377 1378 1378 mb(); 1379 1379 /* Ack it */ 1380 - __get_cpu_var(cpu_state) = CPU_DEAD; 1380 + __this_cpu_write(cpu_state, CPU_DEAD); 1381 1381 1382 1382 /* 1383 1383 * With physical CPU hotplug, we should halt the cpu
+1 -1
arch/x86/kernel/tsc.c
··· 659 659 660 660 local_irq_save(flags); 661 661 662 - __get_cpu_var(cyc2ns_offset) = 0; 662 + __this_cpu_write(cyc2ns_offset, 0); 663 663 offset = cyc2ns_suspend - sched_clock(); 664 664 665 665 for_each_possible_cpu(cpu)
+4 -4
arch/x86/kvm/x86.c
··· 981 981 if (kvm_tsc_changes_freq()) 982 982 printk_once(KERN_WARNING 983 983 "kvm: unreliable cycle conversion on adjustable rate TSC\n"); 984 - ret = nsec * __get_cpu_var(cpu_tsc_khz); 984 + ret = nsec * __this_cpu_read(cpu_tsc_khz); 985 985 do_div(ret, USEC_PER_SEC); 986 986 return ret; 987 987 } ··· 1066 1066 local_irq_save(flags); 1067 1067 kvm_get_msr(v, MSR_IA32_TSC, &tsc_timestamp); 1068 1068 kernel_ns = get_kernel_ns(); 1069 - this_tsc_khz = __get_cpu_var(cpu_tsc_khz); 1069 + this_tsc_khz = __this_cpu_read(cpu_tsc_khz); 1070 1070 1071 1071 if (unlikely(this_tsc_khz == 0)) { 1072 1072 local_irq_restore(flags); ··· 4432 4432 4433 4433 static void tsc_bad(void *info) 4434 4434 { 4435 - __get_cpu_var(cpu_tsc_khz) = 0; 4435 + __this_cpu_write(cpu_tsc_khz, 0); 4436 4436 } 4437 4437 4438 4438 static void tsc_khz_changed(void *data) ··· 4446 4446 khz = cpufreq_quick_get(raw_smp_processor_id()); 4447 4447 if (!khz) 4448 4448 khz = tsc_khz; 4449 - __get_cpu_var(cpu_tsc_khz) = khz; 4449 + __this_cpu_write(cpu_tsc_khz, khz); 4450 4450 } 4451 4451 4452 4452 static int kvmclock_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
+1 -1
arch/x86/oprofile/nmi_int.c
··· 143 143 144 144 inline int op_x86_phys_to_virt(int phys) 145 145 { 146 - return __get_cpu_var(switch_index) + phys; 146 + return __this_cpu_read(switch_index) + phys; 147 147 } 148 148 149 149 inline int op_x86_virt_to_phys(int virt)