© 2003 Wayne WolfOverheads for Computers as
Components
Operating systems
Windows CE (WinCE).
© 2003 Wayne WolfOverheads for Computers as
Components
Goals
Support lightweight consumer devices: PDAs. Set-top boxes.
Simplify porting existing Windows applications to the new platforms.
© 2003 Wayne WolfOverheads for Computers as
Components
WinCE architecture
OEM hardware
OALbootload
driversDevicedrivers
Filedrivers
Networkdrivers
Kernellibrary
GWESDevice
managerFile
managerIrDA TCP/IP
Win32 APIs
WinCE shell services
Embedded shellRemote connectivity
Applications
© 2003 Wayne WolfOverheads for Computers as
Components
Virtual memory
WinCE uses virtual memory. Most devices don’t have disk drive.
Code can be paged from ROM, etc.WinCE suports a flat 32-bit virtual address
space.Virtual address may be:
Statically mapped (kernel-mode code). Dynamically mapped (user-mode and some
kernel-mode code).
© 2003 Wayne WolfOverheads for Computers as
Components
Address space
Bottom half is user space.
Top half is kernel space.
User space2 GB
Kernel space2 GB
© 2003 Wayne WolfOverheads for Computers as
Components
Kernel address space
Operating system (nk.exe).Statically mapped virtual addresses.
Up to 512 MB of physical resources can be statically mapped.
Control of static mapping varies: OEM control for ARM and x86. CPU control for SHx and MIPS.
© 2003 Wayne WolfOverheads for Computers as
Components
User address space
64 slots of 32 MB each.
Slot 0 is currently running process.
Slots 1-33 are the processes. 32 processes max.
Object store, memory mapped files, resource mappings.
Slot 0: current process
Slot 1: DLLs
Slot 2: process
Slot 3: process
…
Slots 33-62: object store,memory mapped files
Slot 63: resource mappings
© 2003 Wayne WolfOverheads for Computers as
Components
Process slot
Includes code, DLL and virtual allocations.
Virtual allocations are 64 KB-aligned; 4KB pages can be committed within an allocation.
Movement: DLL allocations start at
the top and grow down. Process and general
allocations start at the bottom and grow up.
Guard section (64K)
User code: Stack, heapper thread
DLL virtual memoryallocations
© 2003 Wayne WolfOverheads for Computers as
Components
API calls
System call may be to DLL, another EXE.
COREDLL provides link between system API and EXE.
System call: Exception caught by kernel. Kernel determines which EXE gets the
call.
© 2003 Wayne WolfOverheads for Computers as
Components
Driver structure
A driver is a DLL with particular interface points.
Hosted by a device manager process space (may be GWES).
Handle interrupts by dedicated IST thread.
Synchronize driver and application via critical sections and MUTEXes.
© 2003 Wayne WolfOverheads for Computers as
Components
Driver architecture
DeviceI/ORM
GWES
PCI bus display
touch
mouseNotification
LED
battery network audio Firewire USB host
PCMCIAhost
© 2003 Wayne WolfOverheads for Computers as
Components
Device manager
Always-running user-level process.Contains the I/O Resource Manager.Loads the registry enumerator DLL
which in turn loads drivers.Provides power notification
callbacks.
© 2003 Wayne WolfOverheads for Computers as
Components
Registry enumerator
DLL (RegEum.dll). Re-entrant, supports hierarchical usage.
Driver loading: RegEnum scans registry, loads bus drivers. Bus driver scans bus, locates devices. Searches registry for device information. Loads appropriate drivers. Sends notification that interface is
available.
© 2003 Wayne WolfOverheads for Computers as
Components
Interrupt handling
Work divided into two sections: Interrupt service routine (ISR):
Kernel mode service.May be static or installable.
Interrupt service thread (IST):User mode thread.
© 2003 Wayne WolfOverheads for Computers as
Components
Static ISR
Built into the kernel. SHx and MIPS must be written in assembler,
limited register availability.
One-way communication from ISR to IST. Can share a buffer but location must be
predefined.
Nested ISR support based on CPU, OEM’s initialization.
Stack is provided by the kernel.
© 2003 Wayne WolfOverheads for Computers as
Components
Installable ISR
Can be dynamically loaded into kernel.
Loads a C DLL.Can use shared memory for
communication.ISRs are processed in the order they
were installed.Limited stack size.
© 2003 Wayne WolfOverheads for Computers as
Components
WinCE 4.x interrupts
All higherenabled
HW
kernelO
AL
I-ISR
thread
All enabledExcept ID
All enabled
ISH Set event Enable ID
ISR ISR
ISR ISR
IST processing
device
© 2003 Wayne WolfOverheads for Computers as
Components
Kernel scheduler
Two styles of preemptive multitasking. Thread runs until end of quantum. Thread runs until higher priority thread is ready
to run.Round-robin within priority level.Quantum is defined by OEM and application.Priority inheritance to control priority
inversion.256 total priorities.
Top 248 can be protected by the OEM.
© 2003 Wayne WolfOverheads for Computers as
Components
Thread quantum
Per-thread quantum. Default set by OEM.
Use API to set quantum.Quantum of 0 means run-to-
completion.
© 2003 Wayne WolfOverheads for Computers as
Components
System tick
1 ms timer tick normally.Sleep(N) will generally wake up in N
to N+1 ms.
© 2003 Wayne WolfOverheads for Computers as
Components
Causes of interrupt latency
ISR: Amount of time that interrupts are turned off. Time required to vector ISR, save registers,
etc.
IST: Time spent in ISR. Time spent in Kcall. Thread scheduling time.
© 2003 Wayne WolfOverheads for Computers as
Components
Improvements to latency in WinCE 4.x
Less non-preemptable code. Some routines split into several smaller
routines.Kernel data structures moved to
statically mapped virtual addresses.Special-case ISTs provided.Improved priority inversion handling.
© 2003 Wayne WolfOverheads for Computers as
Components
Controlling scheduling/latency
Thread scheduling: Set priorities appropriately, choose proper quantum.
Memory: Preallocate memory, threads, sync objects.
Understand device characteristics: I/O-based access may incur a penalty.
On x86 avoid using CMOS real-time clock, use software real-time clock.
Disable idle processing.Disable demand paging.
© 2003 Wayne WolfOverheads for Computers as
Components
Real-time measurement
ILTiming Software-based real-time measurement
tool.Measures ISR latency from IRQ to ISR.Measures IST latency from end of ISR to
start of IST.
Kernel tracker Tracks interrupts, TLB misses, and
priority inversion.
© 2003 Wayne WolfOverheads for Computers as
Components
Board support package
Customizes OS for a hardware platform. Drivers, memory configuration, power
management, etc.Software development environment
provides tools for BSP development.
© 2003 Wayne WolfOverheads for Computers as
Components
BSP development process
TestHW
CloneReference BSP
DevelopBoot loader
DevelopMinimal kernel
Add devicedrivers
Powermanagement
PackageBSP
© 2003 Wayne WolfOverheads for Computers as
Components
Boot loader
The Boot loader loads an executable image and runs it. Loadable by Ethernet, USB, serial, local
flash, etc. Memory may be flash or ROM. May need different development,
production loaders.
© 2003 Wayne WolfOverheads for Computers as
Components
OAL architecture
Kernel (Microsoft)
HardwareReal-time
clock
USB/Ethernet/
Serial
OALRTCPowerMgt.
interruptfunctions
debug