This repository has been archived by the owner on Oct 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
95 lines (70 loc) · 2.75 KB
/
main.c
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
#include "main.h"
/*global vars*/
cst_config *config;
int main(int argc, char* argv[]){
extern int errno;
int i = 0, command = 0;
unsigned long cookie;
checkRoot();
if((config = loadConfiguration(argc, argv))==NULL){
printHelp();
exit(EXIT_FAILURE);
}
//ckeck that no error returns from prctl() to ensure that CORE SCHEDULING returns no errors
if(prctl(PR_SCHED_CORE, PR_SCHED_CORE_GET, getpid(), 0, &cookie) == -1)
handlePrctlError();
/*
Since an api that allows to directly push a cookie to a certain task i not available,
Firstly tis program must be added to the target core scheduling group, and
then add the <list of task id> tasks to the group
*/
switch (config->cmd)
{
case CREATE_GROUP:
prctl(PR_SCHED_CORE, PR_SCHED_CORE_CREATE, getpid(), config->coreScope, NULL);
pushCookie();
break;
case ADD_TASK_TO_GROUP:
prctl(PR_SCHED_CORE, PR_SCHED_CORE_SHARE_FROM, config->shareFromTask , config->coreScope, NULL);
pushCookie();
break;
case CLEAR_TASK:
pushCookie();
break;
case PEEK_TASK:
printf("Task\tCookie\n");
for(i=0;i<config->numberOfTask;i++){
prctl(PR_SCHED_CORE, PR_SCHED_CORE_GET, config->listOfTask[i] , config->coreScope, &cookie);
printf("[%d]\t[%lu]\n", config->listOfTask[i], cookie);
}
printf("\n");
break;
case EXEC_TASK:
//if a cookie has already been set for another task, i will not set another cookie
//and i will be using the one already created so that the new task will run in core scheduling
//with the others
prctl(PR_SCHED_CORE, PR_SCHED_CORE_GET, getpid() , config->coreScope, &cookie);
if(cookie == 0) //if cookie is not set, i set a new cookie
prctl(PR_SCHED_CORE, PR_SCHED_CORE_CREATE, getpid(), config->coreScope, NULL);
if(config->verbose){
prctl(PR_SCHED_CORE, PR_SCHED_CORE_GET, getpid() , config->coreScope, &cookie);
printf("Setting core scheduling and executing program: %s\n", argv[config->execPosition]);
printf("Task id \tCookie\n[%d] \t[%lu]\n\n", getpid(), cookie);
}
//execute the new exec_task
execvp(argv[config->execPosition], argv+config->execPosition );
printf("Error: unable to start program!\nError is: %s\n", strerror(errno));
exit(EXIT_FAILURE);
break;
default:
printf("Error: unknown prctl command\n");
printConfiguration(config);
exit(EXIT_FAILURE);
break;
}
if(config->verbose){
printConfiguration(config);
printCookies(config);
}
exit(EXIT_SUCCESS);
}