COOLBPF eBPF API

Functions

static inline int fast_log2(long value)
static inline int fast_log10(long v)
static inline void add_hist(struct bpf_map_def *maps, int k, int v)
static inline void hist2_push(struct bpf_map_def *maps, long v)
static inline void hist10_push(struct bpf_map_def *maps, long v)
char _license [] SEC ("license")

Defines

MAX_STACK_DEPTH 20
ns() bpf_ktime_get_ns()

bpf helper function: get timestamp

pid() (bpf_get_current_pid_tgid() >> 32)

bpf helper function: get pid

tid() ((u32)bpf_get_current_pid_tgid())

bpf helper function: get tid

comm(c) bpf_get_current_comm(c, sizeof(c))

bpf helper function: get comm of current

cpu() bpf_get_smp_processor_id()

bpf helper function: get cpu number

BPF_MAP(_name, _type, _key_type, _value_type, _max_entries)

struct                                                          \

{                                                               \

__uint(type, _type);                                        \

__uint(max_entries, _max_entries);                          \

__type(key, _key_type);                                     \

__type(value, _value_type);                                 \

} _name SEC(".maps");


BPF_HASH(_name, _key_type, _value_type, _max_entries) BPF_MAP(_name, BPF_MAP_TYPE_HASH, _key_type, _value_type, _max_entries)

One line of code to create BPF_MAP_TYPE_HASH.

BPF_LRU_HASH(_name, _key_type, _value_type, _max_entries) BPF_MAP(_name, BPF_MAP_TYPE_LRU_HASH, _key_type, _value_type, _max_entries)

One line of code to create BPF_MAP_TYPE_LRU_HASH.

BPF_ARRAY(_name, _value_type, _max_entries) BPF_MAP(_name, BPF_MAP_TYPE_ARRAY, u32, _value_type, _max_entries)

One line of code to create BPF_MAP_TYPE_ARRAY.

BPF_PERCPU_ARRAY(_name, _value_type, _max_entries) BPF_MAP(_name, BPF_MAP_TYPE_PERCPU_ARRAY, u32, _value_type, _max_entries)

One line of code to create BPF_MAP_TYPE_PERCPU_ARRAY.

BPF_PROG_ARRAY(_name, _max_entries) BPF_MAP(_name, BPF_MAP_TYPE_PROG_ARRAY, u32, u32, _max_entries)
BPF_PERF_OUTPUT(_name, _max_entries) BPF_MAP(_name, BPF_MAP_TYPE_PERF_EVENT_ARRAY, int, __u32, _max_entries)

One line of code to create BPF_MAP_TYPE_PERF_EVENT_ARRAY.

BPF_STACK_TRACE(_name, _max_entries) BPF_MAP(_name, BPF_MAP_TYPE_STACK_TRACE, u32, stack_trace_t, _max_entries)
NUM_E16 10000000000000000ULL
NUM_E8 100000000ULL
NUM_E4 10000ULL
NUM_E2 100ULL
NUM_E1 10ULL
incr_hist(maps, k) add_hist(maps, k, 1)