Skip to content

Commit

Permalink
drop macOS cpu tag support
Browse files Browse the repository at this point in the history
  • Loading branch information
zh-jq committed Feb 8, 2025
1 parent b407c3c commit 9b5c887
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 145 deletions.
10 changes: 0 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ capnpc = "0.20"
libc = "0.2.169"
rustix = { version = "0.38", default-features = false }
windows-sys = "0.59"
mach2 = "0.4"
#
serde = "1.0"
yaml-rust = { package = "yaml-rust2", version = "0.9" }
Expand Down
26 changes: 14 additions & 12 deletions g3keymess/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,25 @@
*/

use std::path::PathBuf;
#[cfg(all(unix, not(target_os = "openbsd")))]
#[cfg(any(
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "netbsd",
))]
use std::str::FromStr;
use std::sync::OnceLock;

use anyhow::{anyhow, Context};
use clap::{value_parser, Arg, ArgAction, Command, ValueHint};
#[cfg(all(unix, not(target_os = "openbsd")))]
#[cfg(any(
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "netbsd",
))]
use log::info;

use g3_compat::CpuAffinity;
Expand Down Expand Up @@ -152,16 +164,6 @@ pub fn parse_clap() -> anyhow::Result<Option<ProcArgs>> {
}
}
}
#[cfg(target_os = "macos")]
if let Some(s) = group_name.strip_prefix("core") {
use std::num::NonZeroI32;

if let Ok(id) = NonZeroI32::from_str(s) {
let cpu = CpuAffinity::new(id);
info!("will try to bind to cpu core {id}");
proc_args.core_affinity = Some(cpu);
}
}
}

#[cfg(feature = "openssl-async-job")]
Expand Down
4 changes: 0 additions & 4 deletions lib/g3-compat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,3 @@ rustix = { workspace = true, features = ["system"] }

[target.'cfg(windows)'.dependencies]
windows-sys = { workspace = true, features = ["Win32_System_SystemInformation"] }

[target.'cfg(target_os = "macos")'.dependencies]
libc.workspace = true
mach2.workspace = true
74 changes: 0 additions & 74 deletions lib/g3-compat/src/sched/macos.rs

This file was deleted.

1 change: 0 additions & 1 deletion lib/g3-compat/src/sched/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@
path = "freebsd.rs"
)]
#[cfg_attr(target_os = "netbsd", path = "netbsd.rs")]
#[cfg_attr(target_os = "macos", path = "macos.rs")]
mod os;
pub use os::CpuAffinity;
12 changes: 0 additions & 12 deletions lib/g3-runtime/src/unaided/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,6 @@ impl UnaidedRuntimeConfig {
Ok(())
}

#[cfg(target_os = "macos")]
pub fn set_mapped_sched_affinity(&mut self) -> anyhow::Result<()> {
use std::num::NonZeroI32;

let n = self.num_threads();
for i in 1..=n {
let cpu = CpuAffinity::new(unsafe { NonZeroI32::new_unchecked(i as i32) });
self.sched_affinity.insert(i, cpu);
}
Ok(())
}

pub fn set_max_io_events_per_tick(&mut self, capacity: usize) {
self.max_io_events_per_tick = Some(capacity);
}
Expand Down
35 changes: 22 additions & 13 deletions lib/g3-runtime/src/unaided/yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ impl UnaidedRuntimeConfig {
pub fn parse_yaml(v: &Yaml) -> anyhow::Result<Self> {
if let Yaml::Hash(map) = v {
let mut config = UnaidedRuntimeConfig::default();
#[cfg(all(unix, not(target_os = "openbsd")))]
#[cfg(any(
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "netbsd",
))]
let mut set_mapped_sched_affinity = false;

g3_yaml::foreach_kv(map, |k, v| match g3_yaml::key::normalize(k).as_str() {
Expand All @@ -38,24 +44,21 @@ impl UnaidedRuntimeConfig {
config.set_thread_stack_size(value);
Ok(())
}
#[cfg(all(unix, not(target_os = "openbsd")))]
#[cfg(any(
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "netbsd",
))]
"sched_affinity" => {
if let Yaml::Hash(map) = v {
for (ik, iv) in map.iter() {
let id = g3_yaml::value::as_usize(ik)
.context(format!("the keys for {k} should be usize value"))?;
#[cfg(any(
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "netbsd",
))]

let cpu = g3_yaml::value::as_cpu_set(iv)
.context(format!("invalid cpu set value for {k}/{id}"))?;
#[cfg(target_os = "macos")]
let cpu = g3_yaml::value::as_cpu_tag(iv)
.context(format!("invalid cpu tag value for {k}/{id}"))?;

config.set_sched_affinity(id, cpu);
}
Expand Down Expand Up @@ -87,7 +90,13 @@ impl UnaidedRuntimeConfig {
_ => Err(anyhow!("invalid key {k}")),
})?;

#[cfg(all(unix, not(target_os = "openbsd")))]
#[cfg(any(
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "netbsd",
))]
if set_mapped_sched_affinity {
config
.set_mapped_sched_affinity()
Expand Down
22 changes: 20 additions & 2 deletions lib/g3-yaml/src/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,27 @@ mod quinn;
#[cfg(feature = "quinn")]
pub use quinn::as_quinn_transport_config;

#[cfg(all(unix, not(target_os = "openbsd"), feature = "sched"))]
#[cfg(all(
any(
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "netbsd",
),
feature = "sched"
))]
mod sched;
#[cfg(all(unix, not(target_os = "openbsd"), feature = "sched"))]
#[cfg(all(
any(
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "netbsd",
),
feature = "sched"
))]
pub use sched::*;

#[cfg(feature = "route")]
Expand Down
16 changes: 0 additions & 16 deletions lib/g3-yaml/src/value/sched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ use yaml_rust::Yaml;

use g3_compat::CpuAffinity;

#[cfg(any(
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "netbsd",
))]
pub fn as_cpu_set(v: &Yaml) -> anyhow::Result<CpuAffinity> {
use anyhow::{anyhow, Context};

Expand All @@ -44,12 +37,3 @@ pub fn as_cpu_set(v: &Yaml) -> anyhow::Result<CpuAffinity> {

Ok(set)
}

#[cfg(target_os = "macos")]
pub fn as_cpu_tag(v: &Yaml) -> anyhow::Result<CpuAffinity> {
use anyhow::Context;

let v =
crate::value::as_nonzero_i32(v).context("cpu tag should be valid nonzero isize value")?;
Ok(CpuAffinity::new(v))
}

0 comments on commit 9b5c887

Please sign in to comment.