tools/perf/tests/openat-syscall-all-cpus.c

Source file repositories/reference/linux-study-clean/tools/perf/tests/openat-syscall-all-cpus.c

File Facts

System
Linux kernel
Corpus path
tools/perf/tests/openat-syscall-all-cpus.c
Extension
.c
Size
3550 bytes
Lines
140
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: syscall or user/kernel boundary
Status
core implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

if (cpu.cpu >= CPU_SETSIZE) {
			pr_debug("Ignoring CPU %d\n", cpu.cpu);
			continue;
		}

		CPU_SET(cpu.cpu, &cpu_set);
		if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) {
			pr_debug("sched_setaffinity() failed on CPU %d: %s ",
				 cpu.cpu,
				 str_error_r(errno, sbuf, sizeof(sbuf)));
			goto out_close_fd;
		}
		for (i = 0; i < ncalls; ++i) {
			fd = openat(0, "/etc/passwd", O_RDONLY);
			close(fd);
		}
		CPU_CLR(cpu.cpu, &cpu_set);
	}

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

	err = TEST_OK;

	perf_cpu_map__for_each_cpu(cpu, idx, cpus) {
		unsigned int expected;

		if (cpu.cpu >= CPU_SETSIZE)
			continue;

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

		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, cpu.cpu, perf_counts(evsel->counts, idx, 0)->val);
			err = TEST_FAIL;
		}
	}

	evsel__free_counts(evsel);
out_close_fd:
	perf_evsel__close_fd(&evsel->core);
out_evsel_delete:
	evsel__delete(evsel);
out_cpu_map_delete:
	perf_cpu_map__put(cpus);
out_thread_map_delete:
	perf_thread_map__put(threads);
	return err;
}


static struct test_case tests__openat_syscall_event_on_all_cpus[] = {
	TEST_CASE_REASON("Detect openat syscall event on all cpus",
			 openat_syscall_event_on_all_cpus,
			 "permissions"),
	{	.name = NULL, }
};

struct test_suite suite__openat_syscall_event_on_all_cpus = {
	.desc = "Detect openat syscall event on all cpus",
	.test_cases = tests__openat_syscall_event_on_all_cpus,
};

Annotation

Implementation Notes