[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen master] xen/vsprintf: Introduce %*pb[l] for printing bitmaps
commit 8cd9500958d818e3deabdd0d4164ea6fe1623d7c Author: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> AuthorDate: Thu Sep 6 10:25:59 2018 +0000 Commit: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> CommitDate: Mon Oct 22 13:39:22 2018 +0100 xen/vsprintf: Introduce %*pb[l] for printing bitmaps 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@xxxxxxxxxx> Acked-by: Wei Liu <wei.liu2@xxxxxxxxxx> Acked-by: <jbeulich@xxxxxxxx> --- 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 b5570bc1f1..080f498f65 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 b0ff00c883..352d43b425 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, unsigned int nr_bits) +{ + /* current bit is 'cur', most recently seen range is [rbot, rtop] */ + unsigned 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, unsigned 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; +} + /* Print a domain id, using names for system domains. (e.g. d0 or d[IDLE]) */ static char *print_domain(char *str, char *end, const struct domain *d) { @@ -319,6 +401,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 'd': /* Domain ID from a struct domain *. */ ++*fmt_ptr; return print_domain(str, end, arg); -- generated by git-patchbot for /home/xen/git/xen.git#master _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |