]> rtime.felk.cvut.cz Git - frescor/fwp.git/commitdiff
Compilation fixes of Aquosa CPU(aqcpu) module. Added timespec_usec_ops.h.
authorMartin <molnar@sum.(none)>
Tue, 23 Sep 2008 16:32:23 +0000 (18:32 +0200)
committerMartin <molnar@sum.(none)>
Tue, 23 Sep 2008 16:32:23 +0000 (18:32 +0200)
frsh_aquosa/core.c
frsh_aquosa/cpu_contract.c
frsh_aquosa/cpu_contract.h
frsh_aquosa/timespec_usec_ops.h [new file with mode: 0644]

index dc7135247b6b0f801fb8cf09d4aab81c389a5d1c..32e7646758e8448d26d0334a46f9396b640b40a8 100644 (file)
 #include <sys/types.h>
 #define __USE_UNIX98
 #include <pthread.h>
+#include <semaphore.h>
 #include <stdio.h>
 #include <string.h>
 
 /* FRSH files */
+#include "frsh_cpp_macros.h"
 #include "fosa.h"
+#include "frsh_core_types.h"
 #include "frsh_error.h"
 
 /* AQuoSA files */
 #include "timespec_usec_ops.h"
 
 static int aqcpu_initialized = 0;              /* initialization flag */
+
 /*
  * Test whether Aquosa Cpu modue is initialized 
- *
  */
-
 static inline int aqcpu_is_initialized()
 {
        return (aqcpu_initialized == 1);
@@ -133,8 +135,8 @@ static inline int aqcpu_is_initialized()
  * code... For now it only calls the cleanup function of the AQuoSA
  * Framework
  */
-static void aqcpu_cleanup_wrapper() {
-       return qres_cleanup();
+static inline void aqcpu_cleanup_wrapper() {
+       qres_cleanup();
 }
 
 /*
@@ -158,7 +160,6 @@ static void aqcpu_cleanup_wrapper() {
  *  FRSH_ERR_INTERNAL_ERROR (something, different from the previous case, gone wrong)
  */
 
-
 int aqcpu_init()
 {
        /* check FRSH is not already initialized */
@@ -169,17 +170,16 @@ int aqcpu_init()
        /* check if the name service is available and ty to start it if not */
        /* (try to) initialize the AQuoSA Framework */
        if (qres_init() != QOS_OK || qsup_init() != QOS_OK)
-               FRSH_ERR_RET(FRSH_ERR_INTERNAL_ERROR);
+               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))
-               FRSH_ERR_RET(FRSH_ERR_INTERNAL_ERROR);
+               return(FRSH_ERR_INTERNAL_ERROR);
 
        return FRSH_NO_ERROR;
 }
 
-
 /*
  * frsh_thread_bind(), create a new thread and bind it to a vres
  * frsh_thread_create_in_background(), create a new thread and a new BACKGROUND contract and bind them
@@ -216,6 +216,7 @@ typedef struct {
        frsh_thread_code_t pthread_code;
        void *pthread_arg;
        sem_t *stopper;
+       int  errcode;
 } wrapper_pthread_arg_t;
 
 /*
@@ -237,10 +238,10 @@ typedef struct {
  */
 static void* wrapper_pthread(void *arg)
 {
-       int rv;
-       
        wrapper_pthread_arg_t pth = *((wrapper_pthread_arg_t*) arg);    
        sem_wait(pth.stopper);  
+       if (pth.errcode) /* vres binding was not successful */
+               return NULL;
        /* (pth.thread_id) = fosa_thread_self(); */
        return pth.pthread_code(pth.pthread_arg);
 }
@@ -331,24 +332,21 @@ int frsh_thread_create_and_bind(const frsh_vres_id_t vres,
                "can't create a thread with NULL thread_core or return it in a NULL thread");
        */
 
-       wp.thread_code = thread_code;
-       wp.thread_arg = arg;    
+       wp.pthread_code = thread_code;
+       wp.pthread_arg = arg;   
        wp.stopper = &stopper;
 
        /* create the wrapper thread */ 
        rv = fosa_thread_create(thread, attr, wrapper_pthread, (void*)&wp);
        
        if (rv != 0)
-               FRSH_ERR_RET(rv);
-       
-       rv = frsh_thread_bind();
-       if ( rv != FRSH_NO_ERROR) {
-               FRSH_ERR_RET(FRSH_ERR_INVALID_SCHEDULER_REPLY);
-       }
+               return(rv);
        
