From c84c35511dcc32262e12b8a4e99b4e678a433371 Mon Sep 17 00:00:00 2001 From: Glenn Elliott Date: Mon, 16 Jul 2012 20:28:56 -0400 Subject: API Update: Support arbitrary deadlines. Updated APIs to support arbitrary deadlines. Added macros for implicit deadlines. Note: Had to tweak Makefile to support gcc version >= 4.6 (moved -lrt to the end of the link command). --- Makefile | 2 +- bin/base_mt_task.c | 28 +++++++++++++++++++++++++--- bin/base_task.c | 31 +++++++++++++++++++++++-------- src/litmus.c | 1 + tests/core_api.c | 3 +++ 5 files changed, 53 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 2109a45..391dc65 100644 --- a/Makefile +++ b/Makefile @@ -221,7 +221,7 @@ lib-measure_syscall = -lm .SECONDEXPANSION: ${rt-apps}: $${obj-$$@} liblitmus.a - $(CC) -o $@ $(LDFLAGS) ${ldf-$@} $(filter-out liblitmus.a,$+) $(LOADLIBS) $(LDLIBS) ${lib-$@} ${liblitmus-flags} + $(CC) -o $@ $(LDFLAGS) ${ldf-$@} $(filter-out liblitmus.a,$+) $(LOADLIBS) $(LDLIBS) ${liblitmus-flags} ${lib-$@} # ############################################################################## # Dependency resolution. diff --git a/bin/base_mt_task.c b/bin/base_mt_task.c index 19afb28..78446e3 100644 --- a/bin/base_mt_task.c +++ b/bin/base_mt_task.c @@ -11,6 +11,7 @@ #include #include +#include /* Include gettid() */ #include @@ -21,8 +22,11 @@ /* Include the LITMUS^RT API.*/ #include "litmus.h" -#define PERIOD 100 -#define EXEC_COST 10 +#define PERIOD 100 +#define RELATIVE_DEADLINE 100 +#define EXEC_COST 10 + +#define NS_PER_MS 1e6 /* Let's create 10 threads in the example, * for a total utilization of 1. @@ -122,6 +126,15 @@ void* rt_thread(void *tcontext) { int do_exit; struct thread_context *ctx = (struct thread_context *) tcontext; + struct rt_task param; + + /* Set up task parameters */ + memset(¶m, 0, sizeof(param)); + param.exec_cost = EXEC_COST * NS_PER_MS; + param.period = PERIOD * NS_PER_MS; + param.relative_deadline = RELATIVE_DEADLINE * NS_PER_MS; + param.cls = RT_CLASS_SOFT; + param.budget_policy = NO_ENFORCEMENT; /* Make presence visible. */ printf("RT Thread %d active.\n", ctx->id); @@ -130,7 +143,16 @@ void* rt_thread(void *tcontext) * 1) Initialize real-time settings. */ CALL( init_rt_thread() ); - CALL( sporadic_global(EXEC_COST, PERIOD) ); + + /* To specify a partition, do + * + * param.cpu = CPU; + * be_migrate_to(CPU); + * + * where CPU ranges from 0 to "Number of CPUs" - 1 before calling + * set_rt_task_param(). + */ + CALL( set_rt_task_param(gettid(), ¶m) ); /***** * 2) Transition to real-time mode. diff --git a/bin/base_task.c b/bin/base_task.c index c50990b..8baf3c8 100644 --- a/bin/base_task.c +++ b/bin/base_task.c @@ -12,6 +12,7 @@ */ #include #include +#include /* Second, we include the LITMUS^RT user space library header. * This header, part of liblitmus, provides the user space API of @@ -22,9 +23,14 @@ /* Next, we define period and execution cost to be constant. * These are only constants for convenience in this example, they can be * determined at run time, e.g., from command line parameters. + * + * These are in milliseconds. */ -#define PERIOD 100 -#define EXEC_COST 10 +#define PERIOD 100 +#define RELATIVE_DEADLINE 100 +#define EXEC_COST 10 + +#define NS_PER_MS 1e6 /* Catch errors. */ @@ -60,6 +66,15 @@ int job(void); int main(int argc, char** argv) { int do_exit; + struct rt_task param; + + /* Setup task parameters */ + memset(¶m, 0, sizeof(param)); + param.exec_cost = EXEC_COST * NS_PER_MS; + param.period = PERIOD * NS_PER_MS; + param.relative_deadline = RELATIVE_DEADLINE * NS_PER_MS; + param.cls = RT_CLASS_SOFT; + param.budget_policy = NO_ENFORCEMENT; /* The task is in background mode upon startup. */ @@ -85,16 +100,16 @@ int main(int argc, char** argv) * to the first partition (since partitioning is performed offline). */ CALL( init_litmus() ); - CALL( sporadic_global(EXEC_COST, PERIOD) ); - /* To specify a partition, use sporadic_partitioned(). - * Example: + /* To specify a partition, do * - * sporadic_partitioned(EXEC_COST, PERIOD, CPU); + * param.cpu = CPU; + * be_migrate_to(CPU); * - * where CPU ranges from 0 to "Number of CPUs" - 1. + * where CPU ranges from 0 to "Number of CPUs" - 1 before calling + * set_rt_task_param(). */ - + CALL( set_rt_task_param(gettid(), ¶m) ); /***** diff --git a/src/litmus.c b/src/litmus.c index 33937c8..b32254b 100644 --- a/src/litmus.c +++ b/src/litmus.c @@ -105,6 +105,7 @@ int sporadic_task_ns(lt_t e, lt_t p, lt_t phase, param.exec_cost = e; param.period = p; + param.relative_deadline = p; /* implicit deadline */ param.cpu = cpu; param.cls = cls; param.phase = phase; diff --git a/tests/core_api.c b/tests/core_api.c index 533fb8e..c5bbb5a 100644 --- a/tests/core_api.c +++ b/tests/core_api.c @@ -20,6 +20,7 @@ TESTCASE(set_rt_task_param_invalid_params, ALL, struct rt_task params; params.cpu = 0; params.period = 100; + params.relative_deadline = params.period; params.phase = 0; params.priority = LITMUS_LOWEST_PRIORITY; params.cls = RT_CLASS_HARD; @@ -50,6 +51,7 @@ TESTCASE(reject_bad_priorities, P_FP, params.cpu = 0; params.exec_cost = 10; params.period = 100; + params.relative_deadline = params.period; params.phase = 0; params.cls = RT_CLASS_HARD; params.budget_policy = NO_ENFORCEMENT; @@ -75,6 +77,7 @@ TESTCASE(accept_valid_priorities, P_FP, params.cpu = 0; params.exec_cost = 10; params.period = 100; + params.relative_deadline = params.period; params.phase = 0; params.cls = RT_CLASS_HARD; params.budget_policy = NO_ENFORCEMENT; -- cgit v1.2.2