linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Ondřej Bílka" <neleai@seznam.cz>
To: Andy Lutomirski <luto@amacapital.net>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Ben Maurer <bmaurer@fb.com>, Paul Turner <pjt@google.com>,
	Andrew Hunter <ahh@google.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>, rostedt <rostedt@goodmis.org>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Josh Triplett <josh@joshtriplett.org>,
	Lai Jiangshan <laijs@cn.fujitsu.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-api <linux-api@vger.kernel.org>,
	libc-alpha <libc-alpha@sourceware.org>
Subject: Re: [RFC PATCH] getcpu_cache system call: caching current CPU number (x86)
Date: Sat, 18 Jul 2015 12:35:03 +0200	[thread overview]
Message-ID: <20150718103503.GA30356@domone> (raw)
In-Reply-To: <CALCETrVY=kjeA_4pazy3BL+ekfcV6WHKw8e3z-LBxx_uP1bw2Q@mail.gmail.com>

On Fri, Jul 17, 2015 at 04:33:42PM -0700, Andy Lutomirski wrote:
> On Fri, Jul 17, 2015 at 4:28 PM, Ondřej Bílka <neleai@seznam.cz> wrote:
> > On Fri, Jul 17, 2015 at 11:48:14AM -0700, Linus Torvalds wrote:
> >>
> >> On x86, if you want per-cpu memory areas, you should basically plan on
> >> using segment registers instead (although other odd state has been
> >> used - there's been the people who use segment limits etc rather than
> >> the *pointer* itself, preferring to use "lsl" to get percpu data. You
> >> could also imaging hiding things in the vector state somewhere if you
> >> control your environment well enough).
> >>
> > Thats correct, problem is that you need some sort of hack like this on
> > archs that otherwise would need syscall to get tid/access tls variable.
> >
> > On x64 and archs that have register for tls this could be implemented
> > relatively easily.
> >
> > Kernel needs to allocate
> >
> > int running_cpu_for_tid[32768];
> >
> > On context switch it atomically writes to this table
> >
> > running_cpu_for_tid[tid] = cpu;
> >
> > This table is read-only accessible from userspace as mmaped file.
> >
> > Then userspace just needs to access it with three indirections like:
> >
> > __thread tid;
> >
> > char caches[CPU_MAX];
> > #define getcpu_cache caches[tid > 32768 ? get_cpu() : running_cpu_for_tid[tid]]
> >
> > With more complicated kernel interface you could eliminate one
> > indirection as we would use void * array instead and thread could do
> > syscall to register what values it should use for each thread.
> 
> Or we implement per-cpu segment registers so you can point gs directly
> at percpu data.  This is conceptually easy and has no weird ABI
> issues.  All it needs is an implementation and some good tests.
>
That only works if you have free register on your arch. As gs there was
rfc to teach gcc use it which could give bigger speedup. I didn't see
how much this could help yet so I am bit skeptical.

 
> I think the API should be "set gsbase to x + y*(cpu number)".  On
> x86_64, userspace just allocates a big swath of virtual space and
> populates it as needed.
> 
That wouldn't work well if two shared libraries want to use that. You
would need to use something like se it to 4096*cpu_number or so.

