Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity...
-
date post
20-Dec-2015 -
Category
Documents
-
view
234 -
download
0
Transcript of Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity...
![Page 1: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/1.jpg)
Thread
組員:王傳陞、林威丞 黃品舜、李盈賢
![Page 2: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/2.jpg)
Outline Examining Thread Activity
Thread-related tools : Process Explorer Why a process is hungViewing Ready Threads
Thread SchedulingProcessor affinity Quantum thread dispatching Priority LevelsWindows Scheduling APIs
![Page 3: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/3.jpg)
Outline Examining Thread Activity
Thread-related tools : Process Explorer Why a process is hungViewing Ready Threads
Thread SchedulingProcessor affinity Quantum thread dispatching Priority LevelsWindows Scheduling APIs
![Page 4: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/4.jpg)
Thread-related tools : Process Explorer
![Page 5: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/5.jpg)
Thread-related tools : Process Explorer(con
t.)
![Page 6: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/6.jpg)
Thread-related tools : Process Explorer(con
t.) Download Process Explorer
http://www.sysinternals.com Context switch delta : The number of times that thread began ru
nning between the refreshes Process Explorer
Thread activityContext switch deltaCPU percentage
![Page 7: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/7.jpg)
Thread-related tools : Process Explorer(con
t.) Thread start address : Displayed in the fo
rm “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
![Page 8: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/8.jpg)
Thread-related tools : Process Explorer(con
t.)
![Page 9: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/9.jpg)
Thread-related tools : Process Explorer(con
t.)
![Page 10: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/10.jpg)
Outline Examining Thread Activity
Thread-related tools : Process Explorer Why a process is hungViewing Ready Threads
Thread SchedulingProcessor affinity Quantum thread dispatching Priority LevelsWindows Scheduling APIs
![Page 11: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/11.jpg)
Why a process is hung Use Process Explorer viewing the thread s
tack help us determine why a process is hung.
Example :Show that PowerPoint of thread stack.
![Page 12: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/12.jpg)
Why a process is hung (cont.)
![Page 13: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/13.jpg)
Why a process is hung (cont.)
![Page 14: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/14.jpg)
Why a process is hung (cont.)
![Page 15: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/15.jpg)
Outline Examining Thread Activity
Thread-related tools : Process Explorer Why a process is hungViewing Ready Threads
Thread SchedulingProcessor affinity Quantum thread dispatching Priority LevelsWindows Scheduling APIs
![Page 16: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/16.jpg)
Viewing Ready Threads In the WinDbg
kd> !ready 1
![Page 17: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/17.jpg)
Outline Examining Thread Activity
Thread-related tools : Process Explorer Why a process is hungViewing Ready Threads
Thread SchedulingProcessor affinity Quantum thread dispatching Priority LevelsWindows Scheduling APIs
![Page 18: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/18.jpg)
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.
![Page 19: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/19.jpg)
Processor affinity [wiki] (cont.)
Example :Involves two processor-intensive tasks (A & B) having affinity to one processor while another processor lies unused.
![Page 20: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/20.jpg)
Outline Examining Thread Activity
Thread-related tools : Process Explorer Why a process is hungViewing Ready Threads
Thread SchedulingWindows Scheduling APIsProcessor affinity Quantum thread dispatching Priority Levels
![Page 21: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/21.jpg)
Quantum It run for an amount of time called a
quantum Quantum values can vary
System configuration settingsForeground/background status of the processUse of the job object to alter the quantum
A thread might not complete its quantumPreemptive scheduler
![Page 22: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/22.jpg)
Outline Examining Thread Activity
Thread-related tools : Process Explorer Why a process is hungViewing Ready Threads
Thread SchedulingWindows Scheduling APIsProcessor affinity QuantumThread dispatching Priority Levels
![Page 23: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/23.jpg)
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, proce
ss 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 t
o process B.
![Page 24: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/24.jpg)
Thread dispatching (cont.)
![Page 25: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/25.jpg)
Outline Examining Thread Activity
Thread-related tools : Process Explorer Why a process is hungViewing Ready Threads
Thread SchedulingProcessor affinity Quantum thread dispatching Priority LevelsWindows Scheduling APIs
![Page 26: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/26.jpg)
Priority Levels
![Page 27: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/27.jpg)
Priority Levels Thread priority levels are assigned form two diffe
rent 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
![Page 28: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/28.jpg)
Priority Levels (cont.)
![Page 29: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/29.jpg)
Priority Levels (cont.)
Process has only one priority valuesCurrent priority
Thread has two priority valuesCurrent priorityBase priority
![Page 30: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/30.jpg)
Priority Levels (cont.)
priority boosting in the dynamic range (1 through 15) for brief p
eriods. Windows never adjusts the priority of threads
in the real-time range (16 through 31), so they always have the same base and current pri
ority.
![Page 31: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/31.jpg)
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
![Page 32: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/32.jpg)
Priority Levels (cont.)
Process base priorityDefault 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
![Page 33: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/33.jpg)
Outline Examining Thread Activity
Thread-related tools : Process Explorer Why a process is hungViewing Ready Threads
Thread SchedulingProcessor affinity Quantum thread dispatching Priority LevelsWindows Scheduling APIs
![Page 34: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/34.jpg)
Windows Scheduling APIs Scheduling-Related APIs and Their FunctionsAPI Function
Suspend/ResumeThread Suspends or resumes a paused thread from execution.
Get/SetPriorityClass Returns or sets a process's priority class (base priority).
Get/SetThreadPriority Returns or sets a thread's priority (relative to its process base priority).
Get/SetProcessAffinityMask
Returns or sets a process's affinity mask.
SetThreadAffinityMask Sets 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.
![Page 35: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/35.jpg)
API Function
SetInformationJobObject Sets attributes for a job; some of the attributes affect scheduling, such as affinity and priority.
GetLogicalProcessorInformation
Returns details about processor hardware configuration (for hyper-threaded [wiki] and NUMA [wiki] systems).
Get/SetThreadPriorityBoost Returns or sets the ability for Windows to boost the priority of a thread temporarily. (This ability applies only to threads in the dynamic range.)
SetThreadIdealProcessor Establishes 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
![Page 36: Thread 組員:王傳陞、林威丞 黃品舜、李盈賢. Outline Examining Thread Activity Thread-related tools : Process Explorer Why a process is hung Viewing Ready Threads.](https://reader036.fdocument.pub/reader036/viewer/2022081421/56649d4c5503460f94a2b016/html5/thumbnails/36.jpg)
API Function
Get/SetProcessPriorityBoost
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.)
SwitchToThread
Yields execution to another thread (at priority 1 or higher) that is ready to run on the current processor.
Sleep Puts 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.
SleepEx Causes 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.)