Last active
August 30, 2016 08:45
-
-
Save dmpatel151282/b8d963aaeb024d48e3b7350e2cf567fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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