public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Willy Tarreau <w@1wt.eu>
To: Mark Brown <broonie@kernel.org>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] tools/nolibc: Implement msleep()
Date: Wed, 12 May 2021 07:33:56 +0200	[thread overview]
Message-ID: <20210512053356.GA20749@1wt.eu> (raw)
In-Reply-To: <20210511110159.57286-1-broonie@kernel.org>

Hi Mark,

On Tue, May 11, 2021 at 12:01:59PM +0100, Mark Brown wrote:
> +static __attribute__((unused))
> +void msleep(unsigned int msecs)
> +{
> +	struct timeval my_timeval = { 0, msecs * 1000 };
> +
> +	sys_select(0, 0, 0, 0, &my_timeval);
> +}
> +

Just a quick question, is there any reason for not keeping most of the
precision like this and allow applications to use it beyond 4294 seconds
like this ?

	struct timeval my_timeval = { msecs / 1000, (msecs % 1000) * 1000 };

Another thing that comes to my mind is that sleep() returns the remaining
number of seconds if the syscall was interrupted, and I think it could be
very useful in small tests programs to do the same at the subsecond level
in simple scheduling loops for example. Copying what we're doing in sleep()
we could have this:

        if (sys_select(0, 0, 0, 0, &my_timeval) < 0)
                return my_timeval.tv_sec * 1000 + (my_timeval.tv_usec + 999) / 1000;
        else
                return 0;

And since that's an inline function it will be optimized away if the result
is not used anyway, resulting in the same code as the void version in this
case.

What do you think ?

Thanks!
Willy

      reply	other threads:[~2021-05-12  5:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-11 11:01 [PATCH] tools/nolibc: Implement msleep() Mark Brown
2021-05-12  5:33 ` Willy Tarreau [this message]

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=20210512053356.GA20749@1wt.eu \
    --to=w@1wt.eu \
    --cc=broonie@kernel.org \
    --cc=linux-kernel@vger.kernel.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