Skip to content

Commit 8eb29ef

Browse files
committed
Use 4096 PLDM file part buffer
This is located in sram2 that has spare space. Part size has a large impact on transfer performance. This updates pldm-file crate and other mctp-rs crates, with fixes for PLDM platform and PLDM file CRCs. Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
1 parent 72bb7ed commit 8eb29ef

File tree

3 files changed

+46
-20
lines changed

3 files changed

+46
-20
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,16 @@ num-traits = { version = "0.2", default-features = false }
7373
# embassy-executor = { git = "https://github.com/embassy-rs/embassy/", rev = "0290c8565e9e3443d52edb5c250a53a50f6fc2a8" }
7474

7575
# Updated for embassy-usb api change
76-
mctp-usb-embassy = { git = "https://github.com/CodeConstruct/mctp-rs", rev = "88c9eba20c6ac62025438bb7ca9b9578c9f2679c" }
76+
mctp-usb-embassy = { git = "https://github.com/CodeConstruct/mctp-rs", rev = "d8385ad5f548d0256c89bdb0c187396b29f43e41" }
7777
# Updated to match mtp-usb-embassy. Also has performance and stack size improvements.
7878
# Includes ControlEvent change.
79-
mctp-estack = { git = "https://github.com/CodeConstruct/mctp-rs", rev = "88c9eba20c6ac62025438bb7ca9b9578c9f2679c" }
80-
mctp = { git = "https://github.com/CodeConstruct/mctp-rs", rev = "88c9eba20c6ac62025438bb7ca9b9578c9f2679c" }
79+
mctp-estack = { git = "https://github.com/CodeConstruct/mctp-rs", rev = "d8385ad5f548d0256c89bdb0c187396b29f43e41" }
80+
mctp = { git = "https://github.com/CodeConstruct/mctp-rs", rev = "d8385ad5f548d0256c89bdb0c187396b29f43e41" }
8181

8282
# pldm-file and pldm-platform are not yet published
83-
pldm = { git = "https://github.com/CodeConstruct/mctp-rs", rev = "88c9eba20c6ac62025438bb7ca9b9578c9f2679c" }
84-
pldm-file = { git = "https://github.com/CodeConstruct/mctp-rs", rev = "88c9eba20c6ac62025438bb7ca9b9578c9f2679c" }
85-
pldm-platform = { git = "https://github.com/CodeConstruct/mctp-rs", rev = "88c9eba20c6ac62025438bb7ca9b9578c9f2679c" }
83+
pldm = { git = "https://github.com/CodeConstruct/mctp-rs", rev = "d8385ad5f548d0256c89bdb0c187396b29f43e41" }
84+
pldm-file = { git = "https://github.com/CodeConstruct/mctp-rs", rev = "d8385ad5f548d0256c89bdb0c187396b29f43e41" }
85+
pldm-platform = { git = "https://github.com/CodeConstruct/mctp-rs", rev = "d8385ad5f548d0256c89bdb0c187396b29f43e41" }
8686

8787
[features]
8888
default = ["log-usbserial", "nvme-mi", "pldm-file"]

src/pldm.rs

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
use log::{debug, error, info, trace, warn};
99

1010
use core::future::Future;
11+
use core::mem::MaybeUninit;
12+
13+
use static_cell::StaticCell;
1114

1215
use pldm_file::PLDM_TYPE_FILE_TRANSFER;
1316
use pldm_platform::proto::PdrRecord;
@@ -44,6 +47,13 @@ pub trait PldmTimeout: Future + Sized {
4447

4548
impl<F: Future> PldmTimeout for F {}
4649

50+
// Limited by MCTP message size, must be power of two
51+
const PART_SIZE: usize = 4096;
52+
// sram2 is not zeroed at boot, so need MaybeUninit.
53+
#[link_section = ".sram2_uninit"]
54+
static mut PART_BUF: MaybeUninit<StaticCell<[u8; PART_SIZE + 18]>> =
55+
MaybeUninit::uninit();
56+
4757
#[embassy_executor::task]
4858
pub(crate) async fn pldm_file_task(
4959
router: &'static Router<'static>,
@@ -52,8 +62,12 @@ pub(crate) async fn pldm_file_task(
5262
) -> ! {
5363
info!("PLDM file task started");
5464

55-
let mut host = None;
65+
// Safety: will only be written once, no shared references.
66+
#[allow(static_mut_refs)]
67+
let part_buf = unsafe { PART_BUF.write(StaticCell::new()) };
68+
let part_buf = part_buf.init_with(|| [0u8; _]);
5669

70+
let mut host = None;
5771
loop {
5872
let target = match host.take() {
5973
Some(t) => t,
@@ -63,7 +77,8 @@ pub(crate) async fn pldm_file_task(
6377
info!("Running PLDM file transfer from {target}");
6478

6579
let run = async {
66-
if let Err(e) = pldm_run_file(target, router, hash).await {
80+
if let Err(e) = pldm_run_file(target, router, hash, part_buf).await
81+
{
6782
warn!("Error running file transfer: {e}");
6883
}
6984
};
@@ -143,6 +158,7 @@ async fn pldm_run_file(
143158
eid: Eid,
144159
router: &'static Router<'static>,
145160
hash: &'static SharedHash,
161+
part_buf: &mut [u8],
146162
) -> Result<(), PldmError> {
147163
use pldm_file::client::*;
148164
use pldm_file::proto::*;
@@ -242,7 +258,10 @@ async fn pldm_run_file(
242258
// NegotiateTransferParameters
243259
let req_types = [pldm_file::PLDM_TYPE_FILE_TRANSFER];
244260
let (size, neg_types) = ctrq::negotiate_transfer_parameters(
245-
comm, &req_types, &mut buf, 1024,
261+
comm,
262+
&req_types,
263+
&mut buf,
264+
PART_SIZE as u16,
246265
)
247266
.await
248267
.inspect_err(|e| warn!("Error from Negotiate: {e}"))?;
@@ -275,11 +294,18 @@ async fn pldm_run_file(
275294
None,
276295
);
277296
let mut count = 0;
278-
df_read_with(comm, fd, 0, filedesc.file_max_size as usize, |b| {
279-
count += b.len();
280-
hash.update_blocking(&mut hash_ctx, b);
281-
Ok(())
282-
})
297+
df_read_with(
298+
comm,
299+
fd,
300+
0,
301+
filedesc.file_max_size as usize,
302+
part_buf,
303+
|b| {
304+
count += b.len();
305+
hash.update_blocking(&mut hash_ctx, b);
306+
Ok(())
307+
},
308+
)
283309
.with_timeout(READ_TIMEOUT)
284310
.await?
285311
.inspect_err(|e| warn!("df_read failed {e}"))?;

0 commit comments

Comments
 (0)