diff options
| author | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2008-01-23 16:46:36 -0500 |
|---|---|---|
| committer | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2008-01-23 16:46:36 -0500 |
| commit | 508bf3cc099fae7260804b340144f857a99d8ad0 (patch) | |
| tree | 2bf14cf9353e0f3d3efc7764c05cd79a2a7fceed | |
| parent | 7e062f5db3e3888cda2d0915e14d33b9f69c4c68 (diff) | |
Add example real-time task skeleton base_task.c .
| -rw-r--r-- | Makefile | 5 | ||||
| -rw-r--r-- | bin/base_task.c | 133 |
2 files changed, 137 insertions, 1 deletions
| @@ -6,7 +6,7 @@ LIBS= ./liblitmus.a | |||
| 6 | LIB_OBJ= litmus.o syscalls.o sched_trace.o adaptive.o edf-hsb.o task.o kernel_iface.o | 6 | LIB_OBJ= litmus.o syscalls.o sched_trace.o adaptive.o edf-hsb.o task.o kernel_iface.o |
| 7 | 7 | ||
| 8 | TARGETS = showsched iotest set_rt_mode run timeout rt_launch edfhsb liblitmus.a \ | 8 | TARGETS = showsched iotest set_rt_mode run timeout rt_launch edfhsb liblitmus.a \ |
| 9 | wait_test np_test stdump mode_test | 9 | wait_test np_test stdump mode_test base_task |
| 10 | 10 | ||
| 11 | vpath %.h include/ | 11 | vpath %.h include/ |
| 12 | vpath %.c src/ bin/ | 12 | vpath %.c src/ bin/ |
| @@ -15,6 +15,9 @@ all: ${TARGETS} | |||
| 15 | clean: | 15 | clean: |
| 16 | rm -f *.o *~ ${TARGETS} | 16 | rm -f *.o *~ ${TARGETS} |
| 17 | 17 | ||
| 18 | base_task: base_task.o liblitmus.a | ||
| 19 | cc -static -o base_task base_task.o ${LIBS} | ||
| 20 | |||
| 18 | wait_test: wait_test.o litmus.h liblitmus.a | 21 | wait_test: wait_test.o litmus.h liblitmus.a |
| 19 | cc -static -o wait_test wait_test.o ${LIBS} | 22 | cc -static -o wait_test wait_test.o ${LIBS} |
| 20 | 23 | ||
diff --git a/bin/base_task.c b/bin/base_task.c new file mode 100644 index 0000000..e5f50b1 --- /dev/null +++ b/bin/base_task.c | |||
| @@ -0,0 +1,133 @@ | |||
| 1 | /* based_task.c -- A basic real-time task skeleton. | ||
| 2 | * | ||
| 3 | * This (by itself useless) task demos how to setup LITMUS^RT real-time task. | ||
| 4 | * | ||
| 5 | * Compile: | ||
| 6 | * | ||
| 7 | */ | ||
| 8 | |||
| 9 | |||
| 10 | /* First, we include standard headers. | ||
| 11 | * Generally speaking, a LITMUS^RT real-time task can perform any | ||
| 12 | * system call, etc., but no real-time guarantees can be made if a | ||
| 13 | * system call blocks. To be on the safe side, only use I/O for debugging | ||
| 14 | * purposes and from non-real-time sections. | ||
| 15 | */ | ||
| 16 | #include <stdio.h> | ||
| 17 | #include <stdlib.h> | ||
| 18 | |||
| 19 | /* Second, we include the LITMUS^RT user space library header. | ||
| 20 | * This header, part of liblitmus, provides the user space API of | ||
| 21 | * LITMUS^RT. | ||
| 22 | */ | ||
| 23 | #include "litmus.h" | ||
| 24 | |||
| 25 | /* Next, we define period and execution cost to be constant. | ||
| 26 | * These are only constants for convenience in this example, they can be | ||
| 27 | * determined at run time, e.g., from command line parameters. | ||
| 28 | */ | ||
| 29 | #define PERIOD 100 | ||
| 30 | #define EXEC_COST 10 | ||
| 31 | |||
| 32 | /* Declare the periodically invoked job. | ||
| 33 | * Returns 1 -> task should exit. | ||
| 34 | * 0 -> task should continue. | ||
| 35 | */ | ||
| 36 | int job(void); | ||
| 37 | |||
| 38 | /* typically, main() does a couple of things: | ||
| 39 | * 1) parse command line parameters, etc. | ||
| 40 | * 2) Setup work environment. | ||
| 41 | * 3) Setup real-time parameters. | ||
| 42 | * 4) Transition to real-time mode. | ||
| 43 | * 5) Invoke periodic or sporadic jobs. | ||
| 44 | * 6) Transition to background mode. | ||
| 45 | * 7) Clean up and exit. | ||
| 46 | * | ||
| 47 | * The following main() function provides the basic skeleton of a single-threaded | ||
| 48 | * LITMUS^RT real-time task. In a real program, all the return values should be | ||
| 49 | * checked for errors. | ||
| 50 | */ | ||
| 51 | int main(int argc, char** argv) | ||
| 52 | { | ||
| 53 | int do_exit; | ||
| 54 | |||
| 55 | /* The task is in background mode upon startup. */ | ||
| 56 | |||
| 57 | |||
| 58 | /***** | ||
| 59 | * 1) Command line paramter parsing would be done here. | ||
| 60 | */ | ||
| 61 | |||
| 62 | |||
| 63 | |||
| 64 | /***** | ||
| 65 | * 2) Work environment (e.g., global data structures, file data, etc.) would | ||
| 66 | * be setup here. | ||
| 67 | */ | ||
| 68 | |||
| 69 | |||
| 70 | |||
| 71 | /***** | ||
| 72 | * 3) Setup real-time parameters. | ||
| 73 | * In this example, we create a sporadic task that does not specify a | ||
| 74 | * target partition (and thus is intended to run under global scheduling). | ||
| 75 | * If this were to execute under a partitioned scheduler, it would be assigned | ||
| 76 | * to the first partition (since partitioning is performed offline). | ||
| 77 | */ | ||
| 78 | init_litmus(); | ||
| 79 | sporadic_global(EXEC_COST, PERIOD); | ||
| 80 | |||
| 81 | /* To specify a partition, use sporadic_partitioned(). | ||
| 82 | * Example: | ||
| 83 | * | ||
| 84 | * sporadic_partitioned(EXEC_COST, PERIOD, CPU); | ||
| 85 | * | ||
| 86 | * where CPU ranges from 0 to "Number of CPUs" - 1. | ||
| 87 | */ | ||
| 88 | |||
| 89 | |||
| 90 | |||
| 91 | /***** | ||
| 92 | * 4) Transition to real-time mode. | ||
| 93 | */ | ||
| 94 | task_mode(LITMUS_RT_TASK); | ||
| 95 | |||
| 96 | /* The task is now executing as a real-time task if the call didn't fail. | ||
| 97 | */ | ||
| 98 | |||
| 99 | |||
| 100 | |||
| 101 | /***** | ||
| 102 | * 5) Invoke real-time jobs. | ||
| 103 | */ | ||
| 104 | do { | ||
| 105 | /* Wait until the next job is released. */ | ||
| 106 | sleep_next_period(); | ||
| 107 | /* Invoke job. */ | ||
| 108 | do_exit = job(); | ||
| 109 | } while (!do_exit); | ||
| 110 | |||
| 111 | |||
| 112 | |||
| 113 | /***** | ||
| 114 | * 6) Transition to background mode. | ||
| 115 | */ | ||
| 116 | task_mode(BACKGROUND_TASK); | ||
| 117 | |||
| 118 | |||
| 119 | |||
| 120 | /***** | ||
| 121 | * 7) Clean up and exit. | ||
| 122 | */ | ||
| 123 | return 0; | ||
| 124 | } | ||
| 125 | |||
| 126 | |||
| 127 | int job(void) | ||
| 128 | { | ||
| 129 | /* Do real-time calculation. */ | ||
| 130 | |||
| 131 | /* Don't exit. */ | ||
| 132 | return 0; | ||
| 133 | } | ||
