<?xml version="1.0" encoding="gbk"?>
<rss version="2.0">
  <channel>
    <title>曲径通幽论坛 - Functions and Macro</title>
    <link>http://www.groad.net/bbs/forum.php?mod=forumdisplay&amp;fid=80</link>
    <description>Latest 20 threads of Functions and Macro</description>
    <copyright>Copyright(C) 曲径通幽论坛</copyright>
    <generator>Discuz! Board by Comsenz Inc.</generator>
    <lastBuildDate>Fri, 10 Apr 2026 21:44:56 +0000</lastBuildDate>
    <ttl>60</ttl>
    <image>
      <url>http://www.groad.net/bbs/static/image/common/logo_88_31.gif</url>
      <title>曲径通幽论坛</title>
      <link>http://www.groad.net/bbs/</link>
    </image>
    <item>
      <title>获得当前进程描述符 | current</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=3819</link>
      <description><![CDATA[内核：2.6.11
平台：x86 32位

进程内核态栈结构如下图所示：

上图中，thread_info 结构位于栈的底部，该结构定义为：
[mw_shl_code=cpp,true]struct thread_info {
    struct task_struct    *task;        /* main task structure */
    struct exec_domain    *ex ...]]></description>
      <category>Functions and Macro</category>
      <author>beyes</author>
      <pubDate>Fri, 17 Jun 2011 06:31:25 +0000</pubDate>
    </item>
    <item>
      <title>内核链表遍历 | list_for_each_entry()</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=3544</link>
      <description><![CDATA[内核版本：2.6.24
list_for_each_entry() 宏用来遍历内核链表，它定义在 include/linux/list.h 中：
[mw_shl_code=cpp,true]/**
 * list_for_each_entry    -    iterate over list of given type
 * @pos:    the type * to use as a loop cursor.
 * @head:    the he ...]]></description>
      <category>Functions and Macro</category>
      <author>beyes</author>
      <pubDate>Thu, 19 May 2011 05:47:32 +0000</pubDate>
    </item>
    <item>
      <title>获得链表中第一个结构的指针 |list_first_entry()</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=3540</link>
      <description><![CDATA[list_first_entry() 宏用来获取链表中第一个结构的指针。当然了，如果你将此函数用在一个模块中，当你插入这个模块后，那么链表中原来第一个模块结构就会退变为第 2 个。链表的插入原理见：http://www.groad.net/bbs/read.php?tid-3181.html

该宏定义在 include/linux/ ...]]></description>
      <category>Functions and Macro</category>
      <author>beyes</author>
      <pubDate>Wed, 18 May 2011 07:31:20 +0000</pubDate>
    </item>
    <item>
      <title>获得链表结构体指针 | list_entry()</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=3539</link>
      <description><![CDATA[list_entry() 宏可以用来获得链表结构体指针，它定义在 include/linux/list.h 中：
[mw_shl_code=cpp,true]/**
 * list_entry - get the struct for this entry
 * @ptr:&#160;&#160;&#160;&#160;the &amp;struct list_head pointer.
 * @type:&#160;&#160;&#160;&#160;the  ...]]></description>
      <category>Functions and Macro</category>
      <author>beyes</author>
      <pubDate>Wed, 18 May 2011 06:37:24 +0000</pubDate>
    </item>
    <item>
      <title>分配对齐的空间| ALIGN</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=3520</link>
      <description><![CDATA[ALIGN 宏定义在 linux/kernel.h 中：


它的 ...]]></description>
      <category>Functions and Macro</category>
      <author>beyes</author>
      <pubDate>Thu, 12 May 2011 09:16:24 +0000</pubDate>
    </item>
    <item>
      <title>获取当前时间 | current_kernel_time()</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=3513</link>
      <description><![CDATA[内核：2.6.11 32位 x86
获取当前时间可通过 xtime 变量获得，它是 struct timespec 类型，此类型是秒与纳秒结构：

但是不推荐直接使用该 ...]]></description>
      <category>Functions and Macro</category>
      <author>beyes</author>
      <pubDate>Sun, 08 May 2011 06:26:23 +0000</pubDate>
    </item>
    <item>
      <title>得到 jiffies_64 值 | get_jiffies_64()</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=3409</link>
      <description><![CDATA[内核：2.6.38.2
在 64 位的计算机架构上，jiffies 和 jiffies_64 是同一个变量。但在 32 位的处理器上，对 64 位的值的访问不是原子的，也就是说，在读取 64 位值的高 32 位和低 32 位这段时间间隔里，可能会再次发生更新，从而获得错误的值。因此，对 64 为计数器的直 ...]]></description>
      <category>Functions and Macro</category>
      <author>beyes</author>
      <pubDate>Wed, 20 Apr 2011 12:26:49 +0000</pubDate>
    </item>
    <item>
      <title>自旋锁与顺序锁| spinlock_t, seqlock_t</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=3375</link>
      <description><![CDATA[内核：2.6.32
平台：x86 32位
spinlock_t 是自旋锁类型，定义为：
[mw_shl_code=cpp,true]typedef struct {
        raw_spinlock_t raw_lock;
#ifdef CONFIG_GENERIC_LOCKBREAK
        unsigned int break_lock;
#endif
#ifdef CONFIG_DEBUG_SPINLOCK
        unsigne ...]]></description>
      <category>Functions and Macro</category>
      <author>beyes</author>
      <pubDate>Thu, 14 Apr 2011 08:51:22 +0000</pubDate>
    </item>
    <item>
      <title>读取 TSC 寄存器|rdtsc,rdtscl,rdtscll</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=3374</link>
      <description><![CDATA[内核：2.6.24
平台：x86 32位
TSC (时间戳计数器) 是一个 64 位的寄存器，用来记录 CPU 时钟周期，从内核空间和用户空间都可以读取它。rdtsc, rdtscl, rdtscll 定义在 include/asm-x86/msr.h 中，它们用以读取 TSC 计数器，但有所区别。

rdtsc
[mw_shl_code=cpp,true]# ...]]></description>
      <category>Functions and Macro</category>
      <author>beyes</author>
      <pubDate>Thu, 14 Apr 2011 05:43:27 +0000</pubDate>
    </item>
    <item>
      <title>用户空间时间到 jiffies 的转换|timespec_to_jiffies()</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=3363</link>
      <description><![CDATA[timespec_to_jiffies() 是用户空间到 jiffies 的转换。timespec 的时间结构是由 秒 和 纳秒组成：



最 ...]]></description>
      <category>Functions and Macro</category>
      <author>beyes</author>
      <pubDate>Tue, 12 Apr 2011 04:46:28 +0000</pubDate>
    </item>
    <item>
      <title>SH_DIV,ACTHZ,TICK_NSEC</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=3329</link>
      <description><![CDATA[内核：2.6.24
平台：x86 32位
在 linux 中有一个脉搏，它就是 HZ，在现代的 X86 上，改值被定义为 1000 ，也就是说每 1ms 会产生一次时钟中断，这个时钟间隔叫做一个节拍 (tick) 。

TICK_NSEC 就是以纳秒为单位来表示这个节拍的长度。TICK_NSEC 被定义为：

[mw_shl_co ...]]></description>
      <category>Functions and Macro</category>
      <author>beyes</author>
      <pubDate>Sat, 02 Apr 2011 13:30:39 +0000</pubDate>
    </item>
    <item>
      <title>产生HZ的PIT设置值 | LATCH</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=3319</link>
      <description><![CDATA[LATCH 宏中定义了要写往 PIT (8254) 计数器0 中的值，该值可以让计数器周期性的产生中断。LATCH 定义在 include/linux/jiffies.h 中：
[mw_shl_code=cpp,true]/* LATCH is used in the interval timer and ftape setup. */
#define LATCH  ((CLOCK_TICK_RATE + HZ/2) /  ...]]></description>
      <category>Functions and Macro</category>
      <author>beyes</author>
      <pubDate>Thu, 31 Mar 2011 13:22:06 +0000</pubDate>
    </item>
    <item>
      <title>输入时钟脉冲频率 | CLOCK_TICK_RATE</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=3312</link>
      <description><![CDATA[Linux 使用 CLOCK_TICK_RATE 来表示输入时钟脉冲频率(8254 内部振荡器频率)，这个值在老的内核中会看到是 1193180HZ，在现在的内核中该值会被修正为&#160;&#160;1193182Hz，该值定义在中 asm-x86/timex.h ：
[mw_shl_code=cpp,true]define PIT_TICK_RATE 1193182 /* Und ...]]></description>
      <category>Functions and Macro</category>
      <author>beyes</author>
      <pubDate>Wed, 30 Mar 2011 12:07:16 +0000</pubDate>
    </item>
    <item>
      <title>设置当前进程状态|set_current_state()</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=3279</link>
      <description><![CDATA[内核：2.6.24
平台：X86 32位

set_current_state() 可以用来设置进程状态。在驱动程序中，往往会设置两个状态：TASK_INTERRUPTIBLE 和 TASK_UNINTERRUTIBLE 。这两个状态分别对应着两种休眠，前者可以接受信号，后者则不会接受。

set_current_state() 定义在 linux/sc ...]]></description>
      <category>Functions and Macro</category>
      <author>beyes</author>
      <pubDate>Thu, 24 Mar 2011 05:50:54 +0000</pubDate>
    </item>
    <item>
      <title>选择内存屏障指令|alternative()</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=3276</link>
      <description><![CDATA[内核：2.6.24
平台：x86 32位

在使用 mb(), rmb() 以及 wmb() 等避免内存屏障的宏中，它们最终是被定义成 alternative() 宏的。

mb(), rmb() wmb() 定义如下：
[mw_shl_code=cpp,true]
/*
 * Force strict CPU ordering.
 * And yes, this is required on UP too when ...]]></description>
      <category>Functions and Macro</category>
      <author>beyes</author>
      <pubDate>Thu, 24 Mar 2011 02:12:13 +0000</pubDate>
    </item>
    <item>
      <title>内存复制 | __memcpy()</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=3211</link>
      <description><![CDATA[内核：2.6.24

 __memcpy() 是内存复制函数，它在 asm-x86/string_32.h 中定义，用汇编语言实现，代码如下：


内存复制，一般使将 ESI 指向的内存区里的数据复制到 EDI 指向的内存区里，复制时使用 REP 指令前缀 MOV 数据到目的地 (rep ; movsb)并以 ECX 用作循环计数 ...]]></description>
      <category>Functions and Macro</category>
      <author>beyes</author>
      <pubDate>Thu, 10 Mar 2011 06:05:11 +0000</pubDate>
    </item>
    <item>
      <title>不允许lseek文件 | nonseekable_open()</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=3205</link>
      <description><![CDATA[内核：2.6.24


使用数据区时，可以使用 lseek 来往上往下地定位数据。但像串口或键盘一类设备，使用的是数据流，所以定位这些设备没有意义；在这种情况下，不能简单地不声明 llseek 操作，因为默认方法是允许定位的。

在 open 方法中调用 nonseekable_open() 时，它会 ...]]></description>
      <category>Functions and Macro</category>
      <author>beyes</author>
      <pubDate>Wed, 09 Mar 2011 03:14:42 +0000</pubDate>
    </item>
    <item>
      <title>进程状态|task_struct.state</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=3194</link>
      <description><![CDATA[内核：2.6.24
在进程信息结构体 task_struct 里第 1 个成员为 state ，它指定了进程的当前状态，这些状态由 sched.h 文件中的宏定义给出：
[mw_shl_code=cpp,true]
/*
 * Task state bitmask. NOTE! These bits are also
 * encoded in fs/proc/array.c: get_task_state ...]]></description>
      <category>Functions and Macro</category>
      <author>beyes</author>
      <pubDate>Sun, 06 Mar 2011 08:47:31 +0000</pubDate>
    </item>
    <item>
      <title>加入等待队列 | add_wait_queue() | add_wait_queue_exclusive()</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=3186</link>
      <description><![CDATA[内核：2.6.24


add_wait_queue() 用来将一个进程添加到等待队列，该函数在获得必要的自旋锁后，使用 __add_wait_queue() 函数来完成队列添加工作。

__add_wait_queue() 定义为：


list_add() 是标准的建立队列双向链表函数。


另外还有一个  add_wait_queue_exclusi ...]]></description>
      <category>Functions and Macro</category>
      <author>beyes</author>
      <pubDate>Fri, 04 Mar 2011 13:02:33 +0000</pubDate>
    </item>
    <item>
      <title>等待队列结构体 | wait_queue_t</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=3180</link>
      <description><![CDATA[内核：2.6.24


等待队列中的成员为下面的数据结构：


flag 的值或者为 WQ_FLAG_EXCLUSIVE 或者为 0 。WQ_FLAG_EXCLUSIVE 相被独占地唤醒。
private 是一个指针，一般都用来指向等待进程的 task_struct 实例。
func 调用它来唤醒等待进程。
task_list 用作一个链表元素 ...]]></description>
      <category>Functions and Macro</category>
      <author>beyes</author>
      <pubDate>Fri, 04 Mar 2011 02:20:39 +0000</pubDate>
    </item>
  </channel>
</rss>