Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 338979
b: refs/heads/master
c: 12f8f74
h: refs/heads/master
i:
  338977: f8b73de
  338975: e29cb78
v: v3
  • Loading branch information
Zheng Liu authored and Arnaldo Carvalho de Melo committed Nov 9, 2012
1 parent 1f68306 commit 08b6293
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 27 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 69d2591a829132492662bbfe164fcde5e44ad1c4
refs/heads/master: 12f8f74b2a4d26c4facfa7ef99487cf0930f6ef7
38 changes: 12 additions & 26 deletions trunk/tools/perf/tests/builtin-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,19 +605,13 @@ static int test__basic_mmap(void)
#undef nsyscalls
}

static int sched__get_first_possible_cpu(pid_t pid, cpu_set_t **maskp,
size_t *sizep)
static int sched__get_first_possible_cpu(pid_t pid, cpu_set_t *maskp)
{
cpu_set_t *mask;
size_t size;
int i, cpu = -1, nrcpus = 1024;
realloc:
mask = CPU_ALLOC(nrcpus);
size = CPU_ALLOC_SIZE(nrcpus);
CPU_ZERO_S(size, mask);
CPU_ZERO(maskp);

if (sched_getaffinity(pid, size, mask) == -1) {
CPU_FREE(mask);
if (sched_getaffinity(pid, sizeof(*maskp), maskp) == -1) {
if (errno == EINVAL && nrcpus < (1024 << 8)) {
nrcpus = nrcpus << 2;
goto realloc;
Expand All @@ -627,19 +621,14 @@ static int sched__get_first_possible_cpu(pid_t pid, cpu_set_t **maskp,
}

for (i = 0; i < nrcpus; i++) {
if (CPU_ISSET_S(i, size, mask)) {
if (cpu == -1) {
if (CPU_ISSET(i, maskp)) {
if (cpu == -1)
cpu = i;
*maskp = mask;
*sizep = size;
} else
CPU_CLR_S(i, size, mask);
else
CPU_CLR(i, maskp);
}
}

if (cpu == -1)
CPU_FREE(mask);

return cpu;
}

Expand All @@ -654,8 +643,8 @@ static int test__PERF_RECORD(void)
.freq = 10,
.mmap_pages = 256,
};
cpu_set_t *cpu_mask = NULL;
size_t cpu_mask_size = 0;
cpu_set_t cpu_mask;
size_t cpu_mask_size = sizeof(cpu_mask);
struct perf_evlist *evlist = perf_evlist__new(NULL, NULL);
struct perf_evsel *evsel;
struct perf_sample sample;
Expand Down Expand Up @@ -719,8 +708,7 @@ static int test__PERF_RECORD(void)
evsel->attr.sample_type |= PERF_SAMPLE_TIME;
perf_evlist__config_attrs(evlist, &opts);

err = sched__get_first_possible_cpu(evlist->workload.pid, &cpu_mask,
&cpu_mask_size);
err = sched__get_first_possible_cpu(evlist->workload.pid, &cpu_mask);
if (err < 0) {
pr_debug("sched__get_first_possible_cpu: %s\n", strerror(errno));
goto out_delete_evlist;
Expand All @@ -731,9 +719,9 @@ static int test__PERF_RECORD(void)
/*
* So that we can check perf_sample.cpu on all the samples.
*/
if (sched_setaffinity(evlist->workload.pid, cpu_mask_size, cpu_mask) < 0) {
if (sched_setaffinity(evlist->workload.pid, cpu_mask_size, &cpu_mask) < 0) {
pr_debug("sched_setaffinity: %s\n", strerror(errno));
goto out_free_cpu_mask;
goto out_delete_evlist;
}

/*
Expand Down Expand Up @@ -917,8 +905,6 @@ static int test__PERF_RECORD(void)
}
out_err:
perf_evlist__munmap(evlist);
out_free_cpu_mask:
CPU_FREE(cpu_mask);
out_delete_evlist:
perf_evlist__delete(evlist);
out:
Expand Down

0 comments on commit 08b6293

Please sign in to comment.