On Thu, Dec 03 2015, yalin wang <yalin.wang2...@gmail.com> wrote: >> On Dec 2, 2015, at 13:04, Vlastimil Babka <vba...@suse.cz> wrote: >> >> On 12/02/2015 06:40 PM, yalin wang wrote: >> >> (please trim your reply next time, no need to quote whole patch here) >> >>> i am thinking why not make %pg* to be more generic ? >>> not restricted to only GFP / vma flags / page flags . >>> so could we change format like this ? >>> define a flag spec struct to include flag and trace_print_flags and some >>> other option : >>> typedef struct { >>> unsigned long flag; >>> structtrace_print_flags *flags; >>> unsigned long option; } flag_sec; >>> flag_sec my_flag; >>> in printk we only pass like this : >>> printk(ā%pg\nā, &my_flag) ; >>> then it can print any flags defined by user . >>> more useful for other drivers to use . >> >> I don't know, it sounds quite complicated
Agreed, I think this would be premature generalization. There's also some value in having the individual %pgX specifiers, as that allows individual tweaks such as the mask_out for page flags. given that we had no flags printing >> for years and now there's just three kinds of them. The extra struct >> flag_sec is >> IMHO nuissance. No other printk format needs such thing AFAIK? For example, >> if I >> were to print page flags from several places, each would have to define the >> struct flag_sec instance, or some header would have to provide it? > this can be avoided by provide a macro in header file . > we can add a new struct to declare trace_print_flags : > for example: > #define DECLARE_FLAG_PRINTK_FMT(name, flags_array) flag_spec name = { > .flags = flags_array}; > #define FLAG_PRINTK_FMT(name, flag) ({ name.flag = flag; &name}) > > in source code : > DECLARE_FLAG_PRINTK_FMT(my_flag, vmaflags_names); > printk(ā%pg\nā, FLAG_PRINTK_FMT(my_flag, vma->flag)); > Compared to printk("%pgv\n", &vma->flag), I know which I'd prefer to read. > i am not if DECLARE_FLAG_PRINTK_FMT and FLAG_PRINTK_FMT macro > can be defined into one macro ? > maybe need some trick here . > > is it possible ? Technically, I think the answer is yes, at least in C99 (and I suppose gcc would accept it in gnu89 mode as well). printk("%pg\n", &(struct flag_printer){.flags = my_flags, .names = vmaflags_names}); Not tested, and I still don't think it would be particularly readable even when macroized printk("%pg\n", PRINTF_VMAFLAGS(my_flags)); Rasmus -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/