Rename stack lookup() to get_stackid
authorBrenden Blanco <bblanco@plumgrid.com>
Fri, 4 Mar 2016 21:58:44 +0000 (13:58 -0800)
committerBrenden Blanco <bblanco@plumgrid.com>
Fri, 4 Mar 2016 21:58:44 +0000 (13:58 -0800)
Signed-off-by: Brenden Blanco <bblanco@plumgrid.com>
src/cc/export/helpers.h
src/cc/frontends/clang/b_frontend_action.cc
tests/python/test_stackid.py

index c359c3e..c997e94 100644 (file)
@@ -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) \
index f7a2500..a97c654 100644 (file)
@@ -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 + ")";
index 5cafea5..402d031 100755 (executable)
@@ -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")