Re: [PATCH v7 01/13] tools/libperf: introduce notion of static polled file descriptors

From: Alexey Budankov
Date: Tue Jun 09 2020 - 14:51:33 EST



On 09.06.2020 17:56, Jiri Olsa wrote:
> On Mon, Jun 08, 2020 at 08:18:20PM +0300, Alexey Budankov wrote:
>
> SNIP
>
>>>>>>> So how is it about just adding _revents() and _del() for fixed fds with
>>>>>>> correction of retval to bool for fdarray__add()?
>>>>>>
>>>>>> I don't like the separation for fixed and non-fixed fds,
>>>>>> why can't we make generic?
>>>>>
>>>>> Usage models are different but they want still to be parts of the same class
>>>>> for atomic poll(). The distinction is filterable vs. not filterable.
>>>>> The distinction should be somehow provided in API. Options are:
>>>>> 1. expose separate API calls like __add_nonfilterable(), __del_nonfilterable();
>>>>> use nonfilterable quality in __filter() and __poll() and, perhaps, other internals;
>>>>> 2. extend fdarray__add(, nonfilterable) with the nonfilterable quality
>>>>> use the type in __filter() and __poll() and, perhaps, other internals;
>>>>> expose less API calls in comparison with option 1
>>>>>
>>>>> Exposure of pos for filterable fds should be converted to bool since currently
>>>>> the returned pos can become stale and there is no way in API to check its state.
>>>>> So it could look like this:
>>>>>
>>>>> fdkey = fdarray__add(array, fd, events, type)
>>>>> type: filterable, nonfilterable, somthing else
>>>>> revents = fdarray__get_revents(fdkey);
>>>>> fdarray__del(array, fdkey);
>>>>
>>>> I think there's solution without having filterable type,
>
> so with the changes I proposed it could no longer be called fdarray ;-)
> which I think was the idea at the begning.. just an array of fds
>
> I'd like to have fully flaged events object.. but that's bigger change
>
>>>
>>> and still making the atomic fdarray__poll()?
>>
>> How is it about design like this?
>>
>> int fdarray__poll(struct fdarray *fda, int timeout)
>>
>> with additional external array of fds to simultaneously poll() on:
>>
>> int fdarray__poll(struct fdarray *fda, int timeout,
>> int *fds, size_t fds_size)
>>
>> fds would be added to array just prior poll() call.
>
> yep, I was considering something like this, having:
>
> fdarray__poll2(fda1, fda2)
> fdarray__pollx(fda, ...)
>
> but it would need to create an pollfd array and write
> the poll results back to arrays.. might be expensive

This is quite similar to currently proposed design options.
Saying expensive how do you estimate the cost?

>
> another idea is to forbid filter to screw the array
> and return only remaining number, like below

Important thing with all this is to have atomic poll() on
all fds signalling to the tool in order to avoid tricky races
and complicated design covering them.

Signals can also be consumed via fd and recent pidfd kernel
extension can be subject for this general atomic poll().

So ideally it should look like this:
fdarray__poll(events_fds + ctl_fds + pid_fd + signal_fds)

~Alexey