Skip to content

hardened_std: eliminate thread::sleep from production code#102

Merged
zvonkok merged 4 commits intoNVIDIA:mainfrom
zvonkok:dev-log
Jan 12, 2026
Merged

hardened_std: eliminate thread::sleep from production code#102
zvonkok merged 4 commits intoNVIDIA:mainfrom
zvonkok:dev-log

Conversation

@zvonkok
Copy link
Copy Markdown
Collaborator

@zvonkok zvonkok commented Jan 12, 2026

Eliminate thread::sleep from production code

zvonkok and others added 2 commits January 12, 2026 16:00
- Add poll_timeout() to syslog.rs using blocking poll with timeout
- Update kata_agent.rs syslog_loop to use poll_timeout instead of sleep+poll
- Add process::exit() to hardened_std (thin wrapper around libc::_exit)
- Fix doctest in fs.rs (mark as ignore for private function)
- Remove unused import in kmsg.rs

This eliminates std::thread::sleep and std::time::Duration from production
code, moving closer to no_std compatibility. Test code still uses std.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
NVRC is PID 1 (init) with no threads - no thread::sleep, mutexes,
or thread-safe synchronization needed in production code.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings January 12, 2026 16:01
@zvonkok zvonkok added the ok-to-test Ok to test label Jan 12, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR removes thread::sleep from production code to support no_std compatibility for NVRC's single-threaded init process. The core change replaces the sleep+poll pattern with a blocking poll syscall that has a timeout.

Changes:

  • Introduces poll_timeout() function in syslog.rs that uses blocking poll with timeout instead of sleep+poll pattern
  • Removes std::thread::sleep and std::time::Duration imports from kata_agent.rs
  • Adds hardened_std::process::exit() wrapper for no_std compatibility (preparatory work)

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/syslog.rs Adds poll_timeout() functions that use blocking poll syscall with timeout to replace sleep+poll pattern
src/kata_agent.rs Removes thread::sleep usage, switches syslog_loop to use poll_timeout(500ms) instead
src/kmsg.rs Removes unused AsRawFd import
hardened_std/src/process.rs Adds exit() wrapper around libc::_exit() for no_std compatibility
hardened_std/src/fs.rs Changes doc example to ```ignore to prevent doctest execution
CLAUDE.md Documents single-threaded design principle

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

zvonkok and others added 2 commits January 12, 2026 16:08
- Document timeout clamping in poll_timeout() docstring: values are
  clamped to 65535ms (~65s), negative blocks indefinitely
- Add poll_socket_timeout tests verifying Ok(false) on timeout and
  Ok(true) when data arrives before timeout
- Expand test_syslog_loop_timeout comment explaining why no minimum
  time assertion: /dev/log may not exist in test environments

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- test_poll_socket_timeout_negative_zero_timeout: zero timeout returns immediately
- test_poll_timeout_at_custom_path: exercise poll_once_timeout via custom path
- test_poll_timeout_public_api: exercise public poll_timeout() function

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@zvonkok zvonkok merged commit 905708e into NVIDIA:main Jan 12, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Ok to test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants