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>
This commit is contained in:
Jiri Olsa 2016-07-04 14:16:20 +02:00 committed by Arnaldo Carvalho de Melo
parent 6430a94ead
commit c60da22aca
3 changed files with 39 additions and 52 deletions

View File

@ -18,10 +18,13 @@ void perf_env__exit(struct perf_env *env)
zfree(&env->cmdline_argv); zfree(&env->cmdline_argv);
zfree(&env->sibling_cores); zfree(&env->sibling_cores);
zfree(&env->sibling_threads); zfree(&env->sibling_threads);
zfree(&env->numa_nodes);
zfree(&env->pmu_mappings); zfree(&env->pmu_mappings);
zfree(&env->cpu); zfree(&env->cpu);
for (i = 0; i < env->nr_numa_nodes; i++)
cpu_map__put(env->numa_nodes[i].map);
zfree(&env->numa_nodes);
for (i = 0; i < env->caches_cnt; i++) for (i = 0; i < env->caches_cnt; i++)
cpu_cache_level__free(&env->caches[i]); cpu_cache_level__free(&env->caches[i]);
zfree(&env->caches); zfree(&env->caches);

View File

@ -2,6 +2,7 @@
#define __PERF_ENV_H #define __PERF_ENV_H
#include <linux/types.h> #include <linux/types.h>
#include "cpumap.h"
struct cpu_topology_map { struct cpu_topology_map {
int socket_id; int socket_id;
@ -18,6 +19,13 @@ struct cpu_cache_level {
char *map; char *map;
}; };
struct numa_node {
u32 node;
u64 mem_total;
u64 mem_free;
struct cpu_map *map;
};
struct perf_env { struct perf_env {
char *hostname; char *hostname;
char *os_release; char *os_release;
@ -40,11 +48,11 @@ struct perf_env {
const char **cmdline_argv; const char **cmdline_argv;
char *sibling_cores; char *sibling_cores;
char *sibling_threads; char *sibling_threads;
char *numa_nodes;
char *pmu_mappings; char *pmu_mappings;
struct cpu_topology_map *cpu; struct cpu_topology_map *cpu;
struct cpu_cache_level *caches; struct cpu_cache_level *caches;
int caches_cnt; int caches_cnt;
struct numa_node *numa_nodes;
}; };
extern struct perf_env perf_env; extern struct perf_env perf_env;

View File

@ -1306,42 +1306,19 @@ static void print_total_mem(struct perf_header *ph, int fd __maybe_unused,
static void print_numa_topology(struct perf_header *ph, int fd __maybe_unused, static void print_numa_topology(struct perf_header *ph, int fd __maybe_unused,
FILE *fp) FILE *fp)
{ {
u32 nr, c, i; int i;
char *str, *tmp; struct numa_node *n;
uint64_t mem_total, mem_free;
/* nr nodes */ for (i = 0; i < ph->env.nr_numa_nodes; i++) {
nr = ph->env.nr_numa_nodes; n = &ph->env.numa_nodes[i];
str = ph->env.numa_nodes;
for (i = 0; i < nr; i++) {
/* node number */
c = strtoul(str, &tmp, 0);
if (*tmp != ':')
goto error;
str = tmp + 1;
mem_total = strtoull(str, &tmp, 0);
if (*tmp != ':')
goto error;
str = tmp + 1;
mem_free = strtoull(str, &tmp, 0);
if (*tmp != ':')
goto error;
fprintf(fp, "# node%u meminfo : total = %"PRIu64" kB," fprintf(fp, "# node%u meminfo : total = %"PRIu64" kB,"
" free = %"PRIu64" kB\n", " free = %"PRIu64" kB\n",
c, mem_total, mem_free); n->node, n->mem_total, n->mem_free);
str = tmp + 1; fprintf(fp, "# node%u cpu list : ", n->node);
fprintf(fp, "# node%u cpu list : %s\n", c, str); cpu_map__fprintf(n->map, fp);
str += strlen(str) + 1;
} }
return;
error:
fprintf(fp, "# numa topology : not available\n");
} }
static void print_cpuid(struct perf_header *ph, int fd __maybe_unused, FILE *fp) static 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
struct perf_header *ph, int fd, struct perf_header *ph, int fd,
void *data __maybe_unused) void *data __maybe_unused)
{ {
struct numa_node *nodes, *n;
ssize_t ret; ssize_t ret;
u32 nr, node, i; u32 nr, i;
char *str; char *str;
uint64_t mem_total, mem_free;
struct strbuf sb;
/* nr nodes */ /* nr nodes */
ret = readn(fd, &nr, sizeof(nr)); ret = readn(fd, &nr, sizeof(nr));
@ -1921,47 +1897,47 @@ static int process_numa_topology(struct perf_file_section *section __maybe_unuse
nr = bswap_32(nr); nr = bswap_32(nr);
ph->env.nr_numa_nodes = nr; ph->env.nr_numa_nodes = nr;
if (strbuf_init(&sb, 256) < 0) nodes = zalloc(sizeof(*nodes) * nr);
return -1; if (!nodes)
return -ENOMEM;
for (i = 0; i < nr; i++) { for (i = 0; i < nr; i++) {
n = &nodes[i];
/* node number */ /* node number */
ret = readn(fd, &node, sizeof(node)); ret = readn(fd, &n->node, sizeof(u32));
if (ret != sizeof(node)) if (ret != sizeof(n->node))
goto error; goto error;
ret = readn(fd, &mem_total, sizeof(u64)); ret = readn(fd, &n->mem_total, sizeof(u64));
if (ret != sizeof(u64)) if (ret != sizeof(u64))
goto error; goto error;
ret = readn(fd, &mem_free, sizeof(u64)); ret = readn(fd, &n->mem_free, sizeof(u64));
if (ret != sizeof(u64)) if (ret != sizeof(u64))
goto error; goto error;
if (ph->needs_swap) { if (ph->needs_swap) {
node = bswap_32(node); n->node = bswap_32(n->node);
mem_total = bswap_64(mem_total); n->mem_total = bswap_64(n->mem_total);
mem_free = bswap_64(mem_free); n->mem_free = bswap_64(n->mem_free);
} }
if (strbuf_addf(&sb, "%u:%"PRIu64":%"PRIu64":",
node, mem_total, mem_free) < 0)
goto error;
str = do_read_string(fd, ph); str = do_read_string(fd, ph);
if (!str) if (!str)
goto error; goto error;
/* include a NULL character at the end */ n->map = cpu_map__new(str);
if (strbuf_add(&sb, str, strlen(str) + 1) < 0) if (!n->map)
goto error; goto error;
free(str); free(str);
} }
ph->env.numa_nodes = strbuf_detach(&sb, NULL); ph->env.numa_nodes = nodes;
return 0; return 0;
error: error:
strbuf_release(&sb); free(nodes);
return -1; return -1;
} }