2 * Copyright (c) 2008 Luca Abeni
4 * This is free software; see GPL.txt
7 #include <libavformat/avformat.h>
9 #define QOS_DEBUG_LEVEL QOS_LEVEL_DEBUG
10 #include <linux/aquosa/qos_debug.h>
12 #include <aquosa/qmgr_lib.h>
13 #include <aquosa/percpred_lib.h>
14 #include <aquosa/stochdb_lib.h>
18 #define SERV_PERIOD 10000lu /* us */
19 #define TASK_PERIOD 40000lu /* us */
21 #define DISCARDED 1 /* discard 1 out of 3 ==> percentile = 66.66% */
23 static uint64_t start_time, start_time1;
24 static uint64_t thebeginning;
27 void rt_job_start(uint64_t t)
29 static int started = 0;
30 struct timespec now, now1;
35 t += (1000000ul / fps); /* Hack to work around v4l2vd bug... */
41 qos_log_debug("Initializing qmgr library\n");
42 qos_chk_ok_exit(qmgr_init());
44 qos_log_debug("Setting predictor\n");
45 /* Defaults to 3 samples and forgetting factor = 1 */
46 qos_chk_ok_exit(qmgr_set_predictor(QMGR_PRED_PERC));
48 qos_log_debug("Setting sample size to %d\n", SAMPLE_SZ);
49 /* Sets sample size */
50 qos_chk_ok_exit(percpred_set_sample_size(SAMPLE_SZ));
52 qos_log_debug("Setting discarded to %d\n", DISCARDED);
54 qos_chk_ok_exit(percpred_set_discarded(DISCARDED));
56 qos_log_debug("Setting controller\n");
57 /* Defaults to null target s.e. */
58 //qos_chk_ok_exit(qmgr_set_controller(QMGR_CTRL_INVARIANT/*STOCHDB*/));
59 qos_chk_ok_exit(qmgr_set_controller(QMGR_CTRL_STOCHDB));
61 qos_log_debug("Setting controller parameters\n");
62 /* Assign task period and granularity */
63 qmgr_set_task_period(1000000 / fps);
64 qmgr_set_server_period(1000000 / fps / 6);
65 qmgr_set_max_bandwidth(0.95);
67 qos_log_debug("Starting control loop");
68 qos_chk_ok_exit(qmgr_start());
69 clock_gettime(CLOCK_MONOTONIC, &now);
70 clock_gettime(CLOCK_REALTIME, &now1);
71 delta = (now1.tv_sec - now.tv_sec) * 1000000ll + (now1.tv_nsec - now.tv_nsec) / 1000ll;
73 dl = t + (1000000ul / fps);
75 now.tv_nsec = (dl % 1000000) * 1000;
76 now.tv_sec = dl / 1000000;
77 qmgr_begin_cycle_deadline(&now);
79 start_time1 = av_gettime();
85 qres_time_t sched_err, etime;
88 printf("%lu %lu %lu\t%lu %lu\t", start_time, start_time1, t, t - start_time, t - start_time1);
89 if (cnt == 0) printf("0\t");
90 else printf("%lu\t", (start_time - thebeginning) / cnt);
92 qmgr_end_cycle(&sched_err, &etime);
93 printf(QRES_TIME_FMT "\n", sched_err);
94 //qos_log_debug("Ending job: " QRES_TIME_FMT "\n", sched_err);