Today's plan
- Minix Clock Driver
- Minix Terminal Driver
- Minix System Task
PC Clock Hardware
- quartz crystal oscillator drives counter
- when counter reaches maximum, reloaded with contents of a register,
and also interrupts
- setting the contents of the register controls the frequency of interrupts
- real-time clock is a separate device, uses a very low-power
counter similar to those found on digital watches, battery keeps it
running as main power is off
Minix Clock Driver
- very understandable driver
- neither block device nor character device
- does not conform to the Minix model:
- interrupt handler does a lot more than send a message to the driver
- interrupt handler often does not send a message to the driver
- interrupt handler may send a message to the tty or the printer driver
- all of these are in the interest of speed on slow systems
- functions:
- maintain the time of day
- preempt processes
- account for CPU usage and support profiling
- provide alarm signals for user processes and watchdog timers
for other parts of the system
Time of day support
- 32-bit counter in seconds rolls over in about 136 years
- 32-bit counter in ticks (1/60 of a second) rolls over in about 2 years
- time is usually counted in seconds from Jan 1st, 1970 (Unix, Minix, etc)
or Jan 1st, 1980 (Windows) -- this is the epoch
- options:
- keep 64-bit counter in ticks
- keep 32-bit counter in seconds and another variable to record the
fractional ticks
- use boot time as the epoch and keep a 32-bit count of ticks. Separately
record the boot time (in seconds) as a 32-bit variable. Minix uses this
- getting the time of day: add realtime / HZ to the boot time
- setting the time of day: save the difference between the parameter
and realtime / HZ as the boot time
Supporting Alarms
- alarm (3) in a user program tells the system to send
a signal to the process unless the alarm has been cleared within 3 seconds
- in Minix, tasks can set watchdog timers which result in
calling a function when the time expires
- in Minix, servers can request synchronous alarms before calling
receive, so the call to
receive is guaranteed to eventually terminate
- most of the support for signals is in the servers, but the
clock task must send a message to the memory manager (if MM is receiving,
otherwise just set some bits) to tell it to signal the process
- watchdogs simply require calling a function, but that function
should not block
- synchronous alarms send a message only if the process is blocked
Minix Terminal Driver
- very complex: supports memory-mapped keyboard and displays, RS-232
serial terminals, and network-based logins (Pseudo-ttys, or PTYs, on other
systems)
- character devices, but with two-dimensional
positioning capabilities (screens)
- screens can be character-based or pixel-based (minix only supports
character-based)
- buffering can be reserved per terminal (as is the case in Minix)
or shared among all terminals (central buffer pool)
- terminal driver must perform line editing functions to
honor erase characters and possibly change newlines into CR-LF or
viceversa (or other combinations)
Terminal Modes
- editors will do their own screen redrawing, can handle erase
characters, so should be given the raw stream of characters
the user enters
- most programs take line input and would prefer to have the
operating system take care of editing: canonical or cooked
mode
- special characters can control freezing (^S) or restarting (^Q)
the output, mark end of file (^D), end of line, etc
- in non-canonical mode, Minix allows the specification of a
minimum number of characters to read and of a timeout for terminal
reads -- if either is satisfied, the read call completes
Reading from the terminal
- book, figure 3-37, p. 252
- user process sends message to file system
- file system sends message to TTY task, which may directly go to (6),
but most likely
- replies asking the file system to suspend the process
- the TTY interrupt handler sets tty_timeout and returns
- the next clock interrupt signals the TTY task that one or more
characters are available
- the TTY task copies data directly to the user space using physical
memory copying
- the TTY task tells the file system task (whenever it is ready to
receive the message) that it may wake up the user process
- the FS server wakes up the user process
- this complex technique gives acceptable performance for large bursts
of characters from the serial port on slow hardware
- is this needed now? (in-class discussion)
Bitmapped displays
- each pixel (usually 1, 8, 16, 24, or 32 bits) represents one dot
on the display: one scan sweep position or one pixel on an LCD display
- more resolution requires more memory (1280x1024x24 requires 4MB
for each display, without counting virtual desktop space)
- data can be arranged in various fashions in memory, but usually
such that adjacent elements of a row are adjacent in memory
- basic display operations include moving a block (bitblt),
drawing a point or a line, or filling in a rectangle (can also be done
with bitblt)
- a window manager, which may be part of the OS, must create
windows, associate them with processes, and support opening, closing,
moving, iconifying, etc
- the X-window system is a user-level program (an X
server) that supports basic window operations for (possibly
remote) client programs
- one of these client programs is the X window manager
- other client programs show the time, check for mail, allow for
user command-line input (by running shells, perhaps remote shells),
support surfing the web, etc.
Minix System Task
- coordination between the servers and the kernel is essential
- in Minix, kernel functions needed by the server but not associated
with an I/O device are placed in the system task
- like all tasks, the system task receives messages, executes appropriate
code, and returns results, without blocking
- a special call, cause_sig (p. 740), sends a message
conditionally, that is, only if the memory manager is ready to
receive the signal -- otherwise sets a flag and lets the memory manager
discover that it missed a call
- a number of calls perform the kernel portion of process management
system calls:
fork,
exec,
exit,
times,
kill.
- other calls perform tasks on behalf of the memory manager or file
server, for example mapping memory to a process, returning the stack
pointer of a process (stored in the kernel process table), copying
data between processes, returning the next free memory, converting
virtual to physical addresses, tracing a process execution,
and rebooting or shutting down the system
Supporting Fork and Exec
- fork (p. 729) requires copying the proc table entry (the MM has already
selected the child process ID), changing the return value for the
child (which is in the stack), and clearing the usage times
- the resulting process is not yet mapped, so is not scheduled
- mapping takes the memory map provided by the memory manager and
initializes all the corresponding segments in the process table, then
schedules the process. The segments will be loaded on return from
interrupt, i.e. when the process actually gets started
- exec resets the stack pointer and places a new PC in
the process table, then readies the process for execution. Someone
else must map the new code segments to the memory before calling this
code
- exit does bookkeeping and removes the process from any queues for
any messages it was trying to send, then cancels signals and sets the
slot to free -- someone else is responsible for closing file descriptors,
deallocating memory, etc
Signal Handling
- to send a signal to a process, must:
- save all the process state (done by the context switch code)
- create new state for execution of the signal handler, on the
same stack (lines 15176 and following)
- put a return address that will lead to do_sigreturn,
to allow for cleanup of the stack
- restore the process state (done by the context switch code)
Virtual Memory in Minix
- umap, p. 742
- a virtual address v corresponds to a physical address p based
on two per-segment fields, physical-base and virtual-base (possible segments
include, text, data, and stack)
- v - virtual-base is the offset o into the segment
- p = o + physical-base is the physical address
- computation on lines 15686-15690
Rebooting
- rebooting is done by keyboard code, since the monitor must
be able to receive input from the user