Jump to content

[Odroid HC2] Assign apps to always use certain cpu cores


trohn_javolta

Recommended Posts

I learned that the cpu on my hc2 has 4 'slow' cores and 4 fast ones. Now I would want certain apps to always use the fast cores.

I found `taskset` to do so. My idea was to just add `taskset --cpu-list 4,5,6,7` in the .service file of the desired app in the execstart line in front. To have it always use the big cores. Would this work?

 

Also I have apps 'calling' unrar to extract files. I don't know how I would do it in this case. I think it'll be a bit complicated to tell the apps to call unrar with `taskset --cpu-list 4,5,6,7`. 

Is there a way to have unrar always run on the big cores?

Link to comment
Share on other sites

4 minutes ago, trohn_javolta said:

My idea was to just add `taskset --cpu-list 4,5,6,7` in the .service file of the desired app in the execstart line in front. To have it always use the big cores. Would this work?

For working with systemd services there is a builtin CPU selection support: https://www.freedesktop.org/software/systemd/man/systemd.exec.html#CPUAffinity=

 

5 minutes ago, trohn_javolta said:

Also I have apps 'calling' unrar to extract files. I don't know how I would do it in this case. I think it'll be a bit complicated to tell the apps to call unrar with `taskset --cpu-list 4,5,6,7`. 

Is there a way to have unrar always run on the big cores?

You can call a custom shell/bash script instead that will call taskset and pass all other arguments to unrar. You can even call this custom script "unrar" and put it somewhere in $PATH before the "real" unrar so all applications use it (you'll have to call the "real" unrar from your script by the absolute path and ensure that all apps have correct $PATH value)

Link to comment
Share on other sites

16 hours ago, zador.blood.stained said:

For working with systemd services there is a builtin CPU selection support: https://www.freedesktop.org/software/systemd/man/systemd.exec.html#CPUAffinity=

Thx, I didn't even think about that.

I also have one service in /etc/init.d/, I think that's sysvinit. Is there something like this also for sysvinit you know of?.. I tried googling it but didn't find anything. (

 

17 hours ago, zador.blood.stained said:

You can call a custom shell/bash script instead that will call taskset and pass all other arguments to unrar. You can even call this custom script "unrar" and put it somewhere in $PATH before the "real" unrar so all applications use it (you'll have to call the "real" unrar from your script by the absolute path and ensure that all apps have correct $PATH value)

Don't know if I understood that. I noticed that in my apps I can specify the path to unrar. 

My idea is to change it to a script: `/path/to/unrar_bigcores.sh`

 

And in the script just put:

#!/bin/bash

taskset --cpu-list 4,5,6,7 /usr/bin/unrar

But I don't know what the apps will do with this. I guess they somehow have to add the archive to extract and the location to that unrar path..

Link to comment
Share on other sites

2 hours ago, trohn_javolta said:

I also have one service in /etc/init.d/, I think that's sysvinit. Is there something like this also for sysvinit you know of?.. I tried googling it but didn't find anything. (

systemd creates "temporary" services for sysvinit scripts, so /etc/init.d/foo will be executed by foo.service, and you could add overrides for it in /etc/systemd/foo.service.d/*.conf files: https://wiki.archlinux.org/index.php/systemd#Drop-in_files

 

2 hours ago, trohn_javolta said:

But I don't know what the apps will do with this.

You should change the script to

#!/bin/bash

taskset --cpu-list 4,5,6,7 /usr/bin/unrar "$@"

so command line arguments are passed to unrar

Link to comment
Share on other sites

:unsure: I can't get it to work in service files.

I just added this at the bottom for testing:

[Manager]

CPUAffinity= 1 2 3

then systemctl daemon-reload

restart the process and look up the pid.

 

Then with ps -o pid,psr,comm -p PID check it. But here I see a different core assigned then 1,2 or 3.

 

I also tried creating /etc/systemd/system/unit.d and create a .conf file in it with just the manager part, also didn't work.

I don't know what I'm doing wrong.

Starting the app from console with taskset works.

Link to comment
Share on other sites

58 minutes ago, trohn_javolta said:

:unsure: I can't get it to work in service files.

 

It should be added in the [Service] section

Quote

The execution specific configuration options are configured in the [Service], [Socket], [Mount], or [Swap] sections, depending on the unit type.

 

[Manager] section is related to /etc/systemd/system.conf - you can apply system-wide default CPU affinity for all processes (unless they or individual units override it)

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines