sun.com docs.sun.com My Sun Worldwide Sites

Previous Previous     Contents     Index     Next Next

Resource Controls API Functions

The resource controls API contains functions that:

Operate on Action-value Pairs of a Resource Control

The following list contains the functions that set or get the resource control block.

setrctl(2)

getrctl(2)

Operate on Local Modifiable Values

The following list contains the functions associated with the local, modifiable resource control block.

rctlblk_set_privilege(3C)

rctlblk_get_privilege(3C)

rctlblk_set_value(3C)

rctlblk_get_value(3C)

rctlblk_set_local_action(3C)

rctlblk_get_local_action(3C)

rctlblk_set_local_flags(3C)

rctlblk_get_local_flags(3C)

Retrieve Local Read-only Values

The following list contains the functions associated with the local, read-only resource control block.

rctlblk_get_recipient_pid(3C)

rctlblk_get_firing_time(3C)

rctlblk_get_enforced_value(3C)

Retrieve Global Read-only Actions

The following list contains the functions associated with the global, read-only resource control block.

rctlblk_get_global_action(3C)

rctlblk_get_global_flags(3C)

Resource Control Code Examples

Master Observing Process for Resource Controls

The following example is the master observer process. Figure 5-3 shows the resource controls for the master observing process.


Note - The line break is not valid in an /etc/project file. The line break is shown here only to allow the example to display on a printed or displayed page. Each entry in the /etc/project file must be on a separate line.


Figure 5-3 Master Observing Process

diagram showing resource controls for the master observing
process

The key points for the example include the following:

  • Because the task's limit is privileged, the application cannot change the limit, or specify an action, such as a signal. A master process solves this problem by establishing the same resource control as a basic resource control on the task. The master process uses the same value or a little less on the resource, but with a different action, signal = XRES. The master process creates a thread to wait for this signal.

  • The rctlblk is opaque. The struct needs to be dynamically allocated.

  • Note the blocking of all signals before creating the thread, as required by sigwait(2).

  • The thread calls sigwait(2) to block for the signal. If sigwait() returns the SIGXRES signal, the thread notifies the master process' children, which adapts to reduce the number of LWPs being used. Each child should also be modelled similarly, with a thread in each child, waiting for this signal, and adapting its process' LWP usage appropriately.

rctlblk_t *mlwprcb;
sigset_t smask;

/* Omit return value checking/error processing to keep code sample short */
/* First, install a RCPRIV_BASIC, v=1000, signal=SIGXRES rctl */
mlwprcb = calloc(1, rctlblk_size());	 /* rctl blocks are opaque: */
       rctlblk_set_value(mlwprcb, 1000);
       rctlblk_set_privilege(mlwprcb, RCPRIV_BASIC);
       rctlblk_set_local_action(mlwprcb, RCTL_LOCAL_SIGNAL, SIGXRES);
       if (setrctl("task.max-lwps", NULL, mlwprcb, RCTL_INSERT) == -1) {
           perror("setrctl");
           exit (1);
       }

/* Now, create the thread which waits for the signal */
        sigemptyset(&smask);
        sigaddset(&smask, SIGXRES);
        thr_sigsetmask(SIG_BLOCK, &smask, NULL);
thr_create(NULL, 0, sigthread, (void *)SIGXRES, THR_DETACHED, NULL));

/* Omit return value checking/error processing to keep code sample short */

void *sigthread(void *a)
{
        int sig = (int)a;
        int rsig;
        sigset_t sset;

        sigemptyset(&sset);
        sigaddset(&sset, sig);

        while (1) {
                 rsig = sigwait(&sset);
          if (rsig == SIGXRES) {
              notify_all_children();
              /* e.g. sigsend(P_PID, child_pid, SIGXRES); */
		     }
        }
}

Previous Previous     Contents     Index     Next Next
Company Info Contact Terms of Use Privacy Copyright 1994-2007 Sun Microsystems, Inc.