Skip to content

Commit

Permalink
perf tools: Refactor cpumap to hold nr and the map
Browse files Browse the repository at this point in the history
So that later, we can pass the cpu_map instance instead of (nr_cpus, cpu_map)
for things like perf_evsel__open and friends.

Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Arnaldo Carvalho de Melo committed Jan 4, 2011
1 parent 4829060 commit 60d567e
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 67 deletions.
14 changes: 7 additions & 7 deletions tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static u64 user_interval = ULLONG_MAX;
static u64 default_interval = 0;
static u64 sample_type;

static int nr_cpus = 0;
static struct cpu_map *cpus;
static unsigned int page_size;
static unsigned int mmap_pages = 128;
static unsigned int user_freq = UINT_MAX;
Expand Down Expand Up @@ -670,8 +670,8 @@ static int __cmd_record(int argc, const char **argv)
if (!system_wide && no_inherit && !cpu_list) {
open_counters(-1);
} else {
for (i = 0; i < nr_cpus; i++)
open_counters(cpumap[i]);
for (i = 0; i < cpus->nr; i++)
open_counters(cpus->map[i]);
}

perf_session__set_sample_type(session, sample_type);
Expand Down Expand Up @@ -927,14 +927,14 @@ int cmd_record(int argc, const char **argv, const char *prefix __used)
thread_num = 1;
}

