`
- 浏览:
11417184 次
-
本文翻译整理自:<wbr style="line-height:25px"><a rel="nofollow" href="http://www.faqs.org/docs/kernel/x277.html" style="color:rgb(207,121,28); line-height:25px; text-decoration:none">http://www.faqs.org/docs/kernel/x277.html</a>
<div style="line-height:25px">
<div style="line-height:25px">This demonstrates a feature of kernel 2.2 and later. Notice the change in the definitions of the init and cleanup functions.</div>
<div style="line-height:25px">
<span style="color:#993300; line-height:25px">__init</span><span style="color:#003366; line-height:25px">和</span><span style="color:#993300; line-height:25px">__exit</span><span style="color:#003366; line-height:25px">这两种修饰是在</span><span style="color:#0000ff; line-height:25px">android</span><span style="color:#003366; line-height:25px">的内核2.2中才引入的。它们主要用于释放函数的代码所占的内存。</span>
</div>
<div style="line-height:25px">The __init macro causes the init function to be discarded and its memory freed once the init function finishes for built-in drivers, but not loadable modules. If you think about when the init function is invoked, this makes perfect
sense.</div>
<div style="line-height:25px">
<span style="color:#003366; line-height:25px">在一个函数前添加</span><span style="line-height:25px; color:rgb(153,51,0)">__init</span><span style="color:#003366; line-height:25px">修饰的话,那么在这个函数首次执行完成后,该函数的代码所占的内存,将被释放掉</span>。<span style="line-height:25px; color:rgb(153,51,0)">__init</span><span style="color:#003366; line-height:25px">主要用于驱动的初始话。另外,在</span><span style="color:#0000ff; line-height:25px">loadable</span><span style="color:#003366; line-height:25px">的模块中函数,使用</span><span style="line-height:25px; color:rgb(153,51,0)">__init</span><span style="color:#003366; line-height:25px">,将无效。</span>
</div>
<div style="line-height:25px">There is also an __initdata which works similarly to __init but for init variables rather than functions.</div>
<div style="line-height:25px">
<span style="color:#993300; line-height:25px">__initdata</span><span style="color:#000080; line-height:25px">和</span><span style="line-height:25px; color:rgb(153,51,0)">__init</span><span style="color:#000080; line-height:25px">相似,只是前者用于变量,后者用于函数。</span>
</div>
<div style="line-height:25px">The __exit macro causes the omission of the function when the module is built into the kernel, and like __init, has no effect for loadable modules. Again, if you consider when the cleanup function runs, this makes complete sense;
built-in drivers don't need a cleanup function, while loadable modules do.</div>
<div style="line-height:25px">
<span style="color:#000080; line-height:25px">在一个函数前添加__</span><span style="color:#800000; line-height:25px">exit</span><span style="color:#000080; line-height:25px">修饰的话,那么在the module is built into the kernel后,该函数所占的内存,将被释放掉。另外它和__init一样,在loadable的模块中函数将无效。</span>
</div>
<div style="line-height:25px">These macros are defined in linux/init.h and serve to free up kernel memory. When you boot your kernel and see something like Freeing unused kernel memory: 236k freed, this is precisely what the kernel is freeing.</div>
</div>
<div style="line-height:25px">
<span style="line-height:25px">示例1</span>:</div>
<div style="line-height:25px">
<div style="line-height:25px">Example 2-5. hello-3.c</div>
<div style="line-height:25px"><br style="line-height:25px"></div>
<div style="line-height:25px"><span style="color:#808080; line-height:25px">/* hello-3.c - Illustrating the __init, __initdata and __exit macros.</span></div>
<div style="line-height:25px"><span style="color:#808080; line-height:25px">*/</span></div>
<div style="line-height:25px">#include <linux/module.h> /* Needed by all modules */</div>
<div style="line-height:25px">#include <linux/kernel.h> /* Needed for KERN_ALERT */</div>
<div style="line-height:25px">#include <linux/init.h> /* Needed for the macros */</div>
<div style="line-height:25px">
<span style="color:#993300; line-height:25px">static int</span><span style="color:#0000ff; line-height:25px">hello3_data __initdata = 3;</span>
</div>
<div style="line-height:25px">
<span style="color:#993300; line-height:25px">static int</span><span style="color:#0000ff; line-height:25px"></span><span style="color:#ff00ff; line-height:25px">__init</span><span style="color:#0000ff; line-height:25px">hello_3_init(void)</span>
</div>
<div style="line-height:25px"><span style="color:#0000ff; line-height:25px">{</span></div>
<div style="line-height:25px"><span style="color:#0000ff; line-height:25px"> printk(KERN_ALERT "Hello, world %d\n", hello3_data);</span></div>
<div style="line-height:25px"><span style="color:#0000ff; line-height:25px"> return 0;</span></div>
<div style="line-height:25px"><span style="color:#0000ff; line-height:25px">}</span></div>
<div style="line-height:25px">
<span style="color:#993300; line-height:25px">static void</span><span style="color:#0000ff; line-height:25px"></span><span style="color:#ff00ff; line-height:25px">__exit</span><span style="color:#0000ff; line-height:25px">hello_3_exit(void)</span>
</div>
<div style="line-height:25px"><span style="color:#0000ff; line-height:25px">{</span></div>
<div style="line-height:25px"><span style="color:#0000ff; line-height:25px"> printk(KERN_ALERT "Goodbye, world 3\n");</span></div>
<div style="line-height:25px"><span style="color:#0000ff; line-height:25px">}</span></div>
<div style="line-height:25px">
<span style="color:#0000ff; line-height:25px">module_init(</span><span style="color:#ff6600; line-height:25px">hello_3_init)</span><span style="color:#0000ff; line-height:25px">;</span>
</div>
<div style="line-height:25px">
<span style="color:#0000ff; line-height:25px">module_exit(</span><span style="color:#ff6600; line-height:25px">hello_3_exit)</span><span style="color:#0000ff; line-height:25px">;</span>
</div>
<div style="line-height:25px"><span style="color:#0000ff; line-height:25px"><br style="line-height:25px"></span></div>
<div style="line-height:25px">By the way, you may see the directive "__initfunction()" in drivers written for Linux 2.2 kernels:</div>
<div style="line-height:25px"><span style="color:#3366ff; line-height:25px">__initfunction(int init_module(void))</span></div>
<div style="line-height:25px"><span style="color:#3366ff; line-height:25px">{</span></div>
<div style="line-height:25px"><span style="color:#3366ff; line-height:25px"> printk(KERN_ALERT "Hi there.\n");</span></div>
<div style="line-height:25px"><span style="color:#3366ff; line-height:25px"> return 0;</span></div>
<div style="line-height:25px"><span style="color:#3366ff; line-height:25px">}</span></div>
<div style="line-height:25px">
<span style="color:#000080; line-height:25px">This macro served the same purpose as __init, but is now very</span><span style="color:#ff6600; line-height:25px">deprecated</span><span style="color:#000080; line-height:25px">in
favor of</span><span style="color:#ff9900; line-height:25px">__init</span><span style="color:#000080; line-height:25px">. I only mention it because you might see it modern kernels. As of 2.4.18, there are 38 references to __initfunction(), and of 2.4.20,
there are 37 references. However, don't use it in your own code.</span>
</div>
</div>
</wbr>
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
module的__init__exitmodule的__init__exit
pytorch __init__.pyi文件,博客配套使用,修改pytorch的bug。
u-boot的board_init_f和board_init_r阶段执行任务的对比
1、进入上面创建好的干净的工程目录,把上面建立好的default.xml文件复制到这里。 2、把客户端的id_rsa.pub加入到服务端的 authorized_keys里。... getnames_and_init_push_git_proj.py
linux内核从start_kernel到init.pdf
__init__.py的内容可以为空,一般用来进行包的某些初始化工作或者设置__all__值,__all__是在from … import * 语句使用的,__all__中定义的模块将在from … import * 中全部导入 目录结构: test1代码: package_...
通常在一个工程文件里面,我可能会发现在某个文件夹下面会有一个命名为__init__.py的py文件 why need init.py? 在一个工程文件下面,我们可能会有很多的py文件(模块),文件太多,管理很不方便,这时候我们就可以创建...
解决Pytorch在Pycharm中没有代码提示的问题。首先把Pycharm升级到2019.1.1,然后把Pytorch升级到1.0.1.post2,然后把下载的__init__.pyi替换掉site-packages/torch/中的__init__.pyi就行。
本文实例讲述了php使用curl_init()和curl_multi_init()多线程的速度比较。分享给大家供大家参考,具体如下: php中curl_init()的作用很大,尤其是在抓取网页内容或文件信息的时候,例如之前文章《php使用curl获取...
解决Pytorch在Pycharm中没有代码提示的问题。首先把Pycharm升级到2019.1.1,然后把Pytorch升级到1.0.1.post2,然后把下载的__init__.pyi替换掉site-packages/torch/中的__init__.pyi就行。
drm_i2c_encoder_init - Initialize an I2C slave encoder.
python中__init__(self)方法和__init__(self,参数1,参数2)的区别(csdn)————
mt_soc_snd_init 结构体图
二者均是Python面向对象语言中的函数,__new__比较少用,__init__则用的比较多。 【异】 __new__是在实例创建之前被调用的,因为它的任务就是创建实例然后返回该实例对象,是个静态方法。__init__是当实例对象创建...
初始化串口1,用于输入和输出。 2.RTC初始化。 3.间隔时间将 RTC时间通过串口 1发送出去。整个工程包含 4类源文件,其中有主函数main(void)函数用作程序初始化; RCC_Configuration(void)用于配置系统时钟设置,及...
__new__和__init__的区别主要表现在:它自身的区别及在Python中新式类和老式类的定义。 __new__ 负责对象的创建而 __init__ 负责对象的初始化。 __new__:创建对象时调用,会返回当前对象的一个实例 __init__:创建完...
功能说明:netctoss项目的sql初始化脚本