1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//! Task-context control capability for perf events.
//!
//! The perf fd keeps its historical non-sleeping event lock for BPF output
//! paths that may run with preemption disabled. Implementations that need to
//! wait for a CPU-owned worker expose this separate capability; file control
//! operations dispatch through it without retaining the non-sleeping lock.
use alloc::sync::Arc;
use core::{any::Any, fmt::Debug};
use ax_memory_addr::PhysAddr;
use axpoll::Pollable;
use super::PerfReadValues;
#[cfg(target_arch = "aarch64")]
use super::output::{PerfOutputScope, PerfRingOutput};
/// Sleepable, task-context operations for one perf fd.
pub(super) trait PerfControl: Pollable + Send + Sync + Debug {
/// Starts the event and waits until its owner context has committed it.
fn enable(&self) -> crate::StarryResult<()>;
/// Stops the event and waits for owner-context quiescence.
fn disable(&self) -> crate::StarryResult<()>;
/// Resets the event count in owner-context order.
fn reset(&self) -> crate::StarryResult<()>;
/// Takes an owner-consistent counter and timing snapshot.
fn read_values(&self) -> crate::StarryResult<PerfReadValues>;
/// Allocates and publishes the user-visible mmap backing.
fn device_mmap(
&self,
_len: usize,
) -> crate::StarryResult<(PhysAddr, Arc<dyn Any + Send + Sync>)> {
Err(crate::StarryError::Unsupported)
}
/// Returns a pinned output ring for `PERF_EVENT_IOC_SET_OUTPUT`.
#[cfg(target_arch = "aarch64")]
fn output_ring(&self) -> Option<PerfRingOutput> {
None
}
/// Returns the task or CPU context used for output compatibility checks.
#[cfg(target_arch = "aarch64")]
fn output_scope(&self) -> Option<PerfOutputScope> {
None
}
/// Redirects records into a separately pinned output ring.
#[cfg(target_arch = "aarch64")]
fn redirect_output(&self, _output: PerfRingOutput) -> crate::StarryResult<()> {
Ok(())
}
/// Detaches a previous redirect and restores this event's own mmap ring.
#[cfg(target_arch = "aarch64")]
fn detach_output(&self) -> crate::StarryResult<()> {
Ok(())
}
}