How to have cpuminer use all CPUs on FreeBSD


March 2014.
Image

Situation


You're trying to mine some cryptocoins on your FreeBSD box. Unfortunately, the mining process seems to occur on only one CPU, despite cpuminer creating and binding threads.


[2014-03-23 01:41:53] 8 miner threads started, using 'X11' algorithm.
[2014-03-23 01:41:53] Starting Stratum on stratum+tcp://drkpool.com:3333
[2014-03-23 01:41:53] Binding thread 0 to cpu 0
[2014-03-23 01:41:53] Binding thread 1 to cpu 1
[2014-03-23 01:41:53] Binding thread 2 to cpu 2
[2014-03-23 01:41:53] Binding thread 3 to cpu 3
[2014-03-23 01:41:53] Binding thread 4 to cpu 4
[2014-03-23 01:41:53] Binding thread 5 to cpu 5
[2014-03-23 01:41:53] Binding thread 6 to cpu 6
[2014-03-23 01:41:53] Binding thread 7 to cpu 7
[2014-03-23 01:41:56] Stratum detected new block

Using ktrace yields some information. The thread-cpu binding is failing.

23429 minerd CALL write(0x2,0x7fffff5fa660,0x30)
23429 minerd GIO fd 2 wrote 48 bytes
"[2014-03-23 00:45:32] Binding thread 1 to cpu 1
"
23429 minerd RET write 48/0x30
23429 minerd CALL _umtx_op(0x803019060,0x16,0,0,0)
23429 minerd RET _umtx_op 0
23429 minerd CALL cpuset_setaffinity(0x3,0x3,0xffffffffffffffff,0x10,0x7fffff5faf70)
23429 minerd RET cpuset_setaffinity -1 errno 11 Resource deadlock avoided
23429 minerd CALL nanosleep(0x7fffff5fad90,0x7fffff5fad80)
23429 minerd RET _umtx_op 0
23429 minerd CALL mmap(0,0x400000,0x3,0x1002,0xffffffff,0)
23429 minerd RET mmap 34431041536/0x804400000
23429 minerd CALL _umtx_op(0x803019060,0x16,0,0,0)
23429 minerd RET _umtx_op 0

Solution


Use cpuset to change the affinity of the process once it's launched.

cpuset -c -l 0-15 -p 3044

Adapt the command to your number of CPUs and the PID of your miner process.

See kern/163585 for more information.