Performance Tuning CPU Usage for 16-Bit and 32-Bit Windows Applications

Performance Tuning CPU Usage for 16-Bit and 32-Bit Windows Applications

16-bit or 32-bit Windows applications may use too much CPU time even when idle (no keyboard or mouse events). Terminal Servers registry can be modified to detect this behavior, suspending application execution and allowing other applications to utilize the CPU, making multitasking much more efficient.

Modifying the Registry

1.       Run REGEDT32.EXE and locate the following key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\Current Version\Terminal Server\Compatibility\Applications

2.       Double-click the Applications subkey to reveal several application settings that are pre-defined. Select SETUP under the Applications subkey. The following values are displayed on the right side of the Registry Editor window:

FirstCountMsgQPeeksSleepBadApp:REG_DWORD:0xf

Flags:REG_DWORD:0x8
MsgQBadAppSleepTimeInMillisec:REG_DWORD:0
NthCountMsgQPeeksSleepBadApp:REG_DWORD:0x5

 

3.       With the SETUP subkey highlighted, select Save Key from the Registry pull-down menu. The filename can be anything, such as SETUP.REG. Once the SETUP values are saved, you need to create a subkey for your application.

4.       With the Applications subkey highlighted, choose Add Key on the Edit pull-down menu. Set the Key Name field to the name of the executable in question, minus the extension. For example, for the application MYAPP.EXE, type MYAPP in the Key Name field. Leave the Class field blank. Click OK.

5.       To copy the values from the SETUP subkey, select your new subkey (for example, MYAPP) and choose Restore from the Registry pull-down menu. Choose the filename you created in Step 3. Click Yes when the warning dialog box is displayed. Your new application subkey now has the same values as the SETUP subkey.

6.       You must now fine tune the values for your application. The values are described in the following sections.

Bad Application Registry Values

The default values for the bad application settings are:

FirstCountMsgQPeeksSleepBadApp = 0xf
MsgQBadAppSleepTimeInMillisec = 0x1
NthCountMsgQPeeksSleepBadApp = 0x5
Flags: 0x8

FirstCountMsgQPeeksSleepBadApp is the number of times the application must query the message queue before Terminal Server decides that it is ill-behaved. Decrease this value to put the application to sleep more often so it uses less CPU time.

MsgQBadAppSleepTimeInMillisec is the number of milliseconds the application is suspended once Terminal Server has decided that it is ill-behaved. Increase this value to use less CPU time. If this value is zero, polling detection is disabled.

NthCountMsgQPeeksSleepBadApp After the application is determined to be bad, this setting is the number of times the application must query the message queue before it is suspended again. Decrease this value to use less CPU time.

Flags is set to a value corresponding to the type of Windows application. Valid values are:

0x4 for Win16 applications only
0x8 for Win32 applications only
0xC for either Win16 or Win32 applications

Bad Application Settings

All values are expressed in hexadecimal. When changing the values, first click the Decimal button and input the decimal value. For instance, if you want the MsgQBadAppSleepTimeInMillisec value to be set to 200 milliseconds, perform the following steps:

1.        Double click MsgQBadAppSleepTimeInMillisec

2.        Click the Decimal radio button

3.        Enter 200 in the Data field

4.        Click OK

The value is now converted to 0xc8, the hexadecimal equivalent of 200 decimal.

Notes

1.        To modify polling detection for DOS applications, use the DOSKBD utility. For more information see the article Modifying DOS Application Keyboard Polling Detection.

 

When tuning these parameters, make sure Performance Monitor is running. These parameters will affect the amount of CPU used by an application. These parameters usually trade off CPU usage versus application responsiveness.