Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #define _GNU_SOURCE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include <assert.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/perf_event.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <stdio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <stdlib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <sys/ioctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <sys/resource.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <sys/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <sys/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <sys/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <bpf/bpf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <bpf/libbpf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "perf-sys.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define SAMPLE_PERIOD  0x7fffffffffffffffULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) /* counters, values, values2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static int map_fd[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static void check_on_cpu(int cpu, struct perf_event_attr *attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	struct bpf_perf_event_value value2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	int pmu_fd, error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	cpu_set_t set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	__u64 value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	/* Move to target CPU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	CPU_ZERO(&set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	CPU_SET(cpu, &set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	assert(sched_setaffinity(0, sizeof(set), &set) == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	/* Open perf event and attach to the perf_event_array */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	pmu_fd = sys_perf_event_open(attr, -1/*pid*/, cpu/*cpu*/, -1/*group_fd*/, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	if (pmu_fd < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		fprintf(stderr, "sys_perf_event_open failed on CPU %d\n", cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		error = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		goto on_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	assert(bpf_map_update_elem(map_fd[0], &cpu, &pmu_fd, BPF_ANY) == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	assert(ioctl(pmu_fd, PERF_EVENT_IOC_ENABLE, 0) == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	/* Trigger the kprobe */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	bpf_map_get_next_key(map_fd[1], &cpu, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	/* Check the value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	if (bpf_map_lookup_elem(map_fd[1], &cpu, &value)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		fprintf(stderr, "Value missing for CPU %d\n", cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		error = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		goto on_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		fprintf(stderr, "CPU %d: %llu\n", cpu, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	/* The above bpf_map_lookup_elem should trigger the second kprobe */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	if (bpf_map_lookup_elem(map_fd[2], &cpu, &value2)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		fprintf(stderr, "Value2 missing for CPU %d\n", cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		error = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		goto on_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		fprintf(stderr, "CPU %d: counter: %llu, enabled: %llu, running: %llu\n", cpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 			value2.counter, value2.enabled, value2.running);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) on_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	assert(bpf_map_delete_elem(map_fd[0], &cpu) == 0 || error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	assert(ioctl(pmu_fd, PERF_EVENT_IOC_DISABLE, 0) == 0 || error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	assert(close(pmu_fd) == 0 || error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	assert(bpf_map_delete_elem(map_fd[1], &cpu) == 0 || error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	exit(error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) static void test_perf_event_array(struct perf_event_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 				  const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	int i, status, nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	pid_t pid[nr_cpus];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	printf("Test reading %s counters\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	for (i = 0; i < nr_cpus; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		pid[i] = fork();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		assert(pid[i] >= 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		if (pid[i] == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			check_on_cpu(i, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 			exit(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	for (i = 0; i < nr_cpus; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		assert(waitpid(pid[i], &status, 0) == pid[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		err |= status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		printf("Test: %s FAILED\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static void test_bpf_perf_event(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	struct perf_event_attr attr_cycles = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		.freq = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		.sample_period = SAMPLE_PERIOD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		.inherit = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		.type = PERF_TYPE_HARDWARE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		.read_format = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		.sample_type = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		.config = PERF_COUNT_HW_CPU_CYCLES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	struct perf_event_attr attr_clock = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		.freq = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		.sample_period = SAMPLE_PERIOD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		.inherit = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		.type = PERF_TYPE_SOFTWARE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		.read_format = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		.sample_type = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		.config = PERF_COUNT_SW_CPU_CLOCK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	struct perf_event_attr attr_raw = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		.freq = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		.sample_period = SAMPLE_PERIOD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		.inherit = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		.type = PERF_TYPE_RAW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		.read_format = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		.sample_type = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		/* Intel Instruction Retired */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		.config = 0xc0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	struct perf_event_attr attr_l1d_load = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		.freq = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		.sample_period = SAMPLE_PERIOD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		.inherit = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		.type = PERF_TYPE_HW_CACHE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		.read_format = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		.sample_type = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		.config =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 			PERF_COUNT_HW_CACHE_L1D |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			(PERF_COUNT_HW_CACHE_OP_READ << 8) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			(PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	struct perf_event_attr attr_llc_miss = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		.freq = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		.sample_period = SAMPLE_PERIOD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		.inherit = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		.type = PERF_TYPE_HW_CACHE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		.read_format = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		.sample_type = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		.config =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			PERF_COUNT_HW_CACHE_LL |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 			(PERF_COUNT_HW_CACHE_OP_READ << 8) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 			(PERF_COUNT_HW_CACHE_RESULT_MISS << 16),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	struct perf_event_attr attr_msr_tsc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		.freq = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		.sample_period = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		.inherit = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		/* From /sys/bus/event_source/devices/msr/ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		.type = 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		.read_format = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		.sample_type = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		.config = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	test_perf_event_array(&attr_cycles, "HARDWARE-cycles");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	test_perf_event_array(&attr_clock, "SOFTWARE-clock");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	test_perf_event_array(&attr_raw, "RAW-instruction-retired");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	test_perf_event_array(&attr_l1d_load, "HW_CACHE-L1D-load");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	/* below tests may fail in qemu */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	test_perf_event_array(&attr_llc_miss, "HW_CACHE-LLC-miss");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	test_perf_event_array(&attr_msr_tsc, "Dynamic-msr-tsc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) int main(int argc, char **argv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	struct bpf_link *links[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	struct bpf_program *prog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	struct bpf_object *obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	char filename[256];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	setrlimit(RLIMIT_MEMLOCK, &r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	obj = bpf_object__open_file(filename, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	if (libbpf_get_error(obj)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		fprintf(stderr, "ERROR: opening BPF object file failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	/* load BPF program */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	if (bpf_object__load(obj)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		fprintf(stderr, "ERROR: loading BPF object file failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	map_fd[0] = bpf_object__find_map_fd_by_name(obj, "counters");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	map_fd[1] = bpf_object__find_map_fd_by_name(obj, "values");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	map_fd[2] = bpf_object__find_map_fd_by_name(obj, "values2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if (map_fd[0] < 0 || map_fd[1] < 0 || map_fd[2] < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		fprintf(stderr, "ERROR: finding a map in obj file failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	bpf_object__for_each_program(prog, obj) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		links[i] = bpf_program__attach(prog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		if (libbpf_get_error(links[i])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			fprintf(stderr, "ERROR: bpf_program__attach failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			links[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 			goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	test_bpf_perf_event();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) cleanup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	for (i--; i >= 0; i--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		bpf_link__destroy(links[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	bpf_object__close(obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }