tools/perf/util/bpf_skel/kwork_trace.bpf.c

Source file repositories/reference/linux-study-clean/tools/perf/util/bpf_skel/kwork_trace.bpf.c

File Facts

System
Linux kernel
Corpus path
tools/perf/util/bpf_skel/kwork_trace.bpf.c
Extension
.c
Size
9038 bytes
Lines
385
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source 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

struct work_key {
	__u32 type;
	__u32 cpu;
	__u64 id;
};

struct report_data {
	__u64 nr;
	__u64 total_time;
	__u64 max_time;
	__u64 max_time_start;
	__u64 max_time_end;
};

struct {
	__uint(type, BPF_MAP_TYPE_HASH);
	__uint(key_size, sizeof(struct work_key));
	__uint(value_size, MAX_KWORKNAME);
	__uint(max_entries, KWORK_COUNT);
} perf_kwork_names SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_HASH);
	__uint(key_size, sizeof(struct work_key));
	__uint(value_size, sizeof(__u64));
	__uint(max_entries, KWORK_COUNT);
} perf_kwork_time SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_HASH);
	__uint(key_size, sizeof(struct work_key));
	__uint(value_size, sizeof(struct report_data));
	__uint(max_entries, KWORK_COUNT);
} perf_kwork_report SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_HASH);
	__uint(key_size, sizeof(__u32));
	__uint(value_size, sizeof(__u8));
	__uint(max_entries, 1);
} perf_kwork_cpu_filter SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_ARRAY);
	__uint(key_size, sizeof(__u32));
	__uint(value_size, MAX_KWORKNAME);
	__uint(max_entries, 1);
} perf_kwork_name_filter SEC(".maps");

int enabled = 0;

const volatile int has_cpu_filter = 0;
const volatile int has_name_filter = 0;

static __always_inline int local_strncmp(const char *s1,
					 unsigned int sz, const char *s2)
{
	int ret = 0;
	unsigned int i;

	for (i = 0; i < sz; i++) {
		ret = (unsigned char)s1[i] - (unsigned char)s2[i];
		if (ret || !s1[i])
			break;
	}

	return ret;
}

static __always_inline int trace_event_match(struct work_key *key, char *name)
{
	__u8 *cpu_val;
	char *name_val;
	__u32 zero = 0;
	__u32 cpu = bpf_get_smp_processor_id();

	if (!enabled)
		return 0;

	if (has_cpu_filter) {
		cpu_val = bpf_map_lookup_elem(&perf_kwork_cpu_filter, &cpu);
		if (!cpu_val)
			return 0;
	}

	if (has_name_filter && (name != NULL)) {
		name_val = bpf_map_lookup_elem(&perf_kwork_name_filter, &zero);
		if (name_val &&
		    (local_strncmp(name_val, MAX_KWORKNAME, name) != 0)) {
			return 0;

Annotation

Implementation Notes