Skip to content

Commit cf35157

Browse files
author
Erika Hunhoff
committed
Add support for DCM resource release request
1 parent fdfd0cb commit cf35157

6 files changed

Lines changed: 178 additions & 52 deletions

File tree

kernel/src/arch/x86_64/rackscale/dcm/mod.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,32 @@ use crate::arch::rackscale::controller::{get_local_pid, FrameCacheMemslice};
2828
use crate::fallible_string::TryString;
2929
use crate::transport::ethernet::{init_ethernet_rpc, ETHERNET_IFACE};
3030

31-
pub(crate) mod dcm_request;
3231
pub(crate) mod node_registration;
32+
pub(crate) mod resource_alloc;
33+
pub(crate) mod resource_release;
34+
35+
use resource_alloc::ALLOC_LEN;
3336

3437
#[derive(Debug, Eq, PartialEq, PartialOrd, Clone, Copy)]
3538
#[repr(u8)]
3639
pub(crate) enum DCMOps {
3740
/// Register a node (cores and memory) with DCM
3841
RegisterNode = 1,
39-
/// Request cores or memory from DCM
40-
ResourceRequest = 2,
42+
/// Alloc cores or memory from DCM
43+
ResourceAlloc = 2,
44+
/// Release a resource to DCM
45+
ResourceRelease = 3,
4146

42-
Unknown = 3,
47+
Unknown = 4,
4348
}
4449

