aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2015-02-13 17:36:50 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2015-02-14 00:21:36 -0500
commit513e3d2d11c9f05db1edc70deb18a82555cf9309 (patch)
treef853d7d813be3ef15d033e9a71be1ffbf49f78fc
parent310ee9e8f370f8fd7a76856726aea88839bb0f8f (diff)
cpumask: always use nr_cpu_ids in formatting and parsing functions
bitmap implements two variants of scnprintf functions to format a bitmap into a string and cpumask and nodemask wrap them to provide equivalent interfaces. The scnprintf family of functions require a string buffer as an output target which complicates code paths which just want to print out the mask through printk for informational or debug purposes as they have to worry about how large the buffer should be and whether it's too large to allocate on stack. Neither cpumask or nodemask provides a guildeline on how large the target buffer should be forcing users come up with their own solutions - some allocate an arbitrarily sized buffer which is small enough to allocate on stack but may be too short in corner cases, other come up with a custom upper limit calculation considering the output format, some allocate the buffer dynamically while one resorted to using lock to synchronize access to a static buffer. This is an artificial problem which is being solved repeatedly for no benefit. In a lot of cases, the output area already exists and can be targeted directly making the intermediate buffer unnecessary. This patchset teaches printf family of functions how to format bitmaps and replace the dedicated formatting functions with it. Pointer formatting is extended to cover bitmap formatting. It uses the field width for the number of bits instead of precision. The format used is '%*pb[l]', with the optional trailing 'l' specifying list format instead of hex masks. For more details, please see 0002. This patch (of 31): Currently, the formatting and parsing functions in cpumask.h use nr_cpumask_bits like other cpumask functions; however, nr_cpumask_bits is either NR_CPUS or nr_cpu_ids depending on CONFIG_CPUMASK_OFFSTACK. This leads to inconsistent behaviors. With CONFIG_NR_CPUS=512 and !CONFIG_CPUMASK_OFFSTACK # cat /sys/devices/virtual/net/lo/queues/rx-0/rps_cpus 00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000 # cat /proc/self/status | grep Cpus_allowed: Cpus_allowed: f With CONFIG_NR_CPUS=1024 and CONFIG_CPUMASK_OFFSTACK (fedora default) # cat /sys/devices/virtual/net/lo/queues/rx-0/rps_cpus 0 # cat /proc/self/status | grep Cpus_allowed: Cpus_allowed: f Note that /proc/self/status is always using nr_cpu_ids regardless of config. This is because seq cpumask formattings functions always use nr_cpu_ids. Given that the same output fields may switch between the two forms, converging on nr_cpu_ids always isn't too likely to surprise userland. This patch updates the formatting and parsing functions in cpumask.h to always use nr_cpu_ids. There's no point in dealing with CPUs which aren't even possible on the machine. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: "David S. Miller" <davem@davemloft.net> Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com> Cc: "John W. Linville" <linville@tuxdriver.com> Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Chris Metcalf <cmetcalf@tilera.com> Cc: Chris Zankel <chris@zankel.net> Cc: Christoph Lameter <cl@linux.com> Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com> Cc: Fenghua Yu <fenghua.yu@intel.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Li Zefan <lizefan@huawei.com> Cc: Max Filippov <jcmvbkbc@gmail.com> Cc: Mike Travis <travis@sgi.com> Cc: Pekka Enberg <penberg@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Russell King <linux@arm.linux.org.uk> Acked-by: Rusty Russell <rusty@rustcorp.com.au> Cc: Steffen Klassert <steffen.klassert@secunet.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Tony Luck <tony.luck@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--include/linux/cpumask.h14
1 files changed, 7 insertions, 7 deletions
diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index ff9044286d88..ee9acb0ce542 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -550,7 +550,7 @@ static inline void cpumask_copy(struct cpumask *dstp,
550static inline int cpumask_scnprintf(char *buf, int len, 550static inline int cpumask_scnprintf(char *buf, int len,
551 const struct cpumask *srcp) 551 const struct cpumask *srcp)
552{ 552{
553 return bitmap_scnprintf(buf, len, cpumask_bits(srcp), nr_cpumask_bits); 553 return bitmap_scnprintf(buf, len, cpumask_bits(srcp), nr_cpu_ids);
554} 554}
555 555
556/** 556/**
@@ -564,7 +564,7 @@ static inline int cpumask_scnprintf(char *buf, int len,
564static inline int cpumask_parse_user(const char __user *buf, int len, 564static inline int cpumask_parse_user(const char __user *buf, int len,
565 struct cpumask *dstp) 565 struct cpumask *dstp)
566{ 566{
567 return bitmap_parse_user(buf, len, cpumask_bits(dstp), nr_cpumask_bits); 567 return bitmap_parse_user(buf, len, cpumask_bits(dstp), nr_cpu_ids);
568} 568}
569 569
570/** 570/**
@@ -579,7 +579,7 @@ static inline int cpumask_parselist_user(const char __user *buf, int len,
579 struct cpumask *dstp) 579 struct cpumask *dstp)
580{ 580{
581 return bitmap_parselist_user(buf, len, cpumask_bits(dstp), 581 return bitmap_parselist_user(buf, len, cpumask_bits(dstp),
582 nr_cpumask_bits); 582 nr_cpu_ids);
583} 583}
584 584
585/** 585/**
@@ -595,7 +595,7 @@ static inline int cpulist_scnprintf(char *buf, int len,
595 const struct cpumask *srcp) 595 const struct cpumask *srcp)
596{ 596{
597 return bitmap_scnlistprintf(buf, len, cpumask_bits(srcp), 597 return bitmap_scnlistprintf(buf, len, cpumask_bits(srcp),
598 nr_cpumask_bits); 598 nr_cpu_ids);
599} 599}
600 600
601/** 601/**
@@ -610,7 +610,7 @@ static inline int cpumask_parse(const char *buf, struct cpumask *dstp)
610 char *nl = strchr(buf, '\n'); 610 char *nl = strchr(buf, '\n');
611 unsigned int len = nl ? (unsigned int)(nl - buf) : strlen(buf); 611 unsigned int len = nl ? (unsigned int)(nl - buf) : strlen(buf);
612 612
613 return bitmap_parse(buf, len, cpumask_bits(dstp), nr_cpumask_bits); 613 return bitmap_parse(buf, len, cpumask_bits(dstp), nr_cpu_ids);
614} 614}
615 615
616/** 616/**
@@ -622,7 +622,7 @@ static inline int cpumask_parse(const char *buf, struct cpumask *dstp)
622 */ 622 */
623static inline int cpulist_parse(const char *buf, struct cpumask *dstp) 623static inline int cpulist_parse(const char *buf, struct cpumask *dstp)
624{ 624{
625 return bitmap_parselist(buf, cpumask_bits(dstp), nr_cpumask_bits); 625 return bitmap_parselist(buf, cpumask_bits(dstp), nr_cpu_ids);
626} 626}
627 627
628/** 628/**
@@ -817,7 +817,7 @@ static inline ssize_t
817cpumap_print_to_pagebuf(bool list, char *buf, const struct cpumask *mask) 817cpumap_print_to_pagebuf(bool list, char *buf, const struct cpumask *mask)
818{ 818{
819 return bitmap_print_to_pagebuf(list, buf, cpumask_bits(mask), 819 return bitmap_print_to_pagebuf(list, buf, cpumask_bits(mask),
820 nr_cpumask_bits); 820 nr_cpu_ids);
821} 821}
822 822
823/* 823/*