From: Brenden Blanco Date: Fri, 4 Mar 2016 21:58:44 +0000 (-0800) Subject: Rename stack lookup() to get_stackid X-Git-Tag: v0.2.0~147^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ad0e8836cabd58133c24a48d79165c015d1d4319;p=platform%2Fupstream%2Fbcc.git Rename stack lookup() to get_stackid Signed-off-by: Brenden Blanco --- diff --git a/src/cc/export/helpers.h b/src/cc/export/helpers.h index c359c3e..c997e94 100644 --- a/src/cc/export/helpers.h +++ b/src/cc/export/helpers.h @@ -48,6 +48,7 @@ struct _name##_table_t { \ int (*delete) (_key_type *); \ void (*call) (void *, int index); \ void (*increment) (_key_type); \ + int (*get_stackid) (void *, u64); \ _leaf_type data[_max_entries]; \ }; \ __attribute__((section("maps/" _table_type))) \ @@ -110,15 +111,12 @@ struct _name##_table_t _name #define BPF_HISTOGRAM(...) \ 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) \ -struct _name##_table_t { \ - 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 + BPF_TABLE("stacktrace", int, struct bpf_stacktrace, _name, _max_entries); // packet parsing state machine helpers #define cursor_advance(_cursor, _len) \ diff --git a/src/cc/frontends/clang/b_frontend_action.cc b/src/cc/frontends/clang/b_frontend_action.cc index f7a2500..a97c654 100644 --- a/src/cc/frontends/clang/b_frontend_action.cc +++ b/src/cc/frontends/clang/b_frontend_action.cc @@ -352,16 +352,20 @@ bool BTypeVisitor::VisitCallExpr(CallExpr *Call) { Call->getArg(2)->getLocEnd())); txt = "bpf_perf_event_output(" + arg0 + ", bpf_pseudo_fd(1, " + fd + ")"; txt += ", bpf_get_smp_processor_id(), " + args_other + ")"; - } else { - if (memb_name == "lookup") { + } else if (memb_name == "get_stackid") { if (table_it->type == BPF_MAP_TYPE_STACK_TRACE) { - prefix = "bpf_get_stackid"; - // TODO: expose the different flags, how? - suffix = ", 0)"; + txt = "bpf_get_stackid("; + txt += "bpf_pseudo_fd(1, " + fd + "), " + args + ")"; } else { - prefix = "bpf_map_lookup_elem"; - suffix = ")"; + unsigned diag_id = C.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, + "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") { prefix = "bpf_map_update_elem"; suffix = ", " + map_update_policy + ")"; diff --git a/tests/python/test_stackid.py b/tests/python/test_stackid.py index 5cafea5..402d031 100755 --- a/tests/python/test_stackid.py +++ b/tests/python/test_stackid.py @@ -14,7 +14,9 @@ BPF_STACK_TRACE(stack_traces, 10240); BPF_HASH(stack_entries, int, int); BPF_HASH(stub); 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; stack_entries.update(&key, &id); return 0; @@ -29,7 +31,7 @@ int kprobe__htab_map_delete_elem(struct pt_regs *ctx, struct bpf_map *map, u64 * self.assertIn(k, stack_entries) stackid = stack_entries[k] self.assertIsNotNone(stackid) - stack = stack_traces[stackid].data + stack = stack_traces[stackid].ip self.assertEqual(b.ksym(stack[0]), "htab_map_delete_elem")