Operating Systems II Unit OS6: Device Management 6.3. Windows I/O - - PowerPoint PPT Presentation

operating systems ii unit os6 device management 6 3
SMART_READER_LITE
LIVE PREVIEW

Operating Systems II Unit OS6: Device Management 6.3. Windows I/O - - PowerPoint PPT Presentation

Operating Systems II Unit OS6: Device Management 6.3. Windows I/O Processing Prof. Dr. Andreas Polze, Andreas Grapentin, Bernhard Rabe Roadmap for Sec.on 6.3 Driver and Device Objects I/O Request


slide-1
SLIDE 1

Operating Systems II Unit OS6: Device Management 6.3. Windows I/O Processing

  • Prof. Dr. Andreas Polze,

Andreas Grapentin, Bernhard Rabe

slide-2
SLIDE 2

2 ¡

Roadmap ¡for ¡Sec.on ¡6.3 ¡

¡

  • Driver ¡and ¡Device ¡Objects ¡
  • I/O ¡Request ¡Packets ¡(IRP) ¡Processing ¡
  • Driver ¡Layering ¡and ¡Filtering ¡
  • Plug-­‑and-­‑Play ¡(PnP) ¡and ¡Power ¡Manager ¡

Opera.on ¡

  • Monitoring ¡I/O ¡Ac.vity ¡with ¡Filemon ¡
slide-3
SLIDE 3

3 ¡

Driver ¡Object ¡

  • A ¡driver ¡object ¡represents ¡a ¡loaded ¡driver ¡

– Names ¡are ¡visible ¡in ¡the ¡Object ¡Manager ¡ namespace ¡under ¡\Drivers ¡ – Dispatch ¡table: ¡A ¡driver ¡fills ¡in ¡its ¡driver ¡object ¡ with ¡pointers ¡to ¡its ¡I/O ¡func.ons ¡e.g. ¡open, ¡read, ¡ write ¡ – When ¡you ¡get ¡the ¡“One ¡or ¡More ¡Drivers ¡Failed ¡to ¡ Start” ¡message ¡its ¡because ¡the ¡Service ¡Control ¡ Manager ¡didn’t ¡find ¡one ¡or ¡more ¡driver ¡objects ¡in ¡ the ¡\Drivers ¡directory ¡for ¡drivers ¡that ¡should ¡have ¡ started ¡

slide-4
SLIDE 4

4 ¡

Device ¡Objects ¡

  • A ¡device ¡object ¡represents ¡an ¡instance ¡of ¡a ¡

device ¡

– Device ¡objects ¡are ¡linked ¡in ¡a ¡list ¡off ¡the ¡driver ¡

  • bject ¡

– A ¡driver ¡creates ¡device ¡objects ¡to ¡represent ¡the ¡ interface ¡to ¡the ¡logical ¡device, ¡so ¡each ¡generally ¡ has ¡a ¡unique ¡name ¡visible ¡under ¡\Devices ¡ – Device ¡objects ¡point ¡back ¡at ¡the ¡Driver ¡object ¡

slide-5
SLIDE 5

5 ¡

Driver ¡and ¡Device ¡Objects ¡

\TCPIP ¡ Driver ¡Object ¡

\Device\TCP ¡ \Device\UDP ¡ \Device\IP ¡

Dispatch ¡Table ¡ Open ¡ Write ¡ Read ¡ Loaded ¡Driver ¡Image ¡ Open(…) ¡ Read(…) ¡ Write(…) ¡

TCP/IP ¡Drivers ¡Driver ¡and ¡Device ¡Objects ¡

slide-6
SLIDE 6

6 ¡

File ¡Objects ¡

  • Represents ¡open ¡instance ¡of ¡a ¡device ¡(files ¡on ¡a ¡volume ¡are ¡ ¡virtual ¡

devices) ¡

– Applica.ons ¡and ¡drivers ¡“open” ¡devices ¡by ¡name ¡ – The ¡name ¡is ¡parsed ¡by ¡the ¡Object ¡Manager ¡ – When ¡an ¡open ¡succeeds ¡the ¡object ¡manager ¡creates ¡a ¡file ¡object ¡to ¡represent ¡ the ¡open ¡instance ¡of ¡the ¡device ¡and ¡a ¡file ¡handle ¡in ¡the ¡process ¡handle ¡table ¡

  • A ¡file ¡object ¡links ¡to ¡the ¡device ¡object ¡of ¡the ¡“device” ¡which ¡is ¡opened ¡
  • File ¡objects ¡store ¡addi.onal ¡informa.on ¡

– File ¡offset ¡for ¡sequen.al ¡access ¡ – File ¡open ¡characteris.cs ¡(e.g. ¡delete-­‑on-­‑close) ¡ – File ¡name ¡

slide-7
SLIDE 7

7 ¡

I/O ¡Request ¡Packets ¡

  • System ¡services ¡and ¡drivers ¡allocate ¡I/O ¡request ¡packets ¡to ¡describe ¡I/O ¡
  • A ¡request ¡packet ¡contains: ¡

