]> rtime.felk.cvut.cz Git - frescor/frsh.git/commitdiff
Merge branch 'master' of git://rtime.felk.cvut.cz/frescor/frsh_forb
authorMichal Sojka <sojkam1@fel.cvut.cz>
Tue, 19 May 2009 13:38:41 +0000 (15:38 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Tue, 19 May 2009 13:38:41 +0000 (15:38 +0200)
Conflicts:
frsh_api/frsh_power.c

28 files changed:
.topdeps [deleted file]
.topmsg [deleted file]
demo/Makefile.omk
demo/video/Makefile [new file with mode: 0644]
demo/video/Makefile.omk [new file with mode: 0644]
demo/video/play.c [new file with mode: 0644]
demo/video/play.h [new file with mode: 0644]
demo/video/play_th.c [new file with mode: 0644]
demo/video/play_th.h [new file with mode: 0644]
fres/cbroker/Makefile.omk
fres/cbroker/fcb.c
fres/cbroker/fcb.idl
fres/contract/fres_error.c
fres/contract/fres_error.h
fres/resalloc/fra_registry.c
frsh_api/frsh_contract.c
frsh_api/frsh_error.c
frsh_api/frsh_power.c
frsh_api/tests/spare_capacity.c
resources/acpi_battery/tests/acpi_battery_test.c
resources/acpi_cpu/fra_acpi_cpu.c
resources/acpi_cpu/fra_acpi_cpu.h
resources/acpi_cpu/tests/acpi_cpu_test.c
resources/acpi_lcd/fra_acpi_lcd.c
resources/acpi_lcd/fra_acpi_lcd.h
resources/acpi_lcd/tests/acpi_lcd_test.c
resources/cpu_aquosa/lib/aqcpu_fra.c
resources/dummy/frm_dummy.c

diff --git a/.topdeps b/.topdeps
deleted file mode 100644 (file)
index 1f7391f..0000000
--- a/.topdeps
+++ /dev/null
@@ -1 +0,0 @@
-master
diff --git a/.topmsg b/.topmsg
deleted file mode 100644 (file)
index 1e1cd7c..0000000
--- a/.topmsg
+++ /dev/null
@@ -1,6 +0,0 @@
-From: Michal Sojka <sojkam1@fel.cvut.cz>
-Subject: [PATCH] api-enhancements
-
-<patch description>
-
-Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>
index 93267e3591fd04b4d2761406bcd68f0f999048e0..d4a819ef0ef5f42bb12db265f17887cc03de6ae7 100644 (file)
@@ -1,6 +1,8 @@
-default_CONFIG = CONFIG_DEMO_CAMERA=n CONFIG_DEMO_DCAMERA=y
+default_CONFIG = CONFIG_DEMO_VIDEO=y CONFIG_DEMO_CAMERA=n CONFIG_DEMO_DCAMERA=y
 
 
 SUBDIRS=$(SUBDIRS-y)
+SUBDIRS-$(CONFIG_DEMO_VIDEO) += video
 SUBDIRS-$(CONFIG_DEMO_CAMERA) += camera
 SUBDIRS-$(CONFIG_DEMO_DCAMERA) += dcamera
+
diff --git a/demo/video/Makefile b/demo/video/Makefile
new file mode 100644 (file)
index 0000000..b22a357
--- /dev/null
@@ -0,0 +1,14 @@
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ;  while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" = `pwd`  ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+else
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
diff --git a/demo/video/Makefile.omk b/demo/video/Makefile.omk
new file mode 100644 (file)
index 0000000..24c7ba7
--- /dev/null
@@ -0,0 +1,9 @@
+FRSH_LIBS = frsh
+lib_LOADLIBES+= m pthread rt $(FRSH_LIBS)
+
+bin_PROGRAMS = fplayer
+fplayer_SOURCES = play.c play.h
+
+bin_PROGRAMS += fplayer_th
+fplayer_th_SOURCES = play_th.c play_th.h
+
diff --git a/demo/video/play.c b/demo/video/play.c
new file mode 100644 (file)
index 0000000..4bc7bf8
--- /dev/null
@@ -0,0 +1,132 @@
+#include "play.h"
+
+frsh_rel_time_t player_budget, player_period;
+frsh_contract_t player_contract;
+frsh_thread_id_t player_thread;
+frsh_vres_id_t player_vres;
+
+sem_t *player_stopper;
+int stopper_fd;
+
+void player(struct player_args *args)
+{
+       char cmd[255];
+
+       fprintf(stdout, "== Waiting for being bound...\n");
+
+       sem_wait(player_stopper);
+       munmap(player_stopper, sizeof(sem_t));
+
+       fprintf(stdout,
+               "== Starting playing %s, with %d/%d CPU bandwidth\n",
+               args->file, args->budget, args->period);
+
+       snprintf(cmd, 255, PLAYER_BINARY PLAYER_ARGS " %s", args->file);
+       fprintf(stdout, "== Issuing command:\n  %s\n", cmd);
+
+       execlp(PLAYER_BINARY, PLAYER_BINARY, PLAYER_ARGS, args->file, (char*) NULL);
+}
+
+int main(int argc, char *argv[])
+{
+       struct player_args args;
+       int player_status;
+       pid_t player_pid;
+       int opt, terror;
+
+       if (argc < 7) {
+err_usage:
+               fprintf(stderr, "USAGE:\n"
+                       "%s -b budget_usec -p period_usec -f file\n\n",
+                       argv[0]);
+               error(EXIT_FAILURE, EINVAL, "Wrong argument count");
+       }
+
+       while ((opt = getopt(argc, argv, "b:p:f:")) != -1) {
+               switch (opt) {
+                       case 'b':
+                               args.budget = atoi(optarg);
+                               break;
+                       case 'p':
+                               args.period = atoi(optarg);
+                               break;
+                       case 'f':
+                               strncpy(args.file, optarg, sizeof(args.file));
+                               break;
+                       default:
+                               goto err_usage;
+               }
+       }
+
+       PXW(frsh_init());
+
+       stopper_fd = shm_open("/stopper", O_CREAT|O_EXCL|O_RDWR, S_IRWXU);
+        if (stopper_fd < 0) assert_perror(errno);
+
+        terror = ftruncate(stopper_fd, sizeof(sem_t));
+       if (terror) {
+               shm_unlink("/stopper");
+               assert_perror(errno);
+       }
+
+       player_stopper = mmap(NULL, sizeof(sem_t), PROT_READ|PROT_WRITE,
+                             MAP_SHARED, stopper_fd, 0);
+       if (player_stopper == MAP_FAILED) {
+               shm_unlink("/stopper");
+               assert_perror(errno);
+       }
+
+       terror = close(stopper_fd);
+       if (terror) {
+               shm_unlink("/stopper");
+               assert_perror(errno);
+       }
+
+       sem_init(player_stopper, 1, 0);
+       fprintf(stderr, "FRSH initialized\n");
+
+       player_budget = fosa_usec_to_rel_time(args.budget);
+       player_period = fosa_usec_to_rel_time(args.period);
+       PXW(frsh_contract_init(&player_contract));
+       PXW(frsh_contract_set_basic_params(&player_contract,
+                                          &player_budget,
+                                          &player_period,
+                                          FRSH_WT_INDETERMINATE,
+                                          FRSH_CT_REGULAR));
+       PXW(frsh_contract_set_resource_and_label(&player_contract,
+                                                FRSH_RT_PROCESSOR,
+                                                0,
+                                                "PLAYER_CONTRACT"));
+       fprintf(stdout, "Player contract initialized\n");
+
+       PXW(frsh_contract_negotiate(&player_contract, &player_vres));
+       fprintf(stdout, "Player contract negotiated\n");
+
+       terror = player_pid = fork();
+       if (terror < 0) {
+               /* error */
+               assert_perror(errno);
+       } else if (!terror) {
+               /* child process: */
+               player(&args);
+       }
+
+       player_thread.linux_pid = player_thread.linux_tid = player_pid;
+       PXW(frsh_thread_bind(player_vres, player_thread));
+       fprintf(stdout, "Player thread bound to its contract\n");
+
+       sem_post(player_stopper);
+       munmap(player_stopper, sizeof(sem_t));
+       shm_unlink("/stopper");
+
+       waitpid(player_pid, &player_status, 0);
+       if (WIFEXITED(player_status))
+               fprintf(stdout, "Playback finished normally\n");
+       else if (WIFSIGNALED(player_status))
+               fprintf(stdout, "Playback aborted\n");
+
+       PXW(frsh_contract_cancel(player_vres));
+
+       exit(EXIT_SUCCESS);
+}
+
diff --git a/demo/video/play.h b/demo/video/play.h
new file mode 100644 (file)
index 0000000..e7c1c71
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef _PLAY_H_
+#define _PLAY_H_
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#include <error.h>
+#include <assert.h>
+#include <semaphore.h>
+#include <sys/wait.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+
+#include <frsh.h>
+
+#define PLAYER_BINARY  "mplayer"
+#define PLAYER_ARGS    " -fs -zoom "
+
+struct player_args {
+       int budget, period;
+       char file[128];
+};
+
+void player(struct player_args *args);
+
+#endif /* _PLAY_H_ */
+
diff --git a/demo/video/play_th.c b/demo/video/play_th.c
new file mode 100644 (file)
index 0000000..c896d2a
--- /dev/null
@@ -0,0 +1,113 @@
+#include "play_th.h"
+
+static void player_cleanup(void *arg)
+{
+       frsh_vres_id_t vres;
+
+       frsh_thread_get_vres_id(fosa_thread_self(), &vres);
+       frsh_contract_cancel(vres);
+}
+
+void *player(void *thread_args)
+{
+       struct player_args *args = (struct player_args*) thread_args;
+
+       frsh_rel_time_t player_budget, player_period;
+       frsh_contract_t player_contract;
+       frsh_vres_id_t player_vres;
+
+       int terror, status;
+       char cmd[255];
+
+       fprintf(stdout, "== Waiting for being bound...\n");
+
+       fprintf(stdout,
+               "== Starting playing %s, with %d/%d CPU bandwidth\n",
+               args->file, args->budget, args->period);
+
+       player_budget = fosa_usec_to_rel_time(args->budget);
+       player_period = fosa_usec_to_rel_time(args->period);
+       PXW(frsh_contract_init(&player_contract));
+       PXW(frsh_contract_set_basic_params(&player_contract,
+                                          &player_budget,
+                                          &player_period,
+                                          FRSH_WT_INDETERMINATE,
+                                          FRSH_CT_REGULAR));
+       PXW(frsh_contract_set_resource_and_label(&player_contract,
+                                                FRSH_RT_PROCESSOR,
+                                                0,
+                                                "PLAYER_CONTRACT"));
+       fprintf(stdout, "== Player contract initialized\n");
+
+       PXW(frsh_contract_negotiate(&player_contract, &player_vres));
+       fprintf(stdout, "== Player contract negotiated\n");
+
+       pthread_cleanup_push(player_cleanup, NULL);
+
+       PXW(frsh_thread_bind(player_vres, fosa_thread_self()));
+       fprintf(stdout, "== Player thread bound to its contract\n");
+
+       snprintf(cmd, 255, PLAYER_BINARY PLAYER_ARGS " %s", args->file);
+
+       fprintf(stdout, "== Issuing command:\n  %s\n", cmd);
+
+       status = system(cmd);
+
+       if (WIFEXITED(status))
+               fprintf(stdout, "== Playback finished normally\n");
+       else if (WIFSIGNALED(status))
+               fprintf(stdout, "== Playback aborted\n");
+
+       pthread_cleanup_pop(1);
+
+       pthread_exit(EXIT_SUCCESS);
+}
+
+int main(int argc, char *argv[])
+{
+       pthread_t player_thread;
+       pthread_attr_t player_attr;
+       struct player_args args;
+       int opt, terror;
+
+       if (argc < 7) {
+err_usage:
+               fprintf(stderr, "USAGE:\n"
+                       "%s -b budget_usec -p period_usec -f file\n\n",
+                       argv[0]);
+               error(EXIT_FAILURE, EINVAL, "Wrong argument count");
+       }
+
+       while ((opt = getopt(argc, argv, "b:p:f:")) != -1) {
+               switch (opt) {
+                       case 'b':
+                               args.budget = atoi(optarg);
+                               break;
+                       case 'p':
+                               args.period = atoi(optarg);
+                               break;
+                       case 'f':
+                               strncpy(args.file, optarg, sizeof(args.file));
+                               break;
+                       default:
+                               goto err_usage;
+               }
+       }
+
+       PXW(frsh_init());
+       fprintf(stdout, "FRSH initialized\n");
+
+       terror = pthread_attr_init(&player_attr);
+       if (terror) assert_perror(errno);
+
+       terror = pthread_create(&player_thread, &player_attr, player, (void*) &args);
+       if (terror) assert_perror(errno);
+       fprintf(stdout, "FRSH thread created, waiting for its termination...\n");
+
+       terror = pthread_join(player_thread, NULL);
+       if (terror) assert_perror(errno);
+       fprintf(stdout, "FRSH thread ended. Exiting\n\n");
+
+       exit(EXIT_SUCCESS);
+}
+
diff --git a/demo/video/play_th.h b/demo/video/play_th.h
new file mode 100644 (file)
index 0000000..4d43c59
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef _PLAY_H_
+#define _PLAY_H_
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#include <error.h>
+#include <assert.h>
+#include <semaphore.h>
+#include <sys/wait.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+
+#include <frsh.h>
+
+#define PLAYER_BINARY  "mplayer"
+#define PLAYER_ARGS    " -fs -zoom "
+
+struct player_args {
+       int budget, period;
+       char file[128];
+};
+
+void *player(void *args);
+
+#endif /* _PLAY_H_ */
+
index 0ac35169354627e59a2f3dc1f79a93d00b7d0e9b..2d48ee612a78cbc9336cc269987193eb13dd53d2 100644 (file)
@@ -2,6 +2,7 @@ bin_PROGRAMS += fcb
 
 fcb_SOURCES = fcb.c
 fcb_LIBS = contract fosa forb pthread rt ulut frm_client fra_client
+fcb_LIBS += frsh               # For frsh_strerror
 fcb_SERVER_IDL = fcb.idl
 
 lib_LIBRARIES += fcb_client 
index 19e54d20f3e3f64fa1cc7e042f7aedc6c8b601f2..d18d072d4224708070462608450fcd8352d22519 100644 (file)
@@ -105,14 +105,19 @@ struct res_alloc {
 
 struct fcb_contract {
        fres_contract_id_t id;
+       struct res_alloc *ra;   /**< Allocator for this contract TODO: Remove contract if allocator is destroyed */
        gavl_node_t node_fcb;
        ul_list_node_t node_sc;
-       int next_sc_variant;
-       int reserved_sc_variant;
+       ul_list_node_t node_reservation;
+       struct {
+               int initial;
+               int try;
+       } sc_variant;
        fosa_abs_time_t end_of_stability_period;
-       struct fres_contract *user_contract;
-       struct fres_contract *reserved_contract;
+       struct fres_contract *user_contract; /* The contract sent by user. Set after sucessfull neotiation. */
+       struct fres_contract *requested_contract; /* User request for the contract. Set by prepare_reservation_requests() in the beginning of negotiation. */
        struct fres_contract *to_be_reserved_contract;
+       struct fres_contract *schedulable_contract;
 };
 
 /**
@@ -123,6 +128,12 @@ struct fcb {
        gavl_cust_root_field_t contracts; /**< Contracts negotiated by this FCB */
 };
 
+/** List of contracts to be reserved during spare capacity rebalancing */
+struct reservation_list {
+       ul_list_head_t fcb_contracts;
+       unsigned length;
+};
+
 struct fcb_contract *fcb_contract_new(fres_contract_id_t *id)
 {
        struct fcb_contract *fcb_contract;
@@ -142,6 +153,15 @@ void fcb_contract_destroy(struct fcb_contract *fcb_contract)
        if (fcb_contract->user_contract) {
                fres_contract_destroy(fcb_contract->user_contract);
        }
+       if (fcb_contract->to_be_reserved_contract) {
+               fres_contract_destroy(fcb_contract->to_be_reserved_contract);
+       }
+       if (fcb_contract->requested_contract) {
+               fres_contract_destroy(fcb_contract->requested_contract);
+       }
+       if (fcb_contract->schedulable_contract) {
+               fres_contract_destroy(fcb_contract->requested_contract);
+       }
        free(fcb_contract);
 }
 
@@ -206,6 +226,12 @@ UL_LIST_CUST_DEC(sc_contracts        /* cust_prefix */,                    \
                 sc_contracts   /* cust_head_field */,                  \
                 node_sc        /* cust_node_field */);
 
+UL_LIST_CUST_DEC(reservation_list        /* cust_prefix */,            \
+                struct reservation_list  /* cust_head_t */,            \
+                struct fcb_contract /* cust_item_t */,                 \
+                fcb_contracts  /* cust_head_field */,                  \
+                node_reservation /* cust_node_field */);
+
 /* Container for negotiated contracts */
 GAVL_CUST_NODE_INT_DEC(fcb_contract         /* cust_prefix */,         \
                       struct fcb           /* cust_root_t */,          \
@@ -232,23 +258,12 @@ GAVL_CUST_NODE_INT_IMP(fcb_contract         /* cust_prefix */,            \
 
 #define o2fcb(o) (struct fcb*)forb_instance_data(o)
 
-struct res_key *
-get_res_key(const struct fcb *fcb, const struct fres_contract *contract, struct res_key *key)
+struct res_key*
+get_res_key(const struct fres_contract *contract, struct res_key *key)
 {
        fres_block_resource *block_res;
        
        block_res = fres_contract_get_resource(contract);
-       if (!block_res && !fres_contract_id_is_empty(&contract->id)) {
-               /* If the contract doesn't have resource information,
-                * this might be cancelation or renegotiation request,
-                * so look at our database for formerly submited
-                * contract.  */
-               struct fcb_contract *fcb_contract;
-               fcb_contract = fcb_contract_find(fcb, &contract->id);
-               if (fcb_contract) {
-                       block_res = fres_contract_get_resource(fcb_contract->user_contract);
-               }
-       }
        if (!block_res) {
                ul_logerr("No resource specified\n");
                return NULL;
@@ -260,125 +275,304 @@ get_res_key(const struct fcb *fcb, const struct fres_contract *contract, struct
 }
 
 /** 
- * Checks whether all contracts refers to a single resource.
+ * Fills in an array of fcb_contracts according to requests submited
+ * to negotiate_contracts(). For every contract in @a contracts, there
+ * is one fcb_contract in @a fcb_contracts array.
  * 
- * @param fcb 
- * @param contracts Array of contract pointers.
- * @param num Number of contracts.
+ * @param fcb
+ * @param fcb_contracts Where to store pointers to fcb_contracts
+ * @param resource Resource for which negotiation is being done.
+ * @param app Application which requests negotiation
+ * @param contracts Contracts submited to negotiate_contracts() 
+ * @param num Number of contracts in contracts (which is the same as the number in fcb_contracts).
  * 
- * @return If all contracts refer to a signle resource, pointer to the
- * coresponding resource structure is returned. Otherwise, NULL is
- * returned.
+ * @return Zero on success, non-zero error code on error.
  */
-struct resource *
-check_single_resource(struct fcb *fcb, struct fres_contract *contracts[], int num)
+static int
+prepare_fcb_contracts(struct fcb *fcb, struct fcb_contract *fcb_contracts[],
+                     struct resource **resource,
+                     forb_server_id *app,
+                     struct fres_contract *contracts[], int num)
 {
-       struct resource *resource = NULL;
        unsigned i;
+       struct fcb_contract *fc;
+       struct res_alloc *ra;
        struct res_key key, key2 = {-1,-1};
 
        for (i=0; i<num; i++) {
-               if (!get_res_key(fcb, contracts[i], &key)) {
-                       return NULL;
+               struct fres_contract *c = contracts[i];
+
+               if (fres_contract_id_is_empty(&c->id)) {
+                       /* Normal negotiation request */
+                       forb_uuid_generate((forb_uuid_t *)&c->id);
+                       fc = fcb_contract_new(&c->id);
+                       if (!fc)
+                               return errno;
+                       fcb_contracts[i] = fc;
+                       if (!get_res_key(c, &key)) {
+                               return FRSH_ERR_RESOURCE_ID_INVALID;
+                       }
+               } else {
+                       fc = fcb_contract_find(fcb, &c->id);
+                       if (!fc) {
+                               char str[60];
+                               fres_contract_id_to_string(str, &c->id, sizeof(str));
+                               ul_logerr("Attempt to change unknown contract %s\n", str);
+                               return FRES_ERR_NOTHING_TO_RENEGOTIATE;
+                       } else {
+                               fcb_contracts[i] = fc;
+                               if (fres_contract_get_num_blocks(c) == 0) {
+                                       /* Cancelation */
+                                       get_res_key(fc->user_contract, &key);
+                               } else {
+                                       /* Renegotiation */
+                                       if (!get_res_key(c, &key)) {
+                                               return FRSH_ERR_RESOURCE_ID_INVALID;
+                                       }
+                               }
+                       }
+               }
+               fc->requested_contract = c;
+
+               /* Check that all contracts are for the same resource */
+               if (i==0) {
+                       key2 = key;
+                       *resource = fcb_resource_find(fcb, &key);
+                       if (!*resource) {
+                               ul_logerr("No resource manager for %d.%d registered\n",
+                                         key.type, key.id);
+                               return FRSH_ERR_RESOURCE_ID_INVALID;
+                       }
                }
-               if (i==0) key2 = key;
                else if (key.type != key2.type ||
                         key.id   != key2.id) {
-                       return NULL;
+                       ul_logerr("Contract #%d differs in resource!\n", i);
+                       return FRSH_ERR_RESOURCE_ID_INVALID;
+               }
+
+               /* Find allocator for this request */
+               ra = fcb_alloc_find(*resource, app);
+               if (!ra) {
+                       char str[60];
+                       forb_server_id_to_string(str, app, sizeof(str));
+                       ul_logerr("No resource allocator found for %d.%d and %s\n",
+                                 (*resource)->key.type, (*resource)->key.id, str);
+                       return FRES_ERR_NO_RESOURCE_ALLOCATOR;
                }
+               fc->ra = ra;
+       }       
+       return 0;
+}
+
+static void fres_contract_ptr_destroy(struct fres_contract **p)
+{
+       fres_contract_destroy(*p);
+}
+
+/**
+ * @param resource Resource for which to rebalance capacity and negotiate new contracts
+ * @param fcb_contract New requests to negotiate
+ * @param num The number of elements in @a fcb_contract
+ * @param[out] rl List with changed contracts to be commited
+ */
+static void
+prepare_reservation_list(struct resource *resource,
+                        struct fcb_contract *fcb_contract[], int num,
+                        struct reservation_list *rl)
+{
+       int i;
+       fosa_abs_time_t now;
+       struct fcb_contract *fc;
+
+       reservation_list_init_head(rl);
+       rl->length = 0;
+       for (i=0; i<num; i++) {
+               assert(fcb_contract[i]->requested_contract != NULL);
+               reservation_list_insert(rl, fcb_contract[i]);
+               rl->length++;
        }
-       
-       resource = fcb_resource_find(fcb, &key);
-       if (!resource) {
-               ul_logerr("No resource manager for %d.%d registered\n",
-                         key.type, key.id);
+       fosa_clock_get_time(CLOCK_REALTIME, &now);
+       ul_list_for_each(sc_contracts, resource, fc) {
+               if (fosa_abs_time_smaller(fc->end_of_stability_period, now) &&
+                   fc->requested_contract == NULL) /* Do not insert contract inserted above */
+               {
+                       reservation_list_insert(rl, fc);
+                       rl->length++;
+               }
        }
-       return resource;
 }
 
 /** 
  * 
  * 
- * @param fcb 
- * @param contracts 
- * @param num 
+ * @param resource Resource for which to rebalance capacity and negotiate new contracts
+ * @param rl List with changed contracts to be commited
  * 
- * @return Zero on success, non-zero error code on error.
+ * @return Zero on success, non-zero error code on error
  */
 static int
-prepare_reservation_contracts(struct fcb *fcb, struct fres_contract *contracts[], int num)
+rebalance_spare_capacity_and_reserve(struct resource *resource,
+                                    struct reservation_list *rl)
 {
+       int ret;
        unsigned i;
-       struct fcb_contract *fcb_contract;
-       
-       for (i=0; i<num; i++) {
-               struct fres_contract *c = contracts[i];
+       struct fcb_contract *fc;
+       fres_block_spare_capacity *s;
+
+       fres_contract_ptr_seq contracts;
+       forb_sequence_alloc_buf(contracts, rl->length);
+       contracts._length = rl->length;
+       i=0;
+       /* Initialize optimization */
+       ul_list_for_each(reservation_list, rl, fc) {
+               fc->to_be_reserved_contract =
+                       fc->requested_contract ? fres_contract_duplicate(fc->requested_contract) :
+                       fc->user_contract ? fres_contract_duplicate(fc->user_contract) :
+                       NULL;
+               assert(fc->to_be_reserved_contract != NULL);
+
+               forb_sequence_elem(contracts, i) = fc->to_be_reserved_contract;
+               i++;
                
-               if (fres_contract_id_is_empty(&c->id)) {
-                       /* Normal negotiation request */
-                       forb_uuid_generate((forb_uuid_t *)&c->id);
-                       continue;
-               }
-               if (fres_contract_get_num_blocks(c) == 0) {
-                       /* Nothing to do for deletion requesst */
-                       continue;
+               s = fres_contract_get_spare_capacity(fc->to_be_reserved_contract);
+               if (s && s->granularity == FRSH_GR_DISCRETE) {
+                       fc->sc_variant.initial = s->variants._length - 1;
+                       fc->sc_variant.try = fc->sc_variant.initial;
                }
+       }
 
-               /* Renegotiation */
-               fcb_contract = fcb_contract_find(fcb, &c->id);
-               if (fcb_contract) {
-                       /* Copy missing blocks from fcb_contract to contract */
-                       fres_contract_merge(c, fcb_contract->user_contract);
-               } else {
-                       char str[60];
-                       fres_contract_id_to_string(str, &c->id, sizeof(str));
-                       ul_logerr("Attempt to renegotiate unknown contract %s\n", str);
-                       return FRES_ERR_NOTHING_TO_RENEGOTIATE;
+       bool all_combinations_tried;
+       int criterion, best_criterion = -1;
+       struct fcb_contract *fcb_changed;
+       /* Exhaustive search. Try all combinations of spare capacity
+        * variants and find the one with best creterion. */
+       do {
+               all_combinations_tried = true;
+               fcb_changed = NULL;
+               criterion = 0;
+               /* Prepare spare capacity variant */
+               ul_list_for_each(reservation_list, rl, fc) {
+                       s = fres_contract_get_spare_capacity(fc->to_be_reserved_contract);
+                       /* TODO: Simulate continuous granularity by discretization */
+                       if (s && s->granularity == FRSH_GR_DISCRETE) {
+                               fres_container_copy(fc->to_be_reserved_contract->container,
+                                                   forb_sequence_elem(s->variants, fc->sc_variant.try));
+                               criterion += fc->sc_variant.try;
+
+                               if (fcb_changed == NULL) {
+                                       /* Chnage tried variant for the next round */
+                                       fc->sc_variant.try = fc->sc_variant.try > 0 ?
+                                               fc->sc_variant.try - 1 :
+                                               s->variants._length - 1;
+                                       /* Do not change other
+                                        * contracts unless we have
+                                        * tried all variants */
+                                       if (fc->sc_variant.try != fc->sc_variant.initial) {
+                                               fcb_changed = fc;
+                                       }
+                               }
+                               if (fc->sc_variant.try != fc->sc_variant.initial)
+                                       all_combinations_tried = false;
+                       }
                }
 
-       }       
-       return 0;
-}
+               if (criterion > best_criterion) {
+                       CORBA_Environment ev;
+                       /* Reserve contract */
+                       ret = fres_resource_manager_reserve_contracts(resource->mng, &contracts, &ev);
+                       if (forb_exception_occurred(&ev)) {
+                               ret = FRES_ERR_FORB_EXCEPTION;
+                               ul_logerr("FORB exception when reserving contracts\n");
+                               goto err;
+                       }
+                       if (ret < 0) {
+                               ul_logerr("Contract reservation error %d\n", ret);
+                               ret = FRES_ERR_ADMISSION_TEST;
+                               goto err;
+                       }
+                       if (ret == 0) { /* negotiation succeeded */
+                               best_criterion = criterion;
+                       }
+               }
+       } while (!all_combinations_tried);
 
-static int prepare_next_reservation_variant(struct fcb_contract *fc, fosa_abs_time_t now)
-{
-       fres_block_spare_capacity *s;
-       fres_contract_destroy(fc->to_be_reserved_contract);
-       fc->to_be_reserved_contract = fres_contract_duplicate(fc->user_contract);
-       if (!fc->to_be_reserved_contract)
-               return errno;
-       s = fres_contract_get_spare_capacity(fc->to_be_reserved_contract);
-       if (s) {
-               int variant;
-               variant = fosa_abs_time_smaller(fc->end_of_stability_period, now) ?
-                       fc->next_sc_variant :
-                       fc->reserved_sc_variant;
-               
-               fres_container_copy(fc->to_be_reserved_contract->container,
-                                   forb_sequence_elem(s->variants, variant));
+       if (best_criterion == -1) {
+               ret = FRSH_ERR_CONTRACT_REJECTED;
+       } else {
+               /* At least some variant succeeded */
+               ret = 0;
+               sc_contracts_init_head(resource);
+               ul_list_for_each(reservation_list, rl, fc) {
+                       s = fres_contract_get_spare_capacity(fc->to_be_reserved_contract);
+                       if (s && s->granularity == FRSH_GR_DISCRETE) {
+                               sc_contracts_insert(resource, fc);
+                       }
+               }
+       }
+err:
+       ul_list_for_each(reservation_list, rl, fc) {
+               fres_contract_destroy(fc->to_be_reserved_contract);
+               fc->to_be_reserved_contract = NULL;
        }
+       forb_sequence_free_buf(contracts, forb_no_destructor);
+       return ret;
 }
 
+/**
+ * Create/change VReses according to @a schedulable_contracts.
+ *
+ * There might be more allocators for schedulable contracts, so merge
+ * adjacent vreses with the same allocator together and create/change
+ * them in one step. Also the order of schedulable contracts might be
+ * different from the initial order od ids in commit_contracts()
+ * therefore we have to search for every contract.
+ */
 static int
-rebalance_spare_capacity_and_reserve(struct fcb *fcb, struct resource *resource,
-                                    struct fcb_contract *fcb_contract[], int num)
+change_vreses(struct fcb *fcb, fres_contract_ptr_seq *schedulable_contracts)
 {
-       unsigned i;
-       fosa_abs_time_t now;
-       fosa_clock_get_time(CLOCK_REALTIME, &now);
-       for (i=0; i<num; i++) {
-               prepare_next_reservation_variant(fcb_contract[i], now);
-       }
-#if 0
-       do {
-               /* Reserve contract */
-               ret = fres_resource_manager_reserve_contracts(resource->mng, contracts, ev);
-               if (forb_exception_occurred(ev) || ret < 0) {
-                       return ret;
+       struct res_alloc *last_ra = NULL;
+       fres_contract_ptr_seq vreses;
+       int i, ret;
+       CORBA_Environment ev;
+       
+       forb_sequence_alloc_buf(vreses, schedulable_contracts->_length);
+       vreses._length = 0;
+       
+       for (i=0; i<schedulable_contracts->_length; i++) {
+               struct fcb_contract *fc;
+               struct fres_contract *sc = schedulable_contracts->_buffer[i];
+
+               fc = fcb_contract_find(fcb, &sc->id);
+               assert(fc != NULL);
+
+               if (true /* TODO: if the schedulable contract is changed */) {
+                       if (last_ra != fc->ra) {
+                               if (vreses._length) {
+                                       ret = fres_resource_allocator_change_vreses(last_ra->ra,
+                                                                                   &vreses, &ev);
+                                       if (forb_exception_occurred(&ev)) {
+                                               ret = FRES_ERR_FORB_EXCEPTION;
+                                               goto err;
+                                       }
+                                       if (ret) goto err;
+                               }
+                               vreses._length = 0;
+                       }
+                       vreses._buffer[vreses._length] = sc;
+                       vreses._length++;
+                       fres_contract_destroy(fc->schedulable_contract);
+                       fc->schedulable_contract = fres_contract_duplicate(sc);
+                       last_ra = fc->ra;
+               
                }
-       } while (ret != 0)
-#endif
-       return 0;
+       }
+       ret = fres_resource_allocator_change_vreses(last_ra->ra,
+                                                   &vreses, &ev);
+       if (forb_exception_occurred(&ev))
+               ret = FRES_ERR_FORB_EXCEPTION;
+err:
+       forb_sequence_free_buf(vreses, forb_no_destructor);
+       return ret;
 }
 
 CORBA_long
@@ -389,56 +583,23 @@ negotiate_contracts(fres_contract_broker obj,
 {
        struct fcb *fcb = o2fcb(obj);
        struct resource *resource;
-       struct res_alloc *ra;
        int ret;
        forb_server_id app;
        fres_contract_ptr_seq *schedulable_contracts;
-       struct fcb_contract **fcb_contracts;
+       struct fcb_contract **fcb_contracts, *fc;
        unsigned i;
-       fres_contract_id_seq* ids;
-
-       resource = check_single_resource(fcb, contracts->_buffer, contracts->_length);
-       if (!resource) {
-               ret = FRSH_ERR_RESOURCE_ID_INVALID;
-               goto err;
-       }
-
-       ret = prepare_reservation_contracts(fcb, contracts->_buffer, contracts->_length);
-       if (ret)
-               goto err;
-
-       forb_get_req_source(obj, &app);
-       ra = fcb_alloc_find(resource, &app);
-       if (!ra) {
-               char str[60];
-               forb_server_id_to_string(str, &app, sizeof(str));
-               ul_logerr("No resource allocator found for %d.%d and %s\n",
-                         resource->key.type, resource->key.id, str);
-               ret = FRES_ERR_NO_RESOURCE_ALLOCATOR;
-               goto err;
-       }
+       fres_contract_id_seq commit_ids;
 
-       /* Allocate all the needed memory before doing reservation. If
-        * there is no enough memory, it has no sense to call resource
-        * manager. */
-       /* TODO: Use FORB macros to allocate sequence */
-       ids = malloc(sizeof(*ids));
-       if (!ids) {
+       /* Prepare output sequence for the case we return eariler with
+        * an error */
+       forb_sequence_alloc(*ids_out, 0);
+       if (!*ids_out) {
                ev->major = FORB_EX_NO_MEMORY;
                goto err;
        }
-       memset(ids, 0, sizeof(*ids));
-       CORBA_sequence_set_release(ids, CORBA_TRUE);
-       *ids_out = ids;
-       ids->_buffer = malloc(contracts->_length*sizeof(ids->_buffer[0]));
-       if (!ids->_buffer) {
-               ret = errno;
-               goto err;
-       }
-       ids->_length = ids->_maximum = contracts->_length;
-       for (i=0; i<contracts->_length; i++) {
-               ids->_buffer[i] = contracts->_buffer[i]->id;
-       }
+       CORBA_sequence_set_release(*ids_out, CORBA_TRUE);
+       
+       forb_get_req_source(obj, &app);
        
        fcb_contracts = malloc(sizeof(fcb_contracts[0])*contracts->_length);
        if (!fcb_contracts) {
@@ -447,94 +608,155 @@ negotiate_contracts(fres_contract_broker obj,
        }
        memset(fcb_contracts, 0, sizeof(fcb_contracts[0])*contracts->_length);
 
-       for (i=0; i<contracts->_length; i++) {
-               /* Allocate FCB contracts */
-               struct fres_contract *c = contracts->_buffer[i];
-               if (fres_contract_get_num_blocks(c) > 0) {
-                       fcb_contracts[i] = fcb_contract_new(&c->id);
-                       if (!fcb_contracts[i]) {
-                               ret = errno ? errno : -1;
-                               goto err_free_fcb_contracts;
-                       }
-                       fcb_contracts[i]->user_contract = fres_contract_duplicate(c);
-                       if (!fcb_contracts[i]->user_contract) {
-                               ret = errno ? errno : -1;
-                               goto err_free_fcb_contracts;
-                       }
-               }
-       }
+       ret = prepare_fcb_contracts(fcb, fcb_contracts, &resource,
+                                   &app, contracts->_buffer, contracts->_length);
+       if (ret)
+               goto err_free_fcb_contracts;
+
+       struct reservation_list rl;
+       prepare_reservation_list(resource,
+                                fcb_contracts, contracts->_length,
+                                &rl);
 
-       /* TODO: Optimize the following by introducing
-        * reserve_and_commit FRM method. */
-#if 1  
-       /* Reserve contract */
-       ret = fres_resource_manager_reserve_contracts(resource->mng, contracts, ev);
-       if (forb_exception_occurred(ev) || ret < 0) {
+       /* Allocate all the needed memory before doing reservation. If
+        * there is no enough memory, it has no sense to call resource
+        * manager. */
+       forb_sequence_alloc_buf(commit_ids, rl.length);
+       if (!commit_ids._buffer) {
+               ret = errno;
                goto err_free_fcb_contracts;
        }
-#else
-       ret = rebalance_spare_capacity_and_reserve(fcb, resource, contracts->_buffer,
-                                                  fcb_contracts, contracts->_length);
-#endif
-       if (ret == 1) {
-               ul_logmsg("Contract(s) was not accepted\n");
+
+       /* Reserve contracts */
+       ret = rebalance_spare_capacity_and_reserve(resource, &rl);
+       if (ret) {
+               if (ret == FRSH_ERR_CONTRACT_REJECTED) {
+                       ul_logmsg("Contract(s) was/were rejected\n");
+               } else {
+                       char msg[100];
+                       fres_strerror(ret, msg, sizeof(msg));
+                       ul_logerr("Reservation error: %s\n", msg);
+               }
                goto err_free_fcb_contracts;
        }
 
-       /* Commit contract */
-       fres_resource_manager_commit_contracts(resource->mng, ids,
+       /* Commit contracts */
+       commit_ids._length = rl.length;
+       i=0;
+       ul_list_for_each(reservation_list, &rl, fc) {
+               forb_sequence_elem(commit_ids, i) = fc->id;
+               i++;
+       }
+       
+       fres_resource_manager_commit_contracts(resource->mng, &commit_ids,
                                               &schedulable_contracts, ev);
        if (forb_exception_occurred(ev)) {
                ret = FRES_ERR_FORB_EXCEPTION;
                goto err_cancel_reservation;
        }
 
-       /* Create VRes */
-       ret = fres_resource_allocator_change_vreses(ra->ra, schedulable_contracts, ev);
-       if (CORBA_sequence_get_release(schedulable_contracts)) {
-               int i;
-               for (i=0; i<schedulable_contracts->_length; i++) {
-                       fres_contract_destroy(schedulable_contracts->_buffer[i]);
+       /* Add new contracts to our fcb database for later
+        * reference. Canceled contracts are removed below. */
+       for (i=0; i<contracts->_length; i++) {
+               fc =  fcb_contracts[i];
+
+               if (fc->user_contract) {
+                       if (fres_contract_get_num_blocks(fc->requested_contract) > 0) {
+                               /* Renegotiation */
+                               fres_contract_destroy(fc->user_contract);
+                               fc->user_contract = fres_contract_duplicate(fc->requested_contract);
+                               /* Note: requested_contract is also
+                                * pointed by contracts parameter and
+                                * will be freed by FORB. */
+                               fc->requested_contract = NULL;
+                       }
+               } else {
+                       /* Insert new contracts */
+                       fcb_contract_insert(fcb, fcb_contracts[i]);
+                       fc->user_contract = fres_contract_duplicate(fc->requested_contract);
+                       fc->requested_contract = NULL;
+                       /* See the note above. */
                }
-               forb_free(schedulable_contracts->_buffer);
        }
-       forb_free(schedulable_contracts);
-       if (forb_exception_occurred(ev)) {
-               ret = FRES_ERR_FORB_EXCEPTION;
+
+       ret = change_vreses(fcb, schedulable_contracts);
+       if (ret)
                goto err_cancel_reservation;
-       }
+       
+       forb_sequence_free(schedulable_contracts, fres_contract_ptr_destroy);
        if (ret != 0) {
-               ul_logmsg("VRes was not created\n");
-               goto err_cancel_reservation;
+               ul_logerr("VRes was not created\n");
+               goto err_cancel_contracts;
        }
 
-       /* Update database of negotiated contracts stored for later reference */
+
+       /* Return IDs and delete canceled contracts from out database */
+       forb_sequence_alloc_buf(**ids_out, contracts->_length);
+       if (!(*ids_out)->_buffer) {
+               ev->major = FORB_EX_NO_MEMORY;
+               goto err_cancel_contracts;
+       }
+       (*ids_out)->_length = contracts->_length;
        for (i=0; i<contracts->_length; i++) {
-               struct fcb_contract *fcb_contract;
-               fcb_contract = fcb_contract_find(fcb, &contracts->_buffer[i]->id);
-               /* Delete canceled or renegotiated user contract */
-               if (fcb_contract) {
-                       fcb_contract_delete(fcb, fcb_contract);
-                       fcb_contract_destroy(fcb_contract);
-               }
-               if (fcb_contracts[i]) {
-                       /* Insert new contracts */
-                       fcb_contract_insert(fcb, fcb_contracts[i]);
+               struct fcb_contract *fc =  fcb_contracts[i];
+               forb_sequence_elem(**ids_out, i) = fc->id;
+
+               if (fc->requested_contract &&
+                   fres_contract_get_num_blocks(fc->requested_contract) == 0) {
+                       fcb_contract_delete(fcb, fc);
+                       /* Note: requested_contract is also pointed by
+                        * contracts parameter and will be freed by FORB. */
+                       fc->requested_contract = NULL;
+                       fcb_contract_destroy(fc);
                }
        }
-
        return 0;
 
+err_cancel_contracts:
+       /* TODO */
+       goto err_free_fcb_contracts;
 err_cancel_reservation:
-       fres_resource_manager_cancel_reservations(resource->mng, ids, ev);
+       fres_resource_manager_cancel_reservations(resource->mng, &commit_ids, ev);
 err_free_fcb_contracts:
-       for (i=0; i<contracts->_length; i++) 
-               fcb_contract_destroy(fcb_contracts[i]);
+       for (i=0; i<contracts->_length; i++) {
+               fc = fcb_contracts[i];
+               if (fc && !fc->user_contract) {
+                       fcb_contracts[i]->requested_contract = NULL; /* Destroyed by FORB */
+                       fcb_contract_destroy(fcb_contracts[i]);
+               }
+       }
        free(fcb_contracts);
 err:
        return ret;
 }
 
+void redistribute_spare_capacity(fres_contract_broker obj,
+                                const frsh_resource_type_t restype,
+                                const frsh_resource_id_t resid,
+                                CORBA_Environment *ev)
+{
+       struct fcb *fcb = o2fcb(obj);
+       struct res_key key = {restype, resid };
+       struct resource *resource;
+       struct reservation_list rl;
+       
+       resource = fcb_resource_find(fcb, &key);
+
+       prepare_reservation_list(resource, NULL, 0, &rl);
+
+/*     forb_sequence_alloc(ids, rl.length); */
+/*     if (!ids || !ids->_buffer) { */
+/*             ev->major = FORB_EX_NO_MEMORY; */
+/*             goto err_free_fcb_contracts; */
+/*     } */
+/*     CORBA_sequence_set_release(ids, CORBA_TRUE); */
+/*     *ids_out = ids;         /\* ids is freed by FORB *\/ */
+       
+       
+       rebalance_spare_capacity_and_reserve(resource, &rl);
+       /* Commit */
+}
+
 CORBA_long register_resource(fres_contract_broker obj,
                            const frsh_resource_type_t restype,
                            const frsh_resource_id_t resid,
@@ -624,7 +846,7 @@ CORBA_long register_allocator(fres_contract_broker obj,
        fcb_alloc_insert(res, ra);
        return 0;
 err:
-       return -1;      
+       return FRSH_ERR_RESOURCE_ID_INVALID;
 }
 
 void get_resources(fres_contract_broker obj, fres_resource_seq** resources, CORBA_Environment *ev)
@@ -684,6 +906,7 @@ struct forb_fres_contract_broker_impl impl = {
        .negotiate_contracts = negotiate_contracts,
        .register_resource = register_resource,
        .register_allocator = register_allocator,
+       .redistribute_spare_capacity = redistribute_spare_capacity,
        .get_resources = get_resources,
 };
 
index b4d2fc28a84b5d2f219d173c542e2bbbc67f57ba..9176589a0e103895bf3e87842796da5567a62a5e 100644 (file)
@@ -121,8 +121,8 @@ module fres {
                 * contract is determined as follows:
                 * - neg: contracts without ID
                 * - cancel: contracts with an ID and without any block
-                * - reneg: contracts without   ID and some blocks (these
-                *   blocks will be replaced in the previous contract).
+                * - reneg: contracts with ID and some blocks (the old
+                 *   contract will we replaced by the new one).
                 * 
                 * @param[out] ids IDs of the newly negotiated
                 * contracts, if negotiation was successful. Ordering
@@ -134,6 +134,18 @@ module fres {
                 */
                long negotiate_contracts(in contract::ptr_seq contracts, out contract::id_seq ids);
 
+               /** 
+                * Redistributes spare capacity for a given resource.
+                * This is meant as a support for resources with
+                * variable capacity (WiFi) as a mean for applications
+                * to adapt to the changed capacity.
+                * 
+                * @param restype For which resource to perform
+                * redistribution.
+                */
+               void redistribute_spare_capacity(in frsh_resource_type_t restype,
+                                                in frsh_resource_id_t   resid);
+
                /** 
                 * Returns sequence of registered resources.
                 * 
index bd0a1b8f16f2f9dea71a7ac22e9185849a19fb8e..2bba1a5f85ddf0f3b750f6a15f6857e637052390 100644 (file)
@@ -99,6 +99,8 @@ int fres_strerror (int error, char *message, size_t size)
                MSG(NOTHING_TO_RENEGOTIATE);
                MSG(BLOCK_DUP);
                MSG(NO_RESOURCE_ALLOCATOR);
+               MSG(ADMISSION_TEST);
+               MSG(KERNEL_SUPPORT_MISSING);
        }
 
        if (s == NULL) return FRSH_ERR_BAD_ARGUMENT;
index 06a41a8a37d0d0353c5e12c925a088a3063b5775..2953d75912ff670bee11a413c4c5643323673e0b 100644 (file)
@@ -66,6 +66,8 @@ enum fres_error {
        FRES_ERR_NOTHING_TO_RENEGOTIATE,
        FRES_ERR_BLOCK_DUP,
        FRES_ERR_NO_RESOURCE_ALLOCATOR,
+       FRES_ERR_ADMISSION_TEST,
+       FRES_ERR_KERNEL_SUPPORT_MISSING,
 };
 
 int fres_strerror (int error, char *message, size_t size);
index a27de8407993a1ddd74bf2d8f4a6ff84d816a6f4..bddac54222dd96d67d6a9d82b46fb55517add597 100644 (file)
@@ -177,7 +177,7 @@ int fra_register(struct fres_allocator *allocator)
  * 
  * @param allocator 
  * 
- * @return Zero on success, -1 on error.
+ * @return Zero on success, non-zero error code on error.
  */
 static int register_fra_to_fcb(struct fres_allocator *allocator)
 {
@@ -196,13 +196,16 @@ static int register_fra_to_fcb(struct fres_allocator *allocator)
                                                      allocator->res_type,
                                                      allocator->res_id,
                                                      fra, &env);
-       if (forb_exception_occurred(&env) || ret != 0) {
+       if (forb_exception_occurred(&env)) {
+               ret = FRES_ERR_FORB_EXCEPTION;
                goto err_release;
        }
+       if (ret)
+               goto err_release;
        return 0;
 err_release:
        save_errno(forb_object_release(fra));
-       return -1;
+       return ret;
 }
 
 /** 
@@ -214,7 +217,7 @@ err_release:
  * @param res_type 
  * @param res_id
  * 
- * @return Zero on success, -1 on error.
+ * @return Zero on success, non-zero error code on error.
  */
 
 int fra_activate(frsh_resource_type_t res_type,
@@ -222,7 +225,7 @@ int fra_activate(frsh_resource_type_t res_type,
 {
        struct fres_allocator key, *pkey=&key;
        struct registered_allocator *ra;
-       int ret = -1;
+       int ret;
        
        key.res_type = res_type;
        key.res_id = res_id;
@@ -236,6 +239,8 @@ int fra_activate(frsh_resource_type_t res_type,
                                ra->registered_with_fcb = true;
                        }
                }
+       } else {
+               ret = FRSH_ERR_RESOURCE_ID_INVALID;
        }
 
        return ret;
index b726217175005547ad6740c85c6524d787bd7e86..82aae31d820b564e46c1f479dee9744a62088b65 100644 (file)
@@ -337,7 +337,7 @@ int __contract_check_min_expiration(const frsh_contract_t *contract)
                ret = frsh_battery_get_expiration(&exp_time);
                if (ret) goto err;
 
-               if (fosa_abs_time_smaller(req_time, exp_time))
+               if (fosa_abs_time_smaller(exp_time, req_time))
                        ret = FRSH_ERR_CONTRACT_REJECTED;
        }
 
@@ -374,8 +374,9 @@ int frsh_contract_negotiate
        /* Activate allocator */
        r = fres_contract_get_resource(*contract);
        if (r) {
-               fra_activate(r->resource_type,
-                            r->resource_id);
+               ret = fra_activate(r->resource_type,
+                                  r->resource_id);
+               if (ret) goto err;
        }
 
        /* Negotiate contract */
index 6c0072c8f2135efbb10bfa6ece8468bca4c31e25..026e11847455e52f05a5336c15416d7e97cbf551 100644 (file)
@@ -116,7 +116,7 @@ static char * frsh_strerror_table[] =
     "SCHED_POLICY_NOT_COMPATIBLE    ",
     "SERVER_WORKLOAD_NOT_COMPATIBLE ",
     "ALREADY_BOUND                  ",
-    "WRONG_NETWORK                  ",
+    "RESOURCE_ID_INVALID           ",
     "TOO_LARGE                      ",
     "BUFFER_FULL                    ",
     "NO_SPACE                       ",
index d704f36fcee9884e3af2c653cb0727d03567d010..bd81878f0728c0b1ded1711f0b8b830d75e3b196 100644 (file)
@@ -239,6 +239,7 @@ int frsh_resource_set_power_level
                case FRSH_RT_PROCESSOR:
                {
                        int ret;
+
                        ret = fra_CPU_power_init(resource_id);
                        if (ret) return FRSH_ERR_INTERNAL_ERROR;
                        ret = fra_CPU_set_power(resource_id, power_level);
@@ -256,6 +257,7 @@ int frsh_resource_set_power_level
                case FRSH_RT_LCD:
                {
                        int ret;
+
                        ret = fra_LCD_power_init(resource_id);
                        if (ret) return FRSH_ERR_INTERNAL_ERROR;
                        ret = fra_LCD_set_power(resource_id, power_level);
@@ -281,6 +283,9 @@ int frsh_resource_get_power_level
                case FRSH_RT_PROCESSOR:
                {
                        int ret;
+
+                       ret = fra_CPU_power_init(resource_id);
+                       if (ret) return FRSH_ERR_INTERNAL_ERROR;
                        ret = fra_CPU_get_power(resource_id,
                                                (int*) power_level);
                        if (ret) return FRSH_ERR_INTERNAL_ERROR;
@@ -292,6 +297,9 @@ int frsh_resource_get_power_level
                case FRSH_RT_LCD:
                {
                        int ret;
+
+                       ret = fra_LCD_power_init(resource_id);
+                       if (ret) return FRSH_ERR_INTERNAL_ERROR;
                        ret = fra_LCD_get_power(resource_id,
                                                (int*) power_level);
                        if (ret) return FRSH_ERR_INTERNAL_ERROR;
@@ -306,6 +314,51 @@ int frsh_resource_get_power_level
        return FRSH_NO_ERROR;
 }
 
+int frsh_resource_get_speed
+  (frsh_resource_type_t resource_type,
+   frsh_resource_id_t resource_id,
+   frsh_power_level_t power_level,
+   double *speed_ratio)
+{
+       switch(resource_type)
+       {
+#ifdef CONFIG_ACPI_CPU
+               case FRSH_RT_PROCESSOR:
+               {
+                       int ret;
+
+                       ret = fra_CPU_power_init(resource_id);
+                       if (ret) return FRSH_ERR_INTERNAL_ERROR;
+                       ret = fra_CPU_get_speed(resource_id,
+                                               (int) power_level,
+                                               speed_ratio);
+                       if (ret) return FRSH_ERR_INTERNAL_ERROR;
+
+                       break;
+               }
+#endif
+#ifdef CONFIG_ACPI_LCD
+               case FRSH_RT_LCD:
+               {
+                       int ret;
+
+                       ret = fra_LCD_power_init(resource_id);
+                       if (ret) return FRSH_ERR_INTERNAL_ERROR;
+                       ret = fra_LCD_get_speed(resource_id,
+                                               (int) power_level,
+                                               speed_ratio);
+                       if (ret) return FRSH_ERR_INTERNAL_ERROR;
+
+                       break;
+               }
+#endif
+               default:
+                       return FRSH_ERR_NOT_IMPLEMENTED;
+       }
+
+       return FRSH_NO_ERROR;
+}
+
 int frsh_resource_get_num_power_levels
   (frsh_resource_type_t resource_type,
    frsh_resource_id_t resource_id,
@@ -317,14 +370,14 @@ int frsh_resource_get_num_power_levels
 
        switch(resource_type)
        {
+#ifdef CONFIG_ACPI_CPU
                case FRSH_RT_PROCESSOR:
                {
-#ifdef CONFIG_ACPI_CPU
                        ret = fra_CPU_power_init(resource_id);
                        if (ret) goto out;
-#endif
                        break;
                }
+#endif
 #ifdef CONFIG_ACPI_LCD
                case FRSH_RT_LCD:
                {
@@ -359,17 +412,12 @@ int frsh_battery_get_expiration(frsh_abs_time_t *expiration)
        if (ret) return FRSH_ERR_INTERNAL_ERROR;
 
        ret = fra_battery_expiration(&interval);
-       if (ret == EAGAIN) {
-               *expiration = fosa_msec_to_abs_time(0);
-               goto out;
-       }
-       if (ret)
-               return FRSH_ERR_INTERNAL_ERROR;
+       if (ret == EAGAIN) return ret;
+       if (ret) return FRSH_ERR_INTERNAL_ERROR;
 
        fosa_clock_get_time(FOSA_CLOCK_REALTIME, expiration);
        *expiration = fosa_abs_time_incr(*expiration, interval);
 
-out:
        return FRSH_NO_ERROR;
 #else
        return FRSH_ERR_NOT_IMPLEMENTED;        
index ddfe20437bdee4c402571cf31482db6e66d4856d..b58b1e89ef8fcaa7faeef3d1ffcd910a409b4826 100644 (file)
@@ -28,9 +28,9 @@ int main(int argc, char *argv[])
                { /* Contract 2 */
                        .stability_time = MSEC(1000), .importance = 0, .weight = 1,
                        .variants = {
-                               { .budget = MSEC(30),  .period = MSEC(100),  .deadline = MSEC(100) },
-                               { .budget = MSEC(30),  .period = MSEC( 80),  .deadline = MSEC( 80) },
-                               { .budget = MSEC(30),  .period = MSEC( 60),  .deadline = MSEC( 60) },
+                               { .budget = MSEC(40),  .period = MSEC(100),  .deadline = MSEC(100) },
+                               { .budget = MSEC(40),  .period = MSEC( 80),  .deadline = MSEC( 80) },
+                               { .budget = MSEC(40),  .period = MSEC( 60),  .deadline = MSEC( 60) },
                        }
                },
                { /* Contract 3 */
@@ -95,6 +95,12 @@ int main(int argc, char *argv[])
                if (ret) PERROR_AND_EXIT(ret, "frsh_contract_negotiate");
        }
 
+       printf("Waiting for stability period to end\n");
+       sleep(2);
+       printf("Trying to renegotiate the 3rd contract again\n");
+       ret = frsh_contract_renegotiate_sync(&contract[2], vres[2]);
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_negotiate");
+
        /* Cancel contracts */
        for (i=0; i<NUM_CONTRACTS; i++) {
                ret = frsh_contract_cancel(vres[i]);
index 09c84dffa9b6b73376345d454e2ddb76645523db..fe18b6df1b2c7689ad17fdf2945d1626e56b11aa 100644 (file)
@@ -1,90 +1,84 @@
 #include <frsh.h>
-#include <aqcpu_res.h>
-#include <error.h>
 
 int main()
 {
-       int ret;
+       int terror;
        frsh_vres_id_t vres;
        frsh_contract_t contract;
        frsh_rel_time_t budget, period;
-       frsh_rel_time_t duration, expiration;
-       unsigned long long duration_msec = 10000;
+       frsh_rel_time_t current, duration, expiration;
+       unsigned long duration_msec, duration_step;
 
-       if (frsh_init())
-               error(1, 0, "FRSH initialization failed\n");
+       PXW(frsh_init());
+       
+       PXW(frsh_contract_init(&contract));
+
+       duration_msec = duration_step = 1000UL * 60UL * 10UL;
        
-       /* Contract negotiation for CPU */
-       ret = frsh_contract_init(&contract);
-       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_init");
-               
        budget = fosa_msec_to_rel_time(10);
        period = fosa_msec_to_rel_time(100);
-       ret = frsh_contract_set_basic_params(&contract,
-                                            &budget,
-                                            &period,
-                                            FRSH_WT_BOUNDED,
-                                            FRSH_CT_REGULAR);
-       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_basic_params");
+       PXW(frsh_contract_set_basic_params(&contract,
+                                          &budget,
+                                          &period,
+                                          FRSH_WT_BOUNDED,
+                                          FRSH_CT_REGULAR));
+
+       PXW(frsh_contract_set_resource_and_label(&contract, FRSH_RT_PROCESSOR, 0,"TEST_VRES"));
+
+       PXW(frsh_contract_set_min_budget_pow(&contract, FRSH_PLT_HIGH, &budget));
 
-       ret = frsh_contract_set_resource_and_label(&contract, FRSH_RT_PROCESSOR,
-                                                       0,"TEST_VRES");
-       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_resource_and_label");
+       PXW(frsh_contract_set_min_budget_pow(&contract, FRSH_PLT_MEDIUM, &budget));
 
-       ret = frsh_contract_set_min_budget_pow(&contract, FRSH_PLT_HIGH, &budget);
-       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_min_budget_pow (FRSH_PLT_HIGH)");
+       PXW(frsh_contract_set_min_budget_pow(&contract, FRSH_PLT_LOW, &budget));
 
-       ret = frsh_contract_set_min_budget_pow(&contract, FRSH_PLT_MEDIUM, &budget);
-       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_min_budget_pow (FRSH_PLT_MEDIUM)");
+       terror = frsh_battery_get_expiration(&expiration);
+       if (terror == EAGAIN)
+               PERROR_AND_EXIT(terror, "frsh_battery_get_expiration: system running on AC");
+       if (terror)
+               PERROR_AND_EXIT(terror, "frsh_battery_get_expiration");
 
-       ret = frsh_contract_set_min_budget_pow(&contract, FRSH_PLT_LOW, &budget);
-       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_min_budget_pow (FRSH_PLT_LOW)");
+       fosa_clock_get_time(FOSA_CLOCK_REALTIME, &current);
+       printf("System battery wil expire in %lu seconds\n",
+              fosa_rel_time_to_msec(fosa_abs_time_decr(expiration, current)) / 1000UL);
+
+       printf("Starting with minumum diration = %lu seconds\n"
+              " ans stepping by %lu seconds.\n",
+              duration_msec / 1000UL,
+              duration_step / 1000UL);
 
        duration = fosa_msec_to_rel_time(duration_msec);
-       ret = frsh_contract_set_min_expiration(&contract, duration);
-       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_min_expiration");
+       PXW(frsh_contract_set_min_expiration(&contract, duration));
 
-       ret = frsh_contract_get_min_expiration(&contract, &duration);
-       if (ret || fosa_rel_time_to_msec(duration) != duration_msec)
-               PERROR_AND_EXIT(ret, "frsh_contract_get_min_expiration");
-       printf("Minimum duration correctly set to: %lu\n", fosa_rel_time_to_msec(duration));
+       PXW(frsh_contract_get_min_expiration(&contract, &duration));
 
-       ret = frsh_contract_negotiate(&contract, &vres);
-       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_negotiate");
+       PXW(frsh_contract_negotiate(&contract, &vres));
        printf("Aqcpu vres negotiated, vres-ID: %d\n", (int) vres);
 
        while (1) {
-               duration_msec += duration_msec;
+               duration_msec += duration_step;
                duration = fosa_msec_to_rel_time(duration_msec);
 
-               ret = frsh_contract_set_min_expiration(&contract, duration);
-               if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_min_expiration");
-
-               ret = frsh_contract_get_min_expiration(&contract, &duration);
-               if (ret || fosa_rel_time_to_msec(duration) != duration_msec) {
-                       //PERROR_AND_EXIT(ret, "frsh_contract_get_duration");
-                       printf("%lu %lu\n", fosa_rel_time_to_msec(duration), duration_msec);
-                       break;
-               }
-               printf("Minimum duration correctly set to: %lu\n",
-                      fosa_rel_time_to_msec(duration));
+               fosa_clock_get_time(FOSA_CLOCK_REALTIME, &current);
+               printf(" Renegotiating the contract with minimum expiration %lu sec.\n"
+                      " System expiration time: %lu seconds\n",
+                      fosa_rel_time_to_msec(duration) / 1000UL,
+                      fosa_rel_time_to_msec(fosa_abs_time_decr(expiration, current)) / 1000UL);
 
-               ret = frsh_battery_get_expiration(&expiration);
-               if (ret) PERROR_AND_EXIT(ret, "frsh_battery_get_expiration");
+               PXW(frsh_contract_set_min_expiration(&contract, duration));
 
-               ret = frsh_contract_renegotiate_sync(&contract, vres);
-               if (ret) PERROR_AND_EXIT(ret, "frsh_contract_renegotiate_sync");
-
-               printf("Contract with minimum expiration %lu renegotiated."
-                      "System expiration time: %lu\n",
-                      fosa_rel_time_to_msec(duration),
-                      fosa_abs_time_to_msec(expiration));
+               PXW(frsh_battery_get_expiration(&expiration));
+               terror = frsh_contract_renegotiate_sync(&contract, vres);
+               if (terror == FRSH_ERR_CONTRACT_REJECTED) {
+                       PERROR_FRESCOR(terror, "frsh_contract_renegotiate_sync");
+                       goto out;
+               }
+               if (terror) PERROR_AND_EXIT(terror, "frsh_contract_renegotiate_sync");
 
                sleep(3);
        }
 
-       ret = frsh_contract_cancel(vres);
-       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_cancel");
+out:
+       PXW(frsh_contract_cancel(vres));
 
        printf("Test PASSED!\n");
                
index b7bc9bbe328d0590e262df6327075288108768ce..1ccefcbec9cb6a024d8c888b9e85c508eace804b 100644 (file)
@@ -81,10 +81,19 @@ int fra_CPU_get_power(int cpu, int *level)
 
 int fra_CPU_set_power(int cpu, int level)
 {
-       if (!frequency_initialized ||
-           level >= 3)
+       if (!frequency_initialized || level >= 3)
                return EINVAL;
 
        return cpufreq_set_frequency(cpu, freqs[level]);
 }
 
+int fra_CPU_get_speed(int cpu, int level, double *ratio)
+{
+       if (!frequency_initialized || level >= 3)
+               return EINVAL;
+
+       *ratio = (double) freqs[level] / freqs[0];
+
+       return 0;
+}
+
index 4264455ee791dd7fa6712b5d565b315c0e12b184..1d5d51db79951efae09f106ab210041a171c347f 100644 (file)
@@ -13,5 +13,7 @@ int fra_CPU_get_power(int cpu, int *level);
 
 int fra_CPU_set_power(int cpu, int level);
 
+int fra_CPU_get_speed(int cpu, int level, double *ratio);
+
 #endif
 
index 2dd9f4506f63849e9fb3b7f64deaa87aa46542bf..2f77b06cc1359e5f2bc7a29973cfad8c75620022 100644 (file)
@@ -1,42 +1,42 @@
 #include <frsh.h>
-#include <error.h>
 
 int main()
 {
+       frsh_power_level_t level;
        int power_levels;
-       int ret;
+       double speed;
+       int terror;
 
-       if (frsh_init())
-               error(1, 0, "FRSH initialization failed\n");
+       PXW(frsh_init());
 
-       ret = frsh_resource_get_num_power_levels(FRSH_RT_PROCESSOR,
-                                                0, &power_levels);
-       if (ret) PERROR_AND_EXIT(ret, "frsh_resource_get_num_power_levels");
+       PXW(frsh_resource_get_num_power_levels(FRSH_RT_PROCESSOR, 0, &power_levels));
        printf("Number of power levels suppoerted: %d\n", power_levels);
 
        if (power_levels == 1)
                PERROR_AND_EXIT(EINVAL, "Different power levels not supported");
-
-       printf("Starting...\n");
+       
+       PXW(frsh_resource_get_power_level(FRSH_RT_PROCESSOR, 0, &level));
+       PXW(frsh_resource_get_speed(FRSH_RT_PROCESSOR, 0, level, &speed));
+       printf("Starting with power level %d, speed = %f\n", level, speed);
 
        sleep(3);
-       ret = frsh_resource_set_power_level(FRSH_RT_PROCESSOR,
-                                           0, FRSH_PLT_HIGH);
-       if (ret) PERROR_AND_EXIT(ret, "frsh_resource_set_power_level");
-       printf("FRSH_PLT_MEDIUM correctly set\n");
+       PXW(frsh_resource_set_power_level(FRSH_RT_PROCESSOR, 0, FRSH_PLT_HIGH));
+       PXW(frsh_resource_get_power_level(FRSH_RT_PROCESSOR, 0, &level));
+       PXW(frsh_resource_get_speed(FRSH_RT_PROCESSOR, 0, level, &speed));
+       printf("%d (FRSH_PLT_HIGH) correctly set, speed = %f\n", level, speed);
 
        sleep(3);
-       ret = frsh_resource_set_power_level(FRSH_RT_PROCESSOR,
-                                           0, FRSH_PLT_MEDIUM);
-       if (ret) PERROR_AND_EXIT(ret, "frsh_resource_set_power_level");
-       printf("FRSH_PLT_MEDIUM correctly set\n");
+       PXW(frsh_resource_set_power_level(FRSH_RT_PROCESSOR, 0, FRSH_PLT_MEDIUM));
+       PXW(frsh_resource_get_power_level(FRSH_RT_PROCESSOR, 0, &level));
+       PXW(frsh_resource_get_speed(FRSH_RT_PROCESSOR, 0, level, &speed));
+       printf("%d (FRSH_PLT_MEDIUM) correctly set, speed = %f\n", level, speed);
 
        sleep(3);
-       ret = frsh_resource_set_power_level(FRSH_RT_PROCESSOR,
-                                           0, FRSH_PLT_LOW);
-       if (ret) PERROR_AND_EXIT(ret, "frsh_resource_set_power_level");
-       printf("FRSH_PLT_LOW correctly set\n");
+       PXW(frsh_resource_set_power_level(FRSH_RT_PROCESSOR, 0, FRSH_PLT_LOW));
+       PXW(frsh_resource_get_power_level(FRSH_RT_PROCESSOR, 0, &level));
+       PXW(frsh_resource_get_speed(FRSH_RT_PROCESSOR, 0, level, &speed));
+       printf("%d (FRSH_PLT_LOW) correctly set, speed = %f\n", level, speed);
 
-       return 0;       
+       return 0;
 }
 
index 827b9e22b5b89ad383af68ff7b34b3c5bc3a0f78..8c8227f4ce2da41fe343e582a6618ac5b933fec8 100644 (file)
@@ -118,7 +118,7 @@ static int __set_lcd_brightness(int level)
        int ret = 0;
        char str[128];
 
-       if (lcd_initialized == NONE)
+       if (lcd_initialized == NONE || level >= 3)
                return EINVAL;
 
        if (lcd_initialized == PROC_1) {
@@ -173,3 +173,13 @@ int fra_LCD_set_power(int lcd, int level)
        return __set_lcd_brightness(level);
 }
 
+int fra_LCD_get_speed(int lcd, int level, double *ratio)
+{
+       if (lcd_initialized == NONE || level >= 3)
+                       return EINVAL;
+
+       *ratio = bright[level]/bright[0];
+
+       return 0;
+}
+
index bbe79e4f57500ed9e5547ca914efcfbd1583099b..cb89f87b6271dfa439764226ea383cb0ea5597da 100644 (file)
@@ -29,5 +29,7 @@ int fra_LCD_get_power(int lcd, int *level);
 
 int fra_LCD_set_power(int lcd, int level);
 
+int fra_LCD_get_speed(int lcd, int level, double *ratio);
+
 #endif
 
index add72a28ffe5ad4927c09920187e8f725e093246..7b6942e9ee55c12415d1684587be6edcede9e93d 100644 (file)
@@ -1,42 +1,42 @@
 #include <frsh.h>
-#include <error.h>
 
 int main()
 {
+       frsh_power_level_t level;
        int power_levels;
-       int ret;
+       double speed;
+       int terror;
 
-       if (frsh_init())
-               error(1, 0, "FRSH initialization failed\n");
+       PXW(frsh_init());
 
-       ret = frsh_resource_get_num_power_levels(FRSH_RT_LCD,
-                                                0, &power_levels);
-       if (ret) PERROR_AND_EXIT(ret, "frsh_resource_get_num_power_levels");
+       PXW(frsh_resource_get_num_power_levels(FRSH_RT_LCD, 0, &power_levels));
        printf("Number of power levels suppoerted: %d\n", power_levels);
 
        if (power_levels == 1)
                PERROR_AND_EXIT(EINVAL, "Different power levels not supported");
-
-       printf("Starting...\n");
-
-       sleep(5);
-       ret = frsh_resource_set_power_level(FRSH_RT_LCD,
-                                           0, FRSH_PLT_HIGH);
-       if (ret) PERROR_AND_EXIT(ret, "frsh_resource_set_power_level");
-       printf("FRSH_PLT_MEDIUM correctly set\n");
-
-       sleep(5);
-       ret = frsh_resource_set_power_level(FRSH_RT_LCD,
-                                           0, FRSH_PLT_MEDIUM);
-       if (ret) PERROR_AND_EXIT(ret, "frsh_resource_set_power_level");
-       printf("FRSH_PLT_MEDIUM correctly set\n");
-
-       sleep(5);
-       ret = frsh_resource_set_power_level(FRSH_RT_LCD,
-                                           0, FRSH_PLT_LOW);
-       if (ret) PERROR_AND_EXIT(ret, "frsh_resource_set_power_level");
-       printf("FRSH_PLT_LOW correctly set\n");
-
-       return 0;       
+       
+       PXW(frsh_resource_get_power_level(FRSH_RT_LCD, 0, &level));
+       PXW(frsh_resource_get_speed(FRSH_RT_LCD, 0, level, &speed));
+       printf("Starting with power level %d, speed = %f\n", level, speed);
+
+       sleep(3);
+       PXW(frsh_resource_set_power_level(FRSH_RT_LCD, 0, FRSH_PLT_HIGH));
+       PXW(frsh_resource_get_power_level(FRSH_RT_LCD, 0, &level));
+       PXW(frsh_resource_get_speed(FRSH_RT_LCD, 0, level, &speed));
+       printf("%d (FRSH_PLT_HIGH) correctly set, speed = %f\n", level, speed);
+
+       sleep(3);
+       PXW(frsh_resource_set_power_level(FRSH_RT_LCD, 0, FRSH_PLT_MEDIUM));
+       PXW(frsh_resource_get_power_level(FRSH_RT_LCD, 0, &level));
+       PXW(frsh_resource_get_speed(FRSH_RT_LCD, 0, level, &speed));
+       printf("%d (FRSH_PLT_MEDIUM) correctly set, speed = %f\n", level, speed);
+
+       sleep(3);
+       PXW(frsh_resource_set_power_level(FRSH_RT_LCD, 0, FRSH_PLT_LOW));
+       PXW(frsh_resource_get_power_level(FRSH_RT_LCD, 0, &level));
+       PXW(frsh_resource_get_speed(FRSH_RT_LCD, 0, level, &speed));
+       printf("%d (FRSH_PLT_LOW) correctly set, speed = %f\n", level, speed);
+
+       return 0;
 }
 
index c5566b628039dce086bb96b3e7e07014408d4730..9ea2048f054902690c9d9357d6e032da2f4ee53c 100644 (file)
@@ -372,6 +372,26 @@ int fra_CPU_get_actual_budget
        return 0;
 }
 
+int aqcpu_fra_activate(forb_orb orb)
+{
+       qos_rv qrv;
+       if ((qrv = qres_init()) != QOS_OK) {
+               if (qrv == QOS_E_MISSING_COMPONENT) {
+                       return FRES_ERR_KERNEL_SUPPORT_MISSING;
+               } else
+                       return FRSH_ERR_INTERNAL_ERROR;
+       }
+
+       /* install the cleanup function of th AQuoSA framework as an exit
+        * handler function (quite futile but, for now, it's sufficent) */
+       if (atexit(aqcpu_cleanup_wrapper))
+               return(FRSH_ERR_INTERNAL_ERROR);
+
+       aqcpu_initialized = 1;
+
+       return 0;
+}
+
 static struct fres_allocator aqcpu_allocator = {
        .res_type = FRSH_RT_PROCESSOR,
        .res_id = 0,  /* CPU ID 0 */
@@ -390,6 +410,8 @@ static struct fres_allocator aqcpu_allocator = {
        .get_desired_budget = fra_CPU_get_desired_budget,
        .set_desired_budget = fra_CPU_set_desired_budget,
        .get_actual_budget = fra_CPU_get_actual_budget,
+
+       .activate_callback = aqcpu_fra_activate,
        
        .priv = NULL
 };
@@ -411,24 +433,12 @@ static struct fres_allocator aqcpu_allocator = {
  */
 int aqcpu_fra_init(void)
 {
-       qos_rv qrv;
        int rv;
 
-       if ((qrv = qres_init()) != QOS_OK) {
-               return -1;
-       }
-
        if ((rv = fra_register(&aqcpu_allocator))) {
                qres_cleanup();
                return rv;
        }
        
-       /* install the cleanup function of th AQuoSA framework as an exit
-        * handler function (quite futile but, for now, it's sufficent) */
-       if (atexit(aqcpu_cleanup_wrapper))
-               return(FRSH_ERR_INTERNAL_ERROR);
-
-       aqcpu_initialized = 1;
-
        return 0;
 }
index 0fe5fe142ef197851b93efe8ab31fcb87267755c..6db333444bb0e1c5e7ce76602bc3938727f40db8 100644 (file)
@@ -75,6 +75,7 @@ int admission_test(struct fres_sa_scenario *scenario, void *priv, bool *schedula
        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");
@@ -120,10 +121,16 @@ int admission_test(struct fres_sa_scenario *scenario, void *priv, bool *schedula
                       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 = scenario->num_contracts <= 3;
+       scenario->utilization = utilization/10;
+       *schedulable = utilization < 1000;
+       
 #ifdef CONFIG_RESOURCE_DUMMY_VERBOSE   
-       printf("=> %s\n", *schedulable?"schedulable":"not schedulable");
+       printf("utilization=%ld.%03ld => %s\n", utilization/1000, utilization%1000,
+              *schedulable?"schedulable":"not schedulable");
 #endif
                
        return 0;