⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kernel_objects.html

📁 ADI 公司blackfin系列的用户使用文挡。
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head>  <title></title>  <link rel="stylesheet" media="screen" type="text/css" href="./style.css" />  <link rel="stylesheet" media="screen" type="text/css" href="./design.css" />  <link rel="stylesheet" media="print" type="text/css" href="./print.css" />  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body><a href=start.html>start</a></br><div class="toc"><div class="tocheader toctoggle" id="toc__header">Table of Contents</div><div id="toc__inside"><ul class="toc"><li class="clear"><ul class="toc"><li class="clear"><ul class="toc"><li class="level3"><div class="li"><span class="li"><a href="#kernel_objects_and_sysfs" class="toc">Kernel Objects and Sysfs</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#proc_fs_history" class="toc">Proc FS History</a></span></div></li></ul></li><li class="level2"><div class="li"><span class="li"><a href="#a_brief_overview_of_sysfs" class="toc">A brief Overview of Sysfs</a></span></div><ul class="toc"><li class="level3"><div class="li"><span class="li"><a href="#mounting_sysfs" class="toc">Mounting Sysfs</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#some_sysfs_examples" class="toc">Some sysfs examples</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#sysfs_documentation" class="toc">Sysfs Documentation</a></span></div></li></ul></li><li class="level2"><div class="li"><span class="li"><a href="#kernel_objects_introduction" class="toc">Kernel Objects Introduction</a></span></div><ul class="toc"><li class="level3"><div class="li"><span class="li"><a href="#the_kernel_object_elements" class="toc">The Kernel Object Elements</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#major_components" class="toc">Major Components</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#use_overview" class="toc">Use Overview</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#kset_overview" class="toc">Kset Overview</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#ktype_overview" class="toc">Ktype Overview</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#subsystem_overview" class="toc">Subsystem Overview</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#confused" class="toc">Confused ??</a></span></div></li></ul></li><li class="level2"><div class="li"><span class="li"><a href="#kernel_object_sysfs_example" class="toc">Kernel Object / Sysfs Example</a></span></div><ul class="toc"><li class="level3"><div class="li"><span class="li"><a href="#define_the_kset" class="toc">Define the KSET</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#the_system_in_action" class="toc">The system in action</a></span></div></li></ul></li></ul></li></ul></div></div><h3><a name="kernel_objects_and_sysfs" id="kernel_objects_and_sysfs">Kernel Objects and Sysfs</a></h3><div class="level3"><p>This section contains  </p><ul><li class="level1"><div class="li"> History</div></li><li class="level1"><div class="li"> Sysfs Brief Overview</div></li><li class="level1"><div class="li"> Kernel Objects Overview</div></li><li class="level1"><div class="li"> Sysfs Basic Example</div></li></ul></div><!-- SECTION [1-154] --><h3><a name="proc_fs_history" id="proc_fs_history">Proc FS History</a></h3><div class="level3"><p> The <strong>/proc</strong> filesystem emerged as a superb tool during the development of the 2.4 kernel series.</p><p>It provided &ldquo;instant&rdquo; access to and control of kernel parameters in a user friendly manner such that by simply using &ldquo;cat&rdquo; and &ldquo;echo&rdquo; kernel features could be examined and manipulated.</p><p> Lack of documentation and a non unified structure caused a somewhat haphazard  application of this excellent feature.</p><p>An attempt was made in the 2.4 kernel to provide a more uniform approach to the concept using the SYSCTL interface.</p><p>The 2.6 kernel permitted a major change to the whole infrastructure and produced what is called <strong>sysfs</strong>.</p><p>Tightly coupled with the sysfs are things called kernel objects</p><pre class="code">   (more about those soon)</pre></div><!-- SECTION [155-906] --><h2><a name="a_brief_overview_of_sysfs" id="a_brief_overview_of_sysfs">A brief Overview of Sysfs</a></h2><div class="level2"><p>Sysfs is a ram based file system like procfs. It allows kernel structures to be exported and their attributes and relationships to be visible from userspace.</p><p>In fact it has all of the good features of the proc interface but with formal structure and documentation.</p><p>The only possible drawback to the system is the large amount of memory it takes to hold the in memory filesystem. This problem is being addressed in recent kernel patches.</p><p>Here is an overview of sysfs features</p><ul><li class="level1"><div class="li"> Sysfs is a dynamic system allowing run time events to modify</div></li></ul><p>     the system. </p><ul><li class="level1"><div class="li"> Every Kobject is a directory in sysfs</div></li><li class="level1"><div class="li"> Every Kobject is a child of a subsystem</div></li><li class="level1"><div class="li"> An object&rsquo;s attributes are exposed as regular files in the</div></li></ul><p>     object&rsquo;s directory.</p><ul><li class="level1"><div class="li"> Attributes an be read from or written to using sysfs.</div></li><li class="level1"><div class="li"> The process of registering a kobject will also create an entry in sysfs.</div></li><li class="level1"><div class="li"> Sysfs will implement a hierarchy for a object providing parents,</div></li></ul><p>     subsystem, and type definitions.</p><ul><li class="level1"><div class="li"> The subsystem can include links to show how devices are related.</div></li></ul></div><!-- SECTION [907-1995] --><h3><a name="mounting_sysfs" id="mounting_sysfs">Mounting Sysfs</a></h3><div class="level3"><p>The following command will mount the sysfs on a 2.6 system</p><pre class="code">  mount -t sysfs sysfs /sys</pre></div><!-- SECTION [1996-2128] --><h3><a name="some_sysfs_examples" id="some_sysfs_examples">Some sysfs examples</a></h3><div class="level3"><p>A tree view of a hard disk in sysfs.</p><pre class="code">/sys|-- block|   |-- hda|   |   |-- dev|   |   |-- device -&gt; ../../devices/pci0000:00/0000:00:07.1/ide0/0.0|   |   |-- hda1|   |   |   |-- dev|   |   |   |-- size|   |   |   |-- start|   |   |   `-- stat|   |   |-- queue|   |   |   |-- iosched|   |   |   |   |-- antic_expire|   |   |   |   |-- est_time|   |   |   |   |-- read_batch_expire|   |   |   |   |-- read_expire|   |   |   |   |-- write_batch_expire|   |   |   |   `-- write_expire|   |   |   |-- nr_requests|   |   |   `-- read_ahead_kb|   |   |-- range</pre><p>Looking at some of the elements</p><pre class="code">&gt;cat /sys/block/hda/hda2/start208845&gt;cat /sys/block/hda/hda2/dev3:2&gt;cat /sys/block/hda/queue/nr_requests128&gt;cat /sys/block/hda/queue/iosched/est_time18 % exit probability1 ms new thinktime1056767 sectors new seek distance</pre></div><!-- SECTION [2129-3035] --><h3><a name="sysfs_documentation" id="sysfs_documentation">Sysfs Documentation</a></h3><div class="level3"><p> &lt;p&gt; Unlike the older proc file system the sysfs and associated kernel objects do have some documentation and a reference design to look at.</p><pre class="code">Documentation   linux/Documentation/filesystems/sysfs.txtReference Design   linux/drivers/block/genhd.c</pre></div><!-- SECTION [3036-3333] --><h2><a name="kernel_objects_introduction" id="kernel_objects_introduction">Kernel Objects Introduction</a></h2><div class="level2"><p>The Kernel Object subsystem is complex. This is an attempt to understand the basics.</p><p>The key feature of a kernel object is the concept of a reference count.</p><p>The creator of an object can delete that object at any time but any users of that object will cause the object to remain in the system until its reference count falls to zero. At that time the object will be deleted.</p></div><h4><a name="the_kernel_object_players" id="the_kernel_object_players">The Kernel Object Players</a></h4><div class="level4"><p>The Kernel object basic structure is shown</p><pre class="code c">&nbsp;<span class="kw4">struct</span> kobject <span class="br0">&#123;</span>        <span class="kw4">char</span>                    * k_name;        <span class="kw4">char</span>                    name<span class="br0">&#91;</span>KOBJ_NAME_LEN<span class="br0">&#93;</span>;        atomic_t                refcount;        <span class="kw4">struct</span> list_head        entry;        <span class="kw4">struct</span> kobject          * parent;        <span class="kw4">struct</span> kset             * kset;        <span class="kw4">struct</span> kobj_type        * ktype;        <span class="kw4">struct</span> dentry           * dentry;<span class="br0">&#125;</span>;&nbsp;</pre></div><!-- SECTION [3334-4214] --><h3><a name="the_kernel_object_elements" id="the_kernel_object_elements">The Kernel Object Elements</a></h3><div class="level3"><p> In general a Kernel Object needs the following elements</p><ul><li class="level1"><div class="li"> k_name - The kernel name</div></li><li class="level1"><div class="li"> refcount - a count of processes using the object</div></li><li class="level1"><div class="li"> entry - a list</div></li><li class="level1"><div class="li"> Parent - a parent object</div></li><li class="level1"><div class="li"> name - the object&rsquo;s name</div></li><li class="level1"><div class="li"> type - this defines the attributes for an object</div></li><li class="level1"><div class="li"> set  - this is a set of objects that belong to  a specific subsystem</div></li><li class="level1"><div class="li"> Dentry - this is the reference to the object in the ram disk system</div></li></ul></div><!-- SECTION [4215-4668] --><h3><a name="major_components" id="major_components">Major Components</a></h3><div class="level3"><p> The Major Components used in understanding the Kernel Object System are:</p><ul><li class="level1"><div class="li"> kobjects - directories that appear in the sysfs file system .</div></li><li class="level1"><div class="li"> kset - a group of objects of a certain type.</div></li><li class="level1"><div class="li"> ktype - a group of helper functions for an object</div></li><li class="level1"><div class="li"> subsystem - the controller for a number of ksets.</div></li></ul></div><!-- SECTION [4669-4996] --><h3><a name="use_overview" id="use_overview">Use Overview</a></h3><div class="level3"><p> &lt;p&gt; In general, when using an object the flow is...</p><ol><li class="level1"><div class="li"> Define a type that tells the system the object attributes and the release</div></li></ol><p>function to delete the object. </p><ol><li class="level1"><div class="li"> Create a set of objects of the same type belonging to the same subsystem.</div></li></ol><p>   The set object will be the object&rsquo;s parent. Each set has a object type that defines the subsystem and a type that defines the type of objects contained in the set.</p><ol><li class="level1"><div class="li"> Create a subsystem to act as the root directory ( or use an existing one )</div></li><li class="level1"><div class="li"> Create the object and fill in the name, parent, set and type fields</div></li><li class="level1"><div class="li"> Register the object (which adds it to the sysfs).</div></li></ol></div><!-- SECTION [4997-5639] --><h3><a name="kset_overview" id="kset_overview">Kset Overview</a></h3><div class="level3">

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -