]> rtime.felk.cvut.cz Git - frescor/frsh.git/blobdiff - frsh_api/frsh_spare_capacity.c
Remove "Setup" header from tests
[frescor/frsh.git] / frsh_api / frsh_spare_capacity.c
index f86d7b7932e280c59ca955d794239d41e9924bfb..fb3efff088cffe4a12c37194d49f53c0a58d209e 100644 (file)
@@ -47,6 +47,7 @@
 /**
  * @file   frsh_spare_capacity.c
  * @author Dario Faggioli <faggioli@gandalf.sssup.it>
+ * @author Michal Sojka <sojkam1@fel.cvut.cz>
  * 
  * @brief  Implementation of FRSH contract API on top of FRES contracts.
  * 
@@ -88,20 +89,67 @@ int frsh_contract_set_reclamation_params
            (granularity == FRSH_GR_DISCRETE && utilization_set == NULL))
                return FRSH_ERR_BAD_ARGUMENT;
 
-       if (granularity != FRSH_GR_CONTINUOUS)
+       if (granularity != FRSH_GR_CONTINUOUS &&
+           granularity != FRSH_GR_DISCRETE)
                return FRSH_ERR_NOT_IMPLEMENTED;
 
        s = malloc(sizeof(*s));
        if (!s) return ENOMEM; 
+       memset(s, 0, sizeof(*s));
 
        s->budget = *budget_max;
        s->period = *period_min;
        s->granularity = granularity;
-       /*
-        * TODO:
-        *  support utilization-set for discrete spare
-        *  capacity distribution.
-        */
+
+       if (utilization_set) {
+               int i;
+               if (!forb_sequence_alloc_buf(&s->variants, utilization_set->size)) {
+                       goto err;
+               }
+               for (i=0; i<utilization_set->size; i++) {
+                       struct fres_container *c = NULL;
+                       fres_block_basic *b = NULL;
+                       fres_block_timing_reqs *t = NULL;
+                       c = fres_container_new();
+                       if (!c)
+                               goto err;
+                       b = malloc(sizeof(*b));
+                       if (!b)
+                               goto err_ut;
+                       t = malloc(sizeof(*t));
+                       if (!t)
+                               goto err_ut;
+
+                       b->budget = utilization_set->utilizations[i].budget;
+                       b->period = utilization_set->utilizations[i].period;
+                       /* FIXME: workload and contract type should be
+                        * the same as in basic_params. The easyest
+                        * solution would be to split basic block to
+                        * two blocks - (budget, period) and
+                        * (workload, contract_type).
+                        * Note: frsh_contract_set_reclamation_params()
+                        * should be defined differently. */
+                       b->workload = FRSH_WT_BOUNDED;
+                       b->contract_type = FRSH_CT_REGULAR;
+                       ret = fres_container_add_basic(c, b);
+
+                       t->d_equals_t = true; /* FIXME: the same as above */
+                       t->deadline = utilization_set->utilizations[i].deadline;
+
+                       ret = fres_container_add_timing_reqs(c, t);
+
+                       forb_sequence_elem(&s->variants, i) = c;
+                       continue;
+               err_ut:
+                       fres_container_destroy(c);
+                       free(b); /* FIXME: Possible double free */
+                       free(t);
+                       goto err;
+               }
+               s->variants._length = utilization_set->size;
+       }
+       /* TODO: In case of CONTINUOUS granularity copy min and max
+        * requirements to the variants. */
        s->importance = importance;
        s->weight = weight;
        s->stability_time = *stability_time;
@@ -109,12 +157,14 @@ int frsh_contract_set_reclamation_params
        fres_contract_del_spare_capacity(*contract);
        ret = fres_contract_add_spare_capacity(*contract, s);
 
-       if (ret) {
-               free(s);
-               return errno;
-       }
+       if (ret)
+               goto err;
 
        return FRSH_NO_ERROR;
+err:
+       forb_sequence_free_buf(&s->variants, forb_no_destructor);
+       free(s);
+       return errno;
 }
 
 int frsh_contract_get_reclamation_params