public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: Igor Mammedov <imammedo@redhat.com>, Jiang Liu <liuj97@gmail.com>,
	linux-kernel@vger.kernel.org, pjt@google.com, tglx@linutronix.de,
	seto.hidetoshi@jp.fujitsu.com,
	Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Joe Perches <joe@perches.com>
Subject: Re: [RFC][PATCH] printk: Add %pb to print bitmaps
Date: Wed, 09 May 2012 17:32:42 +0200	[thread overview]
Message-ID: <1336577562.2527.58.camel@twins> (raw)
In-Reply-To: <20120509141528.GA3623@gmail.com>

On Wed, 2012-05-09 at 16:15 +0200, Ingo Molnar wrote:
> > I guess I should use %.*pb and keep the field_width in case someone
> > manages to actually make bitmap_scnlistprintf() conform to it. The
> > precision is unused anyway.
> 
> That's a cute trick, and it's intuitive as well. 

kernel/sched/core.c:5570:3: warning: precision used with ‘%p’ gnu_printf format [-Wformat]

/me curses a bit.. anybody?


The below compiles and works (with the above caveat) and has all the
style muck people 'wanted'.

---
 lib/vsprintf.c |   46 ++++++++++++++++++++++++++++++++--------------
 1 file changed, 32 insertions(+), 14 deletions(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index abbabec..6bd9a66 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -25,6 +25,9 @@
 #include <linux/kallsyms.h>
 #include <linux/uaccess.h>
 #include <linux/ioport.h>
+#include <linux/bitmap.h>
+#include <linux/cpumask.h>
+#include <linux/numa.h>
 #include <net/addrconf.h>
 
 #include <asm/page.h>		/* for PAGE_SIZE */
@@ -857,6 +860,9 @@ int kptr_restrict __read_mostly;
  *       correctness of the format string and va_list arguments.
  * - 'K' For a kernel pointer that should be hidden from unprivileged users
  * - 'NF' For a netdev_features_t
+ * - 'b' For a bitmap; %.*pb is required and the precision is used as bitmap length
+ * - 'bc' For a cpumask
+ * - 'bn' For a nodemask
  *
  * Note: The difference between 'S' and 'F' is that on ia64 and ppc64
  * function pointers are really function descriptors, which contain a
@@ -902,24 +908,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
 					 * 6:   000102...0f
 					 */
 		switch (fmt[1]) {
-		case '6':
-			return ip6_addr_string(buf, end, ptr, spec, fmt);
-		case '4':
-			return ip4_addr_string(buf, end, ptr, spec, fmt);
+		case '6': return ip6_addr_string(buf, end, ptr, spec, fmt);
+		case '4': return ip4_addr_string(buf, end, ptr, spec, fmt);
 		}
 		break;
 	case 'U':
 		return uuid_string(buf, end, ptr, spec, fmt);
-	case 'V':
-		{
-			va_list va;
-
-			va_copy(va, *((struct va_format *)ptr)->va);
-			buf += vsnprintf(buf, end > buf ? end - buf : 0,
-					 ((struct va_format *)ptr)->fmt, va);
-			va_end(va);
-			return buf;
-		}
+	case 'V': {
+		va_list va;
+
+		va_copy(va, *((struct va_format *)ptr)->va);
+		buf += vsnprintf(buf, end > buf ? end - buf : 0,
+				 ((struct va_format *)ptr)->fmt, va);
+		va_end(va);
+		return buf;
+	}
 	case 'K':
 		/*
 		 * %pK cannot be used in IRQ context because its test
@@ -941,6 +944,18 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
 			return netdev_feature_string(buf, end, ptr, spec);
 		}
 		break;
+	case 'b': {
+		int bits;
+
+		switch (fmt[1]) {
+		case 'c': bits = nr_cpumask_bits; break;
+		case 'n': bits = MAX_NUMNODES;    break;
+		default:  bits = spec.precision;  break;
+		}
+
+		return buf + bitmap_scnlistprintf(buf, end - buf, ptr, bits);
+	}
+	default: break;
 	}
 	spec.flags |= SMALL;
 	if (spec.field_width == -1) {
@@ -1175,6 +1190,9 @@ int format_decode(const char *fmt, struct printf_spec *spec)
  * %pI6c print an IPv6 address as specified by RFC 5952
  * %pU[bBlL] print a UUID/GUID in big or little endian using lower or upper
  *   case.
+ * %.*pb print a bitmap list using the precision as bitmap length
+ * %pbc print a cpumask bitmap
+ * %pbn print a nodemask bitmap
  * %n is ignored
  *
  * The return value is the number of characters which would


  parent reply	other threads:[~2012-05-09 15:33 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-09 10:38 [PATCH] sched_groups are expected to be circular linked list, make it so right after allocation Igor Mammedov
2012-05-09 10:21 ` Jiang Liu
2012-05-09 11:44   ` Igor Mammedov
2012-05-09 11:52     ` Peter Zijlstra
2012-05-09 11:58       ` Igor Mammedov
2012-05-09 12:21         ` Peter Zijlstra
2012-05-09 12:22           ` Peter Zijlstra
2012-05-09 12:35             ` Igor Mammedov
2012-05-09 12:30           ` Peter Zijlstra
2012-05-09 13:27             ` [RFC][PATCH] printk: Add %pb to print bitmaps Peter Zijlstra
2012-05-09 13:29               ` Peter Zijlstra
2012-05-09 13:36               ` Ingo Molnar
2012-05-09 13:44                 ` Peter Zijlstra
2012-05-09 13:59                   ` Peter Zijlstra
2012-05-09 14:15                     ` Ingo Molnar
2012-05-09 14:24                       ` Peter Zijlstra
2012-05-09 15:32                       ` Peter Zijlstra [this message]
2012-05-09 15:41                         ` Ingo Molnar
2012-05-09 16:06                           ` Peter Zijlstra
2012-05-09 16:39                             ` Joe Perches
2012-05-09 17:22                               ` Ingo Molnar
2012-05-09 17:24                             ` Ingo Molnar
2012-05-09 17:25                               ` Peter Zijlstra
2012-05-09 17:31                                 ` Ingo Molnar
2012-05-09 14:19                     ` Joe Perches
2012-05-09 15:34                       ` Ingo Molnar
2012-05-09 17:15               ` Linus Torvalds
2012-05-09 17:22                 ` Peter Zijlstra
2012-05-09 17:26                   ` Ingo Molnar
2012-05-09 17:30                     ` Peter Zijlstra
2012-05-09 19:07               ` Andrew Morton
2012-05-09 20:58                 ` Peter Zijlstra
2012-05-10  7:45                   ` Ingo Molnar
2012-05-10 13:26             ` [PATCH] sched_groups are expected to be circular linked list, make it so right after allocation Igor Mammedov
2012-05-10 13:45               ` Peter Zijlstra
2012-05-10 17:01                 ` Igor Mammedov
2012-05-10 17:33                   ` Peter Zijlstra
2012-05-09 10:35 ` [tip:sched/urgent] sched: Fix KVM and ia64 boot crash due to sched_groups circular linked list assumption tip-bot for Igor Mammedov
2012-05-09 11:41 ` [PATCH] sched_groups are expected to be circular linked list, make it so right after allocation Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1336577562.2527.58.camel@twins \
    --to=peterz@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=imammedo@redhat.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liuj97@gmail.com \
    --cc=mingo@kernel.org \
    --cc=pjt@google.com \
    --cc=seto.hidetoshi@jp.fujitsu.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox