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-48195: Instrument client side of forkexecd #5583

Conversation

GabrielBuica
Copy link
Contributor

Instrument:

  • forkhelpers.ml,
  • fecomms.ml

to create spans around functions when a parent span is supplied as tracing.

As follow-up to #5551

ocaml/libs/tracing/tracing.ml Outdated Show resolved Hide resolved
@GabrielBuica GabrielBuica force-pushed the private/dbuica/CP-48195-instrument-forkexecd-client branch from 45eeca7 to 0f771ab Compare April 23, 2024 10:07
Copy link
Contributor

@Vincent-lau Vincent-lau left a comment

Choose a reason for hiding this comment

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

This PR would allow us to trace all programs spawned by forkexecd, and we can gradually implement support in the child proc to support tracing

ocaml/forkexecd/lib/fecomms.ml Outdated Show resolved Hide resolved
ocaml/forkexecd/lib/fecomms.ml Show resolved Hide resolved
ocaml/libs/tracing/tracing.ml Show resolved Hide resolved
ocaml/libs/tracing/tracing.ml Show resolved Hide resolved
ocaml/xapi/sm_exec.ml Show resolved Hide resolved
ocaml/forkexecd/lib/forkhelpers.ml Outdated Show resolved Hide resolved
@GabrielBuica
Copy link
Contributor Author

GabrielBuica commented Apr 23, 2024

Needs work... It currently spams the logs with no tracing provider found...

ocaml/libs/tracing/tracing.ml Outdated Show resolved Hide resolved
ocaml/libs/tracing/tracing.ml Outdated Show resolved Hide resolved
@GabrielBuica
Copy link
Contributor Author

Passed BVT+BST 197518.

@GabrielBuica GabrielBuica force-pushed the private/dbuica/CP-48195-instrument-forkexecd-client branch from b9defa1 to e800417 Compare April 29, 2024 08:53
@@ -573,7 +575,7 @@ let set ?enabled ?attributes ?endpoints ~uuid () =
Hashtbl.clear Spans.spans ;
Hashtbl.clear Spans.finished_spans
)
) else
) else if not (get_observe ()) then
Copy link
Contributor

Choose a reason for hiding this comment

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

It is fine to always call set_observe here. get + set is not atomic as a whole anyway (if you want it to be atomic, then there is compare_and_set).
But this flag is only written from one location and read from multiple locations, and it is not a computation that can race between different threads, so always calling set is probably better.

@@ -309,6 +309,7 @@ module Dom0ObserverConfig (ObserverComponent : OBSERVER_COMPONENT) :

let update_config ~__context ~observer ~uuid =
if Db.Observer.get_enabled ~__context ~self:observer then (
if not (Tracing.get_observe ()) then Tracing.set_observe true ;
Copy link
Contributor

@edwintorok edwintorok Apr 29, 2024

Choose a reason for hiding this comment

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

get + set is not atomic, it is better to just call set directly, so you know what the end result is.
This isn't performance critical code in a tight loop where optimizing that would make a difference (even there it is questionable whether it would)

Copy link
Member

Choose a reason for hiding this comment

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

The equivalent atomic operation in this case would be let _ = Atomic_compare_and_set observe false true in

@@ -573,7 +575,7 @@ let set ?enabled ?attributes ?endpoints ~uuid () =
Hashtbl.clear Spans.spans ;
Hashtbl.clear Spans.finished_spans
)
) else
) else if not (get_observe ()) then
set_observe true
Copy link
Contributor

@edwintorok edwintorok Apr 29, 2024

Choose a reason for hiding this comment

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

The set call here can race with another set call from the API. It is better to do the (atomic) set operation while you are holding the lock. Otherwise if one operation would enable things and the other would disable you'd still have a race.
The atomic only protects the global value itself, not the way it was computed, adding atomic doesn't make the operation itself atomic (that is the responsibility of the code).

Copy link
Contributor

Choose a reason for hiding this comment

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

In fact 'get_tracer_providers' above is not thread-safe: it uses a hashtable, and iterates on it without holding any locks.

@GabrielBuica GabrielBuica force-pushed the private/dbuica/CP-48195-instrument-forkexecd-client branch 2 times, most recently from 1c14e7c to aa22166 Compare April 29, 2024 13:28
@edwintorok
Copy link
Contributor

edwintorok commented Apr 29, 2024

This PR could be rebased on top of this one that first fixes the locking bugs in tracing.ml, so then the changes in this PR have a better starting point: #5601

@GabrielBuica GabrielBuica force-pushed the private/dbuica/CP-48195-instrument-forkexecd-client branch from aa22166 to 4a6c898 Compare April 29, 2024 14:40
@GabrielBuica
Copy link
Contributor Author

This PR could be rebased on top of this one that first fixes the locking bugs in tracing.ml, so then the changes in this PR have a better starting point: #5601

Since the number of changings to tracing.ml's observe_mode are increasing, I am commenting the line that causes the log spam for this PR. I'll make a separate PR for fixing the tracing.ml's observe_mode and reenable the warning.

Instrument:

- `forkhelpers.ml`,
- `fecomms.ml`

to create spans around functions when a parent span is supplied as
`tracing`.

Signed-off-by: Gabriel Buica <danutgabriel.buica@cloud.com>
@GabrielBuica GabrielBuica force-pushed the private/dbuica/CP-48195-instrument-forkexecd-client branch from 4a6c898 to 9ac7c64 Compare April 30, 2024 12:56
Currently the `observe` mode of the `tracing` library do not work
corrently resulting in the logs being spammed by this warning.

Comment it out so that the logs do not become too big (for the time
being).

Signed-off-by: Gabriel Buica <danutgabriel.buica@cloud.com>
@GabrielBuica GabrielBuica force-pushed the private/dbuica/CP-48195-instrument-forkexecd-client branch from 9ac7c64 to 70f8149 Compare April 30, 2024 13:33
Copy link
Member

@mg12 mg12 left a comment

Choose a reason for hiding this comment

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

LGTM: passed bvt, bst, and further changes in tracing.ml in a follow-up PR.

@lindig lindig added the reviewed label May 1, 2024
@mg12 mg12 merged commit 8de2308 into xapi-project:master May 2, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants