linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: David Laight <David.Laight@aculab.com>
Cc: Arnd Bergmann <arnd@kernel.org>,
	Matthew Wilcox <willy@infradead.org>,
	Linux FS-devel Mailing List <linux-fsdevel@vger.kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Andrew Morton <akpm@linux-foundation.org>,
	Soheil Hassas Yeganeh <soheil.kdev@gmail.com>,
	Arnd Bergmann <arnd@arndb.de>, Shuo Chen <shuochen@google.com>,
	linux-man <linux-man@vger.kernel.org>,
	Willem de Bruijn <willemb@google.com>
Subject: Re: [PATCH v3 1/2] epoll: add nsec timeout support with epoll_pwait2
Date: Thu, 19 Nov 2020 09:19:35 -0500	[thread overview]
Message-ID: <CAF=yD-+arBFuZCU3UDx0XKmUGaEz8P1EaDLPK0YFCz82MdwBcg@mail.gmail.com> (raw)
In-Reply-To: <893e8ed21e544d048bff7933013332a0@AcuMS.aculab.com>

On Wed, Nov 18, 2020 at 10:59 AM David Laight <David.Laight@aculab.com> wrote:
>
> From: Arnd Bergmann
> > Sent: 18 November 2020 15:38
> >
> > On Wed, Nov 18, 2020 at 4:10 PM Willem de Bruijn
> > <willemdebruijn.kernel@gmail.com> wrote:
> > > On Wed, Nov 18, 2020 at 10:00 AM Matthew Wilcox <willy@infradead.org> wrote:
> > > >
> > > > On Wed, Nov 18, 2020 at 09:46:15AM -0500, Willem de Bruijn wrote:
> > > > > -static inline struct timespec64 ep_set_mstimeout(long ms)
> > > > > +static inline struct timespec64 ep_set_nstimeout(s64 timeout)
> > > > >  {
> > > > > -     struct timespec64 now, ts = {
> > > > > -             .tv_sec = ms / MSEC_PER_SEC,
> > > > > -             .tv_nsec = NSEC_PER_MSEC * (ms % MSEC_PER_SEC),
> > > > > -     };
> > > > > +     struct timespec64 now, ts;
> > > > >
> > > > > +     ts = ns_to_timespec64(timeout);
> > > > >       ktime_get_ts64(&now);
> > > > >       return timespec64_add_safe(now, ts);
> > > > >  }
> > > >
> > > > Why do you pass around an s64 for timeout, converting it to and from
> > > > a timespec64 instead of passing around a timespec64?
> > >
> > > I implemented both approaches. The alternative was no simpler.
> > > Conversion in existing epoll_wait, epoll_pwait and epoll_pwait
> > > (compat) becomes a bit more complex and adds a stack variable there if
> > > passing the timespec64 by reference. And in ep_poll the ternary
> > > timeout test > 0, 0, < 0 now requires checking both tv_secs and
> > > tv_nsecs. Based on that, I found this simpler. But no strong
> > > preference.
> >
> > The 64-bit division can be fairly expensive on 32-bit architectures,
> > at least when it doesn't get optimized into a multiply+shift.
>
> I'd have thought you'd want to do everything in 64bit nanosecs.
> Conversions to/from any of the 'timespec' structure are expensive.

I took another look at this.

The only real reason for the timespec64 is that
select_estimate_accuracy takes that type. Which makes sense, because
do_select does.

But for epoll, this is inefficient: in ep_set_mstimeout it calls
ktime_get_ts64 to convert timeout to an offset from current time, only
to pass it to select_estimate_accuracy to then perform another
ktime_get_ts64 and subtract this to get back to (approx.) the original
timeout.

How about a separate patch that adds epoll_estimate_accuracy with
the same rules (wrt rt_task, current->timer_slack, nice and upper bound)
but taking an s64 timeout.

One variation, since it is approximate, I suppose we could even replace
division by a right shift?

After that, using s64 everywhere is indeed much simpler. And with that
I will revise the new epoll_pwait2 interface to take a long long
instead of struct timespec.

Apologies for the delay. I forgot that I'm only subscribed to netdev@
in my main email account.

  reply	other threads:[~2020-11-19 14:20 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-18 14:46 [PATCH v3 0/2] add epoll_pwait2 syscall Willem de Bruijn
2020-11-18 14:46 ` [PATCH v3 1/2] epoll: add nsec timeout support with epoll_pwait2 Willem de Bruijn
2020-11-18 15:00   ` Matthew Wilcox
2020-11-18 15:10     ` Willem de Bruijn
2020-11-18 15:37       ` Arnd Bergmann
2020-11-18 15:59         ` David Laight
2020-11-19 14:19           ` Willem de Bruijn [this message]
2020-11-19 14:31             ` Matthew Wilcox
2020-11-19 15:37               ` Willem de Bruijn
2020-11-19 15:45               ` Arnd Bergmann
2020-11-19 20:13                 ` Willem de Bruijn
2020-11-20  8:13                   ` Arnd Bergmann
2020-11-20 16:01                     ` Willem de Bruijn
2020-11-20 19:23                       ` Arnd Bergmann
2020-11-20 22:28                         ` Willem de Bruijn
2020-11-21  9:27                           ` Arnd Bergmann
2020-12-10 17:33                             ` Willem de Bruijn
2020-12-10 20:34                               ` Arnd Bergmann
2020-12-10 22:59                                 ` Willem de Bruijn
2021-01-11 20:06                                   ` Willem de Bruijn
2020-11-18 16:21   ` Willem de Bruijn
2020-11-18 16:50     ` Arnd Bergmann
2020-11-19  3:22       ` Willem de Bruijn
2020-11-18 14:46 ` [PATCH manpages RFC] epoll_wait.2: add epoll_pwait2 Willem de Bruijn
2020-11-18 14:46 ` [PATCH v3 2/2] selftests/filesystems: expand epoll with epoll_pwait2 Willem de Bruijn

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='CAF=yD-+arBFuZCU3UDx0XKmUGaEz8P1EaDLPK0YFCz82MdwBcg@mail.gmail.com' \
    --to=willemdebruijn.kernel@gmail.com \
    --cc=David.Laight@aculab.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=arnd@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-man@vger.kernel.org \
    --cc=shuochen@google.com \
    --cc=soheil.kdev@gmail.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willemb@google.com \
    --cc=willy@infradead.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).