diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2010-12-17 14:49:40 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2010-12-17 14:49:40 +0000 |
commit | abff6d226a55f3453b085c0d920e02973b971743 (patch) | |
tree | f5f15ca1e598f61d5ce78a01ce333e83d7c2f8af /tools/schedsim/shell/schedsim_priority | |
parent | 2010-12-16 Joel Sherrill <joel.sherrill@oarcorp.com> (diff) | |
download | rtems-abff6d226a55f3453b085c0d920e02973b971743.tar.bz2 |
2010-12-17 Joel Sherrill <joel.sherrill@oarcorp.com>
Jennifer Averett <jennifer.averett@oarcorp.com>
Add RTEMS Scheduler Simulator. This is the shell scripting portion.
* .cvsignore, ChangeLog, Makefile.am, schedsim_priority/.cvsignore,
schedsim_priority/Makefile.am, schedsim_priority/config.c,
schedsim_priority/printheir_executing.c,
schedsim_priority/schedsim.cc,
schedsim_priority/wrap_thread_dispatch.c, scripts/script01,
scripts/script02, scripts/script03, scripts/script04,
scripts/script05, scripts/script06, shared/.cvsignore,
shared/Makefile.am, shared/commands.c, shared/getopt.c,
shared/lookup_semaphore.c, shared/lookup_task.c,
shared/main_clocktick.c, shared/main_echo.c, shared/main_executing.c,
shared/main_heir.c, shared/main_help.c, shared/main_rtemsinit.c,
shared/main_semcreate.c, shared/main_semdelete.c,
shared/main_semflush.c, shared/main_semobtain.c,
shared/main_semrelease.c, shared/main_taskcreate.c,
shared/main_taskdelete.c, shared/main_taskmode.c,
shared/main_taskpriority.c, shared/main_taskresume.c,
shared/main_tasksuspend.c, shared/main_taskwakeafter.c,
shared/schedsim_shell.h, shared/shell_cmdset.c,
shared/shell_makeargs.c, shared/include/shell.h,
shared/include/newlib/_ansi.h, shared/include/newlib/getopt.h: New
files.
Diffstat (limited to '')
6 files changed, 283 insertions, 0 deletions
diff --git a/tools/schedsim/shell/schedsim_priority/.cvsignore b/tools/schedsim/shell/schedsim_priority/.cvsignore new file mode 100644 index 0000000000..282522db03 --- /dev/null +++ b/tools/schedsim/shell/schedsim_priority/.cvsignore @@ -0,0 +1,2 @@ +Makefile +Makefile.in diff --git a/tools/schedsim/shell/schedsim_priority/Makefile.am b/tools/schedsim/shell/schedsim_priority/Makefile.am new file mode 100644 index 0000000000..597cbefb16 --- /dev/null +++ b/tools/schedsim/shell/schedsim_priority/Makefile.am @@ -0,0 +1,32 @@ +## +## $Id$ +## + +bin_PROGRAMS = schedsim +schedsim_SOURCES = config.c \ + schedsim.cc wrap_thread_dispatch.c printheir_executing.c + +cpukitdir=$(srcdir)/../../../../cpukit +schedsim_CPPFLAGS = -I$(srcdir)/sched_cpu +schedsim_CPPFLAGS += -I$(srcdir)/../../rtems +schedsim_CPPFLAGS += -I$(cpukitdir)/include +schedsim_CPPFLAGS += -I$(cpukitdir)/score/include +schedsim_CPPFLAGS += -I$(cpukitdir)/score/inline +schedsim_CPPFLAGS += -I$(cpukitdir)/rtems/include +schedsim_CPPFLAGS += -I$(cpukitdir)/rtems/inline +schedsim_CPPFLAGS += -I$(cpukitdir)/sapi/include +schedsim_CPPFLAGS += -I$(cpukitdir)/sapi/inline +schedsim_CPPFLAGS += -I$(cpukitdir)/libcsupport/include +schedsim_CPPFLAGS += -I$(cpukitdir)/libmisc/stringto +schedsim_CPPFLAGS += -I$(srcdir)/../../rtems/sched_cpu +schedsim_CPPFLAGS += -I$(srcdir)/../shared/include +schedsim_CPPFLAGS += -I$(srcdir)/../shared + +schedsim_LDFLAGS =-Wl,--wrap=_Thread_Dispatch +## schedsim_LDADD +=-Wl,--start-group +schedsim_LDADD = ../shared/libschedsim.a +schedsim_LDADD += ../../rtems/librtems.a +schedsim_LDADD += ../shared/libschedsim.a +## schedsim_LDADD +=-Wl,--end-group + +include $(top_srcdir)/../../automake/host.am diff --git a/tools/schedsim/shell/schedsim_priority/config.c b/tools/schedsim/shell/schedsim_priority/config.c new file mode 100644 index 0000000000..227f912389 --- /dev/null +++ b/tools/schedsim/shell/schedsim_priority/config.c @@ -0,0 +1,7 @@ +#include <rtems.h> + +#define CONFIGURE_INIT +#define CONFIGURE_MAXIMUM_TASKS 1000 +#define CONFIGURE_MAXIMUM_SEMAPHORES 1000 +#include <confdefs.h> + diff --git a/tools/schedsim/shell/schedsim_priority/printheir_executing.c b/tools/schedsim/shell/schedsim_priority/printheir_executing.c new file mode 100644 index 0000000000..b0855d3fc4 --- /dev/null +++ b/tools/schedsim/shell/schedsim_priority/printheir_executing.c @@ -0,0 +1,31 @@ +/* + * printheir_executing + * + * COPYRIGHT (c) 1989-2010. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#include <stdio.h> +#include <rtems.h> + +void PRINT_EXECUTING() { + printf( + " Thread Executing: 0x%08x priority=%ld\n", + _Thread_Executing->Object.id, + (long) _Thread_Executing->current_priority + ); +} + +void PRINT_HEIR() { + printf( + " Thread Heir: 0x%08x priority=%ld\n", + _Thread_Heir->Object.id, + (long) _Thread_Heir->current_priority + ); +} diff --git a/tools/schedsim/shell/schedsim_priority/schedsim.cc b/tools/schedsim/shell/schedsim_priority/schedsim.cc new file mode 100644 index 0000000000..b70dd718ec --- /dev/null +++ b/tools/schedsim/shell/schedsim_priority/schedsim.cc @@ -0,0 +1,169 @@ +/* + * COPYRIGHT (c) 1989-2010. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#include <newlib/getopt.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <ctype.h> + +#include "shell.h" +#include "rtems_sched.h" + +/* + * Variables to control global behavior + */ +int verbose = 0; +const char *progname; +const char *scriptname; + +FILE *Script; +int ScriptFileLine = 0; + +/* + * Print program usage message + */ +void usage() +{ + fprintf( + stderr, + "Usage: %s [-v] script\n" + "\n" + " -v - enable verbose output\n", + progname + ); + exit( -1 ); +} + +#define RTEMS_SHELL_MAXIMUM_ARGUMENTS (128) + +void ProcessScript( + FILE *script +) +{ + char buffer[512]; + char *cStatus; + char *c; + size_t length; + int argc; + char *argv[RTEMS_SHELL_MAXIMUM_ARGUMENTS]; + rtems_shell_cmd_t *shell_cmd; + + + while ( 1 ) { + cStatus = fgets( buffer, sizeof(buffer), script ); + if ( cStatus == NULL ) + break; + + // If the last line does not have a CR, then we don't want to + // arbitrarily clobber an = instead of a \n. + length = strlen(buffer); + if ( buffer[ length - 1] == '\n' ) + buffer[ length - 1] = '\0'; + + if ( verbose ) + fprintf( stderr, "%d: %s\n", ++ScriptFileLine, buffer ); + + if ( buffer[0] == '#' ) + continue; + + for ( c = buffer ; *c ; c++ ) { + if (!isblank((int)*c)) + break; + } + + + if (!strcmp(c,"bye") || !strcmp(c,"exit")) { + return; + } + + if (rtems_shell_make_args(c, &argc, argv, RTEMS_SHELL_MAXIMUM_ARGUMENTS)) { + fprintf(stderr, "Error parsing arguments\n" ); + continue; + } + + shell_cmd = rtems_shell_lookup_cmd(argv[0]); + if ( !shell_cmd ) { + fprintf(stderr, "%s is unknown command\n", c ); + continue; + } + + shell_cmd->command(argc, argv); + } +} + +int main( + int argc, + char **argv +) +{ + int opt; + progname = argv[0]; + + while ((opt = getopt(argc, argv, "v")) != -1) { + switch (opt) { + case 'v': verbose = 1; break; + default: /* '?' */ + usage(); + } + } + + if ( optind >= argc ) { + fprintf( stderr, "no script to process\n" ); + usage(); + } + + scriptname = argv[ optind ]; + + if ( verbose ) { + fprintf( + stderr, + "Script File : %s\n" + "verbose : %d\n", + scriptname, + verbose + ); + } + + // + // Initialize the command interpreter + // + rtems_shell_initialize_command_set(); + + // + // Open the script file + // + Script = fopen( scriptname, "r" ); + if ( !Script ) { + fprintf( stderr, "Unable to open script file (%s)\n", scriptname ); + exit( -1 ); + } + + // + // Process the Script + // + ProcessScript( Script ); + + // + // Open the script file + // + (void) fclose( Script ); + + // + // Just in case something throws + // + try { + } catch (...) { + exit(-1); + } + + return 0; +} diff --git a/tools/schedsim/shell/schedsim_priority/wrap_thread_dispatch.c b/tools/schedsim/shell/schedsim_priority/wrap_thread_dispatch.c new file mode 100644 index 0000000000..3432188072 --- /dev/null +++ b/tools/schedsim/shell/schedsim_priority/wrap_thread_dispatch.c @@ -0,0 +1,42 @@ +/* + * Thread Dispatch Wrapper Implmentation + * + * COPYRIGHT (c) 1989-2010. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#include "shell.h" +#include <schedsim_shell.h> + +#include <stdio.h> +#include <rtems.h> + +Thread_Control *last_heir = NULL; +Thread_Control *last_executing = NULL; + +extern void __real__Thread_Dispatch(void); + +void check_heir_and_executing(void) +{ + if ( last_heir != _Thread_Heir ) + PRINT_HEIR(); + + if ( last_executing != _Thread_Executing ) + PRINT_EXECUTING(); + + last_heir = _Thread_Heir; + last_executing = _Thread_Executing; +} + +void __wrap__Thread_Dispatch(void) +{ + check_heir_and_executing(); + __real__Thread_Dispatch(); + check_heir_and_executing(); +} |