diff -NurBb rtlinux-3.1-orig/Makefile rtlinux-3.1-posixtrace/Makefile --- rtlinux-3.1-orig/Makefile 2001-07-26 21:32:41.000000000 +0200 +++ rtlinux-3.1-posixtrace/Makefile 2002-08-21 16:19:29.000000000 +0200 @@ -126,6 +126,10 @@ endif endif +ifdef CONFIG_POSIX_TRACING +EXAMPLE_DIRS += posixtrace/only-rtl posixtrace/rtl-and-linux posixtrace/ktrace-test +endif + ifeq ($(CONFIG_PSC),y) MODULE_DIRS += psc endif @@ -148,6 +152,10 @@ endif endif +ifdef CONFIG_POSIX_TRACING +MODULE_DIRS += posixtrace +endif + MODULE_DIRS += regression CFLAGS += -D__RTL__ -D_LOOSE_KERNEL_NAMES @@ -373,6 +381,7 @@ @-mkdir -p $(MOD_INSTDIR) @-mkdir -p $(DESTDIR)/lib/modules/$(KERNELRELEASE)/misc/ @echo "Instaling modules in" $(MOD_INSTDIR) + @rm -f $(MOD_INSTDIR)/*.o @for mod in modules/*.o ; do \ install -c -m 644 $$mod $(MOD_INSTDIR); \ ln -sf $(IDIR)/modules/`basename $$mod` $(DESTDIR)/lib/modules/$(KERNELRELEASE)/misc/`basename $$mod`; \ Binary files rtlinux-3.1-orig/examples/misc/print_app and rtlinux-3.1-posixtrace/examples/misc/print_app differ diff -NurBb rtlinux-3.1-orig/examples/posixtrace/ktrace-test/Makefile rtlinux-3.1-posixtrace/examples/posixtrace/ktrace-test/Makefile --- rtlinux-3.1-orig/examples/posixtrace/ktrace-test/Makefile 1970-01-01 01:00:00.000000000 +0100 +++ rtlinux-3.1-posixtrace/examples/posixtrace/ktrace-test/Makefile 2002-09-18 18:08:33.000000000 +0200 @@ -0,0 +1,70 @@ +all: rtl_tasks.o + +clean: + rm -f *.o ktrace.* *~ + +include ../../../rtl.mk + +ifneq ($(ARCH),mips) +LIBGCC := $(shell $(CC) -print-libgcc-file-name) +else +LIBGCC = libgcc.o +libgcc.o: mips/libgcc2.c + $(CC) $(CFLAGS) -DCROSS_COMPILE -DIN_GCC -I./include -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED -I. -c -DL_muldi3 mips/libgcc2.c -o libgcc.o +endif + +LDFLAGS=-d + + + + +rtl_tasks.o : rtl_tasks.c + @(echo "************** COMPILING rtl_tasks *********************") + gcc -c -o rtl_tasks.o ${CFLAGS} ${INCLUDE} rtl_tasks.c + + + + + +test: all + @echo "examples/ktrace-test" + @echo "(C) 2002 A. Terrasa, A. Garcia-Fornes, A. Espinosa" + @echo "" + @echo "This program is an example of the RTL-POSIXTRACE 1.0 support." + @echo "It makes some real-time tasks to run and automatically collects" + @echo "system events by using the kernel trace (ktrace) facility." + @echo "See README file for details" + @echo "" + @echo "First we remove any existing rtl-modules" + @echo "You may see error warnings from \"make\" - ignore them" + @echo "Type to continue" + @sync + @read junk + @rm -f ktrace* output + @rtlinux stop + @echo "" + @echo "Start rt-modules and the kernel trace" + @rtlinux start + @./../../../posixtrace/ktrace_analyzer --debug ktrace & + @echo "" + @echo "Start the RT-Linux tasks and the Linux apps" + @insmod rtl_tasks.o + @echo "" + @echo "Now sleep for a while..." + @for i in 5 4 3 2 1; \ + do echo -n "$$i"; echo -n "..."; sleep 2; \ + done; echo "Awaking!" + @echo "" + @echo "Stop the RT-Linux tasks" + @sync + @rmmod rtl_tasks + @rmmod rtl_ktrace + @rtlinux stop + @echo "" + @echo "Done!" + @echo "" + + + + + diff -NurBb rtlinux-3.1-orig/examples/posixtrace/ktrace-test/README rtlinux-3.1-posixtrace/examples/posixtrace/ktrace-test/README --- rtlinux-3.1-orig/examples/posixtrace/ktrace-test/README 1970-01-01 01:00:00.000000000 +0100 +++ rtlinux-3.1-posixtrace/examples/posixtrace/ktrace-test/README 2002-09-18 17:50:30.000000000 +0200 @@ -0,0 +1,46 @@ +-------------------------------------------------------------------- + FILE: + examples/posixtrace/ktrace-test/README + + Copyright (C) 2002 + Ana Garcia Fornes + Andres Terrasa Barrena + Ignacio Paches Giner + Agustin Espinosa Minguet +-------------------------------------------------------------------- + + + This directory contains another examples of use of the POSIX tracing +support implemented in RT-Linux. The examples contained in this +directory are specially intended to test the automatic collecting +of kernel events. None of the examples actually creates more trace +streams or traces any user events. + + + The directory is composed of a bunch of potential source files, +each one creating different number of rt-tasks and using different +resources (mutexes, mainly). + + + In order to run any of them, rename it as 'rtl_tasks.c' (or create a +symbolic link of it named rtl_tasks.c). Then, type 'make' to build the +object file and 'make test' to execute it. + + + After running any of the examples, two output files are available: + + - ktrace.tra : system trace events collected by the + ktrace_analyzer application in 'quivi' format. + 'quivi' is a graphical tool for displaying traces. + (Type 'quivi ktrace.tra &' and enjoy! :) + + - ktrace.dbg : human-readable (textual) format of + the kernel (system) trace events automatically + collected by the ktrace_analyzer application. + + + + + + + diff -NurBb rtlinux-3.1-orig/examples/posixtrace/ktrace-test/rtl_tasks-2.c rtlinux-3.1-posixtrace/examples/posixtrace/ktrace-test/rtl_tasks-2.c --- rtlinux-3.1-orig/examples/posixtrace/ktrace-test/rtl_tasks-2.c 1970-01-01 01:00:00.000000000 +0100 +++ rtlinux-3.1-posixtrace/examples/posixtrace/ktrace-test/rtl_tasks-2.c 2002-08-21 16:19:29.000000000 +0200 @@ -0,0 +1,128 @@ +/* + FILE: + rtl_tasks.c + + DESCRIPTION: + RT-Linux side of a sample application using the POSIX trace + support. + + See README file for details. + + Copyright (C) 2001 + Ana Garcia Fornes + Andres Terrasa Barrena + Ignacio Paches Giner + Agustin Espinosa Minguet + + This is free software; you can redistribute it and/or modify it under + terms of the GNU General Public License as published by the Free Soft- + ware Foundation; either version 2, or (at your option) any later ver- + sion. It is distributed in the hope that it will be useful, but WITH- + OUT 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; see file COPYING. If not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + LAST REVISION: + November 2001 + +*/ + +#include +#include +#include +#include +#include +#include + + + +static pthread_mutex_t mutex; +static pthread_t thr1, thr2; + + + +void *just_execute(void *task_period) { + int i; + int j; + //int nloops; + long period; + struct timespec next_period; + + period = (long) task_period; + + clock_gettime(CLOCK_MONOTONIC, &next_period); + timespec_add_ns(&next_period, period); + + for (i=0; i<100; i++) { + + for (j=0; j +#include +#include +#include +#include +#include + + + +static pthread_mutex_t mutex, mutex2; +static pthread_t thr1, thr2, thr3, thr4; + + +void *just_execute1(void *task_period) { + int i; + int j; + //int nloops; + long period; + struct timespec next_period; + + period = (long) task_period; + + clock_gettime(CLOCK_MONOTONIC, &next_period); + + for (i=0; i<100; i++) { + timespec_add_ns(&next_period, period); + clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &next_period, NULL); + + for (j=0; j +#include +#include +#include +#include +#include + + + +static pthread_mutex_t mutex; +static pthread_t thr1, thr2, thr3, thr4, thr5, thr6, thr7, thr8; + + +void *just_execute(void *task_period) { + int i; + int j; + //int nloops; + long period; + struct timespec next_period; + + period = (long) task_period; + + clock_gettime(CLOCK_MONOTONIC, &next_period); + timespec_add_ns(&next_period, period); + + for (i=0; i<100; i++) { + + for (j=0; j +#include +#include +#include +#include +#include + + + +static pthread_mutex_t mutex; +static pthread_t thr1, thr2, thr3, thr4, thr5, thr6, thr7, thr8; + + +void *just_execute(void *task_period) { + int i; + int j; + //int nloops; + long period; + struct timespec next_period; + + period = (long) task_period; + + clock_gettime(CLOCK_MONOTONIC, &next_period); + timespec_add_ns(&next_period, period); + + for (i=0; i<100; i++) { + + for (j=0; j +#include +#include +#include +#include +#include + + + +static pthread_mutex_t mutex; +static pthread_t thr1, thr2, thr3, thr4, thr5, thr6, thr7, thr8; + + +void *just_execute(void *task_period) { + int i; + int j; + //int nloops; + long period; + struct timespec next_period; + + period = (long) task_period; + + clock_gettime(CLOCK_MONOTONIC, &next_period); + + for (i=0; i<100; i++) { + timespec_add_ns(&next_period, period); + clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &next_period, NULL); + + for (j=0; j +#include +#include +#include +#include +#include + + + +static pthread_mutex_t mutex, mutex2; +static pthread_t thr1, thr2, thr3, thr4, thr5, thr6, thr7, thr8; + + +void *just_execute(void *task_period) { + int i; + int j; + //int nloops; + long period; + struct timespec next_period; + + period = (long) task_period; + + clock_gettime(CLOCK_MONOTONIC, &next_period); + + for (i=0; i<100; i++) { + timespec_add_ns(&next_period, period); + clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &next_period, NULL); + + for (j=0; j to continue" + @sync + @read junk + @rm -f ktrace* + @rtlinux stop + @echo "" + @echo "Start rt-modules and the kernel trace" + @rtlinux start + @./../../../posixtrace/ktrace_analyzer --debug ktrace & + @echo "" + @echo "Start the RT-Linux tasks" + @insmod rtl_tasks.o + @echo "" + @echo "Now sleep for a while..." + @for i in 5 4 3 2 1; \ + do echo -n "$$i"; echo -n "..."; sleep 2; \ + done; echo "Awaking!" + @echo "" + @echo "Stop the RT-Linux tasks" + @sync + @rmmod rtl_tasks + @rmmod rtl_ktrace + @rtlinux stop + @echo "" + @echo "Done!" + @echo "" + + + + +#include $(RTL_DIR)/Rules.make + diff -NurBb rtlinux-3.1-orig/examples/posixtrace/only-rtl/README rtlinux-3.1-posixtrace/examples/posixtrace/only-rtl/README --- rtlinux-3.1-orig/examples/posixtrace/only-rtl/README 1970-01-01 01:00:00.000000000 +0100 +++ rtlinux-3.1-posixtrace/examples/posixtrace/only-rtl/README 2002-08-30 19:59:57.000000000 +0200 @@ -0,0 +1,55 @@ +-------------------------------------------------------------------- + FILE: + examples/posixtrace/only-rtl/README + + Copyright (C) 2002 + Ana Garcia Fornes + Andres Terrasa Barrena + Ignacio Paches Giner + Agustin Espinosa Minguet +-------------------------------------------------------------------- + + + This directory contains a full example of use of the POSIX tracing +support implemented in RT-Linux. It only tests the tracing support +from the RT-Linux side. You must be on the (text) console to see +something happening! + + + Type 'make' to build the example and 'make test' to execute it. + + + The example is composed of one source file: + + - rtl_tasks.c : Creates three new user event types and a + trace stream and then starts five rt-tasks. Among them, + three periodically execute and just consume CPU, another + one periodically wakes up and trace these events, and + the last one waits until a new event is available and + then retrieves it and writes its contents to the console. + + In addition, the implemented POSIX trace support collects +(implementation-defined) system trace events (such as context +switching between rtl-tasks, mutex locking and unlocking, etc.). +These events are retrieved by means of an application called +ktrace_analyzer.c, which is automatically invoked when running the +example. + + + After running the example, two output files are available: + + - ktrace.tra : system trace events collected by the + ktrace_analyzer application in 'quivi' format. + 'quivi' is a graphical tool for displaying traces. + (Type 'quivi ktrace.tra &' and enjoy! :) + + - ktrace.dbg : human-readable (textual) format of + the kernel (system) trace events automatically + collected by the ktrace_analyzer application. + + + + + + + diff -NurBb rtlinux-3.1-orig/examples/posixtrace/only-rtl/rtl_tasks.c rtlinux-3.1-posixtrace/examples/posixtrace/only-rtl/rtl_tasks.c --- rtlinux-3.1-orig/examples/posixtrace/only-rtl/rtl_tasks.c 1970-01-01 01:00:00.000000000 +0100 +++ rtlinux-3.1-posixtrace/examples/posixtrace/only-rtl/rtl_tasks.c 2002-09-18 17:40:35.000000000 +0200 @@ -0,0 +1,303 @@ +/* + FILE: + rtl_tasks.c + + DESCRIPTION: + RT-Linux side of a sample application using the POSIX trace + support. + + See README file for details. + + Copyright (C) 2001 + Ana Garcia Fornes + Andres Terrasa Barrena + Ignacio Paches Giner + Agustin Espinosa Minguet + + This is free software; you can redistribute it and/or modify it under + terms of the GNU General Public License as published by the Free Soft- + ware Foundation; either version 2, or (at your option) any later ver- + sion. It is distributed in the hope that it will be useful, but WITH- + OUT 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; see file COPYING. If not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + LAST REVISION: + September 2001 + +*/ + +#include +#include +#include +#include +#include +#include + +//#define DEBUG + +static trace_id_t trid; +static trace_event_id_t ev_char, ev_int, ev_string; +static pthread_t thr1, thr2, thr3, thr4, thr5; + +static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; + + + +void *writer(void *dummy) { + int i; + int j; + char s[164] ="hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!hello world!\0"; + char c; + int k; + void *data; + + // Create a new event type: + posix_trace_eventid_open ("user event string", &ev_string); + c = 'A'; + k = 0; + + for (i=0; i<30; i++) { + pthread_wait_np(); + + for (j=0; j<80000; j++); + + pthread_mutex_lock(&mutex); + + data = (void *) & c; + posix_trace_event(ev_char, data, sizeof(char)); + data = (void *) & k; + posix_trace_event(ev_int, data, sizeof(int)); + + for (j=0; j<80000; j++); + + posix_trace_event(ev_string, s, sizeof(s)); + + // Values for next loop: + c += 1; + k += 1; + + pthread_mutex_unlock(&mutex); + for (j=0; j<80000; j++); + } + return (void *) 0; +} + + + + + +void *just_execute(void *loops) { + int i; + int j; + int nloops; + + nloops = (int) loops; + + for (i=0; i<100; i++) { + pthread_wait_np(); + + for (j=0; j to continue" + @sync + @read junk + @rm -f ktrace* output + @rtlinux stop + @echo "" + @echo "Start rt-modules and the kernel trace" + @rtlinux start + @./../../../posixtrace/ktrace_analyzer --debug ktrace & + @echo "" + @echo "Start the RT-Linux tasks and the Linux apps" + @insmod rtl_tasks.o + @./linux_target & + @./linux_analyzer 2>analyzer_output & + @echo "" + @echo "Now sleep for a while..." + @for i in 5 4 3 2 1; \ + do echo -n "$$i"; echo -n "..."; sleep 2; \ + done; echo "Awaking!" + @echo "" + @echo "Stop the RT-Linux tasks" + @sync + @rmmod rtl_tasks + @rmmod rtl_ktrace + @echo "" + @echo "Done!" + @echo "" + + + +#include $(RTL_DIR)/Rules.make + diff -NurBb rtlinux-3.1-orig/examples/posixtrace/rtl-and-linux/README rtlinux-3.1-posixtrace/examples/posixtrace/rtl-and-linux/README --- rtlinux-3.1-orig/examples/posixtrace/rtl-and-linux/README 1970-01-01 01:00:00.000000000 +0100 +++ rtlinux-3.1-posixtrace/examples/posixtrace/rtl-and-linux/README 2002-08-30 20:02:03.000000000 +0200 @@ -0,0 +1,65 @@ +-------------------------------------------------------------------- + FILE: + examples/posixtrace/rtl-and-linux/README + + Copyright (C) 2002 + Ana Garcia Fornes + Andres Terrasa Barrena + Ignacio Paches Giner + Agustin Espinosa Minguet +-------------------------------------------------------------------- + + + This directory contains a full example of use of the POSIX tracing +support implemented in RT-Linux. + + + Type 'make' to build the example and 'make test' to execute it. + + + The example is composed of three source files: + + - rtl_tasks.c : Creates three new user event types and a + trace stream and then starts two periodic rt-tasks, one of + which just consumes CPU while the other trace these events. + + - linux_target.c : Creates two user event types (one new + and another already registered by rtl_tasks.c) and + periodically executes and traces both events. + + - linux_analyzer.c : Opens the trace stream created by + rtl_tasks.c and retrieves (and prints) all the information + about this stream (status, event types, etc.). Then, it + starts retrieving all the events traced in such stream by + both rtl_tasks.c and linux_target.c. This information is + printed in standard output, which is redirected to the + analyzer_output file. + + + In addition, the implemented POSIX trace support collects +(implementation-defined) system trace events (such as context +switching between rtl-tasks, mutex locking and unlocking, etc.). +These events are retrieved by means of an application called +ktrace_analyzer.c, which is automatically invoked when running the +example. + + + After running the example, three output files are available: + + - ktrace.tra : system trace events collected by the + ktrace_analyzer application in 'quivi' format. + 'quivi' is a graphical tool for displaying traces. + (Type 'quivi ktrace.tra &' and enjoy! :) + + - ktrace.dbg : human-readable (textual) format of + the kernel (system) trace events automatically + collected by the ktrace_analyzer application. + + - analyzer_output : contains the output of the + linux_analyzer.c application. + + + + + + diff -NurBb rtlinux-3.1-orig/examples/posixtrace/rtl-and-linux/linux_analyzer.c rtlinux-3.1-posixtrace/examples/posixtrace/rtl-and-linux/linux_analyzer.c --- rtlinux-3.1-orig/examples/posixtrace/rtl-and-linux/linux_analyzer.c 1970-01-01 01:00:00.000000000 +0100 +++ rtlinux-3.1-posixtrace/examples/posixtrace/rtl-and-linux/linux_analyzer.c 2002-09-10 17:49:27.000000000 +0200 @@ -0,0 +1,200 @@ +/* + FILE: + linux_analyzer.c + + DESCRIPTION: + Linux side of a sample application using the POSIX trace + support. This Linux program retrieves all the information + (and the user trace events) from the stream created by the + RT-Linux part (rtl_tasks.c). + + See README file for details. + + Copyright (C) 2001 + Ana Garcia Fornes + Andres Terrasa Barrena + Ignacio Paches Giner + Agustin Espinosa Minguet + + This is free software; you can redistribute it and/or modify it under + terms of the GNU General Public License as published by the Free Soft- + ware Foundation; either version 2, or (at your option) any later ver- + sion. It is distributed in the hope that it will be useful, but WITH- + OUT 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; see file COPYING. If not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + LAST REVISION: + September 2001 + +*/ + + +#include +#include +#include + + +#define MAX_DATA_SIZE 256 + + +int main(void) { + + char data[MAX_DATA_SIZE]; + char str[TRACE_NAME_MAX]; + size_t data_len; + size_t size; + int unavailable; + int pol; + int error; + trace_event_id_t ev; + trace_attr_t trace_attr; + trace_id_t trace_id; + struct posix_trace_event_info event; + struct posix_trace_status_info status; + struct timespec time; + int *i; + char *c; + + + // Create (open) **the same** trace stream already created in + // rtl_tasks.c + posix_trace_attr_init(&trace_attr); + posix_trace_attr_setname(&trace_attr, TRACE_STREAM1_NAME); + error = posix_trace_create(0,&trace_attr,&trace_id); + + if(error) { + fprintf(stderr,"ERROR %d while creating stream %s\n", error, + TRACE_STREAM1_NAME); + exit(1); + } + + + // Retrieve the attributes of this stream and print all the info: + error = posix_trace_get_attr(trace_id, &trace_attr); + fprintf(stderr, "get attr (%d)\n", error); + + error = posix_trace_attr_getgenversion(&trace_attr, str); + fprintf(stderr, "get genversion (%d): %s\n", error, str); + + error = posix_trace_attr_getname(&trace_attr, str); + fprintf(stderr, "get name (%d): %s\n", error, str); + + error = posix_trace_attr_getcreatetime(&trace_attr, &time); + fprintf(stderr, "get create time (%d): %ld.%ld\n", error, + time.tv_sec, time.tv_nsec); + + error = posix_trace_attr_getclockres(&trace_attr, &time); + fprintf(stderr, "get clock res (%d): %ld.%ld\n", error, + time.tv_sec, time.tv_nsec); + + error = posix_trace_attr_getstreamfullpolicy(&trace_attr, &pol); + fprintf(stderr, "get full policy (%d): %d\n", error, pol); + + error = posix_trace_attr_getmaxusereventsize(&trace_attr, 0, &size); + fprintf(stderr, "get max user event size (%d): %d\n", error, size); + + error = posix_trace_attr_getmaxsystemeventsize(&trace_attr, &size); + fprintf(stderr, "get max system event size (%d): %d\n", error, size); + + error = posix_trace_attr_getmaxdatasize(&trace_attr, &size); + fprintf(stderr, "get max data size (%d): %d\n", error, size); + + error = posix_trace_attr_getstreamsize(&trace_attr, &size); + fprintf(stderr, "get stream size (%d): %d\n", error, size); + + + // Print the full list of event types available in the stream: + + error = posix_trace_eventtypelist_rewind(trace_id); + fprintf(stderr, "event list rewind (%d)\n", error); + + error = posix_trace_eventtypelist_getnext_id (trace_id, &ev, &unavailable); + while( ! unavailable && ! error) { + + error = posix_trace_eventid_get_name (trace_id, ev, str); + + if (! error) { + fprintf(stderr, "event getname (%d): %s\n", error, str); + } + // Get the next one: + error = posix_trace_eventtypelist_getnext_id (trace_id, &ev, + &unavailable); + } + + + // Print the current status of the stream : + error = posix_trace_get_status(trace_id, &status); + fprintf(stderr, "event get status (%d): %d %d %d \n", error, + status.posix_stream_status, status.posix_stream_full_status, + status.posix_stream_overrun_status); + + + + + // Start retrieving events while the stream is open: + fprintf(stderr, "\n\nNow retrieving events: \n"); + + + while(1) { + + error = posix_trace_getnext_event(trace_id, &event, &data, sizeof(data), + &data_len, &unavailable); + + if(error) { + fprintf(stderr,"No more events (%d). Exiting\n", error); + exit(0); + + } else if (unavailable) { + fprintf(stderr, " Event unavailable\n"); + + } else { + + fprintf(stderr, " ** New event ----------------------------------\n"); + fprintf(stderr, " Event identifier = %d\n", event.posix_event_id); + fprintf(stderr, " Process ID = %d\n", event.posix_pid); + fprintf(stderr, " Address = %x\n", (int) event.posix_prog_address); + fprintf(stderr, " Truncation status= %d\n", event.posix_truncation_status); + fprintf(stderr, " Timestamp = %ld.%9ld\n", event.posix_timestamp.tv_sec, event.posix_timestamp.tv_nsec); + fprintf(stderr, " Thread ID = %d\n", (int) event.posix_thread_id); + + posix_trace_eventid_get_name (trace_id, event.posix_event_id, str); + fprintf(stderr, " Event Name = %s\n", str); + + // Now switch depending on the event type (name): + if (!strcmp(str,"user event char")) { + c = (char *) data; + fprintf(stderr, " Data (char) = %c\n", *c); + } + + else if (!strcmp(str,"user event int")) { + i = (int *) data; + fprintf(stderr, " Data (int) = %d\n", *i); + } + + else if (!strcmp(str,"user event string")) { + fprintf(stderr, " Data (string) = %s\n", (char *) data); + + } + + else if (!strcmp(str,"user event linux")) { + i = (int *) data; + fprintf(stderr, " Data (int) = %d\n", *i); + } + + else { + fprintf(stderr, " Data unknown\n" ); + } + + fprintf(stderr, " Data length = %d\n", data_len); + fprintf(stderr, " -----------------------------------------------\n\n"); + } + + } + + return 0; + + +} diff -NurBb rtlinux-3.1-orig/examples/posixtrace/rtl-and-linux/linux_target.c rtlinux-3.1-posixtrace/examples/posixtrace/rtl-and-linux/linux_target.c --- rtlinux-3.1-orig/examples/posixtrace/rtl-and-linux/linux_target.c 1970-01-01 01:00:00.000000000 +0100 +++ rtlinux-3.1-posixtrace/examples/posixtrace/rtl-and-linux/linux_target.c 2002-09-10 17:46:43.000000000 +0200 @@ -0,0 +1,100 @@ +/* + FILE: + linux_target.c + + DESCRIPTION: + Linux side of a sample application using the POSIX trace + support. This Linux program also traces events into the + active stream(s) that the RT-Linux side has created. + + See README file for details. + + Copyright (C) 2001 + Ana Garcia Fornes + Andres Terrasa Barrena + Ignacio Paches Giner + Agustin Espinosa Minguet + + This is free software; you can redistribute it and/or modify it under + terms of the GNU General Public License as published by the Free Soft- + ware Foundation; either version 2, or (at your option) any later ver- + sion. It is distributed in the hope that it will be useful, but WITH- + OUT 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; see file COPYING. If not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + LAST REVISION: + September 2001 + +*/ + +#include +#include +#include + +#include + + + +//#define DEBUG + + + +#define NTIMES 30 + + +void timer_handler(int dummy) { + return; +} + + +int main(void) { + + int ntimes; + trace_event_id_t ev_linux; + trace_event_id_t ev_string; + void *data; + char s[32] = "Linux says: Hello world!"; + struct itimerval timeout; + struct sigaction action; + + // Create a new type of event: + posix_trace_eventid_open ("user event linux", &ev_linux); + + // Register an event type which has been created in RT-Linux + posix_trace_eventid_open ("user event string", &ev_string); + + + // Initialize the timeout value (oneshot, 500 ms): + timeout.it_interval.tv_sec = 0; + timeout.it_interval.tv_usec = 0; + timeout.it_value.tv_sec = 0; + timeout.it_value.tv_usec = 500000; + + sigfillset(&(action.sa_mask)); + sigdelset(&(action.sa_mask), SIGALRM); + action.sa_handler = timer_handler; + sigaction(SIGALRM,&action,NULL); + + + // Enter the main loop: trace this event and sleep for a timeout: + for (ntimes = 0; ntimes < NTIMES; ntimes ++) { + +#ifdef DEBUG + fprintf(stderr, "linux_target: Tracing value %d\n", ntimes); +#endif + + data = (void *) & ntimes; + posix_trace_event(ev_linux, data, sizeof(int)); + + posix_trace_event(ev_string, s, sizeof(s)); + + setitimer(ITIMER_REAL,&timeout,NULL); + pause(); + } + + return 0; + +} diff -NurBb rtlinux-3.1-orig/examples/posixtrace/rtl-and-linux/rtl_tasks.c rtlinux-3.1-posixtrace/examples/posixtrace/rtl-and-linux/rtl_tasks.c --- rtlinux-3.1-orig/examples/posixtrace/rtl-and-linux/rtl_tasks.c 1970-01-01 01:00:00.000000000 +0100 +++ rtlinux-3.1-posixtrace/examples/posixtrace/rtl-and-linux/rtl_tasks.c 2002-09-18 17:37:59.000000000 +0200 @@ -0,0 +1,208 @@ +/* + FILE: + rtl_tasks.c + + DESCRIPTION: + RT-Linux side of a sample application using the POSIX trace + support. + + See README file for details. + + Copyright (C) 2001 + Ana Garcia Fornes + Andres Terrasa Barrena + Ignacio Paches Giner + Agustin Espinosa Minguet + + This is free software; you can redistribute it and/or modify it under + terms of the GNU General Public License as published by the Free Soft- + ware Foundation; either version 2, or (at your option) any later ver- + sion. It is distributed in the hope that it will be useful, but WITH- + OUT 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; see file COPYING. If not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + LAST REVISION: + September 2001 + +*/ + +#include +#include +#include +#include +#include +#include + + +static trace_id_t trid; +static trace_event_id_t ev_char, ev_int, ev_string; +static pthread_t thr1, thr2, thr3, thr4; + +static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; + + + +void *writer(void *dummy) { + int i; + int j; + char s[32] = "RT-Linux says: Hello world!"; + char c; + int k; + void *data; + + // Create some new event types: + posix_trace_eventid_open ("user event string", &ev_string); + posix_trace_eventid_open ("user event char", &ev_char); + posix_trace_eventid_open ("user event int", &ev_int); + + // Initialize data to be recorded along with the events + c = 'A'; + k = 0; + + + for (i=0; i<50; i++) { + + pthread_mutex_lock(&mutex); + + // Trace the "user event char" event and consume some CPU: + data = (void *) & c; + posix_trace_event(ev_char, data, sizeof(char)); + c += 1; + for (j=0; j<40000; j++) ; + + // Trace the "user event int" event and consume some CPU: + data = (void *) & k; + posix_trace_event(ev_int, data, sizeof(int)); + k += 1; + for (j=0; j<40000; j++) ; + + // Trace the "user event string" event and consume some CPU: + posix_trace_event(ev_string, s, sizeof(s)); + for (j=0; j<40000; j++) ; + + pthread_mutex_unlock(&mutex); + + // Consume some more CPU and go to sleep until next period: + for (j=0; j<40000; j++) ; + pthread_wait_np(); + } + return (void *) 0; +} + + + + + +void *just_execute(void *loops) { + int i; + int j; + int nloops; + + nloops = (int) loops; + + for (i=0; i<100; i++) { + + pthread_wait_np(); + + for (j=0; j +#else +#include +#endif + + +#include "trace_options.h" // Which options are currently supported + + + + +/* + NOTE: + This header file is mostly ordered and labelled according to the + POSIX "P1003.1q: Tracing" standard document. +*/ + + +/* + 2.8.2. Minimum values +*/ +#define _POSIX_TRACE_SYS_MAX 8 +#define _POSIX_TRACE_USER_EVENT_MAX 32 +#define _POSIX_TRACE_NAME_MAX 64 +#define _POSIX_TRACE_EVENT_NAME_MAX 30 + + + + +/* + 24.2. Data definitions +*/ + +// 24.2.1.2. posix_trace_event_info needs this: +typedef int _trace_event_id_t; + + +// 24.2.2 Trace stream attributes +typedef struct { + int magic; // Magic number + + char generation_version[_POSIX_TRACE_NAME_MAX]; + // Origin and version of the trace system + + char trace_name[_POSIX_TRACE_NAME_MAX]; + // Identification of the trace stream + struct timespec + creation_time; // Stream creation time. + struct timespec + clock_resolution; // Timestamps clock resolution + size_t stream_min_size; // User-defined stream minimum size + size_t max_data_size; // User-defined event maximum data size + size_t data_size; // Real maximum data size of any event; + size_t header_size; // Size of the event header (to make Linux know) + int stream_full_policy; // Policy when the stream becomes full +#ifdef _TRACE_INHERITANCE + int inheritance; // Inheritance policy +#endif +#ifdef _TRACE_LOG + size_t log_max_size; // Maximum size (bytes) of the stream's log + int log_full_policy; // Policy when the log becomes full +#endif +} _trace_attr_t; + + + + + + +/* + Implementation-dependent data definitions +*/ + +typedef int _trace_id_t; + + +#define _POSIX_TRACE_SYSTEM_EVENT_MAX 32 + +#define _POSIX_TRACE_EVENT_MAX (_POSIX_TRACE_USER_EVENT_MAX + \ + _POSIX_TRACE_SYSTEM_EVENT_MAX) + +typedef char bool; + +#define TRUE (char) 1 +#define FALSE (char) 0 + +//typedef short int _trace_event_set_t[_POSIX_TRACE_EVENT_MAX]; +typedef bool _trace_event_set_t[_POSIX_TRACE_EVENT_MAX]; + + + + + + + + + +#endif // #ifndef __TRACE_POSIX_TRACE_H diff -NurBb rtlinux-3.1-orig/include/posix/trace/trace_options.h rtlinux-3.1-posixtrace/include/posix/trace/trace_options.h --- rtlinux-3.1-orig/include/posix/trace/trace_options.h 1970-01-01 01:00:00.000000000 +0100 +++ rtlinux-3.1-posixtrace/include/posix/trace/trace_options.h 2002-08-21 16:19:29.000000000 +0200 @@ -0,0 +1,55 @@ +/* + FILE: + trace/trace_options.h + + DESCRIPTION: + Establishes which tracing options are currently supported. + + Copyright (C) 2002 + Ana Garcia Fornes + Andres Terrasa Barrena + Ignacio Paches Giner + Agustin Espinosa Minguet + + This is free software; you can redistribute it and/or modify it under + terms of the GNU General Public License as published by the Free Soft- + ware Foundation; either version 2, or (at your option) any later ver- + sion. It is distributed in the hope that it will be useful, but WITH- + OUT 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; see file COPYING. If not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + LAST REVISION: + April 2002 + +*/ + +#ifndef __TRACE_POSIX_TRACE_OPTIONS_H +#define __TRACE_POSIX_TRACE_OPTIONS_H + +/* + NOTE: + This header file is mostly ordered and labelled according to the + POSIX "P1003.1q: Tracing" standard document. +*/ + + +/* + 1.3 CONFORMANCE + (Values are defined according to Section "2.9 SYMBOLIC CONSTANTS") +*/ + +// Standard's Implementation Options currently supported: +// (NOTE: P1003.1q was finally approved on Sep, 21st 2000, so...) + +#define _POSIX_TRACE 200009L +#define _POSIX_TRACE_EVENT_FILTER 200009L +#undef _POSIX_TRACE_LOG // NOT (YET) SUPPORTED! +#undef _POSIX_TRACE_INHERITANCE // NOT (YET) SUPPORTED! + + + + +#endif diff -NurBb rtlinux-3.1-orig/include/posix/trace.h rtlinux-3.1-posixtrace/include/posix/trace.h --- rtlinux-3.1-orig/include/posix/trace.h 1970-01-01 01:00:00.000000000 +0100 +++ rtlinux-3.1-posixtrace/include/posix/trace.h 2002-08-23 13:26:56.000000000 +0200 @@ -0,0 +1,707 @@ +/* + FILE: + trace.h + + DESCRIPTION: + Public POSIX tracing definitions + + Copyright (C) 2001,2002 + Ana Garcia Fornes + Andres Terrasa Barrena + Ignacio Paches Giner + Agustin Espinosa Minguet + + This is free software; you can redistribute it and/or modify it under + terms of the GNU General Public License as published by the Free Soft- + ware Foundation; either version 2, or (at your option) any later ver- + sion. It is distributed in the hope that it will be useful, but WITH- + OUT 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; see file COPYING. If not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + LAST REVISION: + April 2002 + +*/ + +#ifndef __POSIX_TRACE_H +#define __POSIX_TRACE_H + +// Import the general RTL config options (i.e., check if variable +// CONFIG_POSIX_TRACING is defined) +#include + + +#ifdef CONFIG_POSIX_TRACING + + +// Import which POSIX tracing options are currently supported: +#include "trace/trace_options.h" + + +#ifdef _POSIX_TRACE + + +// --- +// BEGIN include section +#ifdef MODULE +#include +#include +#include +#else +#include +#include +#include +#endif + +#include + + + +#include "trace/trace.h" // POSIX tracing private definitions +// END include section +// --- + + + +/* --------------------------------------------------------------------- + GENERAL NOTE: + This header file is (mostly) ordered and labelled according to the + POSIX "P1003.1q: Tracing" standard document. + --------------------------------------------------------------------- +*/ + + + +/* + -- 2.5 PRIMITIVE SYSTEM DATA TYPES ---------------------------------- +*/ + +// Used to define a trace stream attributes object: +typedef _trace_attr_t trace_attr_t; + +// Used to identify a trace stream: +typedef _trace_id_t trace_id_t; + +// Used to identify a trace event type: +typedef _trace_event_id_t trace_event_id_t; + +// Used to define a set of trace event type identifiers: +typedef _trace_event_set_t trace_event_set_t; + + + +/* + -- 2.8.4. RUN-TIME INVARIANT VALUES --------------------------------- +*/ +#define TRACE_SYS_MAX _POSIX_TRACE_SYS_MAX +#define TRACE_USER_EVENT_MAX _POSIX_TRACE_USER_EVENT_MAX +#define TRACE_NAME_MAX _POSIX_TRACE_NAME_MAX +#define TRACE_EVENT_NAME_MAX _POSIX_TRACE_EVENT_NAME_MAX + + + + +/* + -- 24.2.1. DATA DEFINITIONS: STRUCTURES ----------------------------- +*/ + +// 24.2.1.1. posix_trace_status_info + +typedef struct posix_trace_status_info { + int posix_stream_status; // Operating mode of the trace stream + int posix_stream_full_status; // Full status of the trace stream + int posix_stream_overrun_status; // Trace event were lost? +#ifdef _POSIX_TRACE_LOG + int posix_stream_flush_status; // Is there a flush in progress? + int posix_stram_flush_error; // Error during last flush operation? + int posix_log_overrun_status; // Trace events lost in the log? + int posix_log_full_status // Full status of the trace log +#endif +} posix_trace_status_info; + + +// Pre-defined values for some of the fields: + +enum /* posix_stream_status */ { + POSIX_TRACE_RUNNING, + POSIX_TRACE_SUSPENDED +}; + +enum /* posix_stream_full_status and posix_log_full_status */ { + POSIX_TRACE_FULL, + POSIX_TRACE_NOT_FULL +}; + +enum /* posix_stream_overrun_status and posix_log_overrun_status */ { + POSIX_TRACE_OVERRUN, + POSIX_TRACE_NO_OVERRUN +}; + +#ifdef _POSIX_TRACE_LOG +enum /* posix_stream_flush_status */ { + POSIX_TRACE_FLUSHING, + POSIX_TRACE_NOT_FLUSHING +}; +#endif + + + +// 24.2.1.2. posix_trace_event_info + + +typedef struct posix_trace_event_info { + trace_event_id_t + posix_event_id; // Trace event type idenfication + pid_t posix_pid; // Id of the event generator process + void * posix_prog_address; // Address at which trace point was invoked + int posix_truncation_status;// Truncation info on this event + struct timespec + posix_timestamp; // Event generation time + pthread_t posix_thread_id; // Id of the event generator thread +} posix_trace_event_info; + + +// Pre-defined values for some of the fields: + +enum /* posix_truncation_status */ { + POSIX_TRACE_NOT_TRUNCATED, + POSIX_TRACE_TRUNCATED_RECORD, + POSIX_TRACE_TRUNCATED_READ, +}; + + + + + +/* + -- 24.2.2. TRACE STREAM ATTRIBUTES -------------------------------------- +*/ + + +// Pre-defined values for some of the attributes of trace_attr_t: + +enum /* stream's full policy */ { + POSIX_TRACE_LOOP, + POSIX_TRACE_UNTIL_FULL, + POSIX_TRACE_FLUSH +}; + + +#ifdef _POSIX_TRACE_LOG +enum /* stream log's full policy */ { + POSIX_TRACE_LOOP, + POSIX_TRACE_UNTIL_FULL, + POSIX_TRACE_APPEND +}; +#endif + + +#ifdef _POSIX_TRACE_INHERITANCE +enum /* inheritance policy */ { + POSIX_TRACE_INHERITED, + POSIX_TRACE_CLOSE_FOR_CHILD, +}; +#endif + + + + + +/* + -- 24.2.3. TRACE EVENT TYPE DEFINITIONS --------------------------------- +*/ + +// NOTE: User events are numbered from 0 to TRACE_USER_EVENT_MAX-1, +// while system events are numbered starting on TRACE_USER_EVENT_MAX + + +// 24.2.3.1. System events + +#define TRACE_FIRST_SYSTEM_EVENT TRACE_USER_EVENT_MAX + +// 1) posix_trace_error +#define POSIX_TRACE_ERROR TRACE_FIRST_SYSTEM_EVENT + +typedef struct posix_trace_error_event_data { + int error; +} posix_trace_error_event_data; + +// 2) posix_trace_start +#define POSIX_TRACE_START (TRACE_FIRST_SYSTEM_EVENT+1) + +#ifdef _POSIX_TRACE_EVENT_FILTER +typedef struct posix_trace_start_event_data { + trace_event_set_t event_filter; +} posix_trace_start_event_data; +#endif + +// 3) posix_trace_stop +#define POSIX_TRACE_STOP (TRACE_FIRST_SYSTEM_EVENT+2) + +typedef struct posix_trace_stop_event_data { + int automatic; +} posix_trace_stop_event_data; + +// 4) posix_trace_overflow +#define POSIX_TRACE_OVERFLOW (TRACE_FIRST_SYSTEM_EVENT+3) + +// 5) posix_trace_resume +#define POSIX_TRACE_RESUME (TRACE_FIRST_SYSTEM_EVENT+4) + +// 6) posix_trace_filter +#ifdef _POSIX_TRACE_EVENT_FILTER +#define POSIX_TRACE_FILTER (TRACE_FIRST_SYSTEM_EVENT+5) + +typedef struct posix_trace_filter_event_data { + trace_event_set_t old_event_filter; + trace_event_set_t new_event_filter; +} posix_trace_filter_event_data; +#endif + + + +// 24.2.3.2. User events + +// 1) posix_trace_unnamed_userevent +#define POSIX_TRACE_UNNAMED_USEREVENT 0 + + + + + +/* + -- 24.3. TRACE FUNCTIONS ------------------------------------------------ +*/ + +// 24.3.2. Attribute initialization and destruction + +extern int posix_trace_attr_init (trace_attr_t * attr); + +extern int posix_trace_attr_destroy (trace_attr_t *attr); + + +// 24.3.3. Retrieve and set information about a trace stream + +extern int posix_trace_attr_getgenversion (const trace_attr_t *attr, + char *genversion); + +extern int posix_trace_attr_getname (const trace_attr_t *attr, + char *tracename); + +extern int posix_trace_attr_setname (trace_attr_t *attr, + const char *tracename); + +extern int posix_trace_attr_getcreatetime (const trace_attr_t *attr, + struct timespec *createtime); + +extern int posix_trace_attr_getclockres (const trace_attr_t *attr, + struct timespec * resolution); + + +// 24.3.4. Retrieve and set the behavior of a trace stream + +#ifdef _POSIX_TRACE_INHERITANCE +extern int posix_trace_attr_getinherited (const trace_attr_t *attr, + int *inheritancepolicy); + +extern int posix_trace_attr_setinherited (trace_attr_t *attr, + int inheritancepolicy); +#endif + +extern int posix_trace_attr_getstreamfullpolicy (const trace_attr_t *attr, + int *streampolicy); + +extern int posix_trace_attr_setstreamfullpolicy (trace_attr_t *attr, + int streampolicy); + +#ifdef _POSIX_TRACE_LOG +extern int posix_trace_attr_getlogfullpolicy (const trace_attr_t *attr, + int *logpolicy); + +extern int posix_trace_attr_setlogfullpolicy (trace_attr_t *attr, + int logpolicy); +#endif + + +// 24.3.5. Retrieve and set trace stream size attributes + +extern int posix_trace_attr_getmaxusereventsize (const trace_attr_t *attr, + size_t data_len, + size_t *eventsize); + +extern int posix_trace_attr_getmaxsystemeventsize (const trace_attr_t *attr, + size_t *eventsize); + +extern int posix_trace_attr_getmaxdatasize (const trace_attr_t *attr, + size_t *maxdatasize); + +extern int posix_trace_attr_setmaxdatasize (trace_attr_t *attr, + size_t maxdatasize); + +extern int posix_trace_attr_getstreamsize (const trace_attr_t *attr, + size_t *streamsize); + +extern int posix_trace_attr_setstreamsize (trace_attr_t *attr, + size_t streamsize); + +#ifdef _POSIX_TRACE_LOG +extern int posix_trace_attr_getlogsize (const trace_attr_t *attr, + size_t *logsize); + +extern int posix_trace_attr_setlogsize(trace_attr_t *attr, + size_t logsize); +#endif + + +// 24.3.6. Trace stream initialization, flush and shutdown + + +extern int posix_trace_create (pid_t pid, + const trace_attr_t *attr, + trace_id_t *trid); + +#ifdef _POSIX_TRACE_LOG +extern int posix_trace_create_withlog (pid_t pid, + const trace_attr_t *attr, + int file_desc, + trace_id_t *trid); + +extern int posix_trace_flush (trace_id_t trid); +#endif + +extern int posix_trace_shutdown (trace_id_t trid); + + +// 24.3.7. Clear trace stream and trace log + +extern int posix_trace_clear (trace_id_t trid); + + +// 24.3.8. Manipulate trace event type identifier + +#ifdef _POSIX_TRACE_EVENT_FILTER +extern int posix_trace_trid_eventid_open (trace_id_t trid, + const char *event_name, + trace_event_id_t *event); +#endif + +extern int posix_trace_eventid_get_name (trace_id_t trid, + trace_event_id_t event, + char *event_name); + +extern int posix_trace_eventid_equal (trace_id_t trid, + trace_event_id_t event1, + trace_event_id_t event2); + + +// 24.3.9. Iterate over a mapping of trace event types + +extern int posix_trace_eventtypelist_getnext_id (trace_id_t trid, + trace_event_id_t *event, + int *unavailable); + +extern int posix_trace_eventtypelist_rewind (trace_id_t trid); + + +// 24.3.10. Manipulate trace event type sets + +#ifdef _POSIX_TRACE_EVENT_FILTER + + +// Argument 'what' in posix_trace_eventset_fill() can be: +#define POSIX_TRACE_WOPID_EVENTS 1 +#define POSIX_TRACE_SYSTEM_EVENTS 2 +#define POSIX_TRACE_ALL_EVENTS 3 + +extern int posix_trace_eventset_empty (trace_event_set_t *set); + +extern int posix_trace_eventset_fill (trace_event_set_t *set, + int what); + +extern int posix_trace_eventset_add (trace_event_id_t event_id, + trace_event_set_t *set); + +extern int posix_trace_eventset_del (trace_event_id_t event_id, + trace_event_set_t *set); + +//extern int posix_trace_eventset_complement(trace_event_set_t *set); + +extern int posix_trace_eventset_ismember (trace_event_id_t event_id, + const trace_event_set_t *set, + int *ismember); + + +// 24.3.11. Manipulate trace event type sets + +// Argument 'how' in posix_trace_set_filter() can be: +#define POSIX_TRACE_SET_EVENTSET 1 +#define POSIX_TRACE_ADD_EVENTSET 2 +#define POSIX_TRACE_SUB_EVENTSET 3 + +extern int posix_trace_set_filter (trace_id_t trid, + const trace_event_set_t *set, + int how); + + +extern int posix_trace_get_filter (trace_id_t trid, + trace_event_set_t *set); +#endif + + +// 24.3.12. Trace start and stop + +extern int posix_trace_start (trace_id_t trid); + +extern int posix_trace_stop (trace_id_t trid); + + +// 24.3.13. Instrumenting application code + +extern int posix_trace_eventid_open (const char *event_name, + trace_event_id_t *event_id); + +extern void posix_trace_event (trace_event_id_t event_id, + const void *data_ptr, + size_t data_len); + + +// 24.3.14. Trace log management + +#ifdef _POSIX_TRACE_LOG + +extern int posix_trace_open (int file_desc, + trace_id_t *trid); + +extern int posix_trace_rewind (trace_id_t trid); + +extern int posix_trace_close (trace_id_t trid); + +#endif + + +// 24.3.15. Retrieve the trace attributes or trace statuses + +extern int posix_trace_get_attr (trace_id_t trid, + trace_attr_t *attr); + +extern int posix_trace_get_status (trace_id_t trid, + struct posix_trace_status_info *statusinfo); + + +// 24.3.16. Retrieve a trace event + +extern int posix_trace_getnext_event (trace_id_t trid, + struct posix_trace_event_info *event, + void *data, + size_t num_bytes, + size_t *data_len, + int *unavailable); + +extern int posix_trace_timedgetnext_event (trace_id_t trid, + struct posix_trace_event_info + *event, + void *data, + size_t num_bytes, + size_t *data_len, + int *unavailable, + const struct timespec *abs_timeout); + +extern int posix_trace_trygetnext_event (trace_id_t trid, + struct posix_trace_event_info *event, + void *data, + size_t num_bytes, + size_t *data_len, + int *unavailable); + + + + + + +/* + =========================================================================== + IMPLEMENTATION-DEPENDENT DEFINITIONS + =========================================================================== +*/ + + +/* + NEW SYSTEM EVENT TYPES (DEFINED BY THE IMPLEMENTATION) +*/ + +// Maximum values for system event types and total event types +#define TRACE_SYSTEM_EVENT_MAX _POSIX_TRACE_SYSTEM_EVENT_MAX + +#define TRACE_EVENT_MAX (TRACE_USER_EVENT_MAX + \ + TRACE_SYSTEM_EVENT_MAX) + + +// Identifier definitions and associated data types: +#define POSIX_TRACE_CONTEXT_SWITCH (TRACE_FIRST_SYSTEM_EVENT+6) +#define POSIX_TRACE_TASK_STATE (TRACE_FIRST_SYSTEM_EVENT+7) + +typedef enum task_state_t { + TASK_RELEASE, + TASK_END, + TASK_SUSPENDED, + TASK_READY +} task_state_t; + +typedef struct { + void *task; + int priority; + task_state_t state; + bool is_linux; +} posix_trace_task_state_event_data; + + +#define POSIX_TRACE_KERNEL_OVERHEAD (TRACE_FIRST_SYSTEM_EVENT+8) + +typedef enum kernel_overhead_t { + OVERHEAD_START, + OVERHEAD_END +} kernel_overhead_t; + +typedef struct { + kernel_overhead_t type; + void *task; + bool is_linux; +} posix_trace_overhead_event_data; + + +#define POSIX_TRACE_SYSTEM_CALL (TRACE_FIRST_SYSTEM_EVENT+9) + +typedef enum syscall_types_t { + PTHREAD_CREATE, + PTHREAD_YIELD, + PTHREAD_KILL, + PTHREAD_EXIT, + PTHREAD_WAIT_NP, + PTHREAD_SUSPEND_NP, + PTHREAD_WAKEUP_NP, + PTHREAD_DELETE_NP, + CLOCK_NANOSLEEP, + PTHREAD_MUTEX_LOCK, + PTHREAD_MUTEX_UNLOCK, + PTHREAD_COND_WAIT, + PTHREAD_COND_SIGNAL, + PTHREAD_COND_BROADCAST +} syscall_types_t; + +typedef struct { + syscall_types_t syscall; + void *task; + bool is_linux; +} posix_trace_syscall_event_data; + + +#define POSIX_TRACE_MUTEX_LOCK (TRACE_FIRST_SYSTEM_EVENT+10) +#define POSIX_TRACE_MUTEX_UNLOCK (TRACE_FIRST_SYSTEM_EVENT+11) + +typedef enum mutex_op_t { + MUTEX_LOCK_TRY, + MUTEX_LOCK_DENIED, + MUTEX_LOCK_GRANTED, + MUTEX_UNLOCK +} mutex_op_t; + +typedef struct { + mutex_op_t op; + void *mutex; + void *task; +} posix_trace_mutex_event_data; + + +#define POSIX_TRACE_COND_WAIT (TRACE_FIRST_SYSTEM_EVENT+12) +#define POSIX_TRACE_COND_BROADCAST (TRACE_FIRST_SYSTEM_EVENT+13) + +typedef enum cond_op_t { + COND_WAIT, + COND_SIGNAL, + COND_BROADCAST +} cond_op_t; + +typedef struct { + cond_op_t op; + void *task; + void *cond; + void *mutex; +} posix_trace_cond_event_data; + + + + + +#define POSIX_TRACE_GENERAL_DEBUG (TRACE_FIRST_SYSTEM_EVENT+14) + +#define MESSAGE_SIZE 40 +typedef struct { + char text[MESSAGE_SIZE]; + hrtime_t fst; + hrtime_t snd; + int thd; +} posix_trace_general_event_data; + + +// Reset this if system type events are added or removed +#define TRACE_LAST_SYSTEM_EVENT POSIX_TRACE_GENERAL_DEBUG + + + + +/* + PRE-DEFINED TRACE STREAM NAMES + This allows for the sharing of stream(s) between Linux and RT-Linux + + NOTE: This implementation reserves FIFOs /dev/rtf55 to /dev/rtf63 + These cannot be used for other purposes !!! + + By default, STREAM0 is used for collecting kernel events + automatically. This can be eliminated by the application, + by means of creating this stream again. +*/ + +#define TRACE_STREAM0_NAME "0 STREAM" +#define TRACE_STREAM1_NAME "1 STREAM" +#define TRACE_STREAM2_NAME "2 STREAM" +#define TRACE_STREAM3_NAME "3 STREAM" +#define TRACE_STREAM4_NAME "4 STREAM" +#define TRACE_STREAM5_NAME "5 STREAM" +#define TRACE_STREAM6_NAME "6 STREAM" +#define TRACE_STREAM7_NAME "7 STREAM" + +#define TRACE_KERNEL_STREAM TRACE_STREAM0_NAME + + +/* + RT-FIFO related definitions +*/ +#define TRACE_FIRST_FIFO 55 +#define TRACE_LAST_FIFO 62 +#define TRACE_TARGET_FIFO 63 + + + +// NOTE: When using FIFOs, we need to bound the size of event data. +// If the event data size is greater than this value, the data will +// be truncated to that size: +// (This only affects events which do pass through FIFOs in either +// direction). + +#define MAX_FIFO_DATA_SIZE 256 + + + + +#endif // #ifdef _POSIX_TRACE + + +#endif // #ifdef CONFIG_POSIX_TRACING + + +#endif // #ifndef __POSIX_TRACE_H + + diff -NurBb rtlinux-3.1-orig/include/ppc/rtl_posixtrace.h rtlinux-3.1-posixtrace/include/ppc/rtl_posixtrace.h --- rtlinux-3.1-orig/include/ppc/rtl_posixtrace.h 1970-01-01 01:00:00.000000000 +0100 +++ rtlinux-3.1-posixtrace/include/ppc/rtl_posixtrace.h 2002-09-10 18:52:52.000000000 +0200 @@ -0,0 +1,37 @@ + +/* + FILE: + rtl_posixtrace.h + + DESCRIPTION: + Architecture-dependent definitions + + Copyright (C) 2002 + Ana Garcia Fornes + Andres Terrasa Barrena + Ignacio Paches Giner + Agustin Espinosa Minguet + + This is free software; you can redistribute it and/or modify it under + terms of the GNU General Public License as published by the Free Soft- + ware Foundation; either version 2, or (at your option) any later ver- + sion. It is distributed in the hope that it will be useful, but WITH- + OUT 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; see file COPYING. If not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + LAST REVISION: + September 2002 + +*/ + + + +// Not yet supported (return a 0) +#define posix_trace_get_invoking_address(calling_address) 0 + + + + diff -NurBb rtlinux-3.1-orig/include/rtl_ktrace.h rtlinux-3.1-posixtrace/include/rtl_ktrace.h --- rtlinux-3.1-orig/include/rtl_ktrace.h 1970-01-01 01:00:00.000000000 +0100 +++ rtlinux-3.1-posixtrace/include/rtl_ktrace.h 2002-08-21 16:19:29.000000000 +0200 @@ -0,0 +1,44 @@ +/* + FILE: + rtl_ktrace.h + + DESCRIPTION: + Header file of the module that automatically collects kernel + (system) events. + + This uses the POSIX trace support. See posix/trace.h for details. + + Copyright (C) 2001 + Ana Garcia Fornes + Andres Terrasa Barrena + Ignacio Paches Giner + Agustin Espinosa Minguet + + This is free software; you can redistribute it and/or modify it under + terms of the GNU General Public License as published by the Free Soft- + ware Foundation; either version 2, or (at your option) any later ver- + sion. It is distributed in the hope that it will be useful, but WITH- + OUT 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; see file COPYING. If not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + LAST REVISION: + September 2001 + +*/ + + +#ifndef __RTL_KTRACE_H +#define __RTL_KTRACE_H + + + +extern int rtl_ktrace_start(void); +extern int rtl_ktrace_stop(void); + + + + +#endif /* #ifndef __RTL_KTRACE_H */ diff -NurBb rtlinux-3.1-orig/include/trace.h rtlinux-3.1-posixtrace/include/trace.h --- rtlinux-3.1-orig/include/trace.h 1970-01-01 01:00:00.000000000 +0100 +++ rtlinux-3.1-posixtrace/include/trace.h 2002-08-21 16:19:29.000000000 +0200 @@ -0,0 +1,34 @@ +/* + FILE: + trace.h + + DESCRIPTION: + Posix trace definitions and headers + + Copyright (C) 2001 + Ana Garcia Fornes + Andres Terrasa Barrena + Ignacio Paches Giner + Agustin Espinosa Minguet + + This is free software; you can redistribute it and/or modify it under + terms of the GNU General Public License as published by the Free Soft- + ware Foundation; either version 2, or (at your option) any later ver- + sion. It is distributed in the hope that it will be useful, but WITH- + OUT 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; see file COPYING. If not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + LAST REVISION: + August 2001 + +*/ + +#ifndef __TRACE_H +#include "posix/trace.h" +#define __TRACE_H + +#endif + diff -NurBb rtlinux-3.1-orig/posixtrace/Makefile rtlinux-3.1-posixtrace/posixtrace/Makefile --- rtlinux-3.1-orig/posixtrace/Makefile 1970-01-01 01:00:00.000000000 +0100 +++ rtlinux-3.1-posixtrace/posixtrace/Makefile 2002-08-23 13:18:24.000000000 +0200 @@ -0,0 +1,45 @@ +all: posix_trace.o ktrace_analyzer rtl_ktrace.o + +clean: + rm -f *.o ktrace_analyzer *.a *~ + +include ../rtl.mk + + + +ifneq ($(ARCH),mips) +LIBGCC := $(shell $(CC) -print-libgcc-file-name) +else +LIBGCC = libgcc.o +libgcc.o: mips/libgcc2.c + $(CC) $(CFLAGS) -DCROSS_COMPILE -DIN_GCC -I./include -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED -I. -c -DL_muldi3 mips/libgcc2.c -o libgcc.o +endif + +LDFLAGS=-d + + + +posix_trace.o: posix_trace.c ../include/trace.h + @(echo "*************** COMPILING POSIX TRACING LIBRARY **************") + $(CC) -c -o posix_trace_tmp.o -I../include posix_trace.c + $(LD) -o posix_trace.o posix_trace_tmp.o -r -L/usr/lib -lpthread + @(ar rc libposix_trace.a posix_trace.o) + @(ranlib libposix_trace.a) + @(cp libposix_trace.a /usr/local/lib) + + +ktrace_analyzer: ktrace_analyzer.c ../include/trace.h posix_trace.o + @(echo "************** COMPILING KTRACE_ANALYZER *********************") + gcc -Wall -g -o ktrace_analyzer ${INCLUDE} ktrace_analyzer.c -lposix_trace + + +rtl_ktrace.o: rtl_ktrace.c ../include/trace.h + @(echo "************** COMPILING RTL_KTRACE **************************") + $(CC) ${INCLUDE} ${CFLAGS} -o rtl_ktrace.o -c rtl_ktrace.c + cp -f rtl_ktrace.o ../modules/ + + +install: rtl_ktrace.o + install -c -m 644 rtl_ktrace.o ${RTL_DIR}/modules + +include $(RTL_DIR)/Rules.make diff -NurBb rtlinux-3.1-orig/posixtrace/README rtlinux-3.1-posixtrace/posixtrace/README --- rtlinux-3.1-orig/posixtrace/README 1970-01-01 01:00:00.000000000 +0100 +++ rtlinux-3.1-posixtrace/posixtrace/README 2002-08-21 16:19:29.000000000 +0200 @@ -0,0 +1,8 @@ + General instructions for using the posix_trace functionality. + + + +.... + +Once one /dev/rtfXX is opened by one proccess, it can not be opened +by another process until the first one closes it or exits. diff -NurBb rtlinux-3.1-orig/posixtrace/ktrace_analyzer.c rtlinux-3.1-posixtrace/posixtrace/ktrace_analyzer.c --- rtlinux-3.1-orig/posixtrace/ktrace_analyzer.c 1970-01-01 01:00:00.000000000 +0100 +++ rtlinux-3.1-posixtrace/posixtrace/ktrace_analyzer.c 2002-09-18 18:08:24.000000000 +0200 @@ -0,0 +1,764 @@ +/* + + FILE: + + ktrace_analyzer.c + + DESCRIPTION: + Program that gets the system trace events collected by the + rt-scheduler and generates some files. + + Copyright (C) 1998 + Ana Garcia Fornes + Andres Terrasa Barrena + Ignacio Paches Giner + Agustin Espinosa Minguet + + + + This is free software; you can redistribute it and/or modify it under + terms of the GNU General Public License as published by the Free Soft- + ware Foundation; either version 2, or (at your option) any later ver- + sion. It is distributed in the hope that it will be useful, but WITH- + OUT 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; see file COPYING. If not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + + LAST REVISION: + April 2002 +*/ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + + +#define QUIVI_RELEASE 0 +#define QUIVI_ENDTASK 1 +#define QUIVI_DEADLINE 2 +#define QUIVI_STARTCPU 3 +#define QUIVI_STOPCPU 4 +#define QUIVI_READY 5 +#define QUIVI_NOTREADY 6 +#define QUIVI_MUTEX_LOCK 7 +#define QUIVI_MUTEX_UNLOCK 8 +#define QUIVI_EVNTUP 9 +#define QUIVI_EVNTDOWN 10 +#define QUIVI_SUSPTASK 11 + + +#define MAX_TASKS 10 +#define MAX_MUTEX 10 +#define MAX_COND 10 +#define KERNEL_TASK (void *) 0 +#define LINUX_TASK MAX_TASKS +#define NONE -1 +#define MAGNITUDE 1000 + + + +static void *task_pointers[MAX_TASKS]; +static void *mutex_pointers[MAX_MUTEX]; +static void *cond_pointers[MAX_COND]; + + + +#define LINEAR_TIME(sec,nsec) (\ + (hrtime_t) (((hrtime_t) sec * (hrtime_t) 1000000000)\ + + (hrtime_t) nsec) \ + ) + + +#define TIME_INITIALIZE(t) (\ + initial_time = \ + (initial_time ? \ + initial_time : \ + (hrtime_t) t) \ + ) + + +#define TIME_ABS_TO_RELATIVE(t) (\ + (hrtime_t) ((int) t ? \ + (t - initial_time) : 0) \ + ) + + +#define TIME_QUIVI_TIME(t) (\ + (long) ((float) (t - initial_time) \ + / (float) MAGNITUDE ) \ + ) + + +#define OUTPUT_TO_QUIVI(file,t,event,task) \ + fprintf(file, "%ld { {%d %d} }\n", \ + (long) t, (int) event, (int) task) + +#define OUTPUT_TO_QUIVI2INT(file,t,event,task,arg1) \ + fprintf(file, "%ld { {%d %d {%d}} }\n", \ + (long) t, (int) event, (int) task, (int) arg1) + +#define OUTPUT_TO_QUIVI2STR(file,t,event,task,arg1) \ + fprintf(file, "%ld { {%d %d {%s}} }\n", \ + (long) t, (int) event, (int) task, arg1) + + + + +static inline int register_and_get(void *array[], int max, void *element) { + + int i; + + for (i=0; + i < max && array[i] != element && array[i] != (void *) NONE; + i++) /* void loop */ ; + + if (iis_linux? + LINUX_TASK : + register_and_get(task_pointers, MAX_TASKS, task_event->task)); + + if (task_id != NONE) { + + if (current_task != NONE) { + OUTPUT_TO_QUIVI(quivi_file,time,QUIVI_STOPCPU, current_task); + } + current_task = task_id; + + OUTPUT_TO_QUIVI(quivi_file, time, QUIVI_STARTCPU, task_id); + OUTPUT_TO_QUIVI2INT(quivi_file, time, QUIVI_EVNTUP, task_id, + task_event->priority); + + if (debug) { + fprintf(debug_file, + "TASK_START (%ld.%09ld): task=%d t=%llu\n", + event.posix_timestamp.tv_sec, event.posix_timestamp.tv_nsec, + task_id, time); + } + } + } + + // POSIX_TRACE_TASK_STATE + else if (posix_trace_eventid_equal(trace_id,event.posix_event_id, + POSIX_TRACE_TASK_STATE)) { + + task_event = (posix_trace_task_state_event_data *) message; + + linear_time = LINEAR_TIME(event.posix_timestamp.tv_sec, + event.posix_timestamp.tv_nsec); + + time = TIME_QUIVI_TIME(linear_time); + task_id = register_and_get(task_pointers, MAX_TASKS, task_event->task); + + if (task_id != NONE) { + + switch(task_event->state) { + + case TASK_RELEASE : + OUTPUT_TO_QUIVI(quivi_file, time, QUIVI_RELEASE, task_id); + OUTPUT_TO_QUIVI(quivi_file, time, QUIVI_READY, task_id); + if (debug) { + fprintf(debug_file, + "TASK_STATE (%ld.%09ld): task=%d state=RELEASE\n", + event.posix_timestamp.tv_sec, event.posix_timestamp.tv_nsec, + task_id); + } + break; + + case TASK_END : + OUTPUT_TO_QUIVI(quivi_file, time, QUIVI_NOTREADY, task_id); + OUTPUT_TO_QUIVI(quivi_file, time, QUIVI_ENDTASK, task_id); + if (debug) { + fprintf(debug_file, + "TASK_STATE (%ld.%09ld): task=%d state=END\n", + event.posix_timestamp.tv_sec, event.posix_timestamp.tv_nsec, + task_id); + } + break; + + case TASK_READY : + OUTPUT_TO_QUIVI(quivi_file, time, QUIVI_READY, task_id); + if (debug) { + fprintf(debug_file, + "TASK_STATE (%ld.%09ld): task=%d state=READY\n", + event.posix_timestamp.tv_sec, event.posix_timestamp.tv_nsec, + task_id); + } + break; + + case TASK_SUSPENDED : + OUTPUT_TO_QUIVI(quivi_file, time, QUIVI_NOTREADY, task_id); + if (debug) { + fprintf(debug_file, + "TASK_STATE (%ld.%09ld): task=%d state=SUSPENDED\n", + event.posix_timestamp.tv_sec, event.posix_timestamp.tv_nsec, + task_id); + } + break; + + default: + } + } + } + + + // POSIX_TRACE_MUTEX_LOCK + else if (posix_trace_eventid_equal(trace_id,event.posix_event_id, + POSIX_TRACE_MUTEX_LOCK)) { + + mutex_event = (posix_trace_mutex_event_data *) message; + + linear_time = LINEAR_TIME(event.posix_timestamp.tv_sec, + event.posix_timestamp.tv_nsec); + + time = TIME_QUIVI_TIME(linear_time); + + task_id = register_and_get(task_pointers, MAX_TASKS, mutex_event->task); + mutex_id = register_and_get(mutex_pointers, MAX_MUTEX, mutex_event->mutex); + + if (task_id != NONE && mutex_id != NONE) { + + switch(mutex_event->op) { + + case MUTEX_LOCK_DENIED: + OUTPUT_TO_QUIVI(quivi_file, time, QUIVI_SUSPTASK, task_id); + if (debug) { + fprintf(debug_file, + "MUTEX_LOCK (%ld.%09ld): task=%d mutex=%d t=%llu (LOCK DENIED)\n", + event.posix_timestamp.tv_sec, event.posix_timestamp.tv_nsec, + task_id, mutex_id, time); + } + break; + + case MUTEX_LOCK_GRANTED : + OUTPUT_TO_QUIVI(quivi_file, time, QUIVI_MUTEX_LOCK, task_id); + sprintf(objstr, "m%d", mutex_id); + OUTPUT_TO_QUIVI2STR(quivi_file, time, QUIVI_EVNTUP, task_id, + objstr); + if (debug) { + fprintf(debug_file, + "MUTEX_LOCK (%ld.%09ld): task=%d mutex=%d t=%llu (LOCK GRANTED)\n", + event.posix_timestamp.tv_sec, event.posix_timestamp.tv_nsec, + task_id, mutex_id, time); + } + break; + + case MUTEX_LOCK_TRY: + break; + + case MUTEX_UNLOCK: + break; + default: + } + } + } + + + // POSIX_TRACE_MUTEX_UNLOCK + else if (posix_trace_eventid_equal(trace_id,event.posix_event_id, + POSIX_TRACE_MUTEX_UNLOCK)) { + + mutex_event = (posix_trace_mutex_event_data *) message; + + linear_time = LINEAR_TIME(event.posix_timestamp.tv_sec, + event.posix_timestamp.tv_nsec); + + time = TIME_QUIVI_TIME(linear_time); + + task_id = register_and_get(task_pointers, MAX_TASKS, mutex_event->task); + mutex_id = register_and_get(mutex_pointers, MAX_MUTEX, mutex_event->mutex); + + if (task_id != NONE && mutex_id != NONE) { + OUTPUT_TO_QUIVI(quivi_file, time, QUIVI_MUTEX_UNLOCK, task_id); + sprintf(objstr, "m%d", mutex_id); + OUTPUT_TO_QUIVI2STR(quivi_file, time, QUIVI_EVNTUP, task_id, + objstr); + if (debug) { + fprintf(debug_file, + "MUTEX_UNLOCK (%ld.%09ld): task=%d mutex=%d t=%llu\n", + event.posix_timestamp.tv_sec, event.posix_timestamp.tv_nsec, + task_id, mutex_id, time); + } + } + } + + + + // POSIX_TRACE_SYSTEM_CALL + else if (posix_trace_eventid_equal(trace_id,event.posix_event_id, + POSIX_TRACE_SYSTEM_CALL)) { + + syscall_event = (posix_trace_syscall_event_data *) message; + + linear_time = LINEAR_TIME(event.posix_timestamp.tv_sec, + event.posix_timestamp.tv_nsec); + + time = TIME_QUIVI_TIME(linear_time); + + task_id = (syscall_event->is_linux? + LINUX_TASK : + register_and_get(task_pointers, MAX_TASKS, syscall_event->task)); + + if (task_id != NONE) { + + switch(syscall_event->syscall) { + + case PTHREAD_CREATE : + sprintf(syscallstr,"CREAT"); + task_id = LINUX_TASK; + break; + + case PTHREAD_YIELD : + sprintf(syscallstr,"YIELD"); + break; + + case PTHREAD_KILL: + sprintf(syscallstr,"KILL"); + break; + + case PTHREAD_EXIT: + sprintf(syscallstr,"EXIT"); + break; + + case PTHREAD_WAIT_NP: + sprintf(syscallstr,"WAIT"); + break; + + case PTHREAD_SUSPEND_NP: + sprintf(syscallstr,"SUSP"); + break; + + case PTHREAD_WAKEUP_NP: + sprintf(syscallstr,"WAKUP"); + break; + + case PTHREAD_DELETE_NP: + sprintf(syscallstr,"DLET"); + break; + + case CLOCK_NANOSLEEP: + sprintf(syscallstr,"SLEEP"); + break; + + case PTHREAD_MUTEX_LOCK: + sprintf(syscallstr,"LOCK"); + break; + + case PTHREAD_MUTEX_UNLOCK: + sprintf(syscallstr,"ULOCK"); + break; + + case PTHREAD_COND_WAIT: + sprintf(syscallstr,"CWAIT"); + break; + + case PTHREAD_COND_SIGNAL: + sprintf(syscallstr,"SIGNL"); + break; + + case PTHREAD_COND_BROADCAST: + sprintf(syscallstr,"BCAST"); + break; + default: + } + + OUTPUT_TO_QUIVI2STR(quivi_file, time, QUIVI_EVNTDOWN, task_id, + syscallstr); + if (debug) { + fprintf(debug_file, + "SYSTEM_CALL (%ld.%09ld): syscall=%s task=%d t=%llu (addr=%x)\n", + event.posix_timestamp.tv_sec, event.posix_timestamp.tv_nsec, + syscallstr, task_id, time, (int) event.posix_prog_address); + } + + + } + } + + // POSIX_TRACE_KERNEL_OVERHEAD + else if (posix_trace_eventid_equal(trace_id,event.posix_event_id, + POSIX_TRACE_KERNEL_OVERHEAD)) { + + overhead_event = (posix_trace_overhead_event_data *) message; + + linear_time = LINEAR_TIME(event.posix_timestamp.tv_sec, + event.posix_timestamp.tv_nsec); + + time = TIME_QUIVI_TIME(linear_time); + + task_id = (overhead_event->is_linux? + LINUX_TASK : + register_and_get(task_pointers, MAX_TASKS, overhead_event->task)); + + if (task_id != NONE) { + + switch(overhead_event->type) { + + case OVERHEAD_START : + OUTPUT_TO_QUIVI(quivi_file, time, QUIVI_STARTCPU, KERNEL_TASK); + last_overhead_start = time; + break; + + case OVERHEAD_END : + OUTPUT_TO_QUIVI(quivi_file, time, QUIVI_STOPCPU, KERNEL_TASK); + if (debug) { + fprintf(debug_file, + "OVERHEAD (%ld.%09ld): task=%d t1=%llu t2=%llu\n", + event.posix_timestamp.tv_sec, event.posix_timestamp.tv_nsec, + task_id, last_overhead_start, time); + } + break; + + default : + } + } + } + + + // POSIX_TRACE_COND_WAIT + else if (posix_trace_eventid_equal(trace_id,event.posix_event_id, + POSIX_TRACE_COND_WAIT)) { + + cond_event = (posix_trace_cond_event_data *) message; + + linear_time = LINEAR_TIME(event.posix_timestamp.tv_sec, + event.posix_timestamp.tv_nsec); + + time = TIME_QUIVI_TIME(linear_time); + + task_id = register_and_get(task_pointers, MAX_TASKS, cond_event->task); + mutex_id = register_and_get(mutex_pointers, MAX_MUTEX, cond_event->mutex); + cond_id = register_and_get(cond_pointers, MAX_COND, cond_event->cond); + + if (task_id != NONE && mutex_id != NONE && cond_id != NONE) { + if (debug) { + fprintf(debug_file, + "COND_WAIT (%ld.%09ld): task=%d cond=%d mutex=%d t=%llu\n", + event.posix_timestamp.tv_sec, event.posix_timestamp.tv_nsec, + task_id, cond_id, mutex_id, time); + } + } + } + + + // POSIX_TRACE_COND_BROADCAST + else if (posix_trace_eventid_equal(trace_id,event.posix_event_id, + POSIX_TRACE_COND_BROADCAST)) { + + cond_event = (posix_trace_cond_event_data *) message; + + linear_time = LINEAR_TIME(event.posix_timestamp.tv_sec, + event.posix_timestamp.tv_nsec); + + time = TIME_QUIVI_TIME(linear_time); + + task_id = register_and_get(task_pointers, MAX_TASKS, cond_event->task); + mutex_id = register_and_get(mutex_pointers, MAX_MUTEX, cond_event->mutex); + cond_id = register_and_get(cond_pointers, MAX_COND, cond_event->cond); + + if (task_id != NONE && mutex_id != NONE && cond_id != NONE) { + if (debug) { + fprintf(debug_file, + "COND_BROAD (%ld.%09ld): task=%d cond=%d mutex=%d t=%llu\n", + event.posix_timestamp.tv_sec