Patch - Add pthread affinity for RTEMS

Joel Sherrill joel.sherrill@oarcorp.com
Fri Nov 22 14:30:00 GMT 2013


Hi

This patch follows up on the recent addition of the
RTEMS specific cpuset.h and adds GNU/Linux style
pthread affinity APIs to pthread.h.

Sebastian.. we think the guards follow your recommendations.

OK to commit?

2013-11-22  Jennifer Averett <jennifer.averett@oarcorp.com>

        * libc/include/pthread.h (pthread_attr_setaffinity_np,
        pthread_attr_getaffinity_np, pthread_setaffinity_np,
        pthread_getaffinity_np, pthread_getattr_np): Add pthread obtain
        attribute and SMP affinity methods to RTEMS for compatibility
        with GNU/Linux.
        * libc/include/sys/types.h: Add cpuset to pthread_attr_t for RTEMS.

-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel.sherrill@OARcorp.com        On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
Support Available                (256) 722-9985
-------------- next part --------------
? newlib/libc/include/sys/.types.h.swp
? newlib/libc/sys/rtems/sys/cpuset.h
Index: newlib/libc/include/pthread.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/pthread.h,v
retrieving revision 1.10
diff -u -r1.10 pthread.h
--- newlib/libc/include/pthread.h	22 Jan 2013 21:20:08 -0000	1.10
+++ newlib/libc/include/pthread.h	11 Nov 2013 19:51:02 -0000
@@ -2,7 +2,7 @@
  *
  *  Written by Joel Sherrill <joel@OARcorp.com>.
  *
- *  COPYRIGHT (c) 1989-2010.
+ *  COPYRIGHT (c) 1989-2013.
  *  On-Line Applications Research Corporation (OAR).
  *
  *  Permission to use, copy, modify, and distribute this software for any
@@ -206,6 +206,24 @@
 int	_EXFUN(pthread_attr_setguardsize,
 	(pthread_attr_t *__attr, size_t __guardsize));
 
+#if defined(__USE_GNU) && defined(__rtems__) 
+/* POSIX thread APIs beyond the POSIX standard but provided in RTEMS
+ * for compatibility with GNU/Linux.
+ */
+int	_EXFUN(pthread_attr_setaffinity_np,
+	(pthread_attr_t *__attr,size_t __cpusetsize, 
+	const cpu_set_t *__cpuset));
+int 	_EXFUN(pthread_attr_getaffinity_np,
+	(const pthread_attr_t *__attr, size_t __cpusetsize, 
+	cpu_set_t *__cpuset));
+int	_EXFUN(pthread_getattr_np,
+	(pthread_t __thread, pthread_attr_t *__attr));
+int	_EXFUN(pthread_setaffinity_np,
+	(pthread_t __id, size_t __cpusetsize, const cpu_set_t *__cpuset));
+int	_EXFUN(pthread_getaffinity_np,
+	(const pthread_t __id, size_t __cpusetsize, cpu_set_t *__cpuset));
+#endif
+
 /* Thread Creation, P1003.1c/Draft 10, p. 144 */
 
 int	_EXFUN(pthread_create,
Index: newlib/libc/include/sys/types.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/sys/types.h,v
retrieving revision 1.40
diff -u -r1.40 types.h
--- newlib/libc/include/sys/types.h	5 Jul 2013 21:46:10 -0000	1.40
+++ newlib/libc/include/sys/types.h	11 Nov 2013 19:51:02 -0000
@@ -322,6 +322,10 @@
 #define PTHREAD_CREATE_DETACHED 0
 #define PTHREAD_CREATE_JOINABLE  1
 
+#if defined(__rtems__)
+  #include <sys/cpuset.h>
+#endif
+
 #if defined(__XMK__)
 typedef struct pthread_attr_s {
   int contentionscope;
@@ -342,16 +346,16 @@
   int inheritsched;
   int schedpolicy;
   struct sched_param schedparam;
-#if defined(__rtems__)
-  size_t guardsize;
-#endif
 
   /* P1003.4b/D8, p. 54 adds cputime_clock_allowed attribute.  */
 #if defined(_POSIX_THREAD_CPUTIME)
   int  cputime_clock_allowed;  /* see time.h */
 #endif
   int  detachstate;
-
+#if defined(__rtems__) 
+  size_t guardsize;
+  cpu_set_t affinity;
+#endif
 } pthread_attr_t;
 
 #endif /* !defined(__XMK__) */


More information about the Newlib mailing list