红联Linux门户
Linux帮助

solaris上一个小bug的fix过程

发布时间:2007-12-21 00:02:07来源:红联作者:tribudis
  最近在fix一个bug,说起来挺简单。driver中用到了drv_usecwait(),这个函数是busy-wait,也就是占住CPU,直到指定的时间耗完。如果等待的时间很长,这对CPU资源将是一种很大的浪费。所以需要用其它delay方法。其中就有deay(9F)调用。

  delay(9F)在使用中有种种限制,首先,它不能在interrupt context中调用。第一次的fix没有注意到这一点。被codereviewer指出来了。其次,它不能用于polled模式下,在polled模式下,“when system enters standalone mode, only one CPU and one thread keep active. Timesharing, interrupts and system services are turned off.” delay(9F)使用了timeout(9F),这是通过一个中断服务线程实现的。再次,在dev_ops的devo_reset 函数中也不能调用delay。因为devo_reset会被reset_leaves调到,即系统重启或关闭时,在文件86pc/os/machdep.c中可看到相关注释:
mdboot(int cmd, int fcn, char *mdep, boolean_t invoke_cb)

引用:
/*
* stop other cpus and raise our priority. since there is only
* one active cpu after this, and our priority will be too high
* for us to be preempted, we're essentially single threaded
* from here on out.
*/


  此时,系统处于单线程,单cpu状态, 与polled模式相同。

  当以上这些都fix之后,在最后关头,再次被人质疑,delay不能用在mutex held情况下。因为在mutex_enter 的manpage中,有这么一个注意事项:

引用:
  Never hold a mutex when calling a service that may block,
  for example kmem_alloc(9F) with KM_SLEEP or delay(9F).


  Sigh!所以这个bug fix到目前为止还没有结束。
文章评论

共有 1 条评论

  1. 于 2013-08-14 17:16:26发表:

    不错,谢谢,如果可以将你的问题和解决方法描述的再详细点对我们就更有帮助了。