]> rtime.felk.cvut.cz Git - frescor/frsh.git/blobdiff - resources/disk_bfq/lib/diskbfq_fra.c
disk_bfq: Report ioprio() errors
[frescor/frsh.git] / resources / disk_bfq / lib / diskbfq_fra.c
index 1fc8fd2db0c23d1f84dbd6b9e5b7ef4792664ef1..589a08de7f51c14c7dc21d2e5ff5cd4c48b4b062 100644 (file)
 
 #include <stdio.h>
 #include <ul_log.h>
+#include <ul_logreg.h>
 #include <fra_generic.h>
 #include "diskbfq_contract.h"
 #include "res_disk.h"
 
-UL_LOG_CUST(ulogd_fra_cpucg);
-//ul_log_domain_t ulogd_fra_cpucg = {UL_LOGL_MSG, "fra_cpucg"};
+UL_LOG_CUST(ulogd_fra_diskbfq);
+ul_log_domain_t ulogd_fra_diskbfq = {UL_LOGL_MSG, "fra_diskbfq"};
+UL_LOGREG_SINGLE_DOMAIN_INIT_FUNCTION(fra_diskbfq_logreg_domains, ulogd_fra_diskbfq);
 
 static int diskbfq_initialized = 0; /* initialization flag */
 
@@ -93,10 +95,10 @@ static int diskbfq_create_vres(fres_vres_t *vres, void *priv)
                return -1;
 
        memcpy(vres->priv, &disk_sched->ioprio, sizeof(int));
-       printf("Created BFQ VRES (ioprio=%d budget=%ld ms, period=%ld ms)\n",
-              disk_sched->ioprio,
-              fosa_rel_time_to_msec(basic->budget),
-              fosa_rel_time_to_msec(basic->period));
+       ul_logmsg("Created BFQ VRES (ioprio=%d budget=%ld ms, period=%ld ms)\n",
+                 disk_sched->ioprio,
+                 fosa_rel_time_to_msec(basic->budget),
+                 fosa_rel_time_to_msec(basic->period));
 
        return 0;
 }
@@ -116,12 +118,13 @@ static int diskbfq_cancel_vres(fres_vres_t *vres, void *priv)
         * is automatically released when the thread is unbound
         * from the vres itself.
         */
-       printf("Canceled DISK VRES (ioprio=%d)\n", *((int*)vres->priv));
+       ul_logmsg("Canceled DISK VRES (ioprio=%d)\n", *((int*)vres->priv));
        free(vres->priv);
 
        return 0;
 }
 
+static
 int diskbfq_change_vres(fres_vres_t *vres, void *priv)
 {
        fres_block_disk_sched *disk_sched;
@@ -132,66 +135,21 @@ int diskbfq_change_vres(fres_vres_t *vres, void *priv)
        }
 
        disk_sched = fres_contract_get_disk_sched(vres->new);
-       printf("Changed BFQ VRES from ioprio=%d to ioprio=%d\n",
-              *((int*)vres->priv), (int) disk_sched->ioprio);
+       ul_logmsg("Changed BFQ VRES from ioprio=%d to ioprio=%d\n",
+                 *((int*)vres->priv), (int) disk_sched->ioprio);
        memcpy(vres->priv, &disk_sched->ioprio, sizeof(int));
 
        return 0;
 }
 
-static struct fres_allocator diskbfq_allocator = {
-       .res_type = FRSH_RT_DISK,
-       .res_id = 0,  /* DISK ID 0 */
-       .create_vres = diskbfq_create_vres,
-       .cancel_vres = diskbfq_cancel_vres,
-       .change_vres = diskbfq_change_vres,
-       .priv = NULL
-};
-
-/*
- * diskbfq_fra_init()
- *
- * initialize FRSH for the calling process
- *
- * Must be called before starting using the framework.
- * No FRSH call will be successful if this routine is not invoked
- *
- * Note that no BACKGROUND is created and negotiated and the caller thread
- * is bound to no BACKGROUND vres, since no way is provided in order of
- * specifying the contract label and get back the vres id!
- *
- * Note also that, since in this implementation the threads/processes with
- * backgound contracts are left into the default Linux scheduler hands' and
- * not attached to any AQuoSA server, while we're violating what D-AC2v1
- * (pag. 14) says, we achieve exactly the same behaviour!!
- *
- * possible return values:
- *  FRSH_NO_ERROR
- *  FRSH_ERR_ALREADY_INITIALIZED
- *  FRSH_ERR_INTERNAL_ERROR (something, different from the previous case, gone wrong)
- */
-int diskbfq_fra_init(void)
-{
-       if (diskbfq_is_initialized()) {
-               return -1;
-       }
-
-       fres_block_register_disk_sched();
-       if (fra_register(&diskbfq_allocator)) {
-               return -1;
-       }
-       
-       diskbfq_initialized = 1;
-       return 0;
-}
-
 int diskbfq_fra_exit()
 {
        return 0;
 }
 
