LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 01-15-2019, 04:55 AM   #1
somanyquestions
Member
 
Registered: Jan 2019
Distribution: Ubuntu, Debian, Buildroot
Posts: 34

Rep: Reputation: Disabled
CPU affinity, support for assigning processes - What kernel settings?


On an embedded Linux system, I want to execute a process or thread thereof steadily on a specific core.

I found the API functions sched_setaffinity and pthread_setaffinity_np for that.
The manpage for sched_setaffinity references the page for cpuset, on which it is stated that: there should be a "nodev cpuset" in /proc/filesystems, if CPUSET is supported.

I have here now 2 embedded systems, one with kernel 4.1 running on a dual core iMX6, and one with kernel 3.10 (Linux4Tegra) running on a Tegra TK1 board, quad core CPU.

On both systems, the "nodev cpuset" is *not* present.
Also, their files /proc/config.gz both have CONGIG_CPUSET disabled.
But: on the kernel 4.1 system, setting my process to core1 works and has a visible effect.
On the kernel 3.10 system, sched_setaffinity produces an error, "invalid argument". Since I only masked it to use core1 in a 4-core system, that argument should not be invalid, unless something else is wrong?

Because I want to use the TK1 board (kernel version frozen to 3.10 because NVIDIA drivers), I was thinking about looking into how to compile a new Linux image with the CPUSET option enabled (using the board manufacturer's Yocto based stuff, never done that before).
But I am now doubting that this effort will yield success, as, by the above outlined seeming contradiction, my understanding of what's necessary for a Linux build to support the assigning of CPU affinities must be wrong.

Can someone tell me how it really is, exactly?


Background:
Say I have a program on an embedded Linux system with an ARM dual core processor, which does some comparably heavy data shoveling, receiving a lot of UDP packets. To prevent CPU core0 from ever maxing out on peaks and thus losing packets, I'd like to move my system calls (mainly just recv(socketFd...) )to core1, so core0 will be doing whatever the system does anyway when UDP packets arrive, and core1 takes care of the rest. And then for quad core, further processing gets done on cores2+3, such the first two will be stable.
 
Old 01-15-2019, 04:00 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,099

Rep: Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117
You're on the right horse, just that you picked a pretty old nag ....

cpusets is the right idea, but is the original incarnation, and has long since disappeared into history. The current implementation is cgroups "control groups" which implement and extend the same concepts, but at a higher (easier to manage) abstraction. You mount a sysfs and create a group for yourself with CPU(s) and memory limits if needed, then drop your tasks into it. Everything else runs elsewhere - that's how I isolate my monitoring tasks when running benchmarks on his old i7 laptop.
Should be available on old kernels like yours, but not sure about ARM - some kernel tracing I tried hadn't been ported when I tried it on a pi3. Check your config for "cgroup" - there's a bunch of them; doesn't seem to be an obvious dependancy on cpusets, so you might get lucky.
cgroups are (tersely) documented in the source tree, and there must be tuts/blogs out there too.
 
Old 01-16-2019, 03:34 AM   #3
somanyquestions
Member
 
Registered: Jan 2019
Distribution: Ubuntu, Debian, Buildroot
Posts: 34

Original Poster
Rep: Reputation: Disabled
So what does sched_setaffinity(...) use behind the scenes on newer systems, does it use the cgroups stuff and it's just for keeping the interface that you pass a "cpu_set_t" struct to it (or is the naming just misleading and it had never anything to do with it)?

For the record, my particular issue of why it didn't work was because of "CPU hot plugging", a Linux feature I was unaware of, and is apparently not enabled on the board where it did just work. So CPU cores besides core0 were disabled by default on that particular Linux image, apparently for power saving reasons. They had to be enabled by writing a "1" into their /sys/devices/system/cpu/cpuX/online file, where X=1...3 on my 4-core system where cpu0 is the one active at start.

Last edited by somanyquestions; 01-17-2019 at 09:21 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
CPU affinity, support for assigning processes - What kernel settings? somanyquestions Linux - Kernel 1 01-15-2019 02:09 PM
assigning value with read command vs assigning value with = sign bubai70 Linux - Server 1 12-11-2017 10:47 PM
LXer: How to Change CPU Affinity of CPU Intensive Multithreaded Applications (Ubuntu) LXer Syndicated Linux News 0 12-10-2012 12:10 PM
CPU binding - How to modify the CPU affinity mask? Thaidog Linux - General 1 03-15-2008 05:54 PM
CPU affinity on kernel 2.4.14-SMP tsik Linux - Kernel 0 11-05-2007 09:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 02:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration