2 #include <libavformat/avformat.h>
4 #define QOS_DEBUG_LEVEL QOS_LEVEL_DEBUG
5 #include <linux/aquosa/qos_debug.h>
7 #include <aquosa/qmgr_lib.h>
8 #include <aquosa/percpred_lib.h>
9 #include <aquosa/stochdb_lib.h>
13 #define SERV_PERIOD 10000lu /* us */
14 #define TASK_PERIOD 40000lu /* us */
16 #define DISCARDED 1 /* discard 1 out of 3 ==> percentile = 66.66% */
18 static uint64_t start_time, start_time1;
19 static uint64_t thebeginning;
22 void rt_job_start(uint64_t t)
24 static int started = 0;
25 struct timespec now, now1;
30 t += (1000000ul / fps); /* Hack to work around v4l2vd bug... */
36 qos_log_debug("Initializing qmgr library\n");
37 qos_chk_ok_exit(qmgr_init());
39 qos_log_debug("Setting predictor\n");
40 /* Defaults to 3 samples and forgetting factor = 1 */
41 qos_chk_ok_exit(qmgr_set_predictor(QMGR_PRED_PERC));
43 qos_log_debug("Setting sample size to %d\n", SAMPLE_SZ);
44 /* Sets sample size */
45 qos_chk_ok_exit(percpred_set_sample_size(SAMPLE_SZ));
47 qos_log_debug("Setting discarded to %d\n", DISCARDED);
49 qos_chk_ok_exit(percpred_set_discarded(DISCARDED));
51 qos_log_debug("Setting controller\n");
52 /* Defaults to null target s.e. */
53 //qos_chk_ok_exit(qmgr_set_controller(QMGR_CTRL_INVARIANT/*STOCHDB*/));
54 qos_chk_ok_exit(qmgr_set_controller(QMGR_CTRL_STOCHDB));
56 qos_log_debug("Setting controller parameters\n");
57 /* Assign task period and granularity */
58 qmgr_set_task_period(1000000 / fps);
59 qmgr_set_server_period(1000000 / fps / 6);
60 qmgr_set_max_bandwidth(0.95);
62 qos_log_debug("Starting control loop");
63 qos_chk_ok_exit(qmgr_start());
64 clock_gettime(CLOCK_MONOTONIC, &now);
65 clock_gettime(CLOCK_REALTIME, &now1);
66 delta = (now1.tv_sec - now.tv_sec) * 1000000ll + (now1.tv_nsec - now.tv_nsec) / 1000ll;
68 dl = t + (1000000ul / fps);
70 now.tv_nsec = (dl % 1000000) * 1000;
71 now.tv_sec = dl / 1000000;
72 qmgr_begin_cycle_deadline(&now);
74 start_time1 = av_gettime();
80 qres_time_t sched_err, etime;
83 printf("%lu %lu %lu\t%lu %lu\t", start_time, start_time1, t, t - start_time, t - start_time1);
84 if (cnt == 0) printf("0\t");
85 else printf("%lu\t", (start_time - thebeginning) / cnt);
87 qmgr_end_cycle(&sched_err, &etime);
88 printf(QRES_TIME_FMT "\n", sched_err);
89 //qos_log_debug("Ending job: " QRES_TIME_FMT "\n", sched_err);