Skip to content

Commit 3483b2f

Browse files
veluca93Virv12
authored andcommitted
Update dependencies and fix memory statistics.
1 parent d174fb9 commit 3483b2f

8 files changed

Lines changed: 100 additions & 83 deletions

File tree

pixie-uefi/Cargo.lock

Lines changed: 45 additions & 57 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pixie-uefi/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ coverage = ["dep:minicov"]
1616
anstyle = { version = "1.0.13", default-features = false }
1717
blake3 = { version = "1.8.2", default-features = false, features = ["prefer_intrinsics", "no_avx512", "pure"] }
1818
core_detect = "1.0.0"
19-
futures = { version = "0.3.29", default-features = false, features = ["alloc", "async-await"] }
19+
futures = { version = "0.3.31", default-features = false, features = ["alloc", "async-await"] }
2020
gpt_disk_io = "0.16.2"
2121
log = "0.4.28"
22-
lz4_flex = { version = "0.11.5", default-features = false }
22+
lz4_flex = { version = "0.12.0", default-features = false }
2323
managed = { version = "0.8.0", default-features = false, features = ["alloc"] }
2424
minicov = { version = "0.3.7", optional = true }
2525
postcard = { version = "1.1.3", default-features = false, features = ["alloc"] }
2626
smoltcp = { version = "0.12.0", default-features = false, features = ["alloc", "proto-ipv4", "medium-ethernet", "socket-udp", "socket-tcp", "socket-dhcpv4", "async", "socket-tcp-cubic"] }
2727
thingbuf = { version = "0.1.6", default-features = false, features = ["alloc"] }
28-
uefi = { version = "0.33.0", features = ["alloc", "global_allocator", "panic_handler"] }
28+
uefi = { version = "0.36.1", features = ["alloc", "global_allocator", "panic_handler"] }
2929

3030
[dependencies.pixie-shared]
3131
path = "../pixie-shared"

pixie-uefi/src/flash.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{
22
os::{
33
error::{Error, Result},
4-
TcpStream, UefiOS, PACKET_SIZE,
4+
memory, TcpStream, UefiOS, PACKET_SIZE,
55
},
66
MIN_MEMORY,
77
};
@@ -167,11 +167,11 @@ pub async fn flash(os: UefiOS, server_addr: SocketAddrV4) -> Result<()> {
167167
let task1 = async {
168168
let tx = tx;
169169
let mut last_seen = Vec::new();
170-
let total_mem = os.get_total_mem();
171-
let max_chunks = (total_mem.saturating_sub(MIN_MEMORY) as usize / MAX_CHUNK_SIZE).max(128);
170+
let free_mem = memory::stats().free;
171+
let max_chunks = (free_mem.saturating_sub(MIN_MEMORY) as usize / MAX_CHUNK_SIZE).max(128);
172172
log::debug!(
173-
"Total memory: {}. Max chunks in memory: {max_chunks}",
174-
BytesFmt(total_mem)
173+
"Free memory: {}. Max chunks in memory: {max_chunks}",
174+
BytesFmt(free_mem)
175175
);
176176
while !chunks_info.is_empty() {
177177
let recv = Box::pin(socket.recv(&mut buf));

pixie-uefi/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ mod store;
3131
#[cfg(feature = "coverage")]
3232
mod export_cov;
3333

34-
const MIN_MEMORY: u64 = 500 << 20;
34+
// Memory to keep free for non-chunk storage.
35+
const MIN_MEMORY: u64 = 32 << 20;
3536

3637
async fn server_discover(os: UefiOS) -> Result<SocketAddrV4> {
3738
let socket = os.udp_bind(None).await?;

pixie-uefi/src/os/memory.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use uefi::{boot::MemoryType, mem::memory_map::MemoryMap};
2+
3+
#[derive(Debug)]
4+
pub struct MemoryStats {
5+
pub used: u64,
6+
pub free: u64,
7+
pub other: u64,
8+
}
9+
10+
pub fn stats() -> MemoryStats {
11+
let mut stats = MemoryStats {
12+
used: 0,
13+
free: 0,
14+
other: 0,
15+
};
16+
const PAGE_SIZE: u64 = 4096;
17+
uefi::boot::memory_map(MemoryType::LOADER_DATA)
18+
.expect("Failed to get memory map")
19+
.entries()
20+
.for_each(|entry| {
21+
let sz = entry.page_count * PAGE_SIZE;
22+
match entry.ty {
23+
MemoryType::LOADER_DATA | MemoryType::LOADER_CODE => {
24+
stats.used += sz;
25+
}
26+
MemoryType::CONVENTIONAL => {
27+
stats.free += sz;
28+
}
29+
_ => {
30+
stats.other += sz;
31+
}
32+
}
33+
});
34+
stats
35+
}

pixie-uefi/src/os/mod.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ use core::{
2525
};
2626
use pixie_shared::util::BytesFmt;
2727
use uefi::{
28-
boot::{EventType, MemoryType, ScopedProtocol, TimerTrigger, Tpl},
29-
mem::memory_map::MemoryMap,
28+
boot::{EventType, ScopedProtocol, TimerTrigger, Tpl},
3029
proto::{
3130
console::{
3231
serial::Serial,
@@ -47,6 +46,7 @@ mod boot_options;
4746
pub mod disk;
4847
pub mod error;
4948
mod executor;
49+
pub mod memory;
5050
mod net;
5151
mod sync;
5252
mod timer;
@@ -539,14 +539,6 @@ impl UefiOS {
539539
pub fn shutdown(&self) -> ! {
540540
uefi::runtime::reset(uefi::runtime::ResetType::SHUTDOWN, Status::SUCCESS, None)
541541
}
542-
543-
pub fn get_total_mem(&self) -> u64 {
544-
uefi::boot::memory_map(MemoryType::LOADER_DATA)
545-
.expect("Failed to get memory map")
546-
.entries()
547-
.map(|entry| entry.page_count * 4096)
548-
.sum()
549-
}
550542
}
551543

552544
impl log::Log for UefiOS {

0 commit comments

Comments
 (0)