Tips for Programming Assignment #1 by latenightwaitress

VIEWS: 14 PAGES: 13

									            Tips for Programming
               Assignment #1




1/17/2009      Introduction to Real-Time Embedded Systems   1
                Requirements
• Measure success ratio, deadline miss ratio &
  QoS level for different loads = 0.4, 0.6, 0.8,
  ..., 1.8, 2.0 for three different approaches
    – Simple EDF & RMS without admission control or
      QoS degradation
    – EDF & RMS + admission control
    – EDF & RMS + admission control + QoS degradation
      (e.g., imprecise computation)
    – Run 10 simulations using different seed numbers
      for each load and take the average success ratio,
      miss ratio & QoS level for every approach
      described above
1/17/2009        Introduction to Real-Time Embedded Systems   2
     Time-Driven vs. Event-Driven
             Simulation
• Time-Driven
    – for (usnigned int t=1; t=600000; t++)
      {
      Do something at time t;
      t++;
      }
    – Easy but slow


1/17/2009      Introduction to Real-Time Embedded Systems   3
     Time-Driven vs. Event-Driven
             Simulation
• Event-Driven
• Fast
    – Process the current event
    – Skip to the next event
    – Most professional simulators are event-driven
• More difficult
    – Should be careful to properly manage the event
      queue
• For this assignment, you can do time-driven
  simulation (Extra credit if you successfully
  implement an event-driven simulator)

1/17/2009        Introduction to Real-Time Embedded Systems   4
                               Overall structure
int main(char *argv, int argc)
{
if (argc < NUM_ARGS) cout << “error”; exit(-1);
/* argv[0] -> EDF or RMS */
/* argv[1] -> estErr (execution time estimation error); removed from PA #1 */
/* argv[2] -> turn on/off QoS degradation */
/* argv[3] -> load */
for (unsigned int i=0; i<NUM_SIMULATIONS; i++)
{
     for (unsigned int t=0; t<MAX_TIME; t++) /* one simulation run */
     { /* Use a different seed number for each simulation run */
     bool generated = generae_source(t,load);
     if (generated) admission_control(num_tasks);
     generate_jobs(t);
     schedule();
     dispatch();
     step_run();
     collect_statistics(); /* #submitted, #admitted, #timely, QoS */
     }
cout << “Scheduling algorithm = ” << /* print EDF or RMS accoding to argv[0] */ << endl;
cout << “estErr = “ << argv[1] << endl;
cout << “QoS = “ << /* average QoS in [0,1] */ << endl;
cout << “Load = “ << argv[3] << endl;
cout << “success ratio = “ << #timely / #submitted << endl;
cout << “deadline miss ratio = “ << (#admitted - #timely) / #admitted << endl;
clean_up();
}
1/17/2009                       Introduction to Real-Time Embedded Systems                 5
               Skeletion of class source()
#define MIN_EXEC_TIME 5 //5ms
#define MAX_EXEC_TIME 20 //20ms
#define MIN_PERIOD 20
#define MAX_PERIOD 500
#define MAX_SOURCES
class source()
{
int task_id;
bool admitted; //admitted or not
int next_job_arrival_time;
int exec_time;
int period; //relative deadline = period
float u; //utilization
int qos; //1 = high, 0.5 = low
}
source *s[MAX_SOURCES];
#define AVERAGE_TASK_INTER_ARRIVAL_TIME
int num_tasks = 0;

//Use newran random number generator to create Poisson & uniform distributions
Poisson P(AVERAGE_TASK_INTER_ARRIVAL_TIME);
Uniform Unif();
1/17/2009               Introduction to Real-Time Embedded Systems               6
     generate_source(t, load): Generate a priodic task
u_total = 0.0; //total utilization
for (unsigned int t=0; t<MAX_TIME; t++) /* one simulation run */
{
next_task_arrival_time = t + (int) P.Next();
if (t == next_task_arrival_time) generate_source(t, load);
.......
}

bool generate_source(t, load)
{
s[num_tasks] = new source();
s[num_tasks]->exec_time = (unsigned int) (MIN_EXEC_TIME + Unif.Next() *
                                (MAX_EXEC_TIME – MIN_EXEC_TIME));
s[num_tasks]->period = (unsigned int) (MIN_PERIOD + Unif.Next()*(MAX_PERIOD –
                                MIN_PERIOD))
s[num_tasks]->u = s[num_tasks]->exec_time / s[num_tasks]->period;
if (u_total + s[num_tasks]->u > load)
     //Delete this task and return false
else
     {
     s[num_tasks]-> next_job_arrival_time = t;
     num_tasks++;
     return true;
     }
}

1/17/2009                 Introduction to Real-Time Embedded Systems            7
               generate_jobs(t)
void generate_jobs(t)
{
for (int i=0; i<=num_tasks; i++)
   {
   if (s[i]->admitted && s[i]-> next_job_arrival_time == t)
         {
         // Generate a job with s[i]->period,
         // s[i]->exec_time, etc. and insert it
         // into the ready queue
         s[i]-> next_job_arrival_time = t + s[i]->period;
         }
   }
}


1/17/2009           Introduction to Real-Time Embedded Systems   8
            admission_control()

void admission_control(unsigned int
  source_id)
{
if (u_total + s[source_id] <= U_BOUND)
  admit(source_id);
else
   degrade_qos(source_id);
}
1/17/2009    Introduction to Real-Time Embedded Systems   9
        admit(sid) & degrade(sid)
void admit(unsigned int sid)
{
s[sid]->admitted = true;
}

void degrade_qos(unsigned int sid)
{
if (u_total + 0.5 * s[sid]->u <= U_BOUND) //imprecise computation
     {
     s[sid]->qos = LOW;
     s[sid]->exec_time = 0.5 * s[sid]->exec_time;
     s[sid]->u = 0.5 * s[sid]->u;
     admit(sid);
     return;
     }
else
{
     /* Degrade the QoS of the tasks already in the system to admit the new task sid */
     /* Stop degradation, admit task sid, and return if the new U_total <= U_BOUND */
}
s[sid]->admitted = false; /* Reject task sid; you cannot admit it even after degrading all
     the tasks in the system */
}
1/17/2009                      Introduction to Real-Time Embedded Systems                10
                schedule()
void schedule()
{
// sort the ready queue according to
// the selected scheduling algorithm, i.e.,
// EDF or RM
}


1/17/2009    Introduction to Real-Time Embedded Systems   11
            dispatch() & step_run()
job *dispatch()
{
/* return the highest priority job amog the currently running task
   and the tasks in the ready queue */
}

step_run(unsigned int t, job *highest)
{
highest->exec_time--;
if (highest->exec_time == 0)
    if (its deadline <= t) #timely++;
    /* continue to run a job even if its deadline is missed */
}



1/17/2009            Introduction to Real-Time Embedded Systems      12
            Expected Outcome
• Show the following:
    – No deadline miss for admitted tasks if
      admission control is applied
    – Improved success ratio and degraded QoS
      after applying admission control/imprecise
      computation




1/17/2009      Introduction to Real-Time Embedded Systems   13

								
To top