Skip to content

Commit

Permalink
Semaphores for ocaml probes (#60)
Browse files Browse the repository at this point in the history
* Separate semaphore for ocaml probes to correctly support probe_is_enabled

* Emit semaphore symbol as weak and hidden and without compilation unit in its name

* Update version of ocaml probe notes
  • Loading branch information
gretay-js authored and mshinwell committed Aug 6, 2021
1 parent dec98f0 commit ba43b59
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions backend/amd64/emit.mlp
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ let find_or_add_semaphore name =
match String.Map.find_opt name !probe_semaphores with
| Some label -> label
| None ->
let sym = Compilenv.make_symbol (Some ("semaphore_"^name)) in
let sym = "caml_probes_semaphore_"^name in
probe_semaphores := String.Map.add name sym !probe_semaphores;
sym

Expand Down Expand Up @@ -944,7 +944,11 @@ let emit_instr fallthrough i =
semaphores are of type unsigned short.
[1] https://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation
*)
I.mov (addressing (Ibased(semaphore_sym, 0)) WORD i 0) (res16 i 0);
(* OCaml has it's own semaphore, in addition to system tap,
to control ocaml probe handlers independently from stap probe handlers.
It is placed immediately after stap semaphore, and is the same
size - hence offset 2. *)
I.mov (addressing (Ibased(semaphore_sym, 2)) WORD i 0) (res16 i 0);
(* If the semaphore is 0, then the result is 0, otherwise 1. *)
I.cmp (int 0) (res16 i 0);
I.set (cond (Iunsigned Cne)) (res8 i 0);
Expand Down Expand Up @@ -1421,7 +1425,7 @@ let emit_probe_notes0 () =
D.qword (const 0)
end;
D.qword (ConstLabel semaphore_label);
D.bytes "ocaml\000";
D.bytes "ocaml.1\000";
D.bytes (probe_name ^ "\000");
D.bytes (args ^ "\000");
def_label d;
Expand All @@ -1448,9 +1452,11 @@ let emit_probe_notes0 () =
end;
D.align 2;
String.Map.iter (fun _ label ->
D.global label;
D.weak label;
D.hidden label;
_label label;
D.word (const 0);
D.word (const 0); (* for systemtap probes *)
D.word (const 0); (* for ocaml probes *)
add_def_symbol label)
!probe_semaphores

Expand Down

0 comments on commit ba43b59

Please sign in to comment.