Re: [RFC PATCH 03/10] perf workqueue: add threadpool start and stop functions
From: Arnaldo Carvalho de Melo
Date: Fri Jul 16 2021 - 12:29:25 EST
Em Fri, Jul 16, 2021 at 03:53:58PM +0200, Riccardo Mancini escreveu:
> On Thu, 2021-07-15 at 16:48 -0700, Namhyung Kim wrote:
> > On Tue, Jul 13, 2021 at 5:11 AM Riccardo Mancini <rickyman7@xxxxxxxxx> wrote:
> > > +++ b/tools/perf/util/workqueue/threadpool.c
> > [SNIP]
> > > +/**
> > > + * wait_thread - receive ack from thread
> > > + *
> > > + * NB: call only from main thread!
> > > + */
> > > +static int wait_thread(struct thread_struct *thread)
> > > +{
> > > + int res;
> > > + enum thread_msg msg = THREAD_MSG__UNDEFINED;
> > > +
> > > + res = read(thread->pipes.from[0], &msg, sizeof(msg));
> > > + if (res < 0) {
> > Maybe it needs to handle -EINTR.
> Its behaviour should be retry, right?
> Since these reads are used multiple times in the code, maybe I'm better off
> writing a wrapper function handling also EINTR.
Take a look at readn():
tools/lib/perf/lib.c
static ssize_t ion(bool is_read, int fd, void *buf, size_t n)
{
void *buf_start = buf;
size_t left = n;
while (left) {
/* buf must be treated as const if !is_read. */
ssize_t ret = is_read ? read(fd, buf, left) :
write(fd, buf, left);
if (ret < 0 && errno == EINTR)
continue;
if (ret <= 0)
return ret;
left -= ret;
buf += ret;
}
BUG_ON((size_t)(buf - buf_start) != n);
return n;
}
/*
* Read exactly 'n' bytes or return an error.
*/
ssize_t readn(int fd, void *buf, size_t n)
{
return ion(true, fd, buf, n);
}
- Arnaldo