– File ¡object ¡at ¡which ¡I/O ¡is ¡directed ¡ – I/O ¡characteris.cs ¡(e.g. ¡synchronous, ¡non-­‑buffered) ¡ – Byte ¡offset ¡ – Length ¡ – Buffer ¡loca.on ¡

  • The ¡I/O ¡Manager ¡locates ¡the ¡driver ¡to ¡which ¡to ¡hand ¡the ¡IRP ¡by ¡following ¡the ¡links: ¡

File ¡Object ¡ Device ¡Object ¡ Driver ¡Object ¡

slide-8
SLIDE 8

8 ¡

Pu^ng ¡it ¡Together: ¡Request ¡Flow ¡

Process ¡ NtDeviceIoControlFile ¡

Handle ¡ ¡ Table ¡ File ¡ ¡ Object ¡ Device ¡ ¡ Object ¡ Driver ¡ ¡ Object ¡ Dispatch ¡ ¡ Table ¡

DispatchDeviceControl( ¡DeviceObject, ¡Irp ¡) ¡ Driver ¡Code ¡

User ¡Mode ¡ Kernel ¡Mode ¡

IRP ¡

DeviceIoControl ¡

slide-9
SLIDE 9

9 ¡

I/O ¡Request ¡Packet ¡

Environment ¡ subsystem ¡or ¡ DLL ¡ Services ¡ I/O ¡manager ¡ IRP ¡header ¡ ¡ WRITE ¡ parameters ¡ File ¡

  • bject ¡

Device ¡

  • bject ¡

Driver ¡

  • bject ¡

IRP ¡stack ¡ loca.on ¡ Dispatch ¡ rou.ne(s) ¡ Start ¡I/O ¡ ISR ¡ DPC ¡ rou.ne ¡ Device ¡Driver ¡ 1) An application writes a file to the printer, passing a handle to the file object 2)The I/O manager creates an IRP and initializes first stack location 3)The I/O manager uses the driver object to locate the WRITE dispatch routine and calls it, passing the IRP User ¡mode ¡ Kernel ¡mode ¡

slide-10
SLIDE 10

10 ¡

IRP ¡data ¡

IRP ¡consists ¡of ¡two ¡parts: ¡

  • Fixed ¡por.on ¡(header): ¡

– Type ¡and ¡size ¡of ¡the ¡request ¡ – Whether ¡request ¡is ¡synchronous ¡or ¡asynchronous ¡ – Pointer ¡to ¡buffer ¡for ¡buffered ¡I/O ¡ – State ¡informa.on ¡(changes ¡with ¡progress ¡of ¡the ¡request) ¡

  • One ¡or ¡more ¡stack ¡loca.ons: ¡

– Func.on ¡code ¡ – Func.on-­‑specific ¡parameters ¡ – Pointer ¡to ¡caller‘s ¡file ¡object ¡

  • While ¡ac.ve, ¡IRPs ¡are ¡stored ¡in ¡a ¡thread-­‑specific ¡queue ¡

– I/O ¡system ¡may ¡free ¡any ¡outstanding ¡IRPs ¡if ¡thread ¡terminates ¡

slide-11
SLIDE 11

11 ¡

I/O ¡Processing ¡– ¡synch. ¡I/O ¡to ¡a ¡single-­‑layered ¡driver ¡

1. The ¡I/O ¡request ¡passes ¡through ¡a ¡subsystem ¡DLL ¡ 2. The ¡subsystem ¡DLL ¡calls ¡the ¡I/O ¡manager‘s ¡NtWriteFile() ¡service ¡ 3. I/O ¡manager ¡sends ¡the ¡request ¡in ¡form ¡of ¡an ¡IRP ¡to ¡the ¡driver ¡(a ¡device ¡driver) ¡ 4. The ¡driver ¡starts ¡the ¡I/O ¡opera.on ¡ 5. When ¡the ¡device ¡completes ¡the ¡opera.on ¡and ¡interrupts ¡the ¡CPU, ¡the ¡device ¡ driver ¡services ¡the ¡int. ¡ 6. The ¡I/O ¡manager ¡completes ¡the ¡I/O ¡request ¡

slide-12
SLIDE 12

12 ¡

Comple.ng ¡an ¡I/O ¡request ¡

Servicing ¡an ¡interrupt: ¡

– ISR ¡schedules ¡Deferred ¡Procedure ¡Call ¡(DPC); ¡dismisses ¡int. ¡ – DPC ¡rou.ne ¡starts ¡next ¡I/O ¡request ¡and ¡completes ¡interrupt ¡servicing ¡ – May ¡call ¡comple.on ¡rou.ne ¡of ¡higher-­‑level ¡driver ¡

I/O ¡comple.on: ¡

– Record ¡the ¡outcome ¡of ¡the ¡opera.on ¡in ¡an ¡I/O ¡status ¡block ¡ – Return ¡data ¡to ¡the ¡calling ¡thread ¡– ¡by ¡queuing ¡a ¡kernel-­‑mode ¡Asynchronous ¡ Procedure ¡Call ¡(APC) ¡ – APC ¡executes ¡in ¡context ¡of ¡calling ¡thread; ¡copies ¡data; ¡frees ¡IRP; ¡ sets ¡calling ¡thread ¡to ¡signaled ¡state ¡ – I/O ¡is ¡now ¡considered ¡complete; ¡wai.ng ¡threads ¡are ¡released ¡

slide-13
SLIDE 13

13 ¡

Flow ¡of ¡Interrupts ¡

Peripheral ¡Device ¡Controller ¡ CPU ¡Interrupt ¡ Controller ¡

CPU ¡Interrupt ¡ Service ¡Table ¡ 0 ¡ 2 ¡ 3 ¡ n ¡ ISR ¡Address ¡ Spin ¡Lock ¡ ¡ Dispatch ¡Code ¡

Interrupt ¡Object ¡

Read ¡from ¡device ¡ Acknowledge-­‑ Interrupt ¡ Request ¡DPC ¡

Driver ¡ISR ¡

Raise ¡IRQL ¡ Lower ¡IRQL ¡

KiInterruptDispatch ¡

Grab ¡Spinlock ¡ Drop ¡Spinlock ¡

slide-14
SLIDE 14

14 ¡

Servicing ¡an ¡Interrupt: ¡Deferred ¡Procedure ¡Calls ¡(DPCs) ¡

  • Used ¡to ¡defer ¡processing ¡from ¡higher ¡(device) ¡interrupt ¡level ¡to ¡a ¡lower ¡(dispatch) ¡

level ¡

– Also ¡used ¡for ¡quantum ¡end ¡and ¡.mer ¡expira.on ¡

  • Driver ¡(usually ¡ISR) ¡queues ¡request ¡

– One ¡queue ¡per ¡CPU. ¡ ¡DPCs ¡are ¡normally ¡queued ¡to ¡the ¡current ¡processor, ¡but ¡can ¡be ¡ targeted ¡to ¡other ¡CPUs ¡ – Executes ¡specified ¡procedure ¡at ¡dispatch ¡IRQL ¡(or ¡“dispatch ¡level”, ¡also ¡“DPC ¡level”) ¡when ¡ all ¡higher-­‑IRQL ¡work ¡(interrupts) ¡completed ¡ – Maximum ¡.mes ¡recommended: ¡ISR: ¡10 ¡µsec, ¡DPC: ¡25 ¡µsec ¡

  • See ¡hlp://www.microsom.com/whdc/driver/perform/mmdrv.mspx ¡ ¡

queue ¡head ¡ DPC ¡object ¡ DPC ¡object ¡ DPC ¡object ¡

slide-15
SLIDE 15

15 ¡ DPC ¡

Delivering ¡a ¡DPC ¡

DPC ¡rou.nes ¡can ¡call ¡kernel ¡func.ons ¡ but ¡can‘t ¡call ¡system ¡services, ¡generate ¡ page ¡faults, ¡or ¡create ¡or ¡wait ¡on ¡objects ¡ DPC ¡rou.nes ¡can‘t ¡ assume ¡what ¡ process ¡address ¡ space ¡is ¡currently ¡ mapped ¡

Interrupt ¡ dispatch ¡table ¡ high ¡ Power ¡failure ¡ Dispatch/DPC ¡ APC ¡ Low ¡ DPC ¡

  • 1. ¡Timer ¡expires, ¡kernel ¡

queues ¡DPC ¡that ¡will ¡ release ¡all ¡wai.ng ¡threads ¡ Kernel ¡requests ¡SW ¡int. ¡ DPC ¡ DPC ¡ DPC ¡queue ¡

  • 2. ¡DPC ¡interrupt ¡occurs ¡

when ¡IRQL ¡drops ¡below ¡ dispatch/DPC ¡level ¡ dispatcher ¡

  • 3. ¡Amer ¡DPC ¡interrupt, ¡

control ¡transfers ¡to ¡ thread ¡dispatcher ¡

  • 4. ¡Dispatcher ¡executes ¡each ¡DPC ¡

rou.ne ¡in ¡DPC ¡queue ¡

slide-16
SLIDE 16

16 ¡

I/O ¡Comple.on: ¡ ¡Asynchronous ¡Procedure ¡Calls ¡(APCs) ¡

  • Execute ¡code ¡in ¡context ¡of ¡a ¡par.cular ¡user ¡thread ¡

– APC ¡rou.nes ¡can ¡acquire ¡resources ¡(objects), ¡incur ¡page ¡faults, ¡ call ¡system ¡services ¡

  • APC ¡queue ¡is ¡thread-­‑specific ¡
  • User ¡mode ¡& ¡kernel ¡mode ¡APCs ¡

– Permission ¡required ¡for ¡user ¡mode ¡APCs ¡

  • Execu.ve ¡uses ¡APCs ¡to ¡complete ¡work ¡in ¡thread ¡space ¡

– Wait ¡for ¡asynchronous ¡I/O ¡opera.on ¡ – Emulate ¡delivery ¡of ¡POSIX ¡signals ¡ – Make ¡threads ¡suspend/terminate ¡itself ¡(env. ¡subsystems) ¡

  • APCs ¡are ¡delivered ¡when ¡thread ¡is ¡in ¡alertable ¡wait ¡state ¡

