Setting “task affinity” programmatically

You cannot. taskAffinity is contained by ActivityInfo, which is member of Activity. Source code of Activity public class Activity extends ContextThemeWrapper … … { // set by the thread after the constructor and before // onCreate(Bundle savedInstanceState) is called. @UnsupportedAppUsage /*package*/ ActivityInfo mActivityInfo; } And ActivityInfo has taskAffinity. Source code of ActivityInfo /** * Information …

Read more

How to set CPU affinity for a process from C or C++ in Linux?

You need to use sched_setaffinity(2). For example, to run on CPUs 0 and 2 only: #define _GNU_SOURCE #include <sched.h> cpu_set_t mask; CPU_ZERO(&mask); CPU_SET(0, &mask); CPU_SET(2, &mask); int result = sched_setaffinity(0, sizeof(mask), &mask); (0 for the first parameter means the current process, supply a PID if it’s some other process you want to control). See also …

Read more

Taskset not working over a range of cores in isolcpus

After a day of frustration I’ve determined a solution. This behavior seems to be an artifact of the default kernel scheduler algorithm (SCHED_OTHER for this distro/kernel). Changing the process to a different algorithm eliminates the problem, isolcpus are adequately utilized across the processes/threads. I ended up using SCHED_RR, but I also tested SCHED_FIFO and SCHED_IDLE …

Read more