Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchmark: add thread affinity mask option #68

Merged
merged 2 commits into from
Jun 22, 2019

Conversation

jtgrassie
Copy link
Contributor

Adds a thread affinity mask option for allowing to set miner threads to specific cpus/cores. Accepts a hex or decimal value representing a bitmask.

E.g. --threads 4 --affinity 0x1D, equates to our 4 threads t1,t2,t3,t4 and a mask 11101, which yields: (t4, cpu4), (t3, cpu3), (t2, cpu2), (t1, cpu0). So cpu is the bit position (right-to-left) and each 1 sequentially is the next thread.

Useful for benchmarking multi-processor/NUMA node systems.

@tevador
Copy link
Owner

tevador commented Jun 14, 2019

Good work.

However, to take full advantage of NUMA, we would have to also support having multiple datasets. It may be possible to control dataset allocation with CPU affinity because operating systems tend to allocate memory in the node that first writes to the memory page (this would have to be confirmed).

@jtgrassie
Copy link
Contributor Author

Yes, that's my next task. I'm going to start looking into/testing hwloc for pinning caches and datasets to NUMA nodes and add to this PR.

@jtgrassie
Copy link
Contributor Author

to take full advantage of NUMA, we would have to also support having multiple datasets

hwloc branch here https://github.com/jtgrassie/RandomX/tree/numa that uses multiple datasets and binds their memory to NUMA nodes. Then I'm using the affinity flag to bind threads to nodes. I'm not seeing a significant difference though, so need to investigate further before a PR of that hwloc branch.

@hyc
Copy link
Collaborator

hyc commented Jun 15, 2019

Fwiw, I ran multiple instances on separate NUMA nodes using numactl, don't recall seeing much impact then either.

Though come to think of it, I haven't run the latest version yet. These are from the old code.
#25 (comment)
#25 (comment)

@tevador tevador merged commit 81d3a9d into tevador:master Jun 22, 2019
@tevador
Copy link
Owner

tevador commented Jun 22, 2019

@jtgrassie FYI: I moved the affinity files into the 'tests' directory, since it's not directly related to the RandomX library. Also the mask_to_string function was giving some strange output starting with a null character, so I changed it to use std::ostringstream.

@jtgrassie
Copy link
Contributor Author

@tevador what was the issue with mask_to_string? I tested this pretty thoroughly and no issues. the nulls just present after the 1's and 0's to terminate the string. Also, would have been nice to preserve the files formatting (space vs tabs) as it now has a mixture.

@tevador
Copy link
Owner

tevador commented Jun 23, 2019

When built with Visual Studio, the output looked like this (for example --affinity 5):

 - thread affinity ( 101                                                            )

The whitespace characters inside the parentheses are actually null characters.

@jtgrassie
Copy link
Contributor Author

Very weird MS behavior of printing a string with nulls then! Can you fix the indentation on the file to keep consistently though please.

@jtgrassie jtgrassie deleted the affinity branch June 29, 2019 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants