Re: [PATCH bpf-next v3] selftests/bpf: add BPF program dump in veristat

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Aug 20, 2025 at 2:52 PM Eduard Zingerman <eddyz87@xxxxxxxxx> wrote:
>
> On Wed, 2025-08-20 at 14:34 -0700, Andrii Nakryiko wrote:
>
> [...]
>
> > > +       system(command);
> >
> > Quick googling didn't answer this question, but with system() we make
> > assumption that system()'s stdout/stderr always goes into veristat's
> > stdout/stderr. It might be always true, but why rely on this if we can
> > just popen()? popen() also would allow us to do any processing we
> > might want to do (unlikely, but it's good to have an option, IMO).
> >
> > Let's go with popen(), it's not much of a complication.
>
> I actually double-checked this yesterday:
>
> man system:
>
> > The system() library function behaves as if it used fork(2) to
> > create a child process that executed the shell command specified in
> > command using execl(3) as follows:
> >
> >     execl("/bin/sh", "sh", "-c", command, (char *) NULL);
>
> man execl:
>
> > The exec() family of functions replaces the current process image
> > with a new process image.  The functions described in this manual
> > page are lay‐ ered on top of execve(2).
>
> max execve:
>
> > By default, file descriptors remain open across an execve().  File
> > descriptors that are marked close-on-exec are closed;
>
> So, stdout/stderr is guaranteed to be shared.
>
> (and on a different topic we discussed, 'popen' is documented as doing
>  "sh -c command > pipe", so it differs from 'system' only in that it
>  creates an additional pipe and adds redirection to sh invocation).
>
> But there is a different complication, if one tests this with
> iters.bpf.o, it becomes clear that the following is necessary:
>
>   @@ -1579,7 +1579,9 @@ static void dump(__u32 prog_id, const char *prog_name)
>           snprintf(command, sizeof(command), "bpftool prog dump %s id %u",
>                    env.dump_mode == JITED ? "jited" : "xlated", prog_id);
>           printf("Prog's '%s' dump:\n", prog_name);
>   +       fflush(stdout);
>           system(command);
>   +       fflush(stdout);
>           printf("\n");
>    }
>
> So, whatever.

What's the concern with popen()? That we have to copy one stream into another?

I didn't like (instinctively) the implicitness of system() adding
something to veristat's output, and you just proved that instinct
correct with that fflush()... ;)

It's like an argument of passing data through explicit function
arguments vs some global variable, IMO. Both can work given enough
care (assuming single-threaded execution), but explicit beats implicit
most of the time. And if we ever want to parallelize, then the winner
is obvious.

>
> [...]





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux