pthread affinity patch - v2

Joel Sherrill joel.sherrill@oarcorp.com
Fri Nov 29 15:48:00 GMT 2013


Same ChangeLog with date the changed.

Patch adjusted per request. And I undid the move of the
guardsize. Something bothered me about moving an element
even though we are a "compile from source everytime" sort
of project.

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

        * libc/include/pthread.h (pthread_attr_setaffinity_np):
        Add pthread SMP affinity attributes to methods to RTEMS for
        compatibility with GNU/Linux.
        (pthread_attr_getaffinity_np): Likewise.
        (pthread_setaffinity_np): Likewise.
        (pthread_getaffinity_np): Likewise.
        (pthread_getattr_np): Add for GNU/Linux compatibility.
        * libc/include/sys/types.h: Add cpuset to pthread_attr_t for RTEMS.
        * libc/include/sys/cdefs.h (_GNU_SOURCE): Defining _GNU_SOURCE
        turns on all _XXX_VISBLE feature flags.


On 11/28/2013 4:21 AM, Corinna Vinschen wrote:
> Hi Joel,
> 
> On Nov 27 14:14, Joel Sherrill wrote:
>> Hi
>>
>> I hope this addresses all questions and concerns. There
>> has been a lot of email. :)
>>
>> OK to commit?
> 
> Sorry, but...
> 
>> Index: newlib/libc/include/sys/cdefs.h
>> ===================================================================
>> RCS file: /cvs/src/src/newlib/libc/include/sys/cdefs.h,v
>> retrieving revision 1.7
>> diff -u -r1.7 cdefs.h
>> --- newlib/libc/include/sys/cdefs.h	12 Sep 2013 22:05:43 -0000	1.7
>> +++ newlib/libc/include/sys/cdefs.h	27 Nov 2013 19:28:00 -0000
>> @@ -158,6 +158,18 @@
>>  #endif /* __GNUC__ || __INTEL_COMPILER */
>>  
>>  /*
>> + * If an application defines _GNU_SOURCE, then GNU extensions
>> + * and all features are enabled.
>> + */
>> +#ifdef  _GNU_SOURCE
>> +#define __POSIX_VISIBLE         200809
>> +#define __XSI_VISIBLE           700
>> +#define __BSD_VISIBLE           1
>> +#define __ISO_C_VISIBLE         2011
>> +#define __GNU_VISIBLE           1
>> +#endif
>> +
>> +/*
>>   * The __CONCAT macro is used to concatenate parts of symbol names, e.g.
>>   * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
>>   * The __CONCAT macro is a bit tricky to use if it must work in non-ANSI
> 
> This block comes *much* too early in sys/cdefs.h.  The visibility
> stuff starts at about line 586 (including the longish comments).
> Just for lucidity it need to be moved down to its siblings.
> 
> Suggestion:
> 
> Index: libc/include/sys/cdefs.h
> ===================================================================
> RCS file: /cvs/src/src/newlib/libc/include/sys/cdefs.h,v
> retrieving revision 1.7
> diff -u -p -r1.7 cdefs.h
> --- libc/include/sys/cdefs.h	12 Sep 2013 22:05:43 -0000	1.7
> +++ libc/include/sys/cdefs.h	28 Nov 2013 10:20:14 -0000
> @@ -693,7 +693,13 @@
>  #define	__XSI_VISIBLE		0
>  #define	__BSD_VISIBLE		0
>  #define	__ISO_C_VISIBLE		2011
> -#else				/* Default environment: show everything. */
> +#elif defined(_GNU_SOURCE)	/* Everything and the kitchen sink. */
> +#define	__POSIX_VISIBLE         200809
> +#define	__XSI_VISIBLE           700
> +#define	__BSD_VISIBLE           1
> +#define	__ISO_C_VISIBLE         2011
> +#define	__GNU_VISIBLE           1kj
> +#else				/* Default: everything except __GNU_VISIBLE. */
>  #define	__POSIX_VISIBLE		200809
>  #define	__XSI_VISIBLE		700
>  #define	__BSD_VISIBLE		1
> 
> With this change (or similar) the patch is good to go.
> 
> 
> Thanks,
> Corinna
> 



-- 
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/cscope.out
? newlib/libc/libc.info
? newlib/libm/libm.info
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	29 Nov 2013 14:54:21 -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
@@ -32,6 +32,7 @@
 #include <sys/types.h>
 #include <time.h>
 #include <sys/sched.h>
+#include <sys/cdefs.h>
 
 /* Register Fork Handlers */
 int	_EXFUN(pthread_atfork,(void (*prepare)(void), void (*parent)(void),
@@ -206,6 +207,29 @@
 int	_EXFUN(pthread_attr_setguardsize,
 	(pthread_attr_t *__attr, size_t __guardsize));
 
+/* POSIX thread APIs beyond the POSIX standard but provided 
+ * in GNU/Linux. They may be provided by other OSes for
+ * compatibility.
+ */
+#if defined(__GNU_VISIBLE)
+#if defined(__rtems__) 
+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_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));
+
+int	_EXFUN(pthread_getattr_np,
+	(pthread_t __id, pthread_attr_t *__attr));
+#endif /* defined(__rtems__) */
+#endif /* defined(__GNU_VISIBLE) */
+
 /* Thread Creation, P1003.1c/Draft 10, p. 144 */
 
 int	_EXFUN(pthread_create,
Index: newlib/libc/include/sys/cdefs.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/sys/cdefs.h,v
retrieving revision 1.7
diff -u -r1.7 cdefs.h
--- newlib/libc/include/sys/cdefs.h	12 Sep 2013 22:05:43 -0000	1.7
+++ newlib/libc/include/sys/cdefs.h	29 Nov 2013 14:54:21 -0000
@@ -693,7 +693,13 @@
 #define	__XSI_VISIBLE		0
 #define	__BSD_VISIBLE		0
 #define	__ISO_C_VISIBLE		2011
-#else				/* Default environment: show everything. */
+#elif defined(_GNU_SOURCE)	/* Everything and the kitchen sink. */
+#define	__POSIX_VISIBLE		200809
+#define	__XSI_VISIBLE		700
+#define	__BSD_VISIBLE		1
+#define	__ISO_C_VISIBLE		2011
+#define	__GNU_VISIBLE		1
+#else				/* Default: everything except __GNU_VISIBLE. */
 #define	__POSIX_VISIBLE		200809
 #define	__XSI_VISIBLE		700
 #define	__BSD_VISIBLE		1
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	29 Nov 2013 14:54:21 -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;
@@ -351,7 +355,11 @@
   int  cputime_clock_allowed;  /* see time.h */
 #endif
   int  detachstate;
-
+#if defined(__rtems__)
+  size_t affinitysetsize;
+  cpu_set_t *affinityset;
+  cpu_set_t affinitysetpreallocated;
+#endif
 } pthread_attr_t;
 
 #endif /* !defined(__XMK__) */


More information about the Newlib mailing list