From: Arnd Bergmann <arnd@arndb•de>
To: linuxppc-dev@ozlabs•org
Cc: Thomas Gleixner <tglx@linutronix•de>,
mingo@elte•hu, Anton Blanchard <anton@samba•org>,
linux-kernel@vger•kernel.org
Subject: Re: [PATCH] Rework hrtimer_nanosleep to make sys_compat_nanosleep easier
Date: Mon, 15 Oct 2007 09:28:55 +0200 [thread overview]
Message-ID: <200710150928.56916.arnd@arndb.de> (raw)
In-Reply-To: <20071015063833.GA15396@kryten>
On Monday 15 October 2007, Anton Blanchard wrote:
> Pull the copy_to_user out of hrtimer_nanosleep and into the callers
> (common_nsleep, sys_nanosleep) in preparation for converting
> compat_sys_nanosleep to use hrtimers.
Looks good, except for two micro-optimization:
> Signed-off-by: Anton Blanchard <anton@samba•org>
Acked-by: Arnd Bergmann <arnd@arndb•de>
> @@ -1361,7 +1356,14 @@ sys_nanosleep(struct timespec __user *rqtp, struct=
timespec __user *rmtp)
> =A0=A0=A0=A0=A0=A0=A0=A0if (!timespec_valid(&tu))
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0return -EINVAL;
> =A0
> -=A0=A0=A0=A0=A0=A0=A0return hrtimer_nanosleep(&tu, rmtp, HRTIMER_MODE_RE=
L, CLOCK_MONOTONIC);
> +=A0=A0=A0=A0=A0=A0=A0ret =3D hrtimer_nanosleep(&tu, &rmt, HRTIMER_MODE_R=
EL, CLOCK_MONOTONIC);
> +
> +=A0=A0=A0=A0=A0=A0=A0if (ret && rmtp) {
> +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0if (copy_to_user(rmtp, &rmt=
, sizeof(*rmtp)))
> +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0ret=
urn -EFAULT;
> +=A0=A0=A0=A0=A0=A0=A0}
> +
> +=A0=A0=A0=A0=A0=A0=A0return ret;
> =A0}
> =A0
If it's common to call sys_nanosleep with a NULL rmtp argument, we could sa=
ve a
few cycles using=20
return hrtimer_nanosleep(&tu, rmtp ? &rmp : NULL, HRTIMER_MODE_REL,
CLOCK_MONOTONIC);
> diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
> index 57efe04..cce8c75 100644
> --- a/kernel/posix-timers.c
> +++ b/kernel/posix-timers.c
> @@ -980,9 +980,19 @@ sys_clock_getres(const clockid_t which_clock, struct=
timespec __user *tp)
> =A0static int common_nsleep(const clockid_t which_clock, int flags,
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =
struct timespec *tsave, struct timespec __user *rmtp)
> =A0{
> -=A0=A0=A0=A0=A0=A0=A0return hrtimer_nanosleep(tsave, rmtp, flags & TIMER=
_ABSTIME ?
> +=A0=A0=A0=A0=A0=A0=A0struct timespec rmt;
> +=A0=A0=A0=A0=A0=A0=A0int ret;
> +
> +=A0=A0=A0=A0=A0=A0=A0ret =3D hrtimer_nanosleep(tsave, &rmt, flags & TIME=
R_ABSTIME ?
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0 HRTIMER_MODE_ABS : HRTIMER_MODE_REL,
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0 which_clock);
> +
> +=A0=A0=A0=A0=A0=A0=A0if (ret && rmtp) {
> +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0if (copy_to_user(rmtp, &rmt=
, sizeof(*rmtp)))
> +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0ret=
urn -EFAULT;
> +=A0=A0=A0=A0=A0=A0=A0}
> +
> +=A0=A0=A0=A0=A0=A0=A0return ret;
> =A0}
I think it would be better here to propagate the move to a kernel *rmtp
down to sys_clock_nanosleep so we get the same optimization in
compat_sys_clock_nanosleep. That should probably also be a separate
patch. I can do one if you don't do it first.
Arnd <><
next prev parent reply other threads:[~2007-10-15 7:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-14 21:54 [PATCH] Hook compat_sys_nanosleep up to high res timer code Anton Blanchard
2007-10-14 22:28 ` Arnd Bergmann
2007-10-14 23:16 ` Anton Blanchard
2007-10-15 6:11 ` Thomas Gleixner
2007-10-15 6:38 ` [PATCH] Rework hrtimer_nanosleep to make sys_compat_nanosleep easier Anton Blanchard
2007-10-15 6:43 ` [PATCH] Hook compat_sys_nanosleep up to high res timer code Anton Blanchard
2007-10-15 7:28 ` Arnd Bergmann [this message]
2007-10-15 21:06 ` [PATCH] Rework hrtimer_nanosleep to make sys_compat_nanosleep easier Anton Blanchard
2007-10-15 21:13 ` [PATCH] Hook compat_sys_nanosleep up to high res timer code Anton Blanchard
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=200710150928.56916.arnd@arndb.de \
--to=arnd@arndb$(echo .)de \
--cc=anton@samba$(echo .)org \
--cc=linux-kernel@vger$(echo .)kernel.org \
--cc=linuxppc-dev@ozlabs$(echo .)org \
--cc=mingo@elte$(echo .)hu \
--cc=tglx@linutronix$(echo .)de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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