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

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

File Facts

System
Linux kernel
Corpus path
tools/perf/util/bpf_skel/kwork_top.bpf.c
Extension
.c
Size
6393 bytes
Lines
339
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 time_data {
	__u64 timestamp;
};

struct work_data {
	__u64 runtime;
};

struct task_data {
	__u32 tgid;
	__u32 is_kthread;
	char comm[MAX_COMMAND_LEN];
};

struct work_key {
	__u32 type;
	__u32 pid;
	__u64 task_p;
};

struct task_key {
	__u32 pid;
	__u32 cpu;
};

struct {
	__uint(type, BPF_MAP_TYPE_TASK_STORAGE);
	__uint(map_flags, BPF_F_NO_PREALLOC);
	__type(key, int);
	__type(value, struct time_data);
} kwork_top_task_time SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_PERCPU_HASH);
	__uint(key_size, sizeof(struct work_key));
	__uint(value_size, sizeof(struct time_data));
	__uint(max_entries, MAX_ENTRIES);
} kwork_top_irq_time SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_HASH);
	__uint(key_size, sizeof(struct task_key));
	__uint(value_size, sizeof(struct task_data));
	__uint(max_entries, MAX_ENTRIES);
} kwork_top_tasks SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_PERCPU_HASH);
	__uint(key_size, sizeof(struct work_key));
	__uint(value_size, sizeof(struct work_data));
	__uint(max_entries, MAX_ENTRIES);
} kwork_top_works SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_HASH);
	__uint(key_size, sizeof(u32));
	__uint(value_size, sizeof(u8));
	__uint(max_entries, MAX_NR_CPUS);
} kwork_top_cpu_filter SEC(".maps");

int enabled = 0;

const volatile int has_cpu_filter = 0;

__u64 from_timestamp = 0;
__u64 to_timestamp = 0;

static __always_inline int cpu_is_filtered(__u32 cpu)
{
	__u8 *cpu_val;

	if (has_cpu_filter) {
		cpu_val = bpf_map_lookup_elem(&kwork_top_cpu_filter, &cpu);
		if (!cpu_val)
			return 1;
	}

	return 0;
}

static __always_inline void update_task_info(struct task_struct *task, __u32 cpu)
{
	struct task_key key = {
		.pid = task->pid,
		.cpu = cpu,
	};

	if (!bpf_map_lookup_elem(&kwork_top_tasks, &key)) {
		struct task_data data = {
			.tgid = task->tgid,

Annotation

Implementation Notes