Deep understanding of Linux Network Technology Insider--kernel infrastructure and component initialization

Source: Internet
Author: User

Kernel options during bootLinux allows the user to pass the kernel configuration options to the boot record, and then the boot record to the kernel to make adjustments to the kernel.
Start_kernel calls two times Parse_args to configure user input data during boot.
    Parse_param is a function that resolves input parameter strings for kernel configuration options. The format of the string is:Name_variable=value. addresses a specific keyword and invokes the corresponding function.
Registration Keywords:to define with a macro:
__setup (String, fn)
String represents the keyword, and FN represents the associated handler function. The macro definition of __setup is divided into two kinds of situations
#ifndef module#define early_param (str, FN)                        __setup_param (str, FN, FN, 0) #else/* MODULE */#define EARLY_PARAM (str, FN ) #endif

When a piece of code is compiled into a module, __setup is ignored.
See two examples:
Net/core/dev.c_setup ("netdev=", Netdev_boot_setup); Net/ethernet/eth.c__setup ("ether=", Netdev_boot_setup);   

As can be seen from the example above, different keywords can be associated with the same handler function.    
     the reason for calling two times in Start_kernel Parse_args is that the kernel boot options fall into two categories:

Default options:
    Most options fall into this category, defined by __setup, and processed by the first invocation of Parse_args,
Initial options:
    These options must be processed earlier by other options. Early_param (rather than __setup) for processing.Early_param andThe __setup difference is that Early_param sets an identity for the kernel to recognize.
        The kernel is associated with functions that are handled by parameters and parameters by __setup macros or Early_param macros. Let's take a look at the macro and the definition of the associated structure:
#define __SETUP (str, FN) __setup_param (str, FN, FN, 0) #define EARLY_PARAM (str, FN) __setup_param (str, FN, FN, 1) #define __ Setup_param (str, unique_id, FN, early) static char __setup_str_# #unique_id [] __initdata __aligned (1) = str; The static struct Obs_kernel_param __setup_# #unique_id__used __section (. Init.setup) __attribute__ ((Aligned (sizeof (long ))) = {__setup_str_# #unique_id, FN, early}    Early_param and __setup The only difference is the last parameter __setup_param passed to early. _setup_param defines the structure of a struct obs_kernel_param type, and then passes the _section macro so that the variable can be placed in the segment at link time. Init.setup. The following is an introduction to. init.setup. The    struct OBS_KERNEL_PARAM structure is as follows: struct Obs_kernel_param {    const char *str;    Int (*setup_func) (char *);    


str saysKey,setup_func represents handler. Early is similar to a priority flag because some of the parameters passed to the kernel need to be parsed earlier than others. Refer to the section below for an analysis of both:


two times analysis:
Parse_args ("Early Options", Tmp_cmdline, NULL, 0, Do_early_param);p Arse_args ("booting kernel", Static_command_line, __ Start___param,   __stop___param-__start___param,   &unknown_bootoption);


When the Parse_args function is called the second time in the Start_kernel function, the module options that are filled with Module_param macros are checked, which are stored in the Kernel_param data structure, Module_ param macros Ensure that these data structures are stored in a specific memory block (__param), with pointers __start___param and __stop___param qualified.


__setup_start......__setup_end: This area will be released at the end of the boot phase and the user will not be able to see or modify these options during run time; __start___param......__stop___param: This area will not be released. Its contents are output to the/sys file system, which can be displayed to the user.

The Init.setup memory area has __setup () and Early_param () macros defined keywords are placed into the __setup_start......__setup_end area, except that the EARLY_PARAM macro-defined keywords are set early tags.
struct Obs_kernel_param {    const char *str;    Int (*setup_func) (char *);    int early;};




Module initialization code: Each module is provided with two functions called Init_module and Cleanup_module. specified by the following two macros:
Module_init (XXX); module_exit (XXX);
Current Module Design Model:
Static Char version[] _ _devinitdata = Drv_name "... "; static struct Vortex_chip_info {...} Vortex_info_tbl[] _ _devinitdata = {{"3c590 vortex 10Mbps",... ... ...} static int _ _init vortex_init (void) {...} static void _ _exit Vortex_cleanup (void) {...} Module_init (Vortex_init); Module_exit (Vortex_cleanup);


Macro-label-based optimizations:Linux uses a number of macros to set special properties on some functions and data structures. These grand many are defined inInclude/linux/init.h. Some macros tell the linker to place code or data structures with the same properties in a specific, dedicated memory area.

the right side is the name of the macro.


























Deep understanding of Linux Network Technology Insider--kernel infrastructure and component initialization

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.