简体   繁体   English

FreeBSD内核模块中的Timer?

[英]Timer in FreeBSD kernel module?

I'd like to let my kernel module periodically do something (a certain time interval, like 10 sec) in FreeBSD kernel. 我想让我的内核模块在FreeBSD内核中定期执行某项操作(一定的时间间隔,如10秒)。 Any example for doing that? 有这样做的例子吗?

I searched and found that there are functions like callout/timeout(old), but they seem complicated, and I cannot find good examples for them. 我搜索发现有一些类似callout / timeout(old)的函数,但是它们看起来很复杂,我找不到适合他们的示例。 For callout'', it seems that callout_reset'' is similar to the function I want (arguments include a handler and a time interval). 对于callout'', it seems that callout_reset''与我想要的功能类似(参数包括处理程序和时间间隔)。 But it seems to only execute once. 但它似乎只执行一次。 So I'm confused. 所以我很困惑。

Examples are the best, even for function ``timeout''. 例子是最好的,即使对于功能``timeout''。

You need to use callout(9). 您需要使用callout(9)。 As for examples... Hm, for a real-world code you could take a look at this: http://svnweb.freebsd.org/base/head/sys/dev/iscsi/iscsi.c?revision=275925&view=markup ; 作为示例...嗯,对于真实代码,您可以看一下: http ://svnweb.freebsd.org/base/head/sys/dev/iscsi/iscsi.c?revision=275925&view =标记 ; search for is_callout. 搜索is_callout。 Basically, you need 'struct timeout', a function that will get called periodically, and then you need to get the timer ticking: 基本上,您需要“结构超时”,该函数将定期调用,然后需要对计时器进行计时:

struct callout callout;

static void
callout_handler(void *whatever)
{
        // do your stuff, and make sure to get called again after 'seconds'.
        callout_schedule(&callout, seconds * hz);
}

static void
start_ticking(void)
{
        callout_init(&callout, 1);
        callout_reset(&callout, seconds * hz, callout_handler, whatever);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM