Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753068AbbLDBEf (ORCPT ); Thu, 3 Dec 2015 20:04:35 -0500 Received: from mail-pa0-f48.google.com ([209.85.220.48]:36156 "EHLO mail-pa0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751097AbbLDBEd convert rfc822-to-8bit (ORCPT ); Thu, 3 Dec 2015 20:04:33 -0500 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 9.0 \(3094\)) Subject: Re: [PATCH 1/2] mm, printk: introduce new format string for flags From: yalin wang In-Reply-To: <89A4C9BC-47F6-4768-8AA8-C1C4EFEFC52D@gmail.com> Date: Thu, 3 Dec 2015 17:04:30 -0800 Cc: Vlastimil Babka , "open list:MEMORY MANAGEMENT" , linux-kernel , Andrew Morton , Joonsoo Kim , Minchan Kim , Sasha Levin , "Kirill A. Shutemov" , Mel Gorman , Michal Hocko Content-Transfer-Encoding: 8BIT Message-Id: References: <20151125143010.GI27283@dhcp22.suse.cz> <1448899821-9671-1-git-send-email-vbabka@suse.cz> <4EAD2C33-D0E4-4DEB-92E5-9C0457E8635C@gmail.com> <565F5CD9.9080301@suse.cz> <1F60C207-1CC2-4B28-89AC-58C72D95A39D@gmail.com> <87a8psq7r6.fsf@rasmusvillemoes.dk> <89A4C9BC-47F6-4768-8AA8-C1C4EFEFC52D@gmail.com> To: Rasmus Villemoes X-Mailer: Apple Mail (2.3094) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1658 Lines: 47 >> 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)); > i test on gcc 4.9.3, it can work for this method, > so the final solution like this: > printk.h: > struct flag_fmt_spec { > unsigned long flag; > struct trace_print_flags *flags; > int array_size; > char delimiter; } > > #define FLAG_FORMAT(flag, flag_array, delimiter) (&(struct flag_ft_spec){ .flag = flag, .flags = flag_array, .array_size = ARRAY_SIZE(flag_array), .delimiter = delimiter}) > #define VMA_FLAG_FORMAT(flag) FLAG_FORMAT(flag, vmaflags_names, ‘|’) a little change: #define VMA_FLAG_FORMAT(vma) FLAG_FORMAT(vma->vm_flags, vmaflags_names, ‘|’) > source code: > printk("%pg\n", VMA_FLAG_FORMAT(my_flags)); a little change: printk("%pg\n", VMA_FLAG_FORMAT(vma)); > > that’s all, see cpumask_pr_args(masks) macro, > it also use macro and %*pb to print cpu mask . > i think this method is not very complex to use . > > search source code , > there is lots of printk to print flag into hex number : > $ grep -n -r 'printk.*flag.*%x’ . > it will be great if this flag string print is generic. > > Thanks -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/