Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

Question on tick_count

etc_26
Beginner
781 Views
Hello all,

Browsing through tick_count.h, I was wondering why clock_gettime is called with CLOCK_REALTIME instead of CLOCK_REALTIME_HR. Since I have no experience with this call, this is probably a newbie question.

Additionally, I was wondering what the actual relationship between tick_count and the actual CPU tick counters is, since tick_count uses different timing calls for different cases/OSes.

0 Kudos
3 Replies
Alexey-Kukanov
Employee
781 Views

I checked man pages for clock_gettime on a system running Red Hat EL 3 (quite an old distro nowadays) and did not find CLOCK_REALTIME_HR there; neiherI found it referenced somewhere in /usr/include. Little googling gaveme a number of references to a kernel.org maillist posting saying that CLOCK_REALTIME_HR was removed a while ago.

There is no direct connection between tbb::tick_count and the actual tick count. As you correctly noticed, we rely on OS services to obtain a timer with good enough resolution. In case someone knows a better solution for a particular OS, it's the chance to contribute to TBB :)

0 Kudos
etc_26
Beginner
781 Views
Thanks, Alexey!

I found CLOCK_REALTIME_HR in the man page for clock_getres in the Linux system I'm using:
# uname -a
Linux aa0-010-1.domain.com 2.6.20-1.2944.fc6 #1 SMP Tue Apr 10 17:46:00 EDT 2007 x86_64 x86_64 x86_64 GNU/Linux

It is indeed not the latest version of Linux, so maybe as you suggest it's been removed in the meantime.

As for obtaining tick counts... I'm not an expert, but my understanding is that it's pretty simple to do. There are lots of libraries that work with HW timers (e.g., PAPI http://icl.cs.utk.edu/papi/), and I myself once adapted a very short piece of asm code that gets the HW tick count. It was very accurate and very low latency, but not very useful in multi-threaded environment if you couldn't guarantee always querying the same core for its counter. If needed, I can probably search and dig up that code, but I don't know how to make it work in a parallel environment.


0 Kudos
Alexey-Kukanov
Employee
781 Views

We deliberately use OS services instead of HW counters for getting time stamps. There are several reasons for that, and making it work correctly in the parallel environment called by multiple threads is amongst those. Also, on some older processors HW tick count follows CPU frequency, thus is affected by dynamic frequency change (not sure if OSes fix it, though). And, TBB is more portable relying on OS services than if it would use HW directly.

So if anyone knows better (more precise, more reliable, more portable, etc) OS timing service than those used now in TBB, welcome to suggest it or contribute code.

0 Kudos
Reply