Sysinit framework in FreeBSD [go]

Source: Internet
Author: User

Sysinit is a general framework for calling sorting and separate execution mechanisms. FreeBSD currently uses it for dynamic kernel initialization. Sysinit enables various subsystems of FreeBSD kernel to be reorganized, added, deleted, and replaced when the kernel or module dynamically loads links, during kernel and module loading, you do not have to modify a static ordered initialization schedule table or even re-compile the kernel. This system also enables kernel modules (now known as KLD) to be compiled, linked, loaded during system boot, and even loaded during system runtime. These operations are completed through the "kernel linker" and "linker set. A Linker set is a link method. This method collects the static declarative data in the entire program source file into a adjacent addressable data unit. Sysinit relies on the linker to obtain the static data stated in multiple places throughout the program source code and construct them into a data block adjacent to each other. This method is called "linker set ). Sysinit uses two linker sets to maintain two data sets, including the call sequence, function, and Data Pointer that will be submitted to the function for each data entry .?
Sysinit sorts functions according to two types of priority identifiers for execution. The identifier of the first type of priority is the identifier of the subsystem. The Global sequence of the functions of the sub-system executed by sysinit is defined in the enumeration sysinit_sub_id in. The second type of priority identifies the order of the elements in the subsystem and is defined within the enumeration sysinit_elem_order in. Sysinit can be used at two times: when the system is started or the kernel module is loaded, the system destructor or the kernel module is uninstalled. The kernel subsystem usually uses the sysinit definition item during system startup to initialize the data structure. For example, the process scheduling subsystem uses a sysinit definition item to initialize the data structure of the running queue. The device driver should avoid using sysinit () directly. For physical devices in the bus structure, use the function called by driver_module () to first detect the existence of the device, then initialize the device. In this system process, we will do something specific to the device and then call sysinit () itself. For virtual devices that are not part of the bus structure, use dev_module ().

Use sysinit

Interface

Header file

<Sys/kernel. h>

?

Macro

Sysinit (uniquifier, subsystem, order, func, ident)

Sysuninit (uniquifier, subsystem, order, func, ident)

Start


Macro sysinit () creates a sysinit data item in the sysinit startup dataset so that sysinit can sort and execute functions when the system is started or loaded by modules. Sysinit () has a parameter uniquifier, which is used by sysinit to identify a data item. It is followed by the sub-system sequence number, sub-system element sequence number, to-call function, and data passed to the function. All functions must have a constant pointer parameter.
Example of sysinit ()

# Include <sys/kernel. h>

?

Void foo_null (void * unused)

{

Foo_doo ();

}

Sysinit (Foo, si_sub_foo, si_order_foo, foo_null, null );

?

Struct Foo foo_voodoo = {

Foo_voodoo;

}

?

Void foo_arg (void * vdata)

{

Struct Foo * Foo = (struct Foo *) vdata;

Foo_data (FOO );

}

Sysinit (Bar, si_sub_foo, si_order_foo, foo_arg, & foo_voodoo );

?

Note that si_sub_foo and si_order_foo should be in the enumeration sysinit_sub_id and sysinit_elem_order mentioned above. You can use existing enumeration items or add your own enumeration items to the definitions of these two enumeration items. You can use mathematical expressions to fine-tune the execution sequence of sysinit. The following example shows a sysinit that needs to be executed just before the Kernel Parameter Adjustment.

Example of adjusting the sequence of sysinit ()

Static void

Mptable_register (void * dummy _ unused)

{

?

Apic_register_enumerator (& mptable_enumerator );

}

?

Sysinit (mptable_register, si_sub_tunables-1, si_order_first,

Mptable_register, null );

Structure Analysis


The behavior of macro sysuninit () is equivalent to that of sysinit (), but it adds the data entry to the analytic data set of sysinit .?

Example of sysuninit ()

# Include <sys/kernel. h>

?

Void foo_cleanup (void * unused)

{

Foo_kill ();

}

Sysuninit (foobar, si_sub_foo, si_order_foo, foo_cleanup, null );

?

Struct foo_stack = {

Foo_stack_voodoo;

}

?

Void foo_flush (void * vdata)

{

}

Sysuninit (barfoo, si_sub_foo, si_order_foo, foo_flush, & foo_stack );


Src = http:// OS .51cto.com/art/200511/11446.htm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.