00001 #define QOS_DEBUG_LEVEL QOS_LEVEL_DEBUG
00002 #include <linux/aquosa/qos_debug.h>
00003
00004 #include <aquosa/qres_lib.h>
00005 #include "util_timeval.h"
00006
00007 #include <assert.h>
00008 #include <unistd.h>
00009 #include <stdio.h>
00010 #include <sys/time.h>
00011 #include <math.h>
00012 #include <string.h>
00013
00015 #define ORIG_Q 20000L
00016 #define ORIG_P 100000L
00017
00019 #define N 1
00020
00021 char cmd_line[180];
00022
00023
00024 FILE *replicas[N];
00025
00026 int main_body() {
00027 qres_params_t params = {
00028 .Q_min = ORIG_Q,
00029 .Q = ORIG_Q,
00030 .P = ORIG_P,
00031 .flags = 0,
00032 };
00033 int j;
00034 int rv = 0;
00035 qres_atime_t prev_abs_time, abs_time;
00036 qres_time_t prev_exec_time, exec_time;
00037 qres_sid_t sid;
00038
00039 qos_log_debug("Initializing qres library");
00040 qos_chk_ok_exit(qres_init());
00041
00042 qos_log_debug("Creating QRES Server with Q=" QRES_TIME_FMT ", P=" QRES_TIME_FMT, params.Q, params.P);
00043 qos_chk_ok_exit(qres_create_server(¶ms, &sid));
00044 qos_chk_ok_exit(qres_attach_thread(sid, 0, 0));
00045
00046 qres_get_exec_time(sid, &prev_exec_time, &prev_abs_time);
00047 for (j = 0; j < 100; j++) {
00048 do {
00049 qres_get_exec_time(sid, &exec_time, &abs_time);
00050 } while (abs_time - prev_abs_time < ORIG_P);
00051 qos_log_debug("exec_time: " QRES_TIME_FMT ", abs_time: " QRES_ATIME_FMT,
00052 exec_time, abs_time);
00053 qres_time_t delta = exec_time - prev_exec_time;
00054 if (delta < ORIG_Q * 9 / 10 || delta > ORIG_Q * 11 / 10) {
00055 qos_log_err("Didn't get enough budget: " QRES_TIME_FMT
00056 ", expecting " QRES_TIME_FMT, delta, (qres_time_t) ORIG_Q);
00057 rv = -1;
00058 }
00059 prev_exec_time += ORIG_Q;
00060 prev_abs_time += ORIG_P;
00061 }
00062
00063 qos_log_debug("Destroying QRES Server");
00064 qos_chk_ok_exit(qres_destroy_server(sid));
00065
00066 qos_log_debug("Finalizing QRES library");
00067 qos_chk_ok_exit(qres_cleanup());
00068
00069 return rv;
00070 }
00071
00072 int main(int argc, char **argv) {
00073 int rv = 0;
00074 int j;
00075
00076 if (argc == 1) {
00077 qos_log_debug("Replicating myself...");
00078
00079 for (j = 0; j < N; j++) {
00080 strncpy(cmd_line, argv[0], sizeof(cmd_line));
00081 strncat(cmd_line, " fake_arg", sizeof(cmd_line));
00082 qos_log_debug("... through command: %s", cmd_line);
00083 replicas[j] = popen(cmd_line, "r");
00084 qos_chk_exit(replicas[j] != NULL);
00085 }
00086
00087 rv = main_body();
00088
00089 for (j = 0; j < N; j++) {
00090 qos_chk_exit(pclose(replicas[j]) == 0);
00091 }
00092 } else {
00093 rv = main_body();
00094 }
00095
00096 return rv;
00097 }