aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNamhoon Kim <namhoonk@cs.unc.edu>2017-04-07 06:13:06 -0400
committerNamhoon Kim <namhoonk@cs.unc.edu>2017-04-07 06:13:06 -0400
commitab5ac836a257786daa953edb99435b19024ca971 (patch)
tree5bf00b752e9d77e3698f7097514636c20a522141
parent7789dbd53b8bd1bc1546fa0261df5b1d1cd1bd48 (diff)
Added mode 0 reservation for all tasks
-rw-r--r--include/litmus/reservation.h1
-rw-r--r--kernel/sched/litmus.c5
-rw-r--r--litmus/litmus.c8
-rw-r--r--litmus/polling_reservations.c6
-rw-r--r--litmus/reservation.c2
-rw-r--r--litmus/sched_mc2.c174
6 files changed, 162 insertions, 34 deletions
diff --git a/include/litmus/reservation.h b/include/litmus/reservation.h
index 3c54ce0f0545..ee3aac23c4eb 100644
--- a/include/litmus/reservation.h
+++ b/include/litmus/reservation.h
@@ -137,6 +137,7 @@ struct reservation {
137 137
138 /* for mode change */ 138 /* for mode change */
139 int reported; 139 int reported;
140 int mode;
140 //under mc2 assume only 1 task per reservation 141 //under mc2 assume only 1 task per reservation
141 //multiple reservation per task 142 //multiple reservation per task
142 struct task_struct *tsk; 143 struct task_struct *tsk;
diff --git a/kernel/sched/litmus.c b/kernel/sched/litmus.c
index 9d58690cf51a..60be718b36d3 100644
--- a/kernel/sched/litmus.c
+++ b/kernel/sched/litmus.c
@@ -20,8 +20,9 @@ static void update_time_litmus(struct rq *rq, struct task_struct *p)
20 /* task counter */ 20 /* task counter */
21 p->se.sum_exec_runtime += delta; 21 p->se.sum_exec_runtime += delta;
22 if (delta) { 22 if (delta) {
23 TRACE_TASK(p, "charged %llu exec time (total:%llu, rem:%llu)\n", 23 //TRACE_TASK(p, "charged %llu exec time (total:%llu, rem:%llu)\n",
24 delta, p->rt_param.job_params.exec_time, budget_remaining(p)); 24 // delta, p->rt_param.job_params.exec_time, budget_remaining(p));
25 ;
25 } 26 }
26 /* sched_clock() */ 27 /* sched_clock() */
27 p->se.exec_start = rq->clock; 28 p->se.exec_start = rq->clock;
diff --git a/litmus/litmus.c b/litmus/litmus.c
index 3cf784b19034..7fccc585dedd 100644
--- a/litmus/litmus.c
+++ b/litmus/litmus.c
@@ -374,7 +374,7 @@ asmlinkage long sys_set_page_color(int cpu)
374 374
375 //down_read(&current->mm->mmap_sem); 375 //down_read(&current->mm->mmap_sem);
376 down_read(&mm->mmap_sem); 376 down_read(&mm->mmap_sem);
377 TRACE_TASK(current, "SYSCALL set_page_color\n"); 377 //TRACE_TASK(current, "SYSCALL set_page_color\n");
378 vma_itr = mm->mmap; 378 vma_itr = mm->mmap;
379 while (vma_itr != NULL) { 379 while (vma_itr != NULL) {
380 unsigned int num_pages = 0, i; 380 unsigned int num_pages = 0, i;
@@ -399,7 +399,7 @@ asmlinkage long sys_set_page_color(int cpu)
399 continue; 399 continue;
400 } 400 }
401 401
402 TRACE_TASK(current, "addr: %08x, pfn: %x, _mapcount: %d, _count: %d\n", vma_itr->vm_start + PAGE_SIZE*i, __page_to_pfn(old_page), page_mapcount(old_page), page_count(old_page)); 402 //TRACE_TASK(current, "addr: %08x, pfn: %x, _mapcount: %d, _count: %d\n", vma_itr->vm_start + PAGE_SIZE*i, __page_to_pfn(old_page), page_mapcount(old_page), page_count(old_page));
403 403
404 //if (page_mapcount(old_page) == 1) { 404 //if (page_mapcount(old_page) == 1) {
405 ret = isolate_lru_page(old_page); 405 ret = isolate_lru_page(old_page);
@@ -408,8 +408,8 @@ asmlinkage long sys_set_page_color(int cpu)
408 inc_zone_page_state(old_page, NR_ISOLATED_ANON + !PageSwapBacked(old_page)); 408 inc_zone_page_state(old_page, NR_ISOLATED_ANON + !PageSwapBacked(old_page));
409 nr_pages++; 409 nr_pages++;
410 } else { 410 } else {
411 TRACE_TASK(current, "isolate_lru_page failed\n"); 411 //TRACE_TASK(current, "isolate_lru_page failed\n");
412 TRACE_TASK(current, "page_lru = %d PageLRU = %d\n", page_lru(old_page), PageLRU(old_page)); 412 //TRACE_TASK(current, "page_lru = %d PageLRU = %d\n", page_lru(old_page), PageLRU(old_page));
413 nr_failed++; 413 nr_failed++;
414 } 414 }
415 //printk(KERN_INFO "PRIVATE _mapcount = %d, _count = %d\n", page_mapcount(old_page), page_count(old_page)); 415 //printk(KERN_INFO "PRIVATE _mapcount = %d, _count = %d\n", page_mapcount(old_page), page_count(old_page));
diff --git a/litmus/polling_reservations.c b/litmus/polling_reservations.c
index 4a2fee575127..1cfd09169959 100644
--- a/litmus/polling_reservations.c
+++ b/litmus/polling_reservations.c
@@ -31,9 +31,9 @@ static void periodic_polling_client_arrives(
31 res->next_replenishment = res->env->time_zero + instances * pres->period; 31 res->next_replenishment = res->env->time_zero + instances * pres->period;
32 } 32 }
33 33
34 TRACE("ENV_TIME_ZERO %llu\n", res->env->time_zero); 34 TRACE("ENV_TIME_ZERO %llu in mode %d\n", res->env->time_zero, res->mode);
35 TRACE("pol-res: R%d activate tmp=%llu instances=%llu period=%llu nextrp=%llu cur=%llu\n", 35 TRACE("pol-res: mode %d R%d activate tmp=%llu instances=%llu period=%llu nextrp=%llu cur=%llu\n",
36 res->id, tmp, instances, pres->period, res->next_replenishment, 36 res->mode, res->id, tmp, instances, pres->period, res->next_replenishment,
37 res->env->current_time); 37 res->env->current_time);
38 38
39 res->env->change_state(res->env, res, 39 res->env->change_state(res->env, res,
diff --git a/litmus/reservation.c b/litmus/reservation.c
index a17343efdbae..d288178b9b5f 100644
--- a/litmus/reservation.c
+++ b/litmus/reservation.c
@@ -169,7 +169,7 @@ struct reservation* sup_find_by_id(struct sup_reservation_environment* sup_env,
169 unsigned int id) 169 unsigned int id)
170{ 170{
171 struct reservation *res; 171 struct reservation *res;
172 172 BUG_ON(!sup_env);
173 list_for_each_entry(res, &sup_env->active_reservations, list) { 173 list_for_each_entry(res, &sup_env->active_reservations, list) {
174 if (res->id == id) 174 if (res->id == id)
175 return res; 175 return res;
diff --git a/litmus/sched_mc2.c b/litmus/sched_mc2.c
index 1cb8e56e4ada..b7813ae7d85e 100644
--- a/litmus/sched_mc2.c
+++ b/litmus/sched_mc2.c
@@ -276,7 +276,7 @@ static void task_departs(struct task_struct *tsk, int job_complete)
276 BUG_ON(!is_realtime(tsk)); 276 BUG_ON(!is_realtime(tsk));
277 277
278 for(i = 0; i < NR_MODES; i++){ 278 for(i = 0; i < NR_MODES; i++){
279 if (! in_mode(tsk, i) ) 279 if (! in_mode(tsk, i) && i != 0)
280 continue; 280 continue;
281 res = tinfo->res_info[i].client.reservation; 281 res = tinfo->res_info[i].client.reservation;
282 client = &tinfo->res_info[i].client; 282 client = &tinfo->res_info[i].client;
@@ -329,7 +329,7 @@ static void task_arrives(struct mc2_cpu_state *state, struct task_struct *tsk)
329 TRACE_TASK(tsk, "CLIENT ARRIVES at %llu\n", litmus_clock()); 329 TRACE_TASK(tsk, "CLIENT ARRIVES at %llu\n", litmus_clock());
330 330
331 for(i = 0; i < NR_MODES; i++){ 331 for(i = 0; i < NR_MODES; i++){
332 if (! in_mode(tsk, i) ) 332 if (! in_mode(tsk, i) && i != 0)
333 continue; 333 continue;
334 res = tinfo->res_info[i].client.reservation; 334 res = tinfo->res_info[i].client.reservation;
335 client = &tinfo->res_info[i].client; 335 client = &tinfo->res_info[i].client;
@@ -464,7 +464,7 @@ static void mc2_update_timer_and_unlock(struct mc2_cpu_state *state)
464 * may raise a softirq, which in turn may wake ksoftirqd. */ 464 * may raise a softirq, which in turn may wake ksoftirqd. */
465 raw_spin_unlock(&global_lock); 465 raw_spin_unlock(&global_lock);
466 raw_spin_unlock(&state->lock); 466 raw_spin_unlock(&state->lock);
467 467
468 if (update <= now || reschedule[state->cpu]) { 468 if (update <= now || reschedule[state->cpu]) {
469 reschedule[state->cpu] = 0; 469 reschedule[state->cpu] = 0;
470 litmus_reschedule(state->cpu); 470 litmus_reschedule(state->cpu);
@@ -974,6 +974,8 @@ static struct task_struct* mc2_schedule(struct task_struct * prev)
974 974
975 if (!state->scheduled) { 975 if (!state->scheduled) {
976 raw_spin_lock(&global_lock); 976 raw_spin_lock(&global_lock);
977 if (is_realtime(prev))
978 gmp_update_time(_global_env, now);
977 state->scheduled = mc2_global_dispatch(state); 979 state->scheduled = mc2_global_dispatch(state);
978 raw_spin_unlock(&global_lock); 980 raw_spin_unlock(&global_lock);
979 } 981 }
@@ -1012,10 +1014,11 @@ static struct task_struct* mc2_schedule(struct task_struct * prev)
1012 if (prev != state->scheduled && is_realtime(prev)) { 1014 if (prev != state->scheduled && is_realtime(prev)) {
1013 struct mc2_task_state* tinfo = get_mc2_state(prev); 1015 struct mc2_task_state* tinfo = get_mc2_state(prev);
1014 struct reservation* res = tinfo->res_info[mode].client.reservation; 1016 struct reservation* res = tinfo->res_info[mode].client.reservation;
1015 TRACE_TASK(prev, "PREV JOB scheduled_on = P%d\n", res->scheduled_on);
1016 TRACE_TASK(prev, "PREEPT_COUNT %d\n", preempt_count()); 1017 TRACE_TASK(prev, "PREEPT_COUNT %d\n", preempt_count());
1017 if (res) 1018 if (res) {
1019 TRACE_TASK(prev, "PREV JOB was scheduled_on = P%d\n", res->scheduled_on);
1018 res->scheduled_on = NO_CPU; 1020 res->scheduled_on = NO_CPU;
1021 }
1019 TRACE_TASK(prev, "descheduled at %llu.\n", litmus_clock()); 1022 TRACE_TASK(prev, "descheduled at %llu.\n", litmus_clock());
1020 /* if prev is preempted and a global task, find the lowest cpu and reschedule */ 1023 /* if prev is preempted and a global task, find the lowest cpu and reschedule */
1021 if (tinfo->has_departed == false && get_task_crit_level(prev) == CRIT_LEVEL_C) { 1024 if (tinfo->has_departed == false && get_task_crit_level(prev) == CRIT_LEVEL_C) {
@@ -1189,7 +1192,23 @@ static long mc2_admit_task(struct task_struct *tsk)
1189 tinfo->mc2_param.res_id = mp->res_id; 1192 tinfo->mc2_param.res_id = mp->res_id;
1190 tinfo->mc2_param.mode_mask = mp->mode_mask; 1193 tinfo->mc2_param.mode_mask = mp->mode_mask;
1191 TRACE_TASK(tsk, "mode_mask = %x\n", mp->mode_mask); 1194 TRACE_TASK(tsk, "mode_mask = %x\n", mp->mode_mask);
1192 for(i = 0; i < NR_MODES; i++){ 1195
1196 TRACE_TASK(tsk, "Mode 0\n");
1197 res = sup_find_by_id(&(state->sup_env_modes[0]), mp->res_id);
1198
1199 /* found the appropriate reservation */
1200 if (res) {
1201 TRACE_TASK(tsk, "SUP FOUND RES ID in mode 0\n");
1202
1203 /* initial values */
1204 err = err? err:mc2_task_client_init(&tinfo->res_info[0], &tinfo->mc2_param, tsk, res);
1205 }
1206 else {
1207 //failed to find an expected reservation
1208 err = -ESRCH;
1209 }
1210
1211 for(i = 1; i < NR_MODES; i++){
1193 if (!in_mode(tsk, i)){ 1212 if (!in_mode(tsk, i)){
1194 //task not present in mode 1213 //task not present in mode
1195 continue; 1214 continue;
@@ -1199,7 +1218,7 @@ static long mc2_admit_task(struct task_struct *tsk)
1199 1218
1200 /* found the appropriate reservation */ 1219 /* found the appropriate reservation */
1201 if (res) { 1220 if (res) {
1202 TRACE_TASK(tsk, "SUP FOUND RES ID\n"); 1221 TRACE_TASK(tsk, "SUP FOUND RES ID in mode %d\n", i);
1203 1222
1204 /* initial values */ 1223 /* initial values */
1205 err = err? err:mc2_task_client_init(&tinfo->res_info[i], &tinfo->mc2_param, tsk, res); 1224 err = err? err:mc2_task_client_init(&tinfo->res_info[i], &tinfo->mc2_param, tsk, res);
@@ -1234,14 +1253,31 @@ static long mc2_admit_task(struct task_struct *tsk)
1234 tinfo->has_departed = true; 1253 tinfo->has_departed = true;
1235 tinfo->mc2_param.res_id = mp->res_id; 1254 tinfo->mc2_param.res_id = mp->res_id;
1236 tinfo->mc2_param.mode_mask = mp->mode_mask; 1255 tinfo->mc2_param.mode_mask = mp->mode_mask;
1256 TRACE_TASK(tsk, "mode_mask = %x\n", mp->mode_mask);
1257
1258 TRACE_TASK(tsk, "Mode 0\n");
1259 res = gmp_find_by_id(&(_global_env_modes[0]), mp->res_id);
1237 1260
1238 for(i = 0; i < NR_MODES; i++){ 1261 /* found the appropriate reservation */
1239 if (!in_mode(tsk, i)) continue; 1262 if (res) {
1240 res = gmp_find_by_id(_global_env, mp->res_id); 1263 TRACE_TASK(tsk, "GMP FOUND RES ID in mode 0\n");
1264
1265 /* initial values */
1266 err = err? err:mc2_task_client_init(&tinfo->res_info[0], &tinfo->mc2_param, tsk, res);
1267 }
1268 else {
1269 //failed to find an expected reservation
1270 err = -ESRCH;
1271 }
1272
1273 for(i = 1; i < NR_MODES; i++){
1274 if (!in_mode(tsk, i))
1275 continue;
1276 res = gmp_find_by_id(&(_global_env_modes[i]), mp->res_id);
1241 1277
1242 /* found the appropriate reservation (or vCPU) */ 1278 /* found the appropriate reservation (or vCPU) */
1243 if (res) { 1279 if (res) {
1244 TRACE_TASK(tsk, "GMP FOUND RES ID\n"); 1280 TRACE_TASK(tsk, "GMP FOUND RES ID in mode %d\n", i);
1245 1281
1246 /* initial values */ 1282 /* initial values */
1247 err = err? err:mc2_task_client_init(&tinfo->res_info[i], &tinfo->mc2_param, tsk, res); 1283 err = err? err:mc2_task_client_init(&tinfo->res_info[i], &tinfo->mc2_param, tsk, res);
@@ -1323,11 +1359,10 @@ static void mc2_task_new(struct task_struct *tsk, int on_runqueue,
1323 //BUG_ON(!res); 1359 //BUG_ON(!res);
1324 // the current mode doesn't have this task. 1360 // the current mode doesn't have this task.
1325 // do not update timer and set the next release time. 1361 // do not update timer and set the next release time.
1326 if (!res) {
1327
1328 }
1329 1362
1330 //res = res_find_by_id(state, tinfo->mc2_param.res_id); 1363 //res = res_find_by_id(state, tinfo->mc2_param.res_id);
1364 BUG_ON(!res);
1365
1331 release = res->next_replenishment; 1366 release = res->next_replenishment;
1332 1367
1333 if (on_runqueue || is_running) { 1368 if (on_runqueue || is_running) {
@@ -1380,16 +1415,17 @@ static long mc2_reservation_destroy(unsigned int reservation_id, int cpu)
1380 int i; 1415 int i;
1381 1416
1382 if (cpu == -1) { 1417 if (cpu == -1) {
1418 struct next_timer_event *event, *e_next;
1383 local_irq_save(flags); 1419 local_irq_save(flags);
1384 raw_spin_lock(&global_lock); 1420 raw_spin_lock(&global_lock);
1385 1421
1386 /* if the reservation is global reservation */ 1422 /* if the reservation is global reservation */
1387 //state = local_cpu_state(); 1423 //state = local_cpu_state();
1388 //delete reservation id in all modes 1424 //delete reservation id in all modes
1389 for(i = 0; i < NR_MODES; i++){ 1425 for(i = 0; i < NR_MODES; i++) {
1390 //raw_spin_lock(&state->lock); 1426 //raw_spin_lock(&state->lock);
1391 1427
1392 list_for_each_entry_safe(res, next, &_global_env->depleted_reservations, list) { 1428 list_for_each_entry_safe(res, next, &_global_env_modes[i].depleted_reservations, list) {
1393 if (res->id == reservation_id) { 1429 if (res->id == reservation_id) {
1394 list_del(&res->list); 1430 list_del(&res->list);
1395 kfree(res); 1431 kfree(res);
@@ -1398,7 +1434,7 @@ static long mc2_reservation_destroy(unsigned int reservation_id, int cpu)
1398 } 1434 }
1399 } 1435 }
1400 if (!found) { 1436 if (!found) {
1401 list_for_each_entry_safe(res, next, &_global_env->inactive_reservations, list) { 1437 list_for_each_entry_safe(res, next, &_global_env_modes[i].inactive_reservations, list) {
1402 if (res->id == reservation_id) { 1438 if (res->id == reservation_id) {
1403 list_del(&res->list); 1439 list_del(&res->list);
1404 kfree(res); 1440 kfree(res);
@@ -1408,7 +1444,7 @@ static long mc2_reservation_destroy(unsigned int reservation_id, int cpu)
1408 } 1444 }
1409 } 1445 }
1410 if (!found) { 1446 if (!found) {
1411 list_for_each_entry_safe(res, next, &_global_env->active_reservations, list) { 1447 list_for_each_entry_safe(res, next, &_global_env_modes[i].active_reservations, list) {
1412 if (res->id == reservation_id) { 1448 if (res->id == reservation_id) {
1413 list_del(&res->list); 1449 list_del(&res->list);
1414 kfree(res); 1450 kfree(res);
@@ -1419,7 +1455,15 @@ static long mc2_reservation_destroy(unsigned int reservation_id, int cpu)
1419 } 1455 }
1420 1456
1421 //raw_spin_unlock(&state->lock); 1457 //raw_spin_unlock(&state->lock);
1458 list_for_each_entry_safe(event, e_next, &_global_env_modes[i].next_events, list) {
1459 if (event->id == reservation_id) {
1460 list_del(&event->list);
1461 TRACE("EVENT id %d deleted\n", event->id);
1462 kfree(event);
1463 }
1464 }
1422 } 1465 }
1466
1423 raw_spin_unlock(&global_lock); 1467 raw_spin_unlock(&global_lock);
1424 local_irq_restore(flags); 1468 local_irq_restore(flags);
1425 } else { 1469 } else {
@@ -1430,7 +1474,7 @@ static long mc2_reservation_destroy(unsigned int reservation_id, int cpu)
1430 raw_spin_lock(&state->lock); 1474 raw_spin_lock(&state->lock);
1431 1475
1432 // res = sup_find_by_id(state->sup_env, reservation_id); 1476 // res = sup_find_by_id(state->sup_env, reservation_id);
1433 sup_env = state->sup_env; 1477 sup_env = &(state->sup_env_modes[i]);
1434 list_for_each_entry_safe(res, next, &sup_env->depleted_reservations, list) { 1478 list_for_each_entry_safe(res, next, &sup_env->depleted_reservations, list) {
1435 if (res->id == reservation_id) { 1479 if (res->id == reservation_id) {
1436/* 1480/*
@@ -1444,6 +1488,7 @@ static long mc2_reservation_destroy(unsigned int reservation_id, int cpu)
1444 kfree(res); 1488 kfree(res);
1445 found = 1; 1489 found = 1;
1446 ret = 0; 1490 ret = 0;
1491 TRACE_CUR("FOUND id %d mode %d\n",res->id, res->mode);
1447 } 1492 }
1448 } 1493 }
1449 if (!found) { 1494 if (!found) {
@@ -1459,6 +1504,7 @@ static long mc2_reservation_destroy(unsigned int reservation_id, int cpu)
1459 kfree(res); 1504 kfree(res);
1460 found = 1; 1505 found = 1;
1461 ret = 0; 1506 ret = 0;
1507 TRACE_CUR("FOUND id %d mode %d\n",res->id, res->mode);
1462 } 1508 }
1463 } 1509 }
1464 } 1510 }
@@ -1475,6 +1521,7 @@ static long mc2_reservation_destroy(unsigned int reservation_id, int cpu)
1475 kfree(res); 1521 kfree(res);
1476 found = 1; 1522 found = 1;
1477 ret = 0; 1523 ret = 0;
1524 TRACE_CUR("FOUND id %d mode %d\n",res->id, res->mode);
1478 } 1525 }
1479 } 1526 }
1480 } 1527 }
@@ -1594,7 +1641,7 @@ static long create_polling_reservation(
1594 int res_type, 1641 int res_type,
1595 struct reservation_config *config) 1642 struct reservation_config *config)
1596{ 1643{
1597 struct mc2_cpu_state *state; 1644 struct mc2_cpu_state *state = NULL;
1598 //struct reservation* res = NULL; 1645 //struct reservation* res = NULL;
1599 struct polling_reservation *pres; 1646 struct polling_reservation *pres;
1600 unsigned long flags; 1647 unsigned long flags;
@@ -1637,11 +1684,47 @@ static long create_polling_reservation(
1637 if (!pres) 1684 if (!pres)
1638 return -ENOMEM; 1685 return -ENOMEM;
1639 1686
1687 TRACE("CREATE_POLLING_RESERVATION id %d mode %d\n", config->id, config->mode);
1640 if (config->cpu != -1) { 1688 if (config->cpu != -1) {
1641 1689 int i, is_exist = 0;
1642 //raw_spin_lock_irqsave(&_global_env.lock, flags); 1690 //raw_spin_lock_irqsave(&_global_env.lock, flags);
1643 state = cpu_state_for(config->cpu); 1691 state = cpu_state_for(config->cpu);
1644 raw_spin_lock_irqsave(&state->lock, flags); 1692 raw_spin_lock_irqsave(&state->lock, flags);
1693
1694 /* check if it is the first creation of reservartion */
1695 for (i = 0; i < NR_MODES; i++) {
1696 if( sup_find_by_id(&(state->sup_env_modes[i]), config->id) )
1697 is_exist = 1;
1698 }
1699 if (!is_exist && config->mode != 0) {
1700 /* create mode 0 reservation first */
1701 struct polling_reservation *pres_0 = kzalloc(sizeof(*pres_0), GFP_ATOMIC);
1702
1703 TRACE_CUR("The first mode_num = %d\n",config->mode);
1704
1705 if (!pres_0) {
1706 raw_spin_unlock_irqrestore(&state->lock, flags);
1707 kfree(pres);
1708 return -ENOMEM;
1709 }
1710 polling_reservation_init(pres_0, use_edf, periodic,
1711 config->polling_params.budget,
1712 config->polling_params.period,
1713 config->polling_params.relative_deadline,
1714 config->polling_params.offset);
1715 pres_0->res.id = config->id;
1716 pres_0->res.blocked_by_ghost = 0;
1717 pres_0->res.is_ghost = NO_CPU;
1718 pres_0->res.mode = config->mode;
1719
1720 if (!use_edf)
1721 pres_0->res.priority = config->priority;
1722 sup_add_new_reservation(&(state->sup_env_modes[0]), &pres_0->res);
1723 TRACE_CUR("SUP reservation created R%d for mode 0 priority : %llu\n", config->id, pres_0->res.priority);
1724 pres_0->res.reported = 0;
1725 pres_0->res.tsk = current;
1726 }
1727
1645 //force reservation id unique inside of res_config->mode 1728 //force reservation id unique inside of res_config->mode
1646 if( sup_find_by_id(&(state->sup_env_modes[config->mode]), config->id) ){ 1729 if( sup_find_by_id(&(state->sup_env_modes[config->mode]), config->id) ){
1647 resExist = true; 1730 resExist = true;
@@ -1655,6 +1738,7 @@ static long create_polling_reservation(
1655 pres->res.id = config->id; 1738 pres->res.id = config->id;
1656 pres->res.blocked_by_ghost = 0; 1739 pres->res.blocked_by_ghost = 0;
1657 pres->res.is_ghost = NO_CPU; 1740 pres->res.is_ghost = NO_CPU;
1741 pres->res.mode = config->mode;
1658 /*if (config->priority == LITMUS_MAX_PRIORITY) { 1742 /*if (config->priority == LITMUS_MAX_PRIORITY) {
1659 level_a_priorities[config->cpu]++; 1743 level_a_priorities[config->cpu]++;
1660 pres->res.priority = level_a_priorities[config->cpu]; 1744 pres->res.priority = level_a_priorities[config->cpu];
@@ -1663,7 +1747,7 @@ static long create_polling_reservation(
1663 pres->res.priority = config->priority; 1747 pres->res.priority = config->priority;
1664 sup_add_new_reservation(&(state->sup_env_modes[config->mode]), &pres->res); 1748 sup_add_new_reservation(&(state->sup_env_modes[config->mode]), &pres->res);
1665 err = config->id; 1749 err = config->id;
1666 TRACE_CUR("reservation created R%d for mode %d priority : %llu\n", config->id, config->mode, pres->res.priority); 1750 TRACE_CUR("SUP reservation created R%d for mode %d priority : %llu\n", config->id, config->mode, pres->res.priority);
1667 } else { 1751 } else {
1668 err = -EEXIST; 1752 err = -EEXIST;
1669 } 1753 }
@@ -1672,8 +1756,45 @@ static long create_polling_reservation(
1672 //raw_spin_unlock_irqrestore(&_global_env.lock, flags); 1756 //raw_spin_unlock_irqrestore(&_global_env.lock, flags);
1673 1757
1674 } else { 1758 } else {
1759 int i, is_exist = 0;
1675 raw_spin_lock_irqsave(&global_lock, flags); 1760 raw_spin_lock_irqsave(&global_lock, flags);
1676 1761
1762 /* check if it is the first creation of reservartion */
1763 for (i = 0; i < NR_MODES; i++) {
1764 if(gmp_find_by_id(&(_global_env_modes[i]), config->id))
1765 is_exist = 1;
1766 }
1767 if (!is_exist && config->mode != 0) {
1768 /* create mode 0 reservation first */
1769 struct polling_reservation *pres_0 = kzalloc(sizeof(*pres_0), GFP_ATOMIC);
1770
1771 TRACE_CUR("The first mode_num = %d\n",config->mode);
1772
1773 if (!pres_0) {
1774 raw_spin_unlock_irqrestore(&global_lock, flags);
1775 kfree(pres);
1776 return -ENOMEM;
1777 }
1778 polling_reservation_init(pres_0, use_edf, periodic,
1779 config->polling_params.budget,
1780 config->polling_params.period,
1781 config->polling_params.relative_deadline,
1782 config->polling_params.offset);
1783 pres_0->res.id = config->id;
1784 pres_0->res.blocked_by_ghost = 0;
1785 pres_0->res.scheduled_on = NO_CPU;
1786 pres_0->res.is_ghost = NO_CPU;
1787 pres_0->res.mode = config->mode;
1788
1789 if (!use_edf)
1790 pres_0->res.priority = config->priority;
1791 gmp_add_new_reservation(&(_global_env_modes[0]), &pres_0->res);
1792 TRACE_CUR("GMP reservation created R%d for mode 0 priority : %llu\n", config->id, pres_0->res.priority);
1793 pres_0->res.reported = 0;
1794 pres_0->res.tsk = current;
1795 }
1796
1797
1677 //force id's unique within desired mode 1798 //force id's unique within desired mode
1678 if (gmp_find_by_id(&(_global_env_modes[config->mode]), config->id)){ 1799 if (gmp_find_by_id(&(_global_env_modes[config->mode]), config->id)){
1679 resExist = true; 1800 resExist = true;
@@ -1688,9 +1809,11 @@ static long create_polling_reservation(
1688 pres->res.blocked_by_ghost = 0; 1809 pres->res.blocked_by_ghost = 0;
1689 pres->res.scheduled_on = NO_CPU; 1810 pres->res.scheduled_on = NO_CPU;
1690 pres->res.is_ghost = NO_CPU; 1811 pres->res.is_ghost = NO_CPU;
1812 pres->res.mode = config->mode;
1691 if (!use_edf) 1813 if (!use_edf)
1692 pres->res.priority = config->priority; 1814 pres->res.priority = config->priority;
1693 gmp_add_new_reservation(&(_global_env_modes[config->mode]), &pres->res); 1815 gmp_add_new_reservation(&(_global_env_modes[config->mode]), &pres->res);
1816 TRACE_CUR("GMP reservation created R%d for mode %d priority : %llu\n", config->id, config->mode, pres->res.priority);
1694 err = config->id; 1817 err = config->id;
1695 } else { 1818 } else {
1696 err = -EEXIST; 1819 err = -EEXIST;
@@ -1807,6 +1930,7 @@ static long create_table_driven_reservation(
1807 td_res->res.id = config->id; 1930 td_res->res.id = config->id;
1808 td_res->res.priority = config->priority; 1931 td_res->res.priority = config->priority;
1809 td_res->res.blocked_by_ghost = 0; 1932 td_res->res.blocked_by_ghost = 0;
1933 td_res->res.mode = config->mode;
1810 sup_add_new_reservation(&(state->sup_env_modes[config->mode]), &td_res->res); 1934 sup_add_new_reservation(&(state->sup_env_modes[config->mode]), &td_res->res);
1811 err = config->id; 1935 err = config->id;
1812 } else { 1936 } else {
@@ -1835,10 +1959,12 @@ static long mc2_reservation_create(int res_type, void* __user _config)
1835 struct reservation_config config; 1959 struct reservation_config config;
1836 1960
1837 TRACE("Attempt to create reservation (%d)\n", res_type); 1961 TRACE("Attempt to create reservation (%d)\n", res_type);
1838 1962
1839 if (copy_from_user(&config, _config, sizeof(config))) 1963 if (copy_from_user(&config, _config, sizeof(config)))
1840 return -EFAULT; 1964 return -EFAULT;
1841 1965
1966 TRACE("Attempt to create reservation id %d mode %d\n", config.id, config.mode);
1967
1842 if (config.cpu != -1) { 1968 if (config.cpu != -1) {
1843 if (config.cpu < 0 || !cpu_online(config.cpu)) { 1969 if (config.cpu < 0 || !cpu_online(config.cpu)) {
1844 printk(KERN_ERR "invalid polling reservation (%u): " 1970 printk(KERN_ERR "invalid polling reservation (%u): "
@@ -2006,7 +2132,7 @@ static long mc2_deactivate_plugin(void)
2006 for(i = 0; i < NR_MODES; i++){ 2132 for(i = 0; i < NR_MODES; i++){
2007 /* Delete all reservations --- assumes struct reservation 2133 /* Delete all reservations --- assumes struct reservation
2008 * is prefix of containing struct. */ 2134 * is prefix of containing struct. */
2009 state->sup_env = &state->sup_env_modes[i]; 2135 state->sup_env = &(state->sup_env_modes[i]);
2010 while (!list_empty(&state->sup_env->active_reservations)) { 2136 while (!list_empty(&state->sup_env->active_reservations)) {
2011 res = list_first_entry( 2137 res = list_first_entry(
2012 &state->sup_env->active_reservations, 2138 &state->sup_env->active_reservations,