CS452 F23 Lecture Notes
Lecture 09 - 05 Oct 2023
1. AwaitEvent(int eventId)
- this how tasks synchronize with device activity
- eventIds are defined by the kernel, known to the application
- example event: clock tick
- calling task blocks until specified event occurs
- returns an int - event-specific interpretation
- some flexibility in
AwaitEvent
semantics- what happens if an event occurs when no task is awaiting it?
- event is ignored? remembered?
- unconsumed events are counted?
- what happens when an event occurs if multiple tasks are awaiting it?
- what happens if an event occurs when no task is awaiting it?
1.1. Implementing AwaitEvent
- intention of
AwaitEvent
is to expose kernel-handled interrupts to the application - suppose we want to implement a ClockTick event, occuring every 10ms
- when ~AwaitEvent~(ClockTick) is called, calling task blocks (for at most 10ms)
- suppose the kernel programs SystemTimer to interrupt every 10ms, via system timer C1 register
- interrupt handler does:
- save running task state
- read
GICC_IAR
to learn interrupt type - if system timer interrupt
- find task(s) waiting for ClockTick
- unblock them all (make ready)
- add 10000 to C1
- write Interrupt ID to
GICC_EOIR
- choose next task
- restore task state
- if instead System timer interrupts every 1ms, kernel can maintain a counter that is incremented on each interrupt
2. Clock server
- API:
- Time(int tid) - current time (in ticks)
- Delay(tid, ticks) - delay, relative to current time
- DelayUntil(tid, ticks) - delay, to absolute time
- these are
Send
wrappers. tid is tid of a Clock server - Time measured in “ticks”, defined to be 10ms
2.1. Server Implementation
- needs to Receive, also needs to
AwaitEvent
to know when clock advances - if server calls
AwaitEvent
, it can’t Receive any new requests - so, split implementation across two tasks: server and notifier
- server Receives clock server API request and tick notifications
- notifier blocks on
AwaitEvent
, Sends tick notifications to server
- Notifier pattern
3. Assignment K3
AwaitEvent
, Clock Server, test clients, idle task- idle task should measure and report the percentage of time that it is running
- how?
Figure 1: K3 tasks