From 0b7202dc69584b8ac8ed33a56222e7ad6de26f56 Mon Sep 17 00:00:00 2001 From: Marcus Granado Date: Fri, 18 Oct 2024 17:10:36 +0000 Subject: [PATCH 1/2] CP-51209: add hooks lock_acquired/released for bpftrace Signed-off-by: Marcus Granado --- ocaml/database/db_lock.ml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ocaml/database/db_lock.ml b/ocaml/database/db_lock.ml index 3b752dd5f39..4de02abfa02 100644 --- a/ocaml/database/db_lock.ml +++ b/ocaml/database/db_lock.ml @@ -79,6 +79,10 @@ module ReentrantLock : REENTRANT_LOCK = struct let current_tid () = Thread.(self () |> id) + let[@inline never] [@specialize never] lock_acquired () = () + + let[@inline never] [@specialize never] lock_released () = () + let lock l = let me = current_tid () in match Atomic.get l.holder with @@ -91,6 +95,7 @@ module ReentrantLock : REENTRANT_LOCK = struct while not (Atomic.compare_and_set l.holder None intended) do Condition.wait l.condition l.lock done ; + lock_acquired () ; let stats = l.statistics in let delta = Clock.Timer.span_to_s (Mtime_clock.count counter) in stats.total_time <- stats.total_time +. delta ; @@ -109,7 +114,8 @@ module ReentrantLock : REENTRANT_LOCK = struct let () = Atomic.set l.holder None in Mutex.lock l.lock ; Condition.signal l.condition ; - Mutex.unlock l.lock + Mutex.unlock l.lock ; + lock_released () ) | _ -> failwith From 886b85279056240589fdd32ff8ca0d4017a54146 Mon Sep 17 00:00:00 2001 From: Marcus Granado Date: Tue, 12 Nov 2024 13:34:37 +0000 Subject: [PATCH 2/2] CP-51209: db_notification: enable/disable and begin/end hooks for bpftrace Signed-off-by: Marcus Granado --- ocaml/database/db_cache_types.ml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ocaml/database/db_cache_types.ml b/ocaml/database/db_cache_types.ml index d081dbd674c..be73b91958f 100644 --- a/ocaml/database/db_cache_types.ml +++ b/ocaml/database/db_cache_types.ml @@ -367,7 +367,12 @@ module Database = struct let unregister_callback name x = {x with callbacks= List.filter (fun (x, _) -> x <> name) x.callbacks} + let[@inline never] [@specialize never] notify_begin () = () + + let[@inline never] [@specialize never] notify_end () = () + let notify e db = + notify_begin () ; List.iter (fun (name, f) -> try f e db @@ -376,7 +381,8 @@ module Database = struct (Printexc.to_string e) name ; () ) - db.callbacks + db.callbacks ; + notify_end () let reindex x = let g = x.manifest.Manifest.generation_count in