00001 #include <linux/aquosa/qsup.h>
00002
00003 #include <linux/aquosa/qos_debug.h>
00004 #include <linux/aquosa/qos_types.h>
00005
00006 #include <math.h>
00007 #include <sys/time.h>
00008 #include <time.h>
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 typedef double pair_t[2];
00022
00023 pair_t bw_requests[] = {
00024
00025 { 0.2, 0.2 },
00026
00027 { 0.5, 0.5 },
00028
00029 { 0.4, 0.5 },
00030
00031 { 0.2, 0.6 },
00032
00033 { 0.4, 0.6 },
00034
00035 { 0.0, 0.0 },
00036 };
00037
00038 pair_t bw_approved[] = {
00039 { 0.2, 0.2 },
00040 { 0.5/(0.5+0.5)*0.75, 0.5/(0.5+0.5)*0.75},
00041 { 0.4/(0.4+0.5)*0.75, 0.5/(0.4+0.5)*0.75},
00042 { 0.2, 0.5 },
00043 { 0.4/(0.4+0.5)*0.75, 0.5/(0.4+0.5)*0.75},
00044 { 0.0, 0.0 },
00045 };
00046
00047 double tolerance = 0.0001;
00048
00049 int main(int argc, char *argv[]) {
00050 int err = 0;
00051 unsigned int n;
00052 qsup_server_t *srv0, *srv1;
00053
00054 qos_log_debug("Initing...");
00055 qsup_init();
00056
00057 qsup_add_level_rule(0, d2bw(0.75));
00058
00059 qsup_add_group_constraints(0, & ((qsup_constraints_t) { 0, 1, d2bw(0.5), d2bw(0.0), 0 }) );
00060
00061 qos_chk_ok_exit(qsup_create_server(&srv0, 0, 0, & ((qres_params_t) { 0, 0, 10000, 0 }) ));
00062 qos_chk_ok_exit(qsup_create_server(&srv1, 1, 0, & ((qres_params_t) { 0, 0, 10000, 0 }) ));
00063
00064 qsup_dump();
00065
00066 for (n = 0; n < sizeof(bw_requests) / sizeof(pair_t); n++) {
00067 int i;
00068 struct timeval tv1, tv2;
00069 gettimeofday(&tv1, NULL);
00070 for (i = 0; i < 1000000; ++i)
00071 qsup_set_required_bw(srv0, d2bw(bw_requests[n][0]));
00072 gettimeofday(&tv2, NULL);
00073 qos_log_debug("# microseconds: %g\n", (tv2.tv_usec - tv1.tv_usec + (tv2.tv_sec - tv1.tv_sec) * 1000000) / 1000000.0);
00074 qsup_set_required_bw(srv1, d2bw(bw_requests[n][1]));
00075 if (
00076 (fabs(bw2d(qsup_get_approved_bw(srv0)) - bw_approved[n][0]) > tolerance)
00077 || (fabs(bw2d(qsup_get_approved_bw(srv1)) - bw_approved[n][1]) > tolerance)
00078 ) {
00079 qos_log_err("Requests were %g, %g. Expecting %g, %g while got %g, %g.",
00080 bw_requests[n][0], bw_requests[n][1],
00081 bw_approved[n][0], bw_approved[n][1],
00082 bw2d(qsup_get_approved_bw(srv0)), bw2d(qsup_get_approved_bw(srv1)));
00083 err = -1;
00084 }
00085 }
00086
00087 qsup_dump();
00088
00089 qos_log_debug("Cleaning up supervisor (all at once)");
00090 qsup_cleanup();
00091
00092 return err;
00093 }