Skip to content
This repository was archived by the owner on Jul 17, 2025. It is now read-only.

Commit c994460

Browse files
committed
Added scheme to globally number threads, packages, and NUMA nodes
1 parent 85748b2 commit c994460

File tree

5 files changed

+75
-31
lines changed

5 files changed

+75
-31
lines changed

kernel/src/arch/x86_64/rackscale/client.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ pub(crate) fn get_frame_as(frame_id: u64) -> Result<u64, RPCError> {
6262
}
6363
}
6464

65-
pub(crate) fn get_num_clients() -> u64 {
66-
(crate::CMDLINE.get().map_or(2, |c| c.workers) - 1) as u64
65+
pub(crate) fn get_num_clients() -> ClientId {
66+
(crate::CMDLINE.get().map_or(2, |c| c.workers) - 1) as ClientId
6767
}
6868

69-
pub(crate) fn get_local_client_id() -> u64 {
70-
(crate::CMDLINE.get().map_or(1, |c| c.machine_id) - 1) as u64
69+
pub(crate) fn get_local_client_id() -> ClientId {
70+
(crate::CMDLINE.get().map_or(1, |c| c.machine_id) - 1) as ClientId
7171
}
7272

7373
pub(crate) fn client_get_work() -> () {

kernel/src/arch/x86_64/rackscale/controller.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ lazy_static! {
6666
}
6767

6868
lazy_static! {
69-
pub(crate) static ref HWTHREADS: Arc<Mutex<Vec<(ClientId, CpuThread)>>> = {
69+
pub(crate) static ref HWTHREADS: Arc<Mutex<Vec<CpuThread>>> = {
7070
let mut hwthreads = Vec::try_with_capacity(get_num_clients() as usize)
7171
.expect("Failed to create vector for rack cpu threads");
7272
Arc::new(Mutex::new(hwthreads))

kernel/src/arch/x86_64/rackscale/registration.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rpc::RPCClient;
1515

1616
use super::dcm::node_registration::dcm_register_node;
1717
use crate::arch::rackscale::controller::{HWTHREADS, SHMEM_MANAGERS};
18+
use crate::arch::rackscale::systemops::{local_to_gtid, local_to_node_id, local_to_package_id};
1819
use crate::error::KResult;
1920
use crate::memory::LARGE_PAGE_SIZE;
2021
use crate::transport::shmem::{create_shmem_manager, get_affinity_shmem};
@@ -125,31 +126,39 @@ pub(crate) fn register_client(
125126
if remaining.len() == 0 {
126127
// Register client resources with DCM, DCM doesn't care about pids, so
127128
// send w/ dummy pid
128-
let node_id = dcm_register_node(0, req.num_cores, memslices);
129-
info!("Registered client DCM, assigned client_id={:?}", node_id);
129+
let client_id = dcm_register_node(0, req.num_cores, memslices);
130+
info!("Registered client DCM, assigned client_id={:?}", client_id);
130131

131132
// Create shmem memory manager
132-
// Probably not most accurate to use node_id for affinity here
133+
// Probably not most accurate to use client_id for affinity here
133134
let mut managers = SHMEM_MANAGERS.lock();
134-
managers[node_id as usize] = create_shmem_manager(
135+
managers[client_id as usize] = create_shmem_manager(
135136
req.affinity_shmem_offset,
136137
req.affinity_shmem_size,
137-
node_id,
138+
client_id,
138139
);
139140
log::info!(
140141
"Created shmem manager on behalf of client {:?}: {:?}",
141-
node_id,
142-
managers[node_id as usize]
142+
client_id,
143+
managers[client_id as usize]
143144
);
144145

145146
// Record information about the hardware threads
146147
info!("hwthreads: {:?}", hwthreads);
147148
let mut rack_threads = HWTHREADS.lock();
148149
for hwthread in hwthreads {
149-
rack_threads.push((node_id, *hwthread));
150+
rack_threads.push(CpuThread {
151+
// these are global values to make sure no conflicts across rack
152+
id: local_to_gtid(hwthread.id, client_id),
153+
node_id: local_to_node_id(hwthread.node_id, client_id),
154+
package_id: local_to_package_id(hwthread.package_id, client_id),
155+
// these are local relative to below, so no work to do
156+
core_id: hwthread.core_id,
157+
thread_id: hwthread.thread_id,
158+
});
150159
}
151160

152-
Ok(node_id)
161+
Ok(client_id)
153162
} else {
154163
error!("Extra data in register_client");
155164
Err(RPCError::MalformedResponse)

kernel/src/arch/x86_64/rackscale/systemops/get_hardware_threads.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,29 +82,20 @@ pub(crate) fn handle_get_hardware_threads(
8282
}
8383
let local_pid = local_pid.unwrap();
8484

85-
let rack_threads = HWTHREADS.lock();
86-
87-
// calculate total number of threads
88-
let mut hwthreads =
89-
Vec::try_with_capacity(rack_threads.len()).expect("failed to allocate space for hwthreads");
90-
for i in 0..rack_threads.len() {
91-
hwthreads.push(rack_threads[i].1);
92-
}
93-
log::info!(
94-
"Found {:?} hardware threads: {:?}",
95-
hwthreads.len(),
96-
hwthreads
97-
);
98-
9985
// Encode hwthread information into payload buffer
86+
let rack_threads = HWTHREADS.lock();
10087
let start = KernelRpcRes_SIZE as usize;
10188
let end = start
102-
+ hwthreads.len() * core::mem::size_of::<CpuThread>()
89+
+ rack_threads.len() * core::mem::size_of::<CpuThread>()
10390
+ core::mem::size_of::<Vec<CpuThread>>();
10491
let additional_data = end - start;
105-
unsafe { encode(&hwthreads, &mut &mut payload[start..end]) }
92+
unsafe { encode(&*rack_threads, &mut &mut payload[start..end]) }
10693
.expect("Failed to encode hardware thread vector");
107-
log::info!("Sending back {:?} bytes of data", additional_data);
94+
log::info!(
95+
"Sending back {:?} bytes of data ({:?} hwthreads)",
96+
additional_data,
97+
rack_threads.len()
98+
);
10899

109100
// Construct return
110101
let res = KernelRpcRes {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,48 @@
11
// Copyright © 2022 University of Colorado. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
33

4+
use kpi::system::{GlobalThreadId, NodeId, PackageId};
5+
use rpc::rpc::ClientId;
6+
7+
use crate::arch::rackscale::client::get_num_clients;
8+
49
pub mod get_hardware_threads;
10+
11+
// Helper functions for CpuThread GlobalThreadId
12+
pub(crate) fn local_to_gtid(gtid: GlobalThreadId, client_id: ClientId) -> GlobalThreadId {
13+
get_num_clients() as GlobalThreadId * gtid + client_id as GlobalThreadId
14+
}
15+
16+
pub(crate) fn gtid_to_local(gtid: GlobalThreadId, client_id: ClientId) -> GlobalThreadId {
17+
(gtid - client_id as GlobalThreadId) / get_num_clients() as GlobalThreadId
18+
}
19+
20+
pub(crate) fn is_gtid_local(gtid: GlobalThreadId, client_id: ClientId) -> bool {
21+
gtid % get_num_clients() as GlobalThreadId == client_id as GlobalThreadId
22+
}
23+
24+
// Helper functions for CpuThread NodeId
25+
pub(crate) fn local_to_node_id(node_id: NodeId, client_id: ClientId) -> NodeId {
26+
get_num_clients() as NodeId * node_id + client_id as NodeId
27+
}
28+
29+
pub(crate) fn node_id_to_local(node_id: NodeId, client_id: ClientId) -> NodeId {
30+
(node_id - client_id as NodeId) / get_num_clients() as NodeId
31+
}
32+
33+
pub(crate) fn is_node_id_local(node_id: NodeId, client_id: ClientId) -> bool {
34+
node_id % get_num_clients() as NodeId == client_id as NodeId
35+
}
36+
37+
// Helper functions for CpuThread PackageId
38+
pub(crate) fn local_to_package_id(package_id: PackageId, client_id: ClientId) -> PackageId {
39+
get_num_clients() as PackageId * package_id + client_id as PackageId
40+
}
41+
42+
pub(crate) fn package_id_to_local(package_id: PackageId, client_id: ClientId) -> PackageId {
43+
(package_id - client_id as PackageId) / get_num_clients() as PackageId
44+
}
45+
46+
pub(crate) fn is_package_id_local(package_id: PackageId, client_id: ClientId) -> bool {
47+
package_id % get_num_clients() as PackageId == client_id as PackageId
48+
}

0 commit comments

Comments
 (0)