+static
 int fra_DISK_bind_thread
-  (const fres_vres_t *vres,
+  (fres_vres_t *vres,
    const fosa_thread_id_t thread)
 {
        fres_block_basic *b;
@@ -213,9 +171,11 @@ int fra_DISK_bind_thread
 
        return 0;
 err:
+       ul_logerr("ioprio(): %s\n", strerror(errno));
        return -1;
 }
 
+static
 int fra_DISK_unbind_thread(const fosa_thread_id_t thread)
 {
        int ret;
@@ -229,6 +189,7 @@ int fra_DISK_unbind_thread(const fosa_thread_id_t thread)
        return 0;
 }
 
+static
 int fra_DISK_get_usage
   (const fres_vres_t *vres,
    fosa_rel_time_t *spent)
@@ -236,6 +197,7 @@ int fra_DISK_get_usage
        return -1;
 }
 
+static
 int fra_DISK_get_job_usage
   (const fres_vres_t *vres,
    fosa_rel_time_t *spent)
@@ -243,6 +205,7 @@ int fra_DISK_get_job_usage
        return -1;
 }
 
+static
 int fra_DISK_get_remaining_budget
   (const fres_vres_t *vres,
    fosa_rel_time_t *budget)
@@ -250,12 +213,14 @@ int fra_DISK_get_remaining_budget
        return -1;
 }
 
+static
 int fra_DISK_set_spare_bandwidth
   (fres_vres_t *vres)
 {
        return -1;
 }
 
+static
 int fra_DISK_get_desired_budget
   (fres_vres_t *vres,
    frsh_rel_time_t *p_budget_out)
@@ -263,6 +228,7 @@ int fra_DISK_get_desired_budget
        return -1;
 }
 
+static
 int fra_DISK_set_desired_budget
   (fres_vres_t *vres,
    fosa_rel_time_t *p_budget_in)
@@ -270,6 +236,7 @@ int fra_DISK_set_desired_budget
        return -1;
 }
 
+static
 int fra_DISK_get_actual_budget
   (fres_vres_t *vres,
    fosa_rel_time_t *budget)
@@ -277,3 +244,62 @@ int fra_DISK_get_actual_budget
        return -1;
 }
 
+static struct fres_allocator diskbfq_allocator = {
+       .res_type = FRSH_RT_DISK,
+       .res_id = 0,  /* DISK ID 0 */
+       .create_vres = diskbfq_create_vres,
+       .cancel_vres = diskbfq_cancel_vres,
+       .change_vres = diskbfq_change_vres,
+
+       .bind_thread = fra_DISK_bind_thread,
+       .unbind_thread = fra_DISK_unbind_thread,
+
+       .vres_get_usage = fra_DISK_get_usage,
+       .vres_get_job_usage = fra_DISK_get_job_usage,
+       .vres_get_remaining_budget = fra_DISK_get_remaining_budget,
+
+       .set_spare_bandwidth = fra_DISK_set_spare_bandwidth,
+       .get_desired_budget = fra_DISK_get_desired_budget,
+       .set_desired_budget = fra_DISK_set_desired_budget,
+       .get_actual_budget = fra_DISK_get_actual_budget,
+
+       .priv = NULL
+};
+
+/*
+ * diskbfq_fra_init()
+ *
+ * initialize FRSH for the calling process
+ *
+ * Must be called before starting using the framework.
+ * No FRSH call will be successful if this routine is not invoked
+ *
+ * Note that no BACKGROUND is created and negotiated and the caller thread
+ * is bound to no BACKGROUND vres, since no way is provided in order of
+ * specifying the contract label and get back the vres id!
+ *
+ * Note also that, since in this implementation the threads/processes with
+ * backgound contracts are left into the default Linux scheduler hands' and
+ * not attached to any AQuoSA server, while we're violating what D-AC2v1
+ * (pag. 14) says, we achieve exactly the same behaviour!!
+ *
+ * possible return values:
+ *  FRSH_NO_ERROR
+ *  FRSH_ERR_ALREADY_INITIALIZED
+ *  FRSH_ERR_INTERNAL_ERROR (something, different from the previous case, gone wrong)
+ */
+int diskbfq_fra_init(void)
+{
+       if (diskbfq_is_initialized()) {
+               return -1;
+       }
+
+       fres_block_register_disk_sched();
+       if (fra_register(&diskbfq_allocator)) {
+               return -1;
+       }
+       
+       diskbfq_initialized = 1;
+       return 0;
+}
+