Skip to content

Commit

Permalink
Modified scheduling decision to be constant time in Patmos
Browse files Browse the repository at this point in the history
  • Loading branch information
mziccard committed Jul 28, 2014
1 parent cfa1a80 commit 6db41c4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
34 changes: 26 additions & 8 deletions kernel/core/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
#endif

#include <dependencies.h>
#include <stdio.h>

#ifdef POK_ARCH_PATMOS
#ifdef POK_NEEDS_DEBUG
Expand Down Expand Up @@ -113,6 +114,7 @@ uint32_t prev_current_thread;
pok_sched_t pok_global_sched;
uint64_t pok_sched_next_deadline;
uint64_t pok_sched_next_major_frame;
uint64_t pok_sched_next_major_frame_stub;
int pok_sched_current_slot = 0; /* Which slot are we executing at this time ?*/
uint32_t current_thread = KERNEL_THREAD;

Expand Down Expand Up @@ -396,19 +398,23 @@ uint8_t pok_sched_get_priority_max (const pok_sched_t sched_type)
/* Elects next partition to be executed */
pok_partition_t* pok_elect_partition(uint64_t time)
{
pok_bool_t switched = FALSE;
uint64_t now = time;
/* End of the curently executing partition slot */

pok_sched_current_slot = (pok_sched_current_slot + 1) % POK_CONFIG_SCHEDULING_NBSLOTS;
int pok_sched_current_slot_tmp = pok_sched_current_slot + 1;
if (pok_sched_current_slot_tmp < POK_CONFIG_SCHEDULING_NBSLOTS) {
pok_sched_current_slot = pok_sched_current_slot_tmp;
} else {
pok_sched_current_slot = 0;
}
//pok_sched_current_slot = (pok_sched_current_slot + 1) % POK_CONFIG_SCHEDULING_NBSLOTS;

if (pok_sched_next_major_frame <= now)
{
switched = TRUE;
pok_sched_next_major_frame = pok_sched_next_major_frame + POK_CONFIG_SCHEDULING_MAJOR_FRAME;
#ifdef POK_NEEDS_SCHED_O1
start_of_MAF = now;
#endif

#ifdef POK_NEEDS_DEBUG_O1
printf("[DEBUG_O1]\t pok_sched_next_major_frame %d\n", pok_sched_next_major_frame);
#endif
Expand All @@ -417,11 +423,18 @@ pok_partition_t* pok_elect_partition(uint64_t time)
// Convey data from SOURCE ports to DESTINATION ports
pok_port_flushall();
#endif
}

} else {

#ifdef POK_NEEDS_SCHED_O1
start_of_MAF_stub = now;
#endif
}

/* Sets the next partition switch instant */
pok_sched_next_deadline = pok_sched_next_deadline + pok_sched_slots[pok_sched_current_slot];


#ifdef POK_NEEDS_DEBUG
printf("[DEBUG]\t Slot number %d\n", pok_sched_current_slot);
printf("[DEBUG]\t Switch from partition %d to partition %d\n", pok_current_partition, pok_sched_slots_allocation[pok_sched_current_slot]);
Expand All @@ -435,6 +448,8 @@ pok_partition_t* pok_elect_partition(uint64_t time)

// set the current activation time of the partition -- used to calculate the process first release point
pok_partitions[pok_current_partition].activation = now; // i.e. POK_GETTICK();


#ifdef POK_NEEDS_DEBUG_O1
printf("[DEBUG_O1]\t Slot: %d, Current partition: %d\n", pok_sched_current_slot,pok_current_partition);
printf("[DEBUG_O1]\t Setting partition %d activation to ", pok_current_partition);print_long(now);printf("\n");
Expand All @@ -447,6 +462,7 @@ pok_partition_t* pok_elect_partition(uint64_t time)


#ifdef POK_NEEDS_SCHED_O1
// COMMENTED OUT TO CHECK WHY PARTITION SWITCH ET VARIATE
// Reorder asynch events of the partition and activate those that have timed out
pok_sched_reorder_asynch_list();
pok_sched_service_asynch_events();
Expand Down Expand Up @@ -500,6 +516,7 @@ uint32_t pok_elect_thread (pok_partition_t* current_partition, uint64_t now)
// ********************* O1 SCHEDULER ***********************************************
#ifdef POK_NEEDS_SCHED_O1
moment = now - start_of_MAF + 1;
start_of_MAF_stub = 0;
#ifdef POK_NEEDS_DEBUG_O1
printf("[DEBUG_O1]\t Thread switch!\n");
printf("[DEBUG_O1]\t Now: "); print_long(now); printf("\n");
Expand Down Expand Up @@ -611,7 +628,7 @@ void pok_sched()
pok_arch_cache_enable();
#endif

/* manage POSTWRITE */
/// manage POSTWRITE
if (next_subslot_postwrite)
{
#ifdef POK_NEEDS_DEBUG_O1
Expand Down Expand Up @@ -755,7 +772,7 @@ void pok_sched_partition_switch (const uint32_t elected_id)
current_sp = &POK_CURRENT_THREAD.sp;
new_sp = pok_threads[elected_id].sp;
#endif

/*
if (POK_SCHED_CURRENT_THREAD == elected_id)
{
#ifdef POK_NEEDS_DEBUG
Expand All @@ -771,7 +788,7 @@ void pok_sched_partition_switch (const uint32_t elected_id)
return;
}
/* FIXME : current debug session about exceptions-handled */
// FIXME : current debug session about exceptions-handled
#ifdef POK_NEEDS_DEBUG
#ifndef POK_ARCH_PATMOS
printf("[DEBUG]\t Switch from thread %d, sp: 0x%x\n", POK_SCHED_CURRENT_THREAD, current_sp);
Expand All @@ -787,6 +804,7 @@ void pok_sched_partition_switch (const uint32_t elected_id)
// Switch from one partition to another
pok_space_switch(POK_CURRENT_THREAD.partition, pok_threads[elected_id].partition);
#endif
*/
// Update current thread id now
current_thread = elected_id;
#ifdef POK_ARCH_PATMOS
Expand Down
1 change: 1 addition & 0 deletions kernel/include/core/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ void pok_sched_activate_error_thread (void);
#ifdef POK_NEEDS_SCHED_O1
unsigned int masks[POK_CONFIG_SCHEDULING_MAJOR_FRAME][POK_STATE_T_NR_ELEMENTS]; //32-bits mask for each partition
uint64_t start_of_MAF;
uint64_t start_of_MAF_stub;
extern uint32_t pok_thread_ids_to_pos_map[POK_CONFIG_NB_THREADS];
// inclusions from timer.c
extern unsigned int time_inter;
Expand Down

0 comments on commit 6db41c4

Please sign in to comment.