Modeling Shared Resources

In general terms, a shared resource is an entity that provides a service to a number of competing clients, whose access to the resource is limited. Typically, a client will request access to the resource, and depending on the availability of the resource, access may be granted immediately, or the client may have to wait. When access is granted, the client maintains access to the resource for a period of time, while the task that required the resource is being executed. When the task is completed, the resource is released, so that other competing clients may access it. Real world examples of shared resources include the CPU of a computer system (or one of the CPUs in a multiprocessor system), a printer or other output device, a communications channel, a bus for peripheral devices or expansion cards, or a page of shared random-access memory.

Because it is not always possible for a request to be serviced immediately upon its arrival, there must be some provision for buffering requests until the resource becomes available. A variety of schemes for managing these requests is possible, depending upon the desired performance goals, such as maximizing throughput, minimizing delay, minimizing the variation in delay (a property called fairness), or providing prioritized access to the resource.

A queue module is well suited to address these issues, as its built-in subqueues provide the necessary facilities for buffering requests (implemented as packets), and the ability to execute arbitrary process models allows different access disciplines to be implemented and compared. The process model managing a shared resource controls the manner in which requests are queued when the resource is not available, as well as the method by which the client actually controls the resource after access has been granted.

When a packet representing a request is received, the process model must determine whether the corresponding resource is available. If not, the request must be queued according to the chosen discipline. The queue models described in Modeling Queues can serve as a basis for implementation. When the resource becomes available, the requesting process can be notified in one of two ways, according to the requirements of the simulation:

  • The resource manager can return the request packet to the requesting client, setting a field to indicate that the request was granted and the client now has access to the resource. The client then begins the process for which the resource was needed. When it is done with the resource, it notifies the resource manager (which can be done either by a remote interrupt or by sending another packet), so that other requests can be serviced.

    This approach is called an allocation-oriented scheme, because it models the case where a resource is allocated by a process for its exclusive use. An example of this might be a tape drive allocated by a user of a computing facility to read data from a tape, as no other users can access the tape drive until the first user releases it (after finishing with the tape).

  • Alternatively, the resource manager can retain the request for a specific length of time (the service time), which may be computed according to parameters specified in the request packet. In this case, the processing is modeled within the resource manager, instead of within the client. At the end of the service period, the manager returns the request packet to the client, thereby notifying it that the requested processing has been completed.

    This approach is called a job-oriented scheme, because it models the case where clients submit jobs or tasks to be performed using a resource, and are notified when their job is completed. To continue the previous example, users of the computer facility may submit print jobs containing files to be printed. These jobs may be buffered in a queue and are serviced when the printer becomes available, at which point the users are notified that their documents are available. Another example is the facility’s time-sharing computer system, in which users’ computation tasks are serviced in time slices. This way, many jobs can use the shared resource simultaneously (or at least apparently so).

Each approach has its advantages and disadvantages. The allocation-oriented scheme requires the cooperation of the client processes to notify the resource manager when they release the resource so that other clients may gain access, which the job-oriented scheme avoids. Moreover, the allocation-oriented scheme provides total control of the resource to the client. While this is occasionally desirable, it precludes the use of “round-robin” or other scheduling strategies providing shared access to the resource, which is supported by the job-oriented scheme. On the other hand, it is possible with the allocation-oriented scheme to model cases in which a client must reserve a number of separately managed resources to do a given task.