Skip to content

uefi: use Duration for boot::stall #1659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion uefi-test-runner/examples/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// ANCHOR_END: features

// ANCHOR: use
use core::time::Duration;
use log::info;
use uefi::prelude::*;
// ANCHOR_END: use
Expand All @@ -20,7 +21,7 @@ fn main() -> Status {
// ANCHOR_END: services
// ANCHOR: log
info!("Hello world!");
boot::stall(10_000_000);
boot::stall(Duration::from_secs(10));
// ANCHOR_END: log
// ANCHOR: return
Status::SUCCESS
Expand Down
3 changes: 2 additions & 1 deletion uefi-test-runner/examples/loaded_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#![no_main]
#![no_std]

use core::time::Duration;
use log::info;
use uefi::boot::{self, SearchType};
use uefi::prelude::*;
Expand All @@ -20,7 +21,7 @@ fn main() -> Status {

print_image_path().unwrap();

boot::stall(10_000_000);
boot::stall(Duration::from_secs(10));
Status::SUCCESS
}
// ANCHOR_END: main
Expand Down
7 changes: 3 additions & 4 deletions uefi-test-runner/examples/timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@

extern crate alloc;

use log::{info, warn};

// ANCHOR: use
use core::time::Duration;
use log::{info, warn};
use uefi::boot;
use uefi::prelude::*;
use uefi::proto::misc::Timestamp;

// ANCHOR_END: use

// ANCHOR: entry
Expand All @@ -30,7 +29,7 @@ fn main() -> Status {
// ANCHOR_END: params

// ANCHOR: stall
boot::stall(10_000_000);
boot::stall(Duration::from_secs(10));
// ANCHOR_END: stall

// ANCHOR: return
Expand Down
4 changes: 3 additions & 1 deletion uefi-test-runner/src/proto/network/snp.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: MIT OR Apache-2.0

use core::time::Duration;

use uefi::proto::network::snp::{InterruptStatus, ReceiveFlags, SimpleNetwork};
use uefi::proto::network::MacAddress;
use uefi::{boot, Status};
Expand Down Expand Up @@ -106,7 +108,7 @@ pub fn test() {
if simple_network.receive(&mut buffer, None, None, None, None)
== Err(Status::NOT_READY.into())
{
boot::stall(1_000_000);
boot::stall(Duration::from_secs(1));

simple_network
.receive(&mut buffer, None, None, None, None)
Expand Down
2 changes: 1 addition & 1 deletion uefi-test-runner/src/proto/pi/mp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ extern "efiapi" fn proc_increment_atomic(arg: *mut c_void) {
}

extern "efiapi" fn proc_wait_100ms(_: *mut c_void) {
boot::stall(100_000);
boot::stall(Duration::from_millis(100));
}

fn test_startup_all_aps(mps: &MpServices) {
Expand Down
4 changes: 4 additions & 0 deletions uefi/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# uefi - [Unreleased]

## Changed
- **Breaking:** `boot::stall` now take `Duration` instead of
`usize`.


# uefi - 0.35.0 (2025-05-04)

Expand Down
7 changes: 5 additions & 2 deletions uefi/src/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use core::mem::MaybeUninit;
use core::ops::{Deref, DerefMut};
use core::ptr::{self, NonNull};
use core::sync::atomic::{AtomicPtr, Ordering};
use core::time::Duration;
use core::{mem, slice};
use uefi_raw::table::boot::{InterfaceType, TimerDelay};
#[cfg(feature = "alloc")]
Expand Down Expand Up @@ -1423,11 +1424,13 @@ pub fn set_watchdog_timer(
.to_result()
}

/// Stalls execution for the given number of microseconds.
pub fn stall(microseconds: usize) {
/// Stalls execution for the given duration.
pub fn stall(duration: Duration) {
let bt = boot_services_raw_panicking();
let bt = unsafe { bt.as_ref() };

let microseconds = duration.as_micros() as usize;

unsafe {
// No error conditions are defined in the spec for this function, so
// ignore the status.
Expand Down
4 changes: 3 additions & 1 deletion uefi/src/helpers/panic_handler.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: MIT OR Apache-2.0

use core::time::Duration;

use crate::{boot, println};
use cfg_if::cfg_if;

Expand All @@ -9,7 +11,7 @@ fn panic_handler(info: &core::panic::PanicInfo) -> ! {

// Give the user some time to read the message
if boot::are_boot_services_active() {
boot::stall(10_000_000);
boot::stall(Duration::from_secs(10));
} else {
let mut dummy = 0u64;
// FIXME: May need different counter values in debug & release builds
Expand Down
3 changes: 2 additions & 1 deletion uefi/src/proto/network/ip4config2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use alloc::vec;
use alloc::vec::Vec;
use core::ffi::c_void;
use core::time::Duration;

use uefi::boot::ScopedProtocol;
use uefi::prelude::*;
Expand Down Expand Up @@ -137,7 +138,7 @@ impl Ip4Config2 {
if verbose {
print!(".");
}
boot::stall(1_000_000);
boot::stall(Duration::from_secs(1));
let info = self.get_interface_info()?;
if info.station_addr != no_address {
if verbose {
Expand Down
Loading