powerspy: fine grained power profiler kutty s banerjee emmanuel agu

25
PowerSpy: Fine Grained Power Profiler Kutty S Banerjee Emmanuel Agu

Post on 22-Dec-2015

219 views

Category:

Documents


0 download

TRANSCRIPT

PowerSpy:Fine Grained Power Profiler

Kutty S Banerjee

Emmanuel Agu

Mobile Devices – Energy Crisis

Rate of Growth of– CPU– Memory– Disk Space– Wireless Transfer Speed

Far Greater than that of Battery Energy !!

Powerful Change Part1:Batteries and Possible Alternatives for the Mobile Market. IEEE Pervasive Computing,October-December 2003 (Vol. 2, No. 4)

PowerSpy

Helps answer the following questions: Which Thread consumes How much power? What procedures in each thread are

invoked? Which I/O Device consumes how much

power?– <Application initiated I/O>

PowerSpy Features:

Non Intrusive of Kernel Source Non Intrusive of Application Source `Software-Only’ Accurate Billing sans OS activities Windows 2000,XP,Server 2003

PowerSpy Usage

Installation:– Powerspy.sys (kernel mode driver)

Installation Requires Administrative Privilege

– Powerspy.exe (user mode application)– Windows XP (run checked build)

Boot option `/debug’ flag set

Usage:– powerspy devenv.exe (Microsoft Visual Studio)– Produces `report.dat’ . Results next…

Thread and I/O Profiling

Thread Power Usage

Device Power Usage

Procedural Profiling

Application Profiled

OpenVRML – VRML Browser (disk heavy)– Graphics appln.

Mozilla– I/O heavy (Network heavy)

Windows Media Player– I/O heavy (Network heavy)

Background Work

Work Author School Conference

PowerScope

(Application Runtime)

Jason Flinn et al.

CMU Proceedings of the Second IEEE Workshop on Mobile Computer Systems and Applications, 1999

Monitoring System Activity or OS-Directed Dynamic Power Management

(Finite Elements)

Luca Benini et al.

Univ of di Bologna, Italy

ISLPED 98, Monterey, CA, USA.

Apple Macintosh’s Energy Consumption

(Finite Elements)

Jacob R Lorch et al.

UC

Berkeley

IEEE Micro archive

Volume 18, 1998

Power Measurement Approaches

Measure Power Loss - Application Runtime– Hardware (PowerScope)– Software (PowerSpy)

Break Application Runtime ->Finite Elements– Power Consumption Finitie Elements Known prior– Sum to get total power

PowerScope Approach

Hardware multimeter measures current, voltage.

Samples PC, PID, ISR Analysis offline

OS Context Switches

Time of execution of thread=quantum

Need to monitor `current thread of execution’ as often as quantum period

What about preemption? We’ll see next…

System Architecture

Debugger

KTracker

Application

OS Dispatcher

User Mode

Kernel Mode

Scheduler vs KTracker

ThreadID=1231 ThreadID=315 ThreadID=12 ThreadID=315

Ktracker 1

`Ts’=quantum

Ktracker 2 Ktracker 3 Ktracker 4

ThreadID=79

`Tk’

T1: Power=4500 T2:Power=4200 T3:Power=4000 T4:Power=3910 T5:Power=3810

Ktracker 5

T6:Power=3610

Pseudo Code Algorithm

if(measurePowerOn_==true){

if(currentThread_!=SchedulerThread())measurePowerOn_=false;

tempPower_=instPower_;instPower_=measurePower();totalPower_=tempPower_-instPower_;

}else{

if(currentThread_==SchedulerThread()){

measurePowerOn_=true;instPower_=measurePower();

}}

I/O Devices (Overlap with CPU)

ThreadID=1231 ThreadID=315 ThreadID=12 ThreadID=315

AGP

`Ts’=quantum

ThreadID=79

Network Card

Hard Disk

T1 T2

Overlapped I/O, CPU

I/O Device Monitor

ThreadID=1231 ThreadID=315 ThreadID=12 ThreadID=315

`Ts’=quantum

ThreadID=79

Ktracker 1 Ktracker 2 Ktracker 3 Ktracker 4

`Tk’

Ktracker 5

Disk ThreadID=219 Disk ThreadID=315 Disk ThreadID=219

T1 T2

I/O Device Monitor

Question ->Do you check all I/O Devices live in system ?– Push on stack question until Implementation!!

Question -> What if thread does overlapped I/O with `n’ devices?– Limitation of PowerSpy. We cannot distinguish

b/w them!!

Overlapped I/O

ThreadID=1231 ThreadID=315 ThreadID=12 ThreadID=315

`Ts’=quantum

ThreadID=79

Ktracker 1 Ktracker 2 Ktracker 3 Ktracker 4

`Tk’

Ktracker 5

Disk ThreadID=219 ThreadID=315 ThreadID=219

T1 T2

AGP ThreadID=121 ThreadID=118ThreadID=315

Disk & AGPOVERLAP!!

What about Procedures?

Two Approaches?– Invasive – Add stub of code in executable in

each procedure for all modules Stub merely records itself!!

– NonInvasive – Simply check PC at sampled intervals. (POWERSPY APPROACH)

Use Module Export/Import Table Base Loading Address

For address to module,procedure translation!!

Implementation Overview

ApplicationProfiled

DebuggerMonitor

Database

User Mode

Kernel Mode

IO Work ItemPowerSpy

DriverDPC Routine

OSScheduler/Dispatcher

ETHREADdata block

Windows Scheduling Policy

Preemptive Priority driven. Get current thread running (last running)

PsGetCurrentThreadId (kernel mode call) To monitor Scheduler

– Need to be at same priority– Must be non preemptable by Scheduler– DPC (Deferred Procedure Calls) execute at same priority as

Windows Scheduler called `Dispatcher’– Timed DPC running at 10ms=roughly equal to Windows standard

quantum.– Every 10ms, DPC preempts Scheduler and executes algorithm.– 10ms NOT GUARANTEED EXACT!!Windows is NOT REAL

TIME!!

Monitor I/O Operations

All user mode appln do I/O by Win32 API Win32 API forwards request to I/O Manager I/O Manager creates IRP (I/O Request Packet) and forwards to

appropriate Device Driver. For every thread( user mode or kernel mode), internal OS data

structure (undocumented) -> ETHREAD. ETHREAD contains list of IRPs thread currently blocked on. IRP contains name of I/O Devices. Therefore, thread to I/O Device located!! ETHREAD maintained in `ntoskrnl.exe’. Not Exported!! Therefore need

`debug symbols’. Hence need to run `checked build of Windows’. Have access to Internet!! Symbol Server of Microsoft at http://msdl.microsoft.com

Limitations

Thread Blocked on I/O Device DOES NOT mean I/O Device currently executing its order!!

I/O Device has internal queue.

Thread 4 blocked and billed but not actually serviced!! Excess Power billed!!

Procedures NOT CALL GRAPH!!

I/O DeviceThread 1

Thread 3

Thread 2

Thread 4

Order of P

rocess

Reference

Inside Windows 2000 Programming Applications for MS Windows Windows Loader – Matt Pietrik www.sysinternals.com www.osronline.com Powerscope Windows DDK

Questions