4550
impl From<RPCType> for DCMOps {
4651
/// Construct a RPCType enum based on a 8-bit value.
4752
fn from(op: RPCType) -> DCMOps {
4853
match op {
4954
1 => DCMOps::RegisterNode,
50-
2 => DCMOps::ResourceRequest,
55+
2 => DCMOps::ResourceAlloc,
56+
3 => DCMOps::ResourceRelease,
5157
_ => DCMOps::Unknown,
5258
}
5359
}
@@ -68,8 +74,8 @@ impl DCMInterface {
6874
pub fn new(iface: Arc<Mutex<Interface<'static, DevQueuePhy>>>) -> DCMInterface {
6975
// Create UDP RX buffer
7076
let mut sock_vec = Vec::new();
71-
sock_vec.try_reserve_exact(dcm_request::ALLOC_LEN).unwrap();
72-
sock_vec.resize(dcm_request::ALLOC_LEN, 0);
77+
sock_vec.try_reserve_exact(ALLOC_LEN).unwrap();
78+
sock_vec.resize(ALLOC_LEN, 0);
7379
let mut metadata_vec = Vec::<UdpPacketMetadata>::new();
7480
metadata_vec.try_reserve_exact(1).unwrap();
7581
metadata_vec.resize(1, UdpPacketMetadata::EMPTY);

kernel/src/arch/x86_64/rackscale/dcm/dcm_request.rs renamed to kernel/src/arch/x86_64/rackscale/dcm/resource_alloc.rs

Lines changed: 52 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,90 +14,105 @@ use super::{DCMOps, DCM_INTERFACE};
1414

1515
#[derive(Debug, Default)]
1616
#[repr(C)]
17-
pub struct AllocRequest {
17+
pub struct ResourceAllocRequest {
1818
pub application: u64,
1919
pub cores: u64,
2020
pub memslices: u64,
2121
}
22-
pub const REQ_SIZE: usize = core::mem::size_of::<AllocRequest>();
22+
pub const REQ_SIZE: usize = core::mem::size_of::<ResourceAllocRequest>();
2323

24-
impl AllocRequest {
24+
impl ResourceAllocRequest {
2525
/// # Safety
26-
/// - `self` must be valid AllocRequest
26+
/// - `self` must be valid ResourceAllocRequest
2727
pub unsafe fn as_mut_bytes(&mut self) -> &mut [u8; REQ_SIZE] {
28-
::core::slice::from_raw_parts_mut((self as *const AllocRequest) as *mut u8, REQ_SIZE)
29-
.try_into()
30-
.expect("slice with incorrect length")
28+
::core::slice::from_raw_parts_mut(
29+
(self as *const ResourceAllocRequest) as *mut u8,
30+
REQ_SIZE,
31+
)
32+
.try_into()
33+
.expect("slice with incorrect length")
3134
}
3235

3336
/// # Safety
34-
/// - `self` must be valid AllocRequest
37+
/// - `self` must be valid ResourceAllocRequest
3538
pub unsafe fn as_bytes(&self) -> &[u8; REQ_SIZE] {
36-
::core::slice::from_raw_parts((self as *const AllocRequest) as *const u8, REQ_SIZE)
39+
::core::slice::from_raw_parts((self as *const ResourceAllocRequest) as *const u8, REQ_SIZE)
3740
.try_into()
3841
.expect("slice with incorrect length")
3942
}
4043
}
4144

4245
#[derive(Debug, Default)]
4346
#[repr(C)]
44-
pub struct AllocResponse {
47+
pub struct ResourceAllocResponse {
4548
pub alloc_id: u64,
4649
}
47-
pub const RES_SIZE: usize = core::mem::size_of::<AllocResponse>();
50+
pub const RES_SIZE: usize = core::mem::size_of::<ResourceAllocResponse>();
4851

49-
impl AllocResponse {
52+
impl ResourceAllocResponse {
5053
/// # Safety
51-
/// - `self` must be valid AllocResponse
54+
/// - `self` must be valid ResourceAllocResponse
5255
pub unsafe fn as_mut_bytes(&mut self) -> &mut [u8; RES_SIZE] {
53-
::core::slice::from_raw_parts_mut((self as *const AllocResponse) as *mut u8, RES_SIZE)
54-
.try_into()
55-
.expect("slice with incorrect length")
56+
::core::slice::from_raw_parts_mut(
57+
(self as *const ResourceAllocResponse) as *mut u8,
58+
RES_SIZE,
59+
)
60+
.try_into()
61+
.expect("slice with incorrect length")
5662
}
5763

5864
/// # Safety
59-
/// - `self` must be valid AllocResponse
65+
/// - `self` must be valid ResourceAllocResponse
6066
pub unsafe fn as_bytes(&self) -> &[u8; RES_SIZE] {
61-
::core::slice::from_raw_parts((self as *const AllocResponse) as *const u8, RES_SIZE)
62-
.try_into()
63-
.expect("slice with incorrect length")
67+
::core::slice::from_raw_parts(
68+
(self as *const ResourceAllocResponse) as *const u8,
69+
RES_SIZE,
70+
)
71+
.try_into()
72+
.expect("slice with incorrect length")
6473
}
6574
}
6675

6776
#[derive(Debug, Default)]
6877
#[repr(C)]
69-
pub struct AllocAssignment {
78+
pub struct ResourceAllocAssignment {
7079
pub alloc_id: u64,
7180
pub node: u64,
7281
}
73-
pub const ALLOC_LEN: usize = core::mem::size_of::<AllocAssignment>();
82+
pub const ALLOC_LEN: usize = core::mem::size_of::<ResourceAllocAssignment>();
7483

75-
impl AllocAssignment {
84+
impl ResourceAllocAssignment {
7685
/// # Safety
77-
/// - `self` must be valid AllocAssignment
86+
/// - `self` must be valid ResourceAllocAssignment
7887
pub unsafe fn as_mut_bytes(&mut self) -> &mut [u8; ALLOC_LEN] {
79-
::core::slice::from_raw_parts_mut((self as *const AllocAssignment) as *mut u8, ALLOC_LEN)
80-
.try_into()
81-
.expect("slice with incorrect length")
88+
::core::slice::from_raw_parts_mut(
89+
(self as *const ResourceAllocAssignment) as *mut u8,
90+
ALLOC_LEN,
91+
)
92+
.try_into()
93+
.expect("slice with incorrect length")
8294
}
8395

8496
/// # Safety
85-
/// - `self` must be valid AllocAssignment
97+
/// - `self` must be valid ResourceAllocAssignment
8698
pub unsafe fn as_bytes(&self) -> &[u8; ALLOC_LEN] {
87-
::core::slice::from_raw_parts((self as *const AllocAssignment) as *const u8, ALLOC_LEN)
88-
.try_into()
89-
.expect("slice with incorrect length")
99+
::core::slice::from_raw_parts(
100+
(self as *const ResourceAllocAssignment) as *const u8,
101+
ALLOC_LEN,
102+
)
103+
.try_into()
104+
.expect("slice with incorrect length")
90105
}
91106
}
92107

93-
pub(crate) fn make_dcm_request(local_pid: usize, is_core: bool) -> u64 {
94-
let req = AllocRequest {
95-
application: 1,
108+
pub(crate) fn dcm_resource_alloc(local_pid: usize, is_core: bool) -> u64 {
109+
let req = ResourceAllocRequest {
110+
application: 1, // TODO: filler for application for no
96111
cores: if is_core { 1 } else { 0 },
97112
memslices: if is_core { 0 } else { 1 },
98113
};
99-
let mut res = AllocResponse { alloc_id: 0 };
100-
let mut assignment = AllocAssignment {
114+
let mut res = ResourceAllocResponse { alloc_id: 0 };
115+
let mut assignment = ResourceAllocAssignment {
101116
alloc_id: 0,
102117
node: 0,
103118
};
@@ -109,7 +124,7 @@ pub(crate) fn make_dcm_request(local_pid: usize, is_core: bool) -> u64 {
109124
.client
110125
.call(
111126
local_pid,
112-
DCMOps::ResourceRequest as RPCType,
127+
DCMOps::ResourceAlloc as RPCType,
113128
unsafe { &[req.as_bytes()] },
114129
unsafe { &mut [res.as_mut_bytes()] },
115130
)
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Copyright © 2022 VMware, Inc. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
use log::{debug, warn};
5+
use rpc::rpc::RPCType;
6+
use rpc::RPCClient;
7+
use smoltcp::socket::UdpSocket;
8+
use smoltcp::time::Instant;
9+
10+
use crate::transport::ethernet::ETHERNET_IFACE;
11+
12+
use super::super::kernelrpc::*;
13+
use super::{DCMOps, DCM_INTERFACE};
14+
15+
#[derive(Debug, Default)]
16+
#[repr(C)]
17+
pub struct ResourceReleaseRequest {
18+
pub node_id: u64,
19+
pub application: u64,
20+
pub cores: u64,
21+
pub memslices: u64,
22+
}
23+
pub const REQ_SIZE: usize = core::mem::size_of::<ResourceReleaseRequest>();
24+
25+
impl ResourceReleaseRequest {
26+
/// # Safety
27+
/// - `self` must be valid ResourceReleaseRequest
28+
pub unsafe fn as_mut_bytes(&mut self) -> &mut [u8; REQ_SIZE] {
29+
::core::slice::from_raw_parts_mut(
30+
(self as *const ResourceReleaseRequest) as *mut u8,
31+
REQ_SIZE,
32+
)
33+
.try_into()
34+
.expect("slice with incorrect length")
35+
}
36+
37+
/// # Safety
38+
/// - `self` must be valid ResourceReleaseRequest
39+
pub unsafe fn as_bytes(&self) -> &[u8; REQ_SIZE] {
40+
::core::slice::from_raw_parts(
41+
(self as *const ResourceReleaseRequest) as *const u8,
42+
REQ_SIZE,
43+
)
44+
.try_into()
45+
.expect("slice with incorrect length")
46+
}
47+
}
48+
49+
#[derive(Debug, Default)]
50+
#[repr(C)]
51+
pub struct ResourceReleaseResponse {
52+
pub is_success: u64,
53+
}
54+
pub const RES_SIZE: usize = core::mem::size_of::<ResourceReleaseResponse>();
55+
56+
impl ResourceReleaseResponse {
57+
/// # Safety
58+
/// - `self` must be valid ResourceReleaseResponse
59+
pub unsafe fn as_mut_bytes(&mut self) -> &mut [u8; RES_SIZE] {
60+
::core::slice::from_raw_parts_mut(
61+
(self as *const ResourceReleaseResponse) as *mut u8,
62+
RES_SIZE,
63+
)
64+
.try_into()
65+
.expect("slice with incorrect length")
66+
}
67+
68+
/// # Safety
69+
/// - `self` must be valid ResourceReleaseResponse
70+
pub unsafe fn as_bytes(&self) -> &[u8; RES_SIZE] {
71+
::core::slice::from_raw_parts(
72+
(self as *const ResourceReleaseResponse) as *const u8,
73+
RES_SIZE,
74+
)
75+
.try_into()
76+
.expect("slice with incorrect length")
77+
}
78+
}
79+
80+
pub(crate) fn dcm_resource_release(node_id: u64, local_pid: usize, is_core: bool) -> u64 {
81+
let req = ResourceReleaseRequest {
82+
node_id,
83+
application: 1, // TODO: filler for application for now
84+
cores: if is_core { 1 } else { 0 },
85+
memslices: if is_core { 0 } else { 1 },
86+
};
87+
let mut res = ResourceReleaseResponse { is_success: 0 };
88+
89+
// Send call, get allocation response in return
90+
DCM_INTERFACE
91+
.lock()
92+
.client
93+
.call(
94+
local_pid,
95+
DCMOps::ResourceRelease as RPCType,
96+
unsafe { &[req.as_bytes()] },
97+
unsafe { &mut [res.as_mut_bytes()] },
98+
)
99+
.unwrap();
100+
debug!(
101+
"Received is_success for DCM resource release: {:?}",
102+
res.is_success
103+
);
104+
return res.is_success;
105+
}

kernel/src/arch/x86_64/rackscale/processops/allocate_physical.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::memory::{Frame, PAddr, BASE_PAGE_SIZE};
2121
use crate::nrproc::NrProcess;
2222
use crate::transport::shmem::SHMEM_REGION;
2323

24-
use super::super::dcm::dcm_request::make_dcm_request;
24+
use super::super::dcm::resource_alloc::dcm_resource_alloc;
2525
use super::super::dcm::DCM_INTERFACE;
2626
use super::super::kernelrpc::*;
2727

@@ -126,7 +126,7 @@ pub(crate) fn handle_allocate_physical(
126126
}
127127

128128
// Let DCM choose node
129-
let node = make_dcm_request(local_pid, false);
129+
let node = dcm_resource_alloc(local_pid, false);
130130
debug!("Received node assignment from DCM: node {:?}", node);
131131

132132
let mut shmem_managers = SHMEM_MANAGERS.lock();

kernel/src/arch/x86_64/rackscale/processops/core.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use log::{debug, warn};
88
use rpc::rpc::*;
99
use rpc::RPCClient;
1010

11-
use super::super::dcm::dcm_request::make_dcm_request;
11+
use super::super::dcm::resource_alloc::dcm_resource_alloc;
1212
use super::super::kernelrpc::*;
1313
use crate::arch::rackscale::controller::get_local_pid;
1414

@@ -76,7 +76,7 @@ pub(crate) fn handle_request_core(hdr: &mut RPCHeader, payload: &mut [u8]) -> Re
7676
}
7777
};
7878

79-
let node = make_dcm_request(local_pid, true);
79+
let node = dcm_resource_alloc(local_pid, true);
8080

8181
// Construct and return result
8282
let res = KernelRpcRes {

kernel/src/arch/x86_64/rackscale/processops/release_physical.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::memory::backends::PhysicalPageProvider;
1515
use crate::memory::{Frame, PAddr, BASE_PAGE_SIZE};
1616
use crate::nrproc::NrProcess;
1717

18-
use super::super::dcm::dcm_request::make_dcm_request;
18+
use super::super::dcm::resource_release::dcm_resource_release;
1919
use super::super::dcm::DCM_INTERFACE;
2020
use super::super::kernelrpc::*;
2121
use crate::arch::process::current_pid;
@@ -132,9 +132,9 @@ pub(crate) fn handle_release_physical(
132132
Ok(())
133133
};
134134

135-
// TODO: update DCM
136-
//let node = make_dcm_request(local_pid, false);
137-
//debug!("Received node assignment from DCM: node {:?}", node);
135+
// Tell DCM the resource is no longer being used
136+
let is_success = dcm_resource_release(node_id, local_pid, false);
137+
debug!("DCM release resource: is_success={:?}", is_success);
138138

139139
let res = match ret {
140140
Ok(()) => KernelRpcRes {

0 commit comments

Comments
 (0)