Page 1 of 1

Setting affinity to maximize efficiency on an AMD cpu with Linux: a "case of study"

Posted: Thu Feb 05, 2026 2:13 am
by Lem
I happen to fold on a system with and AMD 7950x and two discrete GPUs. My monitor is attached to my iGPU. My OS is Ubuntu Mate 25.10.

Ryzen 7950x has two CCDs, that is two groups of 8 cores (16 virtual cores) each.
Usually one CCD can run faster than the other: in my system I set CCD0 to run at 5,3GHz max, under load, and CCD1 to run at max 4.8 GHz, under load. I know: I could have done better, findind the max ceiling for every core: however that would have required much more time of testing and fine tuning, which I don't have, so this compromise is good enough for me, at least for now.

Virtual cores 0-7 and 16-23 belong to CCD0, the fast one, whereas core 8-15 and 24-31 belong to CCD1 (the slow one).

Since I wanna fold both on my GPUs and CPU, I've followed this rules:

1) leave some slow virtual cores free to the system, but link the f@h processes feeding the GPUs (usually one for GPU, so 2 in my situation) to this cores. At the end, I left 4 cores free: two of them are used to feed the GPUs, and two are actually free;

2) never let the OS scheduler to spread processes belonging to the same WU to different CCDs: to reduce the use of the Infinity Fabric link, to optimize the use of caches, to give same speed cores to every WU;

3) since CPU folding is based on GROMACS, prefer resource groups made of a multiple of 4, or 6, or 8 cores to let it comfortably spread the work among them.

What did I do?

I created four resouce groups: one for each GPU (with no CPU cores); one made of 16 virtual CPU cores; one of 8 CPU cores.

Then I created a bash script to set the affinity of the meaningful processes to the cores. Since I use to crunch a bit on BOINC, too, I also linked BOINC processes to 4 slow cores. To be clear: the resource group made of 16 cores has been linked to the 16 fast virtual cores, the resource group made of 8 cores has been linked to the 8 slow virtual cores, the BOINC processes to other 4 slow cores, and the (usually 2) f@h processes feeding my 2 GPUs to the remaining 4 slow cores.

Here is the script:

Code: Select all

#!/bin/bash

export SET_FAH_16="0-7,16-23"
export SET_FAH_8="8-11,24-27"
export SET_BOINC="12-13,28-29"
export SET_GPU_SYS="14-15,30-31"

while true; do
    # 1. MANAGING FOLDING@HOME CPU (FahCore_a8)
    pgrep -f "FahCore_a8" | while read -r pid; do
        [ -z "$pid" ] && continue
        threads=$(ps -o nlwp= -p "$pid" | tr -d ' ')
        
        if [ "$threads" -gt 15 ]; then
            taskset -acp "$SET_FAH_16" "$pid" >/dev/null 2>&1
        elif [ "$threads" -gt 6 ] && [ "$threads" -le 14 ]; then
            taskset -acp "$SET_FAH_8" "$pid" >/dev/null 2>&1
        fi
    done

    # 2. MANAGING BOINC 
    pgrep -u boinc | xargs -r -I % taskset -acp "$SET_BOINC" % >/dev/null 2>&1

    # 3. MANAGING FOLDING@HOME GPUs (FahCore_2*)
    pgrep -f "FahCore_2" | xargs -r -I % taskset -acp "$SET_GPU_SYS" % >/dev/null 2>&1

    sleep 60
done
I saved this file as /usr/local/bin/fah-affinity.sh and gave it x permission.

it's possible to run it with cron every minute (omitting the "sleep 60" command), but i chose to run it as a service.

I created the file /etc/systemd/system/fah-affinity.service with this inside:

Code: Select all

[Unit]
Description=F@H and BOINC affinity manager
After=network.target

[Service]
Type=simple
# Run as root to manage PIDs
ExecStart=/usr/local/bin/fah-affinity.sh
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

Then I enabled and started the service:

Code: Select all

$ sudo systemctl daemon-reload && sudo systemctl enable fah-affinity.service && sudo systemctl start fah-affinity.service
This above surely cannot harm the folding, and it seems to me that can help to maximize efficiency and folding productivity.

Of course I post this stuff only as a hint, and everybody should eventually configure it according to his/her hardware, system and preferences. HTH.
--
Bye, Lem

Re: Setting affinity to maximize efficiency on an AMD cpu with Linux: a "case of study"

Posted: Thu Feb 05, 2026 5:36 am
by muziqaz
And where are the results of all that?

Re: Setting affinity to maximize efficiency on an AMD cpu with Linux: a "case of study"

