linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@zytor.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Mike Galbraith <bitbucket@online.de>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Ingo Molnar <mingo@kernel.org>, Andi Kleen <ak@linux.intel.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Arjan van de Ven <arjan@linux.intel.com>,
	linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org
Subject: Re: [RFC][PATCH 0/5] preempt_count rework
Date: Wed, 14 Aug 2013 09:14:34 -0700	[thread overview]
Message-ID: <520BACEA.50604@zytor.com> (raw)
In-Reply-To: <20130814160632.GJ24092@twins.programming.kicks-ass.net>

On 08/14/2013 09:06 AM, Peter Zijlstra wrote:
> On Wed, Aug 14, 2013 at 05:39:11PM +0200, Mike Galbraith wrote:
>> On Wed, 2013-08-14 at 06:47 -0700, H. Peter Anvin wrote:
>>
>>> On x86, you never want to take the address of a percpu variable if you
>>> can avoid it, as you end up generating code like:
>>>
>>> 	movq %fs:0,%rax
>>> 	subl $1,(%rax)
>>
>> Hmmm..
>>
>> #define cpu_rq(cpu)             (&per_cpu(runqueues, (cpu)))
>> #define this_rq()               (&__get_cpu_var(runqueues))
>>
>> ffffffff81438c7f:       48 c7 c3 80 11 01 00    mov    $0x11180,%rbx
>>         /*
>>          * this_rq must be evaluated again because prev may have moved
>>          * CPUs since it called schedule(), thus the 'rq' on its stack
>>          * frame will be invalid.
>>          */
>>         finish_task_switch(this_rq(), prev);
>> ffffffff81438c86:       e8 25 b4 c0 ff          callq  ffffffff810440b0 <finish_task_switch>
>>                  * The context switch have flipped the stack from under us
>>                  * and restored the local variables which were saved when
>>                  * this task called schedule() in the past. prev == current
>>                  * is still correct, but it can be moved to another cpu/rq.
>>                  */
>>                 cpu = smp_processor_id();
>> ffffffff81438c8b:       65 8b 04 25 b8 c5 00    mov    %gs:0xc5b8,%eax
>> ffffffff81438c92:       00
>>                 rq = cpu_rq(cpu);
>> ffffffff81438c93:       48 98                   cltq
>> ffffffff81438c95:       48 03 1c c5 00 f3 bb    add    -0x7e440d00(,%rax,8),%rbx
>>
>> ..so could the rq = cpu_rq(cpu) sequence be improved cycle expenditure
>> wise by squirreling rq pointer away in a percpu this_rq, and replacing
>> cpu_rq(cpu) above with a __this_cpu_read(this_rq) version of this_rq()?
> 
> Well, this_rq() should already get you that. The above code sucks for
> using cpu_rq() when we know cpu == smp_processor_id().
> 

Even so, this_rq() uses __get_cpu_var() and takes its address, which
turns into a sequence like:

	leaq __percpu_runqueues(%rip),%rax
	addq %gs:this_cpu_off,%rax

... which is better than the above but still more heavyweight than it
would be if the pointer was itself a percpu variable.

	-hpa

  reply	other threads:[~2013-08-14 16:16 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-14 13:15 [RFC][PATCH 0/5] preempt_count rework Peter Zijlstra
2013-08-14 13:15 ` Peter Zijlstra
2013-08-14 13:15 ` [RFC][PATCH 1/5] sched: Introduce preempt_count accessor functions Peter Zijlstra
2013-08-14 13:15   ` Peter Zijlstra
2013-08-14 13:15 ` [RFC][PATCH 2/5] sched: Add NEED_RESCHED to the preempt_count Peter Zijlstra
2013-08-14 13:15   ` Peter Zijlstra
2013-08-14 13:15 ` [RFC][PATCH 3/5] sched, arch: Create asm/preempt.h Peter Zijlstra
2013-08-14 13:15   ` Peter Zijlstra
2013-08-14 13:15 ` [RFC][PATCH 4/5] sched: Create more preempt_count accessors Peter Zijlstra
2013-08-14 13:15   ` Peter Zijlstra
2013-08-14 13:15 ` [RFC][PATCH 5/5] sched, x86: Provide a per-cpu preempt_count implementation Peter Zijlstra
2013-08-14 13:47 ` [RFC][PATCH 0/5] preempt_count rework H. Peter Anvin
2013-08-14 15:39   ` Mike Galbraith
2013-08-14 15:39     ` Mike Galbraith
2013-08-14 15:43     ` H. Peter Anvin
2013-08-15  9:01       ` Mike Galbraith
2013-08-14 16:06     ` Peter Zijlstra
2013-08-14 16:14       ` H. Peter Anvin [this message]
2013-08-14 16:52         ` Peter Zijlstra
2013-08-14 16:58           ` H. Peter Anvin
2013-08-14 16:04   ` Peter Zijlstra
2013-08-14 17:31     ` Peter Zijlstra
2013-08-14 16:48 ` Andi Kleen
2013-08-14 16:48   ` Andi Kleen
2013-08-14 16:55   ` Peter Zijlstra
2013-08-14 17:12     ` Andi Kleen

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=520BACEA.50604@zytor.com \
    --to=hpa@zytor.com \
    --cc=ak@linux.intel.com \
    --cc=arjan@linux.intel.com \
    --cc=bitbucket@online.de \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.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).