290 likes | 371 Views
CS523 Operating Systems. Fred Kuhns Applied Research Laboratory Computer Science Washington University. Clock-Driven Approach. With periodic tasks, it is possible to statically determine a schedule: cyclic schedule implemented by a cyclic executive .
E N D
CS523Operating Systems Fred Kuhns Applied Research Laboratory Computer Science Washington University
Clock-Driven Approach • With periodic tasks, it is possible to statically determine a schedule: • cyclic schedule implemented by a cyclic executive. • The cyclic schedule is a table listing jobs and their start times (aka decision time). Each job scheduled as a unit and is non-preemptable. • Job may be function call, block of instructions, portion of procedure. • Cyclic schedule (Table) defines a block of repeatable scheduling decisions where all deadlines and periods are met - Major Cycle. • Timing decisions made only at frame boundaries. CS523 – Operating Systems
Table (Cyclic Schedule) t1 ... tn T(t1) ... T(tn) Example Timer-Driven Schedule int MajorCycle = 10; int entry=-1; clock_handler () { time_t next_time; current = Table[entry].task; entry = (entry+1) % MajorCycle; next_time= Table[entry].time + gettime(); execute_task(current); if (gettime() > next_time) handle_overload(); set_rtclock (next_time); return; } CS523 – Operating Systems
Creating a Model • Major cycle can be divided into a sequence of fixed sized minor cycles (aka frames). • Scheduling decisions are only made at frame boundaries. • Exact start and completion time of jobs within a frame is not known • but must know the max computation time • Jobs are allocated to specific frames • Major cycle time corresponds to a Hyperperiod. • If a schedule can not be found for the set of predefined jobs then they may need to be divided into job slices. • divide job into a sequence of smaller jobs CS523 – Operating Systems
Model Description • Periodic task model: • N periodic tasks, where N is fixed • Parameters of all periodic tasks known a priori • assume interrelease time jitter negligible • Ji,k (job k of task i) ready at its release timeri,k Major Cycle Minor Cycle (frame) ... T1 T3 T2 T1 T4 T1 T3 T2 fn f2 f1 Cyclic Executive runs in response to tick event, bar shows time to execute scheduler CS523 – Operating Systems
frame 3 frame 4 frame 5 frame 2 Constructing a Schedule Cyclic Schedule • Construct static schedule for a Major Cycle • Cyclic Executive repeats this schedule segment • There may be resulting idle intervals • if so attempt to arrange so they occur periodically • Static table lists frame fkand tasks to run (scheduling block),tasksk f1 tasks1 ... ... f5 tasks5 Task = ( r, e) T1 = ( 4, 1) T2 = ( 5, 1.8) T3 = (20, 1) T4 = (20, 2) H = 20 Major Cycle (Hyperperiod) frame 1 T1 T3 T2 T1 T4 T2 T1 T2 T1 T1 T2 t = 0 4 8 12 16 20 CS523 – Operating Systems
Example Cyclic Executive int MajorCycle = 10; int MinorCycle = 1; int frame=-1; // tick handler, called at start of frame ce_handler() { time_t next_time = 0; // make sure the previous frame is done if (previous execute_scheduler running) handle_overrun(); // error // determine frame and schedule frame = (frame + 1) % MajorCycle; next_time = gettime() + MinorCycle; schedule = CyclicTable[frame].sched; // sequentially run each job in schedule execute_schedule (schedule); // done with this frame return; } execute_schedule (schedule) { job_t job; for each job in schedule execute job return } CS523 – Operating Systems
Partitioning Major Cycles into Frames • Three tasks: • choosing frame size, • partitioning jobs into slices (if needed), • placing jobs/slices into frames. • Frames boundaries (start of frame) cyclic executive performs scheduling, monitoring and enforcement • There is no preemption within frame • Phase of every task integer multiple of frame (j * f) • first job of task starts on frame boundary, phase = j * f. T1 T3 T2 T1 T4 T2 T1 T2 T1 T1 T2 Hyperperiod, Major Cycle CS523 – Operating Systems
Frame Size Constraints • Every job can start and complete within a frame • f ≥ max(ei) for all i such that 1 ≤ i ≤ n • Frame size divides H (the Hyperperiod) • f divides pi for at least one value of i • for a, x and k positive integers; ai · pi = H & x · f = pi k · f = H • Between the release time and deadline of every job there is at least one frame • t + 2f ≤ t’ + Di or 2f - (t' - t) ≤ Di, • but t' - t ≥ gcd(pi, f) • 2f - gcd(pi, f) ≤ Di, if true then 2f - (t' - t) ≤ Di is certainly true. fk fk+1 fk+2 t t' t+f t+2f t+3f t'+Di t'+pi CS523 – Operating Systems
Foreground/Background • Scheduling aperiodic jobs with periodic • Foreground jobs are the usual periodic jobs already discussed • background jobs are aperiodic, • Aperiodic jobs • executed within the idle blocks • Aperiodic jobs are preemptable • May optimize response time by scheduling within schedule slack time (slack stealing). CS523 – Operating Systems
Slack Steeling • Slack time = f – xk where xk is the total time allocated to periodic tasks (task instance is a job) within frame k and f = frame size. • Requirements may include some minimal aperiodic arrival rate • Cyclic Exec executes aperiodic jobs as long as there is slack in the schedule. • Periodic jobs must complete by deadline. CS523 – Operating Systems
Slack Stealing Period Jobs Only Without Slack stealing A2 A3 A1 A2 A3 With Slack stealing A2 A3 A1 A2 A3 CS523 – Operating Systems
Simplifying Precedence Constraints • To accommodate precedence and timing constraints derive a set of effective release times and deadlines • Effective release time: no predecessors then equal to its release time. If predecessors then maximum of its own release time and the effective release times of its predecessor. • Effective deadline: No successor, then equal to its original deadline. Otherwise minimum of its deadline the effective deadlines of its successors. CS523 – Operating Systems
= mean arrival rate Departure Dispatching Service Server Modeling System • Modeling the system for an average response time calculation • Assume M/G/1 queuing model: • Poisson arrival process (exponentially distributed inter-arrival times) • General distribution function for service times • Infinite queue, FIFO dispatch discipline • Single server, single queue • nT = # tasks; λi mean arrival rate and ei mean execution time λ = mean arrival rate, μ = mean service rate, Ts = 1/μ = mean service time ρ= λ/μ= utilization, w = items in Q, Tw = mean waiting time in Q, q = total number of items in system, Tq = Tw + Ts = total time waiting in system CS523 – Operating Systems
Average Response Time ... B1 B2 B3 B4 B5 • View as one large sample space comprised of the individual Task sample spaces (used to calculate average and second moments, E[Bi] and E[Bi2]). • Individual events scale by 1/(1-U): • eAi = Bi/(1-U) CS523 – Operating Systems
(i/ ) · E[Bi]/(1-U) = Ts na na (i/ ) * E[Bi]/(1-U) + W0 / {(1-U)2[( 1 - UA/(1-U)]} i i na i * E[Bi2]/2 = W0 i Average Response Time • Average queuing time inversely proportional to the square of the aperiodic bandwidth (1-U). • Can improve average response of some jobs by using priority queues. Average queuing time increases with variance (E[x**2] = E[x] + Variance[x]) CS523 – Operating Systems
Scheduling Sporadic Jobs • Sporadic jobs • represent as S(d,e): d = deadline, e = execution time • have hard deadlines, • minimum interrelease times and maximum execution time are not known in advance • maximum execution time is known on release • jobs are preemptable • Apply an acceptance test at run time • When job is released, determine if there is a feasible schedule that includes this sporadic job • If no feasible schedule, then reject job and notify application of rejection CS523 – Operating Systems
Performing an Acceptance Test • S(d,e)released at time t in frame x-1: • for example an interrupt is received in frame x-1. • The deadline d is in frame (y+1) => • S must complete before frame y+1 begins • Current total slack time available between frames x and y (inclusive) = Qc(x, y) • S is rejected if • e > Qc(x, y),OR • some previously accepted jobs will not meet deadline • Order waiting jobs using EDF CS523 – Operating Systems
Earliest Deadline First (EDF) • EDF: priority driven scheduling algorithm with dynamic task (fixed job) priority assignment. • earlier the deadline, higher the priority • priorities are assigned on job release • Jobs placed in run queue by priority • Assumptions: • Tasks are preemptable and independent • Tasks have arbitrary release times, arbitrary deadlines • Single Processor • Optimal: EDF can produce a feasible schedule for a set of Jobs J if and only if J has a feasible schedule. CS523 – Operating Systems
Latest Release Time (LRT) • Goes "backwards" in time: Treats release times as deadlines and deadlines as release times. • job with latest release time has highest priority • May leave processor idle when jobs are ready, so not a priority-driven algorithm. • Optimal: LRT can produce feasible schedule for a set of jobs J if and only if feasible schedules for J exist. Idle J1, 3 (0, 6] J2, 2 (5, 8] J3, 2 (2, 7] J1 J3 J2 1 4 6 8 CS523 – Operating Systems
Least Slack Time First (LST) • LST or Maximum Laxity First (MLF) • Dispatch job with minimum slack time: smaller slack time, higher priority. • Optimal: Can produce feasible schedules for J if and only if feasible schedules for J exist. • Requires knowledge of execution times, while EDF does not. • Consequently may underutilize processor when using maximum (worst-case) analysis. CS523 – Operating Systems
Performing and Acceptance Test • Beginning of each frame: perform acceptance test on any waiting sporadic tasks • Two steps: • Determine if sporadic task can complete execution using available slack time (subtract any slack time used by accepted tasks with deadlines before d) • Determine if any already accepted sporadic tasks with deadlines after d will be affected CS523 – Operating Systems
Implementation: Calculating Slack Time • Calculating the available slack time • S was released within previous frame, (x - 1) • S has deadline in frame (y + 1) so must complete execution no later than frame y • Acceptance test performed at start of frame x • calculated between frame x and frame immediately preceding deadline, frame y • if deadline is in frame x then S can not be scheduled • Suffices to know original slack time between all frame pairs within one major cycle, Q(x, y) for x, y in H. • Assume x is in major cycle j and y is in major cycle k • Q(x,y) = Q(x,F) + Q(1,y) + [(k - 1) - j]Q(1,F); k > j • Q(x, y) is known if k = j, y > x. • Q(x, x) = is known, slack in current frame CS523 – Operating Systems
Accepting S: Step 1 • If sporadic jobs are already in system then the available slack time is given by: • Qc(x, y) = Q(x, y) - Sum[dkd; (ek - e'k)] • slack plus remaining execution time of higher priority tasks. • e'k = time job k has already executed • The sum is over all jobs with deadline dk d. • If S is accepted • Slack before new sporadic job's deadline: • Qs = Qc(x, y) - e • if job accepted store this value with job • reject if Qs< 0, CS523 – Operating Systems
Accepting S: Step 2 • Check all jobs with deadlines after d to verify they will not miss their deadlines. • d = deadline of new sporadic task • e = execution time of new sporadic task • Let Sl be the set of already accepted sporadic tasks with deadlines after d. • Let Ql be the calculated slack for sporadic task Sl • Accept if Step one is valid and the following condition is valid • Ql- e 0for all sporadic jobs with dl > d. CS523 – Operating Systems
Summary Acceptance Test • Scheduler must store the following • Precomputed slack table, Q(x, y), {x ,y = 1, 2, ..., F} • Completed execution time of accepted sporadic jobs, e'k • Current slack (Qs) of every sporadic job • Optimality of Cyclic EDF (on-line algorithm) • it is optimal compared to other schemes that perform an acceptance test at beginning of frames • Not optimal compared to algorithms performing acceptance tests at arbitrary times. • However, this may impact the periodic tasks which may be interrupted an arbitrary number of times in order to perform acceptance tests for released sporadic jobs. CS523 – Operating Systems
Practical Considerations • Frame Overruns • Abort job, schedule recovery job • Execute unfinished portion as aperiodic job • Continue executing job • Mode changes: system reconfiguration. Assume periodic jobs are independent • Hard-deadline: • Soft-deadline: • Other Workloads CS523 – Operating Systems
Assessing Clock-Driven Scheduling • Advantages: • Simplicity: account for dependencies and resource contention. No need for synchronization mechanisms. • Timing constraints verified or enforced at frame boundaries while minimizing overhead due to context switches and IPC mechanisms. Simple scheduling algorithm to minimize overhead. • Minimal impact of asynchronous system processing (interrupts for example) • often verification is simple CS523 – Operating Systems
Assessing Clock-Driven Scheduling • Disadvantages: • inflexible • Model and implementation may be too simple and restrictive • Difficult to add new components or change existing system parameters • Release times must be fixed • Must know all periodic parameters in advance • operation modes must be explicitly enumerated and scheduled CS523 – Operating Systems