Posted: Thu Feb 05, 2026 9:16 am
by Lem
muziqaz wrote: Thu Feb 05, 2026 5:36 am And where are the results of all that?
I don't know any exact way to measure neither performances nor efficiency with f@h, so I don't have any exact result to show. And we aren't speaking of huge gains, just fine tuning. Looking at my PPDs, I smell it's helped a bit though: I mean a few percent.

I'm happy with this setting: it cannot degrade performances, logically it should help a bit instead, it's simple... so why not?

However I don't want to convince anybody. You don't like it, don't even try. Otherwise, maybe just for fun, give it a try and judge by yourself. Peace.
--
Bye, Lem

Re: Setting affinity to maximize efficiency on an AMD cpu with Linux: a "case of study"

Posted: Thu Feb 05, 2026 9:34 am
by muziqaz
Few percent is margin of error. Not worth potentially messing up stability.
It is always advised to leave things as they are and let Linux scheduler do it's job. Especially when you are doing mission critical workloads. I am certain the people who maintain the scheduler side of things have much better expertise of what is optimised or not.

Re: Setting affinity to maximize efficiency on an AMD cpu with Linux: a "case of study"

Posted: Thu Feb 05, 2026 11:49 am
by Lem
muziqaz wrote: Thu Feb 05, 2026 9:34 am Few percent is margin of error. Not worth potentially messing up stability.
No chance to mess up stability at all.
It is always advised to leave things as they are and let Linux scheduler do it's job. Especially when you are doing mission critical workloads.
BTW: in which sense f@h or BOINC on your or on my rig would be mission critical? Are you kidding?
I am certain the people who maintain the scheduler side of things have much better expertise of what is optimised or not.
Of course they know their business: but, just as an example, they do NOT take into account the different core frequencies of my CPU. How could they? And so on.

And, for instance, you can choose among different schedulers, there'no one and only optimum. If your choice is awfully wrong, you can even end up freezing your system, and with a mainline sheduler. So no guarantee coming from only using the bare scheduler.

And taskset command? Why does it exist and what is it good for, then? People who wrote it were not a bunch of fools.

Others are the dangerous things: for example, if you mess badly with priority and niceness of f@h processes. Which I don't advise.

But what I wrote is totally safe. And I mean totally.
--
Bye, Lem

Re: Setting affinity to maximize efficiency on an AMD cpu with Linux: a "case of study"

Posted: Thu Feb 05, 2026 2:24 pm
by muziqaz
Scientific simulation, if failed, wastes everyone's time. That is mission critical. First thing I care is returned science and stability. I don't want random users coming back to this forum with problems, and then we find out they installed someone's suggested script to "improve" things.
You scripting something does not mean it is good for everyone.
And don't think for a minute that if there is a tool for something, that you or anyone else will be better off using it.
And lastly, when you name your thread as "case study" and suggest people fiddle with affinity and process priority settings, please provide hard evidence and numbers backing your case study. Observing some random projects and determining that there is a benefit to do things you suggest, that is not how case studies work.
Ideally you would need:
Before the application:
P111111 produces these frame times on these many cores
P222222 produces these frame times on these many cores

After application:
P111111 produces these frame times on these many cores
P222222 produces these frame times on these many cores

Re: Setting affinity to maximize efficiency on an AMD cpu with Linux: a "case of study"

Posted: Thu Feb 05, 2026 3:27 pm
by Lem
muziqaz wrote: Thu Feb 05, 2026 2:24 pm Scientific simulation, if failed, wastes everyone's time. That is mission critical. First thing I care is returned science and stability. I don't want random users coming back to this forum with problems, and then we find out they installed someone's suggested script to "improve" things.
You care, you don't want... Maybe I'm missing something: who are you, sir?

From what you're writing, seems to me that you likely do not even understand how distributed computing works.
You scripting something does not mean it is good for everyone.
Everyone can think and decide for himself. Here are only you, wanting to decide what's good and bad even for everyone else.
And lastly, when you name your thread as "case study" and suggest people fiddle with affinity and process priority settings
I suggested WHAT? WHAT? Can you please read, at least, before making things up from scratch?
Ideally you would need:
Before the application:
P111111 produces these frame times on these many cores
P222222 produces these frame times on these many cores

After application:
P111111 produces these frame times on these many cores
P222222 produces these frame times on these many cores
If it's possible to measure exactly so little improvements (you wrote about error margins, before), I'm personally not interested in doing it. And above all there's no need to do it.

Moreover: if you don't understand that what I've written (not suggested, nor even proposed) is totally safe, why do you feel nonetheless the need to write nonsense about it? Don't run a script like that, who cares? Who cares if nobody runs something alike?
I run my script, 'cause I do whatever I like on my system. If someone else find it interesting, and thinks about it, fine. Nobody? Fine again.

Farewell.
--
Bye, Lem

Re: Setting affinity to maximize efficiency on an AMD cpu with Linux: a "case of study"

