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