From: Li Zefan <lizf@cn.fujitsu.com> To: Ingo Molnar <mingo@elte.hu> Cc: Pekka Enberg <penberg@cs.helsinki.fi>, Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>, Peter Zijlstra <peterz@infradead.org>, Frederic Weisbecker <fweisbec@gmail.com>, LKML <linux-kernel@vger.kernel.org>, "linux-mm@kvack.org" <linux-mm@kvack.org> Subject: [PATCH 3/5] perf kmem: Collect cross node allocation statistics Date: Tue, 24 Nov 2009 13:26:31 +0800 [thread overview] Message-ID: <4B0B6E87.10906@cn.fujitsu.com> (raw) In-Reply-To: <4B0B6E44.6090106@cn.fujitsu.com> Show cross node memory allocations: # ./perf kmem SUMMARY ======= ... Cross node allocations: 0/3633 Signed-off-by: Li Zefan <lizf@cn.fujitsu.com> --- tools/perf/builtin-kmem.c | 81 +++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 79 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index dc86f1e..1ecf3f4 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -36,6 +36,9 @@ static char default_sort_order[] = "frag,hit,bytes"; static char *cwd; static int cwdlen; +static int *cpunode_map; +static int max_cpu_num; + struct alloc_stat { union { u64 call_site; @@ -54,12 +57,74 @@ static struct rb_root root_caller_stat; static struct rb_root root_caller_sorted; static unsigned long total_requested, total_allocated; +static unsigned long nr_allocs, nr_cross_allocs; struct raw_event_sample { u32 size; char data[0]; }; +#define PATH_SYS_NODE "/sys/devices/system/node" + +static void init_cpunode_map(void) +{ + FILE *fp; + int i; + + fp = fopen("/sys/devices/system/cpu/kernel_max", "r"); + if (!fp) { + max_cpu_num = 4096; + return; + } + + if (fscanf(fp, "%d", &max_cpu_num) < 1) + die("Failed to read 'kernel_max' from sysfs"); + max_cpu_num++; + + cpunode_map = calloc(max_cpu_num, sizeof(int)); + if (!cpunode_map) + die("calloc"); + for (i = 0; i < max_cpu_num; i++) + cpunode_map[i] = -1; + fclose(fp); +} + +static void setup_cpunode_map(void) +{ + struct dirent *dent1, *dent2; + DIR *dir1, *dir2; + unsigned int cpu, mem; + char buf[PATH_MAX]; + + init_cpunode_map(); + + dir1 = opendir(PATH_SYS_NODE); + if (!dir1) + return; + + while (true) { + dent1 = readdir(dir1); + if (!dent1) + break; + + if (sscanf(dent1->d_name, "node%u", &mem) < 1) + continue; + + snprintf(buf, PATH_MAX, "%s/%s", PATH_SYS_NODE, dent1->d_name); + dir2 = opendir(buf); + if (!dir2) + continue; + while (true) { + dent2 = readdir(dir2); + if (!dent2) + break; + if (sscanf(dent2->d_name, "cpu%u", &cpu) < 1) + continue; + cpunode_map[cpu] = mem; + } + } +} + static int process_comm_event(event_t *event, unsigned long offset, unsigned long head) { @@ -157,15 +222,16 @@ static void insert_caller_stat(unsigned long call_site, static void process_alloc_event(struct raw_event_sample *raw, struct event *event, - int cpu __used, + int cpu, u64 timestamp __used, struct thread *thread __used, - int node __used) + int node) { unsigned long call_site; unsigned long ptr; int bytes_req; int bytes_alloc; + int node1, node2; ptr = raw_field_value(event, "ptr", raw->data); call_site = raw_field_value(event, "call_site", raw->data); @@ -177,6 +243,14 @@ static void process_alloc_event(struct raw_event_sample *raw, total_requested += bytes_req; total_allocated += bytes_alloc; + + if (node) { + node1 = cpunode_map[cpu]; + node2 = raw_field_value(event, "node", raw->data); + if (node1 != node2) + nr_cross_allocs++; + } + nr_allocs++; } static void process_free_event(struct raw_event_sample *raw __used, @@ -359,6 +433,7 @@ static void print_summary(void) total_allocated - total_requested); printf("Internal fragmentation: %f%%\n", fragmentation(total_requested, total_allocated)); + printf("Cross CPU allocations: %lu/%lu\n", nr_cross_allocs, nr_allocs); } static void print_result(void) @@ -685,6 +760,8 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __used) if (list_empty(&alloc_sort)) setup_sorting(&alloc_sort, default_sort_order); + setup_cpunode_map(); + return __cmd_kmem(); } -- 1.6.3
WARNING: multiple messages have this Message-ID (diff)
From: Li Zefan <lizf@cn.fujitsu.com> To: Ingo Molnar <mingo@elte.hu> Cc: Pekka Enberg <penberg@cs.helsinki.fi>, Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>, Peter Zijlstra <peterz@infradead.org>, Frederic Weisbecker <fweisbec@gmail.com>, LKML <linux-kernel@vger.kernel.org>, "linux-mm@kvack.org" <linux-mm@kvack.org> Subject: [PATCH 3/5] perf kmem: Collect cross node allocation statistics Date: Tue, 24 Nov 2009 13:26:31 +0800 [thread overview] Message-ID: <4B0B6E87.10906@cn.fujitsu.com> (raw) In-Reply-To: <4B0B6E44.6090106@cn.fujitsu.com> Show cross node memory allocations: # ./perf kmem SUMMARY ======= ... Cross node allocations: 0/3633 Signed-off-by: Li Zefan <lizf@cn.fujitsu.com> --- tools/perf/builtin-kmem.c | 81 +++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 79 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index dc86f1e..1ecf3f4 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -36,6 +36,9 @@ static char default_sort_order[] = "frag,hit,bytes"; static char *cwd; static int cwdlen; +static int *cpunode_map; +static int max_cpu_num; + struct alloc_stat { union { u64 call_site; @@ -54,12 +57,74 @@ static struct rb_root root_caller_stat; static struct rb_root root_caller_sorted; static unsigned long total_requested, total_allocated; +static unsigned long nr_allocs, nr_cross_allocs; struct raw_event_sample { u32 size; char data[0]; }; +#define PATH_SYS_NODE "/sys/devices/system/node" + +static void init_cpunode_map(void) +{ + FILE *fp; + int i; + + fp = fopen("/sys/devices/system/cpu/kernel_max", "r"); + if (!fp) { + max_cpu_num = 4096; + return; + } + + if (fscanf(fp, "%d", &max_cpu_num) < 1) + die("Failed to read 'kernel_max' from sysfs"); + max_cpu_num++; + + cpunode_map = calloc(max_cpu_num, sizeof(int)); + if (!cpunode_map) + die("calloc"); + for (i = 0; i < max_cpu_num; i++) + cpunode_map[i] = -1; + fclose(fp); +} + +static void setup_cpunode_map(void) +{ + struct dirent *dent1, *dent2; + DIR *dir1, *dir2; + unsigned int cpu, mem; + char buf[PATH_MAX]; + + init_cpunode_map(); + + dir1 = opendir(PATH_SYS_NODE); + if (!dir1) + return; + + while (true) { + dent1 = readdir(dir1); + if (!dent1) + break; + + if (sscanf(dent1->d_name, "node%u", &mem) < 1) + continue; + + snprintf(buf, PATH_MAX, "%s/%s", PATH_SYS_NODE, dent1->d_name); + dir2 = opendir(buf); + if (!dir2) + continue; + while (true) { + dent2 = readdir(dir2); + if (!dent2) + break; + if (sscanf(dent2->d_name, "cpu%u", &cpu) < 1) + continue; + cpunode_map[cpu] = mem; + } + } +} + static int process_comm_event(event_t *event, unsigned long offset, unsigned long head) { @@ -157,15 +222,16 @@ static void insert_caller_stat(unsigned long call_site, static void process_alloc_event(struct raw_event_sample *raw, struct event *event, - int cpu __used, + int cpu, u64 timestamp __used, struct thread *thread __used, - int node __used) + int node) { unsigned long call_site; unsigned long ptr; int bytes_req; int bytes_alloc; + int node1, node2; ptr = raw_field_value(event, "ptr", raw->data); call_site = raw_field_value(event, "call_site", raw->data); @@ -177,6 +243,14 @@ static void process_alloc_event(struct raw_event_sample *raw, total_requested += bytes_req; total_allocated += bytes_alloc; + + if (node) { + node1 = cpunode_map[cpu]; + node2 = raw_field_value(event, "node", raw->data); + if (node1 != node2) + nr_cross_allocs++; + } + nr_allocs++; } static void process_free_event(struct raw_event_sample *raw __used, @@ -359,6 +433,7 @@ static void print_summary(void) total_allocated - total_requested); printf("Internal fragmentation: %f%%\n", fragmentation(total_requested, total_allocated)); + printf("Cross CPU allocations: %lu/%lu\n", nr_cross_allocs, nr_allocs); } static void print_result(void) @@ -685,6 +760,8 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __used) if (list_empty(&alloc_sort)) setup_sorting(&alloc_sort, default_sort_order); + setup_cpunode_map(); + return __cmd_kmem(); } -- 1.6.3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2009-11-24 5:27 UTC|newest] Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top 2009-11-24 5:25 [PATCH 0/5] perf kmem: Add more functions and show more statistics Li Zefan 2009-11-24 5:25 ` Li Zefan 2009-11-24 5:25 ` [PATCH 1/5] perf kmem: Add new option to show raw ip Li Zefan 2009-11-24 5:25 ` Li Zefan 2009-11-24 16:54 ` [tip:perf/core] " tip-bot for Li Zefan 2009-11-24 16:54 ` tip-bot for Li Zefan 2009-11-24 5:26 ` [PATCH 2/5] perf kmem: Default to sort by fragmentation Li Zefan 2009-11-24 5:26 ` Li Zefan 2009-11-24 16:55 ` [tip:perf/core] " tip-bot for Li Zefan 2009-11-24 16:55 ` tip-bot for Li Zefan 2009-11-24 5:26 ` Li Zefan [this message] 2009-11-24 5:26 ` [PATCH 3/5] perf kmem: Collect cross node allocation statistics Li Zefan 2009-11-24 16:55 ` [tip:perf/core] " tip-bot for Li Zefan 2009-11-24 16:55 ` tip-bot for Li Zefan 2009-11-24 5:26 ` [PATCH 4/5] perf kmem: Measure kmalloc/kfree CPU ping-pong call-sites Li Zefan 2009-11-24 5:26 ` Li Zefan 2009-11-24 16:55 ` [tip:perf/core] " tip-bot for Li Zefan 2009-11-24 16:55 ` tip-bot for Li Zefan 2009-11-24 5:27 ` [PATCH 5/5] perf kmem: Add help file Li Zefan 2009-11-24 5:27 ` Li Zefan 2009-11-24 16:55 ` [tip:perf/core] " tip-bot for Li Zefan 2009-11-24 16:55 ` tip-bot for Li Zefan 2009-11-24 7:15 ` [PATCH 0/5] perf kmem: Add more functions and show more statistics Pekka Enberg 2009-11-24 7:15 ` Pekka Enberg 2009-11-24 7:34 ` Ingo Molnar 2009-11-24 7:34 ` Ingo Molnar 2009-11-24 7:45 ` Pekka Enberg 2009-11-24 7:45 ` Pekka Enberg 2009-11-24 7:47 ` Ingo Molnar 2009-11-24 7:47 ` Ingo Molnar 2009-11-24 8:04 ` Li Zefan 2009-11-24 8:04 ` Li Zefan 2009-11-24 8:34 ` Ingo Molnar 2009-11-24 8:34 ` Ingo Molnar 2009-11-24 14:57 ` Arjan van de Ven 2009-11-24 14:57 ` Arjan van de Ven 2009-11-24 7:18 ` Pekka Enberg 2009-11-24 7:18 ` Pekka Enberg 2009-11-24 9:04 ` Ingo Molnar 2009-11-24 9:38 ` Li Zefan 2009-11-24 9:38 ` Li Zefan 2009-11-24 10:07 ` Ingo Molnar 2009-11-24 11:04 ` Li Zefan 2009-11-24 11:04 ` Li Zefan 2009-11-24 20:35 ` Ingo Molnar 2009-11-24 20:35 ` Ingo Molnar 2009-11-24 22:34 ` Ingo Molnar 2009-11-24 22:34 ` Ingo Molnar 2009-11-24 18:49 ` Frederic Weisbecker 2009-11-24 18:49 ` Frederic Weisbecker 2009-11-24 19:38 ` [PATCH] perf: Fix bad software/trace event recursion counting Frederic Weisbecker 2009-11-24 20:36 ` [tip:perf/core] perf_events: " tip-bot for Frederic Weisbecker 2009-11-24 20:48 ` [PATCH] perf: " Peter Zijlstra
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=4B0B6E87.10906@cn.fujitsu.com \ --to=lizf@cn.fujitsu.com \ --cc=eduard.munteanu@linux360.ro \ --cc=fweisbec@gmail.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=mingo@elte.hu \ --cc=penberg@cs.helsinki.fi \ --cc=peterz@infradead.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.