The patch titled Subject: vsprintf: rework bitmap_list_string has been added to the -mm tree. Its filename is vsprintf-rework-bitmap_list_string.patch This patch should soon appear at https://ozlabs.org/~akpm/mmots/broken-out/vsprintf-rework-bitmap_list_string.patch and later at https://ozlabs.org/~akpm/mmotm/broken-out/vsprintf-rework-bitmap_list_string.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Yury Norov <yury.norov@xxxxxxxxx> Subject: vsprintf: rework bitmap_list_string bitmap_list_string() is very ineffective when printing bitmaps with long ranges of set bits because it calls find_next_bit for each bit in the bitmap. We can do better by detecting ranges of set bits. In my environment, before/after is 943008/31008 ns. Link: https://lkml.kernel.org/r/20210814211713.180533-18-yury.norov@xxxxxxxxx Signed-off-by: Yury Norov <yury.norov@xxxxxxxxx> Tested-by: Wolfram Sang <wsa+renesas@xxxxxxxxxxxxxxxxxxxx> Cc: Alexander Lobakin <alobakin@xxxxx> Cc: Alexey Klimov <aklimov@xxxxxxxxxx> Cc: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx> Cc: Dennis Zhou <dennis@xxxxxxxxxx> Cc: Jiri Olsa <jolsa@xxxxxxxxxx> Cc: kernel test robot <lkp@xxxxxxxxx> Cc: Ulf Hansson <ulf.hansson@xxxxxxxxxx> Cc: Will Deacon <will@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- lib/vsprintf.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) --- a/lib/vsprintf.c~vsprintf-rework-bitmap_list_string +++ a/lib/vsprintf.c @@ -1241,20 +1241,13 @@ char *bitmap_list_string(char *buf, char struct printf_spec spec, const char *fmt) { int nr_bits = max_t(int, spec.field_width, 0); - /* current bit is 'cur', most recently seen range is [rbot, rtop] */ - int cur, rbot, rtop; bool first = true; + int rbot, rtop; if (check_pointer(&buf, end, bitmap, spec)) return buf; - 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; - + for_each_set_bitrange(rbot, rtop, bitmap, nr_bits) { if (!first) { if (buf < end) *buf = ','; @@ -1263,15 +1256,12 @@ char *bitmap_list_string(char *buf, char first = false; buf = number(buf, end, rbot, default_dec_spec); - if (rbot < rtop) { - if (buf < end) - *buf = '-'; - buf++; - - buf = number(buf, end, rtop, default_dec_spec); - } + if (rtop == rbot + 1) + continue; - rbot = cur; + if (buf < end) + *buf = '-'; + buf = number(++buf, end, rtop - 1, default_dec_spec); } return buf; } _ Patches currently in -mm which might be from yury.norov@xxxxxxxxx are bitops-protect-find_first_zero_bit-properly.patch bitops-move-find_bit__le-functions-from-leh-to-findh.patch include-move-findh-from-asm_generic-to-linux.patch arch-remove-generic_find_first_bit-entirely.patch lib-add-find_first_and_bit.patch cpumask-use-find_first_and_bit.patch all-replace-find_next_zero_bit-with-find_first_zero_bit-where-appropriate.patch tools-sync-tools-bitmap-with-mother-linux.patch cpumask-replace-cpumask_next_-with-cpumask_first_-where-appropriate.patch include-linux-move-for_each_bit-macros-from-bitopsh-to-findh.patch find-micro-optimize-for_each_setclear_bit.patch replace-for_each__bit_from-with-for_each__bit-where-appropriate.patch mm-percpu-micro-optimize-pcpu_is_populated.patch bitmap-unify-find_bit-operations.patch lib-bitmap-add-performance-test-for-bitmap_print_to_pagebuf.patch vsprintf-rework-bitmap_list_string.patch