LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 889|回复: 8

提两个问题,请各位大侠帮忙看看。

[复制链接]
发表于 2005-9-20 10:34:03 | 显示全部楼层 |阅读模式
1、内核软中断如何初始化,如何把一个软中断关联到处理函数中的?
2、什么是serialization,网络部分serialization有什么用途,serialization是否非常消耗CPU资源?

谢谢!
发表于 2005-9-20 12:42:17 | 显示全部楼层

  1. enum
  2. {
  3.         HI_SOFTIRQ=0,
  4.         TIMER_SOFTIRQ,
  5.         NET_TX_SOFTIRQ,
  6.         NET_RX_SOFTIRQ,
  7.         SCSI_SOFTIRQ,
  8.         TASKLET_SOFTIRQ
  9. };

  10. void open_softirq(int nr, void (*action)(struct softirq_action*), void *data)
  11. {
  12.         softirq_vec[nr].data = data;
  13.         softirq_vec[nr].action = action;
  14. }
复制代码


serialization是什么意思, 串行化?

linux的网络栈大量使用Per_CPU数据, 减少了CPU之间同步的需要。搞不懂serialization是什么意思了.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-9-20 13:16:46 | 显示全部楼层
unlikely()
#define unlikely(x)        __builtin_expect(!!(x), 0)
这个语句怎么这么费解呀?
回复 支持 反对

使用道具 举报

发表于 2005-9-20 14:56:42 | 显示全部楼层
__builtin_expect在man gcc中有解释。
偶也奇怪为什么要用两个!.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-9-20 18:54:25 | 显示全部楼层
我怎么没找到?
能讲讲是什么意思吗?
回复 支持 反对

使用道具 举报

发表于 2005-9-20 20:35:05 | 显示全部楼层
info gcc
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-9-21 12:49:22 | 显示全部楼层
#define unlikely(x) __builtin_expect(!!(x), 0)
有理解的 兄弟吗?
解析一下。
回复 支持 反对

使用道具 举报

发表于 2005-9-21 13:51:34 | 显示全部楼层
Branch Annotation
The gcc C compiler has a built-in directive that optimizes conditional branches as either very likely taken or very unlikely taken. The compiler uses the directive to appropriately optimize the branch. The kernel wraps the directive in very easy-to-use macros, likely() and unlikely().
For example, consider an if statement such as the following:
if (foo) {
        /* ... */
}

To mark this branch as very unlikely taken (that is, likely not taken):
/* we predict foo is nearly always zero ... */
if (unlikely(foo)) {
        /* ... */
}

Conversely, to mark a branch as very likely taken:
/* we predict foo is nearly always nonzero ... */
if (likely(foo)) {
        /* ... */
}

You should only use these directives when the branch direction is overwhelmingly a known priori or when you want to optimize a specific case at the cost of the other case. This is an important point: These directives result in a performance boost when the branch is correctly predicted, but a performance loss when the branch is mispredicted. A very common usage for unlikely() and likely() is error conditions. As one might expect, unlikely() finds much more use in the kernel because if statements tend to indicate a special case.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-9-21 14:09:59 | 显示全部楼层
谢谢。
我也查到了,以前的版本中是没有两个!!号的,最近的版本把它加上了,不知什么原因。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表