From f4ce641b374a20b650c31f60d03424d21d7fcbdf Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Wed, 26 Sep 2018 09:43:51 -0500 Subject: Add various programs to report default attributes for various POSIX objects Closes #3531. --- posix_api/Makefile | 11 +- posix_api/psx_barrier_report/Makefile | 20 +++ posix_api/psx_barrier_report/barrier_attr_report.c | 58 ++++++++ posix_api/psx_barrier_report/rtems_config.c | 48 +++++++ posix_api/psx_barrier_report/wscript | 15 ++ posix_api/psx_condvar_report/Makefile | 20 +++ posix_api/psx_condvar_report/condvar_attr_report.c | 69 +++++++++ posix_api/psx_condvar_report/rtems_config.c | 48 +++++++ posix_api/psx_condvar_report/wscript | 15 ++ posix_api/psx_mqueue_report/Makefile | 20 +++ posix_api/psx_mqueue_report/mqueue_attr_report.c | 48 +++++++ posix_api/psx_mqueue_report/rtems_config.c | 48 +++++++ posix_api/psx_mqueue_report/wscript | 15 ++ posix_api/psx_mutex_report/Makefile | 20 +++ posix_api/psx_mutex_report/mutex_attr_report.c | 131 ++++++++++++++++++ posix_api/psx_mutex_report/rtems_config.c | 49 +++++++ posix_api/psx_mutex_report/wscript | 15 ++ posix_api/psx_pthread_report/Makefile | 20 +++ posix_api/psx_pthread_report/pthread_attr_report.c | 154 +++++++++++++++++++++ posix_api/psx_pthread_report/rtems_config.c | 48 +++++++ posix_api/psx_pthread_report/wscript | 15 ++ posix_api/psx_rwlock_report/Makefile | 20 +++ posix_api/psx_rwlock_report/rtems_config.c | 48 +++++++ posix_api/psx_rwlock_report/rwlock_attr_report.c | 49 +++++++ posix_api/psx_rwlock_report/wscript | 15 ++ posix_api/psx_sched_report/Makefile | 30 +--- posix_api/psx_sched_report/psx_sched_report.c | 55 ++++++++ posix_api/psx_sched_report/rtems_config.c | 11 +- posix_api/psx_sched_report/test.c | 45 ------ posix_api/psx_sched_report/wscript | 3 +- posix_api/wscript | 7 +- 31 files changed, 1093 insertions(+), 77 deletions(-) create mode 100644 posix_api/psx_barrier_report/Makefile create mode 100644 posix_api/psx_barrier_report/barrier_attr_report.c create mode 100644 posix_api/psx_barrier_report/rtems_config.c create mode 100644 posix_api/psx_barrier_report/wscript create mode 100644 posix_api/psx_condvar_report/Makefile create mode 100644 posix_api/psx_condvar_report/condvar_attr_report.c create mode 100644 posix_api/psx_condvar_report/rtems_config.c create mode 100644 posix_api/psx_condvar_report/wscript create mode 100644 posix_api/psx_mqueue_report/Makefile create mode 100644 posix_api/psx_mqueue_report/mqueue_attr_report.c create mode 100644 posix_api/psx_mqueue_report/rtems_config.c create mode 100644 posix_api/psx_mqueue_report/wscript create mode 100644 posix_api/psx_mutex_report/Makefile create mode 100644 posix_api/psx_mutex_report/mutex_attr_report.c create mode 100644 posix_api/psx_mutex_report/rtems_config.c create mode 100644 posix_api/psx_mutex_report/wscript create mode 100644 posix_api/psx_pthread_report/Makefile create mode 100644 posix_api/psx_pthread_report/pthread_attr_report.c create mode 100644 posix_api/psx_pthread_report/rtems_config.c create mode 100644 posix_api/psx_pthread_report/wscript create mode 100644 posix_api/psx_rwlock_report/Makefile create mode 100644 posix_api/psx_rwlock_report/rtems_config.c create mode 100644 posix_api/psx_rwlock_report/rwlock_attr_report.c create mode 100644 posix_api/psx_rwlock_report/wscript create mode 100644 posix_api/psx_sched_report/psx_sched_report.c delete mode 100644 posix_api/psx_sched_report/test.c diff --git a/posix_api/Makefile b/posix_api/Makefile index b070ea9..8af26dc 100644 --- a/posix_api/Makefile +++ b/posix_api/Makefile @@ -4,5 +4,14 @@ include $(RTEMS_SHARE)/make/directory.cfg # If the POSIX API isn't enabled, we can't build these ifeq ($(RTEMS_HAS_POSIX_API),yes) - SUBDIRS = psx_example_1 psx_example_2 psx_example_3 psx_sched_report + SUBDIRS = psx_example_1 + SUBDIRS += psx_example_2 + SUBDIRS += psx_example_3 + SUBDIRS += psx_barrier_report + SUBDIRS += psx_condvar_report + SUBDIRS += psx_mqueue_report + SUBDIRS += psx_mutex_report + SUBDIRS += psx_pthread_report + SUBDIRS += psx_rwlock_report + SUBDIRS += psx_sched_report endif diff --git a/posix_api/psx_barrier_report/Makefile b/posix_api/psx_barrier_report/Makefile new file mode 100644 index 0000000..e8e2f63 --- /dev/null +++ b/posix_api/psx_barrier_report/Makefile @@ -0,0 +1,20 @@ +# +# RTEMS_MAKEFILE_PATH is typically set in an environment variable +# + +PGM=${ARCH}/psx_barrier_report.exe + +# C source names +CSRCS = barrier_attr_report.c rtems_config.c +COBJS = $(CSRCS:%.c=${ARCH}/%.o) + +include $(RTEMS_MAKEFILE_PATH)/Makefile.inc +include $(RTEMS_CUSTOM) +include $(PROJECT_ROOT)/make/leaf.cfg + +OBJS= $(COBJS) $(CXXOBJS) $(ASOBJS) + +all: ${ARCH} $(PGM) + +$(PGM): $(OBJS) + $(make-exe) diff --git a/posix_api/psx_barrier_report/barrier_attr_report.c b/posix_api/psx_barrier_report/barrier_attr_report.c new file mode 100644 index 0000000..c1f0485 --- /dev/null +++ b/posix_api/psx_barrier_report/barrier_attr_report.c @@ -0,0 +1,58 @@ +/* + * Program to print default POSIX barrier attributes + */ + +/* + * Copyright 2018 Joel Sherrill (joel@rtems.org) + * + * This file's license is 2-clause BSD as in this distribution's LICENSE.2 file. + */ + +#include +#include +#include +#include +#include + +#ifndef OS_DOES_NOT_SUPPORT_BARRIERS + +static void print_shared(pthread_barrierattr_t *attr) +{ + int rc; + int shared; + char *s; + + rc = pthread_barrierattr_getpshared( attr, &shared ); + assert( rc == 0 ); + + switch ( shared ) { + case PTHREAD_PROCESS_PRIVATE: s = "PTHREAD_PROCESS_PRIVATE"; break; + case PTHREAD_PROCESS_SHARED: s = "PTHREAD_PROCESS_SHARED"; break; + default: s = "UNKNOWN"; break; + } + + printf( "Process shared: %s\n", s ); +} +#endif + +int main() +{ +#ifndef OS_DOES_NOT_SUPPORT_BARRIERS + pthread_barrierattr_t attr; +#endif + int rc; + + puts( "*** POSIX Barrier Default Attributes Report ***" ); + +#ifndef OS_DOES_NOT_SUPPORT_BARRIERS + rc = pthread_barrierattr_init( &attr ); + assert( rc == 0 ); + + print_shared( &attr ); +#else + printf( "Barriers are not supported\n" ); +#endif + + puts( "*** END OF POSIX Barrier Default Attributes Report ***" ); + exit( 0 ); +} diff --git a/posix_api/psx_barrier_report/rtems_config.c b/posix_api/psx_barrier_report/rtems_config.c new file mode 100644 index 0000000..fd0a0f8 --- /dev/null +++ b/posix_api/psx_barrier_report/rtems_config.c @@ -0,0 +1,48 @@ +/* + * This file contains the RTEMS Configuration for this example. + */ + +/* + * Copyright 2018 Joel Sherrill (joel@rtems.org) + * + * This file's license is 2-clause BSD as in this distribution's LICENSE.2 file. + */ + +#include + +int main(int argc, char **argv); + +static char *argv_list[] = { + "report", + "" +}; +static void *POSIX_Init(void *arg) +{ + (void) arg; /* deliberately ignored */ + + /* + * Initialize optional services + */ + + /* + * Could get arguments from command line or have a static set. + */ + (void) main(1, argv_list); + + return NULL; +} + +#include /* for device driver prototypes */ + +/* NOTICE: the clock driver is explicitly disabled */ +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER + +#define CONFIGURE_POSIX_INIT_THREAD_TABLE + +#define CONFIGURE_UNLIMITED_OBJECTS +#define CONFIGURE_UNIFIED_WORK_AREAS +#define CONFIGURE_MINIMUM_TASK_STACK_SIZE (64 * 1024) + +#define CONFIGURE_INIT +#include diff --git a/posix_api/psx_barrier_report/wscript b/posix_api/psx_barrier_report/wscript new file mode 100644 index 0000000..6e03506 --- /dev/null +++ b/posix_api/psx_barrier_report/wscript @@ -0,0 +1,15 @@ +# Copyright 2018 Joel Sherrill (joel@rtems.org) +# +# This file's license is 2-clause BSD as in this distribution's LICENSE.2 file. +# + +import rtems_waf.rtems as rtems + +def build(bld): + rtems.build(bld) + + bld(features = 'c cprogram', + target = 'psx_barrier_report.exe', + source = ['barrier_attr_report.c','rtems_config.c'], + lib = ['c']) + diff --git a/posix_api/psx_condvar_report/Makefile b/posix_api/psx_condvar_report/Makefile new file mode 100644 index 0000000..27fa8bd --- /dev/null +++ b/posix_api/psx_condvar_report/Makefile @@ -0,0 +1,20 @@ +# +# RTEMS_MAKEFILE_PATH is typically set in an environment variable +# + +PGM=${ARCH}/psx_condvar_report.exe + +# C source names +CSRCS = condvar_attr_report.c rtems_config.c +COBJS = $(CSRCS:%.c=${ARCH}/%.o) + +include $(RTEMS_MAKEFILE_PATH)/Makefile.inc +include $(RTEMS_CUSTOM) +include $(PROJECT_ROOT)/make/leaf.cfg + +OBJS= $(COBJS) $(CXXOBJS) $(ASOBJS) + +all: ${ARCH} $(PGM) + +$(PGM): $(OBJS) + $(make-exe) diff --git a/posix_api/psx_condvar_report/condvar_attr_report.c b/posix_api/psx_condvar_report/condvar_attr_report.c new file mode 100644 index 0000000..4c460d9 --- /dev/null +++ b/posix_api/psx_condvar_report/condvar_attr_report.c @@ -0,0 +1,69 @@ +/* + * Program to print default POSIX condition variable attributes + */ + +/* + * Copyright 2018 Joel Sherrill (joel@rtems.org) + * + * This file's license is 2-clause BSD as in this distribution's LICENSE.2 file. + */ + +#include +#include +#include +#include +#include + +static void print_shared(pthread_condattr_t *attr) +{ + int rc; + int shared; + char *s; + + rc = pthread_condattr_getpshared( attr, &shared ); + assert( rc == 0 ); + + switch ( shared ) { + case PTHREAD_PROCESS_PRIVATE: s = "PTHREAD_PROCESS_PRIVATE"; break; + case PTHREAD_PROCESS_SHARED: s = "PTHREAD_PROCESS_SHARED"; break; + default: s = "UNKNOWN"; break; + } + + printf( "Process shared: %s\n", s ); +} + +static void print_clock(pthread_condattr_t *attr) +{ + int rc; + clockid_t clock; + char *s; + + rc = pthread_condattr_getclock( attr, &clock ); + assert( rc == 0 ); + switch ( clock ) { + case CLOCK_MONOTONIC: s = "CLOCK_MONOTONIC"; break; + case CLOCK_PROCESS_CPUTIME_ID: s = "CLOCK_PROCESS_CPUTIME_ID"; break; + case CLOCK_REALTIME: s = "CLOCK_REALTIME"; break; + case CLOCK_THREAD_CPUTIME_ID: s = "CLOCK_THREAD_CPUTIME_ID"; break; + default: s = "UNKNOWN"; break; + } + + printf( "Clock: %s\n", s ); +} + +int main() +{ + pthread_condattr_t attr; + int rc; + + puts( "*** POSIX Condition Variable Default Attributes Report ***" ); + + rc = pthread_condattr_init( &attr ); + assert( rc == 0 ); + + print_shared( &attr ); + print_clock( &attr ); + + puts( "*** END OF POSIX Condition Variable Default Attributes Report ***" ); + exit( 0 ); +} diff --git a/posix_api/psx_condvar_report/rtems_config.c b/posix_api/psx_condvar_report/rtems_config.c new file mode 100644 index 0000000..fd0a0f8 --- /dev/null +++ b/posix_api/psx_condvar_report/rtems_config.c @@ -0,0 +1,48 @@ +/* + * This file contains the RTEMS Configuration for this example. + */ + +/* + * Copyright 2018 Joel Sherrill (joel@rtems.org) + * + * This file's license is 2-clause BSD as in this distribution's LICENSE.2 file. + */ + +#include + +int main(int argc, char **argv); + +static char *argv_list[] = { + "report", + "" +}; +static void *POSIX_Init(void *arg) +{ + (void) arg; /* deliberately ignored */ + + /* + * Initialize optional services + */ + + /* + * Could get arguments from command line or have a static set. + */ + (void) main(1, argv_list); + + return NULL; +} + +#include /* for device driver prototypes */ + +/* NOTICE: the clock driver is explicitly disabled */ +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER + +#define CONFIGURE_POSIX_INIT_THREAD_TABLE + +#define CONFIGURE_UNLIMITED_OBJECTS +#define CONFIGURE_UNIFIED_WORK_AREAS +#define CONFIGURE_MINIMUM_TASK_STACK_SIZE (64 * 1024) + +#define CONFIGURE_INIT +#include diff --git a/posix_api/psx_condvar_report/wscript b/posix_api/psx_condvar_report/wscript new file mode 100644 index 0000000..b4a5d29 --- /dev/null +++ b/posix_api/psx_condvar_report/wscript @@ -0,0 +1,15 @@ +# Copyright 2013 Gedare Bloom (gedare@rtems.org) +# +# This file's license is 2-clause BSD as in this distribution's LICENSE.2 file. +# + +import rtems_waf.rtems as rtems + +def build(bld): + rtems.build(bld) + + bld(features = 'c cprogram', + target = 'psx_condvar_report.exe', + source = ['condvar_attr_report.c','rtems_config.c'], + lib = ['c']) + diff --git a/posix_api/psx_mqueue_report/Makefile b/posix_api/psx_mqueue_report/Makefile new file mode 100644 index 0000000..52027fd --- /dev/null +++ b/posix_api/psx_mqueue_report/Makefile @@ -0,0 +1,20 @@ +# +# RTEMS_MAKEFILE_PATH is typically set in an environment variable +# + +PGM=${ARCH}/psx_mqueue_report.exe + +# C source names +CSRCS = mqueue_attr_report.c rtems_config.c +COBJS = $(CSRCS:%.c=${ARCH}/%.o) + +include $(RTEMS_MAKEFILE_PATH)/Makefile.inc +include $(RTEMS_CUSTOM) +include $(PROJECT_ROOT)/make/leaf.cfg + +OBJS= $(COBJS) $(CXXOBJS) $(ASOBJS) + +all: ${ARCH} $(PGM) + +$(PGM): $(OBJS) + $(make-exe) diff --git a/posix_api/psx_mqueue_report/mqueue_attr_report.c b/posix_api/psx_mqueue_report/mqueue_attr_report.c new file mode 100644 index 0000000..855330c --- /dev/null +++ b/posix_api/psx_mqueue_report/mqueue_attr_report.c @@ -0,0 +1,48 @@ +/* + * Program to print default POSIX message queue attributes + */ + +/* + * Copyright 2018 Joel Sherrill (joel@rtems.org) + * + * This file's license is 2-clause BSD as in this distribution's LICENSE.2 file. + */ + +#include +#include +#include +#include + +#include /* For O_* constants */ +#include +#include + +static void print_attr(mqd_t mqd) +{ + int rc; + struct mq_attr attr; + + rc = mq_getattr( mqd, &attr ); + assert( rc == 0 ); + + printf( "mq_maxmsg: %ld\n", attr.mq_maxmsg ); + printf( "mq_msgsize: %ld\n", attr.mq_msgsize ); +} + +int main() +{ + mqd_t mqd; + + puts( "*** POSIX Message Queue Default Attributes Report ***" ); + + mqd = mq_open( "/testq", O_CREAT|O_RDWR, 0777, NULL ); + if ( mqd == (mqd_t) -1 ) { + perror("mq_open" ); + } + assert( mqd != (mqd_t) -1 ); + + print_attr( mqd ); + + puts( "*** END OF POSIX Message Queue Default Attributes Report ***" ); + exit( 0 ); +} diff --git a/posix_api/psx_mqueue_report/rtems_config.c b/posix_api/psx_mqueue_report/rtems_config.c new file mode 100644 index 0000000..fd0a0f8 --- /dev/null +++ b/posix_api/psx_mqueue_report/rtems_config.c @@ -0,0 +1,48 @@ +/* + * This file contains the RTEMS Configuration for this example. + */ + +/* + * Copyright 2018 Joel Sherrill (joel@rtems.org) + * + * This file's license is 2-clause BSD as in this distribution's LICENSE.2 file. + */ + +#include + +int main(int argc, char **argv); + +static char *argv_list[] = { + "report", + "" +}; +static void *POSIX_Init(void *arg) +{ + (void) arg; /* deliberately ignored */ + + /* + * Initialize optional services + */ + + /* + * Could get arguments from command line or have a static set. + */ + (void) main(1, argv_list); + + return NULL; +} + +#include /* for device driver prototypes */ + +/* NOTICE: the clock driver is explicitly disabled */ +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER + +#define CONFIGURE_POSIX_INIT_THREAD_TABLE + +#define CONFIGURE_UNLIMITED_OBJECTS +#define CONFIGURE_UNIFIED_WORK_AREAS +#define CONFIGURE_MINIMUM_TASK_STACK_SIZE (64 * 1024) + +#define CONFIGURE_INIT +#include diff --git a/posix_api/psx_mqueue_report/wscript b/posix_api/psx_mqueue_report/wscript new file mode 100644 index 0000000..fed2355 --- /dev/null +++ b/posix_api/psx_mqueue_report/wscript @@ -0,0 +1,15 @@ +# Copyright 2013 Gedare Bloom (gedare@rtems.org) +# +# This file's license is 2-clause BSD as in this distribution's LICENSE.2 file. +# + +import rtems_waf.rtems as rtems + +def build(bld): + rtems.build(bld) + + bld(features = 'c cprogram', + target = 'psx_mqueue_report.exe', + source = ['mqueue_attr_report.c','rtems_config.c'], + lib = ['c']) + diff --git a/posix_api/psx_mutex_report/Makefile b/posix_api/psx_mutex_report/Makefile new file mode 100644 index 0000000..b615525 --- /dev/null +++ b/posix_api/psx_mutex_report/Makefile @@ -0,0 +1,20 @@ +# +# RTEMS_MAKEFILE_PATH is typically set in an environment variable +# + +PGM=${ARCH}/psx_mutex_report.exe + +# C source names +CSRCS = mutex_attr_report.c rtems_config.c +COBJS = $(CSRCS:%.c=${ARCH}/%.o) + +include $(RTEMS_MAKEFILE_PATH)/Makefile.inc +include $(RTEMS_CUSTOM) +include $(PROJECT_ROOT)/make/leaf.cfg + +OBJS= $(COBJS) $(CXXOBJS) $(ASOBJS) + +all: ${ARCH} $(PGM) + +$(PGM): $(OBJS) + $(make-exe) diff --git a/posix_api/psx_mutex_report/mutex_attr_report.c b/posix_api/psx_mutex_report/mutex_attr_report.c new file mode 100644 index 0000000..444a4d0 --- /dev/null +++ b/posix_api/psx_mutex_report/mutex_attr_report.c @@ -0,0 +1,131 @@ +/* + * Program to print default POSIX mutex attributes + */ + +/* + * Copyright 2018 Joel Sherrill (joel@rtems.org) + * + * This file's license is 2-clause BSD as in this distribution's LICENSE.2 file. + */ + +#include +#include +#include +#include +#include + +static void print_shared(pthread_mutexattr_t *attr) +{ + int rc; + int shared; + char *s; + + rc = pthread_mutexattr_getpshared( attr, &shared ); + assert( rc == 0 ); + + switch ( shared ) { + case PTHREAD_PROCESS_PRIVATE: s = "PTHREAD_PROCESS_PRIVATE"; break; + case PTHREAD_PROCESS_SHARED: s = "PTHREAD_PROCESS_SHARED"; break; + default: s = "UNKNOWN"; break; + } + + printf( "Process shared: %s\n", s ); +} + +static void print_type(pthread_mutexattr_t *attr) +{ + int rc; + int type; + char *s; + +#ifndef PTHREAD_MUTEX_ROBUST + puts( "PTHREAD_MUTEX_ROBUST is not supported" ); +#endif +#ifndef PTHREAD_MUTEX_STALLED + puts( "PTHREAD_MUTEX_STALLED is not supported" ); +#endif +#if (PTHREAD_MUTEX_DEFAULT == PTHREAD_MUTEX_NORMAL) + puts( "PTHREAD_MUTEX_DEFAULT == PTHREAD_MUTEX_NORMAL" ); +#endif + + /* + * NOTE: The FACE Technical Standard defines multiple POSIX profiles. + * Some of the profiles do not include pthread_mutexattr_gettype(). + */ +#ifdef OS_DOES_NOT_SUPPORT_PTHREAD_MUTEXATTR_GETTYPE + s = "pthread_mutexattr_gettype() is not supported"; +#else + rc = pthread_mutexattr_gettype( attr, &type ); + assert( rc == 0 ); + switch ( type ) { +#if (PTHREAD_MUTEX_DEFAULT != PTHREAD_MUTEX_NORMAL) + case PTHREAD_MUTEX_DEFAULT: s = "PTHREAD_MUTEX_DEFAULT"; break; +#endif + case PTHREAD_MUTEX_ERRORCHECK: s = "PTHREAD_MUTEX_ERRORCHECK"; break; + case PTHREAD_MUTEX_NORMAL: s = "PTHREAD_MUTEX_NORMAL"; break; + case PTHREAD_MUTEX_RECURSIVE: s = "PTHREAD_MUTEX_RECURSIVE"; break; +#ifdef PTHREAD_MUTEX_ROBUST + case PTHREAD_MUTEX_ROBUST: s = "PTHREAD_MUTEX_ROBUST"; break; +#endif +#ifdef PTHREAD_MUTEX_STALLED + case PTHREAD_MUTEX_STALLED: s = "PTHREAD_MUTEX_STALLED"; break; +#endif + default: s = "UNKNOWN"; break; + } +#endif + + printf( "Type: %s\n", s ); +} + +static void print_protocol(pthread_mutexattr_t *attr) +{ +#if defined(__CYGWIN__) + /* Cygwin does not support the protocols */ + puts( "Mutex protocols not supported" ); +#else + int rc; + int protocol; + char *s; + + rc = pthread_mutexattr_getprotocol( attr, &protocol ); + assert( rc == 0 ); + switch ( protocol ) { + /* XXX something is not right on CentOS. The constants are not available.*/ + /* XXX Figure it out */ +#ifdef __linux__ + case 0: s = "PTHREAD_PRIO_NONE"; break; + case 1: s = "PTHREAD_PRIO_INHERIT"; break; + case 2: s = "PTHREAD_PRIO_PROTECT"; break; +#else + case PTHREAD_PRIO_NONE: s = "PTHREAD_PRIO_NONE"; break; + case PTHREAD_PRIO_INHERIT: s = "PTHREAD_PRIO_INHERIT"; break; + case PTHREAD_PRIO_PROTECT: s = "PTHREAD_PRIO_PROTECT"; break; +#endif + default: s = "UNKNOWN"; break; + } + + printf( "Protocol: %s\n", s ); + /* + * Assuming that PTHREAD_PRIO_CEILING is not used as default, so + * no need to print ceiling. + */ +#endif +} + +int main() +{ + pthread_mutexattr_t attr; + int rc; + + puts( "*** POSIX Mutex Default Attributes Report ***" ); + + rc = pthread_mutexattr_init( &attr ); + assert( rc == 0 ); + + print_type( &attr ); + print_shared( &attr ); + print_protocol( &attr ); + + puts( "*** END OF POSIX Mutex Default Attributes Report ***" ); + exit( 0 ); +} diff --git a/posix_api/psx_mutex_report/rtems_config.c b/posix_api/psx_mutex_report/rtems_config.c new file mode 100644 index 0000000..9d0bd42 --- /dev/null +++ b/posix_api/psx_mutex_report/rtems_config.c @@ -0,0 +1,49 @@ +/* + * This file contains the RTEMS Configuration for this example. + */ + +/* + * Copyright 2018 Joel Sherrill (joel@rtems.org) + * + * This file's license is 2-clause BSD as in this distribution's LICENSE.2 file. + */ + + +#include + +int main(int argc, char **argv); + +static char *argv_list[] = { + "report", + "" +}; +static void *POSIX_Init(void *arg) +{ + (void) arg; /* deliberately ignored */ + + /* + * Initialize optional services + */ + + /* + * Could get arguments from command line or have a static set. + */ + (void) main(1, argv_list); + + return NULL; +} + +#include /* for device driver prototypes */ + +/* NOTICE: the clock driver is explicitly disabled */ +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER + +#define CONFIGURE_POSIX_INIT_THREAD_TABLE + +#define CONFIGURE_UNLIMITED_OBJECTS +#define CONFIGURE_UNIFIED_WORK_AREAS +#define CONFIGURE_MINIMUM_TASK_STACK_SIZE (64 * 1024) + +#define CONFIGURE_INIT +#include diff --git a/posix_api/psx_mutex_report/wscript b/posix_api/psx_mutex_report/wscript new file mode 100644 index 0000000..cb2f199 --- /dev/null +++ b/posix_api/psx_mutex_report/wscript @@ -0,0 +1,15 @@ +# Copyright 2013 Gedare Bloom (gedare@rtems.org) +# +# This file's license is 2-clause BSD as in this distribution's LICENSE.2 file. +# + +import rtems_waf.rtems as rtems + +def build(bld): + rtems.build(bld) + + bld(features = 'c cprogram', + target = 'psx_mutex_report.exe', + source = ['mutex_attr_report.c','rtems_config.c'], + lib = ['c']) + diff --git a/posix_api/psx_pthread_report/Makefile b/posix_api/psx_pthread_report/Makefile new file mode 100644 index 0000000..6f83abb --- /dev/null +++ b/posix_api/psx_pthread_report/Makefile @@ -0,0 +1,20 @@ +# +# RTEMS_MAKEFILE_PATH is typically set in an environment variable +# + +PGM=${ARCH}/psx_pthread_report.exe + +# C source names +CSRCS = pthread_attr_report.c rtems_config.c +COBJS = $(CSRCS:%.c=${ARCH}/%.o) + +include $(RTEMS_MAKEFILE_PATH)/Makefile.inc +include $(RTEMS_CUSTOM) +include $(PROJECT_ROOT)/make/leaf.cfg + +OBJS= $(COBJS) $(CXXOBJS) $(ASOBJS) + +all: ${ARCH} $(PGM) + +$(PGM): $(OBJS) + $(make-exe) diff --git a/posix_api/psx_pthread_report/pthread_attr_report.c b/posix_api/psx_pthread_report/pthread_attr_report.c new file mode 100644 index 0000000..ff2f179 --- /dev/null +++ b/posix_api/psx_pthread_report/pthread_attr_report.c @@ -0,0 +1,154 @@ +/* + * Program to print default pthread attributes + */ + +/* + * Copyright 2018 Joel Sherrill (joel@rtems.org) + * + * This file's license is 2-clause BSD as in this distribution's LICENSE.2 file. + */ + +#include +#include +#include +#include +#include + +static void print_stack_info(pthread_attr_t *attr) +{ + int rc; + void *addr; + size_t size; + + /* + * pthread_attr_getstacksize() and pthread_attr_[sg]etstackaddr() are + * obsolete. + */ + + rc = pthread_attr_getstack( attr, &addr, &size ); + assert( rc == 0 ); + printf( "Stack size: %zu\n", size ); + printf( "Stack address: %p\n", addr ); + + rc = pthread_attr_getguardsize( attr, &size ); + assert( rc == 0 ); + printf( "Stack guard size: %zu\n", size ); + +} + +static void print_inherit_scheduler(pthread_attr_t *attr) +{ + int rc; + int sched; + char *s; + + rc = pthread_attr_getinheritsched( attr, &sched ); + assert( rc == 0 ); + + switch( sched ) { + case PTHREAD_INHERIT_SCHED: s = "PTHREAD_INHERIT_SCHED"; break; + case PTHREAD_EXPLICIT_SCHED: s = "PTHREAD_EXPLICIT_SCHED"; break; + default: s = "UNKNOWN"; break; + } + + printf( "Inherit scheduler: %s\n", s ); +} + +static void print_scope(pthread_attr_t *attr) +{ + int rc; + int scope; + char *s; + + rc = pthread_attr_getscope( attr, &scope ); + assert( rc == 0 ); + + switch( scope ) { + case PTHREAD_SCOPE_SYSTEM: s = "PTHREAD_SCOPE_SYSTEM"; break; + case PTHREAD_SCOPE_PROCESS: s = "PTHREAD_SCOPE_PROCESS"; break; + default: s = "UNKNOWN"; break; + } + + printf( "Thread scope: %s\n", s ); +} + +static void print_detach_state(pthread_attr_t *attr) +{ + int rc; + int state; + char *s; + + rc = pthread_attr_getdetachstate( attr, &state ); + assert( rc == 0 ); + + switch( state ) { + case PTHREAD_CREATE_JOINABLE: s = "PTHREAD_CREATE_JOINABLE"; break; + case PTHREAD_CREATE_DETACHED: s = "PTHREAD_CREATE_DETACHED"; break; + default: s = "UNKNOWN"; break; + } + + printf( "Thread detach state: %s\n", s ); +} + +static void print_sched_info(pthread_attr_t *attr) +{ + int rc; + int policy; + char *s; + struct sched_param sched; + + rc = pthread_attr_getschedpolicy( attr, &policy ); + assert( rc == 0 ); + + rc = pthread_attr_getschedparam( attr, &sched ); + assert( rc == 0 ); + + switch( policy ) { + case SCHED_OTHER: s = "SCHED_OTHER"; break; + case SCHED_FIFO: s = "SCHED_FIFO"; break; + case SCHED_RR: s = "SCHED_RR"; break; +#if defined(SCHED_SPORADIC) + case SCHED_SPORADIC: s = "SCHED_SPORADIC"; break; +#endif + default: s = "UNKNOWN"; break; + } + + printf( "Scheduler policy : %s\n", s ); + printf( "Scheduler priority : %d\n", sched.sched_priority ); +#if defined(SCHED_SPORADIC) + if ( policy == SCHED_SPORADIC ) { + printf( + "Sporadic low priority : %d\n" + "Sporadic period: %lld:%ld\n" + "Sporadic initial budget: %lld:%ld\n" + "Sporadic max pending replenishments: %d\n", + sched.sched_ss_low_priority, + (long long) sched.sched_ss_repl_period.tv_sec, + sched.sched_ss_repl_period.tv_nsec, + (long long) sched.sched_ss_init_budget.tv_sec, + sched.sched_ss_init_budget.tv_nsec, + sched.sched_ss_max_repl + ); + } +#endif +} + +int main() +{ + pthread_attr_t attr; + int rc; + + puts( "*** POSIX Thread Default Attributes Report ***" ); + + rc = pthread_attr_init( &attr ); + assert( rc == 0 ); + + print_stack_info( &attr ); + print_inherit_scheduler( &attr ); + print_scope( &attr ); + print_detach_state( &attr ); + print_sched_info( &attr ); + + puts( "*** END OF POSIX Thread Default Attributes Report ***" ); + exit( 0 ); +} diff --git a/posix_api/psx_pthread_report/rtems_config.c b/posix_api/psx_pthread_report/rtems_config.c new file mode 100644 index 0000000..fd0a0f8 --- /dev/null +++ b/posix_api/psx_pthread_report/rtems_config.c @@ -0,0 +1,48 @@ +/* + * This file contains the RTEMS Configuration for this example. + */ + +/* + * Copyright 2018 Joel Sherrill (joel@rtems.org) + * + * This file's license is 2-clause BSD as in this distribution's LICENSE.2 file. + */ + +#include + +int main(int argc, char **argv); + +static char *argv_list[] = { + "report", + "" +}; +static void *POSIX_Init(void *arg) +{ + (void) arg; /* deliberately ignored */ + + /* + * Initialize optional services + */ + + /* + * Could get arguments from command line or have a static set. + */ + (void) main(1, argv_list); + + return NULL; +} + +#include /* for device driver prototypes */ + +/* NOTICE: the clock driver is explicitly disabled */ +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER + +#define CONFIGURE_POSIX_INIT_THREAD_TABLE + +#define CONFIGURE_UNLIMITED_OBJECTS +#define CONFIGURE_UNIFIED_WORK_AREAS +#define CONFIGURE_MINIMUM_TASK_STACK_SIZE (64 * 1024) + +#define CONFIGURE_INIT +#include diff --git a/posix_api/psx_pthread_report/wscript b/posix_api/psx_pthread_report/wscript new file mode 100644 index 0000000..6ec6cfa --- /dev/null +++ b/posix_api/psx_pthread_report/wscript @@ -0,0 +1,15 @@ +# Copyright 2013 Gedare Bloom (gedare@rtems.org) +# +# This file's license is 2-clause BSD as in this distribution's LICENSE.2 file. +# + +import rtems_waf.rtems as rtems + +def build(bld): + rtems.build(bld) + + bld(features = 'c cprogram', + target = 'psx_pthread_report.exe', + source = ['pthread_attr_report.c','rtems_config.c'], + lib = ['c']) + diff --git a/posix_api/psx_rwlock_report/Makefile b/posix_api/psx_rwlock_report/Makefile new file mode 100644 index 0000000..c0797ba --- /dev/null +++ b/posix_api/psx_rwlock_report/Makefile @@ -0,0 +1,20 @@ +# +# RTEMS_MAKEFILE_PATH is typically set in an environment variable +# + +PGM=${ARCH}/psx_rwlock_report.exe + +# C source names +CSRCS = rwlock_attr_report.c rtems_config.c +COBJS = $(CSRCS:%.c=${ARCH}/%.o) + +include $(RTEMS_MAKEFILE_PATH)/Makefile.inc +include $(RTEMS_CUSTOM) +include $(PROJECT_ROOT)/make/leaf.cfg + +OBJS= $(COBJS) $(CXXOBJS) $(ASOBJS) + +all: ${ARCH} $(PGM) + +$(PGM): $(OBJS) + $(make-exe) diff --git a/posix_api/psx_rwlock_report/rtems_config.c b/posix_api/psx_rwlock_report/rtems_config.c new file mode 100644 index 0000000..fd0a0f8 --- /dev/null +++ b/posix_api/psx_rwlock_report/rtems_config.c @@ -0,0 +1,48 @@ +/* + * This file contains the RTEMS Configuration for this example. + */ + +/* + * Copyright 2018 Joel Sherrill (joel@rtems.org) + * + * This file's license is 2-clause BSD as in this distribution's LICENSE.2 file. + */ + +#include + +int main(int argc, char **argv); + +static char *argv_list[] = { + "report", + "" +}; +static void *POSIX_Init(void *arg) +{ + (void) arg; /* deliberately ignored */ + + /* + * Initialize optional services + */ + + /* + * Could get arguments from command line or have a static set. + */ + (void) main(1, argv_list); + + return NULL; +} + +#include /* for device driver prototypes */ + +/* NOTICE: the clock driver is explicitly disabled */ +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER + +#define CONFIGURE_POSIX_INIT_THREAD_TABLE + +#define CONFIGURE_UNLIMITED_OBJECTS +#define CONFIGURE_UNIFIED_WORK_AREAS +#define CONFIGURE_MINIMUM_TASK_STACK_SIZE (64 * 1024) + +#define CONFIGURE_INIT +#include diff --git a/posix_api/psx_rwlock_report/rwlock_attr_report.c b/posix_api/psx_rwlock_report/rwlock_attr_report.c new file mode 100644 index 0000000..2ec7067 --- /dev/null +++ b/posix_api/psx_rwlock_report/rwlock_attr_report.c @@ -0,0 +1,49 @@ +/* + * Program to print default POSIX rwlock attributes + */ + +/* + * Copyright 2018 Joel Sherrill (joel@rtems.org) + * + * This file's license is 2-clause BSD as in this distribution's LICENSE.2 file. + */ + +#include +#include +#include +#include +#include + +static void print_shared(pthread_rwlockattr_t *attr) +{ + int rc; + int shared; + char *s; + + rc = pthread_rwlockattr_getpshared( attr, &shared ); + assert( rc == 0 ); + + switch ( shared ) { + case PTHREAD_PROCESS_PRIVATE: s = "PTHREAD_PROCESS_PRIVATE"; break; + case PTHREAD_PROCESS_SHARED: s = "PTHREAD_PROCESS_SHARED"; break; + default: s = "UNKNOWN"; break; + } + + printf( "Process shared: %s\n", s ); +} + +int main() +{ + pthread_rwlockattr_t attr; + int rc; + + puts( "*** POSIX RWLock Default Attributes Report ***" ); + + rc = pthread_rwlockattr_init( &attr ); + assert( rc == 0 ); + + print_shared( &attr ); + + puts( "*** END OF POSIX RWLock Default Attributes Report ***" ); + exit( 0 ); +} diff --git a/posix_api/psx_rwlock_report/wscript b/posix_api/psx_rwlock_report/wscript new file mode 100644 index 0000000..56f6354 --- /dev/null +++ b/posix_api/psx_rwlock_report/wscript @@ -0,0 +1,15 @@ +# Copyright 2013 Gedare Bloom (gedare@rtems.org) +# +# This file's license is 2-clause BSD as in this distribution's LICENSE.2 file. +# + +import rtems_waf.rtems as rtems + +def build(bld): + rtems.build(bld) + + bld(features = 'c cprogram', + target = 'psx_rwlock_report.exe', + source = ['rwlock_attr_report.c','rtems_config.c'], + lib = ['c']) + diff --git a/posix_api/psx_sched_report/Makefile b/posix_api/psx_sched_report/Makefile index 96dd47f..f69f38d 100644 --- a/posix_api/psx_sched_report/Makefile +++ b/posix_api/psx_sched_report/Makefile @@ -1,37 +1,14 @@ -# -# Makefile -# - # # RTEMS_MAKEFILE_PATH is typically set in an environment variable # -EXEC=psx_sched_report.exe -PGM=${ARCH}/$(EXEC) - -# optional managers required -MANAGERS=all +PGM=${ARCH}/psx_sched_report.exe # C source names -CSRCS = test.c -COBJS_ = $(CSRCS:.c=.o) -COBJS = $(COBJS_:%=${ARCH}/%) - -# C++ source names -CXXSRCS = -CXXOBJS_ = $(CXXSRCS:.cc=.o) -CXXOBJS = $(CXXOBJS_:%=${ARCH}/%) - -# AS source names -ASSRCS = -ASOBJS_ = $(ASSRCS:.s=.o) -ASOBJS = $(ASOBJS_:%=${ARCH}/%) - -# Libraries -LIBS = -lrtemsall -lc +CSRCS = psx_sched_report.c rtems_config.c +COBJS = $(CSRCS:%.c=${ARCH}/%.o) include $(RTEMS_MAKEFILE_PATH)/Makefile.inc - include $(RTEMS_CUSTOM) include $(PROJECT_ROOT)/make/leaf.cfg @@ -41,4 +18,3 @@ all: ${ARCH} $(PGM) $(PGM): $(OBJS) $(make-exe) - diff --git a/posix_api/psx_sched_report/psx_sched_report.c b/posix_api/psx_sched_report/psx_sched_report.c new file mode 100644 index 0000000..b0381aa --- /dev/null +++ b/posix_api/psx_sched_report/psx_sched_report.c @@ -0,0 +1,55 @@ +/* + * Program to print POSIX Scheduler Characteristics + */ + +/* + * Copyright 2018 Joel Sherrill (joel@rtems.org) + * + * This file's license is 2-clause BSD as in this distribution's LICENSE.2 file. + */ + +#include +#include +#include +/* FreeBSD 10 needs this for struct timespec which seems wrong */ +#include + +void print_sched_info( + char *s, + int policy +) +{ + int min, max, levels; + struct timespec t; + + printf( "Information on %s\n", s ); + min = sched_get_priority_min( policy ); + max = sched_get_priority_max( policy ); + (void) sched_rr_get_interval( 1, &t ); + levels = abs(max - min + 1); + printf( "\tSupports %d priority levels (%d - %d)\n", levels, min, max ); + if ( levels >= 32 ) + printf( "\tImplementation is compliant on priority levels\n"); + else + printf( "\tImplementation is NOT compliant on priority levels\n" ); + + printf( "\tScheduling quantum is %ld seconds and %ld nanoseconds\n", + (long)t.tv_sec, (long)t.tv_nsec ); + puts( "" ); +} + +int main() +{ + puts( "*** POSIX Scheduler Characteristics Report ***" ); + print_sched_info( "SCHED_OTHER", SCHED_OTHER ); + print_sched_info( "SCHED_FIFO", SCHED_FIFO ); + print_sched_info( "SCHED_RR", SCHED_RR ); +#if defined(SCHED_SPORADIC) + print_sched_info( "SCHED_SPORADIC", SCHED_SPORADIC ); +#else + printf( "SCHED_SPORADIC is not supported\n" ); +#endif + puts( "*** END OF POSIX Scheduler Characteristics Report ***" ); + + exit( 0 ); +} diff --git a/posix_api/psx_sched_report/rtems_config.c b/posix_api/psx_sched_report/rtems_config.c index f985453..fd0a0f8 100644 --- a/posix_api/psx_sched_report/rtems_config.c +++ b/posix_api/psx_sched_report/rtems_config.c @@ -1,10 +1,19 @@ +/* + * This file contains the RTEMS Configuration for this example. + */ + +/* + * Copyright 2018 Joel Sherrill (joel@rtems.org) + * + * This file's license is 2-clause BSD as in this distribution's LICENSE.2 file. + */ #include int main(int argc, char **argv); static char *argv_list[] = { - "psx_sched_report", + "report", "" }; static void *POSIX_Init(void *arg) diff --git a/posix_api/psx_sched_report/test.c b/posix_api/psx_sched_report/test.c deleted file mode 100644 index f9cab61..0000000 --- a/posix_api/psx_sched_report/test.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Program to print POSIX Scheduler Characteristics - */ - -#include -#include -#include -#include - -void print_sched_info( - char *s, - int policy -) -{ - int min, max, levels; - struct timespec t; - - printf( "Information on %s\n", s ); - min = sched_get_priority_min( policy ); - max = sched_get_priority_max( policy ); - (void) sched_rr_get_interval( 1, &t ); - levels = max - min; - printf( "\tSupports %d priority levels (%d - %d)\n", levels, min, max ); - if ( levels >= 32 ) - printf( "\tImplementation is compliant on priority levels\n"); - else - printf( "\tImplementation is NOT compliant on priority levels\n" ); - - printf( "\tScheduling quantum is %ld seconds and %ld nanoseconds\n", - (long)t.tv_sec, (long)t.tv_nsec ); -} - -int main() -{ - print_sched_info( "SCHED_OTHER", SCHED_OTHER ); - print_sched_info( "SCHED_FIFO", SCHED_FIFO ); - print_sched_info( "SCHED_RR", SCHED_RR ); -#if defined(SCHED_SPORADIC) - print_sched_info( "SCHED_SPORADIC", SCHED_RR ); -#else - printf( "SCHED_SPORADIC is not supported\n" ); -#endif - - exit( 0 ); -} diff --git a/posix_api/psx_sched_report/wscript b/posix_api/psx_sched_report/wscript index 208b078..deca478 100644 --- a/posix_api/psx_sched_report/wscript +++ b/posix_api/psx_sched_report/wscript @@ -3,7 +3,6 @@ # This file's license is 2-clause BSD as in this distribution's LICENSE.2 file. # -# Waf build script for an RTEMS Hello import rtems_waf.rtems as rtems def build(bld): @@ -11,6 +10,6 @@ def build(bld): bld(features = 'c cprogram', target = 'psx_sched_report.exe', - source = ['test.c','rtems_config.c'], + source = ['psx_sched_report.c','rtems_config.c'], lib = ['c']) diff --git a/posix_api/wscript b/posix_api/wscript index d0fe38a..66a351f 100644 --- a/posix_api/wscript +++ b/posix_api/wscript @@ -10,5 +10,10 @@ def build(bld): bld.recurse('psx_example_1') bld.recurse('psx_example_2') bld.recurse('psx_example_3') + bld.recurse('psx_barrier_report') + bld.recurse('psx_condvar_report') + bld.recurse('psx_mqueue_report') + bld.recurse('psx_mutex_report') + bld.recurse('psx_pthread_report') + bld.recurse('psx_rwlock_report') bld.recurse('psx_sched_report') - -- cgit v1.2.3