The files for the proposed affinity changes to newlib are
attached. cpuset.h is added to newlib/libc/sys/rtems/sys/
and the following will be added to the change log:
3013-11-11 Jennifer Averett <jennifer.aver...@oarcorp.com>
* libc/sys/rtems/sys/cpuset.h: New file.
* libc/include/pthread.h: Add CPU afficinit and get attribute
methods which are in GNU/Linux but beyond the POSIX standard.
* libc/include/sys/types.h: Add cpu_set_t to pthread_attr_t.
Does anyone see any problems?
Jennifer Averett
On-Line Applications Research
? 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 <j...@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/signal.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/sys/signal.h,v
retrieving revision 1.22
diff -u -r1.22 signal.h
--- newlib/libc/include/sys/signal.h 26 Oct 2012 09:23:46 -0000 1.22
+++ newlib/libc/include/sys/signal.h 11 Nov 2013 19:51:02 -0000
@@ -104,6 +104,15 @@
#define sa_sigaction _signal_handlers._sigaction
#endif
+/*
+ * Structure used in sigaltstack call.
+ */
+typedef struct sigalstack {
+ void *ss_sp; /* Stack base or pointer. */
+ size_t ss_size; /* Stack size. */
+ int ss_flags; /* Flags. */
+} stack_t;
+
#elif defined(__CYGWIN__)
#include <cygwin/signal.h>
#else
@@ -161,6 +170,10 @@
int _EXFUN(sigsuspend, (const sigset_t *));
int _EXFUN(sigpause, (int));
+#if defined(__rtems__)
+int _EXFUN(sigaltstack, (const stack_t *, stack_t *));
+#endif
+
#if defined(_POSIX_THREADS)
#ifdef __CYGWIN__
# ifndef _CYGWIN_TYPES_H
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__) */
/*
* Copyright (c) 2013 On-Line Applications Research Corporation.
* All rights reserved.
*
* On-Line Applications Research Corporation
* 7047 Old Madison Pike Suite 320
* Huntsville Alabama 35806
* <i...@oarcorp.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* This file implements an API compatible with static portion of
* the GNU/Linux cpu_set_t macros but is independently implemented.
* The GNU/Linux manual page and the FreeBSD cpuset_t implementation
* were used as reference material.
*
* Not implemented:
* + Linux CPU_XXX_S
* + FreeBSD CPU_SUBSET
* + FreeBSD CPU_OVERLAP
*/
#ifndef _SYS_CPUSET_H_
#define _SYS_CPUSET_H_
#include <sys/types.h>
#include <sys/param.h>
#include <stdint.h>
/* RTEMS supports a maximum of 32 CPU cores */
#ifndef CPU_SETSIZE
#define CPU_SETSIZE 32
#endif
/* word in the cpu set */
typedef uint32_t cpu_set_word_t;
/* Number of bits per cpu_set_t element */
#define _NCPUBITS (sizeof(cpu_set_word_t) * NBBY) /* bits per mask */
/* Number of words in the cpu_set_t array */
#define _NCPUWORDS howmany(CPU_SETSIZE, _NCPUBITS)
/* Define the cpu set structure */
typedef struct _cpuset {
cpu_set_word_t __bits[_NCPUWORDS];
} cpu_set_t;
/* determine the mask for a particular cpu within the element */
static inline cpu_set_word_t __cpuset_mask( size_t cpu)
{
return ((cpu_set_word_t)1 << ((cpu) % _NCPUBITS));
}
/* determine the index for this cpu within the cpu set array */
static inline size_t __cpuset_index( size_t cpu )
{
return ((cpu)/_NCPUBITS);
}
/* zero out set */
static inline void CPU_ZERO( cpu_set_t *set )
{
size_t i;
for (i = 0; i < _NCPUWORDS; i++)
set->__bits[i] = 0;
}
/* fill set */
static inline void CPU_FILL( cpu_set_t *set )
{
size_t i;
for (i = 0; i < _NCPUWORDS; i++)
set->__bits[i] = -1;
}
/* set cpu within set */
static inline void CPU_SET( size_t cpu, cpu_set_t *set )
{
set->__bits[__cpuset_index(cpu)] |= __cpuset_mask(cpu);
}
/* clear cpu within set */
static inline void CPU_CLR( size_t cpu, cpu_set_t *set )
{
set->__bits[__cpuset_index(cpu)] &= ~__cpuset_mask(cpu);
}
/* Return 1 is cpu is set in set, 0 otherwise */
static inline int const CPU_ISSET( size_t cpu, const cpu_set_t *set )
{
return ((set->__bits[__cpuset_index(cpu)] & __cpuset_mask(cpu)) != 0);
}
/* copy src set to dest set */
static inline void CPU_COPY( cpu_set_t *dest, const cpu_set_t *src )
{
*dest = *src;
}
/* logical and: dest set = src1 set and src2 set */
static inline void CPU_AND(
cpu_set_t *dest, const cpu_set_t *src1, const cpu_set_t *src2
)
{
size_t i;
for (i = 0; i < _NCPUWORDS; i++)
dest->__bits[i] = src1->__bits[i] & src2->__bits[i];
}
/* logical or: dest set = src1 set or src2 set */
static inline void CPU_OR(
cpu_set_t *dest, const cpu_set_t *src1, const cpu_set_t *src2
)
{
size_t i;
for (i = 0; i < _NCPUWORDS; i++)
dest->__bits[i] = src1->__bits[i] | src2->__bits[i];
}
/* logical xor: dest set = src1 set xor src2 set */
static inline void CPU_XOR(
cpu_set_t *dest, const cpu_set_t *src1, const cpu_set_t *src2
)
{
size_t i;
for (i = 0; i < _NCPUWORDS; i++)
dest->__bits[i] = src1->__bits[i] ^ src2->__bits[i];
}
/* logical nand: dest set = src1 set nand src2 set */
static inline void CPU_NAND(
cpu_set_t *dest, const cpu_set_t *src1, const cpu_set_t *src2
)
{
size_t i;
for (i = 0; i < _NCPUWORDS; i++)
dest->__bits[i] = ~(src1->__bits[i] & src2->__bits[i]);
}
/* return the number of set cpus in set */
static inline int const CPU_COUNT( const cpu_set_t *set )
{
size_t i;
int count = 0;
for (i=0; i < _NCPUWORDS; i++)
if (CPU_ISSET(i, set) != 0)
count++;
return count;
}
/* return 1 if the sets set1 and set2 are equal, otherwise return 0 */
static inline int const CPU_EQUAL(
const cpu_set_t *set1, const cpu_set_t *set2
)
{
size_t i;
for (i=0; i < _NCPUWORDS; i++)
if (set1->__bits[i] != set2->__bits[i] )
return 0;
return 1;
}
/* return 1 if the sets set1 and set2 are equal, otherwise return 0 */
static inline int const CPU_CMP( const cpu_set_t *set1, const cpu_set_t *set2 )
{
return CPU_EQUAL(set1, set2);
}
/* return 1 if the set is empty, otherwise return 0 */
static inline int const CPU_EMPTY( const cpu_set_t *set )
{
size_t i;
for (i=0; i < _NCPUWORDS; i++)
if (set->__bits[i] != 0 )
return 0;
return 1;
}
#endif
_______________________________________________
rtems-devel mailing list
rtems-devel@rtems.org
http://www.rtems.org/mailman/listinfo/rtems-devel