[PATCH 2/3] x86: modify show_shared_cpu_map in intel_cacheinfo

From: Mike Travis
Date: Tue Apr 01 2008 - 18:55:03 EST


Use cpuset_scnprintf to print cpus on a leaf instead of requiring
a new "cpumask_scnprintf_len" function to determine the size of
the temporary buffer. cpuset_scnprintf can be used to print directly
to the output buffer, eliminating the need for the temporary buffer.

The format that cpuset_scnprintf uses is dependent on the sysctl
variable kernel.compat_cpuset_printf. The default is '1' and results
in this printout when NR_CPUS = 4096:

# cat /sys/devices/system/cpu/cpu3/cache/index0/shared_cpu_map
00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,\
00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,\
00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,\
00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,\
00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,\
00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,\
00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,\
00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,\
00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,\
00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,\
00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,\
00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,\
00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,\
00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,\
00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,\
00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000008

Clearing kernel.compat_cpuset_printf changes the output to:

# sysctl kernel.compat_cpuset_printf=0
# cat /sys/devices/system/cpu/cpu3/cache/index0/shared_cpu_map
3


[Depends on: x86: add cpuset_scnprintf function patch]

Based on:
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
+ x86/latest .../x86/linux-2.6-x86.git
+ sched-devel/latest .../mingo/linux-2.6-sched-devel.git

Cc: Bert Wesarg <bert.wesarg@xxxxxxxxxxxxxx>
Signed-off-by: Mike Travis <travis@xxxxxxx>
---
arch/x86/kernel/cpu/intel_cacheinfo.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)

--- linux-2.6.x86.orig/arch/x86/kernel/cpu/intel_cacheinfo.c
+++ linux-2.6.x86/arch/x86/kernel/cpu/intel_cacheinfo.c
@@ -593,14 +593,17 @@ static ssize_t show_size(struct _cpuid4_

static ssize_t show_shared_cpu_map(struct _cpuid4_info *this_leaf, char *buf)
{
+ unsigned long end = ALIGN((unsigned long)buf, PAGE_SIZE);
+ int len = end - (unsigned long)buf;
int n = 0;
- int len = cpumask_scnprintf_len(nr_cpu_ids);
- char *mask_str = kmalloc(len, GFP_KERNEL);

- if (mask_str) {
- cpumask_scnprintf(mask_str, len, this_leaf->shared_cpu_map);
- n = sprintf(buf, "%s\n", mask_str);
- kfree(mask_str);
+ if (len == 0)
+ len = PAGE_SIZE;
+
+ if (len >= 2) {
+ n = cpuset_scnprintf(buf, len-2, this_leaf->shared_cpu_map);
+ buf[n++] = '\n';
+ buf[n] = '\0';
}
return n;
}

--
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/