Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1980 lines
49 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. thermal
  5. Abstract:
  6. WinDbg Extension Api
  7. Author:
  8. Environment:
  9. User Mode.
  10. Revision History:
  11. --*/
  12. #include "precomp.h"
  13. #pragma hdrstop
  14. #define TZ_LOOP 0x00000001
  15. #define TZ_DUMP_INFO 0x00000002
  16. #define TZ_NO_HEADER 0x80000000
  17. PCHAR DumpPowerStateMappings[10] = {
  18. "x", "0", "1", "2", "3", "4", "5", "?", "?", "?"
  19. };
  20. PCHAR DumpPowerActionMappings[] = {
  21. " None",
  22. " Reserved",
  23. " Sleep",
  24. "Hibernate",
  25. " Shutdown",
  26. " Reset",
  27. " Off"
  28. };
  29. PCHAR DumpDynamicThrottleMapping[] = {
  30. " None",
  31. "Constant",
  32. " Degrade",
  33. "Adaptive",
  34. " Maximum"
  35. };
  36. PCHAR
  37. DumpTimeInStandardForm(
  38. IN ULONG64 CurrentTime
  39. )
  40. /*++
  41. Routine Description:
  42. Print the Kernel's view of time into something that a user can
  43. understand
  44. Arguments:
  45. CurrentTime - Kernel's Idea of time
  46. Return Value:
  47. None
  48. --*/
  49. {
  50. static CHAR TimeBuffer[256];
  51. ULONG TimeIncrement;
  52. TIME_FIELDS Times;
  53. LARGE_INTEGER RunTime;
  54. TimeIncrement = GetNtDebuggerDataValue( KeTimeIncrement );
  55. RunTime.QuadPart = UInt32x32To64(CurrentTime, TimeIncrement);
  56. RtlTimeToElapsedTimeFields( &RunTime, &Times);
  57. if (Times.Hour) {
  58. sprintf(TimeBuffer,"%3ld:%02ld:%02ld.%03lds",
  59. Times.Hour,
  60. Times.Minute,
  61. Times.Second,
  62. Times.Milliseconds);
  63. } else if (Times.Minute) {
  64. sprintf(TimeBuffer,"%02ld:%02ld.%03lds",
  65. Times.Minute,
  66. Times.Second,
  67. Times.Milliseconds);
  68. } else {
  69. sprintf(TimeBuffer,"%02ld.%03lds",
  70. Times.Second,
  71. Times.Milliseconds);
  72. }
  73. return TimeBuffer;
  74. }
  75. PCHAR
  76. DumpMicroSecondsInStandardForm(
  77. IN ULONG64 CurrentTime
  78. )
  79. {
  80. static CHAR PerfBuffer[256];
  81. ULONG64 FreqAddr;
  82. LARGE_INTEGER Freq;
  83. ULONG Result;
  84. ULONG64 MicroSeconds;
  85. ULONG64 MilliSeconds;
  86. ULONG64 Seconds;
  87. ULONG64 Minutes;
  88. ULONG64 Hours;
  89. ULONG64 Days;
  90. MicroSeconds = CurrentTime;
  91. MilliSeconds = MicroSeconds / 1000;
  92. MicroSeconds = MicroSeconds % 1000;
  93. Seconds = MilliSeconds / 1000;
  94. MilliSeconds = MilliSeconds % 1000;
  95. Minutes = Seconds / 60;
  96. Seconds = Seconds % 60;
  97. Hours = Minutes / 60;
  98. Minutes = Minutes % 60;
  99. Days = Hours / 24;
  100. Hours = Hours % 24;
  101. #if 0
  102. sprintf(PerfBuffer,"%02ld:%02ld:%02ld.%03ld.%03lds",
  103. (ULONG)Hours,
  104. (ULONG)Minutes,
  105. (ULONG)Seconds,
  106. (ULONG)MilliSeconds,
  107. (ULONG)MicroSeconds
  108. );
  109. return PerfBuffer;
  110. #endif
  111. if (Hours) {
  112. sprintf(PerfBuffer,"%02ld:%02ld:%02ld.%03ld.%03lds",
  113. (ULONG)Hours,
  114. (ULONG)Minutes,
  115. (ULONG)Seconds,
  116. (ULONG)MilliSeconds,
  117. (ULONG)MicroSeconds
  118. );
  119. } else if (Minutes) {
  120. sprintf(PerfBuffer,"%02ld:%02ld.%03ld.%03lds",
  121. (ULONG)Minutes,
  122. (ULONG)Seconds,
  123. (ULONG)MilliSeconds,
  124. (ULONG)MicroSeconds
  125. );
  126. } else if (Seconds) {
  127. sprintf(PerfBuffer,"%02ld.%03ld.%03lds",
  128. (ULONG)Seconds,
  129. (ULONG)MilliSeconds,
  130. (ULONG)MicroSeconds
  131. );
  132. } else {
  133. sprintf(PerfBuffer,".%03ld.%03lds",
  134. (ULONG)MilliSeconds,
  135. (ULONG)MicroSeconds
  136. );
  137. }
  138. return PerfBuffer;
  139. }
  140. PCHAR
  141. DumpPerformanceCounterInStandardForm(
  142. IN ULONG64 CurrentTime
  143. )
  144. /*++
  145. Routine Description:
  146. Print a performance counter's view of time into something that a
  147. user can understand
  148. --*/
  149. {
  150. static CHAR PerfBuffer[256];
  151. ULONG64 FreqAddr;
  152. LARGE_INTEGER Freq;
  153. ULONG Result;
  154. ULONG64 MicroSeconds;
  155. ULONG64 MilliSeconds;
  156. ULONG64 Seconds;
  157. ULONG64 Minutes;
  158. ULONG64 Hours;
  159. ULONG64 Days;
  160. FreqAddr = GetExpression( "nt!KdPerformanceCounterRate" );
  161. if (!FreqAddr || !ReadMemory( FreqAddr, &Freq, sizeof(Freq), &Result) ) {
  162. sprintf(PerfBuffer,"<unknown rate>");
  163. return PerfBuffer;
  164. }
  165. MicroSeconds = (CurrentTime * 1000000L) / Freq.LowPart;
  166. MilliSeconds = MicroSeconds / 1000;
  167. MicroSeconds = MicroSeconds % 1000;
  168. Seconds = MilliSeconds / 1000;
  169. MilliSeconds = MilliSeconds % 1000;
  170. Minutes = Seconds / 60;
  171. Seconds = Seconds % 60;
  172. Hours = Minutes / 60;
  173. Minutes = Minutes % 60;
  174. Days = Hours / 24;
  175. Hours = Hours % 24;
  176. #if 0
  177. sprintf(PerfBuffer,"%02ld:%02ld:%02ld.%03ld.%03lds",
  178. (ULONG)Hours,
  179. (ULONG)Minutes,
  180. (ULONG)Seconds,
  181. (ULONG)MilliSeconds,
  182. (ULONG)MicroSeconds
  183. );
  184. return PerfBuffer;
  185. #endif
  186. if (Hours) {
  187. sprintf(PerfBuffer,"%02ld:%02ld:%02ld.%03ld.%03lds",
  188. (ULONG)Hours,
  189. (ULONG)Minutes,
  190. (ULONG)Seconds,
  191. (ULONG)MilliSeconds,
  192. (ULONG)MicroSeconds
  193. );
  194. } else if (Minutes) {
  195. sprintf(PerfBuffer,"%02ld:%02ld.%03ld.%03lds",
  196. (ULONG)Minutes,
  197. (ULONG)Seconds,
  198. (ULONG)MilliSeconds,
  199. (ULONG)MicroSeconds
  200. );
  201. } else if (Seconds) {
  202. sprintf(PerfBuffer,"%02ld.%03ld.%03lds",
  203. (ULONG)Seconds,
  204. (ULONG)MilliSeconds,
  205. (ULONG)MicroSeconds
  206. );
  207. } else {
  208. sprintf(PerfBuffer,".%03ld.%03lds",
  209. (ULONG)MilliSeconds,
  210. (ULONG)MicroSeconds
  211. );
  212. }
  213. return PerfBuffer;
  214. }
  215. VOID
  216. DumpTemperatureInKelvins(
  217. IN ULONG Temperature
  218. )
  219. /*++
  220. Routine Description:
  221. Dumps the temperatures in Kelvins
  222. Arguments:
  223. Temperature - What to dump in Kelvins
  224. Return Value:
  225. None
  226. --*/
  227. {
  228. dprintf(" (%d.%dK)", (Temperature / 10), (Temperature % 10) );
  229. }
  230. VOID
  231. DumpPowerActionPolicyBrief(
  232. IN ULONG Action,
  233. IN ULONG Flags,
  234. IN ULONG EventCode
  235. )
  236. {
  237. dprintf("%s Flags: %08lx Event: %08lx ",
  238. DumpPowerActionMappings[Action],
  239. Flags,
  240. EventCode
  241. );
  242. if (Flags & POWER_ACTION_QUERY_ALLOWED) {
  243. dprintf(" Query");
  244. }
  245. if (Flags & POWER_ACTION_UI_ALLOWED) {
  246. dprintf(" UI");
  247. }
  248. if (Flags & POWER_ACTION_OVERRIDE_APPS) {
  249. dprintf(" Override");
  250. }
  251. if (Flags & POWER_ACTION_LOCK_CONSOLE) {
  252. dprintf(" Lock");
  253. }
  254. if (Flags & POWER_ACTION_DISABLE_WAKES) {
  255. dprintf(" NoWakes");
  256. }
  257. if (Flags & POWER_ACTION_CRITICAL) {
  258. dprintf(" Critical");
  259. }
  260. if (EventCode & POWER_LEVEL_USER_NOTIFY_TEXT) {
  261. dprintf(" NotifyText");
  262. }
  263. if (EventCode & POWER_LEVEL_USER_NOTIFY_SOUND) {
  264. dprintf(" NotifySound");
  265. }
  266. if (EventCode & POWER_LEVEL_USER_NOTIFY_EXEC) {
  267. dprintf(" NotifyExec");
  268. }
  269. dprintf("\n");
  270. }
  271. VOID
  272. DumpSystemPowerPolicy(
  273. IN PCHAR Pad,
  274. IN ULONG64 Address,
  275. IN ULONG Flags
  276. )
  277. /*++
  278. Routine Description:
  279. System Power Policy change
  280. Arguments:
  281. Return Value:
  282. --*/
  283. {
  284. UCHAR temp;
  285. InitTypeRead(Address, nt!_SYSTEM_POWER_POLICY);
  286. if (!(Flags & TZ_NO_HEADER)) {
  287. dprintf("%sSYSTEM_POWER_POLICY (R.%d) @ 0x%08p\n",
  288. Pad, (ULONG) ReadField(Revision), Address);
  289. }
  290. temp = (UCHAR) ReadField(DynamicThrottle);
  291. if (temp > PO_THROTTLE_MAXIMUM) {
  292. temp = PO_THROTTLE_MAXIMUM;
  293. }
  294. dprintf("%s PowerButton: ", Pad);
  295. DumpPowerActionPolicyBrief( (ULONG) ReadField(PowerButton.Action),
  296. (ULONG) ReadField(PowerButton.Flags),
  297. (ULONG) ReadField(PowerButton.EventCode));
  298. dprintf("%s SleepButton: ", Pad);
  299. DumpPowerActionPolicyBrief( (ULONG) ReadField(SleepButton.Action),
  300. (ULONG) ReadField(SleepButton.Flags),
  301. (ULONG) ReadField(SleepButton.EventCode));
  302. dprintf("%s LidClose: ", Pad);
  303. DumpPowerActionPolicyBrief( (ULONG) ReadField(LidClose.Action),
  304. (ULONG) ReadField(LidClose.Flags),
  305. (ULONG) ReadField(LidClose.EventCode));
  306. dprintf("%s Idle: ", Pad);
  307. DumpPowerActionPolicyBrief( (ULONG) ReadField(Idle.Action),
  308. (ULONG) ReadField(Idle.Flags),
  309. (ULONG) ReadField(Idle.EventCode));
  310. dprintf("%s OverThrottled: ", Pad);
  311. DumpPowerActionPolicyBrief( (ULONG) ReadField(OverThrottled.Action),
  312. (ULONG) ReadField(OverThrottled.Flags),
  313. (ULONG) ReadField(OverThrottled.EventCode));
  314. dprintf("%s IdleTimeout: %8lx IdleSensitivity: %d%%\n",
  315. Pad,
  316. (ULONG) ReadField(IdleTimeout),
  317. (ULONG) ReadField(IdleSensitivity));
  318. dprintf("%s MinSleep: S%s MaxSleep: S%s\n",
  319. Pad,
  320. DumpPowerStateMappings[(ULONG) ReadField(MinSleep)],
  321. DumpPowerStateMappings[(ULONG) ReadField(MaxSleep)]);
  322. dprintf("%s LidOpenWake: S%s FastSleep: S%s\n",
  323. Pad,
  324. DumpPowerStateMappings[(ULONG) ReadField(LidOpenWake)],
  325. DumpPowerStateMappings[(ULONG) ReadField(ReducedLatencySleep)]);
  326. dprintf("%s WinLogonFlags: %8lx S4Timeout: %8lx\n",
  327. Pad,
  328. (ULONG) ReadField(WinLogonFlags),
  329. (ULONG) ReadField(DozeS4Timeout));
  330. dprintf("%s VideoTimeout: %8d VideoDim: %2d\n",
  331. Pad,
  332. (ULONG) ReadField(VideoTimeout),
  333. (ULONG) ReadField(VideoDimDisplay));
  334. dprintf("%s SpinTimeout: %8lx OptForPower: %2d\n",
  335. Pad,
  336. (ULONG) ReadField(SpindownTimeout),
  337. (ULONG) ReadField(OptimizeForPower)
  338. );
  339. dprintf("%s FanTolerance: %4d%% ForcedThrottle: %4d%%\n",
  340. Pad,
  341. (ULONG) ReadField(FanThrottleTolerance),
  342. (ULONG) ReadField(ForcedThrottle));
  343. dprintf("%s MinThrottle: %4d%% DyanmicThrottle: %8s (%d)\n",
  344. Pad, (ULONG) ReadField(MinThrottle),
  345. DumpDynamicThrottleMapping[temp],
  346. temp
  347. );
  348. }
  349. DECLARE_API( popolicy )
  350. /*++
  351. Routine Description:
  352. Dumps the power policy
  353. Arguments:
  354. Return Value:
  355. --*/
  356. {
  357. ULONG64 Address = 0;
  358. ULONG64 PolicyAddress;
  359. ULONG Flags = 0;
  360. ULONG Result;
  361. if (GetExpressionEx(args, &Address, &args)) {
  362. Flags = (ULONG) GetExpression(args);
  363. }
  364. if (!Address) {
  365. Address = GetExpression("nt!PopPolicy");
  366. if (!Address) {
  367. dprintf("Could not read PopPolicy\n");
  368. return E_INVALIDARG;
  369. }
  370. if (!ReadPointer(Address,
  371. &PolicyAddress) ) {
  372. dprintf("Could not read PopPolicy at %p\n", Address );
  373. return E_INVALIDARG;
  374. }
  375. Address = PolicyAddress;
  376. }
  377. if (!Address) {
  378. dprintf("!popolicy [addr [flags]]\n");
  379. return E_INVALIDARG;
  380. }
  381. if (GetFieldValue( Address,
  382. "nt!_SYSTEM_POWER_POLICY",
  383. "Revision",
  384. Result) ) {
  385. dprintf("Could not read PopPolicy at %p\n", Address );
  386. return E_INVALIDARG;
  387. }
  388. DumpSystemPowerPolicy( "", Address, Flags );
  389. return S_OK;
  390. }
  391. VOID
  392. DumpProcessorPowerPolicy(
  393. IN PCHAR Pad,
  394. IN ULONG64 Address,
  395. IN ULONG Flags
  396. )
  397. /*++
  398. Routine Description:
  399. Processor Power Policy change
  400. Arguments:
  401. Return Value:
  402. --*/
  403. {
  404. ULONG i;
  405. ULONG count;
  406. ULONG offset;
  407. ULONG64 size;
  408. InitTypeRead(Address, nt!_PROCESSOR_POWER_POLICY);
  409. if (!(Flags & TZ_NO_HEADER)) {
  410. dprintf("%sPROCESSOR_POWER_POLICY %p (Rev .%d)\n",
  411. Pad,
  412. Address,
  413. (ULONG) ReadField(Revision)
  414. );
  415. }
  416. dprintf(
  417. "%s DynamicThrottle: %4d PolicyCount: %8d\n",
  418. Pad,
  419. (ULONG) ReadField(DynamicThrottle),
  420. (ULONG) ReadField(PolicyCount)
  421. );
  422. GetFieldOffset("nt!_PROCESSOR_POWER_POLICY", "Policy", &offset);
  423. Address += offset;
  424. size = GetTypeSize("nt!_PROCESSOR_POWER_POLICY_INFO");
  425. count = (ULONG) ReadField(PolicyCount);
  426. if (count > 3) {
  427. count = 3;
  428. }
  429. //
  430. // Walk the PROCESSOR_POWER_POLICY_INFO structures
  431. //
  432. for (i = 0; i < count; i++) {
  433. InitTypeRead(Address, nt!_PROCESSOR_POWER_POLICY_INFO);
  434. dprintf(
  435. "\n%s PROCESSOR_POWER_POLICY_INFO %p\n",
  436. Pad,
  437. Address
  438. );
  439. dprintf(
  440. "%s PromotePercent: %4d%% DemotePercent: %4d%%\n",
  441. Pad,
  442. (ULONG) ReadField( PromotePercent ),
  443. (ULONG) ReadField( DemotePercent )
  444. );
  445. dprintf(
  446. "%s AllowPromotion: %5s AllowDemotion: %5s\n",
  447. Pad,
  448. ( (ULONG) ReadField( AllowPromotion ) ? " TRUE" : "FALSE"),
  449. ( (ULONG) ReadField( AllowDemotion) ? " TRUE" : "FALSE")
  450. );
  451. dprintf(
  452. "%s TimeCheck: %21s (%8p)\n",
  453. Pad,
  454. DumpMicroSecondsInStandardForm( ReadField( TimeCheck ) ),
  455. (ULONG) ReadField( TimeCheck )
  456. );
  457. dprintf(
  458. "%s PromoteLimit: %21s (%8p)\n",
  459. Pad,
  460. DumpMicroSecondsInStandardForm( ReadField( PromoteLimit ) ),
  461. (ULONG) ReadField( PromoteLimit )
  462. );
  463. dprintf(
  464. "%s DemoteLimit: %21s (%8p)\n",
  465. Pad,
  466. DumpMicroSecondsInStandardForm( ReadField( DemoteLimit ) ),
  467. (ULONG) ReadField( DemoteLimit )
  468. );
  469. Address += size;
  470. }
  471. }
  472. DECLARE_API( poprocpolicy )
  473. /*++
  474. Routine Description:
  475. Dumps the power policy
  476. Arguments:
  477. Return Value:
  478. --*/
  479. {
  480. ULONG64 Address = 0;
  481. ULONG64 PolicyAddress;
  482. ULONG Flags = 0;
  483. ULONG Result;
  484. if (GetExpressionEx(args, &Address, &args)) {
  485. Flags = (ULONG) GetExpression(args);
  486. }
  487. if (!Address) {
  488. Address = GetExpression("nt!PopProcessorPolicy");
  489. if (!Address) {
  490. dprintf("Could not read PopProcessorPolicy\n");
  491. return E_INVALIDARG;
  492. }
  493. if (!ReadPointer(Address,&PolicyAddress) ) {
  494. dprintf("Could not read PopProcessorPolicy at %p\n", Address );
  495. return E_INVALIDARG;
  496. }
  497. Address = PolicyAddress;
  498. }
  499. if (!Address) {
  500. dprintf("!poprocpolicy [addr [flags]]\n");
  501. return E_INVALIDARG;
  502. }
  503. if (GetFieldValue( Address,"PROCESSOR_POWER_POLICY", "Revision", Result) ) {
  504. dprintf("Could not read PopProcessorPolicy at %p\n", Address );
  505. return E_INVALIDARG;
  506. }
  507. DumpProcessorPowerPolicy( "", Address, Flags );
  508. return S_OK;
  509. }
  510. VOID
  511. DumpProcessorPowerState(
  512. IN PCHAR Pad,
  513. IN ULONG64 Address,
  514. IN ULONG Flags
  515. )
  516. /*++
  517. Routine Description:
  518. Processor Power State dump
  519. Arguments:
  520. Return Value:
  521. --*/
  522. {
  523. ULONG time;
  524. ULONG temp;
  525. CHAR FunctionName[256];
  526. ULONG64 Offset;
  527. InitTypeRead(Address, nt!_PROCESSOR_POWER_STATE);
  528. if (!(Flags & TZ_NO_HEADER)) {
  529. dprintf("%sPROCESSOR_POWER_STATE %p\n", Pad, Address );
  530. }
  531. dprintf(
  532. "%s IdleState: %16p IdleHandlers: %16p\n",
  533. Pad,
  534. ReadField(IdleState),
  535. ReadField(IdleHandlers)
  536. );
  537. dprintf(
  538. "%s C1 Idle Transitions: %8lx C1 Idle Time: %17s\n",
  539. Pad,
  540. (ULONG) ReadField( TotalIdleTransitions[0] ),
  541. DumpPerformanceCounterInStandardForm( ReadField( TotalIdleStateTime[0] ) )
  542. );
  543. dprintf(
  544. "%s C2 Idle Transitions: %8lx C2 Idle Time: %17s\n",
  545. Pad,
  546. (ULONG) ReadField( TotalIdleTransitions[1] ),
  547. DumpPerformanceCounterInStandardForm( ReadField( TotalIdleStateTime[1] ) )
  548. );
  549. dprintf(
  550. "%s C3 Idle Transitions: %8lx C3 Idle Time: %17s\n\n",
  551. Pad,
  552. (ULONG) ReadField( TotalIdleTransitions[2] ),
  553. DumpPerformanceCounterInStandardForm( ReadField( TotalIdleStateTime[2] ) )
  554. );
  555. dprintf(
  556. "%s DebugDelta: %16I64x LastCheck: %17s\n",
  557. Pad,
  558. ReadField(DebugDelta),
  559. DumpPerformanceCounterInStandardForm( ReadField( LastCheck ) )
  560. );
  561. dprintf(
  562. "%s DebugCount: %8lx IdleTime.Start: %17s\n",
  563. Pad,
  564. (ULONG) ReadField(DebugCount),
  565. DumpPerformanceCounterInStandardForm( ReadField( IdleTimes.StartTime ) )
  566. );
  567. dprintf(
  568. "%s PromotionCheck: %8lx IdleTime.End: %17s\n",
  569. Pad,
  570. (ULONG) ReadField(PromotionCheck ),
  571. DumpPerformanceCounterInStandardForm( ReadField( IdleTimes.EndTime ) )
  572. );
  573. dprintf(
  574. "%s IdleTime1: %8lx Idle0LastTime: %17s\n",
  575. Pad,
  576. (ULONG) ReadField(IdleTime1),
  577. DumpTimeInStandardForm( ReadField( Idle0LastTime ) )
  578. );
  579. dprintf(
  580. "%s IdleTime2: %8lx LastSystTime: %17s\n",
  581. Pad,
  582. (ULONG) ReadField(IdleTime2),
  583. DumpTimeInStandardForm( ReadField( LastSysTime ) )
  584. );
  585. dprintf(
  586. "%s CurrentThrottle: %4d%% Idle0KernelTimeLimit: %15s\n",
  587. Pad,
  588. (ULONG) ReadField(CurrentThrottle),
  589. DumpTimeInStandardForm( ReadField( Idle0KernelTimeLimit ) )
  590. );
  591. dprintf(
  592. "%s CurrentThrottleIndex: %4d ThermalThrottleLimit: %4d%%\n",
  593. Pad,
  594. (ULONG) ReadField(CurrentThrottleIndex),
  595. (ULONG) ReadField(ThermalThrottleLimit)
  596. );
  597. dprintf(
  598. "%s KneeThrottleIndex: %4d ThermalThrottleIndex: %4d\n",
  599. Pad,
  600. (ULONG) ReadField(KneeThrottleIndex),
  601. (ULONG) ReadField(ThermalThrottleIndex)
  602. );
  603. dprintf(
  604. "%s ThrottleLimitIndex: %4d Flags: %8x\n",
  605. Pad,
  606. (ULONG) ReadField(ThrottleLimitIndex),
  607. (ULONG) ReadField(Flags)
  608. );
  609. dprintf(
  610. "%s PerfStates: %8p PerfStatesCount: %4d\n",
  611. Pad,
  612. ReadField(PerfStates),
  613. (ULONG) ReadField(PerfStatesCount)
  614. );
  615. dprintf(
  616. "%s ProcessorMinThrottle: %4d%% ProcessorMaxThrottle: %4d%%\n",
  617. Pad,
  618. (ULONG) ReadField(ProcessorMinThrottle),
  619. (ULONG) ReadField(ProcessorMaxThrottle)
  620. );
  621. dprintf(
  622. "%s PromotionCount: %8d DemotionCount: %8d\n",
  623. Pad,
  624. (ULONG) ReadField( PromotionCount ),
  625. (ULONG) ReadField( DemotionCount )
  626. );
  627. dprintf(
  628. "%s ErrorCount: %8d RetryCount: %8d\n",
  629. Pad,
  630. (ULONG) ReadField(ErrorCount),
  631. (ULONG) ReadField(RetryCount)
  632. );
  633. dprintf(
  634. "%s LastBusyPercentage: %4d%% LastC3Percentage: %4d%%\n",
  635. Pad,
  636. (ULONG) ReadField( LastBusyPercentage ),
  637. (ULONG) ReadField( LastC3Percentage )
  638. );
  639. dprintf(
  640. "%s LastAdjustedBusyPercent: %4d%%\n",
  641. Pad,
  642. (ULONG) ReadField(LastAdjustedBusyPercentage)
  643. );
  644. dprintf("\n");
  645. GetSymbol(ReadField(IdleFunction), FunctionName, &Offset);
  646. dprintf(
  647. "%s IdleFunction: %50s\n",
  648. Pad,
  649. FunctionName
  650. );
  651. GetSymbol(ReadField(PerfSetThrottle), FunctionName, &Offset);
  652. dprintf(
  653. "%s PerfSetThrottle: %50s\n",
  654. Pad,
  655. FunctionName
  656. );
  657. dprintf(
  658. "%s PreviousC3StateTime: %21s (%16p)\n",
  659. Pad,
  660. DumpPerformanceCounterInStandardForm( ReadField( PreviousC3StateTime ) ),
  661. ReadField( PreviousC3StateTime )
  662. );
  663. dprintf(
  664. "%s PerfSystemTime: %21s (%8x)\n",
  665. Pad,
  666. DumpTimeInStandardForm( ReadField(PerfSystemTime) ),
  667. ReadField( PerfSystemTime )
  668. );
  669. dprintf(
  670. "%s PerfIdleTime: %21s (%8x)\n",
  671. Pad,
  672. DumpTimeInStandardForm( ReadField(PerfIdleTime) ),
  673. ReadField( PerfIdleTime )
  674. );
  675. dprintf(
  676. "%s PerfTickCount: %21s (%8x)\n",
  677. Pad,
  678. DumpTimeInStandardForm( ReadField(PerfTickCount) ),
  679. ReadField( PerfTickCount )
  680. );
  681. //
  682. // At this point, go look at the corresponding PRCB to see what the
  683. // kernel and user times are
  684. //
  685. GetFieldOffset("nt!_KPRCB", "PowerState", &temp);
  686. Address -= temp;
  687. InitTypeRead( Address, _KPRCB );
  688. time = (ULONG) ReadField(UserTime) + (ULONG) ReadField(KernelTime);
  689. dprintf(
  690. "%s CurrentSystemTime: %21s (%8x)\n",
  691. Pad,
  692. DumpTimeInStandardForm( time ),
  693. time
  694. );
  695. //
  696. // Read the Idle Thread to see what the current idle thread time is
  697. //
  698. Address = ReadField( IdleThread );
  699. InitTypeRead( Address, _KTHREAD );
  700. time = (ULONG) ReadField(KernelTime);
  701. dprintf(
  702. "%s CurrentIdleTime: %21s (%8x)\n",
  703. Pad,
  704. DumpTimeInStandardForm( time ),
  705. time
  706. );
  707. }
  708. DECLARE_API( poproc )
  709. /*++
  710. Routine Description:
  711. Dumps the Processor Power State
  712. Arguments:
  713. Return Value:
  714. --*/
  715. {
  716. ULONG64 Address = 0;
  717. ULONG64 Pkprcb;
  718. ULONG Flags = 0;
  719. ULONG processor;
  720. ULONG64 Result;
  721. //
  722. // Get address and flags
  723. //
  724. if (GetExpressionEx(args, &Address, &args)) {
  725. Flags = (ULONG) GetExpression(args);
  726. }
  727. if (Address == 0) {
  728. HRESULT Hr;
  729. INIT_API();
  730. GetCurrentProcessor(Client, &processor, NULL);
  731. Hr = g_ExtData->ReadProcessorSystemData(processor,
  732. DEBUG_DATA_KPRCB_OFFSET,
  733. &Pkprcb,
  734. sizeof(Pkprcb),
  735. NULL);
  736. if (Hr != S_OK)
  737. {
  738. dprintf("Cannot get PRCB address\n");
  739. }
  740. else
  741. {
  742. InitTypeRead(Pkprcb,nt!_KPRCB);
  743. Address = ReadField(PowerState);
  744. if (!Address)
  745. {
  746. dprintf("Unable to get PowerState from the PRCB at %p",Pkprcb);
  747. dprintf("poproc <address>\n");
  748. Hr = E_INVALIDARG;
  749. }
  750. }
  751. if (Hr != S_OK)
  752. {
  753. return Hr;
  754. }
  755. }
  756. if (GetFieldValue( Address,
  757. "PROCESSOR_POWER_STATE",
  758. "IdleTime1",
  759. Result) ) {
  760. dprintf("Could not read PROCESSOR_POWER_STATE at %08p\n", Address );
  761. return E_INVALIDARG;
  762. }
  763. //
  764. // Dump the Trigger Information
  765. //
  766. DumpProcessorPowerState("", Address, Flags );
  767. return S_OK;
  768. }
  769. VOID
  770. DumpPowerCapabilities(
  771. IN PCHAR Pad,
  772. IN ULONG64 Address,
  773. IN ULONG Flags
  774. )
  775. /*++
  776. Routine Description:
  777. Dumps the power capabilities
  778. Arguments:
  779. Return Value:
  780. --*/
  781. {
  782. InitTypeRead(Address, nt!SYSTEM_POWER_CAPABILITIES);
  783. if (!(Flags & TZ_NO_HEADER)) {
  784. dprintf("%sPopCapabilities @ 0x%08p\n", Pad, Address );
  785. }
  786. dprintf("%s Misc Supported Features: ", Pad);
  787. if ((ULONG) ReadField(PowerButtonPresent)) {
  788. dprintf(" PwrButton");
  789. }
  790. if ((ULONG) ReadField(SleepButtonPresent)) {
  791. dprintf(" SlpButton");
  792. }
  793. if ((ULONG) ReadField(LidPresent)) {
  794. dprintf(" Lid");
  795. }
  796. if ((ULONG) ReadField(SystemS1)) {
  797. dprintf(" S1");
  798. }
  799. if ((ULONG) ReadField(SystemS2)) {
  800. dprintf(" S2");
  801. }
  802. if ((ULONG) ReadField(SystemS3)) {
  803. dprintf(" S3");
  804. }
  805. if ((ULONG) ReadField(SystemS4)) {
  806. dprintf(" S4");
  807. }
  808. if ((ULONG) ReadField(SystemS5)) {
  809. dprintf(" S5");
  810. }
  811. if ((ULONG) ReadField(HiberFilePresent)) {
  812. dprintf(" HiberFile");
  813. }
  814. if ((ULONG) ReadField(FullWake)) {
  815. dprintf(" FullWake");
  816. }
  817. if ((ULONG) ReadField(VideoDimPresent)) {
  818. dprintf(" VideoDim");
  819. }
  820. dprintf("\n");
  821. dprintf("%s Processor Features: ", Pad);
  822. if ((ULONG) ReadField(ThermalControl)) {
  823. dprintf(" Thermal");
  824. }
  825. if ((ULONG) ReadField(ProcessorThrottle)) {
  826. dprintf(" Throttle (MinThrottle = %d%%, Scale = %d%%)",
  827. (ULONG) ReadField(ProcessorMinThrottle),
  828. (ULONG) ReadField(ProcessorThrottleScale));
  829. }
  830. dprintf("\n");
  831. dprintf("%s Disk Features: ", Pad );
  832. if ((ULONG) ReadField(DiskSpinDown)) {
  833. dprintf(" SpinDown");
  834. }
  835. dprintf("\n");
  836. dprintf("%s Battery Features: ", Pad);
  837. if ((ULONG) ReadField(SystemBatteriesPresent)) {
  838. dprintf(" BatteriesPresent");
  839. }
  840. if ((ULONG) ReadField(BatteriesAreShortTerm)) {
  841. dprintf(" ShortTerm");
  842. }
  843. dprintf("\n");
  844. if ((ULONG) ReadField(SystemBatteriesPresent)) {
  845. dprintf("%s Battery 0 - Capacity: %8lx Granularity: %8lx\n",
  846. Pad,
  847. (ULONG) ReadField(BatteryScale[0].Capacity),
  848. (ULONG) ReadField(BatteryScale[0].Granularity)
  849. );
  850. dprintf("%s Battery 1 - Capacity: %8lx Granularity: %8lx\n",
  851. Pad,
  852. (ULONG) ReadField(BatteryScale[1].Capacity),
  853. (ULONG) ReadField(BatteryScale[1].Granularity)
  854. );
  855. dprintf("%s Battery 2 - Capacity: %8lx Granularity: %8lx\n",
  856. Pad,
  857. (ULONG) ReadField(BatteryScale[2].Capacity),
  858. (ULONG) ReadField(BatteryScale[2].Granularity)
  859. );
  860. }
  861. dprintf("%s Wake Caps\n", Pad);
  862. dprintf("%s Ac OnLine Wake: S%s\n",
  863. Pad,
  864. DumpPowerStateMappings[(ULONG) ReadField(AcOnLineWake)]);
  865. dprintf("%s Soft Lid Wake: S%s\n",
  866. Pad,
  867. DumpPowerStateMappings[(ULONG) ReadField(SoftLidWake)]);
  868. dprintf("%s RTC Wake: S%s\n",
  869. Pad,
  870. DumpPowerStateMappings[(ULONG) ReadField(RtcWake)]);
  871. dprintf("%s Min Device Wake: S%s\n",
  872. Pad,
  873. DumpPowerStateMappings[(ULONG) ReadField(MinDeviceWakeState)]);
  874. dprintf("%s Default Wake: S%s\n",
  875. Pad,
  876. DumpPowerStateMappings[(ULONG) ReadField(DefaultLowLatencyWake)]);
  877. }
  878. DECLARE_API( pocaps )
  879. /*++
  880. Routine Description:
  881. Dumps the power capabilities
  882. Arguments:
  883. Return Value:
  884. --*/
  885. {
  886. ULONG64 Address = 0;
  887. ULONG Flags = 0;
  888. ULONG Result;
  889. if (GetExpressionEx(args, &Address, &args)) {
  890. Flags = (ULONG) GetExpression(args);
  891. }
  892. if (!Address) {
  893. Address = GetExpression("nt!PopCapabilities");
  894. if (!Address) {
  895. dprintf("Could not read PopCapabilities\n");
  896. return E_INVALIDARG;
  897. }
  898. }
  899. if (!Address) {
  900. dprintf("!pocaps [addr [flags]]\n");
  901. return E_INVALIDARG;
  902. }
  903. if (GetFieldValue(Address,
  904. "nt!SYSTEM_POWER_CAPABILITIES",
  905. "PowerButtonPresent",
  906. Result) ) {
  907. dprintf("Could not read PopCapabilities at %08p\n", Address );
  908. return E_INVALIDARG;
  909. }
  910. DumpPowerCapabilities( "", Address, Flags );
  911. return S_OK;
  912. }
  913. VOID
  914. DumpPopActionTrigger(
  915. IN PCHAR Pad,
  916. IN ULONG64 Address,
  917. IN ULONG Flags
  918. )
  919. /*++
  920. --*/
  921. {
  922. ULONG Type, PopFlags;
  923. InitTypeRead(Address, nt!_POP_ACTION_TRIGGER);
  924. //
  925. // Header line
  926. //
  927. if (!(Flags & TZ_NO_HEADER)) {
  928. dprintf("%sPOP_ACTION_TRIGGER @ 0x%08p\n", Pad, Address );
  929. }
  930. dprintf("%s Type: ", Pad);
  931. switch(Type = (ULONG) ReadField(Type)) {
  932. case PolicyDeviceSystemButton:
  933. dprintf(" SystemButton"); break;
  934. case PolicyDeviceThermalZone:
  935. dprintf(" ThermalZone"); break;
  936. case PolicyDeviceBattery:
  937. dprintf(" Battery"); break;
  938. case PolicyInitiatePowerActionAPI:
  939. dprintf(" InitActionAPI"); break;
  940. case PolicySetPowerStateAPI:
  941. dprintf(" SetStateAPI"); break;
  942. case PolicyImmediateDozeS4:
  943. dprintf(" DozeS4"); break;
  944. case PolicySystemIdle:
  945. dprintf(" SystemIdle"); break;
  946. default:
  947. dprintf(" Unknown"); break;
  948. }
  949. dprintf(" Flags: %02x%02x%02x%02x",
  950. (ULONG) ReadField(Spare[2]),
  951. (ULONG) ReadField(Spare[1]),
  952. (ULONG) ReadField(Spare[0]),
  953. (PopFlags = (ULONG) ReadField(Flags)));
  954. if (PopFlags & PO_TRG_USER) {
  955. dprintf(" UserAction");
  956. }
  957. if (PopFlags & PO_TRG_SYSTEM) {
  958. dprintf(" SystemAction");
  959. }
  960. if (PopFlags & PO_TRG_SYNC) {
  961. dprintf(" Sync");
  962. }
  963. if (PopFlags & PO_TRG_SET) {
  964. dprintf(" Set");
  965. }
  966. dprintf("\n");
  967. if (Type != PolicyDeviceBattery) {
  968. dprintf("%s Wait Trigger: %08p\n", Pad, ReadField(Wait ));
  969. } else {
  970. dprintf("%s BatteryLevel: %08lx\n", Pad, (ULONG) ReadField(Battery.Level ));
  971. }
  972. }
  973. DECLARE_API( potrigger )
  974. /*++
  975. Routine Description:
  976. Dumps a Pop Action Trigger
  977. Arguments:
  978. Return Value:
  979. --*/
  980. {
  981. ULONG64 Address = 0;
  982. ULONG Flags = 0;
  983. ULONG Result;
  984. //
  985. // Get address and flags
  986. //
  987. if (GetExpressionEx(args, &Address, &args)) {
  988. Flags = (ULONG) GetExpression(args);
  989. }
  990. if (Address == 0) {
  991. dprintf("potrigger <address>\n");
  992. return E_INVALIDARG;
  993. }
  994. if (GetFieldValue(Address,
  995. "nt!_POP_ACTION_TRIGGER",
  996. "Type",
  997. Result) ) {
  998. dprintf("Could not read POP_ACTION_TRIGGER at %08p\n", Address );
  999. return E_INVALIDARG;
  1000. }
  1001. //
  1002. // Dump the Trigger Information
  1003. //
  1004. DumpPopActionTrigger("", Address, Flags );
  1005. return S_OK;
  1006. }
  1007. VOID
  1008. DumpThermalZoneInformation(
  1009. IN PCHAR Pad,
  1010. IN ULONG64 Address,
  1011. IN ULONG Flags
  1012. )
  1013. /*++
  1014. Routine Description:
  1015. Displays the thermal zone information structure
  1016. Arguments:
  1017. Return Value:
  1018. --*/
  1019. {
  1020. ULONG i, Count;
  1021. InitTypeRead(Address, nt!_THERMAL_INFORMATION);
  1022. //
  1023. // Header line
  1024. //
  1025. if (!(Flags & TZ_NO_HEADER)) {
  1026. dprintf("%sThermalInfo @ 0x%08p\n", Pad, Address );
  1027. }
  1028. //
  1029. // First line
  1030. //
  1031. dprintf("%s Stamp: %08lx Constant1: %08lx Constant2: %08lx\n",
  1032. Pad,
  1033. (ULONG) ReadField(ThermalStamp),
  1034. (ULONG) ReadField(ThermalConstant1),
  1035. (ULONG) ReadField(ThermalConstant2));
  1036. //
  1037. // Second Line
  1038. //
  1039. dprintf("%s Affinity: %08lx Period: %08lx ActiveCnt: %08lx\n",
  1040. Pad,
  1041. (ULONG) ReadField(Processors),
  1042. (ULONG) ReadField(SamplingPeriod),
  1043. (ULONG) ReadField(ActiveTripPointCount ));
  1044. //
  1045. // Temperatures
  1046. //
  1047. dprintf("%s Current Temperature: %08lx",
  1048. Pad,
  1049. (ULONG) ReadField(CurrentTemperature ));
  1050. DumpTemperatureInKelvins((ULONG) ReadField(CurrentTemperature));
  1051. dprintf("\n");
  1052. dprintf("%s Passive TripPoint Temperature: %08lx",
  1053. Pad,
  1054. (ULONG) ReadField(PassiveTripPoint ));
  1055. DumpTemperatureInKelvins((ULONG) ReadField(PassiveTripPoint));
  1056. dprintf("\n");
  1057. //
  1058. // Active trip points
  1059. //
  1060. Count = (ULONG) ReadField(ActiveTripPointCount);
  1061. for (i = 0; i < Count; i++) {
  1062. CHAR Buff[40];
  1063. ULONG Act;
  1064. sprintf(Buff, "ActiveTripPoint[%d]", i);
  1065. dprintf("%s Active TripPoint Temperature %d: %08lx",
  1066. Pad,
  1067. i,
  1068. (Act = (ULONG) GetShortField(0, Buff, 0)));
  1069. DumpTemperatureInKelvins(Act);
  1070. dprintf("\n");
  1071. }
  1072. //
  1073. // Dump critical temperatures
  1074. //
  1075. dprintf("%s Critical TripPoint Temperature: %08lx",
  1076. Pad,
  1077. (ULONG) ReadField(CriticalTripPoint ));
  1078. DumpTemperatureInKelvins((ULONG) ReadField(CriticalTripPoint));
  1079. dprintf("\n");
  1080. }
  1081. DECLARE_API( tzinfo )
  1082. /*++
  1083. Routine Description:
  1084. Dumps the thermal zone information structure
  1085. Arguments:
  1086. Return Value:
  1087. --*/
  1088. {
  1089. // THERMAL_INFORMATION ThermalInfo;
  1090. ULONG64 Address = 0;
  1091. ULONG Flags = 0;
  1092. ULONG Result;
  1093. //
  1094. // Get address and flags
  1095. //
  1096. if (GetExpressionEx(args, &Address, &args)) {
  1097. Flags = (ULONG) GetExpression(args);
  1098. }
  1099. if (Address == 0) {
  1100. dprintf("tzinfo <address>\n");
  1101. return E_INVALIDARG;
  1102. }
  1103. if (GetFieldValue(Address,
  1104. "nt!_THERMAL_INFORMATION",
  1105. "ThermalStamp",
  1106. Result) ) {
  1107. dprintf("Could not read THERMAL_INFO at %08p\n", Address );
  1108. return E_INVALIDARG;
  1109. }
  1110. //
  1111. // Dump the thermal zone information
  1112. //
  1113. DumpThermalZoneInformation("", Address, Flags );
  1114. return S_OK;
  1115. }
  1116. VOID
  1117. DumpThermalZone(
  1118. IN ULONG Count,
  1119. IN PCHAR Pad,
  1120. IN ULONG64 Address,
  1121. IN ULONG Flags
  1122. )
  1123. /*++
  1124. Routine Description:
  1125. Dumps a thermal zone
  1126. --*/
  1127. {
  1128. ULONG ThFlags, Off1, Off2, LastTemp;
  1129. InitTypeRead(Address, NT!_POP_THERMAL_ZONE);
  1130. //
  1131. // Header line
  1132. //
  1133. if (!(Flags & TZ_NO_HEADER)) {
  1134. dprintf("%s%d - ThermalZone @ 0x%08p\n", Pad, Count, Address );
  1135. }
  1136. //
  1137. // First line
  1138. //
  1139. dprintf("%s State: ",Pad);
  1140. switch ((ULONG) ReadField(State)) {
  1141. case 1: dprintf(" Read"); break;
  1142. case 2: dprintf("Set Mode"); break;
  1143. case 3: dprintf(" Active"); break;
  1144. default:dprintf("No State"); break;
  1145. }
  1146. dprintf(" Flags: %08lx", (ThFlags = (ULONG) ReadField(Flags)));
  1147. if (ThFlags & PO_TZ_THROTTLING) {
  1148. dprintf(" Throttling");
  1149. }
  1150. if (ThFlags & PO_TZ_CLEANUP) {
  1151. dprintf(" CleanUp");
  1152. }
  1153. dprintf("\n");
  1154. //
  1155. // Second Line
  1156. //
  1157. dprintf("%s Mode: ", Pad );
  1158. switch((ULONG) ReadField(Mode)) {
  1159. case 0: dprintf(" Active"); break;
  1160. case 1: dprintf(" Passive"); break;
  1161. default: dprintf(" Invalid"); break;
  1162. }
  1163. dprintf(" PendingMode: ");
  1164. switch((ULONG) ReadField(PendingMode)) {
  1165. case 0: dprintf(" Active"); break;
  1166. case 1: dprintf(" Passive"); break;
  1167. default: dprintf(" Invalid"); break;
  1168. }
  1169. dprintf("\n");
  1170. dprintf("%s ActivePoint: %08lx PendingTrp: %08lx\n",
  1171. Pad, (ULONG) ReadField(ActivePoint), (ULONG) ReadField(PendingActivePoint ));
  1172. dprintf("%s SampleRate: %08lx LastTime: %016I64x\n",
  1173. Pad, (ULONG) ReadField(SampleRate), ReadField(LastTime ));
  1174. GetFieldOffset("NT!_POP_THERMAL_ZONE", "PassiveTimer", &Off1);
  1175. GetFieldOffset("NT!_POP_THERMAL_ZONE", "PassiveDpc", &Off2);
  1176. dprintf("%s Timer: %08lx Dpc: %08lx\n",
  1177. Pad,
  1178. Address + Off1,
  1179. Address + Off2);
  1180. GetFieldOffset("NT!_POP_THERMAL_ZONE", "OverThrottled", &Off1);
  1181. dprintf("%s OverThrottled: %08lx Irp: %08p\n",
  1182. Pad,
  1183. Address + Off1,
  1184. ReadField(Irp ));
  1185. dprintf("%s Throttle: %08lx LastTemp: %08lx",
  1186. Pad,
  1187. (ULONG) ReadField(Throttle),
  1188. (LastTemp = (ULONG) ReadField(LastTemp )));
  1189. DumpTemperatureInKelvins( LastTemp );
  1190. dprintf("\n");
  1191. GetFieldOffset("NT!_POP_THERMAL_ZONE", "Info", &Off1);
  1192. dprintf("%s Thermal Info: %08lx\n",
  1193. Pad,
  1194. Address + Off1);
  1195. if (Flags & TZ_DUMP_INFO) {
  1196. CHAR buffer[80];
  1197. //
  1198. // Increase the buffer
  1199. //
  1200. sprintf(buffer," %s", Pad );
  1201. //
  1202. // Dump the thermal zone
  1203. //
  1204. DumpThermalZoneInformation(
  1205. buffer,
  1206. (Address + Off1),
  1207. (Flags | TZ_NO_HEADER)
  1208. );
  1209. }
  1210. }
  1211. DECLARE_API( tz )
  1212. /*++
  1213. Routine Description:
  1214. Arguments:
  1215. args -
  1216. Return Value:
  1217. None
  1218. --*/
  1219. {
  1220. ULONG64 Address = 0;
  1221. ULONG Count = 0;
  1222. ULONG64 EndAddress = 0, Flink;
  1223. ULONG Flags = 0;
  1224. ULONG Result;
  1225. //
  1226. // Get address and flags
  1227. //
  1228. if (GetExpressionEx(args, &Address, &args)) {
  1229. Flags = (ULONG) GetExpression(args);
  1230. }
  1231. if (Address == 0) {
  1232. Address = GetExpression("nt!PopThermal");
  1233. if (!Address) {
  1234. dprintf("Could not read PopThermal\n");
  1235. return E_INVALIDARG;
  1236. }
  1237. if (GetFieldValue(Address,
  1238. "nt!_LIST_ENTRY",
  1239. "Flink",
  1240. Flink) ) {
  1241. dprintf("Could not read PopThermal at %08p\n", Address );
  1242. return E_INVALIDARG;
  1243. }
  1244. if (Flink == Address) {
  1245. dprintf("No Thermal Zones\n");
  1246. return E_INVALIDARG;
  1247. }
  1248. Flags |= TZ_LOOP;
  1249. EndAddress = Address;
  1250. Address = Flink;
  1251. } else {
  1252. EndAddress = Address;
  1253. }
  1254. //
  1255. // Now read the proper thermal zone
  1256. //
  1257. if (GetFieldValue(Address,
  1258. "nt!_LIST_ENTRY",
  1259. "Flink",
  1260. Flink) ) {
  1261. dprintf("Could not read LIST_ENTRY at %08p\n", Address );
  1262. return E_INVALIDARG;
  1263. }
  1264. //
  1265. // Do we stop looping?
  1266. //
  1267. if (!(Flags & TZ_LOOP)) {
  1268. EndAddress = Flink;
  1269. }
  1270. do {
  1271. //
  1272. // Read the thermal zone
  1273. // Try both names for backward compatibility
  1274. //
  1275. if (GetFieldValue(Address, "NT!_POP_THERMAL_ZONE", "Link.Flink", Flink) &&
  1276. GetFieldValue(Address, "NT!POP_THERMAL_ZONE", "Link.Flink", Flink)) {
  1277. dprintf("Could not read THERMAL_ZONE at %08p\n", Address );
  1278. return E_INVALIDARG;
  1279. }
  1280. //
  1281. // Dump the zone
  1282. //
  1283. DumpThermalZone( Count, "", Address, Flags );
  1284. //
  1285. // Check for Control C
  1286. //
  1287. if (CheckControlC()) {
  1288. return E_INVALIDARG;
  1289. }
  1290. //
  1291. // Next
  1292. //
  1293. Address = Flink;
  1294. Count++;
  1295. } while (Address != EndAddress );
  1296. return S_OK;
  1297. }
  1298. VOID
  1299. DumpPopIdleHandler(
  1300. IN ULONG64 Address,
  1301. IN ULONG Flags
  1302. )
  1303. /*++
  1304. Routine Description:
  1305. Arguments:
  1306. Return Value:
  1307. --*/
  1308. {
  1309. CHAR FunctionName[256];
  1310. ULONG64 Offset;
  1311. if (InitTypeRead(Address,nt!_POP_IDLE_HANDLER)) {
  1312. // If the new type name fails, use the old one
  1313. InitTypeRead(Address,nt!POP_IDLE_HANDLER);
  1314. }
  1315. dprintf("PopIdleHandle[%d] - POP_IDLE_HANDLER %p\n",(ULONG)ReadField(State),Address);
  1316. dprintf(" State: %8d PromoteCount: %8d\n",
  1317. (ULONG)ReadField(State),
  1318. (ULONG)ReadField(PromoteCount)
  1319. );
  1320. dprintf(" DemotePercent: %8d%% PromotePercent: %8d%%\n",
  1321. (ULONG)ReadField(DemotePercent),
  1322. (ULONG)ReadField(PromotePercent)
  1323. );
  1324. dprintf(" Demote: %8d Promote: %8d\n",
  1325. (ULONG)ReadField(Demote),
  1326. (ULONG)ReadField(Promote)
  1327. );
  1328. dprintf("\n");
  1329. GetSymbol(ReadField(IdleFunction), FunctionName, &Offset);
  1330. dprintf(" Function: %27s (%p)\n",
  1331. FunctionName,
  1332. ReadField(IdleFunction)
  1333. );
  1334. dprintf(" Latency: %27s (%8x)\n",
  1335. DumpPerformanceCounterInStandardForm( (ULONG)ReadField(Latency) ),
  1336. (ULONG)ReadField(Latency)
  1337. );
  1338. dprintf(" TimeCheck: %27s (%8x)\n",
  1339. DumpPerformanceCounterInStandardForm( (ULONG)ReadField(TimeCheck) ),
  1340. (ULONG)ReadField(TimeCheck)
  1341. );
  1342. dprintf(" PromoteLimit: %27s (%8x)\n",
  1343. DumpPerformanceCounterInStandardForm( (ULONG)ReadField(PromoteLimit) ),
  1344. (ULONG)ReadField(PromoteLimit)
  1345. );
  1346. dprintf(" DemoteLimit: %27s (%8x)\n",
  1347. DumpPerformanceCounterInStandardForm( (ULONG)ReadField(DemoteLimit) ),
  1348. (ULONG) ReadField(DemoteLimit)
  1349. );
  1350. dprintf("\n");
  1351. }
  1352. DECLARE_API( poidle )
  1353. /*++
  1354. Routine Description:
  1355. Arguments:
  1356. Return Value:
  1357. --*/
  1358. {
  1359. ULONG64 Address = 0;
  1360. ULONG64 Pkprcb;
  1361. ULONG64 PowerState;
  1362. ULONG64 Size;
  1363. ULONG Loop = 3;
  1364. ULONG Flags = 0;
  1365. ULONG processor = 0;
  1366. //
  1367. // Get address and flags
  1368. //
  1369. if (GetExpressionEx(args, &Address, &args)) {
  1370. Flags = (ULONG) GetExpression(args);
  1371. }
  1372. if (Address == 0) {
  1373. HRESULT Hr;
  1374. INIT_API();
  1375. GetCurrentProcessor(Client, &processor, NULL);
  1376. Hr = g_ExtData->ReadProcessorSystemData(processor,
  1377. DEBUG_DATA_KPRCB_OFFSET,
  1378. &Pkprcb,
  1379. sizeof(Pkprcb),
  1380. NULL);
  1381. if (Hr != S_OK) {
  1382. dprintf("Cannot get PRCB address\n");
  1383. } else {
  1384. InitTypeRead(Pkprcb,nt!_KPRCB);
  1385. PowerState = ReadField(PowerState);
  1386. if (!PowerState) {
  1387. dprintf("Unable to get PowerState from the PRCB at %p",Pkprcb);
  1388. dprintf("poproc <address>\n");
  1389. Hr = E_INVALIDARG;
  1390. }
  1391. }
  1392. if (Hr != S_OK){
  1393. return Hr;
  1394. }
  1395. if (GetFieldValue( PowerState,
  1396. "PROCESSOR_POWER_STATE",
  1397. "IdleHandlers",
  1398. Address) ) {
  1399. dprintf("Could not read PROCESSOR_POWER_STATE at %p\n", PowerState );
  1400. return E_INVALIDARG;
  1401. }
  1402. Loop = 3;
  1403. }
  1404. //
  1405. // We will need to know how large the structure is..
  1406. //
  1407. Size = GetTypeSize("nt!_POP_IDLE_HANDLER");
  1408. if (!Size) {
  1409. Size = GetTypeSize("nt!POP_IDLE_HANDLER");
  1410. }
  1411. do {
  1412. DumpPopIdleHandler( Address, Flags );
  1413. Address += Size;
  1414. if (CheckControlC() || !Loop) {
  1415. break;
  1416. }
  1417. Loop--;
  1418. } while ( Loop );
  1419. return S_OK;
  1420. }
  1421. VOID
  1422. DumpProcessorPerfState(
  1423. IN ULONG64 Address,
  1424. IN ULONG Flags
  1425. )
  1426. /*++
  1427. Routine Description:
  1428. Arguments:
  1429. Return Value:
  1430. --*/
  1431. {
  1432. ULONG64 Value = 0;
  1433. InitTypeRead(Address,nt!PROCESSOR_PERF_STATE);
  1434. dprintf(
  1435. " Power: %4dmW",
  1436. (ULONG)ReadField(Power)
  1437. );
  1438. Value = ReadField(Flags);
  1439. if (Value) {
  1440. dprintf(" NonLinear\n");
  1441. } else {
  1442. dprintf(" Linear\n");
  1443. }
  1444. dprintf(
  1445. " Frequency: %8d%% MinCapacity: %8d%%\n",
  1446. (ULONG)ReadField(PercentFrequency),
  1447. (ULONG)ReadField(MinCapacity)
  1448. );
  1449. dprintf(
  1450. " IncreaseLevel: %8d%% DecreaseLevel: %8d%%\n",
  1451. (ULONG)ReadField(IncreaseLevel),
  1452. (ULONG)ReadField(DecreaseLevel)
  1453. );
  1454. dprintf(
  1455. " IncreaseCount: %8x DecreaseCount: %8x\n",
  1456. (ULONG)ReadField(IncreaseCount),
  1457. (ULONG)ReadField(DecreaseCount)
  1458. );
  1459. dprintf(
  1460. " PerformanceTime: %21s (%8x)\n",
  1461. DumpPerformanceCounterInStandardForm( ReadField(PerformanceTime) ),
  1462. ReadField(PerformanceTime)
  1463. );
  1464. dprintf(
  1465. " IncreaseTime: %21s (%8x)\n",
  1466. DumpTimeInStandardForm( (ULONG) ReadField(IncreaseTime) ),
  1467. ReadField(IncreaseTime)
  1468. );
  1469. dprintf(
  1470. " DecreaseTime: %21s (%8x)\n",
  1471. DumpTimeInStandardForm( (ULONG) ReadField(DecreaseTime) ),
  1472. ReadField(DecreaseTime)
  1473. );
  1474. }
  1475. DECLARE_API( poperf )
  1476. /*++
  1477. Routine Description:
  1478. Arguments:
  1479. Return Value:
  1480. --*/
  1481. {
  1482. ULONG64 Address = 0;
  1483. ULONG64 Count = 1;
  1484. ULONG64 Index;
  1485. ULONG64 PolicyAddress;
  1486. ULONG64 Size = 0;
  1487. ULONG Flags = 0;
  1488. ULONG Processor;
  1489. ULONG Prcb;
  1490. //
  1491. // Get address and flags
  1492. //
  1493. if (GetExpressionEx(args, &Address, &args)) {
  1494. Flags = (ULONG) GetExpression(args);
  1495. }
  1496. if (Address == 0) {
  1497. HRESULT Hr;
  1498. INIT_API();
  1499. //
  1500. // Fetch them from the current processor's prcb
  1501. //
  1502. GetCurrentProcessor(Client, &Processor, NULL);
  1503. Hr = g_ExtData->ReadProcessorSystemData(
  1504. Processor,
  1505. DEBUG_DATA_KPRCB_OFFSET,
  1506. &Address,
  1507. sizeof(Address),
  1508. NULL
  1509. );
  1510. if (Hr != S_OK) {
  1511. dprintf("Unable to get PRCB address\n");
  1512. return Hr;
  1513. }
  1514. InitTypeRead(Address,nt!_KPRCB);
  1515. PolicyAddress = ReadField(PowerState.PerfStates);
  1516. Count = ReadField(PowerState.PerfStatesCount);
  1517. //
  1518. // Remember what's the address we will use
  1519. //
  1520. Address = PolicyAddress;
  1521. dprintf("Prcb.PowerState.PerfStates - %p (%d Levels)\n", Address, (ULONG) Count );
  1522. } else {
  1523. dprintf("PROCESSOR_PERF_STATE - %p\n",Address);
  1524. }
  1525. //
  1526. // We will need to know how large the structure is..
  1527. //
  1528. Size = GetTypeSize("nt!PROCESSOR_PERF_STATE");
  1529. //
  1530. // Dump all the states
  1531. //
  1532. for (Index = 0; Index < Count; Index++, Address += Size) {
  1533. DumpProcessorPerfState( Address, Flags );
  1534. if (CheckControlC()) {
  1535. break;
  1536. }
  1537. }
  1538. //
  1539. // Done
  1540. //
  1541. return S_OK;
  1542. }
  1543. DECLARE_API( whattime )
  1544. {
  1545. ULONG64 Address = 0;
  1546. //
  1547. // Get address and flags
  1548. //
  1549. GetExpressionEx(args, &Address, &args);
  1550. dprintf(
  1551. "%d Ticks in Standard Time: %s\n",
  1552. (ULONG) Address,
  1553. DumpTimeInStandardForm( (ULONG) Address )
  1554. );
  1555. return S_OK;
  1556. }
  1557. DECLARE_API( whatperftime )
  1558. {
  1559. ULONG64 Address = 0;
  1560. //
  1561. // Get address and flags
  1562. //
  1563. GetExpressionEx(args, &Address, &args);
  1564. dprintf(
  1565. "%ld Performance Counter in Standard Time: %s\n",
  1566. (ULONG) Address,
  1567. DumpPerformanceCounterInStandardForm( Address )
  1568. );
  1569. return S_OK;
  1570. }