Skip to content

Draft: allow using an external symbol as a semaphore#26

Draft
bonzini wants to merge 6 commits intocuviper:masterfrom
bonzini:extern-semaphore
Draft

Draft: allow using an external symbol as a semaphore#26
bonzini wants to merge 6 commits intocuviper:masterfrom
bonzini:extern-semaphore

Conversation

@bonzini
Copy link

@bonzini bonzini commented Sep 25, 2025

In QEMU, each probe point has the address of its semaphore stored in a table, so that it's possible to observe which semaphores are enabled and which are not.

While in principle it is possible for a single (provider, name) pair to be associated to multiple semaphores, support for this is sometimes buggy so it's preferable to have a single semaphore shared between C code (which is where the table lies) and Rust invocations of probe_lazy!.

This series modifies probe_lazy! so that:

  • the conditional around lazy argument evaluation is placed in common code, wrapped in a platform-specific instance of Semaphore
  • optionally, the semaphore can be declared outside of probe_lazy!, as long as it has static lifetime.

Semaphore replaces the static mut semaphore with an UnsafeCell wrapper that only allows reading. Alternatively, it could also use an AtomicU16, and the volatile read would be replaced with a relaxed load.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
As a step towards allowing user-provided semaphores, move from
"static mut" to properly annotated interior mutability.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
In preparation for allowing semaphores declared outside the probe_lazy
macro, split platform_probe_lazy in two: one macro to place the
semaphore in the .probes section, one to create the tracepoint.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Change the macro argument from ident to path.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
For now, this is kept internal and not documented.  However, it will be
used by QEMU to let C code declare the semaphores.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Ensure that Semaphore is documented properly.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
// put it in the stapsdt note. The program cannot really do
// anything with it---the only available method is enabled(); therefore,
// even though not placing it in the .probes section could upset the tracing
// tool, it cannot be used to trigger undefined behavior.
Copy link
Author

Choose a reason for hiding this comment

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

This is worth pointing out—here I assume that the tools are robust enough and will either complain or ignore the probe, but not mess themselves up.

@bonzini
Copy link
Author

bonzini commented Sep 25, 2025

CI run at bonzini#3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant