|
1 | 1 | //! Wrapper for DPDK's environment abstraction layer (EAL).
|
2 | 2 | use crate::ffi;
|
3 | 3 | use arrayvec::*;
|
| 4 | +use crossbeam::thread::{Scope, ScopedJoinHandle}; |
4 | 5 | use log::{debug, info, warn};
|
5 | 6 | use std::collections::{HashMap, HashSet};
|
6 | 7 | use std::convert::{TryFrom, TryInto};
|
@@ -134,6 +135,31 @@ impl LCoreId {
|
134 | 135 | f()
|
135 | 136 | })
|
136 | 137 | }
|
| 138 | + |
| 139 | + /// Launch a thread pined to this core. |
| 140 | + /// TODO: change it to crossbeam's `spawn` signature when we start to use crossbeam. |
| 141 | + pub fn launch_scoped<'scope, 'env, F, T>( |
| 142 | + self, |
| 143 | + s: &'scope Scope<'env>, |
| 144 | + f: F, |
| 145 | + ) -> ScopedJoinHandle<'scope, T> |
| 146 | + where |
| 147 | + F: FnOnce() -> T, |
| 148 | + F: Send + 'env, |
| 149 | + T: Send + 'env, |
| 150 | + { |
| 151 | + let lcore_id = self.0; |
| 152 | + s.spawn(move |_| { |
| 153 | + // Safety: foreign function. |
| 154 | + let ret = unsafe { |
| 155 | + dpdk_sys::rte_thread_set_affinity(&mut dpdk_sys::rte_lcore_cpuset(lcore_id)) |
| 156 | + }; |
| 157 | + if ret < 0 { |
| 158 | + warn!("Failed to set affinity on lcore {}", lcore_id); |
| 159 | + } |
| 160 | + f() |
| 161 | + }) |
| 162 | + } |
137 | 163 | }
|
138 | 164 |
|
139 | 165 | #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
@@ -903,8 +929,7 @@ impl Eal {
|
903 | 929 | for lcore_id in &lcore_id_list {
|
904 | 930 | let lcore_id = *lcore_id;
|
905 | 931 | // Safety: foreign function.
|
906 |
| - let socket_id = |
907 |
| - unsafe { dpdk_sys::rte_lcore_to_socket_id(lcore_id.try_into().unwrap()) }; |
| 932 | + let socket_id = unsafe { dpdk_sys::rte_lcore_to_socket_id(lcore_id) }; |
908 | 933 | // Safety: foreign function.
|
909 | 934 | let cpu_id = unsafe { dpdk_sys::rte_lcore_to_cpu_id(lcore_id.try_into().unwrap()) };
|
910 | 935 | debug!(
|
|
0 commit comments