+/**************************************************************************/
+/* ---------------------------------------------------------------------- */
+/* Copyright (C) 2006 - 2008 FRESCOR consortium partners: */
+/* */
+/* Universidad de Cantabria, SPAIN */
+/* University of York, UK */
+/* Scuola Superiore Sant'Anna, ITALY */
+/* Kaiserslautern University, GERMANY */
+/* Univ. Politécnica Valencia, SPAIN */
+/* Czech Technical University in Prague, CZECH REPUBLIC */
+/* ENEA SWEDEN */
+/* Thales Communication S.A. FRANCE */
+/* Visual Tools S.A. SPAIN */
+/* Rapita Systems Ltd UK */
+/* Evidence ITALY */
+/* */
+/* See http://www.frescor.org for a link to partners' websites */
+/* */
+/* FRESCOR project (FP6/2005/IST/5-034026) is funded */
+/* in part by the European Union Sixth Framework Programme */
+/* The European Union is not liable of any use that may be */
+/* made of this code. */
+/* */
+/* */
+/* This file is part of FRSH (FRescor ScHeduler) */
+/* */
+/* FRSH is free software; you can redistribute it and/or modify it */
+/* under terms of the GNU General Public License as published by the */
+/* Free Software Foundation; either version 2, or (at your option) any */
+/* later version. FRSH 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 FRSH; see file */
+/* COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, */
+/* Cambridge, MA 02139, USA. */
+/* */
+/* As a special exception, including FRSH header files in a file, */
+/* instantiating FRSH generics or templates, or linking other files */
+/* with FRSH objects to produce an executable application, does not */
+/* by itself cause the resulting executable application to be covered */
+/* by the GNU General Public License. This exception does not */
+/* however invalidate any other reasons why the executable file might be */
+/* covered by the GNU Public License. */
+/**************************************************************************/
+
+/**
+ * @file frm_dummy.c
+ * @author Michal Sojka <sojkam1@fel.cvut.cz>
+ * @date Wed Feb 18 16:06:04 2009
+ *
+ * @brief Dummy resource manager implementation
+ *
+ *
+ */
+
+
#include <frm_generic.h>
#include <forb.h>
#include <error.h>
#include <errno.h>
+#include <getopt.h>
#include <fres_sa_scenario.h>
#include <stdbool.h>
#include <ul_log.h>
+#include <ul_logreg.h>
#include "res_dummy.h"
#include <stdio.h>
+#include "dummy_config.h"
+
+bool opt_accept_all = false;
+bool opt_daemon = false;
+char *opt_pidfile = NULL;
+int opt_res_id = DUMMY_RESOURCE_ID;
struct dummy_data {
int some_data;
};
-
-bool admission_test(struct fres_sa_scenario *scenario, void *priv)
+int admission_test(struct fres_sa_scenario *scenario, void *priv, bool *schedulable)
{
- bool schedulable;
struct dummy_data *data = priv;
struct fres_sa_contract *c;
+ int ret;
+ long int utilization = 0;
+#ifdef CONFIG_RESOURCE_DUMMY_VERBOSE
printf("Admission test:\n");
+#endif
+
+ if (opt_accept_all) {
+ *schedulable = true;
+ return 0;
+ }
+
data->some_data++;
- fres_sa_scenario_for_each_contract(scenario, c) {
+ fres_sa_scenario_for_each_no_cancel_contract(scenario, c) {
fres_block_basic *basic;
fres_block_dummy_sched *dummy_sched;
char id[40];
- fres_contract_id_to_string(id, &c->contract->id, sizeof(id));
+ fres_contract_id_to_string(id, &c->id, sizeof(id));
+#ifdef CONFIG_RESOURCE_DUMMY_VERBOSE
+ printf(" %s contract: id=%s num_blocks=%d\n",
+ c->contract == c->new ? "new" : "old", id,
+ fres_contract_get_num_blocks(c->contract));
+#endif
+
basic = fres_contract_get_basic(c->contract);
+ if (!basic) {
+ fprintf(stderr, "No basic block present\n");
+ return -1;
+ }
- if (c->status == FRES_SA_CONTRACT_NEW) {
+ if (c->contract == c->new) {
/* Add data for scheduler to the new contracts */
dummy_sched = malloc(sizeof(*dummy_sched));
- if (!dummy_sched) return false;
+ if (!dummy_sched) return -1;
dummy_sched->priority = 100 - fosa_rel_time_to_msec(basic->budget);
- fres_contract_add_block(c->contract, FRES_BLOCK_DUMMY_SCHED, dummy_sched);
+ ret = fres_contract_add_dummy_sched(c->contract, dummy_sched);
+ if (ret) {
+ fprintf(stderr, "Cannot add dummy_sched block\n");
+ return -1;
+ }
} else {
- dummy_sched = fres_contract_get_block(c->contract, FRES_BLOCK_DUMMY_SCHED);
+ dummy_sched = fres_contract_get_dummy_sched(c->contract);
+ if (!dummy_sched) {
+ fprintf(stderr, "Dummy_sched is not present\n");
+ return -1;
+ }
}
-
- printf(" %s contract: id=%s, period=%ld ms, budget=%ld ms, priority=%d\n",
- c->status == FRES_SA_CONTRACT_NEW ? "new" : "old", id,
+#ifdef CONFIG_RESOURCE_DUMMY_VERBOSE
+ printf(" period=%ld ms, budget=%ld ms, priority=%d\n",
fosa_rel_time_to_msec(basic->period),
fosa_rel_time_to_msec(basic->budget), dummy_sched->priority);
-
-
+#endif
+ utilization +=
+ 1000*fosa_rel_time_to_msec(basic->budget) /
+ fosa_rel_time_to_msec(basic->period);
+ }
+ *schedulable = utilization < 1000;
+ if (*schedulable) {
+ scenario->utilization = utilization/10;
}
- schedulable = scenario->num_contracts <= 3;
- printf("=> %s\n", schedulable?"schedulable":"not schedulable");
+
+#ifdef CONFIG_RESOURCE_DUMMY_VERBOSE
+ printf("utilization=%ld.%03ld => %s\n", utilization/1000, utilization%1000,
+ *schedulable?"schedulable":"not schedulable");
+#endif
- return schedulable;
+ return 0;
}
struct dummy_data dummy_data;
-static const struct fres_res_manager frm = {
+static struct fres_res_manager frm = {
.res_type = DUMMY_RESOURCE_TYPE,
.res_id = DUMMY_RESOURCE_ID,
.admission_test = admission_test,
- .priv = &dummy_data
+ .priv = &dummy_data,
+ .name = "Dummy resource",
};
+static struct option long_opts[] = {
+ { "loglevel", 1, 0, 'l' },
+// { "id", required_argument, 0, 'i' },
+ { "accept-all", 0, 0, 'a' },
+ { "help", 0, 0, 'h' },
+ { 0, 0, 0, 0}
+};
-int main(int argc, char *argv[])
+static void
+usage(void)
+{
+ printf("usage: frm_dummy [ options ]\n");
+ printf(" -a, --accept-all Accepts all contracts\n");
+ printf(" -d, --daemon [pid-file] go to background after FORB initialization\n");
+/* printf(" -i, --id <resource id> Use a different id that the default (%d)\n", DUMMY_RESOURCE_ID);*/
+ printf(" -h, --help Display this help\n");
+ printf(" -l, --loglevel <number>|<domain>=<number>,...\n");
+}
+
+int forb_main(forb_orb orb, int argc, char *argv[])
{
- forb_orb orb;
int ret;
+ forb_init_attr_t attr = { .orb_id = "org.frescor.frm.dummy" };
+ int opt;
+
+ while ((opt = getopt_long(argc, argv, "ai:l:h", &long_opts[0], NULL)) != EOF) {
+ switch (opt) {
+ case 'a':
+ opt_accept_all = true;
+ case 'd':
+ opt_daemon = true;
+ opt_pidfile = optarg;
+ break;
+// case 'i':
+// opt_res_id = atoi(optarg);
+// break;
+ case 'l':
+ ul_log_domain_arg2levels(optarg);
+ break;
+ case 'h':
+ /*default:*/
+ usage();
+ exit(opt == 'h' ? 0 : 1);
+ }
+ }
- orb = forb_init(&argc, &argv, "frm_dummy");
- if (!orb) error(1, errno, "forb_init");
+ if (opt_daemon)
+ forb_daemon_prepare(opt_pidfile);
/* Register fres_block_dummy_sched to contract handling
* functions */
fres_block_register_dummy();
+#ifndef CONFIG_RESOURCE_DUMMY_VERBOSE
+ ulogd_frm_generic.level = UL_LOGL_ERR;
+#endif
+
+ frm.res_id = opt_res_id;
ret = frm_register_and_run(orb, &frm);
if (ret != 0) {