有没有一种安全的方法从 Xenomai 实时线程调用 gettimeofday() ?

发布于 2024-11-19 02:29:03 字数 630 浏览 3 评论 0原文

我正在运行一个 Xenomai 实时线程,有时需要调用 gettimeofday(),以便根据 ptpd 找出当前时间。

然而,这样做似乎是不安全的:特别是,它偶尔会将 Xenomai 线程和 Linux 内核置于“活锁”状态,导致 gettimeofday() 旋转 CPU 并且永远不会返回,如 此处

我的问题是,有没有一种安全的方法可以从 Xenomai 实时线程获取 gettimeofday() 的信息?我正在考虑将我自己的 gettimeofday() 版本添加到我的 Linux 内核中(如果 read_seqretry() 返回 true,我的版本将会失败,这与 常规版本,发生这种情况时将永远循环)。然而,如果有更好的方法的话,我宁愿不开始定制 Linux 内核。

I'm running a Xenomai real time thread that sometimes needs to call gettimeofday(), in order to find out what the current time is according to ptpd.

However, doing that appears to be unsafe: in particular, it occasionally puts the Xenomai thread and the Linux kernel into a "livelock" situation, causing gettimeofday() to spin the CPU and never return, as described here.

My question is, is there a safe way to get gettimeofday()'s information from a Xenomai real time thread? I'm considering adding my own version of gettimeofday() to my Linux kernel (my version would fail if read_seqretry() returns true, unlike the regular version which will loop forever when that happens). However, I'd just as soon not start customizing the Linux kernel if there is a better way to do it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七禾 2024-11-26 02:29:03

2012 年 10 月更新
对于任何其他偶然发现此线程的人...

检查 Xenomai API:
http://www.xenomai.org/documentation/trunk/html/api /group__clock.html

这是一个代码片段,已使用 Xenomai 2.6 进行测试:

// Get system time in nanoseconds (real-time safe)
// Time is usually related to GMT, because Xenomai syncs time during
// bootup, so you might get a different time offset to gettimeofday()
// which is based on your current timezone. 
double time = (double)rt_timer_read(); 
time /= 1000000000; // convert to seconds

Update Oct 2012
For anyone else stumbling across this thread...

Check the Xenomai API:
http://www.xenomai.org/documentation/trunk/html/api/group__clock.html

Here's a code snippet for you, tested with Xenomai 2.6:

// Get system time in nanoseconds (real-time safe)
// Time is usually related to GMT, because Xenomai syncs time during
// bootup, so you might get a different time offset to gettimeofday()
// which is based on your current timezone. 
double time = (double)rt_timer_read(); 
time /= 1000000000; // convert to seconds
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文