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.

566 lines
17 KiB

  1. /*++
  2. Microsoft Confidential
  3. Copyright (c) 1992-1997 Microsoft Corporation
  4. All rights reserved
  5. Module Name:
  6. perf.c
  7. Abstract:
  8. Implements the Performance dialog of the System Control Panel Applet
  9. Author:
  10. Eric Flo (ericflo) 19-Jun-1995
  11. Revision History:
  12. 15-Oct-1997 scotthal
  13. Complete overhaul
  14. 10-Jul-2000 SilviuC
  15. Added the LargeSystemCache setting.
  16. --*/
  17. #include <sysdm.h>
  18. #include <help.h>
  19. #define PROCESS_PRIORITY_SEPARATION_MASK 0x00000003
  20. #define PROCESS_PRIORITY_SEPARATION_MAX 0x00000002
  21. #define PROCESS_PRIORITY_SEPARATION_MIN 0x00000000
  22. #define PROCESS_QUANTUM_VARIABLE_MASK 0x0000000c
  23. #define PROCESS_QUANTUM_VARIABLE_DEF 0x00000000
  24. #define PROCESS_QUANTUM_VARIABLE_VALUE 0x00000004
  25. #define PROCESS_QUANTUM_FIXED_VALUE 0x00000008
  26. #define PROCESS_QUANTUM_LONG_MASK 0x00000030
  27. #define PROCESS_QUANTUM_LONG_DEF 0x00000000
  28. #define PROCESS_QUANTUM_LONG_VALUE 0x00000010
  29. #define PROCESS_QUANTUM_SHORT_VALUE 0x00000020
  30. //
  31. // Globals
  32. //
  33. HKEY m_hKeyPerf = NULL;
  34. TCHAR m_szRegPriKey[] = TEXT( "SYSTEM\\CurrentControlSet\\Control\\PriorityControl" );
  35. TCHAR m_szRegPriority[] = TEXT( "Win32PrioritySeparation" );
  36. HKEY m_hKeyMemoryManagement = NULL;
  37. TCHAR m_szRegMemoryManagementKey[] = TEXT( "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Memory Management" );
  38. TCHAR m_szRegLargeSystemCache[] = TEXT( "LargeSystemCache" );
  39. //
  40. // Help ID's
  41. //
  42. // ISSUE: SilviuC: 07/11/2000: IDC_PERF_CACHE_XXX should get help IDs when help is written
  43. DWORD aPerformanceHelpIds[] =
  44. {
  45. IDC_STATIC, NO_HELP,
  46. IDC_PERF_VM_ALLOCD, (IDH_PERF + 1),
  47. IDC_PERF_VM_ALLOCD_LABEL, (IDH_PERF + 1),
  48. IDC_PERF_GROUP, NO_HELP,
  49. IDC_PERF_TEXT, (IDH_PERF + 3),
  50. IDC_PERF_TEXT2, NO_HELP,
  51. IDC_PERF_WORKSTATION, (IDH_PERF + 4),
  52. IDC_PERF_SERVER, (IDH_PERF + 5),
  53. IDC_PERF_VM_GROUP, NO_HELP,
  54. IDC_PERF_VM_ALLOCD_TEXT, NO_HELP,
  55. IDC_PERF_CHANGE, (IDH_PERF + 7),
  56. IDC_PERF_CACHE_GROUP, NO_HELP,
  57. IDC_PERF_CACHE_TEXT, NO_HELP,
  58. IDC_PERF_CACHE_TEXT2, NO_HELP,
  59. IDC_PERF_CACHE_APPLICATION, (IDH_PERF + 14),
  60. IDC_PERF_CACHE_SYSTEM, (IDH_PERF + 15),
  61. 0, 0
  62. };
  63. INT_PTR
  64. APIENTRY
  65. PerformanceDlgProc(
  66. IN HWND hDlg,
  67. IN UINT uMsg,
  68. IN WPARAM wParam,
  69. IN LPARAM lParam
  70. )
  71. /*++
  72. Routine Description:
  73. Handles messages sent to Performance dialog
  74. Arguments:
  75. hDlg -
  76. Supplies window handle
  77. uMsg -
  78. Supplies message being sent
  79. wParam -
  80. Supplies message parameter
  81. lParam -
  82. Supplies message parameter
  83. Return Value:
  84. TRUE if message was handled
  85. FALSE if message was unhandled
  86. --*/
  87. {
  88. static int iNewChoice = 0;
  89. LONG RegRes;
  90. DWORD Type, Value, Length;
  91. DWORD CacheType;
  92. DWORD CacheValue = 0;
  93. DWORD CacheLength;
  94. static int InitPos;
  95. static int InitRegVal, InitCacheRegVal;
  96. static int NewRegVal, NewCacheRegVal;
  97. static BOOL fVMInited = FALSE;
  98. static BOOL fTempPfWarningShown = FALSE;
  99. BOOL fTempPf;
  100. BOOL fWorkstationProduct = !IsOS(OS_ANYSERVER);
  101. BOOL fAdministrator = IsUserAnAdmin();
  102. BOOL fVariableQuanta = FALSE;
  103. BOOL fShortQuanta = FALSE;
  104. BOOL fFailedToOpenMmKey = FALSE;
  105. switch (uMsg)
  106. {
  107. case WM_INITDIALOG:
  108. InitPos = 0;
  109. InitRegVal = 0;
  110. InitCacheRegVal = 0;
  111. //
  112. // initialize from the registry
  113. //
  114. RegRes = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  115. m_szRegPriKey,
  116. 0,
  117. fAdministrator ? KEY_QUERY_VALUE | KEY_SET_VALUE : KEY_QUERY_VALUE,
  118. &m_hKeyPerf );
  119. if (RegRes == ERROR_SUCCESS)
  120. {
  121. Length = sizeof( Value );
  122. RegRes = SHRegGetValue(m_hKeyPerf,
  123. NULL,
  124. m_szRegPriority,
  125. SRRF_RT_DWORD,
  126. &Type,
  127. (LPBYTE) &Value,
  128. &Length );
  129. if (RegRes == ERROR_SUCCESS)
  130. {
  131. InitRegVal = Value;
  132. InitPos = InitRegVal & PROCESS_PRIORITY_SEPARATION_MASK;
  133. if (InitPos > PROCESS_PRIORITY_SEPARATION_MAX)
  134. {
  135. InitPos = PROCESS_PRIORITY_SEPARATION_MAX;
  136. }
  137. }
  138. }
  139. if ((RegRes != ERROR_SUCCESS) || (!fAdministrator))
  140. {
  141. EnableWindow(GetDlgItem(hDlg, IDC_PERF_WORKSTATION), FALSE);
  142. EnableWindow(GetDlgItem(hDlg, IDC_PERF_SERVER), FALSE);
  143. }
  144. NewRegVal = InitRegVal;
  145. //
  146. // determine if we are using fixed or variable quantums
  147. //
  148. switch (InitRegVal & PROCESS_QUANTUM_VARIABLE_MASK)
  149. {
  150. case PROCESS_QUANTUM_VARIABLE_VALUE:
  151. fVariableQuanta = TRUE;
  152. break;
  153. case PROCESS_QUANTUM_FIXED_VALUE:
  154. fVariableQuanta = FALSE;
  155. break;
  156. case PROCESS_QUANTUM_VARIABLE_DEF:
  157. default:
  158. if (fWorkstationProduct)
  159. {
  160. fVariableQuanta = TRUE;
  161. }
  162. else
  163. {
  164. fVariableQuanta = FALSE;
  165. }
  166. break;
  167. }
  168. //
  169. // determine if we are using long or short
  170. //
  171. switch (InitRegVal & PROCESS_QUANTUM_LONG_MASK)
  172. {
  173. case PROCESS_QUANTUM_LONG_VALUE:
  174. fShortQuanta = FALSE;
  175. break;
  176. case PROCESS_QUANTUM_SHORT_VALUE:
  177. fShortQuanta = TRUE;
  178. break;
  179. case PROCESS_QUANTUM_LONG_DEF:
  180. default:
  181. if (fWorkstationProduct)
  182. {
  183. fShortQuanta = TRUE;
  184. }
  185. else
  186. {
  187. fShortQuanta = FALSE;
  188. }
  189. break;
  190. }
  191. //
  192. // Short, Variable Quanta == Workstation-like interactive response
  193. // Long, Fixed Quanta == Server-like interactive response
  194. //
  195. if (fVariableQuanta && fShortQuanta)
  196. {
  197. iNewChoice = PROCESS_PRIORITY_SEPARATION_MAX;
  198. CheckRadioButton(
  199. hDlg,
  200. IDC_PERF_WORKSTATION,
  201. IDC_PERF_SERVER,
  202. IDC_PERF_WORKSTATION
  203. );
  204. } // if
  205. else
  206. {
  207. iNewChoice = PROCESS_PRIORITY_SEPARATION_MIN;
  208. CheckRadioButton(
  209. hDlg,
  210. IDC_PERF_WORKSTATION,
  211. IDC_PERF_SERVER,
  212. IDC_PERF_SERVER
  213. );
  214. } // else
  215. //
  216. // Initialize the `memory usage' part.
  217. //
  218. fFailedToOpenMmKey = FALSE;
  219. RegRes = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  220. m_szRegMemoryManagementKey,
  221. 0,
  222. fAdministrator ? KEY_QUERY_VALUE | KEY_SET_VALUE : KEY_QUERY_VALUE,
  223. &m_hKeyMemoryManagement );
  224. if (RegRes == ERROR_SUCCESS)
  225. {
  226. CacheValue = 0;
  227. CacheLength = sizeof( CacheValue );
  228. RegRes = SHRegGetValue( m_hKeyMemoryManagement,
  229. NULL,
  230. m_szRegLargeSystemCache,
  231. SRRF_RT_DWORD,
  232. &CacheType,
  233. (LPBYTE) &CacheValue,
  234. &CacheLength );
  235. if (RegRes == ERROR_SUCCESS && CacheValue != 0)
  236. {
  237. CheckRadioButton(hDlg,
  238. IDC_PERF_CACHE_APPLICATION,
  239. IDC_PERF_CACHE_SYSTEM,
  240. IDC_PERF_CACHE_SYSTEM);
  241. }
  242. else
  243. {
  244. CheckRadioButton(hDlg,
  245. IDC_PERF_CACHE_APPLICATION,
  246. IDC_PERF_CACHE_SYSTEM,
  247. IDC_PERF_CACHE_APPLICATION);
  248. }
  249. }
  250. else
  251. {
  252. fFailedToOpenMmKey = TRUE;
  253. }
  254. if (fFailedToOpenMmKey || (!fAdministrator))
  255. {
  256. CheckRadioButton(hDlg,
  257. IDC_PERF_CACHE_APPLICATION,
  258. IDC_PERF_CACHE_SYSTEM,
  259. IDC_PERF_CACHE_APPLICATION);
  260. EnableWindow(GetDlgItem(hDlg, IDC_PERF_CACHE_APPLICATION), FALSE);
  261. EnableWindow(GetDlgItem(hDlg, IDC_PERF_CACHE_SYSTEM), FALSE);
  262. }
  263. InitCacheRegVal = CacheValue;
  264. NewCacheRegVal = CacheValue;
  265. //
  266. // Init the virtual memory part
  267. //
  268. if (VirtualInitStructures())
  269. {
  270. fVMInited = TRUE;
  271. SetDlgItemMB( hDlg, IDC_PERF_VM_ALLOCD, VirtualMemComputeAllocated(hDlg, &fTempPf) );
  272. //
  273. // If the system created a temp pagefile, warn the user that
  274. // the total pagefile size may appear a bit large, but only
  275. // do so once per System Applet invokation.
  276. //
  277. if (fTempPf && !fTempPfWarningShown)
  278. {
  279. MsgBoxParam(
  280. hDlg,
  281. IDS_TEMP_PAGEFILE_WARN,
  282. IDS_SYSDM_TITLE,
  283. MB_ICONINFORMATION | MB_OK
  284. );
  285. fTempPfWarningShown = TRUE;
  286. } // if (fTempPf...
  287. }
  288. break;
  289. case WM_DESTROY:
  290. //
  291. // If the dialog box is going away, then close the
  292. // registry key.
  293. //
  294. if (m_hKeyPerf)
  295. {
  296. RegCloseKey( m_hKeyPerf );
  297. m_hKeyPerf = NULL;
  298. }
  299. if (m_hKeyMemoryManagement)
  300. {
  301. RegCloseKey( m_hKeyMemoryManagement );
  302. m_hKeyMemoryManagement = NULL;
  303. }
  304. if (fVMInited)
  305. {
  306. VirtualFreeStructures();
  307. }
  308. break;
  309. case WM_NOTIFY:
  310. switch (((NMHDR *)lParam)->code)
  311. {
  312. case PSN_APPLY:
  313. //
  314. // Save new time quantum stuff, if it has changed
  315. //
  316. NewRegVal &= ~PROCESS_PRIORITY_SEPARATION_MASK;
  317. NewRegVal |= iNewChoice;
  318. if (NewRegVal != InitRegVal)
  319. {
  320. Value = NewRegVal;
  321. if (m_hKeyPerf)
  322. {
  323. Type = REG_DWORD;
  324. Length = sizeof( Value );
  325. RegSetValueEx( m_hKeyPerf,
  326. m_szRegPriority,
  327. 0,
  328. REG_DWORD,
  329. (LPBYTE) &Value,
  330. Length );
  331. InitRegVal = Value;
  332. //
  333. // Kernel monitors this part of the
  334. // registry, so don't tell user he has to reboot
  335. //
  336. }
  337. }
  338. //
  339. // Save `LargeSystemCache' if value changed
  340. //
  341. if (InitCacheRegVal != NewCacheRegVal) {
  342. CacheValue = NewCacheRegVal;
  343. if (m_hKeyMemoryManagement) {
  344. CacheType = REG_DWORD;
  345. CacheLength = sizeof( CacheValue );
  346. RegSetValueEx( m_hKeyMemoryManagement,
  347. m_szRegLargeSystemCache,
  348. 0,
  349. REG_DWORD,
  350. (LPBYTE) &CacheValue,
  351. CacheLength );
  352. InitCacheRegVal = CacheValue;
  353. //
  354. // Request a reboot if things changed
  355. //
  356. MsgBoxParam(
  357. hDlg,
  358. IDS_SYSDM_RESTART,
  359. IDS_SYSDM_TITLE,
  360. MB_OK | MB_ICONINFORMATION
  361. );
  362. g_fRebootRequired = TRUE;
  363. }
  364. }
  365. break;
  366. }
  367. break;
  368. case WM_COMMAND:
  369. {
  370. BOOL fEnableApply = (LOWORD(wParam) != IDC_PERF_CHANGE);
  371. LRESULT lres;
  372. switch (LOWORD(wParam))
  373. {
  374. case IDC_PERF_CHANGE:
  375. {
  376. lres = DialogBox(
  377. hInstance,
  378. MAKEINTRESOURCE(DLG_VIRTUALMEM),
  379. hDlg,
  380. VirtualMemDlg
  381. );
  382. if (fVMInited)
  383. {
  384. SetDlgItemMB(
  385. hDlg,
  386. IDC_PERF_VM_ALLOCD,
  387. VirtualMemComputeAllocated(hDlg, NULL)
  388. );
  389. }
  390. if (lres != RET_NO_CHANGE)
  391. {
  392. fEnableApply = TRUE;
  393. if (lres != RET_CHANGE_NO_REBOOT)
  394. {
  395. MsgBoxParam(
  396. hDlg,
  397. IDS_SYSDM_RESTART,
  398. IDS_SYSDM_TITLE,
  399. MB_OK | MB_ICONINFORMATION
  400. );
  401. g_fRebootRequired = TRUE;
  402. }
  403. }
  404. }
  405. break;
  406. case IDC_PERF_WORKSTATION:
  407. if (BN_CLICKED == HIWORD(wParam))
  408. {
  409. //
  410. // Workstations have maximum foreground boost
  411. //
  412. iNewChoice = PROCESS_PRIORITY_SEPARATION_MAX;
  413. //
  414. // Workstations have variable, short quanta
  415. NewRegVal &= ~PROCESS_QUANTUM_VARIABLE_MASK;
  416. NewRegVal |= PROCESS_QUANTUM_VARIABLE_VALUE;
  417. NewRegVal &= ~PROCESS_QUANTUM_LONG_MASK;
  418. NewRegVal |= PROCESS_QUANTUM_SHORT_VALUE;
  419. } // if
  420. break;
  421. case IDC_PERF_SERVER:
  422. if (BN_CLICKED == HIWORD(wParam))
  423. {
  424. //
  425. // Servers have minimum foreground boost
  426. //
  427. iNewChoice = PROCESS_PRIORITY_SEPARATION_MIN;
  428. //
  429. // Servers have fixed, long quanta
  430. //
  431. NewRegVal &= ~PROCESS_QUANTUM_VARIABLE_MASK;
  432. NewRegVal |= PROCESS_QUANTUM_FIXED_VALUE;
  433. NewRegVal &= ~PROCESS_QUANTUM_LONG_MASK;
  434. NewRegVal |= PROCESS_QUANTUM_LONG_VALUE;
  435. } // if
  436. break;
  437. case IDC_PERF_CACHE_APPLICATION:
  438. if (BN_CLICKED == HIWORD(wParam))
  439. {
  440. NewCacheRegVal = 0;
  441. } // if
  442. break;
  443. case IDC_PERF_CACHE_SYSTEM:
  444. if (BN_CLICKED == HIWORD(wParam))
  445. {
  446. NewCacheRegVal = 1;
  447. } // if
  448. break;
  449. }
  450. if (fEnableApply)
  451. {
  452. // Enable the "Apply" button because changes have happened.
  453. SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM)hDlg, 0L);
  454. }
  455. }
  456. break;
  457. case WM_HELP: // F1
  458. WinHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, HELP_FILE, HELP_WM_HELP,
  459. (DWORD_PTR) (LPSTR) aPerformanceHelpIds);
  460. break;
  461. case WM_CONTEXTMENU: // right mouse click
  462. WinHelp((HWND) wParam, HELP_FILE, HELP_CONTEXTMENU,
  463. (DWORD_PTR) (LPSTR) aPerformanceHelpIds);
  464. break;
  465. default:
  466. return FALSE;
  467. }
  468. return TRUE;
  469. }