add coreid
This commit is contained in:
parent
71af7b785a
commit
1628a9c690
8
Cargo.lock
generated
8
Cargo.lock
generated
@ -116,6 +116,13 @@ version = "1.0.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
|
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "coreid"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crc32c"
|
name = "crc32c"
|
||||||
version = "0.6.8"
|
version = "0.6.8"
|
||||||
@ -207,6 +214,7 @@ name = "kv_bench"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
|
"coreid",
|
||||||
"mace",
|
"mace",
|
||||||
"rand 0.9.2",
|
"rand 0.9.2",
|
||||||
]
|
]
|
||||||
|
|||||||
@ -8,6 +8,7 @@ edition = "2024"
|
|||||||
mace = { path = "/home/workspace/gits/github/mace"}
|
mace = { path = "/home/workspace/gits/github/mace"}
|
||||||
clap = { version = "4.5.42", features = ["derive"] }
|
clap = { version = "4.5.42", features = ["derive"] }
|
||||||
rand = "0.9.2"
|
rand = "0.9.2"
|
||||||
|
coreid = { path = "coreid"}
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = true
|
lto = true
|
||||||
|
|||||||
2
coreid/.gitignore
vendored
Normal file
2
coreid/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/target
|
||||||
|
Cargo.lock
|
||||||
8
coreid/Cargo.toml
Normal file
8
coreid/Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "coreid"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
authors = ["abbytsing@gmail.com"]
|
||||||
|
|
||||||
|
[target.'cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))'.dependencies]
|
||||||
|
libc = "^0.2.0"
|
||||||
37
coreid/src/lib.rs
Normal file
37
coreid/src/lib.rs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
use libc::{
|
||||||
|
cpu_set_t, pthread_self, pthread_setaffinity_np, sched_getcpu, sysconf, CPU_SET,
|
||||||
|
_SC_NPROCESSORS_ONLN,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
pub fn current_core() -> usize {
|
||||||
|
unsafe { sched_getcpu() as usize }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
pub fn cores_online() -> usize {
|
||||||
|
unsafe { sysconf(_SC_NPROCESSORS_ONLN) as usize }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
pub fn bind_core(id: usize) {
|
||||||
|
unsafe {
|
||||||
|
let mut set: cpu_set_t = std::mem::zeroed();
|
||||||
|
CPU_SET(id % cores_online(), &mut set);
|
||||||
|
pthread_setaffinity_np(pthread_self(), size_of::<cpu_set_t>(), &set);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
pub fn unbind_core() {
|
||||||
|
unsafe {
|
||||||
|
let mut set: cpu_set_t = std::mem::zeroed();
|
||||||
|
pthread_setaffinity_np(pthread_self(), std::mem::size_of::<cpu_set_t>(), &mut set);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
pub fn gettid() -> usize {
|
||||||
|
unsafe { libc::gettid() as usize }
|
||||||
|
}
|
||||||
@ -63,6 +63,7 @@ fn main() {
|
|||||||
let mut opt = Options::new(path);
|
let mut opt = Options::new(path);
|
||||||
opt.sync_on_write = false;
|
opt.sync_on_write = false;
|
||||||
opt.tmp_store = true;
|
opt.tmp_store = true;
|
||||||
|
opt.consolidate_threshold = 512;
|
||||||
// opt.cache_capacity = 3 << 30; // this is very important for large key-value store
|
// opt.cache_capacity = 3 << 30; // this is very important for large key-value store
|
||||||
let db = Mace::new(opt.validate().unwrap()).unwrap();
|
let db = Mace::new(opt.validate().unwrap()).unwrap();
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user