00001 #define QOS_DEBUG_LEVEL QOS_LEVEL_DEBUG 00002 #include <linux/aquosa/qos_debug.h> 00003 #include <aquosa/qres_lib.h> 00004 00005 #include "util_periodic.h" 00006 #include <stdio.h> 00007 00008 #define N 1000 00009 #define TICK_US 100ull 00010 00011 struct timeval t0; 00012 00013 struct data { 00014 unsigned long timestamps[N]; 00015 qres_time_t gua_budgets[N]; 00016 qres_time_t req_budgets[N]; 00017 qres_time_t appr_budgets[N]; 00018 qres_time_t next_budgets[N]; 00019 qres_time_t curr_budgets[N]; 00020 int num; 00021 qres_sid_t sid; 00022 } data; 00023 00024 void f(void * p) { 00025 struct data * p_data = (struct data *) p; 00026 struct timeval t; 00027 unsigned long timestamp; 00028 qres_time_t gua_budget, req_budget, appr_budget, next_budget, curr_budget; 00029 qres_params_t params; 00030 00031 gettimeofday(&t, NULL); 00032 00033 timestamp = timeval_sub_us(&t, &t0); 00034 qos_chk_ok_exit(qres_get_params(p_data->sid, ¶ms)); 00035 gua_budget = params.Q_min; 00036 req_budget = params.Q; 00037 qos_chk_ok_exit(qres_get_appr_budget(p_data->sid, &appr_budget)); 00038 qos_chk_ok_exit(qres_get_next_budget(p_data->sid, &next_budget)); 00039 qos_chk_ok_exit(qres_get_curr_budget(p_data->sid, &curr_budget)); 00040 00041 if (p_data->num < N) { 00042 p_data->timestamps[p_data->num] = timestamp; 00043 p_data->gua_budgets[p_data->num] = gua_budget; 00044 p_data->req_budgets[p_data->num] = req_budget; 00045 p_data->appr_budgets[p_data->num] = appr_budget; 00046 p_data->next_budgets[p_data->num] = next_budget; 00047 p_data->curr_budgets[p_data->num] = curr_budget; 00048 p_data->num++; 00049 } 00050 } 00051 00052 void data_write_timestamps(struct data *p_data, const char *fname) { 00053 FILE *f; 00054 int i; 00055 qos_chk_exit((f = fopen(fname, "w")) != NULL); 00056 00057 for (i = 0; i < p_data->num; ++i) { 00058 fprintf(f, "%lu\t" QRES_TIME_FMT "\t" QRES_TIME_FMT "\t" QRES_TIME_FMT 00059 "\t" QRES_TIME_FMT "\t" QRES_TIME_FMT "\n", p_data->timestamps[i], p_data->gua_budgets[i], 00060 p_data->req_budgets[i], p_data->appr_budgets[i], 00061 p_data->next_budgets[i], p_data->curr_budgets[i]); 00062 } 00063 00064 fclose(f); 00065 } 00066 00067 int main(int argc, char *argv[]) 00068 { 00069 qres_params_t params; 00070 struct timeval t1; 00071 struct timeval duration = { .tv_sec = (TICK_US * N) / 1000000, .tv_usec = (TICK_US * N) % 1000000 }; 00072 struct timeval tick = { .tv_sec = TICK_US / 1000000, .tv_usec = TICK_US % 1000000 }; 00073 00074 qos_chk_ok_exit(qres_init()); 00075 00076 params.Q = 9900; 00077 params.Q_min = 0; 00078 params.P = 10000; 00079 params.flags = 0; 00080 qos_chk_ok_exit(qres_create_server(¶ms, &data.sid)); 00081 qos_chk_ok_exit(qres_attach_thread(data.sid, 0, 0)); 00082 00083 gettimeofday(&t0, NULL); 00084 timeval_add(&t1, &t0, &duration); 00085 00086 data.num = 0; 00087 spin_periodic_call(&t0, &t1, &tick, f, &data); 00088 00089 qos_chk_ok_exit(qres_destroy_server(data.sid)); 00090 00091 data_write_timestamps(&data, "/tmp/ts.txt"); 00092 00093 qos_chk_ok_exit(qres_cleanup()); 00094 00095 return 0; 00096 }