Posted: Thu Feb 05, 2026 4:13 pm
by muziqaz
Dude, so you come here with the case study and the script and tell us that it will help us improve something, trust me bro?

I would hint to you to Google what is "Case Study"

Re: Setting affinity to maximize efficiency on an AMD cpu with Linux: a "case of study"

Posted: Thu Feb 05, 2026 7:07 pm
by toTOW
Where are the time per frame and PPD values from each test cases, taken from the same projects ? These are the only values we trust to measure FAH performance.

Re: Setting affinity to maximize efficiency on an AMD cpu with Linux: a "case of study"

Posted: Thu Feb 05, 2026 11:47 pm
by Lem
muziqaz wrote: Thu Feb 05, 2026 4:13 pm I would hint to you to Google what is "Case Study"
I would hint to you to google what quotation marks are.
--
Bye, Lem

Re: Setting affinity to maximize efficiency on an AMD cpu with Linux: a "case of study"

Posted: Fri Feb 06, 2026 12:09 am
by Lem
toTOW wrote: Thu Feb 05, 2026 7:07 pm Where are the time per frame and PPD values from each test cases, taken from the same projects ? These are the only values we trust to measure FAH performance.
BTW: you said "we". We? We who? Who are you? Is it something like a clan? Are you used to speak for others, and do they agree?

"The same project" means nothing, in this case. So I don't even bother. You want meaningless numbers? Try yourself. Or not. As I said from the first article, I don't care: I don't want you to do anything. And I dont' want anybody to run my exact script. Anybody. Can you understand? Or I can spell it for you: a-n-y-b-o-d-y.

I think I've had enough of this amusement. Go entertain someone else, please.
--
Bye, Lem

Re: Setting affinity to maximize efficiency on an AMD cpu with Linux: a "case of study"

Posted: Fri Feb 06, 2026 1:17 am
by Joe_H
Lem wrote: Fri Feb 06, 2026 12:09 am BTW: you said "we". We? We who? Who are you? Is it something like a clan? Are you used to speak for others, and do they agree?
Who they are, members of the internal testing group who have been working with the researchers and developers for many years. Considering what goes on before you ever see projects released, they know quite a few people involved and the processes they go through.

What you have posted is not a "case study". At best you have posted some kluges you think necessary to make up for a poor cooling solution in your system that leaves one CCD not as well called as the other and unable to run at as high a clock rate. No before and after testing, no data to back up your assertions. And you do need to to compare WUs from the same project to get a good idea whether it helps or not as different projects will get different PPD results.

Oh, and I and I assume others don't find you amusing.

Re: Setting affinity to maximize efficiency on an AMD cpu with Linux: a "case of study"

Posted: Fri Feb 06, 2026 2:37 am
by Lem
Joe_H wrote: Fri Feb 06, 2026 1:17 am At best you have posted some kluges you think necessary
Necessary? I've never ever written anything about necessity.
to make up for a poor cooling solution in your system that leaves one CCD not as well called as the other and unable to run at as high a clock rate.
LOL. Don't you know anything about overclocking and undervolting, do you? Neither about AMD Ryzen CPUs, right? And do you pretend to know my system better than me? Is it a habit, here, to write just to send fingers around the keyboard? I'm impressed, actually.
No before and after testing, no data to back up your assertions.
And what were my assertions? That I smelled that script could have helped my system fold a bit more efficiently and productively. So what? What have I to prove? That I smelled it? Go figure.
And you do need to to compare WUs from the same project to get a good idea whether it helps or not as different projects will get different PPD results
No, it would be meaningless, for many reasons. I do not run only f@h on my system, for instance, and my system is always almost 100% busy.

Using affinity as I do on my system cannot harm folding. It cannot. How could it? None of you has spent a word on it.
Oh, and I and I assume others
You too feel the need to make assumptions for others. Interesting.
don't find you amusing.
I'm fine with it. I'm not fine with people writing nonsense about possible instability issues, nor with people putting unsaid things into my mouth.

I don't think it can be of any importance, anyway with my arc b580 (stock: you cannot overclock it with linux), my overclocked 5060ti and 24 of my 32 CPU cores (two groups, 16 + 8) I'm between 12+M and 14+M PPDs per day. The 16+8 CPU cores, all toghether, get about 1,5M PPDs per day. Of course every wu, even of the same project, gets a different amount of PPDs, as always.
Before the script, it seems to me that I earned a bit less PPDs. I have never seen 14+M before the script. Maybe it's a coincidence, I'm telling you.

You want PPDs, here they are. I don't think they are relevant. A script like that, tailored on the single system hardware and use, can only help folding, not damaging it or causing instability. Or prove the contrary. Or write something appropriate and sensible. Or maybe shut up.
--
Bye, Lem