Commit aa11e55a authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo
Browse files

perf test: Use perf_cpu_map__for_each_cpu()



Clean up variable naming to make cpu and index clearer.

Signed-off-by: default avatarIan Rogers <irogers@google.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Vineet Singh <vineet.singh@intel.com>
Cc: coresight@lists.linaro.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: zhengjun.xing@intel.com
Link: https://lore.kernel.org/r/20220105061351.120843-41-irogers@google.com


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 6f844b1f
Loading
Loading
Loading
Loading
+14 −14
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@
static int test__openat_syscall_event_on_all_cpus(struct test_suite *test __maybe_unused,
						  int subtest __maybe_unused)
{
	int err = -1, fd, cpu;
	int err = -1, fd, idx, cpu;
	struct perf_cpu_map *cpus;
	struct evsel *evsel;
	unsigned int nr_openat_calls = 111, i;
@@ -58,23 +58,23 @@ static int test__openat_syscall_event_on_all_cpus(struct test_suite *test __mayb
		goto out_evsel_delete;
	}

	for (cpu = 0; cpu < cpus->nr; ++cpu) {
		unsigned int ncalls = nr_openat_calls + cpu;
	perf_cpu_map__for_each_cpu(cpu, idx, cpus) {
		unsigned int ncalls = nr_openat_calls + idx;
		/*
		 * XXX eventually lift this restriction in a way that
		 * keeps perf building on older glibc installations
		 * without CPU_ALLOC. 1024 cpus in 2010 still seems
		 * a reasonable upper limit tho :-)
		 */
		if (cpus->map[cpu] >= CPU_SETSIZE) {
			pr_debug("Ignoring CPU %d\n", cpus->map[cpu]);
		if (cpu >= CPU_SETSIZE) {
			pr_debug("Ignoring CPU %d\n", cpu);
			continue;
		}

		CPU_SET(cpus->map[cpu], &cpu_set);
		CPU_SET(cpu, &cpu_set);
		if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) {
			pr_debug("sched_setaffinity() failed on CPU %d: %s ",
				 cpus->map[cpu],
				 cpu,
				 str_error_r(errno, sbuf, sizeof(sbuf)));
			goto out_close_fd;
		}
@@ -82,29 +82,29 @@ static int test__openat_syscall_event_on_all_cpus(struct test_suite *test __mayb
			fd = openat(0, "/etc/passwd", O_RDONLY);
			close(fd);
		}
		CPU_CLR(cpus->map[cpu], &cpu_set);
		CPU_CLR(cpu, &cpu_set);
	}

	evsel->core.cpus = perf_cpu_map__get(cpus);

	err = 0;

	for (cpu = 0; cpu < cpus->nr; ++cpu) {
	perf_cpu_map__for_each_cpu(cpu, idx, cpus) {
		unsigned int expected;

		if (cpus->map[cpu] >= CPU_SETSIZE)
		if (cpu >= CPU_SETSIZE)
			continue;

		if (evsel__read_on_cpu(evsel, cpu, 0) < 0) {
		if (evsel__read_on_cpu(evsel, idx, 0) < 0) {
			pr_debug("evsel__read_on_cpu\n");
			err = -1;
			break;
		}

		expected = nr_openat_calls + cpu;
		if (perf_counts(evsel->counts, cpu, 0)->val != expected) {
		expected = nr_openat_calls + idx;
		if (perf_counts(evsel->counts, idx, 0)->val != expected) {
			pr_debug("evsel__read_on_cpu: expected to intercept %d calls on cpu %d, got %" PRIu64 "\n",
				 expected, cpus->map[cpu], perf_counts(evsel->counts, cpu, 0)->val);
				 expected, cpu, perf_counts(evsel->counts, idx, 0)->val);
			err = -1;
		}
	}