]> rtime.felk.cvut.cz Git - frescor/streamer.git/blob - rt_qosmgr.c
Export fps for rt_qosmgr.c (so that it can correctly set server period, etc...)
[frescor/streamer.git] / rt_qosmgr.c
1 #include <stdio.h>
2 #include <ffmpeg/avformat.h>
3
4 #define QOS_DEBUG_LEVEL QOS_LEVEL_DEBUG
5 #include <linux/aquosa/qos_debug.h>
6
7 #include <aquosa/qmgr_lib.h>
8 #include <aquosa/percpred_lib.h>
9 #include <aquosa/stochdb_lib.h>
10
11 #define SERV_PERIOD 10000lu     /* us */
12 #define TASK_PERIOD 40000lu     /* us */
13 #define SAMPLE_SZ 3
14 #define DISCARDED 1     /* discard 1 out of 3 ==> percentile = 66.66% */
15
16 static uint64_t start_time, start_time1;
17
18 void rt_job_start(uint64_t t)
19 {
20   static int started = 0;
21
22   if (! started) {
23     started = 1;
24     qos_log_debug("Initializing qmgr library\n");
25     qos_chk_ok_exit(qmgr_init());
26
27     qos_log_debug("Setting predictor\n");
28     /* Defaults to 3 samples and forgetting factor = 1 */
29     qos_chk_ok_exit(qmgr_set_predictor(QMGR_PRED_PERC));
30
31     qos_log_debug("Setting sample size to %d\n", SAMPLE_SZ);
32     /* Sets sample size */
33     qos_chk_ok_exit(percpred_set_sample_size(SAMPLE_SZ));
34
35     qos_log_debug("Setting discarded to %d\n", DISCARDED);
36     /* Sets discarded */
37     qos_chk_ok_exit(percpred_set_discarded(DISCARDED));
38
39     qos_log_debug("Setting controller\n");
40     /* Defaults to null target s.e. */
41     qos_chk_ok_exit(qmgr_set_controller(QMGR_CTRL_STOCHDB));
42
43     qos_log_debug("Setting controller parameters\n");
44     /* Assign task period and granularity */
45     qmgr_set_task_period(TASK_PERIOD);
46     qmgr_set_server_period(SERV_PERIOD);
47     qmgr_set_max_bandwidth(0.95);
48
49     qos_log_debug("Starting control loop");
50     qos_chk_ok_exit(qmgr_start());
51   }
52
53   qos_chk_ok_exit(qmgr_begin_cycle());
54   start_time = t;
55   start_time1 = av_gettime();
56 }
57
58 void rt_job_end(void)
59 {
60   uint64_t t;
61   qres_time_t sched_err;
62
63   t = av_gettime();
64   qos_log_debug("%lu %lu %lu\t%lu %lu\n", start_time, start_time1, t, t - start_time, t - start_time1);
65
66   qmgr_end_cycle(&sched_err);
67   qos_log_debug("Ending job: " QRES_TIME_FMT "\n", sched_err);
68 }