michaelmelanson / michaelmelanson/panda-os
Implement OP_ENVIRONMENT_TIME syscall
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
Summary
Implement an OP_ENVIRONMENT_TIME syscall to return the current time to userspace. Needed for timing-sensitive applications, benchmarking, and the service manager (restart backoff timers).
Current state
- No mechanism for userspace to query the current time
- The kernel has APIC timer infrastructure (
DeadlineTracker) but no wall-clock or monotonic time exposed to userspace
Desired behaviour
Add OP_ENVIRONMENT_TIME syscall that returns:
- Monotonic time: Nanoseconds since boot (for measuring durations, timeouts)
- Wall-clock time (optional/future): Real time from RTC if available
Possible time sources
- TSC (Time Stamp Counter): High-resolution, low-overhead. Requires calibration against a known time source at boot. Most x86_64 CPUs have invariant TSC.
- ACPI PM Timer: 3.579545 MHz fixed-frequency timer. Reliable but lower resolution. Accessed via I/O port.
- RTC (Real-Time Clock): Wall-clock time from CMOS. Low resolution (1 second), but gives actual date/time.
- HPET: High-precision event timer. Good resolution but MMIO-based access is slower than TSC.
Suggested approach
- Calibrate TSC frequency at boot using ACPI PM timer or PIT as reference
- Store TSC offset at boot time
OP_ENVIRONMENT_TIMEreads TSC, subtracts boot offset, converts to nanoseconds- Return as a 64-bit nanosecond value in the syscall response
Key files
panda-abi/src/lib.rs— addOP_ENVIRONMENT_TIMEopcodepanda-kernel/src/syscall/— implement the syscall handlerpanda-kernel/src/— TSC calibration at boot (new module or extend existing timer code)libpanda/src/sys/mod.rs— add low-level wrapperlibpanda/src/— add high-leveltime::monotonic()function
Testing
- Kernel test: call
OP_ENVIRONMENT_TIMEtwice with a busy-wait in between, verify the second value is larger - Userspace test: measure time before and after a known operation, verify the delta is reasonable
- Test that the value is monotonically increasing across multiple calls
Documentation
- Document the syscall in
panda-abiwith doc comments - Document the time source and resolution in
libpandadoc comments - Note any caveats (e.g., TSC may not be calibrated under QEMU TCG emulation)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with panda-abi/src/lib.rs and the syscall handlers under panda-kernel/src/syscall/, then trace the existing timer code under panda-kernel/src/. Review how time can be calibrated and exposed through libpanda/src/sys/mod.rs and libpanda/src/. Done means the opcode, kernel implementation, wrappers, documentation, and monotonicity tests work across the named kernel and userspace paths.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- api, operating-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100