Skip to content

Semaphores for ocaml probes #60

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

Merged
merged 3 commits into from
Aug 5, 2021
Merged
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
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. *)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why this is offset 2 not 1. Is this value not in units of 8-byte words?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The units are bytes, and the size of the new semaphore is set to be the same as the size of stap semaphores, so the code for reading them remains unchanged.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, and the semaphores are 16-bit quantities. ok.

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";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name is a bit mysterious

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, suggestions for a better name are most welcome!
The prefix ".1" is the version number for ocaml probe notes. There is already a proposal for "ocaml.2" in PR #142.
The suffix "ocaml" is useful for distinguishing probes emitted by OCaml compiler from other stap "providers" of probes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Users will see these strings if they inspect probe notes using "readelf -n" or gdb's "info probes".

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems ok for now.

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