On 3/21/18 12:44 PM, Linus Torvalds wrote:
On Wed, Mar 21, 2018 at 11:54 AM, Alexei Starovoitov <ast@xxxxxx> wrote:
add fancy macro to compute number of arguments passed into tracepoint
at compile time and store it as part of 'struct tracepoint'.
We should probably do this __COUNT() thing in some generic header, we
just talked last week about another use case entirely.
ok. Not sure which generic header though.
Should I move it to include/linux/kernel.h ?
And wouldn't it be nice to just have some generic infrastructure like this:
/*
* This counts to ten.
*
* Any more than that, and we'd need to take off our shoes
*/
#define __GET_COUNT(_0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_n,...) _n
#define __COUNT(...) \
__GET_COUNT(__VA_ARGS__,10,9,8,7,6,5,4,3,2,1,0)
#define COUNT(...) __COUNT(dummy,##__VA_ARGS__)
since it will be a build time error, it's a good time to discuss
how many arguments we want to support in tracepoints and
in general in other places that would want to use this macro.
Like the only reason my patch is counting till 17 is because of
trace_iwlwifi_dev_ucode_error().
The next offenders are using 12 arguments:
trace_mc_event()
trace_mm_vmscan_lru_shrink_inactive()
Clearly not every efficient usage of it:
trace_mm_vmscan_lru_shrink_inactive(pgdat->node_id,
nr_scanned, nr_reclaimed,
stat.nr_dirty, stat.nr_writeback,
stat.nr_congested, stat.nr_immediate,
stat.nr_activate, stat.nr_ref_keep,
stat.nr_unmap_fail,
sc->priority, file);
could have passed &stat instead.
I'd like to refactor that trace_iwlwifi_dev_ucode_error()
and from now on set the limit to 12.
Any offenders should be using tracepoints with <= 12 args
instead of extending the macro.
Does it sound reasonable ?
#define __CONCAT(a,b) a##b
#define __CONCATENATE(a,b) __CONCAT(a,b)
and then you can do things like:
#define fn(...) __CONCATENATE(fn,COUNT(__VA_ARGS__))(__VA_ARGS__)
which turns "fn(x,y,z..)" into "fn<N>(x,y,z)".
That can be useful for things like "max(a,b,c,d)" expanding to
"max4()", and then you can just have the trivial
#define max3(a,b,c) max2(a,max2(b.c))
I can try that. Not sure my macro-fu is up to that level.
__CAST_TO_U64() macro from the next patch was difficult to make
work across compilers and architectures.
--
To unsubscribe from this list: send the line "unsubscribe linux-api" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html