linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Christoph Lameter <cl@linux.com>
Cc: Tejun Heo <tj@kernel.org>,
	akpm@linuxfoundation.org,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Ingo Molnar <mingo@redhat.com>,
	linux-arch@vger.kernel.org, Steven Rostedt <srostedt@redhat.com>,
	linux-kernel@vger.kernel.org,
	Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Subject: Re: [guv v2 08/31] tracing: Replace __get_cpu_var uses
Date: Wed, 28 Aug 2013 15:48:04 -0400	[thread overview]
Message-ID: <20130828154804.20f4dde6@gandalf.local.home> (raw)
In-Reply-To: <00000140bc5f00c2-8e9ffffa-de46-4329-aef3-317c258828bd-000000@email.amazonses.com>

On Mon, 26 Aug 2013 20:44:37 +0000
Christoph Lameter <cl@linux.com> wrote:

> __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.
> 
> Others usage 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 a 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 and explicit address calculation using this_cpu_ptr()
> or into a use of this_cpu operations that use the offset. Thereby address calcualtions are avoided
> and less registers are used when code is generated.
> 
> At the end of the patchset all uses of __get_cpu_var have been removed so the macro is removed too.
> 
> The patchset 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.

You should limit the width of the change log to 76 characters.

I fixed it for now.

