CS 452/652 Winter 2026 - Lecture 10
Events, Clock, Idle
Feb 5, 2026 prev next
AwaitEvent
- synchronization: user tasks ↔ device
- AwaitEvent() argument and return code → design decision
- eventIds are defined by the kernel, known to the application
- return code - event-specific interpretation
- example: subtype, count, data
- micro-kernel: put as much functionality as possible in user-level tasks
- AwaitEvent() blocks calling task
- matchmaking task ↔ event
- 0, 1, N tasks waiting? store in queue (cf. SRR)?
- N tasks wait for event? complexity? unblock one or all?
- 0 tasks wait for interrupt? buffer in kernel?
- multiple same interrupts without waiting task indicate performance problem
- use task prioritity to make sure that hardware interrupts are handled promptly
- use assertion vs warning for testing vs production
- intention of AwaitEvent() is to expose device interrupts to the application
- program periodic interrupt in kernel
- can be decoupled: 1ms timer interrupt vs. 10ms clock tick
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
- DelayUntil = Time + Delay, but at server
- convenience for real-time loop
- these are Send() wrappers; tid is tid of a Clock server
- Time measured in "ticks"
Server Implementaion
- AwaitEvent() might block; server pattern?
- if server calls AwaitEvent(), it cannot Receive() new requests (e.g., Time())
- delegate event blocking to special task: Notifier pattern
Clock Notifier
for (;;) {
AwaitEvent();
Send(); // send tick to clock server
}
Clock Server
for (;;) {
Receive();
process(); // manage tasks
Reply(); // if applicable
}
- needs to manage list of suspended tasks
Idle/Halt
Note: Per-Task Information Registers
- TPIDR_EL0: per-thread pointer (RW in EL0)
- TPIDR_EL1: per-thread pointer (RW in EL1)
- can be used by kernel to store pointer to task context
- TPIDRRO_EL0: per-thread pointer (RO in EL0)
- could also be used to store thread-local data
SRR Performance
- effect of message size
- effect of compiler optimization
- effect of i-cache, d-cache
- for opt: S and R different → bug
- independent of msg len → bug
SRR for Producer/Consumer
- communication pattern; asynchronous buffering; control blocking
- single producer, single consumer (SPSC)
- producer sends, consumer responds with ack: "push" communication
- consumer sends/requests, producer responds with element: "pull" communication
- multiple producers, single consumer (MPSC)
- push communication works → consumer is server
- pull communication: slow producer might block consumer (and thus other producers)
- single producer, multiple consumers (SPMC)
- push communication: head-of-line blocking
- pull communication works → producer is server
- multiple producers, multiple consumers (MPMC)
- need intermediary: buffer ("distributor", "warehouse")
- buffer: acts as single consumer to producers, single producer to consumers
- buffer receives requests, processes request, (delayed?) response
- buffer full or empty: block respective producer(s)/consumer(s)?