Lecture 1 on Windows CE organization.

Download Report

Transcript Lecture 1 on Windows CE organization.

Operating systems
Windows CE (WinCE).
© 2003 Wayne Wolf
Overheads for Computers as
Components
Goals
Support lightweight consumer devices:
PDAs.
Set-top boxes.
Simplify porting existing Windows
applications to the new platforms.
© 2003 Wayne Wolf
Overheads for Computers as
Components
WinCE architecture
Applications
Embedded shell
Remote connectivity
WinCE shell services
Win32 APIs
Kernel
library
GWES
Device
manager
File
manager
OAL
bootload
drivers
Device
drivers
File
drivers
OEM hardware
© 2003 Wayne Wolf
Overheads for Computers as
Components
IrDA
TCP/IP
Network
drivers
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 kernelmode code).
© 2003 Wayne Wolf
Overheads for Computers as
Components
Address space
Bottom half is
user space.
Top half is kernel
space.
© 2003 Wayne Wolf
2 GB
Kernel space
2 GB
User space
Overheads 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 Wolf
Overheads 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.
Slot 63: resource mappings
Slots 33-62: object store,
memory mapped files
…
Slot 3: process
32 processes max.
Object store, memory
mapped files, resource
mappings.
© 2003 Wayne Wolf
Slot 2: process
Slot 1: DLLs
Slot 0: current process
Overheads 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.
© 2003 Wayne Wolf
DLL virtual memory
allocations
User code:
Stack, heap
per thread
Guard section (64K)
Overheads 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 Wolf
Overheads 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 Wolf
Overheads for Computers as
Components
Driver architecture
I/O
RM
Device
GWES
PCI bus
battery network
audio
Firewire USB host
PCMCIA
host
© 2003 Wayne Wolf
Overheads for Computers as
Components
display
touch
mouse
Notification
LED
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 Wolf
Overheads 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 Wolf
Overheads 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 Wolf
Overheads 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 Wolf
Overheads 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 Wolf
Overheads for Computers as
Components
WinCE 4.x interrupts
ISR
ISR
ISR
ISR
ISH
device
All higher
enabled
© 2003 Wayne Wolf
Set event
Enable ID
All enabled
Except ID
Overheads for Computers as
Components
All enabled
thread I-ISR OAL kernel HW
IST processing
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 Wolf
Overheads 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 Wolf
Overheads 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 Wolf
Overheads 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 Wolf
Overheads 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 Wolf
Overheads 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 Wolf
Overheads 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 Wolf
Overheads 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 Wolf
Overheads for Computers as
Components
BSP development process
Test
HW
Power
management
Clone
Reference BSP
Add device
drivers
Package
BSP
© 2003 Wayne Wolf
Overheads for Computers as
Components
Develop
Boot loader
Develop
Minimal kernel
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 Wolf
Overheads for Computers as
Components
OAL architecture
Kernel (Microsoft)
RTC
Real-time
clock
© 2003 Wayne Wolf
Power
Mgt.
OAL
interrupt
functions
Hardware
Overheads for Computers as
Components
debug
USB/
Ethernet/
Serial