From: Jiri Olsa <olsajiri@gmail.com>
To: Yonghong Song <yonghong.song@linux.dev>
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
bpf@vger.kernel.org, Martin KaFai Lau <kafai@fb.com>,
Song Liu <songliubraving@fb.com>, Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@chromium.org>,
Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>
Subject: Re: [PATCHv2 bpf-next] selftests/bpf: Add read_trace_pipe_iter function
Date: Fri, 12 Apr 2024 11:44:06 +0200 [thread overview]
Message-ID: <ZhkCZrUQdE9gSo88@krava> (raw)
In-Reply-To: <64fa1c03-26dc-4ec3-a54c-205900950862@linux.dev>
On Wed, Apr 10, 2024 at 05:09:18PM -0700, Yonghong Song wrote:
>
> On 4/10/24 7:09 AM, Jiri Olsa wrote:
> > We have two printk tests reading trace_pipe in non blocking way,
> > with the very same code. Moving that in new read_trace_pipe_iter
> > function.
> >
> > Current read_trace_pipe is used from sampless/bpf and needs to
> > do blocking read and printf of the trace_pipe data, using new
> > read_trace_pipe_iter to implement that.
> >
> > Both printk tests do early checks for the number of found messages
> > and can bail earlier, but I did not find any speed difference w/o
> > that condition, so I did not complicate the change more for that.
> >
> > Some of the samples/bpf programs use read_trace_pipe function,
> > so I kept that interface untouched. I did not see any issues with
> > affected samples/bpf programs other than there's slight change in
> > read_trace_pipe output. The current code uses puts that adds new
> > line after the printed string, so we would occasionally see extra
> > new line. With this patch we read output per lines, so there's no
> > need to use puts and we can use just printf instead without extra
> > new line.
> >
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
>
> Ack with a nit below.
>
> Acked-by: Yonghong Song <yonghong.song@linux.dev>
SNIP
> > @@ -56,21 +47,12 @@ void serial_test_trace_printk(void)
> > goto cleanup;
> > /* verify our search string is in the trace buffer */
> > - while (getline(&buf, &buflen, fp) >= 0 || errno == EAGAIN) {
> > - if (strstr(buf, SEARCHMSG) != NULL)
> > - found++;
> > - if (found == bss->trace_printk_ran)
> > - break;
>
> The above condition is not covered, but I think it is okay since the test
> will run in serial mode.
right, I made a note about that in the changelog:
> > Both printk tests do early checks for the number of found messages
> > and can bail earlier, but I did not find any speed difference w/o
> > that condition, so I did not complicate the change more for that.
I think it's fine
SNIP
> > +int read_trace_pipe_iter(void (*cb)(const char *str, void *data), void *data, int iter)
> > +{
> > + size_t buflen, n;
> > + char *buf = NULL;
> > + FILE *fp = NULL;
> > +
> > + if (access(TRACEFS_PIPE, F_OK) == 0)
> > + fp = fopen(TRACEFS_PIPE, "r");
> > + else
> > + fp = fopen(DEBUGFS_PIPE, "r");
> > + if (!fp)
> > + return -1;
> > +
> > + /* We do not want to wait forever when iter is specified. */
> > + if (iter)
> > + fcntl(fileno(fp), F_SETFL, O_NONBLOCK);
> > +
> > + while ((n = getline(&buf, &buflen, fp) >= 0) || errno == EAGAIN) {
> > + if (n > 0)
> > + cb(buf, data);
> > + if (iter && !(--iter))
>
> "if (iter-- == 1)" should also work. But your code works too.
ok, keeping the current one ;-)
thanks,
jirka
>
> > + break;
> > + }
> > +
> > + free(buf);
> > + if (fp)
> > + fclose(fp);
> > + return 0;
> > +}
> > +
> [...]
next prev parent reply other threads:[~2024-04-12 9:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-10 14:09 [PATCHv2 bpf-next] selftests/bpf: Add read_trace_pipe_iter function Jiri Olsa
2024-04-11 0:09 ` Yonghong Song
2024-04-12 9:44 ` Jiri Olsa [this message]
2024-04-12 16:30 ` patchwork-bot+netdevbpf
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=ZhkCZrUQdE9gSo88@krava \
--to=olsajiri@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@chromium.org \
--cc=sdf@google.com \
--cc=songliubraving@fb.com \
--cc=yhs@fb.com \
--cc=yonghong.song@linux.dev \
/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