Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1290663 > unrolled thread
| Started by | Andi Kleen <andi@firstfloor.org> |
|---|---|
| First post | 2015-12-13 19:20 +0100 |
| Last post | 2015-12-13 21:30 +0100 |
| Articles | 4 — 3 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: [RFC PATCH 1/2] thread_local_abi system call: caching current CPU number (x86) Andi Kleen <andi@firstfloor.org> - 2015-12-13 19:20 +0100
Re: [RFC PATCH 1/2] thread_local_abi system call: caching current CPU number (x86) Mathieu Desnoyers <mathieu.desnoyers@efficios.com> - 2015-12-13 21:00 +0100
Re: [RFC PATCH 1/2] thread_local_abi system call: caching current CPU number (x86) Andi Kleen <andi@firstfloor.org> - 2015-12-13 21:20 +0100
Re: [RFC PATCH 1/2] thread_local_abi system call: caching current CPU number (x86) Andy Lutomirski <luto@amacapital.net> - 2015-12-13 21:30 +0100
| From | Andi Kleen <andi@firstfloor.org> |
|---|---|
| Date | 2015-12-13 19:20 +0100 |
| Subject | Re: [RFC PATCH 1/2] thread_local_abi system call: caching current CPU number (x86) |
| Message-ID | <qFjpw-3nE-13@gated-at.bofh.it> |
> This getcpu cache is an alternative to the sched_getcpu() vdso which has > a few benefits: Note the first version of getcpu() I proposed had a cache. But it was rejected. > - It is faster to do a memory read that to call a vDSO, > - This cached value can be read from within an inline assembly, which > makes it a useful building block for restartable sequences. On x86 we already have the de-facto ABI of using LSL with the magic segment directly. While that is a few cycles slower than a memory load I question the difference is big enough to justify a new system call, and risk slow page fault in context switches. BTW the vdso could be also optimized I think. For example glibc today does some stupid (slow) things with it, like doing double iindirect jumps. -Andi -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
|---|---|
| Date | 2015-12-13 21:00 +0100 |
| Message-ID | <qFkYi-4eF-5@gated-at.bofh.it> |
| In reply to | #1290663 |
----- On Dec 13, 2015, at 1:15 PM, Andi Kleen andi@firstfloor.org wrote: >> This getcpu cache is an alternative to the sched_getcpu() vdso which has >> a few benefits: > > > Note the first version of getcpu() I proposed had a cache. But it was > rejected. > >> - It is faster to do a memory read that to call a vDSO, >> - This cached value can be read from within an inline assembly, which >> makes it a useful building block for restartable sequences. > > On x86 we already have the de-facto ABI of using LSL with the magic > segment directly. While that is a few cycles slower than a memory load > I question the difference is big enough to justify a new system call, > and risk slow page fault in context switches. In the context of restartable sequences [1] [2], the goal is to turn atomic operations on per-cpu data into a sequence of simple load/store operations. Therefore, improving getcpu from 12ns to 0.3ns will have a significant impact there. Those will be used in memory allocators, RCU read-side in userspace, and tracing fast path, where we can expect significant speedups even for those few cycles per call. Moreover, AFAIU, restartable sequences cannot do the function call required by the vdso while within the c.s.: those need to entirely fit within an inline assembly. So this CPU number caching actually enables restartable sequences, whereas the vdso approach cannot be used in that context. Regarding your concern about slow page fault in context switches, this updated patch takes care of it: the context switch is only setting TIF_NOTIFY_RESUME, which lets the cache value update be performed on return to userspace. Finally, even if overall this new system call is not deemed sufficiently interesting on x86, other popular architectures such as ARM32 don't have any vDSO for getcpu at the moment, mainly because they don't have similar segment selector tricks, and I'm not aware of other solutions than caching the CPU value for those architectures. So we might very well end up having to implement this system call for other architectures anyway. > > BTW the vdso could be also optimized I think. For example glibc today > does some stupid (slow) things with it, like doing double iindirect > jumps. I suspect that most of the difference between the vDSO approach and CPU number caching is simply the function call required for the vDSO. I doubt there is much to be done on this front. Thanks, Mathieu [1] https://lwn.net/Articles/664645/ [2] https://lkml.org/lkml/2015/10/27/1095 > > -Andi -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Andi Kleen <andi@firstfloor.org> |
|---|---|
| Date | 2015-12-13 21:20 +0100 |
| Message-ID | <qFlhD-4AO-3@gated-at.bofh.it> |
| In reply to | #1290681 |
> In the context of restartable sequences [1] [2], the goal is to turn > atomic operations on per-cpu data into a sequence of simple load/store > operations. Therefore, improving getcpu from 12ns to 0.3ns will have a I don't think LSL is 12ns. It's a few cycles. > Moreover, AFAIU, restartable sequences cannot do the function call > required by the vdso while within the c.s.: those need to entirely fit > within an inline assembly. So this CPU number caching actually enables > restartable sequences, whereas the vdso approach cannot be used in that > context. You can use the LSL directly though. In practice people already rely on it (and it's very cheap on the kernel side), so it's a defacto ABI and could be documented. So it's not function call vs load, but LSL vs load. > > Finally, even if overall this new system call is not deemed sufficiently > interesting on x86, other popular architectures such as ARM32 don't have > any vDSO for getcpu at the moment, mainly because they don't have similar > segment selector tricks, and I'm not aware of other solutions than caching Has that been confirmed by architecture experts? Maybe there is some trick there too. > I suspect that most of the difference between the vDSO approach and > CPU number caching is simply the function call required for the vDSO. > I doubt there is much to be done on this front. Not sure about that. Basic function calls are not that expensive. Right now there is some baggage but that could be optimized. The only unavoidable overhead would be the ABI register clobbering. -Andi -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Andy Lutomirski <luto@amacapital.net> |
|---|---|
| Date | 2015-12-13 21:30 +0100 |
| Subject | Re: [RFC PATCH 1/2] thread_local_abi system call: caching current CPU number (x86) |
| Message-ID | <qFlrk-4EA-9@gated-at.bofh.it> |
| In reply to | #1290686 |
On Sun, Dec 13, 2015 at 12:18 PM, Andi Kleen <andi@firstfloor.org> wrote: >> In the context of restartable sequences [1] [2], the goal is to turn >> atomic operations on per-cpu data into a sequence of simple load/store >> operations. Therefore, improving getcpu from 12ns to 0.3ns will have a > > I don't think LSL is 12ns. It's a few cycles. 11ns on my Skylale laptop. (rdtscp is now almost as fast as lsl.) FWIW, a failed LSL is 55ns. We could play sneaky tricks and use SGDT instead. Long term on x86, I think we should be using per-cpu segments, though. > >> Moreover, AFAIU, restartable sequences cannot do the function call >> required by the vdso while within the c.s.: those need to entirely fit >> within an inline assembly. So this CPU number caching actually enables >> restartable sequences, whereas the vdso approach cannot be used in that >> context. > > You can use the LSL directly though. In practice people already rely > on it (and it's very cheap on the kernel side), so it's a defacto ABI > and could be documented. > > So it's not function call vs load, but LSL vs load. I do wonder if the function call itself is cheap enough that we should do this entirely within the vDSO. Unfortunately, the vDSO can't use TLS, so that's not so easy without trickery. --Andy -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web