aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2016-07-04 08:16:20 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-07-04 18:39:01 -0400
commitc60da22aca8755b77b7f4d4caf57ada8654db939 (patch)
tree850dc675f62c2f3a3097a6d411d346002d86d067 /tools/perf
parent6430a94ead2a4c8f350441351a735303eb6d1c8a (diff)
perf header: Transform nodes string info to struct
Storing NUMA info within struct numa_node instead of strings. This way it's usable in future patches. Also it turned out it's slightly less code involved than using strings. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Cc: David Ahern <dsahern@gmail.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/1467634583-29147-2-git-send-email-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/util/env.c5
-rw-r--r--tools/perf/util/env.h10
-rw-r--r--tools/perf/util/header.c76
3 files changed, 39 insertions, 52 deletions
diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c
index 49a11d9d8b8f..bb964e86b09d 100644
--- a/tools/perf/util/env.c
+++ b/tools/perf/util/env.c
@@ -18,10 +18,13 @@ void perf_env__exit(struct perf_env *env)
18 zfree(&env->cmdline_argv); 18 zfree(&env->cmdline_argv);
19 zfree(&env->sibling_cores); 19 zfree(&env->sibling_cores);
20 zfree(&env->sibling_threads); 20 zfree(&env->sibling_threads);
21 zfree(&env->numa_nodes);
22 zfree(&env->pmu_mappings); 21 zfree(&env->pmu_mappings);
23 zfree(&env->cpu); 22 zfree(&env->cpu);
24 23
24 for (i = 0; i < env->nr_numa_nodes; i++)
25 cpu_map__put(env->numa_nodes[i].map);
26 zfree(&env->numa_nodes);
27
25 for (i = 0; i < env->caches_cnt; i++) 28 for (i = 0; i < env->caches_cnt; i++)
26 cpu_cache_level__free(&env->caches[i]); 29 cpu_cache_level__free(&env->caches[i]);
27 zfree(&env->caches); 30 zfree(&env->caches);
diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h
index 56cffb60a0b4..b164dfd2dcbf 100644
--- a/tools/perf/util/env.h
+++ b/tools/perf/util/env.h
@@ -2,6 +2,7 @@
2#define __PERF_ENV_H 2#define __PERF_ENV_H
3 3
4#include <linux/types.h> 4#include <linux/types.h>
5#include "cpumap.h"
5 6
6struct cpu_topology_map { 7struct cpu_topology_map {
7 int socket_id; 8 int socket_id;
@@ -18,6 +19,13 @@ struct cpu_cache_level {
18 char *map; 19 char *map;
19}; 20};
20 21
22struct numa_node {
23 u32 node;
24 u64 mem_total;
25 u64 mem_free;
26 struct cpu_map *map;
27};
28
21struct perf_env { 29struct perf_env {
22 char *hostname; 30 char *hostname;
23 char *os_release; 31 char *os_release;
@@ -40,11 +48,11 @@ struct perf_env {
40 const char **cmdline_argv; 48 const char **cmdline_argv;
41 char *sibling_cores; 49 char *sibling_cores;
42 char *sibling_threads; 50 char *sibling_threads;
43 char *numa_nodes;
44 char *pmu_mappings; 51 char *pmu_mappings;
45 struct cpu_topology_map *cpu; 52 struct cpu_topology_map *cpu;
46 struct cpu_cache_level *caches; 53 struct cpu_cache_level *caches;
47 int caches_cnt; 54 int caches_cnt;
55 struct numa_node *numa_nodes;
48}; 56};
49 57
50extern struct perf_env perf_env; 58extern struct perf_env perf_env;
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index c5cd2698281f..8f0db4007282 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1306,42 +1306,19 @@ static void print_total_mem(struct perf_header *ph, int fd __maybe_unused,
1306static void print_numa_topology(struct perf_header *ph, int fd __maybe_unused, 1306static void print_numa_topology(struct perf_header *ph, int fd __maybe_unused,
1307 FILE *fp) 1307 FILE *fp)
1308{ 1308{
1309 u32 nr, c, i; 1309 int i;
1310 char *str, *tmp; 1310 struct numa_node *n;
1311 uint64_t mem_total, mem_free;
1312
1313 /* nr nodes */
1314 nr = ph->env.nr_numa_nodes;
1315 str = ph->env.numa_nodes;
1316
1317 for (i = 0; i < nr; i++) {
1318 /* node number */
1319 c = strtoul(str, &tmp, 0);
1320 if (*tmp != ':')
1321 goto error;
1322
1323 str = tmp + 1;
1324 mem_total = strtoull(str, &tmp, 0);
1325 if (*tmp != ':')
1326 goto error;
1327 1311
1328 str = tmp + 1; 1312 for (i = 0; i < ph->env.nr_numa_nodes; i++) {
1329 mem_free = strtoull(str, &tmp, 0); 1313 n = &ph->env.numa_nodes[i];
1330 if (*tmp != ':')
1331 goto error;
1332 1314
1333 fprintf(fp, "# node%u meminfo : total = %"PRIu64" kB," 1315 fprintf(fp, "# node%u meminfo : total = %"PRIu64" kB,"
1334 " free = %"PRIu64" kB\n", 1316 " free = %"PRIu64" kB\n",
1335 c, mem_total, mem_free); 1317 n->node, n->mem_total, n->mem_free);
1336 1318
1337 str = tmp + 1; 1319 fprintf(fp, "# node%u cpu list : ", n->node);
1338 fprintf(fp, "# node%u cpu list : %s\n", c, str); 1320 cpu_map__fprintf(n->map, fp);
1339
1340 str += strlen(str) + 1;
1341 } 1321 }
1342 return;
1343error:
1344 fprintf(fp, "# numa topology : not available\n");
1345} 1322}
1346 1323
1347static void print_cpuid(struct perf_header *ph, int fd __maybe_unused, FILE *fp) 1324static void print_cpuid(struct perf_header *ph, int fd __maybe_unused, FILE *fp)
@@ -1906,11 +1883,10 @@ static int process_numa_topology(struct perf_file_section *section __maybe_unuse
1906 struct perf_header *ph, int fd, 1883 struct perf_header *ph, int fd,
1907 void *data __maybe_unused) 1884 void *data __maybe_unused)
1908{ 1885{
1886 struct numa_node *nodes, *n;
1909 ssize_t ret; 1887 ssize_t ret;
1910 u32 nr, node, i; 1888 u32 nr, i;
1911 char *str; 1889 char *str;
1912 uint64_t mem_total, mem_free;
1913 struct strbuf sb;
1914 1890
1915 /* nr nodes */ 1891 /* nr nodes */
1916 ret = readn(fd, &nr, sizeof(nr)); 1892 ret = readn(fd, &nr, sizeof(nr));
@@ -1921,47 +1897,47 @@ static int process_numa_topology(struct perf_file_section *section __maybe_unuse
1921 nr = bswap_32(nr); 1897 nr = bswap_32(nr);
1922 1898
1923 ph->env.nr_numa_nodes = nr; 1899 ph->env.nr_numa_nodes = nr;
1924 if (strbuf_init(&sb, 256) < 0) 1900 nodes = zalloc(sizeof(*nodes) * nr);
1925 return -1; 1901 if (!nodes)
1902 return -ENOMEM;
1926 1903
1927 for (i = 0; i < nr; i++) { 1904 for (i = 0; i < nr; i++) {
1905 n = &nodes[i];
1906
1928 /* node number */ 1907 /* node number */
1929 ret = readn(fd, &node, sizeof(node)); 1908 ret = readn(fd, &n->node, sizeof(u32));
1930 if (ret != sizeof(node)) 1909 if (ret != sizeof(n->node))
1931 goto error; 1910 goto error;
1932 1911
1933 ret = readn(fd, &mem_total, sizeof(u64)); 1912 ret = readn(fd, &n->mem_total, sizeof(u64));
1934 if (ret != sizeof(u64)) 1913 if (ret != sizeof(u64))
1935 goto error; 1914 goto error;
1936 1915
1937 ret = readn(fd, &mem_free, sizeof(u64)); 1916 ret = readn(fd, &n->mem_free, sizeof(u64));
1938 if (ret != sizeof(u64)) 1917 if (ret != sizeof(u64))
1939 goto error; 1918 goto error;
1940 1919
1941 if (ph->needs_swap) { 1920 if (ph->needs_swap) {
1942 node = bswap_32(node); 1921 n->node = bswap_32(n->node);
1943 mem_total = bswap_64(mem_total); 1922 n->mem_total = bswap_64(n->mem_total);
1944 mem_free = bswap_64(mem_free); 1923 n->mem_free = bswap_64(n->mem_free);
1945 } 1924 }
1946 1925
1947 if (strbuf_addf(&sb, "%u:%"PRIu64":%"PRIu64":",
1948 node, mem_total, mem_free) < 0)
1949 goto error;
1950
1951 str = do_read_string(fd, ph); 1926 str = do_read_string(fd, ph);
1952 if (!str) 1927 if (!str)
1953 goto error; 1928 goto error;
1954 1929
1955 /* include a NULL character at the end */ 1930 n->map = cpu_map__new(str);
1956 if (strbuf_add(&sb, str, strlen(str) + 1) < 0) 1931 if (!n->map)
1957 goto error; 1932 goto error;
1933
1958 free(str); 1934 free(str);
1959 } 1935 }
1960 ph->env.numa_nodes = strbuf_detach(&sb, NULL); 1936 ph->env.numa_nodes = nodes;
1961 return 0; 1937 return 0;
1962 1938
1963error: 1939error:
1964 strbuf_release(&sb); 1940 free(nodes);
1965 return -1; 1941 return -1;
1966} 1942}
1967 1943