Download presentation
Presentation is loading. Please wait.
1
Thread 組員:王傳陞、林威丞 黃品舜、李盈賢
2
Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads Thread Scheduling Processor affinity Quantum thread dispatching Priority Levels Windows Scheduling APIs
3
Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads Thread Scheduling Processor affinity Quantum thread dispatching Priority Levels Windows Scheduling APIs
4
Thread-related tools : Process Explorer
5
Thread-related tools : Process Explorer (cont.)
6
Download Process Explorer http://www.sysinternals.com Context switch delta : The number of times that thread began running between the refreshes Process Explorer Thread activity Context switch delta CPU percentage
7
Thread-related tools : Process Explorer (cont.) Thread start address : Displayed in the form “module!function” address,where module is the name of the.exe or.dll. Note : Windows threads start at a common process or thread startup wrapper function Problem : most threads would appear to have started at same address
8
Thread-related tools : Process Explorer (cont.)
10
Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads Thread Scheduling Processor affinity Quantum thread dispatching Priority Levels Windows Scheduling APIs
11
Why a process is hung Use Process Explorer viewing the thread stack help us determine why a process is hung. Example : Show that PowerPoint of thread stack.
12
Why a process is hung (cont.)
15
Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads Thread Scheduling Processor affinity Quantum thread dispatching Priority Levels Windows Scheduling APIs
16
Viewing Ready Threads In the WinDbg kd> !ready 1
17
Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads Thread Scheduling Processor affinity Quantum thread dispatching Priority Levels Windows Scheduling APIs
18
Processor affinity the highest-priority runnable (ready) thread always runs, with the caveat that the thread chosen to run might be limited by the processors, a phenomenon called processor affinity.
19
Processor affinity [wiki] (cont.) [wiki] Example : Involves two processor-intensive tasks (A & B) having affinity to one processor while another processor lies unused.
20
Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads Thread Scheduling Windows Scheduling APIs Processor affinity Quantum thread dispatching Priority Levels
21
Quantum It run for an amount of time called a quantum Quantum values can vary System configuration settings Foreground/background status of the process Use of the job object to alter the quantum A thread might not complete its quantum Preemptive scheduler
22
Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads Thread Scheduling Windows Scheduling APIs Processor affinity Quantum Thread dispatching Priority Levels
23
Thread dispatching Events might require thread dispatching A thread become ready to execute A thread leaves the running state A thread’s priority changes A thread’s processor affinity changes Note: Windows schedule at the thread granularity Example : If process A has 10 runnable threads, process B has 2 runnable threads, and all 12 threads are at the same priority. Threads would receive one-twelfth of CPU time Windows wouldn’t give 50% CPU to process A and 50% CPU to process B.
24
Thread dispatching (cont.)
25
Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads Thread Scheduling Processor affinity Quantum thread dispatching Priority Levels Windows Scheduling APIs
26
Priority Levels
27
Thread priority levels are assigned form two different perspectives: Windows API : First organizes processes Windows kernel : Set relative priority of the individual threads within those processes Priority class Real-time High Above Normal Normal Below Normal Idle
28
Priority Levels (cont.)
29
Process has only one priority values Current priority Thread has two priority values Current priority Base priority
30
Priority Levels (cont.) priority boosting in the dynamic range (1 through 15) for brief periods. Windows never adjusts the priority of threads in the real-time range (16 through 31), so they always have the same base and current priority.
31
Priority Levels (cont.) A thread’s initial bas priority is inherited from the process base priority A process inherits its base priority from the process that created it. CreateProcess function Command-line START command Changed process priority SetPriorityClass Various tools that expose that function Task Manager Process Explorer
32
Priority Levels (cont.) Process base priority Default to the value at middle of each process priority range(24,13,10,8,6,4) Some Windows system processes have a bas process priority slightly higer than the default for the Normal class(8) Session Manager, service controller, local security authentication server Use an internal system call (NtSetInformationProcess) to set process base priority
33
Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads Thread Scheduling Processor affinity Quantum thread dispatching Priority Levels Windows Scheduling APIs
34
Windows Scheduling APIs Scheduling-Related APIs and Their Functions APIFunction SuspendSuspend/ResumeThreadResumeThreadSuspends or resumes a paused thread from execution. GetGet/SetPriorityClassSetPriorityClassReturns or sets a process's priority class (base priority). GetGet/SetThreadPrioritySetThreadPriorityReturns or sets a thread's priority (relative to its process base priority). GetGet/SetProcessAffinity MaskSetProcessAffinity Mask Returns or sets a process's affinity mask. SetThreadAffinityMaskSets a thread's affinity mask (must be a subset of the process's affinity mask) for a particular set of processors, restricting it to running on those processors.
35
APIFunction SetInformationJobObjectSets attributes for a job; some of the attributes affect scheduling, such as affinity and priority. GetLogicalProcessor Information Returns details about processor hardware configuration (for hyper-threaded [wiki] and NUMA [wiki] systems).[wiki] GetGet/SetThreadPriorityBoostSetThreadPriorityBoostReturns or sets the ability for Windows to boost the priority of a thread temporarily. (This ability applies only to threads in the dynamic range.) SetThreadIdealProcessorEstablishes a preferred processor for a particular thread, but doesn't restrict the thread to that processor. Windows Scheduling APIs (cont.) Scheduling-Related APIs and Their Functions
36
APIFunction GetGet/SetProcess PriorityBoostSetProcess PriorityBoost Returns or sets the default priority boost control state of the current process. (This function is used to set the thread priority boost control state when a thread is created.) SwitchTo Thread Yields execution to another thread (at priority 1 or higher) that is ready to run on the current processor. SleepPuts the current thread into a wait state for a specified time interval (figured in milliseconds [msec]). A zero value relinquishes the rest of the thread's quantum. SleepExCauses the current thread to go into a wait state until either an I/O completion callback is completed, an APC is queued to the thread, or the specified time interval ends. Scheduling-Related APIs and Their Functions Windows Scheduling APIs (cont.)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.