简体   繁体   English

如何在Vxworks中实现C定时器

[英]How to implement C timer in Vxworks

I have implemented timer functionality to find the performance of my task in windows and linux.我已经实现了计时器功能来查找我的任务在 windows 和 linux 中的性能。 But linux implementation is not working in Vxworks PPC 750 board.但是 linux 实现在 Vxworks PPC 750 板上不起作用。 gettimeofday is not available in Vxworks. gettimeofday在 Vxworks 中不可用。

t1 = vxworks_start_timer(); //How to implement ?
my_task();
t2 = vxworks_stop_timer(); //How to implement ?
elapsedtime = t2-t1;

How to implement this timer in Vxworks to calculate elapsed time of a task.如何在 Vxworks 中实现这个计时器来计算任务的经过时间。

If the system timer tick resolution is sufficient, you could use tickGet() and sysClkRateGet() or clock_gettime() , but resolution is still limited to system clock tick如果系统计时器滴答分辨率足够,您可以使用tickGet()tickGet() sysClkRateGet()clock_gettime() ,但分辨率仍限于系统时钟滴答

Otherwise, you could read TBL and TBU (arch-specific)否则,您可以阅读TBLTBU (特定于拱门)

There are various approaches to this, dependant on your needs.有多种方法可以解决此问题,具体取决于您的需求。

If the activity to be measured is long running, you might prefer to use the system tick counter, accessible via tickGet() or tickGet64() .如果要测量的活动长时间运行,您可能更喜欢使用系统滴答计数器,可通过tickGet()tickGet64()

This increments at the system clock rate frequency (ie the rate of the scheduler, not the CPU freq), and so the resolution is limited to a single tick - which might be as large as 1/60th of a second.这以系统时钟频率频率(即调度程序的速率,而不是 CPU 频率)递增,因此分辨率仅限于单个滴答声 - 可能大到 1/60 秒。 You can use sysClkRateGet() to determine the frequency.您可以使用sysClkRateGet()来确定频率。

For long running tasks, the above is probably sufficient, however if you require higher resolution, possibly at the expense of limited duration, you can use the system timestamp counter, if it is configured.对于长时间运行的任务,以上可能就足够了,但是如果您需要更高的分辨率,可能以有限的持续时间为代价,您可以使用系统时间戳计数器(如果已配置)。 For this, you can use sysTimestamp() (or sysTimestamp64() ), and also use sysTimestampFreq() to get the frequency.为此,您可以使用sysTimestamp() (或sysTimestamp64() ),也可以使用sysTimestampFreq()来获取频率。

Dependant on your system configuration, the counter may reset frequently, and you can use sysTimestampPeriod() to workout when this will occur - you will need to handle this in your timing code.根据您的系统配置,计数器可能会频繁重置,并且您可以使用sysTimestampPeriod()来进行锻炼,这将发生在您的计时代码中。

You can, of course, use both methods together to provide both a long running, yet high resolution timer当然,您可以同时使用这两种方法来提供长时间运行但高分辨率的计时器

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

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