Skip to content

Commit

Permalink
PoC for SystemTap semaphores - using asm_sym
Browse files Browse the repository at this point in the history
  • Loading branch information
nbaksalyar committed Apr 27, 2022
1 parent 8520232 commit 5fb1ec0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
19 changes: 12 additions & 7 deletions examples/loop.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#![feature(asm_sym)]

use probe::probe;

fn main() {
probe!(foo, begin);
let mut total = 0;
for i in 0..100 {
total += i;
probe!(foo, loop, i, total);
let mut iter = 0;
loop {
iter += 1;
probe!(foo, iter, {
std::thread::sleep(std::time::Duration::from_secs(1));
iter
});
}
assert_eq!(total, 4950);
probe!(foo, end);
}

// bcc/tools/trace.py -p $(pidof loop) 'u::foo:iter "iter = %d", arg1'
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
//! ```

#![no_std]
#![feature(asm_sym)]

mod platform;

Expand Down
14 changes: 8 additions & 6 deletions src/platform/systemtap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ macro_rules! sdt_asm(
#[macro_export]
macro_rules! _sdt_asm(
($size:literal, options ($($opt:ident),*), $provider:ident, $name:ident, $($argstr:literal, $arg:expr,)*) => (
::core::arch::asm!(concat!(r#"
static SEMAPHORE: u16 = 0;
if ::core::ptr::read_volatile(&SEMAPHORE) == 1 {
::core::arch::asm!(concat!(r#"
990: nop
.pushsection .note.stapsdt,"?","note"
.balign 4
Expand All @@ -110,7 +112,7 @@ macro_rules! _sdt_asm(
992: .balign 4
993: ."#, $size, r#"byte 990b
."#, $size, r#"byte _.stapsdt.base
."#, $size, r#"byte 0 // FIXME set semaphore address
."#, $size, r#"byte {}
.asciz ""#, stringify!($provider), r#""
.asciz ""#, stringify!($name), r#""
.asciz ""#, $($argstr,)* r#""
Expand All @@ -123,10 +125,10 @@ macro_rules! _sdt_asm(
_.stapsdt.base: .space 1
.size _.stapsdt.base, 1
.popsection
.endif
"#
),
.endif"#),
sym SEMAPHORE,
$(in(reg) (($arg) as isize) ,)*
options(readonly, nostack, preserves_flags, $($opt),*),
)
);
}
));

0 comments on commit 5fb1ec0

Please sign in to comment.