diff options
author | Adrian Hunter <adrian.hunter@intel.com> | 2013-07-04 09:20:26 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-07-12 12:52:54 -0400 |
commit | 93edcbd91d888c7530c7fc749176fc935b8e2287 (patch) | |
tree | 62d98c3dd72bb775fc965b7d71b324ffbfaffecc /tools/perf/util | |
parent | b6b96fb48f75d62858b39baf13c83c4504642f15 (diff) |
perf evlist: Tidy duplicated munmap code
The same lines of code are used in three places. Make it a new function
'__perf_evlist__munmap()'.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1372944040-32690-8-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util')
-rw-r--r-- | tools/perf/util/evlist.c | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index d8f34e0afbfb..42ea4e947eb8 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c | |||
@@ -403,16 +403,20 @@ union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx) | |||
403 | return event; | 403 | return event; |
404 | } | 404 | } |
405 | 405 | ||
406 | static void __perf_evlist__munmap(struct perf_evlist *evlist, int idx) | ||
407 | { | ||
408 | if (evlist->mmap[idx].base != NULL) { | ||
409 | munmap(evlist->mmap[idx].base, evlist->mmap_len); | ||
410 | evlist->mmap[idx].base = NULL; | ||
411 | } | ||
412 | } | ||
413 | |||
406 | void perf_evlist__munmap(struct perf_evlist *evlist) | 414 | void perf_evlist__munmap(struct perf_evlist *evlist) |
407 | { | 415 | { |
408 | int i; | 416 | int i; |
409 | 417 | ||
410 | for (i = 0; i < evlist->nr_mmaps; i++) { | 418 | for (i = 0; i < evlist->nr_mmaps; i++) |
411 | if (evlist->mmap[i].base != NULL) { | 419 | __perf_evlist__munmap(evlist, i); |
412 | munmap(evlist->mmap[i].base, evlist->mmap_len); | ||
413 | evlist->mmap[i].base = NULL; | ||
414 | } | ||
415 | } | ||
416 | 420 | ||
417 | free(evlist->mmap); | 421 | free(evlist->mmap); |
418 | evlist->mmap = NULL; | 422 | evlist->mmap = NULL; |
@@ -477,12 +481,8 @@ static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist, int prot, int m | |||
477 | return 0; | 481 | return 0; |
478 | 482 | ||
479 | out_unmap: | 483 | out_unmap: |
480 | for (cpu = 0; cpu < nr_cpus; cpu++) { | 484 | for (cpu = 0; cpu < nr_cpus; cpu++) |
481 | if (evlist->mmap[cpu].base != NULL) { | 485 | __perf_evlist__munmap(evlist, cpu); |
482 | munmap(evlist->mmap[cpu].base, evlist->mmap_len); | ||
483 | evlist->mmap[cpu].base = NULL; | ||
484 | } | ||
485 | } | ||
486 | return -1; | 486 | return -1; |
487 | } | 487 | } |
488 | 488 | ||
@@ -517,12 +517,8 @@ static int perf_evlist__mmap_per_thread(struct perf_evlist *evlist, int prot, in | |||
517 | return 0; | 517 | return 0; |
518 | 518 | ||
519 | out_unmap: | 519 | out_unmap: |
520 | for (thread = 0; thread < nr_threads; thread++) { | 520 | for (thread = 0; thread < nr_threads; thread++) |
521 | if (evlist->mmap[thread].base != NULL) { | 521 | __perf_evlist__munmap(evlist, thread); |
522 | munmap(evlist->mmap[thread].base, evlist->mmap_len); | ||
523 | evlist->mmap[thread].base = NULL; | ||
524 | } | ||
525 | } | ||
526 | return -1; | 522 | return -1; |
527 | } | 523 | } |
528 | 524 | ||