0
$\begingroup$

Rosanswers logo

Dear all,

I am tyring to run a node with a specific cpu core but have no idea how to do that.

What's more, I also want to specify the cpu core of callback functions. I know I can use asynchronous spinner to control the number of threads, but it seems there is no way to manually set which core the thread uses.

Look forward to any help!

Ziyang


Originally posted by ZiyangLI on ROS Answers with karma: 93 on 2015-02-09

Post score: 1

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

Without being able to get access to the underlying threads, I think it will be difficult (impossible) to do for individual threads, but for entire processes this should be doable using taskset and a launch-prefix (taskset is from the util-linux package on Debian/Ubuntu).

Something like launch-prefix="taskset -c 1" added to a node element in a launch file should work (I haven't tested it though). That binds the node to cpu 2.

Note that according to man/1/taskset, your user needs to have CAP_SYS_NICE.

Note also that the taskset approach is not ROS specific. The launch-prefix is ROS specific (see roslaunch/XML/node - Attributes).

Final note: the fact that you've bound task X to cpu Y does not mean that other tasks cannot be run on cpu Y, obviously.


Originally posted by gvdhoorn with karma: 86574 on 2015-02-09

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by lucasw on 2020-01-02:
taskset 1 (without the -c) worked for me in Ubuntu 18.04

Comment by gvdhoorn on 2020-01-03:
The -c option is slightly more specific and supports "list format" (which is convenient when working with a (highly) multi-core CPU):

-c, --cpu-list          display and specify cpus in list format

Without -c, taskset will also work, but doesn't support lists.

It's the same on all versions of Ubuntu afaik.

Comment by lucasw on 2020-01-03:
I tested both the list and mask cpu setting as a launch-prefix in melodic and they work https://github.com/lucasw/timer_test/blob/master/launch/timer_test.launch

$\endgroup$
0
$\begingroup$

Rosanswers logo

See also the RT-PREEMPT Wiki on the Cpuset management utility which would be helpful if you're really serious about explicitly specifying what runs on which core. It should be noted that a plain Linux Kernel and plain ROS are probably not the right toosl for the job if you're looking for short deadlines and hard real-time guarantees, however.


Originally posted by Stefan Kohlbrecher with karma: 24361 on 2015-02-09

This answer was NOT ACCEPTED on the original site

Post score: 2

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.