kernel - Reduce console spam in verbose mode when printing cpu sets
authorMatthew Dillon <dillon@apollo.backplane.com>
Sun, 13 Jul 2014 00:20:29 +0000 (17:20 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Sun, 13 Jul 2014 00:29:32 +0000 (17:29 -0700)
* 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
sys/kern/subr_prf.c
sys/kern/usched_bsd4.c
sys/kern/usched_dfly.c
sys/sys/systm.h

index 8338551..26c2027 100644 (file)
@@ -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)
index 9ea0402..f1a5570 100644 (file)
@@ -55,6 +55,7 @@
 #include <sys/ctype.h>
 #include <sys/eventhandler.h>
 #include <sys/kthread.h>
+#include <sys/cpu_topology.h>
 
 #include <sys/thread2.h>
 #include <sys/spinlock2.h>
@@ -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(") ");
+}
index 474fccb..295a8d5 100644 (file)
@@ -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");
index 9a49def..2989e10 100644 (file)
@@ -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");
index 8827d21..dfcdd80 100644 (file)
@@ -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)