> 
> 
> 
> 
> 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, u);
> 	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(this_cpu_ptr(&y), x, 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)
> 
> 
> Signed-off-by: Christoph Lameter <cl@linux.com>
> 
> Index: linux/include/linux/kprobes.h
> ===================================================================
> --- linux.orig/include/linux/kprobes.h	2013-08-26 14:25:53.000000000 -0500
> +++ linux/include/linux/kprobes.h	2013-08-26 14:26:29.460993659 -0500
> @@ -329,7 +329,7 @@ static inline void reset_current_kprobe(
>  
>  static inline struct kprobe_ctlblk *get_kprobe_ctlblk(void)
>  {
> -	return (&__get_cpu_var(kprobe_ctlblk));
> +	return this_cpu_ptr(&kprobe_ctlblk);
>  }

Masami,

Can you give me an Acked-by: for this.

Thanks!

-- Steve

>  
>  int register_kprobe(struct kprobe *p);
> Index: linux/kernel/trace/ftrace.c
> ===================================================================
> --- linux.orig/kernel/trace/ftrace.c	2013-08-26 14:25:53.000000000 -0500
> +++ linux/kernel/trace/ftrace.c	2013-08-26 14:26:29.460993659 -0500
> @@ -870,7 +870,7 @@ function_profile_call(unsigned long ip,
>  
>  	local_irq_save(flags);
>  
> -	stat = &__get_cpu_var(ftrace_profile_stats);
> +	stat = this_cpu_ptr(&ftrace_profile_stats);
>  	if (!stat->hash || !ftrace_profile_enabled)
>  		goto out;
>  
> @@ -901,7 +901,7 @@ static void profile_graph_return(struct
>  	unsigned long flags;
>  
>  	local_irq_save(flags);
> -	stat = &__get_cpu_var(ftrace_profile_stats);
> +	stat = this_cpu_ptr(&ftrace_profile_stats);
>  	if (!stat->hash || !ftrace_profile_enabled)
>  		goto out;
>  
> Index: linux/kernel/trace/trace.c
> ===================================================================
> --- linux.orig/kernel/trace/trace.c	2013-08-26 14:25:53.000000000 -0500
> +++ linux/kernel/trace/trace.c	2013-08-26 14:26:29.464993617 -0500
> @@ -1676,7 +1676,7 @@ static void __ftrace_trace_stack(struct
>  	 */
>  	barrier();
>  	if (use_stack == 1) {
> -		trace.entries		= &__get_cpu_var(ftrace_stack).calls[0];
> +		trace.entries		= this_cpu_ptr(ftrace_stack.calls);
>  		trace.max_entries	= FTRACE_STACK_MAX_ENTRIES;
>  
>  		if (regs)

  parent reply	other threads:[~2013-08-28 19:48 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20130826204351.725357339@linux.com>
2013-08-26 20:44 ` [guv v2 02/31] percpu: Make __verify_pcu_ptr handle per cpu pointers to arrays Christoph Lameter
2013-08-26 20:44 ` [guv v2 03/31] Coccinelle script for __get_cpu_var conversion Christoph Lameter
2013-08-26 20:44 ` [guv v2 04/31] net: Replace __get_cpu_var uses Christoph Lameter
2013-08-26 20:44 ` [guv v2 05/31] time: " Christoph Lameter
2013-08-26 20:44   ` Christoph Lameter
2013-08-26 20:44 ` [guv v2 06/31] scheduler: " Christoph Lameter
2013-08-26 20:44   ` Christoph Lameter
2013-08-26 20:44 ` [guv v2 08/31] tracing: " Christoph Lameter
2013-08-26 20:44   ` Christoph Lameter
2013-08-28 19:48   ` Steven Rostedt [this message]
2013-08-29  3:44     ` Masami Hiramatsu
2013-08-29  3:44       ` Masami Hiramatsu
2013-08-29 16:35     ` Christoph Lameter
2013-08-30  7:00       ` Ingo Molnar
2013-08-26 20:44 ` [guv v2 09/31] block: " Christoph Lameter
2013-08-26 20:44   ` Christoph Lameter
2013-08-26 20:44 ` [guv v2 10/31] rcu: " Christoph Lameter
2013-08-26 20:44   ` Christoph Lameter
2013-08-26 20:44 ` [guv v2 07/31] mm: " Christoph Lameter
2013-08-26 20:44   ` Christoph Lameter
2013-08-26 20:44 ` [guv v2 11/31] percpu: " Christoph Lameter
2013-08-26 20:44   ` Christoph Lameter
2013-08-26 20:44 ` [guv v2 13/31] kernel misc: " Christoph Lameter
2013-08-26 20:44   ` Christoph Lameter
2013-08-26 20:44 ` [guv v2 14/31] drivers: " Christoph Lameter
2013-08-26 20:44 ` [guv v2 12/31] watchdog: " Christoph Lameter
2013-08-26 20:44   ` Christoph Lameter
2013-08-26 20:44 ` [guv v2 17/31] mips: " Christoph Lameter
2013-08-26 20:44   ` Christoph Lameter
2013-08-26 20:44 ` [guv v2 15/31] zcache/zsmalloc: " Christoph Lameter
2013-08-26 20:44 ` [guv v2 16/31] x86: " Christoph Lameter
2013-08-26 20:44   ` Christoph Lameter
2013-08-26 20:44 ` [guv v2 18/31] s390: " Christoph Lameter
2013-08-28  6:27   ` Heiko Carstens
2013-08-26 20:44 ` [guv v2 01/31] x86: Use this_cpu_inc/dec for debug registers Christoph Lameter
2013-08-26 20:44   ` Christoph Lameter
2013-08-26 20:44 ` [guv v2 19/31] ia64: Replace __get_cpu_var uses Christoph Lameter
2013-08-26 20:44   ` Christoph Lameter
2013-08-26 20:44 ` [guv v2 20/31] powerpc: " Christoph Lameter
2013-08-27  8:44   ` Geert Uytterhoeven
2013-08-27  8:44     ` Geert Uytterhoeven
2013-08-27 15:37     ` Christoph Lameter
2013-08-26 20:44 ` [guv v2 21/31] sparc: " Christoph Lameter
2013-08-26 20:44 ` [guv v2 22/31] arm: " Christoph Lameter
2013-08-27  9:41   ` Catalin Marinas
2013-08-26 20:56 ` [guv v2 25/31] avr32: " Christoph Lameter
2013-08-27  6:58   ` Hans-Christian Egtvedt
2013-08-27  6:58     ` Hans-Christian Egtvedt
2013-08-26 20:56 ` [guv v2 23/31] tile: " Christoph Lameter
2013-08-26 20:56   ` Christoph Lameter
2013-08-26 22:22   ` Chris Metcalf
2013-08-27 14:48     ` Christoph Lameter
2013-08-28 17:19       ` Chris Metcalf
2013-08-28 17:54         ` Christoph Lameter
2013-08-28 18:13           ` Chris Metcalf
2013-08-28 18:22             ` Christoph Lameter
2013-08-30 16:01             ` Chris Metcalf
2013-08-26 20:56 ` [guv v2 29/31] parisc: " Christoph Lameter
2013-08-26 21:16 ` [guv v2 31/31] Remove __get_cpu_var and __raw_get_cpu_var macros Christoph Lameter
2013-08-26 21:16 ` [guv v2 24/31] blackfin: Replace __get_cpu_var uses Christoph Lameter
2013-08-26 21:16 ` [guv v2 26/31] alpha: Replace __get_cpu_var Christoph Lameter
2013-08-26 21:16   ` Christoph Lameter
2013-08-26 21:56 ` [guv v2 30/31] metag: Replace __get_cpu_var uses Christoph Lameter
2013-08-26 21:56   ` Christoph Lameter
2013-08-27  9:53   ` James Hogan
2013-08-26 21:56 ` [guv v2 28/31] arc: Replace __get_cpu_var uses throughout the kernel Christoph Lameter
     [not found]   ` <521C2A9F.3070400@synopsys.com>
     [not found]     ` <00000140c05d28b7-f0a2bc86-fe85-40f7-b627-32664cd616a4-000000@email.amazonses.com>
2013-08-28  4:24       ` Vineet Gupta
2013-08-28 13:46         ` Christoph Lameter
2013-08-26 21:56 ` [guv v2 27/31] sh: " Christoph Lameter
2013-09-02 21:35 ` [guv v2 04/31] net: Replace __get_cpu_var uses David Howells
2013-09-03  3:33   ` David Miller
2013-09-03  3:33     ` David Miller
2013-09-03 14:21     ` Christoph Lameter
2013-09-03 14:20   ` Christoph Lameter
2013-09-03 20:39   ` David Howells

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=20130828154804.20f4dde6@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=akpm@linuxfoundation.org \
    --cc=cl@linux.com \
    --cc=fweisbec@gmail.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=mingo@redhat.com \
    --cc=srostedt@redhat.com \
    --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).