aboutsummaryrefslogtreecommitdiffstats
path: root/arch/alpha/kernel
diff options
context:
space:
mode:
authorChristoph Lameter <cl@linux.com>2014-08-17 13:30:48 -0400
committerTejun Heo <tj@kernel.org>2014-08-26 13:45:53 -0400
commit2999a4b354c24985268f9310bc9522ff358453a8 (patch)
tree4587919ee0c98ef80b52e137b1cceca0e4a0bfba /arch/alpha/kernel
parent6065a244a039a23d933e4b803a4e052da2849208 (diff)
alpha: Replace __get_cpu_var
__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 #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: Ivan Kokshaysky <ink@jurassic.park.msu.ru> Cc: Matt Turner <mattst88@gmail.com> Acked-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Christoph Lameter <cl@linux.com> Signed-off-by: Tejun Heo <tj@kernel.org>
Diffstat (limited to 'arch/alpha/kernel')
-rw-r--r--arch/alpha/kernel/perf_event.c16
-rw-r--r--arch/alpha/kernel/time.c6
2 files changed, 11 insertions, 11 deletions
diff --git a/arch/alpha/kernel/perf_event.c b/arch/alpha/kernel/perf_event.c
index c52e7f0ee5f6..5c218aa3f3df 100644
--- a/arch/alpha/kernel/perf_event.c
+++ b/arch/alpha/kernel/perf_event.c
@@ -431,7 +431,7 @@ static void maybe_change_configuration(struct cpu_hw_events *cpuc)
431 */ 431 */
432static int alpha_pmu_add(struct perf_event *event, int flags) 432static int alpha_pmu_add(struct perf_event *event, int flags)
433{ 433{
434 struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); 434 struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
435 struct hw_perf_event *hwc = &event->hw; 435 struct hw_perf_event *hwc = &event->hw;
436 int n0; 436 int n0;
437 int ret; 437 int ret;
@@ -483,7 +483,7 @@ static int alpha_pmu_add(struct perf_event *event, int flags)
483 */ 483 */
484static void alpha_pmu_del(struct perf_event *event, int flags) 484static void alpha_pmu_del(struct perf_event *event, int flags)
485{ 485{
486 struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); 486 struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
487 struct hw_perf_event *hwc = &event->hw; 487 struct hw_perf_event *hwc = &event->hw;
488 unsigned long irq_flags; 488 unsigned long irq_flags;
489 int j; 489 int j;
@@ -531,7 +531,7 @@ static void alpha_pmu_read(struct perf_event *event)
531static void alpha_pmu_stop(struct perf_event *event, int flags) 531static void alpha_pmu_stop(struct perf_event *event, int flags)
532{ 532{
533 struct hw_perf_event *hwc = &event->hw; 533 struct hw_perf_event *hwc = &event->hw;
534 struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); 534 struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
535 535
536 if (!(hwc->state & PERF_HES_STOPPED)) { 536 if (!(hwc->state & PERF_HES_STOPPED)) {
537 cpuc->idx_mask &= ~(1UL<<hwc->idx); 537 cpuc->idx_mask &= ~(1UL<<hwc->idx);
@@ -551,7 +551,7 @@ static void alpha_pmu_stop(struct perf_event *event, int flags)
551static void alpha_pmu_start(struct perf_event *event, int flags) 551static void alpha_pmu_start(struct perf_event *event, int flags)
552{ 552{
553 struct hw_perf_event *hwc = &event->hw; 553 struct hw_perf_event *hwc = &event->hw;
554 struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); 554 struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
555 555
556 if (WARN_ON_ONCE(!(hwc->state & PERF_HES_STOPPED))) 556 if (WARN_ON_ONCE(!(hwc->state & PERF_HES_STOPPED)))
557 return; 557 return;
@@ -724,7 +724,7 @@ static int alpha_pmu_event_init(struct perf_event *event)
724 */ 724 */
725static void alpha_pmu_enable(struct pmu *pmu) 725static void alpha_pmu_enable(struct pmu *pmu)
726{ 726{
727 struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); 727 struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
728 728
729 if (cpuc->enabled) 729 if (cpuc->enabled)
730 return; 730 return;
@@ -750,7 +750,7 @@ static void alpha_pmu_enable(struct pmu *pmu)
750 750
751static void alpha_pmu_disable(struct pmu *pmu) 751static void alpha_pmu_disable(struct pmu *pmu)
752{ 752{
753 struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); 753 struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
754 754
755 if (!cpuc->enabled) 755 if (!cpuc->enabled)
756 return; 756 return;
@@ -814,8 +814,8 @@ static void alpha_perf_event_irq_handler(unsigned long la_ptr,
814 struct hw_perf_event *hwc; 814 struct hw_perf_event *hwc;
815 int idx, j; 815 int idx, j;
816 816
817 __get_cpu_var(irq_pmi_count)++; 817 __this_cpu_inc(irq_pmi_count);
818 cpuc = &__get_cpu_var(cpu_hw_events); 818 cpuc = this_cpu_ptr(&cpu_hw_events);
819 819
820 /* Completely counting through the PMC's period to trigger a new PMC 820 /* Completely counting through the PMC's period to trigger a new PMC
821 * overflow interrupt while in this interrupt routine is utterly 821 * overflow interrupt while in this interrupt routine is utterly
diff --git a/arch/alpha/kernel/time.c b/arch/alpha/kernel/time.c
index ee39cee8064c..643a9dcdf093 100644
--- a/arch/alpha/kernel/time.c
+++ b/arch/alpha/kernel/time.c
@@ -56,9 +56,9 @@ unsigned long est_cycle_freq;
56 56
57DEFINE_PER_CPU(u8, irq_work_pending); 57DEFINE_PER_CPU(u8, irq_work_pending);
58 58
59#define set_irq_work_pending_flag() __get_cpu_var(irq_work_pending) = 1 59#define set_irq_work_pending_flag() __this_cpu_write(irq_work_pending, 1)
60#define test_irq_work_pending() __get_cpu_var(irq_work_pending) 60#define test_irq_work_pending() __this_cpu_read(irq_work_pending)
61#define clear_irq_work_pending() __get_cpu_var(irq_work_pending) = 0 61#define clear_irq_work_pending() __this_cpu_write(irq_work_pending, 0)
62 62
63void arch_irq_work_raise(void) 63void arch_irq_work_raise(void)
64{ 64{