Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
c60da22a 6430a94e

+39 -52
+4 -1
tools/perf/util/env.c
··· 18 18 zfree(&env->cmdline_argv); 19 19 zfree(&env->sibling_cores); 20 20 zfree(&env->sibling_threads); 21 - zfree(&env->numa_nodes); 22 21 zfree(&env->pmu_mappings); 23 22 zfree(&env->cpu); 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); 24 27 25 28 for (i = 0; i < env->caches_cnt; i++) 26 29 cpu_cache_level__free(&env->caches[i]);
+9 -1
tools/perf/util/env.h
··· 2 2 #define __PERF_ENV_H 3 3 4 4 #include <linux/types.h> 5 + #include "cpumap.h" 5 6 6 7 struct cpu_topology_map { 7 8 int socket_id; ··· 17 16 char *type; 18 17 char *size; 19 18 char *map; 19 + }; 20 + 21 + struct numa_node { 22 + u32 node; 23 + u64 mem_total; 24 + u64 mem_free; 25 + struct cpu_map *map; 20 26 }; 21 27 22 28 struct perf_env { ··· 48 40 const char **cmdline_argv; 49 41 char *sibling_cores; 50 42 char *sibling_threads; 51 - char *numa_nodes; 52 43 char *pmu_mappings; 53 44 struct cpu_topology_map *cpu; 54 45 struct cpu_cache_level *caches; 55 46 int caches_cnt; 47 + struct numa_node *numa_nodes; 56 48 }; 57 49 58 50 extern struct perf_env perf_env;
+26 -50
tools/perf/util/header.c
··· 1306 1306 static void print_numa_topology(struct perf_header *ph, int fd __maybe_unused, 1307 1307 FILE *fp) 1308 1308 { 1309 - u32 nr, c, i; 1310 - char *str, *tmp; 1311 - uint64_t mem_total, mem_free; 1309 + int i; 1310 + struct numa_node *n; 1312 1311 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 - 1328 - str = tmp + 1; 1329 - mem_free = strtoull(str, &tmp, 0); 1330 - if (*tmp != ':') 1331 - goto error; 1312 + for (i = 0; i < ph->env.nr_numa_nodes; i++) { 1313 + n = &ph->env.numa_nodes[i]; 1332 1314 1333 1315 fprintf(fp, "# node%u meminfo : total = %"PRIu64" kB," 1334 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; 1338 - fprintf(fp, "# node%u cpu list : %s\n", c, str); 1339 - 1340 - str += strlen(str) + 1; 1319 + fprintf(fp, "# node%u cpu list : ", n->node); 1320 + cpu_map__fprintf(n->map, fp); 1341 1321 } 1342 - return; 1343 - error: 1344 - fprintf(fp, "# numa topology : not available\n"); 1345 1322 } 1346 1323 1347 1324 static void print_cpuid(struct perf_header *ph, int fd __maybe_unused, FILE *fp) ··· 1883 1906 struct perf_header *ph, int fd, 1884 1907 void *data __maybe_unused) 1885 1908 { 1909 + struct numa_node *nodes, *n; 1886 1910 ssize_t ret; 1887 - u32 nr, node, i; 1911 + u32 nr, i; 1888 1912 char *str; 1889 - uint64_t mem_total, mem_free; 1890 - struct strbuf sb; 1891 1913 1892 1914 /* nr nodes */ 1893 1915 ret = readn(fd, &nr, sizeof(nr)); ··· 1897 1921 nr = bswap_32(nr); 1898 1922 1899 1923 ph->env.nr_numa_nodes = nr; 1900 - if (strbuf_init(&sb, 256) < 0) 1901 - return -1; 1924 + nodes = zalloc(sizeof(*nodes) * nr); 1925 + if (!nodes) 1926 + return -ENOMEM; 1902 1927 1903 1928 for (i = 0; i < nr; i++) { 1929 + n = &nodes[i]; 1930 + 1904 1931 /* node number */ 1905 - ret = readn(fd, &node, sizeof(node)); 1906 - if (ret != sizeof(node)) 1932 + ret = readn(fd, &n->node, sizeof(u32)); 1933 + if (ret != sizeof(n->node)) 1907 1934 goto error; 1908 1935 1909 - ret = readn(fd, &mem_total, sizeof(u64)); 1936 + ret = readn(fd, &n->mem_total, sizeof(u64)); 1910 1937 if (ret != sizeof(u64)) 1911 1938 goto error; 1912 1939 1913 - ret = readn(fd, &mem_free, sizeof(u64)); 1940 + ret = readn(fd, &n->mem_free, sizeof(u64)); 1914 1941 if (ret != sizeof(u64)) 1915 1942 goto error; 1916 1943 1917 1944 if (ph->needs_swap) { 1918 - node = bswap_32(node); 1919 - mem_total = bswap_64(mem_total); 1920 - mem_free = bswap_64(mem_free); 1945 + n->node = bswap_32(n->node); 1946 + n->mem_total = bswap_64(n->mem_total); 1947 + n->mem_free = bswap_64(n->mem_free); 1921 1948 } 1922 - 1923 - if (strbuf_addf(&sb, "%u:%"PRIu64":%"PRIu64":", 1924 - node, mem_total, mem_free) < 0) 1925 - goto error; 1926 1949 1927 1950 str = do_read_string(fd, ph); 1928 1951 if (!str) 1929 1952 goto error; 1930 1953 1931 - /* include a NULL character at the end */ 1932 - if (strbuf_add(&sb, str, strlen(str) + 1) < 0) 1954 + n->map = cpu_map__new(str); 1955 + if (!n->map) 1933 1956 goto error; 1957 + 1934 1958 free(str); 1935 1959 } 1936 - ph->env.numa_nodes = strbuf_detach(&sb, NULL); 1960 + ph->env.numa_nodes = nodes; 1937 1961 return 0; 1938 1962 1939 1963 error: 1940 - strbuf_release(&sb); 1964 + free(nodes); 1941 1965 return -1; 1942 1966 } 1943 1967