Ragnaroek / mithril

Pure Rust Monero Miner
GNU General Public License v3.0
231 stars 40 forks source link

Thread Affinity #15

Open KronXIII opened 6 years ago

KronXIII commented 6 years ago

It'd be helpful to be able to specify in the config if the threads should be assigned to only some subset of cores, either explicitely pinning to cores A, B...N in tandem with the num_threads option, or as predefined "slots" for the bandit optimisation. For instance, if I have 8 cores available on a home machine, and I want to mine while keeping cores 1 & 2 free for day to day things. Does that sound doable here or would that mean rewriting a lot of things?

Ragnaroek commented 6 years ago

Thread Affinity is definitely something I want to implement. But it needs to be supported by Rust somehow. I did a very, very brief investigation on this, but didn't find anything.

The use-case was not trashing the CPU caches, though. I did not see the use-case leaving some CPUs idle :)

Could you share how want do configure something like this in cargo.toml?

It's definitely doable and should only touch the code that is starting the threads (so very local, I guess).

KronXIII commented 6 years ago

I'll look into the thread spawning and work on integrating something, but I doubt I can contribute meaningfully. Frankly I know just enough Rust/Threading to be dangerous, so no promises.

For the config, optionaly specifying an array of coreids would do? Something like

# Default empty array falls back to existing num_thread strategy
# bind_to_cores = []

# Or non empty array flags the named cores for exclusive use
bind_to_cores = [4, 6, 8, 10]

I looked into rust support for this, and everything calls out to C at some point. This stood out to me while searching https://github.com/Elzair/core_affinity_rs