3
0
mirror of https://github.com/Qortal/Brooklyn.git synced 2025-01-31 07:12:18 +00:00
Brooklyn/tools/testing/selftests/bpf/progs/stacktrace_map_skip.c
crowetic a94b3d14aa Brooklyn+ (PLUS) changes
Changes included (and more):

1. Dynamic RAM merge

2. Real-time page scan and allocation

3. Cache compression

4. Real-time IRQ checks

5. Dynamic I/O allocation for Java heap

6. Java page migration

7. Contiguous memory allocation

8. Idle pages tracking

9. Per CPU RAM usage tracking

10. ARM NEON scalar multiplication library

11. NEON/ARMv8 crypto extensions

12. NEON SHA, Blake, RIPEMD crypto extensions

13. Parallel NEON crypto engine for multi-algo based CPU stress reduction
2022-05-12 10:47:00 -07:00

69 lines
1.6 KiB
C

// SPDX-License-Identifier: GPL-2.0
#include <vmlinux.h>
#include <bpf/bpf_helpers.h>
#define TEST_STACK_DEPTH 2
#define TEST_MAX_ENTRIES 16384
typedef __u64 stack_trace_t[TEST_STACK_DEPTH];
struct {
__uint(type, BPF_MAP_TYPE_STACK_TRACE);
__uint(max_entries, TEST_MAX_ENTRIES);
__type(key, __u32);
__type(value, stack_trace_t);
} stackmap SEC(".maps");
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__uint(max_entries, TEST_MAX_ENTRIES);
__type(key, __u32);
__type(value, __u32);
} stackid_hmap SEC(".maps");
struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, TEST_MAX_ENTRIES);
__type(key, __u32);
__type(value, stack_trace_t);
} stack_amap SEC(".maps");
int pid = 0;
int control = 0;
int failed = 0;
SEC("tracepoint/sched/sched_switch")
int oncpu(struct trace_event_raw_sched_switch *ctx)
{
__u32 max_len = TEST_STACK_DEPTH * sizeof(__u64);
__u32 key = 0, val = 0;
__u64 *stack_p;
if (pid != (bpf_get_current_pid_tgid() >> 32))
return 0;
if (control)
return 0;
/* it should allow skipping whole buffer size entries */
key = bpf_get_stackid(ctx, &stackmap, TEST_STACK_DEPTH);
if ((int)key >= 0) {
/* The size of stackmap and stack_amap should be the same */
bpf_map_update_elem(&stackid_hmap, &key, &val, 0);
stack_p = bpf_map_lookup_elem(&stack_amap, &key);
if (stack_p) {
bpf_get_stack(ctx, stack_p, max_len, TEST_STACK_DEPTH);
/* it wrongly skipped all the entries and filled zero */
if (stack_p[0] == 0)
failed = 1;
}
} else {
/* old kernel doesn't support skipping that many entries */
failed = 2;
}
return 0;
}
char _license[] SEC("license") = "GPL";