JayDDee / cpuminer-opt

Optimized multi algo CPU miner
Other
762 stars 541 forks source link

cpu-priority option #309

Open JayDDee opened 3 years ago

JayDDee commented 3 years ago

This issue is opened to document the problems with cpu-priority option in a cpu miner. Although specific to cpuminer-opt some issues may also applies to other CPU miners.

TLDR: I have concluded the option should be removed from CPU miners. (this is actually more of a teaser to make you read it all)

The fundamental nature of CPU miners is they will use any and all CPU time available. With a preemptive scheduler no process with a lower priority will get any CPU time. It is therefore imperative that a process with unlimited CPU demand should always run at the lowest scheduler priority. This is often called idle priority and has only 1 process, often also called idle. The idle process reposnsibility is just to mark time (for statistical purposes) and wait for any other process that wants to run. The idle process will also defer to any other process with idle priority making it the absolute lowest prority. If any other process has idle priority it will only prevent the idle process from running resulting in 100% CPU occupancy.

If other processes are interferring with CPU mining and are not essential they should be shut down. Essential processes should be allowed to run as required.

By default cpuminer-opt miner threads run at idle priority. Other threads, like stratum run at default priority. This results in the stratum thread running at a higher priority than the miner threads reducing scheduling latency which reduces overall latency. High latency increases the risk of stale shares.

This issue doesn't exist for GPU miners because the CPU is not used for hashing and is not overloaded.

cpuminer-opt has other issues as well. Priority seems to work as intended (misguided intention IMO) on Windows. But on Linux it's a little more complicated. There are 2 components to CPU priority: the priority (nice value) and the scheduler class (idle, batch etc). The scheduler class is only set to idle if using default priority (nice 19). If cpu-priority option is set the scduler class is left at the default (TODO: find out what that is).

Furthermore any attempt to set a negative nice value (default is zero, negative is higher priority) requires root. Running a miner as root has security issues and I have avoided requiring it.

If anyone can make a case for keeping the cpu-priority option, please do so.

YetAnotherRussian commented 3 years ago

In Windows, these built-in priority settings are useless. If someone has low core count CPU (<=3 hw cores), the desired job is done through Process Lasso, which is Freeware (reduced, but enough functionality in free mode) and does it's job pretty well (e.g. we mine and surf the web, or mine and play an old single-core game). If core count >3, then proper thread count should be used to split the load. To achieve the best single-core performance, affinity is used (to force task sheduler to use the best aka best-hw-quality cores, which have the maximum turbo freq, and avoid switching between 'em).

So I guess the option may be removed safely.