From: Christoph Lameter <cl@linux.com>
To: Tejun Heo <tj@kernel.org>
Cc: akpm@linuxfoundation.org, rostedt@goodmis.org,
linux-kernel@vger.kernel.org, Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
Richard Henderson <rth@twiddle.net>,
Ivan Kokshaysky <ink@jurassic.park.msu.ru>,
Matt Turner <mattst88@gmail.com>
Subject: [PATCH 38/41] alpha: Replace __get_cpu_var
Date: Tue, 03 Dec 2013 17:33:10 -0600 [thread overview]
Message-ID: <20131203233305.012919046@linux.com> (raw)
In-Reply-To: 20131203233232.928771708@linux.com
[-- Attachment #1: this_alpha --]
[-- Type: text/plain, Size: 6047 bytes --]
__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: Richard Henderson <rth@twiddle.net>
CC: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Signed-off-by: Christoph Lameter <cl@linux.com>
Index: linux/arch/alpha/kernel/perf_event.c
===================================================================
--- linux.orig/arch/alpha/kernel/perf_event.c 2013-12-02 16:08:01.194316776 -0600
+++ linux/arch/alpha/kernel/perf_event.c 2013-12-02 16:08:01.194316776 -0600
@@ -431,7 +431,7 @@ static void maybe_change_configuration(s
*/
static int alpha_pmu_add(struct perf_event *event, int flags)
{
- struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+ struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
struct hw_perf_event *hwc = &event->hw;
int n0;
int ret;
@@ -483,7 +483,7 @@ static int alpha_pmu_add(struct perf_eve
*/
static void alpha_pmu_del(struct perf_event *event, int flags)
{
- struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+ struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
struct hw_perf_event *hwc = &event->hw;
unsigned long irq_flags;
int j;
@@ -531,7 +531,7 @@ static void alpha_pmu_read(struct perf_e
static void alpha_pmu_stop(struct perf_event *event, int flags)
{
struct hw_perf_event *hwc = &event->hw;
- struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+ struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
if (!(hwc->state & PERF_HES_STOPPED)) {
cpuc->idx_mask &= ~(1UL<<hwc->idx);
@@ -551,7 +551,7 @@ static void alpha_pmu_stop(struct perf_e
static void alpha_pmu_start(struct perf_event *event, int flags)
{
struct hw_perf_event *hwc = &event->hw;
- struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+ struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
if (WARN_ON_ONCE(!(hwc->state & PERF_HES_STOPPED)))
return;
@@ -724,7 +724,7 @@ static int alpha_pmu_event_init(struct p
*/
static void alpha_pmu_enable(struct pmu *pmu)
{
- struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+ struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
if (cpuc->enabled)
return;
@@ -750,7 +750,7 @@ static void alpha_pmu_enable(struct pmu
static void alpha_pmu_disable(struct pmu *pmu)
{
- struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+ struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
if (!cpuc->enabled)
return;
@@ -815,7 +815,7 @@ static void alpha_perf_event_irq_handler
int idx, j;
__this_cpu_inc(irq_pmi_count);
- cpuc = &__get_cpu_var(cpu_hw_events);
+ cpuc = this_cpu_ptr(&cpu_hw_events);
/* Completely counting through the PMC's period to trigger a new PMC
* overflow interrupt while in this interrupt routine is utterly
Index: linux/arch/alpha/kernel/time.c
===================================================================
--- linux.orig/arch/alpha/kernel/time.c 2013-12-02 16:08:01.194316776 -0600
+++ linux/arch/alpha/kernel/time.c 2013-12-02 16:08:01.194316776 -0600
@@ -56,9 +56,9 @@ unsigned long est_cycle_freq;
DEFINE_PER_CPU(u8, irq_work_pending);
-#define set_irq_work_pending_flag() __get_cpu_var(irq_work_pending) = 1
-#define test_irq_work_pending() __get_cpu_var(irq_work_pending)
-#define clear_irq_work_pending() __get_cpu_var(irq_work_pending) = 0
+#define set_irq_work_pending_flag() __this_cpu_write(irq_work_pending, 1)
+#define test_irq_work_pending() __this_cpu_read(irq_work_pending)
+#define clear_irq_work_pending() __this_cpu_writeirq_work_pending, 0)
void arch_irq_work_raise(void)
{
next prev parent reply other threads:[~2013-12-03 23:39 UTC|newest]
Thread overview: 84+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-03 23:32 [PATCH 00/41] percpu: Consistent per cpu operations V1 Christoph Lameter
2013-12-03 23:32 ` [PATCH 01/41] mm: Replace __get_cpu_var uses with this_cpu_ptr Christoph Lameter
2014-08-26 17:59 ` Tejun Heo
2013-12-03 23:32 ` [PATCH 02/41] tracing: " Christoph Lameter
2014-08-26 17:59 ` Tejun Heo
2014-09-17 16:12 ` Steven Rostedt
2013-12-03 23:32 ` [PATCH 03/41] percpu: Replace __get_cpu_var " Christoph Lameter
2014-08-26 18:00 ` Tejun Heo
2013-12-03 23:32 ` [PATCH 04/41] kernel misc: Replace __get_cpu_var uses Christoph Lameter
2014-08-26 18:00 ` Tejun Heo
2013-12-03 23:32 ` [PATCH 05/41] drivers/char/random: " Christoph Lameter
2014-08-26 18:00 ` Tejun Heo
2013-12-03 23:32 ` [PATCH 06/41] drivers/cpuidle: Replace __get_cpu_var uses for address calculation Christoph Lameter
2014-08-26 18:01 ` Tejun Heo
2013-12-03 23:32 ` [PATCH 07/41] drivers/oprofile: " Christoph Lameter
2013-12-03 23:32 ` [PATCH 08/41] drivers/leds: Replace __get_cpu_var use through this_cpu_ptr Christoph Lameter
2014-08-26 18:01 ` Tejun Heo
2013-12-03 23:32 ` [PATCH 09/41] drivers/clocksource: Replace __get_cpu_var used for address calculation Christoph Lameter
2014-08-26 18:02 ` Tejun Heo
2013-12-03 23:32 ` [PATCH 10/41] staging/zsmalloc: Replace instances of using __get_cpu_var " Christoph Lameter
2014-08-26 18:02 ` Tejun Heo
2013-12-03 23:32 ` [PATCH 11/41] parisc: Replace __get_cpu_var uses " Christoph Lameter
2013-12-04 0:10 ` James Bottomley
2013-12-05 18:46 ` Christoph Lameter
[not found] ` <alpine.DEB.2.02.1312051244540.26098@gentwo.org>
2013-12-05 20:58 ` quilt 0.60 does not include CCed email without name Christoph Lameter
2013-12-06 8:18 ` Martin Quinson
2013-12-08 9:19 ` Andreas Gruenbacher
2013-12-08 9:52 ` Martin Quinson
2013-12-03 23:32 ` [PATCH 12/41] metag: Replace __get_cpu_var uses for address calculation Christoph Lameter
2013-12-03 23:32 ` [PATCH 13/41] percpu: Add raw_cpu_ops Christoph Lameter
2013-12-10 15:34 ` Tejun Heo
2013-12-10 15:45 ` Ingo Molnar
2013-12-10 15:49 ` Tejun Heo
2013-12-10 15:55 ` Ingo Molnar
2013-12-10 18:13 ` Christoph Lameter
2013-12-10 18:31 ` Ingo Molnar
2013-12-10 19:32 ` Tejun Heo
2013-12-10 20:02 ` Christoph Lameter
2013-12-11 15:12 ` Ingo Molnar
2013-12-11 17:48 ` Christoph Lameter
2013-12-11 17:52 ` Ingo Molnar
2013-12-11 18:30 ` Christoph Lameter
2013-12-10 18:11 ` Christoph Lameter
2013-12-03 23:32 ` [PATCH 14/41] x86: Rename __this_cpu_xxx_# operations to raw_cpu_xxx_# Christoph Lameter
2013-12-03 23:32 ` [PATCH 15/41] mm: Use raw_cpu ops for determining current NUMA node Christoph Lameter
2013-12-03 23:32 ` [PATCH 16/41] modules: Use raw_cpu_write for initialization of per cpu refcount Christoph Lameter
2013-12-03 23:32 ` [PATCH 17/41] net:i Replace __this_cpu_inc in route.c with raw_cpu_inc Christoph Lameter
2013-12-03 23:32 ` [PATCH 18/41] percpu: Add preemption checks to __this_cpu ops Christoph Lameter
2013-12-03 23:32 ` [PATCH 19/41] time: Replace __get_cpu_var uses Christoph Lameter
2013-12-03 23:32 ` [PATCH 20/41] scheduler: Replace __get_cpu_var with this_cpu_ptr Christoph Lameter
2013-12-03 23:32 ` [PATCH 21/41] block: Replace __this_cpu_ptr with raw_cpu_ptr Christoph Lameter
2013-12-04 2:20 ` Jens Axboe
2013-12-04 16:38 ` Christoph Lameter
2013-12-04 16:51 ` Jens Axboe
2013-12-03 23:32 ` [PATCH 22/41] rcu: Replace __this_cpu_ptr uses " Christoph Lameter
2013-12-04 1:12 ` Paul E. McKenney
2013-12-04 16:37 ` Christoph Lameter
2013-12-03 23:32 ` [PATCH 23/41] watchdog: Replace __raw_get_cpu_var uses Christoph Lameter
2013-12-03 23:32 ` [PATCH 24/41] net: Replace get_cpu_var through this_cpu_ptr Christoph Lameter
2013-12-03 23:32 ` [PATCH 25/41] drivers/net/ethernet/tile: Replace __get_cpu_var uses for address calculation Christoph Lameter
2013-12-09 20:22 ` Chris Metcalf
2013-12-03 23:32 ` [PATCH 26/41] md: Replace __this_cpu_ptr with raw_cpu_ptr Christoph Lameter
2013-12-03 23:32 ` [PATCH 27/41] irqchips: Replace __this_cpu_ptr uses Christoph Lameter
2013-12-03 23:33 ` [PATCH 28/41] x86: Replace __get_cpu_var uses Christoph Lameter
2013-12-03 23:33 ` [PATCH 29/41] arm: Replace __this_cpu_ptr with raw_cpu_ptr Christoph Lameter
2013-12-03 23:33 ` [PATCH 30/41] mips: Replace __get_cpu_var uses Christoph Lameter
2013-12-03 23:33 ` [PATCH 31/41] s390: " Christoph Lameter
2013-12-03 23:33 ` [PATCH 32/41] ia64: " Christoph Lameter
2013-12-03 23:33 ` [PATCH 33/41] powerpc: " Christoph Lameter
2013-12-03 23:33 ` [PATCH 34/41] sparc: " Christoph Lameter
2013-12-03 23:33 ` [PATCH 35/41] tile: " Christoph Lameter
2013-12-09 20:52 ` Chris Metcalf
2013-12-10 15:23 ` Christoph Lameter
2013-12-03 23:33 ` [PATCH 36/41] blackfin: " Christoph Lameter
2013-12-03 23:33 ` [PATCH 37/41] avr32: Replace __get_cpu_var with __this_cpu_write Christoph Lameter
2013-12-03 23:33 ` Christoph Lameter [this message]
2013-12-03 23:33 ` [PATCH 39/41] sh: Replace __get_cpu_var uses Christoph Lameter
2013-12-03 23:33 ` [PATCH 40/41] Remove __get_cpu_var and __raw_get_cpu_var macros [only in 3.15] Christoph Lameter
2013-12-03 23:33 ` [PATCH 41/41] percpu: Remove __this_cpu_ptr Christoph Lameter
2013-12-04 8:40 ` [PATCH 00/41] percpu: Consistent per cpu operations V1 Ingo Molnar
2013-12-04 16:43 ` Christoph Lameter
2013-12-04 17:02 ` Ingo Molnar
2013-12-05 19:09 ` Christoph Lameter
-- strict thread matches above, loose matches on Subject: below --
2014-01-17 15:18 [PATCH 00/41] percpu: Consistent per cpu operations V3 Christoph Lameter
2014-01-17 15:18 ` [PATCH 38/41] alpha: Replace __get_cpu_var Christoph Lameter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20131203233305.012919046@linux.com \
--to=cl@linux.com \
--cc=akpm@linuxfoundation.org \
--cc=ink@jurassic.park.msu.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=mattst88@gmail.com \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=rth@twiddle.net \
--cc=tglx@linutronix.de \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).