"two cores, shared L2" test: check L2 cpumask
authorNathan Lynch <ntl@pobox.com>
Tue, 14 Oct 2008 19:34:17 +0000 (14:34 -0500)
committerNathan Lynch <ntl@pobox.com>
Tue, 14 Oct 2008 19:34:17 +0000 (14:34 -0500)
Ensure that both logical CPUs are accounted in the L2 cpumask.

tests/simple_shared_cache.c

index f51d6d204f43df0143bd02db99d2615b26706c23..ebd68489d7d88ffe8d32e9cb289e9663fd376190 100644 (file)
  */
 
 #define NAME "two cores, shared L2"
+#define _GNU_SOURCE
+#include <sched.h>
 #include <string.h>
 #include "boilerplate-begin.h"
 
 {
        topo_device_t dev;
        int nr_l1 = 0, nr_l2 = 0, nr_data = 0, nr_insn = 0, nr_unified = 0;
+       cpu_set_t *cpumask;
+       size_t cpumask_size;
+
+       cpumask_size = topology_sizeof_cpumask(ctx);
+       cpumask = malloc(cpumask_size);
 
        topology_for_each_device_of_type(ctx, dev, "cache") {
                const char *level;
 
                level = topology_device_get_attribute(dev, "level");
                type = topology_device_get_attribute(dev, "type");
+               topology_device_cpumask(dev, cpumask);
 
                if (!strcmp(level, "1"))
                        nr_l1++;
-               if (!strcmp(level, "2"))
+               if (!strcmp(level, "2")) {
                        nr_l2++;
+                       /* L2 must have both CPUs in cpumask */
+                       fail_on(!CPU_ISSET_S(0, cpumask_size, cpumask));
+                       fail_on(!CPU_ISSET_S(1, cpumask_size, cpumask));
+               }
                if (!strcmp(type, "Data"))
                        nr_data++;
                if (!strcmp(type, "Instruction"))
@@ -44,6 +56,9 @@
                if (!strcmp(type, "Unified"))
                        nr_unified++;
        }
+
+       free(cpumask);
+
        fail_on(nr_l1 != 4); /* 2 data, 2 instruction */
        fail_on(nr_l2 != 1);
        fail_on(nr_data != 2);