From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: "Stefano Stabellini" <sstabellini@kernel.org>,
"Wei Liu" <wei.liu2@citrix.com>,
"George Dunlap" <george.dunlap@eu.citrix.com>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Dario Faggioli" <dfaggioli@suse.com>,
"Julien Grall" <julien.grall@arm.com>,
"Jan Beulich" <JBeulich@suse.com>,
"Roger Pau Monné" <roger.pau@citrix.com>
Subject: [PATCH 1/6] xen/vsprintf: Introduce %*pb[l] for printing bitmaps
Date: Thu, 6 Sep 2018 13:08:11 +0100 [thread overview]
Message-ID: <1536235696-31359-2-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1536235696-31359-1-git-send-email-andrew.cooper3@citrix.com>
The format identifier is consistent with Linux. The code is adapted from
bitmap_scn{,list}printf() but cleaned up.
This change allows all callers to avoid needing a secondary buffer to render a
cpumask/nodemask into.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Wei Liu <wei.liu2@citrix.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
CC: Stefano Stabellini <sstabellini@kernel.org>
CC: Julien Grall <julien.grall@arm.com>
CC: George Dunlap <george.dunlap@eu.citrix.com>
CC: Dario Faggioli <dfaggioli@suse.com>
---
docs/misc/printk-formats.txt | 8 ++++
xen/common/vsprintf.c | 97 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 105 insertions(+)
diff --git a/docs/misc/printk-formats.txt b/docs/misc/printk-formats.txt
index 525108f..d0e1537 100644
--- a/docs/misc/printk-formats.txt
+++ b/docs/misc/printk-formats.txt
@@ -13,6 +13,14 @@ Raw buffer as hex string:
Up to 64 characters. Buffer length expected via the field_width
paramter. i.e. printk("%*ph", 8, buffer);
+Bitmaps (e.g. cpumask/nodemask):
+
+ %*pb 4321
+ %*pbl 0,5,8-9,14
+
+ Print a bitmap as either a hex string, or a range list. Bitmap length
+ (in bits) expected via the field_width parameter.
+
Symbol/Function pointers:
%ps Symbol name with condition offset and size (iff offset != 0)
diff --git a/xen/common/vsprintf.c b/xen/common/vsprintf.c
index f92fb67..1750e5e 100644
--- a/xen/common/vsprintf.c
+++ b/xen/common/vsprintf.c
@@ -264,6 +264,88 @@ static char *string(char *str, char *end, const char *s,
return str;
}
+/* Print a bitmap as '0-3,6-15' */
+static char *print_bitmap_list(char *str, char *end,
+ const unsigned long *bitmap, int nr_bits)
+{
+ /* current bit is 'cur', most recently seen range is [rbot, rtop] */
+ int cur, rbot, rtop;
+ bool first = true;
+
+ rbot = cur = find_first_bit(bitmap, nr_bits);
+ while ( cur < nr_bits )
+ {
+ rtop = cur;
+ cur = find_next_bit(bitmap, nr_bits, cur + 1);
+
+ if ( cur < nr_bits && cur <= rtop + 1 )
+ continue;
+
+ if ( !first )
+ {
+ if ( str < end )
+ *str = ',';
+ str++;
+ }
+ first = false;
+
+ str = number(str, end, rbot, 10, -1, -1, 0);
+ if ( rbot < rtop )
+ {
+ if ( str < end )
+ *str = '-';
+ str++;
+
+ str = number(str, end, rtop, 10, -1, -1, 0);
+ }
+
+ rbot = cur;
+ }
+
+ return str;
+}
+
+/* Print a bitmap as a comma separated hex string. */
+static char *print_bitmap_string(char *str, char *end,
+ const unsigned long *bitmap, int nr_bits)
+{
+ const unsigned int CHUNKSZ = 32;
+ unsigned int chunksz;
+ int i;
+ bool first = true;
+
+ chunksz = nr_bits & (CHUNKSZ - 1);
+ if ( chunksz == 0 )
+ chunksz = CHUNKSZ;
+
+ /*
+ * First iteration copes with the trailing partial word if nr_bits isn't a
+ * round multiple of CHUNKSZ. All subsequent iterations work on a
+ * complete CHUNKSZ block.
+ */
+ for ( i = ROUNDUP(nr_bits, CHUNKSZ) - CHUNKSZ; i >= 0; i -= CHUNKSZ )
+ {
+ unsigned int chunkmask = (1ull << chunksz) - 1;
+ unsigned int word = i / BITS_PER_LONG;
+ unsigned int offset = i % BITS_PER_LONG;
+ unsigned long val = (bitmap[word] >> offset) & chunkmask;
+
+ if ( !first )
+ {
+ if ( str < end )
+ *str = ',';
+ str++;
+ }
+ first = false;
+
+ str = number(str, end, val, 16, DIV_ROUND_UP(chunksz, 4), -1, ZEROPAD);
+
+ chunksz = CHUNKSZ;
+ }
+
+ return str;
+}
+
static char *pointer(char *str, char *end, const char **fmt_ptr,
const void *arg, int field_width, int precision,
int flags)
@@ -273,6 +355,21 @@ static char *pointer(char *str, char *end, const char **fmt_ptr,
/* Custom %p suffixes. See XEN_ROOT/docs/misc/printk-formats.txt */
switch ( fmt[1] )
{
+ case 'b': /* Bitmap as hex, or list */
+ ++*fmt_ptr;
+
+ if ( field_width < 0 )
+ return str;
+
+ if ( fmt[2] == 'l' )
+ {
+ ++*fmt_ptr;
+
+ return print_bitmap_list(str, end, arg, field_width);
+ }
+
+ return print_bitmap_string(str, end, arg, field_width);
+
case 'h': /* Raw buffer as hex string. */
{
const uint8_t *hex_buffer = arg;
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2018-09-06 12:08 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-06 12:08 [PATCH 0/6] xen: Use %*pb[l] for printing bitmaps Andrew Cooper
2018-09-06 12:08 ` Andrew Cooper [this message]
2018-09-06 16:32 ` [PATCH 1/6] xen/vsprintf: Introduce " Wei Liu
2018-09-07 7:41 ` Jan Beulich
2018-09-07 13:01 ` Andrew Cooper
2018-09-07 15:14 ` Jan Beulich
2018-09-25 13:06 ` Andrew Cooper
2018-09-25 13:22 ` Jan Beulich
2018-09-06 12:08 ` [PATCH 2/6] xen/sched: Use %*pb[l] instead of cpumask_scn{, list}printf() Andrew Cooper
2018-09-07 8:03 ` Jan Beulich
2018-09-07 13:56 ` Andrew Cooper
2018-09-07 14:42 ` George Dunlap
2018-09-07 15:17 ` Jan Beulich
2018-09-07 15:35 ` George Dunlap
2018-09-07 15:53 ` Jan Beulich
2018-09-07 16:07 ` Andrew Cooper
2018-09-10 6:39 ` Jan Beulich
2018-09-07 14:42 ` George Dunlap
2018-09-12 8:05 ` Dario Faggioli
2018-09-06 12:08 ` [PATCH 3/6] xen/common: Use %*pb[l] instead of {cpu, node}mask_scn{, list}printf() Andrew Cooper
2018-09-06 16:32 ` Wei Liu
2018-09-07 8:06 ` Jan Beulich
2018-09-07 8:30 ` Juergen Gross
2018-09-06 12:08 ` [PATCH 4/6] xen/x86: Use %*pb[l] instead of cpumask_scn{, list}printf() Andrew Cooper
2018-09-06 16:33 ` Wei Liu
2018-09-07 8:12 ` Jan Beulich
2018-09-07 14:00 ` Andrew Cooper
2018-09-06 12:08 ` [PATCH 5/6] xen/bitmap: Drop all bitmap_scn{, list}printf() infrastructure Andrew Cooper
2018-09-06 16:34 ` Wei Liu
2018-09-12 8:09 ` Dario Faggioli
2018-09-06 12:08 ` [PATCH RFC 6/6] xen/keyhandler: Drop keyhandler_scratch Andrew Cooper
2018-09-06 16:31 ` Wei Liu
2018-09-07 8:24 ` Jan Beulich
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=1536235696-31359-2-git-send-email-andrew.cooper3@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=JBeulich@suse.com \
--cc=dfaggioli@suse.com \
--cc=george.dunlap@eu.citrix.com \
--cc=julien.grall@arm.com \
--cc=roger.pau@citrix.com \
--cc=sstabellini@kernel.org \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.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;
as well as URLs for NNTP newsgroup(s).