– WaitForMul.pleObjectsEx(), ¡SleepEx() ¡

slide-17
SLIDE 17

17 ¡

Asynchronous ¡Procedure ¡Calls ¡(APCs) ¡

  • Special ¡kernel ¡APCs ¡

– Run ¡in ¡kernel ¡mode, ¡at ¡IRQL ¡1 ¡ – Always ¡deliverable ¡unless ¡thread ¡is ¡already ¡at ¡IRQL ¡1 ¡or ¡above ¡ – Used ¡for ¡I/O ¡comple.on ¡repor.ng ¡from ¡“arbitrary ¡thread ¡context” ¡ – Kernel-­‑mode ¡interface ¡is ¡linkable, ¡but ¡not ¡documented ¡

  • Normal ¡kernel ¡APCs ¡

– Always ¡deliverable ¡if ¡at ¡IRQL ¡0, ¡unless ¡explicitly ¡disabled ¡ ¡ (disable ¡with ¡KeEnterCri.calRegion) ¡

  • User ¡mode ¡APCs ¡

– Used ¡for ¡I/O ¡comple.on ¡callback ¡rou.nes ¡(see ¡ReadFileEx, ¡WriteFileEx); ¡also, ¡ QueueUserApc ¡ – Only ¡deliverable ¡when ¡thread ¡is ¡in ¡“alertable ¡wait” ¡

Thread ¡ Object ¡ K ¡ U ¡ APC ¡objects ¡

slide-18
SLIDE 18

18 ¡

Driver ¡Layering ¡and ¡Filtering ¡

  • To ¡divide ¡func.onality ¡across ¡drivers, ¡

provide ¡added ¡value, ¡etc. ¡ ¡

– Only ¡the ¡lowest ¡layer ¡talks ¡to ¡the ¡I/O ¡ hardware ¡

  • “Filter ¡drivers” ¡alach ¡their ¡devices ¡

to ¡other ¡devices ¡

– They ¡see ¡all ¡requests ¡first ¡and ¡can ¡ manipulate ¡them ¡ – Example ¡filter ¡drivers: ¡

  • File ¡system ¡filter ¡driver ¡
  • Bus ¡filter ¡driver ¡

Process ¡

User ¡Mode ¡ Kernel ¡Mode ¡

System ¡Services ¡ I/O ¡Manager ¡ File ¡System ¡ ¡ Driver ¡ Volume ¡ ¡ Manager ¡ Driver ¡ Disk ¡Driver ¡

IRP ¡

slide-19
SLIDE 19

19 ¡

Driver ¡Filtering: ¡ ¡Volume ¡Shadow ¡Copy ¡

  • New ¡to ¡XP/Server ¡2003 ¡

– Addresses ¡the ¡“backup ¡open ¡files” ¡problem ¡

  • Volumes ¡can ¡be ¡“snapsholed” ¡
  • Allows ¡“hot ¡backup” ¡(including ¡open ¡files) ¡
  • Applica.ons ¡can ¡.e ¡in ¡with ¡mechanism ¡to ¡ensure ¡consistent ¡snapshots ¡

– Database ¡servers ¡flush ¡transac.ons ¡ – Windows ¡components ¡ ¡ such ¡as ¡the ¡Registry ¡ ¡ flush ¡data ¡files ¡

  • Different ¡snapshot ¡providers ¡ ¡

can ¡implement ¡different ¡snapshot ¡ ¡ mechanisms: ¡ – Copy-­‑on-­‑write ¡ – Mirroring ¡

Volsnap ¡is ¡the ¡built-­‑in ¡provider: ¡

  • Built ¡into ¡Windows ¡XP/Server ¡2003 ¡
  • Implements ¡copy-­‑on-­‑write ¡snapshots ¡
  • Saves ¡volume ¡changes ¡in ¡files ¡on ¡the ¡volume ¡
  • Uses ¡defrag ¡API ¡to ¡determine ¡where ¡the ¡file ¡is ¡

and ¡where ¡paging ¡file ¡is ¡to ¡avoid ¡tracking ¡their ¡ changes ¡

¡

slide-20
SLIDE 20

20 ¡

Volume ¡Shadow ¡ ¡ Copy ¡Driver ¡ (volsnap.sys) ¡ Mirror ¡provider ¡ Oracle ¡ SQL ¡ Volume ¡Shadow ¡ Copy ¡Service ¡ Backup ¡ ¡ ApplicaZon ¡

1. Backup application requests shadow copy

  • 2. Writers told

to freeze activity

  • 3. Providers asked to

create volume shadow copies

  • 4. Writers told

to resume (“thaw”) activity

Writers ¡ Providers ¡

  • 5. ¡Backup ¡applicaZon ¡

saves ¡data ¡from ¡volume ¡ ¡ Shadow ¡copies ¡

Volume ¡Snapshots ¡

slide-21
SLIDE 21

21 ¡

Volsnap.sys ¡

File System Driver Volsnap.sys a b c a d … b c Backup read of sector c

Snapshot

Backup Application Application Shadow Volume C: C: Application read of sector c All reads of sector d

slide-22
SLIDE 22

22 ¡

Shadow ¡Copies ¡of ¡Shared ¡Folders ¡

  • When ¡enabled, ¡Server ¡

2003 ¡uses ¡shadow ¡copy ¡ to ¡periodically ¡create ¡ snapshots ¡of ¡volumes ¡

  • Schedule ¡and ¡space ¡used ¡

is ¡configurable ¡

slide-23
SLIDE 23

23 ¡

Shadow ¡Copies ¡on ¡Shared ¡Folders ¡

  • Shadow ¡copies ¡are ¡only ¡

exposed ¡as ¡network ¡shares ¡

  • Clients ¡may ¡install ¡an ¡Explorer ¡

extension ¡that ¡integrates ¡with ¡ the ¡file ¡server ¡and ¡let’s ¡them ¡

– View ¡the ¡state ¡of ¡folders ¡and ¡files ¡ within ¡a ¡snapshot ¡ – Rollback ¡individual ¡folders ¡and ¡ files ¡to ¡a ¡snapshot ¡

slide-24
SLIDE 24

24 ¡

The ¡PnP ¡Manager ¡

  • In ¡NT ¡4.0 ¡each ¡device ¡driver ¡is ¡responsible ¡for ¡

enumera.ng ¡all ¡supported ¡busses ¡in ¡search ¡of ¡ devices ¡they ¡support ¡

  • As ¡of ¡Windows ¡2000, ¡the ¡PnP ¡Manager ¡has ¡

bus ¡drivers ¡enumerate ¡their ¡busses ¡and ¡ inform ¡it ¡of ¡present ¡devices ¡

  • If ¡the ¡device ¡driver ¡for ¡a ¡device ¡not ¡already ¡

present ¡on ¡the ¡system, ¡the ¡PnP ¡Manager ¡in ¡ the ¡kernel ¡informs ¡the ¡user-­‑mode ¡PnP ¡ Manager ¡to ¡start ¡the ¡Hardware ¡Wizard ¡

slide-25
SLIDE 25

25 ¡

The ¡PnP ¡Manager ¡

  • Once ¡a ¡device ¡driver ¡is ¡located, ¡ ¡

the ¡PnP ¡Manager ¡determines ¡if ¡ ¡the ¡driver ¡is ¡signed ¡ – ¡If ¡the ¡driver ¡ ¡ is ¡not ¡signed, ¡the ¡system’s ¡driver ¡ ¡ signing ¡policy ¡determines ¡whether ¡ ¡

  • r ¡not ¡the ¡driver ¡is ¡installed ¡ ¡

¡ ¡ ¡

  • Amer ¡loading ¡a ¡driver, ¡the ¡PnP ¡Manager ¡calls ¡the ¡driver’s ¡AddDevice ¡entry ¡point ¡

– The ¡driver ¡informs ¡the ¡PnP ¡Manager ¡of ¡the ¡device’s ¡resource ¡requirements ¡ – The ¡PnP ¡Manager ¡reconfigures ¡other ¡devices ¡to ¡accommodate ¡the ¡new ¡device ¡

slide-26
SLIDE 26

26 ¡

The ¡PnP ¡Manager ¡

  • Enumera.on ¡is ¡recursive, ¡and ¡directed ¡by ¡bus ¡drivers ¡

– Bus ¡drivers ¡iden.fy ¡device ¡on ¡a ¡bus ¡

  • As ¡busses ¡and ¡devices ¡are ¡registered, ¡a ¡device ¡tree ¡is ¡constructed, ¡and ¡

filled ¡in ¡with ¡devices ¡

Root ACPI PCI USB Video Disk Key- board Battery

Device Tree

slide-27
SLIDE 27

27 ¡

Resource ¡Arbitra.on ¡

  • Devices ¡require ¡system ¡hardware ¡resources ¡to ¡func.on ¡(e.g. ¡IRQs, ¡I/O ¡

ports) ¡

  • The ¡PnP ¡Manager ¡keeps ¡track ¡of ¡hardware ¡resource ¡assignments ¡
  • If ¡a ¡device ¡requires ¡a ¡resource ¡that’s ¡already ¡been ¡assigned, ¡the ¡PnP ¡

Manager ¡tries ¡to ¡reassign ¡resources ¡in ¡order ¡to ¡accommodate ¡ ¡

  • Example: ¡ ¡
  • 1. Device ¡1 ¡can ¡use ¡IRQ ¡5 ¡or ¡IRQ ¡6 ¡
  • 2. PnP ¡Manager ¡assigns ¡it ¡IRQ ¡5 ¡
  • 3. Device ¡2 ¡can ¡only ¡use ¡IRQ ¡5 ¡
  • 4. PnP ¡Manager ¡reassigns ¡Device ¡1 ¡IRQ ¡6 ¡
  • 5. PnP ¡Manager ¡assigns ¡Device ¡2 ¡IRQ ¡5 ¡
slide-28
SLIDE 28

28 ¡

Plug ¡and ¡Play ¡(PnP) ¡State ¡Transi.ons ¡

  • PnP ¡manager ¡recognizes ¡hardware, ¡allocates ¡resources, ¡loads ¡driver, ¡

no.fies ¡about ¡config. ¡changes ¡

Not ¡started ¡ Started ¡ Pending ¡stop ¡ Stopped ¡ Pending ¡ ¡ remove ¡ Surprise ¡ remove ¡ Removed ¡

Start-­‑device ¡ command ¡ Start-­‑device ¡ command ¡ Query-­‑stop ¡ command ¡ Stop ¡ command ¡ Query-­‑remove ¡ command ¡ Surprise-­‑remove ¡ command ¡ Remove ¡ command ¡ Remove ¡ command ¡

Device ¡Plug ¡and ¡Play ¡state ¡transi.ons ¡

slide-29
SLIDE 29

29 ¡

The ¡Power ¡Manager ¡

  • A ¡system ¡must ¡have ¡an ¡ACPI-­‑compliant ¡BIOS ¡for ¡full ¡compa.bility ¡(APM ¡gives ¡

limited ¡power ¡support) ¡

  • A ¡number ¡of ¡factors ¡guide ¡the ¡Power ¡Manager’s ¡decision ¡to ¡change ¡power ¡state: ¡

– System ¡ac.vity ¡level ¡ ¡ – System ¡balery ¡level ¡ ¡ – Shutdown, ¡hibernate, ¡or ¡sleep ¡requests ¡from ¡ ¡ applica.ons ¡ ¡ – User ¡ac.ons, ¡such ¡as ¡pressing ¡the ¡power ¡bulon ¡ ¡ – Control ¡Panel ¡power ¡se^ngs ¡

  • The ¡system ¡can ¡go ¡into ¡low ¡power ¡modes, ¡ ¡

but ¡it ¡requires ¡the ¡coopera.on ¡of ¡every ¡ ¡ device ¡driver ¡-­‑ ¡applica.ons ¡can ¡provide ¡their ¡input ¡as ¡well ¡

slide-30
SLIDE 30

30 ¡

The ¡Power ¡Manager ¡

  • There ¡are ¡different ¡system ¡power ¡states: ¡

– On ¡

  • Everything ¡is ¡fully ¡on ¡

– Standby ¡

  • Intermediate ¡states ¡
  • Lower ¡standby ¡states ¡must ¡consume ¡less ¡power ¡than ¡higher ¡ones ¡

– Hiberna.ng ¡

  • Save ¡memory ¡to ¡disk ¡in ¡a ¡file ¡called ¡hiberfil.sys ¡in ¡the ¡root ¡directory ¡of ¡the ¡

system ¡volume ¡ – Off ¡

  • All ¡devices ¡are ¡off ¡
  • Device ¡drivers ¡manage ¡their ¡own ¡power ¡level ¡

– Only ¡a ¡driver ¡knows ¡the ¡capabili.es ¡of ¡their ¡device ¡ – Some ¡devices ¡only ¡have ¡“on” ¡and ¡“off”, ¡others ¡have ¡intermediate ¡states ¡

  • Drivers ¡can ¡control ¡their ¡own ¡power ¡independently ¡of ¡system ¡power ¡

– Display ¡can ¡dim, ¡disk ¡spin ¡down, ¡etc. ¡

slide-31
SLIDE 31

31 ¡

Power ¡Manager ¡

  • based ¡on ¡the ¡Advanced ¡Configura.on ¡and ¡Power ¡Interface ¡(ACPI) ¡

State Power Consumption Software Resumption HW Latency S0 (fully on) Maximum Not applicable None S1 (sleeping) Less than S0, more than S2 System resumes where it left

  • ff (returns to S0)

Less than 2 sec. S2 (sleeping) Less than S1, more than S3 System resumes where it left

  • ff (returns to S0)

2 or more sec. S3 (sleeping) Less than S2, processor is off System resumes where it left

  • ff (returns to S0)

Same as S2 S4 (sleeping) Trickle current to power button and wake circuitry System restarts from hibernate file and resumes where it left off (returns to S0) Long and undefined S5 (fully off) Trickle current to power button System boot Long and undefined System ¡Power-­‑State ¡Defini.ons ¡

slide-32
SLIDE 32

32 ¡

Troubleshoo.ng ¡I/O ¡Ac.vity ¡

  • Filemon ¡can ¡be ¡a ¡great ¡help ¡to ¡understand ¡and ¡troubleshoo.ng ¡I/O ¡problems ¡
  • Two ¡basic ¡techniques: ¡

– Go ¡to ¡end ¡of ¡log ¡and ¡look ¡backwards ¡to ¡where ¡problem ¡occurred ¡or ¡is ¡evident ¡and ¡ focused ¡on ¡the ¡last ¡things ¡done ¡ – Compare ¡a ¡good ¡log ¡with ¡a ¡bad ¡log ¡

  • Omen ¡comparing ¡the ¡I/O ¡ac.vity ¡of ¡a ¡failing ¡process ¡with ¡one ¡that ¡works ¡may ¡

point ¡to ¡the ¡problem ¡

