Using DOSKBD to Modify MS-DOS Keyboard Polling Detection
Determining that a Problem ExistsApplication performance problems will be obvious to the user, but to get amore precise picture of application resource use, use Performance Monitor.If you suspect an MS-DOS application is monopolizing the CPU, PerformanceMonitor can tell you precisely how much CPU time the application is using.To avoid false readings, make sure that Terminal Server is running as fewsystem-processes as possible. Run only Performance Monitor and a singleclient connection from which to run the MS-DOS application.
In Performance Monitor, open a graph that displays total system CPU usage,every second. Note the CPU usage before you have the client run the MS-DOSapplication. This will give you a baseline.
Now have the client run the MS-DOS application and note the increased CPUusage.
Lowering CPU Usage through Application PropertiesHave the client close the MS-DOS application. At the Terminal Server, runWindows NT Explorer, and highlight the application's executable file. Right-click this file and select Properties from the popup list. On theProperties Screen, select MISC (miscellaneous). You will find a slider barcalled Idle Sensitivity. This setting tells the system how much CPU time toallow the application to use while it is idle. Low sensitivity allows theapplication to use more CPU time. High sensitivity reduces allowable CPUtime. In this case, you want to increase sensitivity. Every applicationwill be different, so determining the correct sensitivity level willnecessitate some trial and error.
NOTE: If you are familiar with Citrix Winframe, you may have used the PIFEditor to modify an MS-DOS application's properties. Terminal Server usesthe Windows NT 4.0 method: right-click the application name in Windows NTExplorer, and open the application's Properties. Whenever properties arechanged, an application shortcut is created. You can place this shortcut onthe user's desktop, folder, or START Menu. Launching the application fromthe shortcut activates the properties you select. However, running theapplication's executable from a command line will not activate theproperties you select.
After you modify the application properties and exit the Properties screen,a shortcut will be created with a default name identical to the applicationexecutable name. Use this shortcut to start the application. You can modifythe shortcut name if you want to create multiple instances with differentproperties.
Have the client run this shortcut while you monitor Performance Monitor fordecreased CPU use.
NOTE: Modifying the application properties affects ONLY idle time. It doesnot decrease CPU use while the application is active (for example, when theuser is typing).
The DOSKBD UtilityThe DOSKBD utility can decrease an MS-DOS application's CPU usage fromkeyboard polling during active and idle times. It is also much more complexthan simply modifying the application properties. What is also much morecomplex?
DOSKBD works by monitoring how frequently the MS-DOS application checks thekeyboard buffer for input. If it checks too frequently during a specificinterval (by default, a single system timer tick), the application issuspended, or put to sleep, for a short period of time.
The default values for DOSKBD are in effect whenever an MS-DOS applicationis started. The defaults, switches, and usage are detailed below. If youneed to modify any of the default values, run DOSKBD with the new valuesfrom the same command prompt (or within the same MS-DOS session) that youuse to run the application. The easiest way to accomplish this is to createa batch file that runs DOSKBD with the appropriate settings and then runsthe application. An alternative to using a batch file is to create a customautoexec.nt file and associate it with the MS-DOS application's shortcutproperties.
By using batch files to run your MS-DOS applications, you can set differentvalues for DOSKBD as needed.
These are the default values for DOSKBD. These are the values in effect,whenever an MS-DOS window is opened.
- Number of milliseconds in a system timer tick is 10
- DetectionInterval = 1 tick(s) (10 msec)
- DetectProbationCount= 80
- InProbationCount= 35
- msAllowed= 0
- msSleep= 100
- BusymsAllowed= 60
- msProbationTrial= 2500
- msGoodProbationEnd= 2500
Activities such as updating the screen, doing file I/O, or getting mouse orkeyboard activity cause the system to mark the application as busy. Whenthe application is determined to be busy, it is awakened if it is beingpunished. In addition, the application is taken off probation.
If an application polls DetectProbationCount number of times within a giventimer tick, the application is put into probation if BusymsAllowed numberof milliseconds have elapsed since the last time the application wasdetected as busy. When the application is put into probation for msAllowedmilliseconds, it is punished for exceeding the allowed number of pollswithin a timer tick by being put to sleep for msSleep number ofmilliseconds.
While the application is on probation, the number of allowed polls isreduced to InProbationCount from DetectProbationCount. After exceeding theallowed number of polls, it is put to sleep as long as msAllowedmilliseconds have elapsed since the application probation.
The application is taken off probation if msGoodProbationEnd millisecondshave elapsed since the application was last punished. In addition, everymsProbationTrial milliseconds, the allowed number of polls in a timer tickis increased to DetectProbationCount. As long as the application is notpunished, the allowed number of polls stays at the higher level. If theapplication exceeds that level, the allowed level of polls is reduced toInProbationCount.
DOSKBD Command-Line Switches, Syntax, and ValuesAt a command prompt, type DOSKBD /? to display how to use DOSKBD. Todisplay the current settings, type DOSKBD. The number of millisecondsin a system timer tick is also displayed.
DOSKBD DOSKBD /DEFAULTS [/Q] DOSKBD [/DETECTPROBATIONCOUNT:nnn] [/INPROBATIONCOUNT:nnn] [/MSALLOWED:nnn] [/MSSLEEP:nnn] [/BUSYMSALLOWED:nnn] [/MSPROBATIONTRIAL:nnn] [/MSGOODPROBATIONEND:nnn] [/DETECTIONINTERVAL:nnn] [/STARTMONITOR [appname] | /STOPMONITOR] [/Q] DOSKBD displays the current settings. DOSKBD /DEFAULTS resets all tuning parameters to the system defaults. Any DOSKBD command line ending with /Q will not display any information. NOTE: Valid range for all values (represented by nnn) is 0 to 32767. /DETECTPROBATIONCOUNT:nnn The number of peeks in the detection interval required to force the application into the probation state and to sleep the application. /INPROBATIONCOUNT:nnn The number of peeks in the detection interval required to sleep the application when the application is in probation. Should be <= DETECTPROBATIONCOUNT. /MSALLOWED:nnn The number of milliseconds the application is allowed to be in the probation state before the system starts sleeping the application. /MSSLEEP:nnn The number of milliseconds that the application is put to sleep. /BUSYMSALLOWED:nnn When the application is detected as 'busy', the application cannot be put into the probation state for this # of milliseconds. /MSPROBATIONTRIAL:nnn When the application is in probation, DETECTPROBATIONCOUNT is used instead of INPROBATIONCOUNT every MSPROBATIONTRIAL milliseconds. /MSGOODPROBATIONEND:nnn When the application is in probation it must avoid being put to sleep for this # of milliseconds in order to be removed from probation. /DETECTIONINTERVAL:nnn The length of time (in ticks) used to count up the number of polling events. /STARTMONITOR [appname] Start gathering polling statistics. /STOPMONITOR Stop gathering polling information and display statistics.
How to Use DOSKBDThe typical scenario (typical scenario for what?) is that an MS-DOSapplication runs fine for a single user, but the system slows down whenmore users start using the application. When the system slows in this way,it is possible that the polling detection is not being aggressive enough toput the application into probation. Observe how much CPU the application isusing while doing nothing, and while doing common operations. Then exit theapplication and use DOSKBD to refine the polling parameters. Remember thatDOSKBD settings affect only the MS-DOS session in which they are set, so itis advisable that you modify your DOSKBD settings and run the MS-DOSapplication within a batch file, or through the use of a custom autoexec.ntfile.
Changing parameters by about 30 percent per try is recommended.
To more aggressively take the CPU away from the application, first trydecreasing DetectProbationCount and InProbationCount.
If that does not help or does not help enough, try lowering BusymsAllowedby 10 milliseconds per try. The default of msAllowed is already 0 (zero).If polling is being detected, the CPU should be significantly less than 100percent by now.
At this point it is important to make sure that the application is stillAble to respond in all the ways that it will be used. If it is notresponsive, you have gone too far, and you must back off some of thesettings. To further reduce the CPU used, msSleep can be increased. Usecaution while increasing msSleep, because some applications becomeunresponsive or jerky if this value is increased too much.
As you reduce the amount of CPU that the application is using, whileensuring that the application is still responsive, the systemshould be able to support a greater number of concurrent users.
Some applications may use close to 100 percent CPU, regardless of howaggressive you make the polling detection. Keyboard polling is a commonproblem, but applications may monopolize the CPU in other ways.
If an application is not getting enough CPU, the polling detection isprobably too aggressive, or the application needs more time to run beforeit is punished. You can increase DetectProbationCount and InProbationCountto lengthen the time it takes to detect that the application is polling.You can increase msAllowed from zero to give the application additionalexecution time, before it is punished for being on probation. You can alsogive the application more CPU while it is being punished by reducing thevalue of msSleep.
All these possibilities increase the amount of CPU that the applicationgets, which reduces the number of users who can simultaneously do usefulwork on the system.
NOTE: DOSKBD is used only for MS-DOS applications. However, Windowsapplications may also monopolize the CPU by checking the message queue toofrequently. This behavior can be modified through the system registry. Seethe article Performance Tuning CPU Usage for 16-bit and 32-bit WindowsApplications for more information.
Article ID: 186560 - Last Review: 12/05/2015 08:43:48 - Revision: 2.1
- kbnosurvey kbarchive kbinfo KB186560