Re: [PATCH v8 21/22] perf session: Introduce READER_NODATA state

From: Bayduraev, Alexey V
Date: Thu Jul 01 2021 - 06:08:13 EST


Hi,

On 30.06.2021 18:55, Alexey Bayduraev wrote:
> Adding READER_NODATA state to differentiate it from the real end-of-file
> state. Also an indent depth in reades initialization loop is reduced.

Just a little note: I will squash this patch to 19 and 20.

Regards,
Alexey

>
> Suggested-by: Namhyung Kim <namhyung@xxxxxxxxx>
> Signed-off-by: Alexey Bayduraev <alexey.v.bayduraev@xxxxxxxxxxxxxxx>
> ---
> tools/perf/util/session.c | 45 ++++++++++++++++++++-------------------
> 1 file changed, 23 insertions(+), 22 deletions(-)
>
> diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
> index b11a502c22a3..c2b6c5f4e119 100644
> --- a/tools/perf/util/session.c
> +++ b/tools/perf/util/session.c
> @@ -70,7 +70,8 @@ struct reader_state {
>
> enum {
> READER_EOF = 0,
> - READER_OK = 1,
> + READER_NODATA = 1,
> + READER_OK = 2,
> };
>
> struct reader {
> @@ -2305,7 +2306,7 @@ reader__read_event(struct reader *rd, struct perf_session *session,
> return PTR_ERR(event);
>
> if (!event)
> - return READER_EOF;
> + return READER_NODATA;
>
> session->active_reader = rd;
> size = event->header.size;
> @@ -2395,7 +2396,7 @@ static int __perf_session__process_events(struct perf_session *session)
> err = reader__read_event(rd, session, &prog);
> if (err < 0)
> break;
> - if (err == READER_EOF) {
> + if (err == READER_NODATA) {
> err = reader__mmap(rd, session);
> if (err <= 0)
> break;
> @@ -2472,25 +2473,25 @@ static int __perf_session__process_dir_events(struct perf_session *session)
> readers++;
>
> for (i = 0; i < data->dir.nr; i++) {
> - if (data->dir.files[i].size) {
> - rd[readers] = (struct reader) {
> - .fd = data->dir.files[i].fd,
> - .path = data->dir.files[i].path,
> - .data_size = data->dir.files[i].size,
> - .data_offset = 0,
> - .in_place_update = session->data->in_place_update,
> - };
> - ret = reader__init(&rd[readers], NULL);
> - if (ret)
> - goto out_err;
> - ret = reader__mmap(&rd[readers], session);
> - if (ret != READER_OK) {
> - if (ret == READER_EOF)
> - ret = -EINVAL;
> - goto out_err;
> - }
> - readers++;
> + if (!data->dir.files[i].size)
> + continue;
> + rd[readers] = (struct reader) {
> + .fd = data->dir.files[i].fd,
> + .path = data->dir.files[i].path,
> + .data_size = data->dir.files[i].size,
> + .data_offset = 0,
> + .in_place_update = session->data->in_place_update,
> + };
> + ret = reader__init(&rd[readers], NULL);
> + if (ret)
> + goto out_err;
> + ret = reader__mmap(&rd[readers], session);
> + if (ret != READER_OK) {
> + if (ret == READER_EOF)
> + ret = -EINVAL;
> + goto out_err;
> }
> + readers++;
> }
>
> i = 0;
> @@ -2507,7 +2508,7 @@ static int __perf_session__process_dir_events(struct perf_session *session)
> ret = reader__read_event(&rd[i], session, &prog);
> if (ret < 0)
> break;
> - if (ret == READER_EOF) {
> + if (ret == READER_NODATA) {
> ret = reader__mmap(&rd[i], session);
> if (ret < 0)
> goto out_err;
>