From ff87ca319b0cd76f96f78f0347ad9aaa967bb16e Mon Sep 17 00:00:00 2001 From: Jonathan Herman Date: Thu, 26 Apr 2012 16:53:06 -0400 Subject: Bespin now requests resources --- Makefile | 14 +++++++------- bin/bespin.c | 15 +++++++++++---- bin/common.c | 41 +++++++++++++++++++++++++++++++++++++++++ bin/rtspin.c | 14 +++++++++++--- include/common.h | 3 ++- src/kernel_iface.c | 7 +++++++ src/litmus.c | 1 + 7 files changed, 80 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index c5a8c0a..6b1feed 100644 --- a/Makefile +++ b/Makefile @@ -12,14 +12,15 @@ host-arch := $(shell uname -m | \ ARCH ?= ${host-arch} # LITMUS_KERNEL -- where to find the litmus kernel? -LITMUS_KERNEL ?= ../litmus2010 +LITMUS_KERNEL ?= ../litmus-rt # ############################################################################## # Internal configuration. # compiler flags -flags-debug = -Wall -Werror -g -Wdeclaration-after-statement +# flags-debug = -Wall -Werror -g -Wdeclaration-after-statement +flags-debug = -Wall -g -Wdeclaration-after-statement flags-api = -D_XOPEN_SOURCE=600 -D_GNU_SOURCE # architecture-specific flags @@ -154,7 +155,7 @@ arch/${include-${ARCH}}/include/asm/%.h: \ cp $< $@ litmus-headers = include/litmus/rt_param.h include/litmus/unistd_32.h \ - include/litmus/unistd_64.h include/litmus/sched_mc.h + include/litmus/unistd_64.h include/litmus/sched_mc.h include/litmus/color.h unistd-headers = \ $(foreach file,${unistd-${ARCH}},arch/${include-${ARCH}}/include/asm/$(file)) @@ -207,14 +208,13 @@ obj-base_mt_task = base_mt_task.o ldf-base_mt_task = -pthread obj-rt_launch = rt_launch.o common.o +lib-rt_launch = -lgsl -lgslcblas obj-rtspin = rtspin.o common.o -lib-rtspin = -lrt +lib-rtspin = -lrt -lgsl -lgslcblas obj-rtspin.ovh = rtspin.ovh.o common.o -lib-rtspin.ovh = -lrt - - +lib-rtspin.ovh = -lrt -lgsl -lgslcblas obj-rtspin.beta = rtspin.beta.o common.o lib-rtspin.beta = -lrt $(shell gsl-config --libs) diff --git a/bin/bespin.c b/bin/bespin.c index 5c98a1f..4495721 100644 --- a/bin/bespin.c +++ b/bin/bespin.c @@ -51,6 +51,8 @@ static void usage(char *error) { static int num[NUMS]; static char* progname; +static int task_colors, avg_ways; + static gsl_rng *exec_rng; static gsl_rng *ia_rng; static struct timespec sleep_ts = { .tv_sec = 0 }; @@ -240,6 +242,8 @@ static void setup_litmus_task(const double phase_ms, const int cpu) if (ret < 0) bail_out("could not setup rt task params"); + request_resources(task_colors, avg_ways); + init_litmus(); ret = task_mode(LITMUS_RT_TASK); @@ -247,7 +251,7 @@ static void setup_litmus_task(const double phase_ms, const int cpu) bail_out("could not become RT task"); } -#define OPTSTR "p:wnos:f:" +#define OPTSTR "p:wl:r:nos:f:h:" int main(int argc, char** argv) { @@ -286,9 +290,9 @@ int main(int argc, char** argv) case 's': seed = atoi(optarg); break; - case 'h': - phase_ms = atof(optarg); - break; + /* case 'h': */ + /* phase_ms = atof(optarg); */ + /* break; */ case 'e': exec_mean_ms = atof(optarg); break; @@ -298,6 +302,9 @@ int main(int argc, char** argv) case 'f': out_fname = optarg; break; + case 'h': + sscanf(optarg, "%d,%d", &task_colors, &avg_ways); + break; case ':': usage("Argument missing."); break; diff --git a/bin/common.c b/bin/common.c index 452b882..2aa9a7c 100644 --- a/bin/common.c +++ b/bin/common.c @@ -3,9 +3,50 @@ #include #include "common.h" +#include "litmus.h" +#include + +#include +#include void bail_out(const char* msg) { perror(msg); exit(-1 * errno); } + +void request_resources(int task_colors, int avg_ways) +{ + const gsl_rng *way_rng = gsl_rng_alloc(gsl_rng_taus); + struct control_page *page = get_ctrl_page(); + int color, ways, rem = task_colors; + float random; + char taken[NUM_COLORS]; + + memset(page->requests, 0, NUM_COLORS*sizeof(*page->requests)); + + gsl_rng_set(way_rng, rand()); + memset(taken, 0, NUM_COLORS); + + srand(getpid()); + gsl_rng_set(way_rng, getpid()); + + while (rem) { + /* select a random unchosen color */ + do { + color = rand() % NUM_COLORS; + } while (taken[color]); + + if (rand() % NUM_COLORS <= task_colors) { + taken[color] = 1; + rem --; + + random = gsl_ran_exponential(way_rng, avg_ways + 1); + ways = 1 + (int)random; + ways = (ways < 1) ? 1 : ways; + ways = (ways > NUM_WAYS) ? NUM_WAYS : ways; + + page->requests[color] = ways; + } + } +} diff --git a/bin/rtspin.c b/bin/rtspin.c index 9800eb2..c680529 100644 --- a/bin/rtspin.c +++ b/bin/rtspin.c @@ -6,14 +6,14 @@ #include #include #include - +#include #include "litmus.h" #include "common.h" +/* #include "color.h" */ #include - static void usage(char *error) { fprintf(stderr, "Error: %s\n", error); fprintf(stderr, @@ -24,6 +24,7 @@ static void usage(char *error) { "\n" "COMMON-OPTS = [-w] [-p PARTITION] [-c CLASS] [-s SCALE]\n" " [-r CRITICALITY = [a|b|c|d]] [-i MC-LVL-A-ID]\n" + " [-h NUM-COLORS,AVG-WAYS]\n" "\n" "WCET and PERIOD are milliseconds, DURATION is seconds.\n"); exit(EXIT_FAILURE); @@ -176,7 +177,7 @@ enum crit_level str2crit(const char* str) return NUM_CRIT_LEVELS; } -#define OPTSTR "p:c:wlveo:f:s:r:i:" +#define OPTSTR "p:c:wlveo:f:s:r:i:h:" int main(int argc, char** argv) { @@ -197,6 +198,8 @@ int main(int argc, char** argv) double scale = 1.0; task_class_t class = RT_CLASS_HARD; int cur_job, num_jobs; + int task_colors = 0; + int avg_ways = 0; struct mc_task mc_task = { .crit = NUM_CRIT_LEVELS, .lvl_a_id = -1 }; progname = argv[0]; @@ -238,6 +241,9 @@ int main(int argc, char** argv) case 'i': mc_task.lvl_a_id = atoi(optarg); break; + case 'h': + sscanf(optarg, "%d,%d", &task_colors, &avg_ways); + break; case ':': usage("Argument missing."); break; @@ -313,6 +319,8 @@ int main(int argc, char** argv) init_litmus(); + request_resources(task_colors, avg_ways); + ret = task_mode(LITMUS_RT_TASK); if (ret != 0) bail_out("could not become RT task"); diff --git a/include/common.h b/include/common.h index d1234ba..5c7ed68 100644 --- a/include/common.h +++ b/include/common.h @@ -1,7 +1,8 @@ #ifndef COMMON_H #define COMMON_H - void bail_out(const char* msg); +void request_resources(int task_colors, int avg_ways); + #endif diff --git a/src/kernel_iface.c b/src/kernel_iface.c index 1426795..6286810 100644 --- a/src/kernel_iface.c +++ b/src/kernel_iface.c @@ -71,6 +71,13 @@ void exit_np(void) } } +void request_resource(int resource, int replicas) +{ + if (likely(ctrl_page != NULL)) { + ctrl_page->requests[resource] = replicas; + } +} + /* init and return a ptr to the control page for * preemption and migration overhead analysis * diff --git a/src/litmus.c b/src/litmus.c index d3cc6bb..d8a6b96 100644 --- a/src/litmus.c +++ b/src/litmus.c @@ -72,6 +72,7 @@ int sporadic_task_ns(lt_t e, lt_t p, lt_t phase, ret = be_migrate_to(cpu); check("migrate to cpu"); } + return set_rt_task_param(gettid(), ¶m); } -- cgit v1.2.2