aboutsummaryrefslogtreecommitdiffstats
path: root/src/task.c
blob: 7cfa6cede681f3155ba9124bcc21a706d58038df (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
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

#include "litmus.h"
#include "internal.h"

static void tperrorx(char* msg) 
{
	fprintf(stderr, 
		"Task %d: %s: %m",
		getpid(), msg);
	exit(-1);
}

/* common launch routine */
int __launch_rt_task(rt_fn_t rt_prog, void *rt_arg, rt_setup_fn_t setup, 
		     void* setup_arg) 
{
	int ret;
	int rt_task = fork();

	if (rt_task == 0) {
		/* we are the real-time task 
		 * launch task and die when it is done
		 */		
		rt_task = getpid();		
		ret = setup(rt_task, setup_arg);
		if (ret < 0)
			tperrorx("could not setup task parameters");
		ret = task_mode(LITMUS_RT_TASK);
		if (ret < 0)
			tperrorx("could not become real-time task");
		exit(rt_prog(rt_arg));
	}

	return rt_task;
}

int __create_rt_task(rt_fn_t rt_prog, void *arg, int cpu, int wcet, int period,
		     task_class_t class) 
{
	struct rt_task params;
	params.cpu = cpu;
	params.period = period;
	params.exec_cost = wcet;
	params.cls = class;
	return __launch_rt_task(rt_prog, arg, 
				(rt_setup_fn_t) set_rt_task_param, &params);
}

int create_rt_task(rt_fn_t rt_prog, void *arg, int cpu, int wcet, int period) {
	return __create_rt_task(rt_prog, arg, cpu, wcet, period, RT_CLASS_HARD);
}