~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/perf/tests/topology.c

Version: ~ [ linux-5.1-rc2 ] ~ [ linux-5.0.4 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.31 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.108 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.165 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.177 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.137 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.63 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.39.4 ] ~ [ linux-2.6.38.8 ] ~ [ linux-2.6.37.6 ] ~ [ linux-2.6.36.4 ] ~ [ linux-2.6.35.14 ] ~ [ linux-2.6.34.15 ] ~ [ linux-2.6.33.20 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 #include <string.h>
  3 #include <stdlib.h>
  4 #include <stdio.h>
  5 #include "tests.h"
  6 #include "util.h"
  7 #include "session.h"
  8 #include "evlist.h"
  9 #include "debug.h"
 10 
 11 #define TEMPL "/tmp/perf-test-XXXXXX"
 12 #define DATA_SIZE       10
 13 
 14 static int get_temp(char *path)
 15 {
 16         int fd;
 17 
 18         strcpy(path, TEMPL);
 19 
 20         fd = mkstemp(path);
 21         if (fd < 0) {
 22                 perror("mkstemp failed");
 23                 return -1;
 24         }
 25 
 26         close(fd);
 27         return 0;
 28 }
 29 
 30 static int session_write_header(char *path)
 31 {
 32         struct perf_session *session;
 33         struct perf_data data = {
 34                 .file      = {
 35                         .path = path,
 36                 },
 37                 .mode      = PERF_DATA_MODE_WRITE,
 38         };
 39 
 40         session = perf_session__new(&data, false, NULL);
 41         TEST_ASSERT_VAL("can't get session", session);
 42 
 43         session->evlist = perf_evlist__new_default();
 44         TEST_ASSERT_VAL("can't get evlist", session->evlist);
 45 
 46         perf_header__set_feat(&session->header, HEADER_CPU_TOPOLOGY);
 47         perf_header__set_feat(&session->header, HEADER_NRCPUS);
 48         perf_header__set_feat(&session->header, HEADER_ARCH);
 49 
 50         session->header.data_size += DATA_SIZE;
 51 
 52         TEST_ASSERT_VAL("failed to write header",
 53                         !perf_session__write_header(session, session->evlist, data.file.fd, true));
 54 
 55         perf_session__delete(session);
 56 
 57         return 0;
 58 }
 59 
 60 static int check_cpu_topology(char *path, struct cpu_map *map)
 61 {
 62         struct perf_session *session;
 63         struct perf_data data = {
 64                 .file      = {
 65                         .path = path,
 66                 },
 67                 .mode      = PERF_DATA_MODE_READ,
 68         };
 69         int i;
 70 
 71         session = perf_session__new(&data, false, NULL);
 72         TEST_ASSERT_VAL("can't get session", session);
 73 
 74         /* On platforms with large numbers of CPUs process_cpu_topology()
 75          * might issue an error while reading the perf.data file section
 76          * HEADER_CPU_TOPOLOGY and the cpu_topology_map pointed to by member
 77          * cpu is a NULL pointer.
 78          * Example: On s390
 79          *   CPU 0 is on core_id 0 and physical_package_id 6
 80          *   CPU 1 is on core_id 1 and physical_package_id 3
 81          *
 82          *   Core_id and physical_package_id are platform and architecture
 83          *   dependend and might have higher numbers than the CPU id.
 84          *   This actually depends on the configuration.
 85          *
 86          *  In this case process_cpu_topology() prints error message:
 87          *  "socket_id number is too big. You may need to upgrade the
 88          *  perf tool."
 89          *
 90          *  This is the reason why this test might be skipped.
 91          */
 92         if (!session->header.env.cpu)
 93                 return TEST_SKIP;
 94 
 95         for (i = 0; i < session->header.env.nr_cpus_avail; i++) {
 96                 if (!cpu_map__has(map, i))
 97                         continue;
 98                 pr_debug("CPU %d, core %d, socket %d\n", i,
 99                          session->header.env.cpu[i].core_id,
100                          session->header.env.cpu[i].socket_id);
101         }
102 
103         for (i = 0; i < map->nr; i++) {
104                 TEST_ASSERT_VAL("Core ID doesn't match",
105                         (session->header.env.cpu[map->map[i]].core_id == (cpu_map__get_core(map, i, NULL) & 0xffff)));
106 
107                 TEST_ASSERT_VAL("Socket ID doesn't match",
108                         (session->header.env.cpu[map->map[i]].socket_id == cpu_map__get_socket(map, i, NULL)));
109         }
110 
111         perf_session__delete(session);
112 
113         return 0;
114 }
115 
116 int test__session_topology(struct test *test __maybe_unused, int subtest __maybe_unused)
117 {
118         char path[PATH_MAX];
119         struct cpu_map *map;
120         int ret = TEST_FAIL;
121 
122         TEST_ASSERT_VAL("can't get templ file", !get_temp(path));
123 
124         pr_debug("templ file: %s\n", path);
125 
126         if (session_write_header(path))
127                 goto free_path;
128 
129         map = cpu_map__new(NULL);
130         if (map == NULL) {
131                 pr_debug("failed to get system cpumap\n");
132                 goto free_path;
133         }
134 
135         ret = check_cpu_topology(path, map);
136         cpu_map__put(map);
137 
138 free_path:
139         unlink(path);
140         return ret;
141 }
142 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp