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 int 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 abs_time, prev_abs_time;
00042 qos_chk_ok_exit(qres_get_exec_time(sid, &prev_exec_time, &prev_abs_time));
00043
00044 do {
00045 qos_chk_ok_exit(qres_get_exec_time(sid, &exec_time, &abs_time));
00046
00047 } while (abs_time - prev_abs_time < 4 * 1000000L);
00048 return 0;
00049 }
00050
00051 int main() {
00052 int rv = 0;
00053
00054 qos_log_debug("Initializing qres library");
00055 qos_chk_ok_exit(qres_init());
00056
00057 pid_t child_pid;
00058 int child_rv;
00059
00060 child_pid = fork();
00061 qos_chk_exit(child_pid != -1);
00062
00063 if (child_pid == 0) {
00064
00065 main_loop(¶ms);
00066 waitpid(child_pid, &child_rv, 0);
00067 } else {
00068
00069 return main_loop(&child_params);
00070 }
00071 qos_log_debug("Finalizing QRES library");
00072 qos_chk_ok_exit(qres_cleanup());
00073
00074
00075 return rv | child_rv;
00076 }