mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 18:25:30 +00:00
aquatic_common: rename CpuPinningMode to CpuPinningDirection
This commit is contained in:
parent
ffce413217
commit
76ccd8ba55
1 changed files with 22 additions and 22 deletions
|
|
@ -5,12 +5,12 @@ use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, TomlConfig, Serialize, Deserialize)]
|
#[derive(Clone, Copy, Debug, PartialEq, TomlConfig, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "lowercase")]
|
#[serde(rename_all = "lowercase")]
|
||||||
pub enum CpuPinningMode {
|
pub enum CpuPinningDirection {
|
||||||
Ascending,
|
Ascending,
|
||||||
Descending,
|
Descending,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for CpuPinningMode {
|
impl Default for CpuPinningDirection {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::Ascending
|
Self::Ascending
|
||||||
}
|
}
|
||||||
|
|
@ -34,7 +34,7 @@ impl Default for HyperThreadMapping {
|
||||||
|
|
||||||
pub trait CpuPinningConfig {
|
pub trait CpuPinningConfig {
|
||||||
fn active(&self) -> bool;
|
fn active(&self) -> bool;
|
||||||
fn mode(&self) -> CpuPinningMode;
|
fn direction(&self) -> CpuPinningDirection;
|
||||||
#[cfg(feature = "with-glommio")]
|
#[cfg(feature = "with-glommio")]
|
||||||
fn hyperthread(&self) -> HyperThreadMapping;
|
fn hyperthread(&self) -> HyperThreadMapping;
|
||||||
fn core_offset(&self) -> usize;
|
fn core_offset(&self) -> usize;
|
||||||
|
|
@ -42,9 +42,9 @@ pub trait CpuPinningConfig {
|
||||||
|
|
||||||
// Do these shenanigans for compatibility with aquatic_toml_config
|
// Do these shenanigans for compatibility with aquatic_toml_config
|
||||||
#[duplicate::duplicate_item(
|
#[duplicate::duplicate_item(
|
||||||
mod_name struct_name direction;
|
mod_name struct_name cpu_pinning_direction;
|
||||||
[asc] [CpuPinningConfigAsc] [CpuPinningMode::Ascending];
|
[asc] [CpuPinningConfigAsc] [CpuPinningDirection::Ascending];
|
||||||
[desc] [CpuPinningConfigDesc] [CpuPinningMode::Descending];
|
[desc] [CpuPinningConfigDesc] [CpuPinningDirection::Descending];
|
||||||
)]
|
)]
|
||||||
pub mod mod_name {
|
pub mod mod_name {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
@ -52,7 +52,7 @@ pub mod mod_name {
|
||||||
#[derive(Clone, Debug, PartialEq, TomlConfig, Deserialize)]
|
#[derive(Clone, Debug, PartialEq, TomlConfig, Deserialize)]
|
||||||
pub struct struct_name {
|
pub struct struct_name {
|
||||||
pub active: bool,
|
pub active: bool,
|
||||||
pub mode: CpuPinningMode,
|
pub direction: CpuPinningDirection,
|
||||||
#[cfg(feature = "with-glommio")]
|
#[cfg(feature = "with-glommio")]
|
||||||
pub hyperthread: HyperThreadMapping,
|
pub hyperthread: HyperThreadMapping,
|
||||||
pub core_offset: usize,
|
pub core_offset: usize,
|
||||||
|
|
@ -62,7 +62,7 @@ pub mod mod_name {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
active: false,
|
active: false,
|
||||||
mode: direction,
|
direction: cpu_pinning_direction,
|
||||||
#[cfg(feature = "with-glommio")]
|
#[cfg(feature = "with-glommio")]
|
||||||
hyperthread: Default::default(),
|
hyperthread: Default::default(),
|
||||||
core_offset: 0,
|
core_offset: 0,
|
||||||
|
|
@ -73,8 +73,8 @@ pub mod mod_name {
|
||||||
fn active(&self) -> bool {
|
fn active(&self) -> bool {
|
||||||
self.active
|
self.active
|
||||||
}
|
}
|
||||||
fn mode(&self) -> CpuPinningMode {
|
fn direction(&self) -> CpuPinningDirection {
|
||||||
self.mode
|
self.direction
|
||||||
}
|
}
|
||||||
#[cfg(feature = "with-glommio")]
|
#[cfg(feature = "with-glommio")]
|
||||||
fn hyperthread(&self) -> HyperThreadMapping {
|
fn hyperthread(&self) -> HyperThreadMapping {
|
||||||
|
|
@ -111,9 +111,9 @@ impl WorkerIndex {
|
||||||
|
|
||||||
let ascending_index = ascending_index.min(max_core_index);
|
let ascending_index = ascending_index.min(max_core_index);
|
||||||
|
|
||||||
match config.mode() {
|
match config.direction() {
|
||||||
CpuPinningMode::Ascending => ascending_index,
|
CpuPinningDirection::Ascending => ascending_index,
|
||||||
CpuPinningMode::Descending => max_core_index - ascending_index,
|
CpuPinningDirection::Descending => max_core_index - ascending_index,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -160,14 +160,14 @@ pub mod glommio {
|
||||||
let core_index =
|
let core_index =
|
||||||
worker_index.get_core_index(config, socket_workers, request_workers, num_cpu_cores);
|
worker_index.get_core_index(config, socket_workers, request_workers, num_cpu_cores);
|
||||||
|
|
||||||
let too_many_workers = match (&config.hyperthread(), &config.mode()) {
|
let too_many_workers = match (&config.hyperthread(), &config.direction()) {
|
||||||
(
|
(
|
||||||
HyperThreadMapping::Split | HyperThreadMapping::Subsequent,
|
HyperThreadMapping::Split | HyperThreadMapping::Subsequent,
|
||||||
CpuPinningMode::Ascending,
|
CpuPinningDirection::Ascending,
|
||||||
) => core_index >= num_cpu_cores / 2,
|
) => core_index >= num_cpu_cores / 2,
|
||||||
(
|
(
|
||||||
HyperThreadMapping::Split | HyperThreadMapping::Subsequent,
|
HyperThreadMapping::Split | HyperThreadMapping::Subsequent,
|
||||||
CpuPinningMode::Descending,
|
CpuPinningDirection::Descending,
|
||||||
) => core_index < num_cpu_cores / 2,
|
) => core_index < num_cpu_cores / 2,
|
||||||
(_, _) => false,
|
(_, _) => false,
|
||||||
};
|
};
|
||||||
|
|
@ -178,22 +178,22 @@ pub mod glommio {
|
||||||
|
|
||||||
let cpu_set = match config.hyperthread() {
|
let cpu_set = match config.hyperthread() {
|
||||||
HyperThreadMapping::System => get_cpu_set()?.filter(|l| l.core == core_index),
|
HyperThreadMapping::System => get_cpu_set()?.filter(|l| l.core == core_index),
|
||||||
HyperThreadMapping::Split => match config.mode() {
|
HyperThreadMapping::Split => match config.direction() {
|
||||||
CpuPinningMode::Ascending => get_cpu_set()?
|
CpuPinningDirection::Ascending => get_cpu_set()?
|
||||||
.filter(|l| l.cpu == core_index || l.cpu == core_index + num_cpu_cores / 2),
|
.filter(|l| l.cpu == core_index || l.cpu == core_index + num_cpu_cores / 2),
|
||||||
CpuPinningMode::Descending => get_cpu_set()?
|
CpuPinningDirection::Descending => get_cpu_set()?
|
||||||
.filter(|l| l.cpu == core_index || l.cpu == core_index - num_cpu_cores / 2),
|
.filter(|l| l.cpu == core_index || l.cpu == core_index - num_cpu_cores / 2),
|
||||||
},
|
},
|
||||||
HyperThreadMapping::Subsequent => {
|
HyperThreadMapping::Subsequent => {
|
||||||
let cpu_index_offset = match config.mode() {
|
let cpu_index_offset = match config.direction() {
|
||||||
// 0 -> 0 and 1
|
// 0 -> 0 and 1
|
||||||
// 1 -> 2 and 3
|
// 1 -> 2 and 3
|
||||||
// 2 -> 4 and 5
|
// 2 -> 4 and 5
|
||||||
CpuPinningMode::Ascending => core_index * 2,
|
CpuPinningDirection::Ascending => core_index * 2,
|
||||||
// 15 -> 14 and 15
|
// 15 -> 14 and 15
|
||||||
// 14 -> 12 and 13
|
// 14 -> 12 and 13
|
||||||
// 13 -> 10 and 11
|
// 13 -> 10 and 11
|
||||||
CpuPinningMode::Descending => num_cpu_cores - 2 * (num_cpu_cores - core_index),
|
CpuPinningDirection::Descending => num_cpu_cores - 2 * (num_cpu_cores - core_index),
|
||||||
};
|
};
|
||||||
|
|
||||||
get_cpu_set()?
|
get_cpu_set()?
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue