Unverified Commit 7310c21d authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!12003 perf cpumap: Wrapper for CPU map indices

parents dae62c1b 27e756c7
Loading
Loading
Loading
Loading
+14 −14
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ struct perf_cpu_map *perf_cpu_map__dummy_new(void)

	if (cpus != NULL) {
		cpus->nr = 1;
		cpus->map[0] = -1;
		cpus->map[0].cpu = -1;
		refcount_set(&cpus->refcnt, 1);
	}

@@ -59,7 +59,7 @@ static struct perf_cpu_map *cpu_map__default_new(void)
		int i;

		for (i = 0; i < nr_cpus; ++i)
			cpus->map[i] = i;
			cpus->map[i].cpu = i;

		cpus->nr = nr_cpus;
		refcount_set(&cpus->refcnt, 1);
@@ -85,7 +85,7 @@ static struct perf_cpu_map *cpu_map__trim_new(int nr_cpus, int *tmp_cpus)
		/* Remove dups */
		j = 0;
		for (i = 0; i < nr_cpus; i++) {
			if (i == 0 || cpus->map[i] != cpus->map[i - 1])
			if (i == 0 || cpus->map[i].cpu != cpus->map[i - 1].cpu)
				cpus->map[j++] = cpus->map[i];
		}
		cpus->nr = j;
@@ -248,7 +248,7 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list)
int perf_cpu_map__cpu(const struct perf_cpu_map *cpus, int idx)
{
	if (cpus && idx < cpus->nr)
		return cpus->map[idx];
		return cpus->map[idx].cpu;

	return -1;
}
@@ -260,7 +260,7 @@ int perf_cpu_map__nr(const struct perf_cpu_map *cpus)

bool perf_cpu_map__empty(const struct perf_cpu_map *map)
{
	return map ? map->map[0] == -1 : true;
	return map ? map->map[0].cpu == -1 : true;
}

int perf_cpu_map__idx(struct perf_cpu_map *cpus, int cpu)
@@ -268,7 +268,7 @@ int perf_cpu_map__idx(struct perf_cpu_map *cpus, int cpu)
	int i;

	for (i = 0; i < cpus->nr; ++i) {
		if (cpus->map[i] == cpu)
		if (cpus->map[i].cpu == cpu)
			return i;
	}

@@ -280,8 +280,8 @@ int perf_cpu_map__max(struct perf_cpu_map *map)
	int i, max = -1;

	for (i = 0; i < map->nr; i++) {
		if (map->map[i] > max)
			max = map->map[i];
		if (map->map[i].cpu > max)
			max = map->map[i].cpu;
	}

	return max;
@@ -323,19 +323,19 @@ struct perf_cpu_map *perf_cpu_map__merge(struct perf_cpu_map *orig,
	/* Standard merge algorithm from wikipedia */
	i = j = k = 0;
	while (i < orig->nr && j < other->nr) {
		if (orig->map[i] <= other->map[j]) {
			if (orig->map[i] == other->map[j])
		if (orig->map[i].cpu <= other->map[j].cpu) {
			if (orig->map[i].cpu == other->map[j].cpu)
				j++;
			tmp_cpus[k++] = orig->map[i++];
			tmp_cpus[k++] = orig->map[i++].cpu;
		} else
			tmp_cpus[k++] = other->map[j++];
			tmp_cpus[k++] = other->map[j++].cpu;
	}

	while (i < orig->nr)
		tmp_cpus[k++] = orig->map[i++];
		tmp_cpus[k++] = orig->map[i++].cpu;

	while (j < other->nr)
		tmp_cpus[k++] = other->map[j++];
		tmp_cpus[k++] = other->map[j++].cpu;
	assert(k <= tmp_len);

	merged = cpu_map__trim_new(k, tmp_cpus);
+1 −1
Original line number Diff line number Diff line
@@ -102,7 +102,7 @@ int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus,

			fd = sys_perf_event_open(&evsel->attr,
						 threads->map[thread].pid,
						 cpus->map[cpu], -1, 0);
						 cpus->map[cpu].cpu, -1, 0);

			if (fd < 0)
				return -errno;
+2 −1
Original line number Diff line number Diff line
@@ -3,11 +3,12 @@
#define __LIBPERF_INTERNAL_CPUMAP_H

#include <linux/refcount.h>
#include <perf/cpumap.h>

struct perf_cpu_map {
	refcount_t	refcnt;
	int		nr;
	int		map[];
	struct perf_cpu	map[];
};

#ifndef MAX_NR_CPUS
+5 −0
Original line number Diff line number Diff line
@@ -6,6 +6,11 @@
#include <stdio.h>
#include <stdbool.h>

/** A wrapper around a CPU to avoid confusion with the perf_cpu_map's map's indices. */
struct perf_cpu {
	int cpu;
};

struct perf_cpu_map;

LIBPERF_API struct perf_cpu_map *perf_cpu_map__dummy_new(void);
+1 −1
Original line number Diff line number Diff line
@@ -254,7 +254,7 @@ static int do_threads(struct worker *worker, struct perf_cpu_map *cpu)

		if (!noaffinity) {
			CPU_ZERO(&cpuset);
			CPU_SET(cpu->map[i % cpu->nr], &cpuset);
			CPU_SET(cpu->map[i % cpu->nr].cpu, &cpuset);

			ret = pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpuset);
			if (ret)
Loading