Re: [PATCH v4 01/10] tools/libperf: introduce static poll file descriptors

From: Alexey Budankov
Date: Mon Jun 01 2020 - 03:34:16 EST



On 31.05.2020 21:19, Jiri Olsa wrote:
> On Mon, May 25, 2020 at 05:17:31PM +0300, Alexey Budankov wrote:
>
> SBIP
>
>> +int fdarray__add_stat(struct fdarray *fda, int fd, short revents)
>> +{
>> + int pos = fda->nr_stat;
>> +
>> + if (pos >= FDARRAY__STAT_ENTRIES_MAX)
>> + return -1;
>> +
>> + fda->stat_entries[pos].fd = fd;
>> + fda->stat_entries[pos].events = revents;
>> + fda->nr_stat++;
>> +
>> + return pos;
>> +}
>> +
>> int fdarray__filter(struct fdarray *fda, short revents,
>> void (*entry_destructor)(struct fdarray *fda, int fd, void *arg),
>> void *arg)
>> @@ -113,7 +133,27 @@ int fdarray__filter(struct fdarray *fda, short revents,
>>
>> int fdarray__poll(struct fdarray *fda, int timeout)
>> {
>> - return poll(fda->entries, fda->nr, timeout);
>> + int nr, i, pos, res;
>> +
>> + nr = fda->nr;
>> +
>> + for (i = 0; i < fda->nr_stat; i++) {
>> + if (fda->stat_entries[i].fd != -1) {
>> + pos = fdarray__add(fda, fda->stat_entries[i].fd,
>> + fda->stat_entries[i].events);
>> + if (pos >= 0)
>> + fda->priv[pos].idx = i;
>> + }
>> + }
>
> hum, so every time we call evlist__poll we end up in here
> adding more stuff to entries?

It depends on whether static fds were added by perf_evlist__add_pollfd_stat() or not.
If they weren't then poll() checks only event fds added by perf_evlist__add_pollfd().
If static fds have been added and there are valid (!=-1) fds still then they are
appended to fds array. After return from poll() its result copied back to static fds
storage so fds state could be checked separately from event fds.

~Alexey