Home > pthread setaffinity np error > pthread_setaffinity_np error

Pthread_setaffinity_np Error

Contents

size_t cpusetsize, const cpu_set_t *cpuset);int pthread_getaffinity_np(pthread_t thread, size_t cpusetsize, cpu_set_t *cpuset); Compile and link with -pthread. Description The pthread_setaffinity_np() function sets the CPU affinity mask of the thread thread to the CPU set pointed to by cpuset. If the call is pthread_setaffinity_np vs sched_setaffinity successful, and the thread is not currently running on one of the CPUs cpu_set_t in cpuset, then it is migrated to one of those CPUs. The pthread_getaffinity_np() function returns the CPU affinity mask of

Pthread_setaffinity Example

the thread thread in the buffer pointed to by cpuset. For more details on CPU affinity masks, see sched_setaffinity(2). For a description of a set of macros that can be used to manipulate

Cpu_zero

and inspect CPU sets, see cpu_set(3). The argument cpusetsize is the length (in bytes) of the buffer pointed to by cpuset. Typically, this argument would be specified as sizeof(cpu_set_t). (It may be some other value, if using the macros described in cpu_set(3) for dynamically allocating a CPU set.) Return Value On success, these functions return 0; on error, they return a nonzero error number. Errors pthread_attr_setaffinity_np example EFAULT A supplied memory address was invalid. EINVAL (pthread_setaffinity_np()) The affinity bit mask mask contains no processors that are currently physically on the system and permitted to the thread according to any restrictions that may be imposed by the "cpuset" mechanism described in cpuset(7). EINVAL (pthread_setaffinity_np()) cpuset specified a CPU that was outside the set supported by the kernel. (The kernel configuration option CONFIG_NR_CPUS defines the range of the set supported by the kernel data type used to represent CPU sets.) EINVAL (pthread_getaffinity_np()) cpusetsize is smaller than the size of the affinity mask used by the kernel. ESRCH No thread with the ID thread could be found. Versions These functions are provided by glibc since version 2.3.4. Conforming to These functions are nonstandard GNU extensions; hence the suffix "_np" (nonportable) in the names. Notes After a call to pthread_setaffinity_np(), the set of CPUs on which the thread will actually run is the intersection of the set specified in the cpuset argument and the set of CPUs actually present on the system. The system may further restrict the set of CPUs on which the thread runs if the "cpuset" mechanism described in cpuset(7) is being used.

here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About

Pthread_setaffinity_np Android

Us Learn more about Stack Overflow the company Business Learn more about hiring cpu_set example developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the sched_setaffinity example Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up CPU Affinity Masks (Putting Threads on https://linux.die.net/man/3/pthread_setaffinity_np different CPUs) up vote 10 down vote favorite 5 I have 4 threads, and I am trying to set thread 1 to run on CPU 1, thread 2 on CPU 2, etc. However, when I run my code below, the affinity masks are returning the correct values, but when I do a sched_getcpu() on the threads, they all return that they are running on CPU 4. Anybody http://stackoverflow.com/questions/2563442/cpu-affinity-masks-putting-threads-on-different-cpus know what my problem here is? Thanks in advance! #define _GNU_SOURCE #include #include #include #include #include void *pthread_Message(char *message) { printf("%s is running on CPU %d\n", message, sched_getcpu()); } int main() { pthread_t thread1, thread2, thread3, thread4; pthread_t threadArray[4]; cpu_set_t cpu1, cpu2, cpu3, cpu4; char *thread1Msg = "Thread 1"; char *thread2Msg = "Thread 2"; char *thread3Msg = "Thread 3"; char *thread4Msg = "Thread 4"; int thread1Create, thread2Create, thread3Create, thread4Create, i, temp; CPU_ZERO(&cpu1); CPU_SET(1, &cpu1); temp = pthread_setaffinity_np(thread1, sizeof(cpu_set_t), &cpu1); printf("Set returned by pthread_getaffinity_np() contained:\n"); for (i = 0; i < CPU_SETSIZE; i++) if (CPU_ISSET(i, &cpu1)) printf("CPU1: CPU %d\n", i); CPU_ZERO(&cpu2); CPU_SET(2, &cpu2); temp = pthread_setaffinity_np(thread2, sizeof(cpu_set_t), &cpu2); for (i = 0; i < CPU_SETSIZE; i++) if (CPU_ISSET(i, &cpu2)) printf("CPU2: CPU %d\n", i); CPU_ZERO(&cpu3); CPU_SET(3, &cpu3); temp = pthread_setaffinity_np(thread3, sizeof(cpu_set_t), &cpu3); for (i = 0; i < CPU_SETSIZE; i++) if (CPU_ISSET(i, &cpu3)) printf("CPU3: CPU %d\n", i); CPU_ZERO(&cpu4); CPU_SET(4, &cpu4); temp = pthread_setaffinity_np(thread4, sizeof(cpu_set_t), &cpu4); for (i = 0; i < CPU_SETSIZE; i++) if (CPU_ISSET(i, &cpu4)) printf("CPU4: CPU %d\n", i); thread1Create = pthread_create(&thread1, NULL, (void *)pthread_Message, thread1Msg); thread2Create = pthread_create(&thread2, NULL, (void *)pthread_Message, thread2Msg); thread3Create = pthread_create(&thread3, NULL, (void *)pthread_Message, thread3Msg); thread4Create = pthread_cre

Bug #519 fix pthread_setaffinity_np error https://charm.cs.illinois.edu/redmine/issues/519 handling Added by Jim Phillips over 2 years ago. Updated over 2 years ago. Status:ClosedStart date:06/13/2014Priority:HighDue date:Assignee:Phil Miller% Done:0%Category:machine layersEstimated time:1.00 hourTarget version:6.6.0Spent time:- Description Since bug 501 is delayed to 6.0.1 I've broken out this fix to pthread_setaffinity_np() error pthread_setaffinity_np error handling. The old code assumed that pthread_setaffinity_np() set errno and returned 0 or -1 like setaffinity, but it actually returns the full error code. This patch (emailed to core) sets errno to the return value of pthread_setaffinity_np() so that perror() works. pthread_setaffinity_np vs sched_setaffinity thread_affinity_errno.patch (1.46 KB) Jim Phillips, 06/13/2014 10:45 am History #1 Updated by Phil Miller over 2 years ago Assignee set to Phil Miller Patch looks good, applying. Thanks #2 Updated by Phil Miller over 2 years ago Status changed from New to Implemented Jim: for future issues for which you have a patch prepared, feel free to submit them directly to Gerrit. We're not going to be strict about an open issue for every change to the codebase. #3 Updated by Phil Miller over 2 years ago Status changed from Implemented to Merged #4 Updated by Phil Miller over 2 years ago Status changed from Merged to Closed Also available in: Atom PDF Loading... Powered by Redmine © 2006-2013 Jean-Philippe Lang

 

Related content

pthread_setaffinity_np error 22

Pthread setaffinity np Error table id toc tbody tr td div id toctitle Contents div ul li a href Pthread setaffinity np Vs Sched setaffinity a li li a href Cpu set t a li li a href Set Affinity Linux Example a li li a href Pthread attr setaffinity np Example a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this relatedl site About Us Learn more about Stack Overflow the company Business p h