aboutsummaryrefslogtreecommitdiffstats
path: root/bin/mode_test.c
blob: 8bdf21bbfe5cb4baa03d6e02f4e0fb3aff783f0a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include "litmus.h"

#define US_PER_MS 1000

int  prefix(void) 
{
	char field[1024];
	int prefix[1024];
	int i, sum = 0;

	for (i = 0; i < 1024; i++) {
		sum += field[i];
		prefix[i] = sum;
	}
	return sum;
}

void do_stuff(void)
{
	int i =0, j =0;

	for (; i < 50000; i++)
		j += prefix();
}

#define CALL(sc) do { ret = sc; if (ret == -1) {perror(" (!!) " #sc " failed"); /*exit(1)*/;}} while (0);

unsigned int job_no;

void next(void)
{
	int ret;
	unsigned int actual;
	CALL(get_job_no(&actual));
	CALL(wait_for_job_release(++job_no));
	printf("Now executing job %u, waited for %u\n", actual, job_no);
}

int main(int argc, char** argv) 
{
	int ret;

	init_litmus();

	CALL(getpid());
	printf("my pid is %d\n", ret);


	CALL(get_job_no(&job_no));
	printf("my job_no is %u", job_no);	

	CALL( task_mode(LITMUS_RT_TASK) );

	CALL( sporadic_global(3, 33) );

	CALL( task_mode(LITMUS_RT_TASK) );	

	next();
	do_stuff();

	next();
	do_stuff();

	next();
	do_stuff();

	CALL( task_mode(BACKGROUND_TASK) );
	
	do_stuff();
	do_stuff();
	do_stuff();
	do_stuff();
	do_stuff();

	CALL( task_mode(LITMUS_RT_TASK) );

	do_stuff();
	do_stuff();
	do_stuff();
	do_stuff();
	do_stuff();


	next();
	next();
	next();
	next();
	next();
	next();
	next();


	next();
	do_stuff();

	next();
	do_stuff();

	next();
	do_stuff();

	CALL( task_mode(BACKGROUND_TASK) );	
	printf("Exiting...\n");

	return 0;	
}