BOINC / boinc

Open-source software for volunteer computing and grid computing.
https://boinc.berkeley.edu
GNU Lesser General Public License v3.0
1.99k stars 444 forks source link

Use CPU affinity on Apple Silicon Macs #5268

Open dirspb opened 1 year ago

dirspb commented 1 year ago

Describe the problem When BOINC CPUs usage set lower then 100%, tasks threads executed on Performance(P) cores. Utilizing Efficiency(E) core in such case would lower power usage or increase performance (for the same power usage).

Describe the solution you'd like Assume CPU has x efficiency cores. Then x tasks should be assigned to E cores. E.g. M1 Pro CPU has 2 efficiency cores and 8 performance ones. If running 6 tasks and two of them assigned to E cores fan runs with 2500 rpm. If running 5 tasks without assignment the fan is 4200rpm. While performance of 2E+4P cores is higher then 5P cores. It will be most useful for Macbook Air since they have 4E + 4P cores and no fan. They start throttle CPU even if one BOINC task is running. For them best option is to run just 4E core tasks.

Additional context assigning to E core can be done during process start or using shell command: sudo taskpolicy -b -p <PID>

AenBleidd commented 1 year ago

@CharlieFenton, do you think it is something valuable (and not technically complex) to implement on MacOS?

davidpanderson commented 1 year ago

This would be a medium-sized change to the CPU scheduling logic, which currently has no notion of high/low performance cores. Which CPUs besides Apple have this? I think some phone chips do.

barton2526 commented 1 year ago

Which CPUs besides Apple have this? I think some phone chips do.

Notably, Intel 12th gen chips (Alder Lake). https://en.wikipedia.org/wiki/Alder_Lake

davidpanderson commented 1 year ago

Interesting. My feeling is that OSs (like Win) are developing schemes for scheduling performance/efficiency cores, and that BOINC shouldn't try to override these schemes (e.g. by CPU pinning). But if the OS has a way to say "run this process on an efficiency core if possible" we should use that for task processes.

(though as always, some BOINC users may want the opposite policy.)

We should collect info on the relevant features of Win/Mac/Linux/Android. MacOS has these APIs: https://developer.apple.com/library/archive/documentation/Performance/Conceptual/power_efficiency_guidelines_osx/PrioritizeWorkAtTheTaskLevel.html

davidpanderson commented 1 year ago

BTW, some OSs have ways to prioritize disk I/O. We should look into these too.

dirspb commented 1 year ago

I was manually using it on M1 MBP for quite some time already. So have a few tips:

dirspb commented 1 year ago

Another option I would use is ability to keep running tasks on E core only when working on battery. But not sure if it's enough useful for complicating config.

CharlieFenton commented 1 year ago

@dirspb How does running on the efficiency cores affect the performance? Does processing tasks take longer on efficiency cores? Please finish this incomplete critical sentence from your original post:

While performance of:

Please note that we receive many concerns from BOINC volunteers who want to speed up BOINC's processing of tasks, and almost none who are concerned about the power consumption, fan speed, etc. (for example, #5249.) So if this reduces throughput, it would generate many complaints.

davidpanderson commented 1 year ago

Sounds like the Manager should run at user-interactive (or maybe user-initiated) priority, and apps should run at utility priority (I assume the OS will preferentially run them on efficiency cores).

dirspb commented 1 year ago

@davidpanderson, utility priority will still use P cores if available.

dirspb commented 1 year ago

For tasks running on P core it took ~29300s to complete (1531775775, 1531775777, 1531775778). For tasks running on E core it took ~34180s to complete (1531775776, 1531775780). While two P cores use ~4.5W and two E cores use ~0.5W (+ idle system uses 0.8W).

MBP M1 Pro power usage
dirspb commented 1 year ago

@CharlieFenton , if config is "100% of the CPUs" behavior should be kept as current. This request addresses only case when BOINC CPUs usage set lower then 100%. Main BOINC is concept is to be ran in background minimally affecting user experience. Having hot laptop and full throttled fans does affects user. Currently on 10 core M1 CPU and "100% of the CPUs" config it runs 8 P core tasks and 2 E core tasks. When change config to "60% of the CPUs" it runs 6 P core tasks. Means shutdowns 2 E core and 2 P core tasks. Suggested behavior for "60% of the CPUs" config to run 4 P core tasks and 2 E core tasks. Means shutdowns 4 P core tasks. OS default scheduling doesn't work best because of special nature of BOINC tasks. They should have lowest QoS (background), but still use as much CPU resources as possible.

dirspb commented 1 year ago

What I'm curious is why E core tasks receive twice less credit than (P core tasks ). Even though it was completed in 11 hours and P core task was completed in 2.5 days.

AenBleidd commented 1 year ago

What is more interesting: why CPU time is equal for both E and P tasks?

dirspb commented 1 year ago

@AenBleidd , they just did different amount of attempts during the same time:

DONE :: 498 starting structures 28755.8 cpu seconds This process generated 498 decoys from 498 attempts

DONE :: 1115 starting structures 28784 cpu seconds This process generated 1115 decoys from 1115 attempts

So E core performance is 54% of P core. Power use is 11%.

AenBleidd commented 1 year ago

So, maybe this is the reason E task received twice less points because for the same amount of CPU time two times less simulations were done? TBH, I don't know the way Rosetta calculates granted points.

dirspb commented 1 year ago

@davidpanderson ,

change to the CPU scheduling logic

can you point me to the specific file so I'll try to make initial change myself?

AenBleidd commented 1 year ago

https://github.com/BOINC/boinc/blob/master/client/cpu_sched.cpp

davidpanderson commented 1 year ago

Please propose a policy before changing code.

CharlieFenton commented 1 year ago

If you make this change, it needs to be user selectable, either as a separate option or associated with an existing option (such as percent of CPU time.) While laptop users will want it to reduce the temperature, many desktop users will complain if it slows down processing.

AenBleidd commented 1 year ago

More or less similar to #4663 but for Windows. I may assume, linux has the same issues with such kind of hybrid CPUs. Don't really have the answer if BOINC should care about this instead of the OS kernel