Update of /cvsroot/ltp/ltp/testcases/realtime/func/async_handler In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv18188/ltp/testcases/realtime/func/async_handler Added Files: GNUmakefile.am GNUmakefile.in async_handler.c async_handler_jk.c async_handler_tsc.c run_auto.sh Log Message: Initial Set of Real Time Linux Test Cases, by Nivedita Singhvi <ni...@us...> & sudhanshu Singh <sud...@in...> --- NEW FILE: GNUmakefile.am --- if HAVE_PTHREAD_MUTEXATTR_SETPROTOCOL bin_PROGRAMS = \ async_handler \ async_handler_jk \ async_handler_tsc endif AM_CPPFLAGS = \ -I$(top_srcdir)/include \ -I$(top_builddir)/include \ -I$(DESTDIR)/usr/include/nptl AM_CFLAGS = \ -O2 \ -D_GNU_SOURCE LDADD = \ $(top_builddir)/lib/libjvmsim.a \ $(top_builddir)/lib/librttest.a \ $(top_builddir)/lib/libstats.a AM_LDFLAGS = \ -lpthread -lrt -lm MAINTAINERCLEANFILES = \ GNUmakefile.in --- NEW FILE: async_handler_tsc.c --- /****************************************************************************** * * Copyright International Business Machines Corp., 2007 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See * the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * NAME * async_handler_tsc.c * * DESCRIPTION * Measure the latency involved with asynchronous event handlers. * Specifically it measures the latency of the pthread_cond_signal * call until the signalled thread is scheduled. * * USAGE: * Use run_auto.sh script in current directory to build and run test. * Use "-j" to enable jvm simulator. * * Compilation: gcc -O2 -g -D_GNU_SOURCE -I/usr/include/nptl -I ../../include * -L/usr/lib/nptl -lpthread -lrt -lm async_handler_tsc.c -o async_handler_tsc * * AUTHOR * Darren Hart <dv...@us...> * * HISTORY * 2006-Oct-20: Initial version by Darren Hart <dv...@us...> * *****************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <math.h> #include <stdint.h> #include <librttest.h> #include <libjvmsim.h> #include <libstats.h> #define SIGNAL_PRIO 98 #define HANDLER_PRIO 99 #define ITERATIONS 10000000 #define HIST_BUCKETS 100 #define PASS_US 100 nsec_t start; nsec_t end; unsigned long long tsc_period; /* in picoseconds */ int over_20 = 0; int over_25 = 0; int over_30 = 0; #define CHILD_START 0 #define CHILD_WAIT 1 #define CHILD_HANDLED 2 #define CHILD_QUIT 3 atomic_t step; pthread_cond_t cond = PTHREAD_COND_INITIALIZER; pthread_mutex_t mutex; #define ULL_MAX 18446744073709551615ULL // (1 << 64) - 1 #if defined(__i386__) #define rdtscll(val) __asm__ __volatile__("rdtsc" : "=A" (val)) #elif defined(__x86_64__) #define rdtscll(val) \ do { \ uint32_t low, high; \ __asm__ __volatile__ ("rdtsc" : "=a" (low), "=d" (high)); \ val = (uint64_t)high << 32 | low; \ } while(0) #elif defined(__powerpc__) /* 32bit version */ #define rdtscll(val) \ do { \ uint32_t tbhi, tblo ; \ __asm__ __volatile__ ("mftbu %0" : "=r" (tbhi)); \ __asm__ __volatile__ ("mftbl %0" : "=r" (tblo)); \ val = 1000 * ((uint64_t) tbhi << 32) | tblo; \ } while(0) #else #error #endif static int run_jvmsim=0; void usage(void) { rt_help(); printf("async_handler_tsc specific options:\n"); printf(" -j enable jvmsim\n"); } int parse_args(int c, char *v) { int handled = 1; switch (c) { case 'j': run_jvmsim = 1; break; case 'h': usage(); exit(0); default: handled = 0; break; } return handled; } /* return difference in microseconds */ unsigned long long tsc_minus(unsigned long long tsc_start, unsigned long long tsc_end) { unsigned long long delta; if (tsc_start < tsc_end) delta = tsc_end - tsc_start; else { delta = ULL_MAX - (tsc_end - tsc_start) + 1; printf("TSC wrapped, delta=%llu\n", delta); } return delta; } /* calculate the tsc period */ unsigned long long tsc_period_ps(void) { nsec_t ns_start; nsec_t ns_end; unsigned long long tsc_start, tsc_end; rdtscll(tsc_start); ns_start = rt_gettime(); sleep(1); rdtscll(tsc_end); ns_end = rt_gettime(); return (1000*(ns_end - ns_start)) / tsc_minus(tsc_start, tsc_end); } void *signal_thread(void *arg) { // struct thread *t = (struct thread *)arg; while (atomic_get(&step) != CHILD_QUIT) { pthread_mutex_lock(&mutex); atomic_set(CHILD_WAIT, &step); if (pthread_cond_wait(&cond, &mutex) != 0) { perror("pthead_cond_wait"); break; } rdtscll(end); atomic_set(CHILD_HANDLED, &step); pthread_mutex_unlock(&mutex); while (atomic_get(&step) == CHILD_HANDLED) usleep(10); } printf("handler thread exiting\n"); return NULL; } void *handler_thread(void *arg) { // struct thread *t = (struct thread *)arg; int i; long delta, max, min; stats_container_t dat; stats_container_t hist; stats_container_init(&dat, ITERATIONS); stats_container_init(&hist, HIST_BUCKETS); min = max = 0; for (i = 0; i < ITERATIONS; i++) { /* wait for child to wait on cond, then signal the event */ while (atomic_get(&step) != CHILD_WAIT) usleep(10); pthread_mutex_lock(&mutex); rdtscll(start); pthread_mutex_unlock(&mutex); if (pthread_cond_signal(&cond) != 0) { perror("pthread_cond_signal"); atomic_set(CHILD_QUIT, &step); break; } /* wait for the event handler to schedule */ while (atomic_get(&step) != CHILD_HANDLED) usleep(10); pthread_mutex_lock(&mutex); delta = (long)(tsc_period * (end - start) / 1000000); if (delta > 30) { over_30++; } else if (delta > 25) { over_25++; } else if (delta > 20) { over_20++; } dat.records[i].x = i; dat.records[i].y = delta; if (i == 0) min = max = delta; else { min = MIN(min, delta); max = MAX(max, delta); } atomic_set((i == ITERATIONS-1) ? CHILD_QUIT : CHILD_START, &step); pthread_mutex_unlock(&mutex); } printf("recording statistics...\n"); printf("Minimum: %ld\n", min); printf("Maximum: %ld\n", max); printf("Average: %f\n", stats_avg(&dat)); printf("Standard Deviation: %f\n", stats_stddev(&dat)); stats_hist(&hist, &dat); stats_container_save("samples", "Asynchronous Event Handling Latency (TSC) Scatter Plot",\ "Iteration", "Latency (us)", &dat, "points"); stats_container_save("hist", "Asynchronous Event Handling Latency (TSC) Histogram",\ "Iteration", "Latency (us)", &hist, "steps"); printf("signal thread exiting\n"); return NULL; } int main(int argc, char *argv[]) { int signal_id, handler_id; setup(); rt_init("jh", parse_args, argc, argv); printf("-------------------------------\n"); printf("Asynchronous Event Handling Latency\n"); printf("-------------------------------\n\n"); printf("Running %d iterations\n", ITERATIONS); printf("Calculating tsc period..."); fflush(stdout); tsc_period = tsc_period_ps(); printf("%llu ps\n", tsc_period); init_pi_mutex(&mutex); atomic_set(CHILD_START, &step); if (run_jvmsim) { printf("jvmsim enabled\n"); jvmsim_init(); // Start the JVM simulation } else { printf("jvmsim disabled\n"); } handler_id = create_fifo_thread(handler_thread, (void*)0, HANDLER_PRIO); signal_id = create_fifo_thread(signal_thread, (void*)0, SIGNAL_PRIO); join_thread(signal_id); join_threads(); printf("%d samples over 20 us latency\n", over_20); printf("%d samples over 25 us latency\n", over_25); printf("%d samples over 30 us latency\n", over_30); return 0; } --- NEW FILE: async_handler.c --- /****************************************************************************** * * Copyright International Business Machines Corp., 2007 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See * the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * NAME * async_handler.c * * DESCRIPTION * Measure the latency involved in asynchronous event handlers. * Specifically it measures the latency of the pthread_cond_signal * call until the signalled thread is scheduled. * * USAGE: * Use run_auto.sh script in current directory to build and run test. * Use "-j" to enable jvm simulator. * * Compilation: gcc -O2 -g -D_GNU_SOURCE -I/usr/include/nptl -I ../../include * -L/usr/lib/nptl -lpthread -lrt -lm async_handler.c -o async_handler * * AUTHOR * Darren Hart <dv...@us...> * * HISTORY * 2006-Oct-20: Initial version by Darren Hart <dv...@us...> * *****************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <math.h> #include <librttest.h> #include <libjvmsim.h> #include <libstats.h> #include <getopt.h> #define SIGNAL_PRIO 89 #define HANDLER_PRIO 89 #define DEFAULT_ITERATIONS 5000 /* about 1 minute @ 2GHz */ #define HIST_BUCKETS 100 #define PASS_US 100 static nsec_t start; static nsec_t end; static int iterations = 0; static int run_jvmsim = 0; #define CHILD_START 0 #define CHILD_WAIT 1 #define CHILD_HANDLED 2 #define CHILD_QUIT 3 atomic_t step; pthread_cond_t cond = PTHREAD_COND_INITIALIZER; pthread_mutex_t mutex; static int ret = 0; void usage(void) { rt_help(); printf("async_handler specific options:\n"); printf(" -j enable jvmsim\n"); printf(" -iITERATIONS number of iterations to calculate the average over\n"); } int parse_args(int c, char *v) { int handled = 1; switch (c) { case 'j': run_jvmsim = 1; break; case 'h': usage(); exit(0); case 'i': iterations = atoi(v); break; default: handled = 0; break; } return handled; } void *signal_thread(void *arg) { // struct thread *t = (struct thread *)arg; while (atomic_get(&step) != CHILD_QUIT) { pthread_mutex_lock(&mutex); atomic_set(CHILD_WAIT, &step); if (pthread_cond_wait(&cond, &mutex) != 0) { perror("pthead_cond_wait"); break; } end = rt_gettime(); atomic_set(CHILD_HANDLED, &step); pthread_mutex_unlock(&mutex); while (atomic_get(&step) == CHILD_HANDLED) usleep(10); } printf("handler thread exiting\n"); return 0; } void *handler_thread(void *arg) { int i; long delta, max, min; stats_container_t dat; stats_container_t hist; stats_container_init(&dat, iterations); stats_container_init(&hist, HIST_BUCKETS); min = max = 0; for (i = 0; i < iterations; i++) { /* wait for child to wait on cond, then signal the event */ while (atomic_get(&step) != CHILD_WAIT) usleep(10); pthread_mutex_lock(&mutex); start = rt_gettime(); pthread_mutex_unlock(&mutex); if (pthread_cond_signal(&cond) != 0) { perror("pthread_cond_signal"); atomic_set(CHILD_QUIT, &step); break; } /* wait for the event handler to schedule */ while (atomic_get(&step) != CHILD_HANDLED) usleep(10); pthread_mutex_lock(&mutex); delta = (long)((end - start)/NS_PER_US); if (delta > PASS_US) ret = 1; dat.records[i].x = i; dat.records[i].y = delta; if (i == 0) min = max = delta; else { min = MIN(min, delta); max = MAX(max, delta); } atomic_set((i == iterations-1) ? CHILD_QUIT : CHILD_START, &step); pthread_mutex_unlock(&mutex); } printf("recording statistics...\n"); printf("Min: %ld us\n", min); printf("Max: %ld us\n", max); printf("Avg: %.4f us\n", stats_avg(&dat)); printf("StdDev: %.4f us\n", stats_stddev(&dat)); stats_hist(&hist, &dat); stats_container_save("samples", "Asynchronous Event Handling Latency Scatter Plot",\ "Iteration", "Latency (us)", &dat, "points"); stats_container_save("hist", "Asynchronous Event Handling Latency Histogram",\ "Iteration", "Latency (us)", &hist, "steps"); printf("signal thread exiting\n"); return NULL; } int main(int argc, char *argv[]) { int signal_id, handler_id; setup(); printf("\n-----------------------------------\n"); printf("Asynchronous Event Handling Latency\n"); printf("-----------------------------------\n\n"); rt_init("ji:h", parse_args, argc, argv); init_pi_mutex(&mutex); atomic_set(CHILD_START, &step); if (run_jvmsim) { printf("jvmsim enabled\n"); jvmsim_init(); // Start the JVM simulation } else { printf("jvmsim disabled\n"); } if (iterations == 0) iterations = DEFAULT_ITERATIONS; printf("Running %d iterations\n", iterations); handler_id = create_fifo_thread(handler_thread, (void*)0, HANDLER_PRIO); signal_id = create_fifo_thread(signal_thread, (void*)0, SIGNAL_PRIO); join_thread(signal_id); join_threads(); printf("\nCriteria: latencies < %d\n", PASS_US); printf("Result: %s\n", ret ? "FAIL" : "PASS"); return ret; } --- NEW FILE: GNUmakefile.in --- # GNUmakefile.in generated by automake 1.9.6 from GNUmakefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, # 2003, 2004, 2005 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. @SET_MAKE@ srcdir = @srcdir@ top_srcdir = @top_srcdir@ VPATH = @srcdir@ pkgdatadir = $(datadir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ top_builddir = ../.. am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd INSTALL = @INSTALL@ install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c install_sh_SCRIPT = $(install_sh) -c INSTALL_HEADER = $(INSTALL_DATA) transform = $(program_transform_name) NORMAL_INSTALL = : PRE_INSTALL = : POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ @HAVE_PTHREAD_MUTEXATTR_SETPROTOCOL_TRUE@bin_PROGRAMS = async_handler$(EXEEXT) \ @HAVE_PTHREAD_MUTEXATTR_SETPROTOCOL_TRUE@ async_handler_jk$(EXEEXT) \ @HAVE_PTHREAD_MUTEXATTR_SETPROTOCOL_TRUE@ async_handler_tsc$(EXEEXT) subdir = func/async_handler DIST_COMMON = $(srcdir)/GNUmakefile.am $(srcdir)/GNUmakefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/include/rttests_config.h CONFIG_CLEAN_FILES = am__installdirs = "$(DESTDIR)$(bindir)" binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) PROGRAMS = $(bin_PROGRAMS) async_handler_SOURCES = async_handler.c async_handler_OBJECTS = async_handler.$(OBJEXT) async_handler_LDADD = $(LDADD) async_handler_DEPENDENCIES = $(top_builddir)/lib/libjvmsim.a \ $(top_builddir)/lib/librttest.a $(top_builddir)/lib/libstats.a async_handler_jk_SOURCES = async_handler_jk.c async_handler_jk_OBJECTS = async_handler_jk.$(OBJEXT) async_handler_jk_LDADD = $(LDADD) async_handler_jk_DEPENDENCIES = $(top_builddir)/lib/libjvmsim.a \ $(top_builddir)/lib/librttest.a $(top_builddir)/lib/libstats.a async_handler_tsc_SOURCES = async_handler_tsc.c async_handler_tsc_OBJECTS = async_handler_tsc.$(OBJEXT) async_handler_tsc_LDADD = $(LDADD) async_handler_tsc_DEPENDENCIES = $(top_builddir)/lib/libjvmsim.a \ $(top_builddir)/lib/librttest.a $(top_builddir)/lib/libstats.a DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/include depcomp = $(SHELL) $(top_srcdir)/config/autoconf/depcomp am__depfiles_maybe = depfiles COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) CCLD = $(CC) LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ SOURCES = async_handler.c async_handler_jk.c async_handler_tsc.c DIST_SOURCES = async_handler.c async_handler_jk.c async_handler_tsc.c ETAGS = etags CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMDEP_FALSE = @AMDEP_FALSE@ AMDEP_TRUE = @AMDEP_TRUE@ AMTAR = @AMTAR@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ EXEEXT = @EXEEXT@ GREP = @GREP@ HAVE_PTHREAD_MUTEXATTR_SETPROTOCOL_FALSE = @HAVE_PTHREAD_MUTEXATTR_SETPROTOCOL_FALSE@ HAVE_PTHREAD_MUTEXATTR_SETPROTOCOL_TRUE = @HAVE_PTHREAD_MUTEXATTR_SETPROTOCOL_TRUE@ HAVE_PTHREAD_MUTEXATTR_SETROBUST_NP_FALSE = @HAVE_PTHREAD_MUTEXATTR_SETROBUST_NP_FALSE@ HAVE_PTHREAD_MUTEXATTR_SETROBUST_NP_TRUE = @HAVE_PTHREAD_MUTEXATTR_SETROBUST_NP_TRUE@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LDFLAGS = @LDFLAGS@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ LTLIBOBJS = @LTLIBOBJS@ MAINT = @MAINT@ MAINTAINER_MODE_FALSE = @MAINTAINER_MODE_FALSE@ MAINTAINER_MODE_TRUE = @MAINTAINER_MODE_TRUE@ MAKEINFO = @MAKEINFO@ OBJEXT = @OBJEXT@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ RANLIB = @RANLIB@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ VERSION = @VERSION@ ac_ct_CC = @ac_ct_CC@ am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ am__tar = @am__tar@ am__untar = @am__untar@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ build_cpu = @build_cpu@ build_os = @build_os@ build_vendor = @build_vendor@ datadir = @datadir@ datarootdir = @datarootdir@ docdir = @docdir@ dvidir = @dvidir@ exec_prefix = @exec_prefix@ host = @host@ host_alias = @host_alias@ host_cpu = @host_cpu@ host_os = @host_os@ host_vendor = @host_vendor@ htmldir = @htmldir@ includedir = @includedir@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ AM_CPPFLAGS = \ -I$(top_srcdir)/include \ -I$(top_builddir)/include \ -I$(DESTDIR)/usr/include/nptl AM_CFLAGS = \ -O2 \ -D_GNU_SOURCE LDADD = \ $(top_builddir)/lib/libjvmsim.a \ $(top_builddir)/lib/librttest.a \ $(top_builddir)/lib/libstats.a AM_LDFLAGS = \ -lpthread -lrt -lm MAINTAINERCLEANFILES = \ GNUmakefile.in all: all-am .SUFFIXES: .SUFFIXES: .c .o .obj $(srcdir)/GNUmakefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/GNUmakefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ && exit 0; \ exit 1;; \ esac; \ done; \ echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign func/async_handler/GNUmakefile'; \ cd $(top_srcdir) && \ $(AUTOMAKE) --foreign func/async_handler/GNUmakefile .PRECIOUS: GNUmakefile GNUmakefile: $(srcdir)/GNUmakefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ *) \ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh install-binPROGRAMS: $(bin_PROGRAMS) @$(NORMAL_INSTALL) test -z "$(bindir)" || $(mkdir_p) "$(DESTDIR)$(bindir)" @list='$(bin_PROGRAMS)'; for p in $$list; do \ p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ if test -f $$p \ ; then \ f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \ echo " $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(bindir)/$$f'"; \ $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(bindir)/$$f" || exit 1; \ else :; fi; \ done uninstall-binPROGRAMS: @$(NORMAL_UNINSTALL) @list='$(bin_PROGRAMS)'; for p in $$list; do \ f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \ echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \ rm -f "$(DESTDIR)$(bindir)/$$f"; \ done clean-binPROGRAMS: -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) async_handler$(EXEEXT): $(async_handler_OBJECTS) $(async_handler_DEPENDENCIES) @rm -f async_handler$(EXEEXT) $(LINK) $(async_handler_LDFLAGS) $(async_handler_OBJECTS) $(async_handler_LDADD) $(LIBS) async_handler_jk$(EXEEXT): $(async_handler_jk_OBJECTS) $(async_handler_jk_DEPENDENCIES) @rm -f async_handler_jk$(EXEEXT) $(LINK) $(async_handler_jk_LDFLAGS) $(async_handler_jk_OBJECTS) $(async_handler_jk_LDADD) $(LIBS) async_handler_tsc$(EXEEXT): $(async_handler_tsc_OBJECTS) $(async_handler_tsc_DEPENDENCIES) @rm -f async_handler_tsc$(EXEEXT) $(LINK) $(async_handler_tsc_LDFLAGS) $(async_handler_tsc_OBJECTS) $(async_handler_tsc_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/async_handler.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/async_handler_jk.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/async_handler_tsc.Po@am__quote@ .c.o: @am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ @am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(COMPILE) -c $< .c.obj: @am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \ @am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` uninstall-info-am: ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ $(AWK) ' { files[$$0] = 1; } \ END { for (i in files) print i; }'`; \ mkid -fID $$unique tags: TAGS TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ $(TAGS_FILES) $(LISP) tags=; \ here=`pwd`; \ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ $(AWK) ' { files[$$0] = 1; } \ END { for (i in files) print i; }'`; \ if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ test -n "$$unique" || unique=$$empty_fix; \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ $$tags $$unique; \ fi ctags: CTAGS CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ $(TAGS_FILES) $(LISP) tags=; \ here=`pwd`; \ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ $(AWK) ' { files[$$0] = 1; } \ END { for (i in files) print i; }'`; \ test -z "$(CTAGS_ARGS)$$tags$$unique" \ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ $$tags $$unique GTAGS: here=`$(am__cd) $(top_builddir) && pwd` \ && cd $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) $$here distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags distdir: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ list='$(DISTFILES)'; for file in $$list; do \ case $$file in \ $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ esac; \ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ if test "$$dir" != "$$file" && test "$$dir" != "."; then \ dir="/$$dir"; \ $(mkdir_p) "$(distdir)$$dir"; \ else \ dir=''; \ fi; \ if test -d $$d/$$file; then \ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ fi; \ cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ else \ test -f $(distdir)/$$file \ || cp -p $$d/$$file $(distdir)/$$file \ || exit 1; \ fi; \ done check-am: all-am check: check-am all-am: GNUmakefile $(PROGRAMS) installdirs: for dir in "$(DESTDIR)$(bindir)"; do \ test -z "$$dir" || $(mkdir_p) "$$dir"; \ done install: install-am install-exec: install-exec-am install-data: install-data-am uninstall: uninstall-am install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am installcheck: installcheck-am install-strip: $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ `test -z '$(STRIP)' || \ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install mostlyclean-generic: clean-generic: distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." -test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES) clean: clean-am clean-am: clean-binPROGRAMS clean-generic mostlyclean-am distclean: distclean-am -rm -rf ./$(DEPDIR) -rm -f GNUmakefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-tags dvi: dvi-am dvi-am: html: html-am info: info-am info-am: install-data-am: install-exec-am: install-binPROGRAMS install-info: install-info-am install-man: installcheck-am: maintainer-clean: maintainer-clean-am -rm -rf ./$(DEPDIR) -rm -f GNUmakefile maintainer-clean-am: distclean-am maintainer-clean-generic mostlyclean: mostlyclean-am mostlyclean-am: mostlyclean-compile mostlyclean-generic pdf: pdf-am pdf-am: ps: ps-am ps-am: uninstall-am: uninstall-binPROGRAMS uninstall-info-am .PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \ clean-generic ctags distclean distclean-compile \ distclean-generic distclean-tags distdir dvi dvi-am html \ html-am info info-am install install-am install-binPROGRAMS \ install-data install-data-am install-exec install-exec-am \ install-info install-info-am install-man install-strip \ installcheck installcheck-am installdirs maintainer-clean \ maintainer-clean-generic mostlyclean mostlyclean-compile \ mostlyclean-generic pdf pdf-am ps ps-am tags uninstall \ uninstall-am uninstall-binPROGRAMS uninstall-info-am # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: --- NEW FILE: run_auto.sh --- #! /bin/bash if [ ! $SCRIPTS_DIR ]; then # assume we're running standalone export SCRIPTS_DIR=../../scripts/ fi source $SCRIPTS_DIR/setenv.sh $SCRIPTS_DIR/run_c_files.sh "async_handler" $SCRIPTS_DIR/run_c_files.sh "async_handler_jk" # The async_handler_tsc test is off by default for now. #$SCRIPTS_DIR/run_c_files.sh "async_handler_tsc " --- NEW FILE: async_handler_jk.c --- /****************************************************************************** * * Copyright International Business Machines Corp., 2007 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See * the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * NAME * async_handler_jk.c * * DESCRIPTION * This test mimics an async event handler in a real-time JVM * An async event server thread is created that goes to sleep waiting * to be woken up to do some work. * * A user thread is created that simulates the firing of an event by * signalling the async handler thread to do some work. * * USAGE: * Use run_auto.sh script in current directory to build and run test. * Use "-j" to enable jvm simulator. * * Compilation: gcc -O2 -g -D_GNU_SOURCE -I/usr/include/nptl -I ../../include * -L/usr/lib/nptl -lpthread -lrt -lm async_handler_jk.c -o async_handler_jk * * AUTHOR * John Kacur <jk...@ca...> * * HISTORY * 2006-Nov-20: Initial Version by John Kacur <jk...@ca...> * *****************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <math.h> #include <librttest.h> #include <libjvmsim.h> #include <libstats.h> // This is the normal priority for an event handler if not specified. #define NORMAL_PRIORITY 43 #define THREAD_FLAG_SUSPENDED 8 #define PASS_US 100 long start, end; static int run_jvmsim = 0; /* Function Prototypes */ void *async_event_server(void *arg); void *handler1(void *arg); void usage(void) { rt_help(); printf("async_handler_jk specific options:\n"); printf(" -j enable jvmsim\n"); } int parse_args(int c, char *v) { int handled = 1; switch (c) { case 'j': run_jvmsim = 1; break; case 'h': usage(); exit(0); default: handled = 0; break; } return handled; } void *async_event_server(void *arg) { int err=0; struct thread *thread = ((struct thread *)arg); thread->func = NULL; // entrypoint thread->flags |= THREAD_FLAG_SUSPENDED; for ( ; ; ) { if ((err = pthread_mutex_lock(&thread->mutex))) return (void*)(intptr_t)err; /* Go to sleep and wait for work */ while (thread->flags & THREAD_FLAG_SUSPENDED) pthread_cond_wait(&thread->cond, &thread->mutex); pthread_mutex_unlock(&thread->mutex); /* The JVM would be able to dynamically choose a handler */ thread->func = handler1; if (thread->func != NULL) thread->func(arg); // Reset Priority to original async server priority set_thread_priority(thread->pthread, thread->priority); thread->flags |= THREAD_FLAG_SUSPENDED; } // Go back to sleep and wait for next command } void *user_thread(void *arg) { struct thread *thread = ((struct thread *)arg); struct thread *server = (struct thread*)thread->arg; start = rt_gettime(); /* Change the async server thread priority to be the priority of the user_thread. (event thread) */ set_thread_priority(server->pthread, thread->priority); /* Clear the THREAD_FLAG_SUSPENDED flag of the server before signal */ server->flags &= ~THREAD_FLAG_SUSPENDED; /* Signal the async server thread - simulates firing of an event */ pthread_cond_broadcast(&server->cond); return NULL; } void *handler1(void *arg) { end = rt_gettime(); return NULL; } int main(int argc, char* argv[]) { int aes_id; // asynchronous event server id int user_id; // User thread - that fires the event long delta; struct thread *server; setup(); rt_init("jh", parse_args, argc, argv); if (run_jvmsim) { printf("jvmsim enabled\n"); jvmsim_init(); // Start the JVM simulation } else { printf("jvmsim disabled\n"); } aes_id = create_fifo_thread(async_event_server, (void*)0, 83); server = get_thread(aes_id); user_id = create_fifo_thread(user_thread, (void*)server, NORMAL_PRIORITY); usleep(1000); pthread_detach(server->pthread); join_thread(user_id); join_threads(); delta = (end - start)/NS_PER_US; printf("delta = %ld us\n", delta); printf("\nCriteria: latencies < %d\n", PASS_US); printf("Result: %s\n", delta > PASS_US ? "FAIL" : "PASS"); return 0; } |