ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

How to bind a node to a specific cpu core?

asked 2015-02-09 00:25:39 -0500

ZiyangLI gravatar image

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

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2015-02-09 01:37:48 -0500

gvdhoorn gravatar image

updated 2015-02-09 01:46:19 -0500

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.

edit flag offensive delete link more

Comments

taskset 1 (without the -c) worked for me in Ubuntu 18.04

lucasw gravatar image lucasw  ( 2020-01-02 17:44:54 -0500 )edit
1

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.

gvdhoorn gravatar image gvdhoorn  ( 2020-01-03 06:15:47 -0500 )edit

I tested both the list and mask cpu setting as a launch-prefix in melodic and they work https://github.com/lucasw/timer_test/...

lucasw gravatar image lucasw  ( 2020-01-03 07:18:14 -0500 )edit
2

answered 2015-02-09 02:22:50 -0500

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.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-02-09 00:25:39 -0500

Seen: 5,461 times

Last updated: Feb 09 '15