Also we didn't considered yet overhead, as this slows down everything a
bit due slower context switches. So will this needs to have widespread
performance improvement to be worthwhile. What are use cases to make
that pay itself?

  reply	other threads:[~2015-07-18 10:35 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-12 18:06 [RFC PATCH] getcpu_cache system call: caching current CPU number (x86) Mathieu Desnoyers
     [not found] ` <1436724386-30909-1-git-send-email-mathieu.desnoyers-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
2015-07-12 18:47   ` Josh Triplett
2015-07-13  3:40     ` Andy Lutomirski
2015-07-13 15:09     ` Mathieu Desnoyers
2015-07-13  3:38   ` Andy Lutomirski
     [not found]     ` <CALCETrV1suAbvMgD1jOEFyn3JcDE_hhi6X7+sGs9e3Oqw_6jUw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-07-13 15:27       ` Mathieu Desnoyers
     [not found]         ` <1050138282.1065.1436801252018.JavaMail.zimbra-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
2015-07-13 15:30           ` Andrew Hunter
     [not found]             ` <CADroS=7MnUULrjDeQtmscxjkpjCtti9V-HfFXU0sjKhi6PsaAg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-07-13 16:07               ` Mathieu Desnoyers
2015-07-13 18:36           ` Andy Lutomirski
2015-07-13 11:17   ` Ben Maurer
     [not found]     ` <5CDDBDF2D36D9F43B9F5E99003F6A0D48D5F39C6-f8hGUhss0nh9TZdEUguypQ2O0Ztt9esIQQ4Iyu8u01E@public.gmane.org>
2015-07-13 17:36       ` Mathieu Desnoyers
2015-07-14  9:34         ` Ben Maurer
     [not found]           ` <5CDDBDF2D36D9F43B9F5E99003F6A0D48D5F5DA0-f8hGUhss0nh9TZdEUguypQ2O0Ztt9esIQQ4Iyu8u01E@public.gmane.org>
2015-07-16 18:08             ` Mathieu Desnoyers
     [not found]               ` <549319255.383.1437070088597.JavaMail.zimbra-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
2015-07-16 19:27                 ` Andy Lutomirski
2015-07-17 10:21                   ` Ondřej Bílka
2015-07-17 15:53                     ` Andy Lutomirski
     [not found]                   ` <CALCETrWEKE=mow3vVh7C4r8CuGy_d5VOEz7KkpijuR5cpBfFtg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-07-17 18:48                     ` Linus Torvalds
     [not found]                       ` <CA+55aFz-VBnEKh0SPKgu8xV5=Zb+=6odybVUDoOYOknshbcFJA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-07-17 18:55                         ` Andy Lutomirski
     [not found]                           ` <CALCETrVNcLpZVATHOs-gZR9AMUSW_ScvXW_0oY=OnFHXXHLdaA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-07-17 19:11                             ` Linus Torvalds
2015-07-17 23:28                       ` Ondřej Bílka
2015-07-17 23:33                         ` Andy Lutomirski
2015-07-18 10:35                           ` Ondřej Bílka [this message]
     [not found]                           ` <CALCETrVY=kjeA_4pazy3BL+ekfcV6WHKw8e3z-LBxx_uP1bw2Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-07-20  8:35                             ` Florian Weimer
     [not found]                               ` <55ACB2DC.5010503-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-07-20 15:31                                 ` Andy Lutomirski
     [not found]                                   ` <CALCETrV9Vp5UUOb3e_R5tphyE-urBgTwQR2pFWUOOFnHqWXHKQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-07-20 15:32                                     ` Florian Weimer
     [not found]                                       ` <55AD14A4.6030101-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-07-20 17:41                                         ` Andy Lutomirski
     [not found]                                           ` <CALCETrUx6wFxmz+9TyW5bNgaMN0q180G8y9YOyq_D41sdhFaRQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-07-20 20:07                                             ` josh-iaAMLnmF4UmaiuxdJuQwMA
2015-07-21  7:55                                               ` Florian Weimer
     [not found]                                           ` <CA+55aFzMJkzydXb7uVv1iSUnp=539d43ghQaonGdzMoF7QLZBA@mail.gmail.com>
     [not found]                                             ` <CA+55aFzMJkzydXb7uVv1iSUnp=539d43ghQaonGdzMoF7QLZBA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-07-20 21:09                                               ` Andy Lutomirski
2015-07-20 22:39                                                 ` Linus Torvalds
     [not found]                                                   ` <CA+55aFwLZLeeN7UN82dyt=emQcNBc8qZPJAw5iqtAbBwFA7FPQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-07-21  0:25                                                     ` Mathieu Desnoyers
     [not found]                                                       ` <2010227315.699.1437438300542.JavaMail.zimbra-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
2015-07-21  7:30                                                         ` Ondřej Bílka
2015-07-21 12:58                                                           ` Mathieu Desnoyers
     [not found]                                                             ` <894137397.137.1437483493715.JavaMail.zimbra-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
2015-07-21 15:16                                                               ` Ondřej Bílka
2015-07-21 17:45                                                                 ` Mathieu Desnoyers
     [not found]                                                                   ` <1350114812.1035.1437500726799.JavaMail.zimbra-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
2015-07-21 18:00                                                                     ` Ondřej Bílka
2015-07-21 18:18                                                                       ` Mathieu Desnoyers
     [not found]                                                                         ` <2028561497.1088.1437502683664.JavaMail.zimbra-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
2015-07-22  7:53                                                                           ` Ondřej Bílka
2015-07-21  8:01                                                         ` Florian Weimer
2015-07-20 13:18                             ` Konstantin Khlebnikov
2015-07-18  7:34                         ` Rich Felker
     [not found]                           ` <20150718073433.GH1173-C3MtFaGISjmo6RMmaWD+6Sb1p8zYI1N1@public.gmane.org>
2015-07-18 10:51                             ` Ondřej Bílka
2015-07-18  9:47               ` Florian Weimer
     [not found]         ` <587954201.31.1436808992876.JavaMail.zimbra-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
2015-07-17 10:58           ` Ondřej Bílka
2015-07-17 16:03             ` Mathieu Desnoyers
     [not found]               ` <626545401.1010.1437149010438.JavaMail.zimbra-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
2015-07-17 22:43                 ` Ondřej Bílka
2015-07-18  2:43                   ` Mathieu Desnoyers

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=20150718103503.GA30356@domone \
    --to=neleai@seznam.cz \
    --cc=ahh@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=bmaurer@fb.com \
    --cc=josh@joshtriplett.org \
    --cc=laijs@cn.fujitsu.com \
    --cc=libc-alpha@sourceware.org \
    --cc=linux-api@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mingo@redhat.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=pjt@google.com \
    --cc=rostedt@goodmis.org \
    --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).