Commit 7074674e authored by Andi Kleen's avatar Andi Kleen Committed by Arnaldo Carvalho de Melo

perf cpumap: Maintain cpumaps ordered and without dups

Enforce this in _trim()

Needed for followon change.
Signed-off-by: default avatarAndi Kleen <ak@linux.intel.com>
Acked-by: default avatarJiri Olsa <jolsa@kernel.org>
Link: http://lore.kernel.org/lkml/20191121001522.180827-4-andi@firstfloor.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent e680a41f
...@@ -68,14 +68,28 @@ static struct perf_cpu_map *cpu_map__default_new(void) ...@@ -68,14 +68,28 @@ static struct perf_cpu_map *cpu_map__default_new(void)
return cpus; return cpus;
} }
static int cmp_int(const void *a, const void *b)
{
return *(const int *)a - *(const int*)b;
}
static struct perf_cpu_map *cpu_map__trim_new(int nr_cpus, int *tmp_cpus) static struct perf_cpu_map *cpu_map__trim_new(int nr_cpus, int *tmp_cpus)
{ {
size_t payload_size = nr_cpus * sizeof(int); size_t payload_size = nr_cpus * sizeof(int);
struct perf_cpu_map *cpus = malloc(sizeof(*cpus) + payload_size); struct perf_cpu_map *cpus = malloc(sizeof(*cpus) + payload_size);
int i, j;
if (cpus != NULL) { if (cpus != NULL) {
cpus->nr = nr_cpus;
memcpy(cpus->map, tmp_cpus, payload_size); memcpy(cpus->map, tmp_cpus, payload_size);
qsort(cpus->map, nr_cpus, sizeof(int), cmp_int);
/* Remove dups */
j = 0;
for (i = 0; i < nr_cpus; i++) {
if (i == 0 || cpus->map[i] != cpus->map[i - 1])
cpus->map[j++] = cpus->map[i];
}
cpus->nr = j;
assert(j <= nr_cpus);
refcount_set(&cpus->refcnt, 1); refcount_set(&cpus->refcnt, 1);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment