Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CP-49141: mark the DB lock as high priority #6180

Draft
wants to merge 3 commits into
base: feature/perf
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion ocaml/database/db_cache_types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 9 additions & 1 deletion ocaml/database/db_lock.ml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ module ReentrantLock : REENTRANT_LOCK = struct

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

let[@inline never] [@specialize never] lock_acquired () =
Xapi_timeslice.Timeslice.lock_acquired ()

let[@inline never] [@specialize never] lock_released () =
Xapi_timeslice.Timeslice.lock_released ()

let lock l =
let me = current_tid () in
match Atomic.get l.holder with
Expand All @@ -91,6 +97,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 ;
Expand All @@ -109,7 +116,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
Expand Down
1 change: 1 addition & 0 deletions ocaml/database/dune
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
xapi-stdext-std
xapi-stdext-threads
xapi-stdext-unix
xapi_timeslice
xml-light2
xmlm
)
Expand Down
Loading