On Fri, 9 May 2025 at 01:31, Eduard Zingerman <eddyz87@xxxxxxxxx> wrote: > > On Wed, 2025-05-07 at 10:17 -0700, Kumar Kartikeya Dwivedi wrote: > > [...] > > > diff --git a/tools/lib/bpf/bpf_helpers.h b/tools/lib/bpf/bpf_helpers.h > > index a50773d4616e..1a748c21e358 100644 > > --- a/tools/lib/bpf/bpf_helpers.h > > +++ b/tools/lib/bpf/bpf_helpers.h > > [...] > > > /* Use __bpf_printk when bpf_printk call has 3 or fewer fmt args > > - * Otherwise use __bpf_vprintk > > + * Otherwise use __bpf_vprintk. Virtualize choices so stream printk > > + * can override it to bpf_stream_vprintk. > > */ > > -#define ___bpf_pick_printk(...) \ > > - ___bpf_nth(_, ##__VA_ARGS__, __bpf_vprintk, __bpf_vprintk, __bpf_vprintk, \ > > - __bpf_vprintk, __bpf_vprintk, __bpf_vprintk, __bpf_vprintk, \ > > - __bpf_vprintk, __bpf_vprintk, __bpf_printk /*3*/, __bpf_printk /*2*/,\ > > - __bpf_printk /*1*/, __bpf_printk /*0*/) > > +#define ___bpf_pick_printk(choice, choice_3, ...) \ > > + ___bpf_nth(_, ##__VA_ARGS__, choice, choice, choice, \ > > + choice, choice, choice, choice, \ > > + choice, choice, choice_3 /*3*/, choice_3 /*2*/, \ > > + choice_3 /*1*/, choice_3 /*0*/) > > > > /* Helper macro to print out debug messages */ > > -#define bpf_printk(fmt, args...) ___bpf_pick_printk(args)(fmt, ##args) > > +#define __bpf_trace_printk(fmt, args...) \ > > + ___bpf_pick_printk(__bpf_vprintk, __bpf_printk, args)(fmt, ##args) > > +#define __bpf_stream_printk(stream, fmt, args...) \ > > + ___bpf_pick_printk(__bpf_stream_vprintk, __bpf_stream_vprintk, args)(stream, fmt, ##args) > ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ > These two parameters are identical, > why is ___bpf_pick_printk is necessary in such case? In our case choice and choice_3 are the same, but for bpf_printk they're different, I was mostly trying to reuse the pick_printk machinery for both (which dispatches correctly to the actual macro). > > + > > +#define bpf_stream_printk(stream, fmt, args...) __bpf_stream_printk(stream, fmt, ##args) > > + > > +#define bpf_printk(arg, args...) __bpf_trace_printk(arg, ##args) > > > > struct bpf_iter_num; > > > >