Optimiizing Windows CE for Real

Download Report

Transcript Optimiizing Windows CE for Real

®
Optimizing Windows CE
For Real-Time Systems
Paul Yao
President
The Paul Yao Company
http://www.paulyao.com
8-309
Agenda






Introductions (5 minutes)
Terms (5 minutes)
RT-features of Windows CE
(15 minutes)
RT enhancements for Windows CE 3.0
(15 minutes)
Optimization tips (20 minutes)
Discussion (15 minutes)
Terms

Real time – A system in which specific data
collection or device control must be handled
within specified time parameters




1 Millisecond (1 ms) = .001 second
1 Microsecond (1 ms) = .000001 second
Hard real time – Catastrophic results for
failure to meet time-critical needs
Soft real time – Non-catastrophic results
CE Kernel Features


Multi-process operating system (32 max)
Multi-threaded


Synchronization





256 thread priorities (new with Windows CE 3.0)
Critical sections
Mutexes
Semaphores (new with Windows CE 3.0)
Events
Memory


Paged
No backing store
Interrupt Handling
IST = “Interrupt
Service Thread”
C
User Mode
Kernel Mode
A
Event
IRQ
NK.EXE
B
ISR = “Interrupt
Service Routine”
Event
Windows CE 3.0
Real-Time Features

Better interrupt handling



Support for nested interrupts
Improved interrupt latencies
Better control of Scheduler






More thread priorities
Control of time-slice quantum
Restrictions based on Trust
Better synchronization support
Higher timer resolution
Better priority inversion handling
Nested Interrupts

Windows CE 2.x



No nesting
IRQs always run
to completion
ISTs run to
completion when
created with
highest priority

Windows CE 3.0




Nesting supported
IRQs can be
interrupted
Registers saved
and restored
Interrupts only
occur for higher
priority IRQs
Interrupt Latency
IST = “Interrupt
Service Thread”
User Mode
Kernel Mode
A
Event
IRQ
NK.EXE
B
ISR = “Interrupt
Service Routine”
Event
Thread Priorities

Windows CE 2.x



Eight priorities – 0 to 8
SetThreadPriority(hThread, nPriority)
Windows CE 3.0


256 priorities – 0 (real-time) to 255
CeSetThreadPriority(hThread, nPriority)
New Thread Priorities

Windows CE 2.x
SetThreadPriority()

Windows CE 3.0
CeSetThreadPriority()









0 = real-time
1
2
3 = normal
4
5
6
7 = idle-time








0 (RT) to 247
248
249
250
251
252
253
253
255
Thread Quantum Control


Quantum = Duration of time slice
Platform builder – Set default



During call to OEMInit()
Set dwDefaultThreadQuantum
Individual threads:


DWORD CeGetThreadQuantum();
BOOL CeSetThreadQuantum
(DWORD dwTime)
Thread Quantum Examples
// Set quantum to 100 ms.
CeSetThreadQuantum(100);
// Set quantum to 500 ms.
CeSetThreadQuantum(500);
// Set run to completion.
CeSetThreadQuantum(0);
Certifying Trust

Untrusted applications:




Cannot call CeSetThreadPriority
Cannot call CeSetThreadQuantum
Platform Builder – OEMCertifyModule
Checking Trust:



DWORD CeGetCurrentTrust(void);
DWORD CeGetCallerTrust(void);
0 = None, 1 = Some, 2 = All
Synchronization
Enhancements

TryEnterCriticalSection() –


Non-blocking call
Semaphores

A “mutex with a count”
Timers

Sleep(int nMilliseconds)

1 ms granularity on CE 3.0
Sleep(100); // block for 100 ms.
Sleep(5); // block for 5 ms.
Sleep(0); // yield quantum.

Avoid SetTimer()


Not RT
Message-based, UI-oriented timer
Priority Inversion
Mutex
Priority
Blocks on
Mutex
Acquires
Mutex
A
B
C
Acquires
Mutex
Frees
Mutex
Time
Optimizing Tips

Avoid priority inversion




Memory



Avoid file I/O from RT threads
Avoid graphic calls from RT threads
Avoid UI calls from RT threads
Pre-allocate heap memory
Pre-commit stack memory
To Control Paging


Use LoadDriver() - not LoadLibrary()
For individual pages - LockPages()
Measurement Tools

ILTIMING – Check Interrupt Latency


OSBENCH – Thread scheduling


\wince300\public\common\oak\
utils\iltiming
\wince300\public\common\oak\
utils\osbench
White paper:

http://www.microsoft.com/windows/
embedded/ce/resources/developing
Measurement APIs
QueryPerformanceFrequency()

QueryPerformanceFrequency()


QueryPerformanceCounter()


Returns Ticks per Second
Returns Current tick count
GetTickCount()
Discussion
Thank You!