Skip to content

Commit 8862cfc

Browse files
authored
CP-51209: hooks for bpftrace (#6179)
eBPF exitprobes do not work on OCaml functions that are tailcalls. Introduce some noop hooks that are forced to be non-tailcalls, by disabling inlining on them. This enables `bpftrace` to be able to hook these functions for debugging and performance measurement purposes, and otherwise have negligible runtime impact (just a function call and a return).
2 parents bae7526 + 886b852 commit 8862cfc

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

ocaml/database/db_cache_types.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,12 @@ module Database = struct
367367
let unregister_callback name x =
368368
{x with callbacks= List.filter (fun (x, _) -> x <> name) x.callbacks}
369369

370+
let[@inline never] [@specialize never] notify_begin () = ()
371+
372+
let[@inline never] [@specialize never] notify_end () = ()
373+
370374
let notify e db =
375+
notify_begin () ;
371376
List.iter
372377
(fun (name, f) ->
373378
try f e db
@@ -376,7 +381,8 @@ module Database = struct
376381
(Printexc.to_string e) name ;
377382
()
378383
)
379-
db.callbacks
384+
db.callbacks ;
385+
notify_end ()
380386

381387
let reindex x =
382388
let g = x.manifest.Manifest.generation_count in

ocaml/database/db_lock.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ module ReentrantLock : REENTRANT_LOCK = struct
7979

8080
let current_tid () = Thread.(self () |> id)
8181

82+
let[@inline never] [@specialize never] lock_acquired () = ()
83+
84+
let[@inline never] [@specialize never] lock_released () = ()
85+
8286
let lock l =
8387
let me = current_tid () in
8488
match Atomic.get l.holder with
@@ -91,6 +95,7 @@ module ReentrantLock : REENTRANT_LOCK = struct
9195
while not (Atomic.compare_and_set l.holder None intended) do
9296
Condition.wait l.condition l.lock
9397
done ;
98+
lock_acquired () ;
9499
let stats = l.statistics in
95100
let delta = Clock.Timer.span_to_s (Mtime_clock.count counter) in
96101
stats.total_time <- stats.total_time +. delta ;
@@ -109,7 +114,8 @@ module ReentrantLock : REENTRANT_LOCK = struct
109114
let () = Atomic.set l.holder None in
110115
Mutex.lock l.lock ;
111116
Condition.signal l.condition ;
112-
Mutex.unlock l.lock
117+
Mutex.unlock l.lock ;
118+
lock_released ()
113119
)
114120
| _ ->
115121
failwith

0 commit comments

Comments
 (0)