00001 #include <aquosa/qres_lib.h>
00002 #include <linux/aquosa/qos_debug.h>
00003
00004 #include <assert.h>
00005 #include <unistd.h>
00006 #include <stdio.h>
00007 #include <sys/time.h>
00008 #include <math.h>
00009 #include <pthread.h>
00010 #include <sys/types.h>
00011 #include <sys/wait.h>
00012
00014 #define ORIG_Q 15000L
00015 #define ORIG_P 60000L
00016
00017 qres_params_t params = {
00018 .Q_min = 0,
00019 .Q = 15000,
00020 .P = 60000,
00021 .flags = 0,
00022 };
00023
00024 qres_params_t child_params = {
00025 .Q_min = 0,
00026 .Q = 30000,
00027 .P = 60000,
00028 .flags = 0,
00029 };
00030
00031 void *main_loop(void *ptr) {
00032 qres_params_t *params = (qres_params_t *) ptr;
00033 qres_sid_t sid;
00034
00035 qos_log_debug("Creating QRES Server with Q=" QRES_TIME_FMT
00036 ", P=" QRES_TIME_FMT, params->Q, params->P);
00037 qos_chk_ok_exit(qres_create_server(params, &sid));
00038 qos_chk_ok_exit(qres_attach_thread(sid, 0, 0));
00039
00040 qres_time_t prev_exec_time, exec_time;
00041 qres_atime_t prev_abs_time, abs_time;
00042 qos_chk_ok_exit(qres_get_exec_time(sid, &prev_exec_time, &prev_abs_time));
00043 do {
00044 qos_chk_ok_exit(qres_get_exec_time(sid, &exec_time, &abs_time));
00045
00046 } while (abs_time - prev_abs_time < 4 * 1000000L);
00047 return NULL;
00048 }
00049
00050 int main() {
00051 int rv = 0;
00052
00053 qos_log_debug("Initializing qres library");
00054 qos_chk_ok_exit(qres_init());
00055
00056 pthread_t child_tid;
00057 void *child_rv;
00058
00059 rv = pthread_create(&child_tid, NULL, main_loop, (void *) &child_params);
00060 qos_chk_exit(rv == 0);
00061
00062
00063 main_loop(¶ms);
00064
00065 pthread_join(child_tid, &child_rv);
00066
00067 qos_log_debug("Finalizing QRES library");
00068 qos_chk_ok_exit(qres_cleanup());
00069
00070
00071 return rv | (int) (long) child_rv;
00072 }