00001 #define QOS_DEBUG_LEVEL QOS_LEVEL_DEBUG
00002 #include <linux/aquosa/qos_debug.h>
00003
00004 #include <aquosa/qres_lib.h>
00005
00006 #include <assert.h>
00007 #include <unistd.h>
00008 #include <stdio.h>
00009 #include <sys/time.h>
00010 #include <math.h>
00011
00013 #define ORIG_Q 50000L
00014 #define ORIG_P 100000L
00015
00018 long count_and_wait() {
00019 unsigned long counted_sheeps = 0;
00020 unsigned long elapsed_usecs;
00021 struct timeval tv1, tv2;
00022
00023 qos_log_debug("Counting sheeps for 2 seconds ...");
00024 gettimeofday(&tv1, NULL);
00025 do {
00026 gettimeofday(&tv2, NULL);
00027 elapsed_usecs = tv2.tv_usec - tv1.tv_usec + (tv2.tv_sec - tv1.tv_sec) * 1000000;
00028 counted_sheeps++;
00029 } while (elapsed_usecs < 2000000);
00030 qos_log_debug("Counted %lu sheeps in 2 seconds", counted_sheeps);
00031 return counted_sheeps;
00032 }
00033
00034 int main() {
00035 qres_params_t params = {
00036 .Q_min = 0,
00037 .Q = ORIG_Q,
00038 .P = ORIG_P,
00039 .flags = 0,
00040 };
00041 qres_sid_t sid;
00042
00043
00044 qos_log_debug("Initializing qres library");
00045 qos_chk_ok_exit(qres_init());
00046
00047 qos_log_debug("Creating QRES Server with Q=" QRES_TIME_FMT ", P=" QRES_TIME_FMT, params.Q, params.P);
00048 qos_chk_ok_exit(qres_create_server(¶ms, &sid));
00049 qos_chk_ok_exit(qres_attach_thread(sid, 0, 0));
00050
00051 count_and_wait();
00052
00053 qos_log_debug("Destroying QRES Server");
00054 qos_chk_ok_exit(qres_destroy_server(sid));
00055
00056 qos_log_debug("Finalizing QRES library");
00057 qos_chk_ok_exit(qres_cleanup());
00058
00059
00060
00061 qos_log_debug("Initializing qres library");
00062 qos_chk_ok_exit(qres_init());
00063
00064 qos_log_debug("Creating QRES Server with Q=" QRES_TIME_FMT ", P=" QRES_TIME_FMT, params.Q, params.P);
00065 qos_chk_ok_exit(qres_create_server(¶ms, &sid));
00066 qos_chk_ok_exit(qres_attach_thread(sid, 0, 0));
00067
00068 count_and_wait();
00069
00070 qos_log_debug("Detaching QRES Server");
00071 qos_chk_ok_exit(qres_detach_thread(QRES_SID_NULL, 0, 0));
00072
00073 qos_log_debug("Finalizing QRES library");
00074 qos_chk_ok_exit(qres_cleanup());
00075
00076
00077
00078 qos_log_debug("Initializing qres library");
00079 qos_chk_ok_exit(qres_init());
00080
00081 qos_log_debug("Creating QRES Server with Q=" QRES_TIME_FMT ", P=" QRES_TIME_FMT, params.Q, params.P);
00082 qos_chk_ok_exit(qres_create_server(¶ms, &sid));
00083 qos_chk_ok_exit(qres_attach_thread(sid, 0, 0));
00084
00085 count_and_wait();
00086
00087 params.Q = params.Q / 2;
00088 qos_log_debug("Setting QRES params");
00089 qos_chk_ok_exit(qres_set_params(sid, ¶ms));
00090
00091 count_and_wait();
00092
00093 params.Q = params.Q * 2;
00094 qos_log_debug("Setting QRES params");
00095 qos_chk_ok_exit(qres_set_params(sid, ¶ms));
00096
00097 count_and_wait();
00098
00099 qos_log_debug("Detaching QRES Server");
00100 qos_chk_ok_exit(qres_destroy_server(sid));
00101
00102 qos_log_debug("Finalizing QRES library");
00103 qos_chk_ok_exit(qres_cleanup());
00104
00105 return 0;
00106 }