Skip to content

Instantly share code, notes, and snippets.

@dmpatel151282
Last active August 30, 2016 08:45
Show Gist options
  • Save dmpatel151282/b8d963aaeb024d48e3b7350e2cf567fe to your computer and use it in GitHub Desktop.
Save dmpatel151282/b8d963aaeb024d48e3b7350e2cf567fe to your computer and use it in GitHub Desktop.
#define _GNU_SOURCE
#include <sched.h>
Set:-
cpu_set_t mask;
CPU_ZERO(&mask);
pid_t pid = gettid(); // Thread. For pid, use getpid()
CPU_SET(1, &mask);
if(sched_setaffinity(pid, sizeof(mask), &mask) == -1) {
LOGE("set affinity failed, cpu: 1");
}
//int syscallres = syscall(__NR_sched_setaffinity, pid, sizeof(mask), &mask);
//if (syscallres)
//{
// err = errno;
// LOGE("Error in the syscall setaffinity: mask=%d=0x%x err=%d=0x%x", mask, mask, err, err);
//}
Get :-
cpu_set_t get;
CPU_ZERO(&get);
if (sched_getaffinity(0, sizeof(get), &get) == -1)
{
LOGE("warning: cound not get thread affinity, continuing...");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment