《深入理解Windows操作系统》笔记3

X86/X64的页面错误异常号是0xe,页面错误:一个线程企图访问虚拟内存中没有定义的或者已经存在的页面时产生的异常。Windows支持的硬件体系结构允许最多可达256IDT项。一台PC所能支持的中断IRQ数量是由该机器的中断控制器的具体设计决定的。

由于大多数X86都依赖一个硬件i8259A可编程中断控制器(PIC)在单处理器系统上有15条中断线。

0: kd> !idt

Dumping IDT:

37:     806e6864 hal!PicSpuriousService37

3d:     806e7e2c hal!HalpApcInterrupt

41:     806e7c88 hal!HalpDispatchInterrupt

50:     806e693c hal!HalpApicRebootService

62:     8a301954 8a38ecb8 (KINTERRUPT 8a301918)

63:     89d3d044 NDIS!ndisMIsr (KINTERRUPT 89d3d008)

                 8a225cb8 (KINTERRUPT 89cc7bb0)

73:     8a056bec VIDEOPRT!pVideoPortInterrupt (KINTERRUPT 8a056bb0)

                 8a225cb8 (KINTERRUPT 89cd8938)

                 8a225cb8 (KINTERRUPT 89ccf938)

83:     8a2b6afc 8a38ecb8 (KINTERRUPT 8a2b6ac0)

                 8a38ecb8 (KINTERRUPT 8a2b5bb0)

                 NDIS!ndisMIsr (KINTERRUPT 89ce2930)

92:     899e1bec serial!SerialCIsrSw (KINTERRUPT 899e1bb0)

93:     899e8044 i8042prt!I8042KeyboardInterruptService (KINTERRUPT 899e8008)

a4:     89cdfbec 8a225cb8 (KINTERRUPT 89cdfbb0)

                 8a225cb8 (KINTERRUPT 89cd0bb0)

b1:     8a36f044 ACPI!ACPIInterruptServiceRoutine (KINTERRUPT 8a36f008)

                 8a1d0cb8 (KINTERRUPT 8a075508)

b4:     89d38bec 8a225cb8 (KINTERRUPT 89d38bb0)

                 HDAudBus!AzController::Isr (KINTERRUPT 89d32410)

c1:     806e6ac0 hal!HalpBroadcastCallService

d1:     806e5e54 hal!HalpClockInterrupt

e1:     806e7048 hal!HalpIpiHandler

e3:     806e6dac hal!HalpLocalApicErrorService

fd:     806e75a8 hal!HalpProfileInterrupt

fe:     806e7748 hal!HalpPerfInterrupt

查看PICAPIC

0: kd> !pic

----- IRQ Number ----- 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F

Physically in service:  Y  Y  .  Y  .  .  .  .  Y  Y  .  Y  .  .  .  .

Physically masked:      Y  Y  Y  .  Y  .  Y  .  Y  Y  Y  .  Y  .  Y  .

Physically requested:   .  Y  .  Y  .  .  .  .  .  Y  .  Y  .  .  .  .

0: kd>

对于本机单CPU双核来看:是否使用了MPS HAL

lkd> !apic

Apic @ fffe0000  ID:1 (80050010)  LogDesc:02000000  DestFmt:ffffffff  TPR 41

TimeCnt: 0be420e0clk  SpurVec:1f  FaultVec:e3  error:0

Ipi Cmd: 01000000`00040041  Vec:41  FixedDel    Dest=Self      edg high       

Timer..: 00000000`000300fd  Vec:FD  FixedDel    Dest=Self      edg high      m

Linti0.: 00000000`0001001f  Vec:1F  FixedDel    Dest=Self      edg high      m

Linti1.: 00000000`000184ff  Vec:FF  NMI         Dest=Self      lvl high      m

TMR: 63, 73, A4, B1, B4

IRR: 

ISR: 

0: kd> !ioapic

IoApic @ FEC00000  ID:0 (0)  Arb:0

Inti00.: 00000000`00000000  Vec:00  FixedDel  Ph:00000000      edg high

仅在windows 2003上菜支持!Irql查看一个处理器的IRQL

lkd> !pcr

KPCR for Processor 0 at ffdff000:

    Major 1 Minor 1

NtTib.ExceptionList: ffffffff

    NtTib.StackBase: 805524f0

   NtTib.StackLimit: 8054f700

 NtTib.SubSystemTib: 00000000

      NtTib.Version: 00000000

  NtTib.UserPointer: 00000000

      NtTib.SelfTib: 00000000

            SelfPcr: ffdff000

               Prcb: ffdff120

               Irql: 00000000

                IRR: 00000000

                IDR: ffffffff

      InterruptMode: 00000000

                IDT: 8003f400

                GDT: 8003f000

                TSS: 80042000

      CurrentThread: 8055ce60

         NextThread: 00000000

         IdleThread: 8055ce60

          DpcQueue: 

可以使用DDK上头文件中的ntddk.H定义的PCRPRCB的信息。不幸的是在不适用延迟IRQL的系统上,比如本机器AMD Athlon64 X2 6000+ windows XP SP3上就不支持,因此为0,需要至少WINDOWS 2003

http://msdn.microsoft.com/zh-cn/windows/hardware/gg463382
下载安装kernrates软件,进行内核性能剖析程序来分析性能。

C:\Program Files\Support Tools>cd "c:\Program Files\KrView\Kernrates"

C:\Program Files\KrView\Kernrates>dir

 驱动器 中的卷没有标签。

 卷的序列号是 18F6-A188

 C:\Program Files\KrView\Kernrates 的目录

2012-02-07  16:57    

          .

2012-02-07  16:57    

          ..

2003-11-07  16:58           269,312 Kernrate_i386_Win2000.exe

2003-11-07  16:58           129,024 Kernrate_i386_XP.exe

2003-11-07  16:59           326,656 Kernrate_ia64_XP.exe

               3 个文件        724,992 字节

               2 个目录 146,187,862,016 可用字节

C:\Program Files\KrView\Kernrates>Kernrate_i386_XP.exe

 /==============================\

<         KERNRATE LOG           >

 \==============================/

Date: 2012/02/07   Time: 16:58:17

Machine Name: AMD6000

Number of Processors: 2

PROCESSOR_ARCHITECTURE: x86

PROCESSOR_LEVEL: 15

PROCESSOR_REVISION: 4303

Physical Memory: 2816 MB

Pagefile Total: 2656 MB

Virtual Total: 2047 MB

PageFile1: (null), 0MB

OS Version: 5.1 Build 2600 Service-Pack: 3.0

WinDir: C:\WINDOWS

Kernrate User-Specified Command Line:

Kernrate_i386_XP.exe

Kernel Profile (PID = 0): Source= Time,

Using Kernrate Default Rate of 25000 events/hit

Starting to collect profile data

***> Press ctrl-c to finish collecting profile data

------------Overall Summary:--------------

P0     K 0:00:08.562 ( 8.8%)  U 0:00:11.109 (11.4%)  I 0:01:17.703 (79.8%)  DPC

0:00:01.656 ( 1.7%)  Interrupt 0:00:00.062 ( 0.1%)

       Interrupts= 142334, Interrupt Rate= 1462/sec.

P1     K 0:00:10.562 (10.8%)  U 0:00:06.406 ( 6.6%)  I 0:01:20.406 (82.6%)  DPC

0:00:05.828 ( 6.0%)  Interrupt 0:00:00.265 ( 0.3%)

       Interrupts= 73111, Interrupt Rate= 751/sec.

TOTAL  K 0:00:19.125 ( 9.8%)  U 0:00:17.515 ( 9.0%)  I 0:02:38.109 (81.2%)  DPC

0:00:07.484 ( 3.8%)  Interrupt 0:00:00.328 ( 0.2%)

       Total Interrupts= 215445, Total Interrupt Rate= 2213/sec.

Total Profile Time = 97375 msec

                                       BytesStart          BytesStop         Byt

esDiff.

    Available Physical Memory   ,      1864134656,      2005221376,       141086

720

    Available Pagefile(s)       ,      1864282112,      2005024768,       140742

656

    Available Virtual           ,      2131689472,      2130640896,        -1048

576

    Available Extended Virtual  ,               0,               0,

  0

                                  Total      Avg. Rate

    Context Switches     ,       571193,         5866/sec.

    System Calls         ,      2132527,         21900/sec.

    Page Faults          ,       325110,         3339/sec.

    I/O Read Operations  ,        11188,         115/sec.

    I/O Write Operations ,         8299,         85/sec.

    I/O Other Operations ,        29196,         300/sec.

    I/O Read Bytes       ,     39124405,         3497/ I/O

    I/O Write Bytes      ,     16790740,         2023/ I/O

    I/O Other Bytes      ,      4785210,         164/ I/O

-----------------------------

Results for Kernel Mode:

-----------------------------

OutputResults: KernelModuleCount = 142

Percentage in the following table is based on the Total Hits for the Kernel

Time   69611 hits, 25000 events per hit --------

 Module                                Hits   msec  %Total  Events/Sec

processr                              60855      97359    87 %    15626444

ntkrnlpa                               4118      97375     5 %     1057252

ati2cqag                                947      97359     1 %      243172

hal                                     907      97375     1 %      232862

ati2dvag                                838      97359     1 %      215182

PECKP                                   701      97359     1 %      180003

win32k                                  654      97359     0 %      167935

USBPORT                                 130      97359     0 %       33381

athuw                                    81      97359     0 %       20799

RtkHDAud                                 38      97359     0 %        9757

usbehci                                  38      97359     0 %        9757

ati2mtag                                 37      97359     0 %        9500

kmixer                                   34      97359     0 %        8730

tcpip                                    30      97359     0 %        7703

NDIS                                     24      97359     0 %        6162

Ntfs                                     23      97359     0 %        5905

afd                                      21      97359     0 %        5392

Npfs                                     18      97359     0 %        4622

portcls                                  15      97359     0 %        3851

l151x86                                  13      97359     0 %        3338

sptd                                     13      97359     0 %        3338

usbhub                                   12      97359     0 %        3081

wdf01000                                  9      97359     0 %        2311

watchdog                                  6      97359     0 %        1540

fltMgr                                    6      97359     0 %        1540

ipnat                                     5      97359     0 %        1283

LiveKdD                                   4      97359     0 %        1027

avipbb                                    4      97359     0 %        1027

ati3duag                                  3      97359     0 %         770

ks                                        3      97359     0 %         770

avgntflt                                  2      97359     0 %         513

el90xbc5                                  2      97359     0 %         513

usbohci                                   2      97359     0 %         513

wdmaud                                    1      97359     0 %         256

sniffer                                   1      97359     0 %         256

LMouFilt                                  1      97359     0 %         256

mouhid                                    1      97359     0 %         256

LHidFilt                                  1      97359     0 %         256

HIDPARSE                                  1      97359     0 %         256

avkmgr                                    1      97359     0 %         256

rdbss                                     1      97359     0 %         256

ipsec                                     1      97359     0 %         256

psched                                    1      97359     0 %         256

TDI                                       1      97359     0 %         256

av261r6u                                  1      97359     0 %         256

HDAudBus                                  1      97359     0 %         256

Mup                                       1      97359     0 %         256

CLASSPNP                                  1      97359     0 %         256

PartMgr                                   1      97359     0 %         256

PCIIDEX                                   1      97359     0 %         256

WMILIB                                    1      97359     0 %         256

================================= END OF RUN ==================================

============================== NORMAL END OF RUN ==============================

C:\Program Files\KrView\Kernrates>

由此可见系统在内核模式下花了TOTAL  K 0:00:19.125 ( 9.8%) 的时间。碰撞率最高的模块是process,这个是CPU处理器驱动程序。

X86的多处理器系统上,IRQ本质上是随机的,但在X64或者IA64上,IRQ16除中断向量号。

因为windows并没有以任何一种可控的方式对设备IRQ进行优先级处理,而且用户的应用程序只能在处理器的IRQL为被动级别的时候才能执行,所以windows不适合作实时系统。

声明:真相:windows XP Embedded并没有实时特性,而是借助venturcom公司将实时内核内嵌到自定义好的HAL中。



你可能感兴趣的:(读书笔记,windows,x86,ddk,c,build,编程)