When There's Never Enough Time....Resource Control
by Walter Ruppe and Rose Pozomke, IBM TPF Resource Control Team

Do you sometimes feel like there aren't enough hours in a day? Well, think about your TPF system. There are times when it, too, has to give all it's got just to keep up with its work. Wouldn't it be nice if you could help your TPF system? Wouldn't it be nice if you could shift some of your system's work to times when it wasn't so busy? Well, now there is something that can help....resource control.

Resource control is new code that is available on the TPF 4.1 system for program update tape (PUT) 5. When your system is running like crazy and using a lot of system resources, you can use resource control to limit which programs are allowed to run. You can force utility or batch processes to run only when system resource utilization is low.

You can also use resource control to time slice some of your transactions. If you have transactions that use a lot of CPU time but don't necessarily need to be completed quickly, time slicing may be the answer. Time slicing will break the run time of your transaction into smaller chunks. It will let your transaction run for a while and then suspend it for a while. It will continue in this way, running and suspending, until your transaction is completed successfully. This will give your other transactions more of a chance to get their work done.

Resource Control Macros
Resource control is implemented as two macros: the LODIC macro and the TMSLC macro. The LODIC macro is a general use macro that applications can use to determine the level of available system resources and to identify entry control blocks (ECBs) as low-priority ECBs. This provides the ability to automatically control utility or batch processes so that these processes do not deplete system resources during busy periods.

The TMSLC macro is a restricted use macro that provides the ability to time slice CPU-intensive application This macro forces these applications to give up control after running for a certain period of time. This gives other transactions a chance to run.

LODIC Overview
There are a number of different ways you can use the LODIC macro:

· To simply check the level of available system resources

· To immediately suspend an ECB

· To mark an ECB to be suspended later.

In all these cases, the LODIC macro checks the availability of system resources. When we say that the LODIC macro checks the availability of system resources, we are talking about the availability of the following block types:

· Common blocks (CMBs)

· Entry control blocks (ECBs)

· Frames (FRMs)

· Input/output blocks (IOBs)

· System work blocks (SWBs).

You can code the LODIC macro to check the availability of any one or more of these five block types. As your system runs, a certain percentage of each of these block types will be free and a certain percentage will be in use. Before you use the LODIC macro, define the percentage of each block type that must be free for your ECB to continue to run. We call these percentages shutdown levels.

In general, when the availability of a particular block type falls below a shutdown percentage, all ECBs associated with that shutdown percentage will be suspended, and will remain suspended, until the availability of that block type rises above the shutdown percentage.

LODIC Warnings
Watch out for suspended ECBs that use a large amount of resources. If you get too many resources tied up in suspended ECBs, you can get into a condition where the suspended ECBs never regain control. You never want to get into the condition where your suspended ECBs are holding so many resources that there are not enough free resources remaining for the system to get to the point where the availability of resources is above the LODIC macro shutdown levels.

You also need to be careful when using the LODIC macro to determine if enough resources are available to create an ECB. When you use a macro to create an ECB (such as CREMC or SWISC), the ECB is not created immediately. First, a system work block (SWB) is placed on a list in the CPU loop. The ECB is not actually created until the SWB is dispatched from the list. Because of this delay, you should call the LODIC macro each time before you create a single ECB, and the application program that issues the LODIC macro should give up control before calling the LODIC macro again. You need to do this to help ensure that ECBs that are created are given a chance to receive control and perform work. If you do not do this, you can end up running out of resources because too much work was scheduled before any work actually started.

TMSLC Overview
The TMSLC macro is used to enable or disable time slicing for an ECB. When an ECB is enabled for time slicing, it will lose control at defined time intervals. This allows other tasks in the system to receive control.

The TMSLC macro will let you specify the length of time an ECB can run without giving up control, the length of time the ECB can remain suspended, and the maximum total lifetime of the ECB.

TMSLC Warnings
Time slicing was created to address TPF Users Group requirement S93018, "Long Running Programs." This requirement requests the ability to time slice CPU-intensive applications. TPF time-slicing support meets these requirements. It provides a way to run CPU-intensive applications like fare calculations and large table lookups, which can take an extremely long CPU time to process. CPU-intensive applications like these used to require the use of DLAYC or DEFRC macros to avoid application timeout dumps (CTL-10); but now, time slicing can be used to handle these situations.

Because of the way time slicing has been implemented, it is important to remember that time slicing should be enabled only in CPU-intensive application code. Time slicing is not supported across TPF services such as:

· SVC and fast-link macro calls

· Enters to TPF real-time segments

· TPF Database Facility (TPFDF) functions

· TPF application programming interface (API) library functions.

Also remember that there is no way to tell exactly where in the application code the ECB will be when it gets time sliced. Because of this, an ECB that is enabled for time slicing must never issue a $LOCKC macro. For much the same reason, an ECB that is enabled for time slicing must never update a global field or any other storage area that can be updated simultaneously by another ECB.

System Task Dispatcher Changes
A major change in functional flow is being made to the system task dispatcher (CPU loop) for all I-streams. A new list, called the suspend list, is being added. This list will function similarly to the way that the VCT list functions. ECBs that issue TMSLC or LODIC macros can end up being suspended at any time following the macro call. While suspended, these ECBs reside on a suspend list while other transactions get processed. The system task dispatcher will dispense from the suspend list similarly to the way it dispenses from the VCT list; that is, at equal priority to the input list but still dispatched during input list shutdown.

Application Timeout Changes
A new application timeout dump (CTL-2010) has been added, which pertains only to ECBs that can be time sliced. This timeout will only occur if the ECB that is being time sliced exceeded its maximum allowable CPU run time, which is never reset (even during a loss of control) while the ECB is marked for time slicing.

When an ECB issues a TMSLC macro, it becomes enabled for time slicing and will (in general) not time out with a CTL-10. Instead, it gets time sliced and allows other work to get done. The ECB that is being time sliced can, theoretically, use an infinite amount of CPU time while giving up control at random time intervals.

Functional Message Changes
To support resource control, two new functional messages have been added and two existing functional messages have been updated. The two new functional messages are ZSYSL and ZTMSL. ZSYSL is used to adjust parameters that are used by the LODIC macro and ZTMSL is used to adjust parameters that are used by the TMSLC macro.

ZSYSL allows you to display or change the defined shutdown levels and ZTMSL allows you to change the run time, suspend time, and maximum lifetime of an ECB.

The two existing functional messages that have been updated are ZECBL and ZSTAT. ZECBL will now allow you to display and resume a suspended ECB. ZSTAT has been updated to include the ECB counts for the VCT list and the SUSPEND list in the ZSTAT U System Utilization Display.

Data Collection and Data Reduction
Resource control adds a few new data collection and data reduction fields. These fields will help to give you some information about what resource control is doing in your system. These new fields include information about the suspend list, the VCT list, and the activities associated with the LODIC and TMSLC macros.

Note: Because of the changes made by resource control, you will need to update your Data Reduction JCL. You will need to specify STEMP as LRECL=328, BLKSIZE=3280 and specify STEMPIS as LRECL=1024,BLKSIZE=10240.

Getting Ready for Resource Control
If this overview has whet your appetite, you may want to start looking at your applications to find places where you can use resource checking or time slicing. If you already have some form of resource checking or time slicing in your system, it may be to your advantage to remove those changes and standardize on the new macros that are provided by resource control.