Browse Source

Don't rely on CPU cycles to measure time.

We have a proper clocksource in the kernel, use this instead.

This commit also fixes jackd on ARM boards with newer Linux kernels
where /proc/cpuinfo has changed.
tags/0.124
Adrian Knoth 11 years ago
parent
commit
c97157fc6e
1 changed files with 1 additions and 64 deletions
  1. +1
    -64
      config/os/gnu-linux/time.c

+ 1
- 64
config/os/gnu-linux/time.c View File

@@ -23,7 +23,6 @@

#include <stdint.h>

static jack_time_t __jack_cpu_mhz = 0;
jack_time_t (*_jack_get_microseconds)(void) = 0;

#if defined(__gnu_linux__) && (defined(__i386__) || defined(__x86_64__))
@@ -113,68 +112,10 @@ jack_get_microseconds_from_hpet (void)
#endif /* HPET_SUPPORT */


jack_time_t
jack_get_microseconds_from_cycles (void) {
return get_cycles() / __jack_cpu_mhz;
}

/*
* This is another kludge. It looks CPU-dependent, but actually it
* reflects the lack of standards for the Linux kernel formatting of
* /proc/cpuinfo.
*/

jack_time_t
jack_get_mhz (void)
{
FILE *f = fopen("/proc/cpuinfo", "r");
if (f == 0)
{
perror("can't open /proc/cpuinfo\n");
exit(1);
}

for ( ; ; )
{
jack_time_t mhz;
int ret;
char buf[1000];

if (fgets(buf, sizeof(buf), f) == NULL) {
jack_error ("FATAL: cannot locate cpu MHz in "
"/proc/cpuinfo\n");
exit(1);
}

#if defined(__powerpc__)
ret = sscanf(buf, "clock\t: %" SCNu64 "MHz", &mhz);
#elif defined( __i386__ ) || defined (__hppa__) || defined (__ia64__) || \
defined(__x86_64__)
ret = sscanf(buf, "cpu MHz : %" SCNu64, &mhz);
#elif defined( __sparc__ )
ret = sscanf(buf, "Cpu0Bogo : %" SCNu64, &mhz);
#elif defined( __mc68000__ )
ret = sscanf(buf, "Clocking: %" SCNu64, &mhz);
#elif defined( __s390__ )
ret = sscanf(buf, "bogomips per cpu: %" SCNu64, &mhz);
#elif defined( __sh__ )
ret = sscanf(buf, "bogomips : %" SCNu64, &mhz);
#else /* MIPS, ARM, alpha */
ret = sscanf(buf, "BogoMIPS : %" SCNu64, &mhz);
#endif

if (ret == 1)
{
fclose(f);
return (jack_time_t)mhz;
}
}
}

void
jack_init_time ()
{
__jack_cpu_mhz = jack_get_mhz ();
/* nothing to do on a generic system - we use the system clock */
}

void
@@ -182,10 +123,6 @@ jack_set_clock_source (jack_timer_type_t clocksrc)
{
switch (clocksrc)
{
case JACK_TIMER_CYCLE_COUNTER:
_jack_get_microseconds = jack_get_microseconds_from_cycles;
break;

case JACK_TIMER_HPET:
if (jack_hpet_init () == 0) {
_jack_get_microseconds = jack_get_microseconds_from_hpet;


Loading…
Cancel
Save