– Have ¡to ¡first ¡massage ¡log ¡file ¡to ¡remove ¡data ¡that ¡differs ¡run ¡to ¡run ¡

  • Delete ¡first ¡3 ¡columns ¡(they ¡are ¡always ¡different: ¡line ¡#, ¡.me, ¡process ¡id) ¡

– Easy ¡to ¡do ¡with ¡Excel ¡by ¡dele.ng ¡columns ¡

– Then ¡compare ¡with ¡FC ¡(built ¡in ¡tool) ¡or ¡Windiff ¡(Resource ¡Kit) ¡

slide-33
SLIDE 33

33 ¡

Filemon ¡

  • # ¡-­‑ ¡opera.on ¡number ¡
  • Process: ¡image ¡name ¡+ ¡process ¡id ¡
  • Request: ¡internal ¡I/O ¡request ¡code ¡
  • Result: ¡return ¡code ¡from ¡I/O ¡opera.on ¡
  • Other: ¡flags ¡passed ¡on ¡I/O ¡request ¡
slide-34
SLIDE 34

34 ¡

Using ¡Filemon ¡

  • Start/stop ¡logging ¡(Control/E) ¡
  • Clear ¡display ¡(Control/X) ¡
  • Open ¡Explorer ¡window ¡to ¡folder ¡containing ¡file: ¡

– Double ¡click ¡on ¡a ¡line ¡does ¡this ¡

  • Find ¡– ¡finds ¡text ¡within ¡window ¡
  • Save ¡to ¡log ¡file ¡
  • Advanced ¡mode ¡
  • Network ¡op.on ¡
slide-35
SLIDE 35

35 ¡

What ¡Filemon ¡Monitors ¡

  • By ¡default ¡Filemon ¡traces ¡all ¡file ¡I/O ¡to: ¡

– Local ¡non-­‑removable ¡media ¡ – Network ¡shares ¡

  • Stores ¡all ¡output ¡in ¡listview ¡

– Can ¡exhaust ¡virtual ¡memory ¡in ¡long ¡ ¡ runs ¡ – You ¡can ¡limit ¡captured ¡data ¡with ¡history ¡ ¡ depth ¡

  • You ¡can ¡limit ¡what ¡is ¡monitored: ¡

– What ¡volumes ¡to ¡watch ¡in ¡Volumes ¡menu ¡ – What ¡paths ¡and ¡processes ¡to ¡watch ¡in ¡Filter ¡dialog ¡ – What ¡opera.ons ¡to ¡watch ¡in ¡Filter ¡dialog ¡(reads, ¡ writes, ¡successes ¡and ¡errors) ¡

slide-36
SLIDE 36

36 ¡

Filemon ¡Filtering ¡and ¡Highligh.ng ¡

  • Include ¡and ¡exclude ¡filters ¡are ¡substring ¡matches ¡against ¡the ¡

process ¡and ¡path ¡columns ¡

– Exclude ¡overrides ¡include ¡filter ¡

  • Be ¡careful ¡that ¡you ¡don’t ¡exclude ¡poten.ally ¡useful ¡data ¡

– Capture ¡everything ¡and ¡save ¡the ¡log ¡ – Then ¡apply ¡filters ¡(you ¡can ¡always ¡reload ¡the ¡log) ¡

  • Highlight ¡matches ¡all ¡columns ¡
slide-37
SLIDE 37

37 ¡

Basic ¡vs ¡Advanced ¡Mode ¡

  • Basic ¡mode ¡massages ¡output ¡to ¡be ¡sysadmin-­‑

friendly ¡and ¡target ¡common ¡troubleshoo.ng ¡

  • Things ¡you ¡don’t ¡see ¡in ¡Basic ¡mode: ¡

– Raw ¡I/O ¡request ¡names ¡ – Various ¡internal ¡file ¡system ¡opera.ons ¡ – Ac.vity ¡in ¡the ¡System ¡process ¡ – Page ¡file ¡I/O ¡ – Filemon ¡file ¡system ¡ac.vity ¡

slide-38
SLIDE 38

38 ¡

Understanding ¡Disk ¡Ac.vity ¡

  • Use ¡Filemon ¡to ¡see ¡why ¡you’re ¡hard ¡disk ¡is ¡crunching ¡

– Process ¡performance ¡counters ¡show ¡I/O ¡ac.vity, ¡but ¡not ¡to ¡where ¡ – System ¡performance ¡counters ¡show ¡which ¡disks ¡are ¡being ¡hit, ¡but ¡not ¡ which ¡files ¡or ¡which ¡process ¡ – Filemon ¡pinpoints ¡which ¡file(s) ¡are ¡being ¡accessed, ¡by ¡whom, ¡and ¡how ¡ frequently ¡

  • You ¡can ¡also ¡use ¡Filemon ¡on ¡a ¡server ¡to ¡determine ¡which ¡file(s) ¡

were ¡being ¡accessed ¡most ¡frequently ¡

– Import ¡into ¡Excel ¡and ¡make ¡a ¡pie ¡chart ¡by ¡file ¡name ¡or ¡opera.on ¡type ¡ – Move ¡heavy-­‑access ¡files ¡to ¡a ¡different ¡disk ¡on ¡a ¡different ¡controller ¡

slide-39
SLIDE 39

39 ¡

Polling ¡and ¡File ¡Change ¡No.fica.on ¡

  • Many ¡applica.ons ¡respond ¡to ¡file ¡and ¡directory ¡changes ¡

– A ¡poorly ¡wrilen ¡applica.on ¡will ¡“poll” ¡for ¡changes ¡ – A ¡well-­‑wrilen ¡applica.on ¡will ¡request ¡no.fica.on ¡by ¡the ¡system ¡of ¡ changes ¡

  • Polling ¡for ¡changes ¡causes ¡performance ¡degrada.on ¡

– Context ¡switches ¡including ¡TLB ¡flush ¡ – Cache ¡invalida.on ¡ – Physical ¡memory ¡usage ¡ – CPU ¡usage ¡

  • Alterna.ve: ¡file ¡change ¡no.fica.on ¡ ¡
  • When ¡you ¡run ¡Filemon ¡on ¡an ¡idle ¡system ¡you ¡should ¡only ¡see ¡

bursty ¡system ¡background ¡ac.vity ¡

– Polling ¡is ¡visible ¡as ¡periodic ¡accesses ¡to ¡the ¡same ¡files ¡and ¡directories ¡ – File ¡change ¡no.fica.on ¡is ¡visible ¡as ¡directory ¡queries ¡that ¡have ¡no ¡ result ¡

slide-40
SLIDE 40

40 ¡

Example: ¡Word ¡Crash ¡

  • While ¡typing ¡in ¡the ¡document ¡Word ¡XP ¡would ¡

intermilently ¡close ¡without ¡any ¡error ¡ message ¡

  • To ¡troubleshoot ¡ran ¡Filemon ¡on ¡user’s ¡system ¡

– Set ¡the ¡history ¡depth ¡to ¡10,000 ¡ – Asked ¡user ¡to ¡send ¡Filemon ¡log ¡when ¡Word ¡exited ¡

slide-41
SLIDE 41

41 ¡

Solu.on: ¡Word ¡Crash ¡

  • Working ¡backwards, ¡the ¡first ¡“strange” ¡or ¡

unexplainable ¡behavior ¡are ¡the ¡constant ¡reads ¡ past ¡end ¡of ¡file ¡to ¡MSSP3ES.LEX ¡ ¡ ¡ ¡ ¡

  • User ¡looked ¡up ¡what ¡.LEX ¡file ¡was ¡

– Related ¡to ¡Word ¡proofing ¡tools ¡ – Uninstalled ¡and ¡reinstalled ¡proofing ¡tools ¡& ¡ problem ¡went ¡away ¡

slide-42
SLIDE 42

42 ¡

Example: ¡Useless ¡Excel ¡Error ¡Message ¡

  • Excel ¡reports ¡an ¡error ¡“Unable ¡to ¡read ¡file" ¡

when ¡star.ng ¡

slide-43
SLIDE 43

43 ¡

Solu.on: ¡Useless ¡Excel ¡Error ¡Message ¡

  • Filemon ¡trace ¡shows ¡Excel ¡reading ¡file ¡in ¡

XLStart ¡folder ¡ ¡

– All ¡Office ¡apps ¡autoload ¡files ¡in ¡their ¡start ¡folders ¡

  • Should ¡have ¡reported: ¡

– Name ¡and ¡loca.on ¡of ¡file ¡ – Reason ¡why ¡it ¡didn’t ¡like ¡it ¡

slide-44
SLIDE 44

44 ¡

Further ¡Reading ¡

¡

  • Mark ¡E. ¡Russinovich ¡and ¡David ¡A. ¡Solomon, ¡ ¡

Microsom ¡Windows ¡Internals, ¡4th ¡Edi.on, ¡ Microsom ¡Press, ¡2004. ¡

– I/O ¡Processing ¡(from ¡pp. ¡561) ¡ – The ¡Plug ¡and ¡Play ¡(PnP) ¡Manager ¡(from ¡pp. ¡590) ¡ – The ¡Power ¡Manager ¡(from ¡pp. ¡607) ¡ – Troubleshoo.ng ¡File ¡System ¡Problems ¡(from ¡pp. ¡ 711) ¡

slide-45
SLIDE 45

45 ¡

Source ¡Code ¡References ¡

  • Windows ¡Research ¡Kernel ¡sources ¡

– \base\ntos\io ¡– ¡I/O ¡Manager ¡ – \base\ntos\inc\io.h ¡– ¡addi.onal ¡structure/type ¡ defini.ons ¡ – \base\ntos\verifer ¡– ¡Driver ¡Verifier ¡ – \base\ntos\inc\verifier.h ¡– ¡addi.onal ¡structure/ type ¡defini.ons ¡

slide-46
SLIDE 46

Current ¡Trends ¡

  • SSDs ¡

– Large ¡Block ¡Size ¡ – TRIM ¡func.onality ¡

  • Hybrid ¡Drives ¡

– Apple ¡Fusion ¡Drive ¡is ¡fast ¡because ¡of ¡OS ¡ integra.on ¡

  • Long ¡term ¡Storage ¡

– Amazon ¡Glacier: ¡0,01 ¡USD ¡/ ¡GB ¡/ ¡month ¡