2

I've inherited a embedded project that requires some simple, per-function performance profiling. It consists of a Coldfire (MCF5328) running uClinux (2.6.17.7-uc1).

I'm not an expert on either the Coldfire, or uClinux (or Linux for that matter), so excuse my ignorance.

In Windows I would simply use QueryPerformanceCounter to access the x86 high-resolution timer. Record the counter before and after and compare the difference.

I've learned that Linux has a number of variations on QueryPerformanceCounter:

  • clock_gettime/res
  • getnstimeofday
  • ktime_x

Or even access to the Time Stamp Counter via

  • get_cycles

None of these are available on the uClinux build this device is running. So it appears that the OS has no high-resolution timer access.

Does this mean that the Coldfire itself provides no such feature? Or did the author of the uClinux port leave them out? Is there something on the hardware that I can use, and how would go about using it?

Tergiver
  • 14,171
  • 3
  • 41
  • 68

2 Answers2

1

Given how old your kernel is, you may not have support for high-resolution timers.

If you are writing a kernel driver, the APIs are different. If get_cycles() is stubbed out, it probably means your CPU architecture doesn't support a cycle counter. Since your kernel is very old, do_gettimeofday is probably the best you can do, short of writing a driver to directly query some timer hardware.

bdonlan
  • 224,562
  • 31
  • 268
  • 324
  • In the case of `clock_gettime`, linux/time.h does not even have it. If i create a declaration to get it to build (the driver module in question links dynamically to the kernel), the device crashes because the function doesn't exist in the kernel. In the case of the ktime_x functions, they exist in the distribution's header file, but again do not exist in the kernel. In the case of get_cycles, the header defines it as an inline function that returns zero (i.e. it is not implemented). – Tergiver Jun 17 '11 at 23:54
  • I found that exact posix-timers.c file in the distribution files, which means that that particular file isn't getting built-in for some reason. I'm guessing there are 1001 possible reasons it might not be built and one of them is a #define or config setting somewhere in that list of 1001 things. – Tergiver Jun 18 '11 at 00:06
  • Yes, it is a kernel driver and my hunch has been that the hardware doesn't support it. I was hoping for a quick fix because I only need to change how a single module works and need to profile those changes so that I do not consume N more cycles than before. do_gettimeofday doesn't have sufficient resolution. – Tergiver Jun 18 '11 at 00:10
1

I ended up using one of the four DMA Timers on the Coldfire. It was a simple matter to enable the timer as a free-running, non-interrupt generating, counter. This provides a 12.5ns counter (at 80Mhz).

Tergiver
  • 14,171
  • 3
  • 41
  • 68