]> rtime.felk.cvut.cz Git - frescor/frsh.git/blobdiff - resources/cpu_aquosa/mngr/frm_aqcpu.c
Merge branch 'master' of git://frsh-forb.git.sourceforge.net/gitroot/frsh-forb/frsh
[frescor/frsh.git] / resources / cpu_aquosa / mngr / frm_aqcpu.c
index a9e7a529c1d083d9ca642e0aa7d4a463bdf20949..381ad70ad6b6aae5a8ec38f428303f875dccb29d 100644 (file)
 #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 <stdio.h>
 
 UL_LOG_CUST(ulogd_frm_aqcpu);
-ul_log_domain_t ulogd_fra_fwp = {UL_LOGL_DEB, "frm_aqcpu"};
+ul_log_domain_t ulogd_frm_aqcpu = {UL_LOGL_DEB, "frm_aqcpu"};
 
 static int aqcpu_admtest(struct fres_sa_scenario *scenario, void *priv, 
                         bool *schedulable)
@@ -88,29 +90,70 @@ static int aqcpu_admtest(struct fres_sa_scenario *scenario, void *priv,
 
                sum_utilization+= budget*100/period;
        }
-       *schedulable = sum_utilization < 100;
-       printf("=> %s\n", *schedulable?"schedulable":"not schedulable");
+       *schedulable = sum_utilization <= 88; // 100;
+       if (*schedulable) {
+               scenario->utilization = sum_utilization;
+       }
+       ul_logmsg("=> %s\n", *schedulable?"schedulable":"not schedulable");
                
        return 0;
 }
 
-static const struct fres_res_manager frm = {
+static struct fres_res_manager frm = {
        .res_type = FRSH_RT_PROCESSOR,
-       .res_id = 0,
+       .res_id = FRSH_CPU_ID_DEFAULT,
        .admission_test = aqcpu_admtest,
        .name = "AQuoSA",
        .priv = NULL
 };
 
+static struct option long_opts[] = {
+    { "loglevel", 1, 0, 'l' },
+    { 0, 0, 0, 0}
+};
+
+static void
+usage(void)
+{
+       printf("usage: frm_aqcpu [ options ]\n");
+       printf("  -d, --daemon [pid-file]   go to background after FORB initialization\n");
+       printf("  -l, --loglevel <number>|<domain>=<number>,...\n");
+}
+
 int main(int argc, char *argv[])
 {
        forb_orb orb;
        int ret;
        forb_init_attr_t attr = { .orb_id = "org.frescor.frm.aqcpu" };
+       int  opt;
+       bool opt_daemon = false;
+       char *opt_pidfile = NULL;
+
+       ul_logreg_domain(&ulogd_frm_aqcpu);
+
+       while ((opt = getopt_long(argc, argv, "d::hl:", &long_opts[0], NULL)) != EOF) {
+               switch (opt) {
+                       case 'd':
+                               opt_daemon = true;
+                               opt_pidfile = optarg;
+                               break;
+                       case 'l':
+                               ul_log_domain_arg2levels(optarg);
+                               break;
+                       case 'h':
+                       /*default:*/
+                               usage();
+                               exit(opt == 'h' ? 0 : 1);
+               }
+       }
        
+       if (opt_daemon)
+               forb_daemon_prepare(opt_pidfile);
+
        orb = forb_init(&argc, &argv, &attr);
        if (!orb) error(1, errno, "forb_init");
-       
+
+       frm.res_id = frsh_get_local_cpu_id();
        ret = frm_register_and_run(orb, &frm);
 
        if (ret != 0) {