aboutsummaryrefslogtreecommitdiffstats
path: root/litmus/pgm.c
diff options
context:
space:
mode:
authorNamhoon Kim <namhoonk@cs.unc.edu>2016-04-30 19:46:44 -0400
committerNamhoon Kim <namhoonk@cs.unc.edu>2016-04-30 19:46:44 -0400
commitfc35ca6c9592d43b067a45c49f98cf4b5b361b87 (patch)
tree9a7d7d6eec9ea24bea317de137cc0431ff54cb8b /litmus/pgm.c
parentf0e07f0e5cba027377c57e1aa25101023640c62b (diff)
PGM supportwip-mc2-new
Diffstat (limited to 'litmus/pgm.c')
-rw-r--r--litmus/pgm.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/litmus/pgm.c b/litmus/pgm.c
new file mode 100644
index 000000000000..db3378ff803d
--- /dev/null
+++ b/litmus/pgm.c
@@ -0,0 +1,61 @@
1/* litmus/pgm.c - common pgm control code
2 */
3
4#include <linux/sched.h>
5#include <litmus/litmus.h>
6#include <litmus/pgm.h>
7#include <litmus/sched_trace.h>
8
9/* Only readjust release/deadline if difference is over a given threshold.
10 It's a weak method for accounting overheads. Ideally, we'd know the last
11 time t was woken up by its last predecessor, rather than having to look
12 at 'now'. Adjustment threshold currently set to 200us. */
13#define ADJUSTMENT_THRESH_NS (200*1000LL)
14
15int setup_pgm_release(struct task_struct* t)
16{
17 int shifted_release = 0;
18
19 /* approximate time last predecessor gave us tokens */
20 lt_t now = litmus_clock();
21
22 TRACE_TASK(t, "is starting a new PGM job: waiting:%d\n",
23 tsk_rt(t)->ctrl_page->pgm_waiting);
24
25 BUG_ON(!tsk_rt(t)->ctrl_page->pgm_waiting);
26
27 /* Adjust release time if we got the last tokens after release of this job.
28 This is possible since PGM jobs are early-released. Don't shift our
29 deadline if we got the tokens earlier than expected. */
30 if (now > tsk_rt(t)->job_params.release) {
31 long long diff_ns = now - tsk_rt(t)->job_params.release;
32 if (diff_ns > ADJUSTMENT_THRESH_NS) {
33 lt_t adj_deadline = now + get_rt_relative_deadline(t);
34
35 TRACE_TASK(t, "adjusting PGM release time from (r = %llu, d = %llu) "
36 "to (r = %llu, d = %llu)\n",
37 tsk_rt(t)->job_params.release, tsk_rt(t)->job_params.deadline,
38 now, adj_deadline);
39
40 tsk_rt(t)->job_params.release = now;
41 tsk_rt(t)->job_params.deadline = adj_deadline;
42 shifted_release = 1;
43 }
44 else {
45 TRACE_TASK(t, "adjustment falls below threshold. %lld < %lld\n",
46 diff_ns, ADJUSTMENT_THRESH_NS);
47 }
48 }
49 else {
50 TRACE_TASK(t, "got tokens early--no need to adjust release. "
51 "cur time = %llu, release time = %llu\n",
52 now, tsk_rt(t)->job_params.release);
53 }
54
55 /* possible that there can be multiple instances of pgm_release logged.
56 analysis tools should filter out all but the last pgm_release for
57 a given job release */
58 sched_trace_pgm_release(t);
59
60 return shifted_release;
61}