+       rv = frsh_thread_bind(vres, *thread);
+       wp.errcode = rv;
        sem_post(&stopper);
 
-       return FRSH_NO_ERROR;
+       return rv;
 }
 
 /*
index e71132e7904613d35c1b0225f4e0747eef8dfc55..0f049474eec16f27e7becc5883478c0b13660161 100644 (file)
@@ -12,6 +12,7 @@ int set_cpu_vres(contract_t contract, qres_sid_t vres)
 
 int get_cpu_params(contract_t *contract, cpu_params_t *cpu_params)
 {
+#if 0
        /* core contract parameters */
        cpu_params->Q_min = timespec_to_usec(contract->budget_min);
        cpu_params->P = timespec_to_usec(contract->period_max);
@@ -27,6 +28,8 @@ int get_cpu_params(contract_t *contract, cpu_params_t *cpu_params)
        }
                        
        cpu_params->timeout = 0;
+#endif
+       return 0;
 }
 
 int set_cpu_params(contract_t *contract, cpu_params_t *cpu_params)
index 8601699508a60192e1d336efdf95f0cba3b2a63c..e93e5d58ee9513d8088665cac2f5b09e757fa280 100644 (file)
@@ -1,5 +1,10 @@
 #ifndef CPU_CONTRACT_H
+#include "aquosa/qres_lib.h"
+#include "timespec_usec_ops.h"
+
 typedef qres_params_t cpu_params_t;
+/* temporarily */
+typedef int* contract_t;
 
 int get_cpu_vres(contract_t contract, qres_sid_t *vres);
 int set_cpu_vres(contract_t contract, qres_sid_t vres);
diff --git a/frsh_aquosa/timespec_usec_ops.h b/frsh_aquosa/timespec_usec_ops.h
new file mode 100644 (file)
index 0000000..57cc989
--- /dev/null
@@ -0,0 +1,69 @@
+#ifndef        __TIMESPEC_USEC_OPS_H__
+#define __TIMESPEC_USEC_OPS_H__
+
+/*
+ * timespec_usec_ops.h
+ *
+ * ...
+ */
+
+#include <time.h>
+
+#define equal_timespec(t1, t2) \
+ ( ( (t1)->tv_sec == (t2)->tv_sec ) && ( (t1)->tv_nsec == (t2)->tv_nsec )  )
+
+#define increment_timespec(t) \
+do { \
+ (t)->tv_nsec ++; \
+ if ((t)->tv_nsec >= 1000000000UL) { \
+   (t)->tv_sec ++; \
+   (t)->tv_nsec -= 1000000000UL; \
+ } \
+} while(0)
+
+#define decrement_timespec(t) \
+do { \
+ if ( (t)->tv_nsec == 0) { \
+  (t)->tv_nsec = 1000000000UL; \
+  (t)->tv_sec --; \
+ } \
+ else \
+  (t)->tv_nsec --; \
+} while(0)
+
+#define sum_timespec(t1, t2, ts) \
+do { \
+ (ts)->tv_sec  = (t1)->tv_sec  + (t2)->tv_sec; \
+ (ts)->tv_nsec = (t1)->tv_nsec + (t2)->tv_nsec; \
+ while ( (ts)->tv_nsec >= 1000000000UL) { \
+  (ts)->tv_sec ++; \
+  (ts)->tv_nsec -= 1000000000UL; \
+ } \
+} while(0)
+
+#define sub_timespec(t1, t2, ts) \
+do { \
+ if ( (t2)->tv_sec < (t1)->tv_sec || \
+  ((t2)->tv_sec == (t1)->tv_nsec && (t2)->tv_nsec < (t1)->tv_nsec) ) { \
+  (ts)->tv_sec = (t1)->tv_sec - (t2)->tv_sec; \
+  (ts)->tv_nsec = (t1)->tv_nsec - (t2)->tv_sec; \
+  while ( (ts)->tv_nsec < 0) { \
+   (ts)->tv_sec --; \
+   (ts)->tv_nsec = (ts)->tv_nsec + 1000000000UL; \
+  } \
+ } else { \
+  (ts)->tv_sec = 0UL; \
+  (ts)->tv_nsec = 0UL; \
+ } \
+} while(0)
+
+#define zero_timespec(t) \
+do { \
+ (t)->tv_sec = 0; \
+ (t)->tv_nsec = 0; \
+} while(0)
+
+#define is_zero_timespec(t) \
+( (t)->tv_sec == 0 && (t)->tv_nsec == 0 )
+
+#endif /* __TIMESPEC_USEC_OPS_H__ */