nr_cpus = read_cpu_map(cpu_list);
if (nr_cpus < 1) {
perror("failed to collect number of CPUs");
cpus = cpu_map__new(cpu_list);
if (cpus == NULL) {
perror("failed to parse CPUs map");
return -1;
}

list_for_each_entry(pos, &evsel_list, node) {
if (perf_evsel__alloc_fd(pos, nr_cpus, thread_num) < 0)
if (perf_evsel__alloc_fd(pos, cpus->nr, thread_num) < 0)
goto out_free_fd;
}
event_array = malloc(
Expand Down
36 changes: 18 additions & 18 deletions tools/perf/builtin-stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static struct perf_event_attr default_attrs[] = {
};

static bool system_wide = false;
static int nr_cpus = 0;
static struct cpu_map *cpus;
static int run_idx = 0;

static int run_count = 1;
Expand Down Expand Up @@ -167,7 +167,7 @@ static int create_perf_stat_counter(struct perf_evsel *evsel)
PERF_FORMAT_TOTAL_TIME_RUNNING;

if (system_wide)
return perf_evsel__open_per_cpu(evsel, nr_cpus, cpumap);
return perf_evsel__open_per_cpu(evsel, cpus->nr, cpus->map);

attr->inherit = !no_inherit;
if (target_pid == -1 && target_tid == -1) {
Expand Down Expand Up @@ -200,7 +200,7 @@ static int read_counter_aggr(struct perf_evsel *counter)
u64 *count = counter->counts->aggr.values;
int i;

if (__perf_evsel__read(counter, nr_cpus, thread_num, scale) < 0)
if (__perf_evsel__read(counter, cpus->nr, thread_num, scale) < 0)
return -1;

for (i = 0; i < 3; i++)
Expand Down Expand Up @@ -233,7 +233,7 @@ static int read_counter(struct perf_evsel *counter)
u64 *count;
int cpu;

for (cpu = 0; cpu < nr_cpus; cpu++) {
for (cpu = 0; cpu < cpus->nr; cpu++) {
if (__perf_evsel__read_on_cpu(counter, cpu, 0, scale) < 0)
return -1;

Expand All @@ -259,9 +259,6 @@ static int run_perf_stat(int argc __used, const char **argv)
const bool forks = (argc > 0);
char buf;

if (!system_wide)
nr_cpus = 1;

if (forks && (pipe(child_ready_pipe) < 0 || pipe(go_pipe) < 0)) {
perror("failed to create pipes");
exit(1);
Expand Down Expand Up @@ -351,12 +348,12 @@ static int run_perf_stat(int argc __used, const char **argv)
if (no_aggr) {
list_for_each_entry(counter, &evsel_list, node) {
read_counter(counter);
perf_evsel__close_fd(counter, nr_cpus, 1);
perf_evsel__close_fd(counter, cpus->nr, 1);
}
} else {
list_for_each_entry(counter, &evsel_list, node) {
read_counter_aggr(counter);
perf_evsel__close_fd(counter, nr_cpus, thread_num);
perf_evsel__close_fd(counter, cpus->nr, thread_num);
}
}

Expand Down Expand Up @@ -384,7 +381,7 @@ static void nsec_printout(int cpu, struct perf_evsel *evsel, double avg)
if (no_aggr)
sprintf(cpustr, "CPU%*d%s",
csv_output ? 0 : -4,
cpumap[cpu], csv_sep);
cpus->map[cpu], csv_sep);

fprintf(stderr, fmt, cpustr, msecs, csv_sep, event_name(evsel));

Expand Down Expand Up @@ -412,7 +409,7 @@ static void abs_printout(int cpu, struct perf_evsel *evsel, double avg)
if (no_aggr)
sprintf(cpustr, "CPU%*d%s",
csv_output ? 0 : -4,
cpumap[cpu], csv_sep);
cpus->map[cpu], csv_sep);
else
cpu = 0;

Expand Down Expand Up @@ -498,14 +495,14 @@ static void print_counter(struct perf_evsel *counter)
u64 ena, run, val;
int cpu;

for (cpu = 0; cpu < nr_cpus; cpu++) {
for (cpu = 0; cpu < cpus->nr; cpu++) {
val = counter->counts->cpu[cpu].val;
ena = counter->counts->cpu[cpu].ena;
run = counter->counts->cpu[cpu].run;
if (run == 0 || ena == 0) {
fprintf(stderr, "CPU%*d%s%*s%s%-24s",
csv_output ? 0 : -4,
cpumap[cpu], csv_sep,
cpus->map[cpu], csv_sep,
csv_output ? 0 : 18,
"<not counted>", csv_sep,
event_name(counter));
Expand Down Expand Up @@ -697,12 +694,15 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
}

if (system_wide)
nr_cpus = read_cpu_map(cpu_list);
cpus = cpu_map__new(cpu_list);
else
nr_cpus = 1;
cpus = cpu_map__dummy_new();

if (nr_cpus < 1)
if (cpus == NULL) {
perror("failed to parse CPUs map");
usage_with_options(stat_usage, options);
return -1;
}

if (target_pid != -1) {
target_tid = target_pid;
Expand All @@ -723,8 +723,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)

list_for_each_entry(pos, &evsel_list, node) {
if (perf_evsel__alloc_stat_priv(pos) < 0 ||
perf_evsel__alloc_counts(pos, nr_cpus) < 0 ||
perf_evsel__alloc_fd(pos, nr_cpus, thread_num) < 0)
perf_evsel__alloc_counts(pos, cpus->nr) < 0 ||
perf_evsel__alloc_fd(pos, cpus->nr, thread_num) < 0)
goto out_free_fd;
}

Expand Down
22 changes: 11 additions & 11 deletions tools/perf/builtin-top.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static int target_tid = -1;
static pid_t *all_tids = NULL;
static int thread_num = 0;
static bool inherit = false;
static int nr_cpus = 0;
static struct cpu_map *cpus;
static int realtime_prio = 0;
static bool group = false;
static unsigned int page_size;
Expand Down Expand Up @@ -564,12 +564,12 @@ static void print_sym_table(void)
printf(" (all");

if (cpu_list)
printf(", CPU%s: %s)\n", nr_cpus > 1 ? "s" : "", cpu_list);
printf(", CPU%s: %s)\n", cpus->nr > 1 ? "s" : "", cpu_list);
else {
if (target_tid != -1)
printf(")\n");
else
printf(", %d CPU%s)\n", nr_cpus, nr_cpus > 1 ? "s" : "");
printf(", %d CPU%s)\n", cpus->nr, cpus->nr > 1 ? "s" : "");
}

printf("%-*.*s\n", win_width, win_width, graph_dotted_line);
Expand Down Expand Up @@ -1197,7 +1197,7 @@ static void perf_session__mmap_read(struct perf_session *self)
struct perf_evsel *counter;
int i, thread_index;

for (i = 0; i < nr_cpus; i++) {
for (i = 0; i < cpus->nr; i++) {
list_for_each_entry(counter, &evsel_list, node) {
for (thread_index = 0;
thread_index < thread_num;
Expand All @@ -1221,7 +1221,7 @@ static void start_counter(int i, struct perf_evsel *evsel)
int thread_index;

if (target_tid == -1)
cpu = cpumap[i];
cpu = cpus->map[i];

attr = &evsel->attr;

Expand Down Expand Up @@ -1310,7 +1310,7 @@ static int __cmd_top(void)
else
event__synthesize_threads(event__process, session);

for (i = 0; i < nr_cpus; i++) {
for (i = 0; i < cpus->nr; i++) {
group_fd = -1;
list_for_each_entry(counter, &evsel_list, node)
start_counter(i, counter);
Expand Down Expand Up @@ -1460,16 +1460,16 @@ int cmd_top(int argc, const char **argv, const char *prefix __used)
}

if (target_tid != -1)
nr_cpus = 1;
cpus = cpu_map__dummy_new();
else
nr_cpus = read_cpu_map(cpu_list);
cpus = cpu_map__new(cpu_list);

if (nr_cpus < 1)
if (cpus == NULL)
usage_with_options(top_usage, options);

list_for_each_entry(pos, &evsel_list, node) {
if (perf_evsel__alloc_mmap_per_thread(pos, nr_cpus, thread_num) < 0 ||
perf_evsel__alloc_fd(pos, nr_cpus, thread_num) < 0)
if (perf_evsel__alloc_mmap_per_thread(pos, cpus->nr, thread_num) < 0 ||
perf_evsel__alloc_fd(pos, cpus->nr, thread_num) < 0)
goto out_free_fd;
/*
* Fill in the ones not specifically initialized via -c:
Expand Down
Loading

0 comments on commit 60d567e

Please sign in to comment.