From 399efd7ffa729b837536da2a6e7180d2ac48e13a Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sat, 12 Jul 2014 17:20:29 -0700 Subject: [PATCH] kernel - Reduce console spam in verbose mode when printing cpu sets * Add helper function kprint_cpuset(). * Print cpu ranges when printing out cpu sets. * Print cpu ranges when generating topology output for sysctl --- sys/kern/subr_cpu_topology.c | 62 ++++++++++++++++++++++++++++-------- sys/kern/subr_prf.c | 43 +++++++++++++++++++++++++ sys/kern/usched_bsd4.c | 17 ++++------ sys/kern/usched_dfly.c | 15 ++++----- sys/sys/systm.h | 1 + 5 files changed, 106 insertions(+), 32 deletions(-) diff --git a/sys/kern/subr_cpu_topology.c b/sys/kern/subr_cpu_topology.c index 833855162f..26c2027c78 100644 --- a/sys/kern/subr_cpu_topology.c +++ b/sys/kern/subr_cpu_topology.c @@ -65,6 +65,7 @@ static struct sysctl_ctx_list cpu_topology_sysctl_ctx; static struct sysctl_oid *cpu_topology_sysctl_tree; static char cpu_topology_members[8*MAXCPU]; static per_cpu_sysctl_info_t pcpu_sysctl[MAXCPU]; +static void sbuf_print_cpuset(struct sbuf *sb, cpumask_t *mask); int cpu_topology_levels_number = 1; cpu_node_t *root_cpu_node; @@ -369,10 +370,7 @@ print_cpu_topology_tree_sysctl_helper(cpu_node_t *node, } else { sbuf_printf(sb,"UNKNOWN: "); } - CPUSET_FOREACH(i, node->members) { - sbuf_printf(sb,"cpu%d ", i); - } - + sbuf_print_cpuset(sb, &node->members); sbuf_printf(sb,"\n"); for (i = 0; i < node->child_no; i++) { @@ -501,7 +499,6 @@ get_cpumask_from_level(int cpuid, static void init_pcpu_topology_sysctl(void) { - int cpu; int i; cpumask_t mask; struct sbuf sb; @@ -523,9 +520,7 @@ init_pcpu_topology_sysctl(void) sbuf_new(&sb, pcpu_sysctl[i].physical_siblings, sizeof(pcpu_sysctl[i].physical_siblings), SBUF_FIXEDLEN); - CPUSET_FOREACH(cpu, mask) { - sbuf_printf(&sb,"cpu%d ", cpu); - } + sbuf_print_cpuset(&sb, &mask); sbuf_trim(&sb); sbuf_finish(&sb); @@ -540,9 +535,7 @@ init_pcpu_topology_sysctl(void) sbuf_new(&sb, pcpu_sysctl[i].core_siblings, sizeof(pcpu_sysctl[i].core_siblings), SBUF_FIXEDLEN); - CPUSET_FOREACH(cpu, mask) { - sbuf_printf(&sb,"cpu%d ", cpu); - } + sbuf_print_cpuset(&sb, &mask); sbuf_trim(&sb); sbuf_finish(&sb); @@ -585,9 +578,7 @@ build_sysctl_cpu_topology(void) /* SYSCTL cpu_topology "members" entry */ sbuf_new(&sb, cpu_topology_members, sizeof(cpu_topology_members), SBUF_FIXEDLEN); - CPUSET_FOREACH(i, cpu_root_node->members) { - sbuf_printf(&sb,"cpu%d ", i); - } + sbuf_print_cpuset(&sb, &cpu_root_node->members); sbuf_trim(&sb); sbuf_finish(&sb); SYSCTL_ADD_STRING(&cpu_topology_sysctl_ctx, @@ -646,6 +637,49 @@ build_sysctl_cpu_topology(void) } } +static +void +sbuf_print_cpuset(struct sbuf *sb, cpumask_t *mask) +{ + int i; + int b = -1; + int e = -1; + int more = 0; + + sbuf_printf(sb, "cpus("); + CPUSET_FOREACH(i, *mask) { + if (b < 0) { + b = i; + e = b + 1; + continue; + } + if (e == i) { + ++e; + continue; + } + if (more) + sbuf_printf(sb, ", "); + if (b == e - 1) { + sbuf_printf(sb, "%d", b); + } else { + sbuf_printf(sb, "%d-%d", b, e - 1); + } + more = 1; + b = i; + e = b + 1; + } + if (more) + sbuf_printf(sb, ", "); + if (b >= 0) { + if (b == e + 1) { + sbuf_printf(sb, "%d", b); + } else { + sbuf_printf(sb, "%d-%d", b, e - 1); + } + } + sbuf_printf(sb, ") "); +} + /* Build the CPU Topology and SYSCTL Topology tree */ static void init_cpu_topology(void) diff --git a/sys/kern/subr_prf.c b/sys/kern/subr_prf.c index 9ea04028e9..f1a5570b63 100644 --- a/sys/kern/subr_prf.c +++ b/sys/kern/subr_prf.c @@ -55,6 +55,7 @@ #include #include #include +#include #include #include @@ -1212,3 +1213,45 @@ hexdump(const void *ptr, int length, const char *hdr, int flags) kprintf("\n"); } } + +void +kprint_cpuset(cpumask_t *mask) +{ + int i; + int b = -1; + int e = -1; + int more = 0; + + kprintf("cpus("); + CPUSET_FOREACH(i, *mask) { + if (b < 0) { + b = i; + e = b + 1; + continue; + } + if (e == i) { + ++e; + continue; + } + if (more) + kprintf(", "); + if (b == e - 1) { + kprintf("%d", b); + } else { + kprintf("%d-%d", b, e - 1); + } + more = 1; + b = i; + e = b + 1; + } + if (more) + kprintf(", "); + if (b >= 0) { + if (b == e + 1) { + kprintf("%d", b); + } else { + kprintf("%d-%d", b, e - 1); + } + } + kprintf(") "); +} diff --git a/sys/kern/usched_bsd4.c b/sys/kern/usched_bsd4.c index 474fccba16..295a8d5842 100644 --- a/sys/kern/usched_bsd4.c +++ b/sys/kern/usched_bsd4.c @@ -1879,7 +1879,6 @@ static void sched_thread_cpu_init(void) { int i; - int cpuid; int smt_not_supported = 0; int cache_coherent_not_supported = 0; @@ -1907,13 +1906,13 @@ sched_thread_cpu_init(void) smt_not_supported = 1; cache_coherent_not_supported = 1; if (bootverbose) - kprintf ("\tcpu%d - WARNING: No CPU NODE " + kprintf (" cpu%d - WARNING: No CPU NODE " "found for cpu\n", i); } else { switch (dd->cpunode->type) { case THREAD_LEVEL: if (bootverbose) - kprintf ("\tcpu%d - HyperThreading " + kprintf (" cpu%d - HyperThreading " "available. Core siblings: ", i); break; @@ -1921,7 +1920,7 @@ sched_thread_cpu_init(void) smt_not_supported = 1; if (bootverbose) - kprintf ("\tcpu%d - No HT available, " + kprintf (" cpu%d - No HT available, " "multi-core/physical " "cpu. Physical siblings: ", i); @@ -1930,7 +1929,7 @@ sched_thread_cpu_init(void) smt_not_supported = 1; if (bootverbose) - kprintf ("\tcpu%d - No HT available, " + kprintf (" cpu%d - No HT available, " "single-core/physical cpu. " "Package Siblings: ", i); @@ -1940,7 +1939,7 @@ sched_thread_cpu_init(void) smt_not_supported = 1; cache_coherent_not_supported = 1; if (bootverbose) - kprintf ("\tcpu%d - Unknown cpunode->" + kprintf (" cpu%d - Unknown cpunode->" "type=%u. Siblings: ", i, (u_int)dd->cpunode->type); @@ -1949,10 +1948,8 @@ sched_thread_cpu_init(void) if (bootverbose) { if (dd->cpunode->parent_node != NULL) { - CPUSET_FOREACH(cpuid, - dd->cpunode->parent_node->members) { - kprintf("cpu%d ", cpuid); - } + kprint_cpuset(&dd->cpunode-> + parent_node->members); kprintf("\n"); } else { kprintf(" no siblings\n"); diff --git a/sys/kern/usched_dfly.c b/sys/kern/usched_dfly.c index 9a49defdf6..2989e10f3f 100644 --- a/sys/kern/usched_dfly.c +++ b/sys/kern/usched_dfly.c @@ -2140,7 +2140,6 @@ usched_dfly_cpu_init(void) { int i; int j; - int cpuid; int smt_not_supported = 0; int cache_coherent_not_supported = 0; @@ -2176,13 +2175,13 @@ usched_dfly_cpu_init(void) smt_not_supported = 1; cache_coherent_not_supported = 1; if (bootverbose) - kprintf ("\tcpu%d - WARNING: No CPU NODE " + kprintf (" cpu%d - WARNING: No CPU NODE " "found for cpu\n", i); } else { switch (dd->cpunode->type) { case THREAD_LEVEL: if (bootverbose) - kprintf ("\tcpu%d - HyperThreading " + kprintf (" cpu%d - HyperThreading " "available. Core siblings: ", i); break; @@ -2190,7 +2189,7 @@ usched_dfly_cpu_init(void) smt_not_supported = 1; if (bootverbose) - kprintf ("\tcpu%d - No HT available, " + kprintf (" cpu%d - No HT available, " "multi-core/physical " "cpu. Physical siblings: ", i); @@ -2199,7 +2198,7 @@ usched_dfly_cpu_init(void) smt_not_supported = 1; if (bootverbose) - kprintf ("\tcpu%d - No HT available, " + kprintf (" cpu%d - No HT available, " "single-core/physical cpu. " "Package Siblings: ", i); @@ -2209,7 +2208,7 @@ usched_dfly_cpu_init(void) smt_not_supported = 1; cache_coherent_not_supported = 1; if (bootverbose) - kprintf ("\tcpu%d - Unknown cpunode->" + kprintf (" cpu%d - Unknown cpunode->" "type=%u. Siblings: ", i, (u_int)dd->cpunode->type); @@ -2218,8 +2217,8 @@ usched_dfly_cpu_init(void) if (bootverbose) { if (dd->cpunode->parent_node != NULL) { - CPUSET_FOREACH(cpuid, dd->cpunode->parent_node->members) - kprintf("cpu%d ", cpuid); + kprint_cpuset(&dd->cpunode-> + parent_node->members); kprintf("\n"); } else { kprintf(" no siblings\n"); diff --git a/sys/sys/systm.h b/sys/sys/systm.h index 8827d21abc..dfcdd8035f 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -204,6 +204,7 @@ int kvsprintf (char *buf, const char *, __va_list) __printflike(2, 0); int ttyprintf (struct tty *, const char *, ...) __printflike(2, 3); void hexdump (const void *ptr, int length, const char *hdr, int flags); +void kprint_cpuset(cpumask_t *mask); #define HD_COLUMN_MASK 0xff #define HD_DELIM_MASK 0xff00 #define HD_OMIT_COUNT (1 << 16) -- 2.41.0