免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: iterator
打印 上一主题 下一主题

关于内核线程的几个问题,请教 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2008-07-26 11:07 |只看该作者
原帖由 crspo 于 2008-7-26 10:25 发表

http://lxr.linux.no/linux/kernel/softirq.c#L490
行吗?

ksoftirqd我是看过的,现在我觉得光看代码中kthread有否让出CPU还不能说明问题,因为很可能只是设计的好而非必须要遵守什么规则。
实际上对于内核线程在设计时必须主动让出CPU这条规则,我没在其它文档(内核文档我也查了)上看到过(可能是由于我读书粗心),我觉得这是条很重要的规则,在看这个帖子前我就从没想过这个问题。
当然主要原因是因为我水平还不够。
我非常奇怪ULK和LKD这样书,作者怎么会忽略这么重要的东西。昨天看了一下ktrhead相关函数,发觉很多书籍都对它忽略了,因为本身就是进程的衍生物,所以介绍内容不多。不过现在看来还是要研究一下,昨天从注释看来,userspace也是可以创建的kthread的,抽空研究一下
欢迎继续讨论啊,看有没有什么新发现

论坛徽章:
0
12 [报告]
发表于 2008-07-26 22:42 |只看该作者
原帖由 Solaris12 于 2008-7-25 09:59 发表



Solaris系统的内核线程没有时间片,不属于分时调度类。

Solaris用户内核线程才有时间片的概念。

好久不见,

如果可以对kthread作nice操作,2.6.24+ scheduler就可以调度kthread, 且与preempt无关,
BTW, hrtimer and tick-sched 对2.6.26 scheduler的改进很有意思。

论坛徽章:
0
13 [报告]
发表于 2008-07-27 11:09 |只看该作者
原帖由 sisi8408 于 2008-7-26 22:42 发表

好久不见,

如果可以对kthread作nice操作,2.6.24+ scheduler就可以调度kthread, 且与preempt无关,
BTW, hrtimer and tick-sched 对2.6.26 scheduler的改进很有意思。

不明白。即使kthread的优先级最低,关抢占,该kthread不主动调用scheduler,当kthread运行时,如何被调度出去?调度点在什么地方?
兄弟对hrtimer和tickless kernel有研究吗?前段时间我正好把这部分代码看了一遍,讨论讨论?可以从这个帖子开始http://linux.chinaunix.net/bbs/thread-990377-1-1.html
此外2.6.26已经完全支持tickless kernel了吗?在2.6.25里面还只支持CPU进入S3后关掉tick,离full tickless还很远。不过我认为不管怎么改都和kthread的调度问题无关,因为现在的问题是如果kthread不主动调scheduler,我找不到调度点在什么地方。

论坛徽章:
0
14 [报告]
发表于 2008-07-27 11:34 |只看该作者
on UP,
#define MAX_SOFTIRQ_RESTART 1
and issue tcpdump
then load NIC, say 200Kpps

cat /proc/82546/status

what u get?

[ 本帖最后由 sisi8408 于 2008-7-27 11:35 编辑 ]

论坛徽章:
0
15 [报告]
发表于 2008-07-27 11:39 |只看该作者
原帖由 sisi8408 于 2008-7-27 11:34 发表
on UP,
#define MAX_SOFTIRQ_RESTART 1
and issue tcpdump
then load NIC, say 200Kpps

cat /proc/82546/status

what u get?

??????????????????????????????????????????

论坛徽章:
0
16 [报告]
发表于 2008-07-27 21:31 |只看该作者

  1. /*
  2. * we cannot loop indefinitely here to avoid userspace starvation,
  3. * but we also don't want to introduce a worst case 1/HZ latency
  4. * to the pending events,
  5. **********************************************
  6. * so lets the scheduler to balance the softirq load for us. *
  7. **********************************************
  8. */
  9. static inline void wakeup_softirqd(void)
  10. {
  11.         /* Interrupts are disabled: no need to stop preemption */
  12.         struct task_struct *tsk = __get_cpu_var(ksoftirqd);

  13.         if (tsk && tsk->state != TASK_RUNNING)
  14.                 wake_up_process(tsk);
  15. }
复制代码

论坛徽章:
0
17 [报告]
发表于 2008-07-28 08:06 |只看该作者
原帖由 sisi8408 于 2008-7-27 21:31 发表

/*
* we cannot loop indefinitely here to avoid userspace starvation,
* but we also don't want to introduce a worst case 1/HZ latency
* to the pending events,
*************************** ...



看来Linux的system kernel thread一样不是分时调度的,没有时间片的概念。

论坛徽章:
0
18 [报告]
发表于 2008-07-28 09:36 |只看该作者
原帖由 sisi8408 于 2008-7-27 21:31 发表

/*
* we cannot loop indefinitely here to avoid userspace starvation,
* but we also don't want to introduce a worst case 1/HZ latency
* to the pending events,
*************************** ...

兄弟是在回答我的问题吗?
如果是很抱歉你理解错这段话了。这是指软中断过多导致用户态程序饥饿的情况,这也是ksoftirqd存在的原因。
此外兄弟能否多打几个字,并且用汉语。

论坛徽章:
0
19 [报告]
发表于 2008-07-28 10:00 |只看该作者
原帖由 Solaris12 于 2008-7-28 08:06 发表



看来Linux的system kernel thread一样不是分时调度的,没有时间片的概念。

时间片的概念是有的,因为本身kthread就是用和普通进程一样的接口创建的,除了地址空间在内核态外,没有任何区别。
只是现在看来即使超时它也无法到达调度点。
嗯,我今天把这部分代码看一遍应该找到原因了

论坛徽章:
0
20 [报告]
发表于 2008-07-28 10:08 |只看该作者
Robert Love当年对类似问题的答复中,也只是轻描淡写地说kernel thread是I/O-bound型的,很奇怪。

In 2.4, a process running in the kernel (whether its a normal process or
a kernel thread) cannot be preempted.  It only relinquishes the
processor when it voluntarily does so.

In 2.6, the kernel is preemptive, so processes (including kernel
threads) can be preempted.

But in either case, kernel threads are I/O-bound and they perform a set
amount of work in response to certain events.  So they are not always
running.

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

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP