• Aucun résultat trouvé

Process Management Kernel Services

Dans le document WRITING A DEVICE DRIVER FOR AIX VERSION 3 (Page 78-82)

buf_ptr = xmalloc(buffer_length, align, pinned_heap);

3.3.3 Other Services

3.3.3.3 Process Management Kernel Services

The Process and Exception Management kernel services provided by the base AIX kernel provide the capability to:

• Create kernel processes

• Reg ister exception handlers

• Provide process serialization

• Generate and handle signals

• Support event waiting and notification.

Kernel extensions can use the creatp and initp services to create and intialize a kernel process. Kernel processes are sheduled like user mode processes, but execute only within the kernel protection domain and have all security

privileges. They can use the sig_chk service to poll for signals that have been sent to the kernel process.2

Kernel processes are usually created as follows:

• A user mode process loads the kernel extension containing the process code (using sysconfig).

• A user mode process invokes the kernel extension's config entry point (using sysconfig again). The config entry point uses creatp and initp to make the process ready to run.

• The user process becomes the parent.

The setpinit kernel service allows a kernel process to change its parent process from the one that created it to the init process, so that the creating process does not receive the death-of-child signal upon kernel process termination.

The setjmpx, clrjmpx, and longjmpx kernel services allow a kernel extension to register an exception handler by:

• Saving the exception handler's context with the setjmpx kernel service

• Removing its saved context with the clrjmpx kernel service if no exception occurred

• Invoking the next registered exception handler with the longjmpx kernel service if it was unable to handle the exception.

The typical sequence of operation should be:

• Extension uses setjmpx to save state.

• setjmpx returns zero.

• The exception occurs.

• The kernel first-level exception handler arranges for longjmpx to be called after the retrun to the interrupted code.

• longjmpx executes in the environment of the interrupted code.

2 Kernel processes are not preemptable by signals.

3-19

• Execution continues at the return from sefjmpx, but with a non-zero return code.

The lockl and unlockl kernel services allow kernel extensions executing in the process environment to acquire or release locks that are typically used to serialize access to a resource. This provides a method to access and update global memory. The AIX kernel processes are preemptable. This means that even though you own a lock on a data structure in global memory, a kerne.l process of higher priority may preempt your process. That higher priority process will not preempt your process IF it tries to lock the data structure that you have locked. In that case, your process will execute at this higher priority until you release the lock (and then the other process will preempt you.)

CAUTION: TO AVOID DEADLOCK - - - , No deadlock detection is available.

To avoid deadlock, you must obey the following rules:

• Your system call (kernel service) should never return with locks still being held. (If you write a kernel process and use locks, do not return back to the calling process until you have released all locks.)

• Nesting locks (using more than one at a time) is permitted only if the nested lock has a finer granularity.

• Order of locks:

The kernel_lock has the coarsest granularity.

The file system locks (private to the filesystem).

Device driver locks (private to a device driver).

Private fine granularity locks.

• Locks must be unlocked in the reverse order of obtaining them.

The getpid kernel service can be used by a kernel extension in either the process or interrupt environment to determine the current execution

environment and obtain the process 10 of the current process if in the process environment.

The event notification services provide support for primitive interprocess communications where there can be only one process waiting on the event or shared event interprocess communications where there can be multiple processes waiting on the event. The traditional sleep and wakeup kernel services are also provided for code that is being ported from other Unix operating systems or previous versions of the AIX operating system. These compatibility services require that the Galler have the global kerne,-'ock (defined in lusr/include/sys/lockl.h), which is released before waiting in the sleep routine and re-acquired upon wakeup.

NOTE ---~

For performance reasons, use the e_sleep and e_wakeup kernel services instead of the traditional sleep and wakeup calls from the kernel.

The e_wait and e_post kernel services support single waiter event notification by using mutually agreed upon event control bits for the process being posted.

There are a limited number of control bits available for use by kernel

extensions. If the kernel_lock is owned by the caller of the e_wait service, it is released and re-acquired upon wakeup.

The e_wakeup, e_sleep and e_sleepl kernel services support a shared event notification mechanism that allows for multiple processes to be waiting on the shared event. These services support an unlimited number of shared events (by using caller-supplied event words). All processes waiting on the shared event are awakened by the e_wakeup service. If the caller of the e_sleep service owns the kernel lock, it is released before waiting and is reacquired upon wakeup. The e_sleepl service provides the same function as the e_sleep service except that a caller-specified lock is released and reacquired instead of the kernelJock.

There are 19 Process and Exception Management kernel services:

clrjmpx Removes a saved context by popping the most recently saved jump buffer from the list of saved contexts.

creatp Creates a new kernel process.

e_post Notifies a process of the occurrence of one or more events.

e_sleep Forces a process to wait for the occurrence of a shared event.

e_sleepl Forces a process to wait for the occurrence of a shared event.

e_wait Forces a process to wait for the occurrence of an event.

e_wakeup Notifies processes waiting on a shared event of the event's getpid

initp lockl

occurrence.

Gets the process 10 of the current process.

Changes the state of a kernel process from idle to ready.

Locks a conventional process lock.

longjmpx Allows exception handling by causing execution to resume at the most recently saved context.

pdsignal Sends a signal to a process group.

pidsig Sends a signal to a process.

setjmpx Allows saving the current execution state or context.

setpinit Sets the parent of the current kernel process to the init process.

sig_chk Provides a kernel process the ability to poll for receipt of signals.

sleep Forces the calling process to wait on a specified channel.

unlockl Unlocks a conventional process lock.

wakeup Activates processes sleeping on the speCified channel.

Dans le document WRITING A DEVICE DRIVER FOR AIX VERSION 3 (Page 78-82)