elzair / core_affinity_rs Goto Github PK
View Code? Open in Web Editor NEWRust crate for managing CPU core affinities
License: Apache License 2.0
Rust crate for managing CPU core affinities
License: Apache License 2.0
Just noticed this crate is still maintained, IIRC it felt a bit dormant for a while.
Since we needed new features, we forked this library and added support for a range of other OSses like dragonfly BSD, solaris and more, see here:
https://github.com/AFLplusplus/LibAFL/blob/main/libafl_bolts/src/core_affinity.rs
Apart from more OS support, we have also changed the API in some ways.
If there is some interest we could still try to merge the two libraries again?
Recently, GitHub CI started to warn, since this crates uses a rather old winapi
version. Any chances to update the dependencies? Do you still accept PRs?
set_for_current() doesn't check the result value of sched_setaffinity or the errno after the call.
https://docs.rs/core_affinity/latest/src/core_affinity/lib.rs.html#104
https://linux.die.net/man/2/sched_setaffinity
So if you call core_affinity::set_for_current(x) when x is a core that doesn't exist it fails silently.
set_for_current should check the result and return a Result<> or at the very least the result value
Thanks for sharing this lib.
I'd like to suggest the possibility of setting the cpu affinity for more than 1 cpu.
(set_for_current would receive an array or vector instead of a scalar).
thanks,
Luiz.
It seems we can implement it on linux with sched_getcpu
.
This link gives another way to get cpu id on x86 platform, which can cover windows on x86.
Hi,
I've tried the library successfully on Linux but on my development machine running macOS Monterey (version 12.6.3) it doesn't work with version 0.8.0 or 0.8.1 of this crate.
The Vec
of available cores returned by core_affinity::get_core_ids()
does contain the core I'm trying to pin to but the bool
returned from core_affinity::set_for_current(core_id)
is false.
Are there any tricks I need to apply on Mac?
Kind regards,
Nicholas
On Windows, you can set the affinity for the whole process which is then inherited by child processes. Unfortunately, this is not the behavior for thread affinities.
Could it be possible to also add a set_for_current_process
function ?
The documentation for
"core_affinity::get_core_ids"
says:
"This function tries to retrieve information on all the "cores" active on this system."
But what the function actually does is call sched_getaffinity, and check which cores the current thread is allowed to run on.
On a freshly started thread, this will typically be all cores on the machine.
However, if affinity has been set, the core_affinity::get_core_ids-function will return only the cores the current thread is allowed to run on.
I think the documentation, or the implementation should change.
(I was bitten by this. In my test-suite all but the first test that ran hade horrible performance. Turns out all but the first test actually ran with affinity = core 0 for all threads, since the first test had set the affinity for the main thread to core 0)
The current version supports only Linux, Windows and macOS. PR #15 should this issue.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.