Commit ad0e8836 authored by Brenden Blanco's avatar Brenden Blanco

Rename stack lookup() to get_stackid

Signed-off-by: default avatarBrenden Blanco <bblanco@plumgrid.com>
parent 9cafce2a
...@@ -48,6 +48,7 @@ struct _name##_table_t { \ ...@@ -48,6 +48,7 @@ struct _name##_table_t { \
int (*delete) (_key_type *); \ int (*delete) (_key_type *); \
void (*call) (void *, int index); \ void (*call) (void *, int index); \
void (*increment) (_key_type); \ void (*increment) (_key_type); \
int (*get_stackid) (void *, u64); \
_leaf_type data[_max_entries]; \ _leaf_type data[_max_entries]; \
}; \ }; \
__attribute__((section("maps/" _table_type))) \ __attribute__((section("maps/" _table_type))) \
...@@ -110,15 +111,12 @@ struct _name##_table_t _name ...@@ -110,15 +111,12 @@ struct _name##_table_t _name
#define BPF_HISTOGRAM(...) \ #define BPF_HISTOGRAM(...) \
BPF_HISTX(__VA_ARGS__, BPF_HIST3, BPF_HIST2, BPF_HIST1)(__VA_ARGS__) BPF_HISTX(__VA_ARGS__, BPF_HIST3, BPF_HIST2, BPF_HIST1)(__VA_ARGS__)
struct bpf_stacktrace {
u64 ip[BPF_MAX_STACK_DEPTH];
};
#define BPF_STACK_TRACE(_name, _max_entries) \ #define BPF_STACK_TRACE(_name, _max_entries) \
struct _name##_table_t { \ BPF_TABLE("stacktrace", int, struct bpf_stacktrace, _name, _max_entries);
int key; \
struct { u64 data[BPF_MAX_STACK_DEPTH]; } leaf; \
int (*lookup) (void *); \
struct { u64 data[BPF_MAX_STACK_DEPTH]; } data[_max_entries]; \
}; \
__attribute__((section("maps/stacktrace"))) \
struct _name##_table_t _name
// packet parsing state machine helpers // packet parsing state machine helpers
#define cursor_advance(_cursor, _len) \ #define cursor_advance(_cursor, _len) \
......
...@@ -352,16 +352,20 @@ bool BTypeVisitor::VisitCallExpr(CallExpr *Call) { ...@@ -352,16 +352,20 @@ bool BTypeVisitor::VisitCallExpr(CallExpr *Call) {
Call->getArg(2)->getLocEnd())); Call->getArg(2)->getLocEnd()));
txt = "bpf_perf_event_output(" + arg0 + ", bpf_pseudo_fd(1, " + fd + ")"; txt = "bpf_perf_event_output(" + arg0 + ", bpf_pseudo_fd(1, " + fd + ")";
txt += ", bpf_get_smp_processor_id(), " + args_other + ")"; txt += ", bpf_get_smp_processor_id(), " + args_other + ")";
} else { } else if (memb_name == "get_stackid") {
if (memb_name == "lookup") {
if (table_it->type == BPF_MAP_TYPE_STACK_TRACE) { if (table_it->type == BPF_MAP_TYPE_STACK_TRACE) {
prefix = "bpf_get_stackid"; txt = "bpf_get_stackid(";
// TODO: expose the different flags, how? txt += "bpf_pseudo_fd(1, " + fd + "), " + args + ")";
suffix = ", 0)";
} else { } else {
prefix = "bpf_map_lookup_elem"; unsigned diag_id = C.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error,
suffix = ")"; "get_stackid only available on stacktrace maps");
C.getDiagnostics().Report(Call->getLocStart(), diag_id);
return false;
} }
} else {
if (memb_name == "lookup") {
prefix = "bpf_map_lookup_elem";
suffix = ")";
} else if (memb_name == "update") { } else if (memb_name == "update") {
prefix = "bpf_map_update_elem"; prefix = "bpf_map_update_elem";
suffix = ", " + map_update_policy + ")"; suffix = ", " + map_update_policy + ")";
......
...@@ -14,7 +14,9 @@ BPF_STACK_TRACE(stack_traces, 10240); ...@@ -14,7 +14,9 @@ BPF_STACK_TRACE(stack_traces, 10240);
BPF_HASH(stack_entries, int, int); BPF_HASH(stack_entries, int, int);
BPF_HASH(stub); BPF_HASH(stub);
int kprobe__htab_map_delete_elem(struct pt_regs *ctx, struct bpf_map *map, u64 *k) { int kprobe__htab_map_delete_elem(struct pt_regs *ctx, struct bpf_map *map, u64 *k) {
int id = stack_traces.lookup(ctx); int id = stack_traces.get_stackid(ctx, (BPF_F_REUSE_STACKID));
if (id < 0)
return 0;
int key = 1; int key = 1;
stack_entries.update(&key, &id); stack_entries.update(&key, &id);
return 0; return 0;
...@@ -29,7 +31,7 @@ int kprobe__htab_map_delete_elem(struct pt_regs *ctx, struct bpf_map *map, u64 * ...@@ -29,7 +31,7 @@ int kprobe__htab_map_delete_elem(struct pt_regs *ctx, struct bpf_map *map, u64 *
self.assertIn(k, stack_entries) self.assertIn(k, stack_entries)
stackid = stack_entries[k] stackid = stack_entries[k]
self.assertIsNotNone(stackid) self.assertIsNotNone(stackid)
stack = stack_traces[stackid].data stack = stack_traces[stackid].ip
self.assertEqual(b.ksym(stack[0]), "htab_map_delete_elem") self.assertEqual(b.ksym(stack[0]), "htab_map_delete_elem")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment