From: Segher Boessenkool <segher@kernel.crashing.org>
To: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>,
Santosh Sivaraj <santosh@fossix.org>,
linuxppc-dev <linuxppc-dev@lists.ozlabs.org>,
Srikar Dronamraju <srikar@linux.vnet.ibm.com>,
Segher Boessenkool <segher.boessenkool@nl.ibm.com>
Subject: Re: [PATCH] powerpc/vdso64: Add support for CLOCK_{REALTIME/MONOTONIC}_COARSE
Date: Thu, 20 Jul 2017 17:03:07 -0500 [thread overview]
Message-ID: <20170720220306.GD13471@gate.crashing.org> (raw)
In-Reply-To: <1500585459.10674.8.camel@kernel.crashing.org>
On Fri, Jul 21, 2017 at 07:17:39AM +1000, Benjamin Herrenschmidt wrote:
> > Great patch! Always good to see asm replaced with C.
>
> Yeah ewll ... when C becomes some kind of weird glorifed asm like
> below, I don't see much of a point ;-)
Yeah.
> > > diff --git a/arch/powerpc/kernel/vdso64/gettime.c b/arch/powerpc/kernel/vdso64/gettime.c
> > > new file mode 100644
> > > index 0000000..01f411f
> > > --- /dev/null
> > > +++ b/arch/powerpc/kernel/vdso64/gettime.c
> > > @@ -0,0 +1,162 @@
> >
> > ...
> > > +static notrace int gettime_syscall_fallback(clockid_t clk_id,
> > > + struct timespec *tp)
> > > +{
> > > + register clockid_t id asm("r3") = clk_id;
> > > + register struct timespec *t asm("r4") = tp;
> > > + register int nr asm("r0") = __NR_clock_gettime;
> > > + register int ret asm("r3");
> >
> > I guess this works. I've always been a bit nervous about register
> > variables TBH.
>
> Does it really work ? That really makes me nervous too, I woudn't do
> this without a strong ack from a toolchain person... Segher ?
Local register variables work perfectly well, but only for one thing:
those variables are guaranteed to be in those registers, _as arguments
to an asm_.
> > > + asm volatile("sc"
> > > + : "=r" (ret)
> > > + : "r"(nr), "r"(id), "r"(t)
> > > + : "memory");
> >
> > Not sure we need the memory clobber?
> >
> > It can clobber more registers than that though.
It needs the memory clobber (if the system call accessess any of "your"
memory). You need more register clobbers: also for most CR fields,
CTR, etc.
One trick that often works is doing the system call from within an
assembler function that uses the C ABI, since that has almost the same
calling conventions.
Something as simple as
.globl syscall42
syscall42:
li 0,42
sc
blr
(and yeah handle the CR bit 3 thing somehow)
and declare it as
int syscall42(some_type r3_arg, another_type r4_arg);
Inline asm is good when you want the asm code inlined into the callers,
potentially with arguments optimised etc. The only overhead making the
syscall a function has is that single blr; the only optimisation you
miss is you could potentially load GPR0 a bit earlier (and you can get
a tiny bit more scheduling flexibility).
Segher
next prev parent reply other threads:[~2017-07-20 22:03 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-20 9:58 [PATCH] powerpc/vdso64: Add support for CLOCK_{REALTIME/MONOTONIC}_COARSE Santosh Sivaraj
2017-07-20 13:18 ` Michael Ellerman
2017-07-20 21:17 ` Benjamin Herrenschmidt
2017-07-20 22:03 ` Segher Boessenkool [this message]
2017-07-21 3:05 ` Anton Blanchard
2017-07-21 4:40 ` Santosh Sivaraj
2017-07-21 6:05 ` Benjamin Herrenschmidt
2017-07-21 9:09 ` [PATCH v2] " Santosh Sivaraj
2017-07-25 6:56 ` [PATCH v3] " Santosh Sivaraj
2017-07-25 10:07 ` Benjamin Herrenschmidt
2017-07-25 13:47 ` Santosh Sivaraj
2017-07-26 2:02 ` Benjamin Herrenschmidt
2017-08-11 8:23 ` [PATCH] " Santosh Sivaraj
2017-07-22 19:29 ` kbuild test robot
2017-07-23 15:12 ` kbuild test robot
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=20170720220306.GD13471@gate.crashing.org \
--to=segher@kernel.crashing.org \
--cc=benh@kernel.crashing.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mpe@ellerman.id.au \
--cc=santosh@fossix.org \
--cc=segher.boessenkool@nl.ibm.com \
--cc=srikar@linux.vnet.ibm.com \
/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).