Skip to main content

bb_ops/syscalls/clock_rng/
clock.rs

1//! `Clock` syscall - reads the scheduler's current time.
2
3use bb_ir::proto::onnx::NodeProto;
4use bb_runtime::atomic::DispatchResult;
5use bb_runtime::bus::OpError;
6use bb_runtime::runtime::RuntimeResourceRef;
7use bb_runtime::slot_value::SlotValue;
8use bb_runtime::syscall::values::TimestampValue;
9
10/// Marker struct.
11pub struct ClockOp;
12
13/// Op domain.
14pub const DOMAIN: &str = "ai.bytesandbrains.syscall";
15/// Op type name.
16pub const OP_TYPE: &str = "Clock";
17
18/// Invoke fn - emits `TimestampValue(now_ns)`.
19pub fn invoke(
20    _node: &NodeProto,
21    _inputs: &[(&str, &dyn SlotValue)],
22    ctx: &mut RuntimeResourceRef<'_>,
23) -> Result<DispatchResult, OpError> {
24    let now_ns = ctx.time.scheduler.now_ns();
25    Ok(DispatchResult::Immediate(vec![(
26        "now".to_string(),
27        Box::new(TimestampValue(now_ns)),
28    )]))
29}
30
31use bb_runtime::registry::OpRegistration as _BbOpsSyscallReg;
32
33inventory::submit! {
34    _BbOpsSyscallReg {
35        domain: DOMAIN,
36        op_type: OP_TYPE,
37        invoke,
38        kind: bb_runtime::registry::RegistrationKind::Syscall,
39    }
40}