From 1324bafd0d2d8856e106bc8d929e2d36b47b2273 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Thu, 6 Aug 2009 21:26:29 +0000 Subject: 2009-08-06 Joel Sherrill * ChangeLog, Makefile, psx_example_1/Makefile, psx_example_1/test1.c, psx_example_2/Makefile, psx_example_2/test2.c, psx_example_3/Makefile, psx_example_3/test3.c, psx_sched_report/Makefile, psx_sched_report/README, psx_sched_report/test.c: New files. --- posix_api/ChangeLog | 13 ++++++ posix_api/Makefile | 12 +++++ posix_api/psx_example_1/Makefile | 29 ++++++++++++ posix_api/psx_example_1/test1.c | 46 +++++++++++++++++++ posix_api/psx_example_2/Makefile | 29 ++++++++++++ posix_api/psx_example_2/test2.c | 51 +++++++++++++++++++++ posix_api/psx_example_3/Makefile | 29 ++++++++++++ posix_api/psx_example_3/test3.c | 89 +++++++++++++++++++++++++++++++++++++ posix_api/psx_sched_report/Makefile | 44 ++++++++++++++++++ posix_api/psx_sched_report/README | 6 +++ posix_api/psx_sched_report/test.c | 68 ++++++++++++++++++++++++++++ 11 files changed, 416 insertions(+) create mode 100644 posix_api/ChangeLog create mode 100644 posix_api/Makefile create mode 100644 posix_api/psx_example_1/Makefile create mode 100644 posix_api/psx_example_1/test1.c create mode 100644 posix_api/psx_example_2/Makefile create mode 100644 posix_api/psx_example_2/test2.c create mode 100644 posix_api/psx_example_3/Makefile create mode 100644 posix_api/psx_example_3/test3.c create mode 100644 posix_api/psx_sched_report/Makefile create mode 100644 posix_api/psx_sched_report/README create mode 100644 posix_api/psx_sched_report/test.c (limited to 'posix_api') diff --git a/posix_api/ChangeLog b/posix_api/ChangeLog new file mode 100644 index 0000000..466b983 --- /dev/null +++ b/posix_api/ChangeLog @@ -0,0 +1,13 @@ +2009-08-06 Joel Sherrill + + * ChangeLog, Makefile, psx_example_1/Makefile, psx_example_1/test1.c, + psx_example_2/Makefile, psx_example_2/test2.c, + psx_example_3/Makefile, psx_example_3/test3.c, + psx_sched_report/Makefile, psx_sched_report/README, + psx_sched_report/test.c: New files. + +2009-08-06 Joel Sherrill + + * ChangeLog, Makefile, psx_sched_report/Makefile, + psx_sched_report/README, psx_sched_report/test.c: New files. + diff --git a/posix_api/Makefile b/posix_api/Makefile new file mode 100644 index 0000000..c247972 --- /dev/null +++ b/posix_api/Makefile @@ -0,0 +1,12 @@ +# +# $Id$ +# + +include $(RTEMS_MAKEFILE_PATH)/Makefile.inc +include $(RTEMS_CUSTOM) +include $(RTEMS_ROOT)/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 +endif diff --git a/posix_api/psx_example_1/Makefile b/posix_api/psx_example_1/Makefile new file mode 100644 index 0000000..cbe498f --- /dev/null +++ b/posix_api/psx_example_1/Makefile @@ -0,0 +1,29 @@ +# +# Makefile +# + +# +# RTEMS_MAKEFILE_PATH is typically set in an environment variable +# + +PGM=${ARCH}/psx_example_1.exe + +# optional managers required +MANAGERS=all + +# C source names +CSRCS = test1.c +COBJS_ = $(CSRCS:.c=.o) +COBJS = $(COBJS_:%=${ARCH}/%) + +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_example_1/test1.c b/posix_api/psx_example_1/test1.c new file mode 100644 index 0000000..4c26bbc --- /dev/null +++ b/posix_api/psx_example_1/test1.c @@ -0,0 +1,46 @@ +/* + * $Id$ + */ + +#include +#include +#include +#include +#include + +void * print_hello(void * arg) +{ + sleep(1); + printf(": Hello World!\n"); + return NULL; +} + +void *POSIX_Init() +{ + pthread_t child1; + pthread_t child2; + int status; + + status = pthread_create( &child1, NULL, print_hello, NULL ); + if ( status ) perror("Error on create child 1"); + + status = pthread_create( &child2, NULL, print_hello, NULL ); + if ( status ) perror("Error on create child 1"); + + printf("
: Wait for child2 thread...\n"); + + status = pthread_join( child1, NULL ); + if ( status ) perror ("Error on join"); + printf("
: Successfully joined with child1\n" ); + exit(0); +} + +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER + +#define CONFIGURE_MAXIMUM_POSIX_THREADS 10 +#define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 10 +#define CONFIGURE_MAXIMUM_POSIX_MUTEXES 10 +#define CONFIGURE_POSIX_INIT_THREAD_TABLE +#define CONFIGURE_INIT +#include diff --git a/posix_api/psx_example_2/Makefile b/posix_api/psx_example_2/Makefile new file mode 100644 index 0000000..689b1e1 --- /dev/null +++ b/posix_api/psx_example_2/Makefile @@ -0,0 +1,29 @@ +# +# Makefile +# + +# +# RTEMS_MAKEFILE_PATH is typically set in an environment variable +# + +PGM=${ARCH}/psx_example_2.exe + +# optional managers required +MANAGERS=all + +# C source names +CSRCS = test2.c +COBJS_ = $(CSRCS:.c=.o) +COBJS = $(COBJS_:%=${ARCH}/%) + +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_example_2/test2.c b/posix_api/psx_example_2/test2.c new file mode 100644 index 0000000..61d5795 --- /dev/null +++ b/posix_api/psx_example_2/test2.c @@ -0,0 +1,51 @@ +/* + * $Id$ + */ + +#include +#include +#include +#include +#include + +pthread_mutex_t mutex; +pthread_cond_t cond; + +void * print_hello(void * arg) +{ + struct timeval time; + struct timespec timeout; + + gettimeofday(&time, NULL); + timeout.tv_sec = time.tv_sec + 2; + timeout.tv_nsec = time.tv_usec * 1000; + printf(": Hello World coming to wait!\n"); + + if (pthread_cond_timedwait(&cond, &mutex, &timeout)) + perror ("Error on pthread_cond_timedwait"); + + printf(": Hello World exit to wait!\n"); + return NULL; +} + +int *POSIX_Init() +{ + pthread_t child; + if ( pthread_create( &child, NULL, print_hello, NULL )) + perror("Error on pthread_create"); + printf("
: Wait for child thread...\n"); + if ( pthread_join( child, NULL )) + perror("Error on pthread_join"); + return 0; +} + +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER + +#define CONFIGURE_MAXIMUM_POSIX_THREADS 10 +#define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 10 +#define CONFIGURE_MAXIMUM_POSIX_MUTEXES 10 +#define CONFIGURE_POSIX_INIT_THREAD_TABLE + +#define CONFIGURE_INIT +#include diff --git a/posix_api/psx_example_3/Makefile b/posix_api/psx_example_3/Makefile new file mode 100644 index 0000000..2f2d4b3 --- /dev/null +++ b/posix_api/psx_example_3/Makefile @@ -0,0 +1,29 @@ +# +# Makefile +# + +# +# RTEMS_MAKEFILE_PATH is typically set in an environment variable +# + +PGM=${ARCH}/psx_example_3.exe + +# optional managers required +MANAGERS=all + +# C source names +CSRCS = test3.c +COBJS_ = $(CSRCS:.c=.o) +COBJS = $(COBJS_:%=${ARCH}/%) + +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_example_3/test3.c b/posix_api/psx_example_3/test3.c new file mode 100644 index 0000000..7d5e9ac --- /dev/null +++ b/posix_api/psx_example_3/test3.c @@ -0,0 +1,89 @@ +/* + * $Id$ + */ +#include +#include +#include +#include +#include + + pthread_mutex_t mutex; + pthread_cond_t cond; + struct timespec timeout; + struct sched_param param; + pthread_attr_t attr; + +void * print_hello(void * arg) +{ + printf(": Hello World! task with max priority \n"); + clock_gettime( CLOCK_REALTIME, &timeout ); + timeout.tv_sec += 3; + timeout.tv_nsec = 0; + printf("The task is coming to enter in a timed wait\n"); + pthread_cond_timedwait(&cond, &mutex, &timeout); + printf("The task is coming out from the timed wait \n"); + return NULL; +} + +void * print_hello_a(void * arg) +{ + printf(" : Hello World! Task with lowest priority "); + return NULL; +} + + +void *POSIX_Init() +{ + pthread_t child1; + pthread_t child2; + + pthread_attr_init(&attr); + pthread_attr_setschedpolicy(&attr, SCHED_FIFO); + pthread_mutex_init( &mutex, NULL ); + pthread_cond_init( &cond, NULL ); + + printf("
Enter in the main \n"); + + printf("Creating first task \n"); + param.sched_priority = sched_get_priority_max(SCHED_FIFO); + pthread_attr_setschedparam(&attr, ¶m); + if ( pthread_create( &child1, &attr, print_hello, NULL) || + pthread_setschedparam(child1, SCHED_FIFO, ¶m) ) { + printf( + "Thread cannot be created or you have not enough privileges \n" + " to set priority!!!!\n"); + exit(1); + } + + printf("First Task created \n"); + printf("Creating second task \n"); + param.sched_priority = sched_get_priority_max(SCHED_FIFO) - 1; + pthread_attr_setschedparam(&attr, ¶m); + if ( pthread_create( &child2, &attr, print_hello_a, NULL) || + pthread_setschedparam(child2, SCHED_FIFO, ¶m) ) { + printf( + "Thread cannot be created or you have not enough privileges \n" + " to set priority!!!!\n"); + exit(1); + } + printf("Second task created \n"); + + printf("
Out of the main\n"); + pthread_join( child1, NULL ); + pthread_join( child2, NULL ); + + exit(0); +} +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER + +#define CONFIGURE_MAXIMUM_POSIX_THREADS 10 +#define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 10 +#define CONFIGURE_MAXIMUM_POSIX_MUTEXES 10 +#define CONFIGURE_POSIX_INIT_THREAD_TABLE + +#define CONFIGURE_INIT +#include + + + diff --git a/posix_api/psx_sched_report/Makefile b/posix_api/psx_sched_report/Makefile new file mode 100644 index 0000000..96dd47f --- /dev/null +++ b/posix_api/psx_sched_report/Makefile @@ -0,0 +1,44 @@ +# +# Makefile +# + +# +# RTEMS_MAKEFILE_PATH is typically set in an environment variable +# + +EXEC=psx_sched_report.exe +PGM=${ARCH}/$(EXEC) + +# optional managers required +MANAGERS=all + +# 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 + +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_sched_report/README b/posix_api/psx_sched_report/README new file mode 100644 index 0000000..381066a --- /dev/null +++ b/posix_api/psx_sched_report/README @@ -0,0 +1,6 @@ +# +# README for POSIX Scheduling information test +# + +Prints some POSIX scheduling information and reports compliancy on +some issues. diff --git a/posix_api/psx_sched_report/test.c b/posix_api/psx_sched_report/test.c new file mode 100644 index 0000000..8d0b9b3 --- /dev/null +++ b/posix_api/psx_sched_report/test.c @@ -0,0 +1,68 @@ +/* + * Simple test program -- simplified version of sample test hello. + */ + +#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 ); +} + + +#if defined(__rtems__) + #include + +rtems_task Init( + rtems_task_argument ignored +) +#else +int main() +#endif +{ + print_sched_info( "SCHED_OTHER", SCHED_OTHER ); + print_sched_info( "SCHED_FIFO", SCHED_FIFO ); + print_sched_info( "SCHED_RR", SCHED_RR ); + + exit( 0 ); +} + +#if defined(__rtems__) +/* configuration information */ + +/* NOTICE: the clock driver is explicitly disabled */ +#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER + +#define CONFIGURE_RTEMS_INIT_TASKS_TABLE +#define CONFIGURE_MICROSECONDS_PER_TICK 1000 +#define CONFIGURE_TICKS_PER_TIMESLICE 1 +#define CONFIGURE_MAXIMUM_TASKS 1 + +#define CONFIGURE_INIT + +#include +#endif + +/* end of file */ -- cgit v1.2.3