Commit ae662f33 authored by Sergiy Galaburda's avatar Sergiy Galaburda

Fixed ticks per second detection for Linux.

parent e58830f1
......@@ -209,6 +209,11 @@ cdef extern from "sys/sysctl.h":
int sysctlbyname(char *name, void *oldp, size_t *oldlenp, void *newp,
size_t newlen)
IF UNAME_SYSNAME == "Linux":
DEF _GNU_SOURCE=1
cdef extern from "sched.h":
int sched_getcpu()
# This is a pointer so that the time shifting functions can replace it.
cdef uint64_t (*c_rdtsc) ()
c_rdtsc = _c_rdtsc
......@@ -236,9 +241,34 @@ cdef uint64_t get_ticks_per_sec() except -1:
cdef char buffer[128]
cdef size_t buffer_size
# XXX - Need to find a way to get ticks per sec on Linux, fake it for now
IF UNAME_SYSNAME == "Linux":
return 2793008320
current_cpu_number = sched_getcpu()
f = open('/proc/cpuinfo')
try:
lines = f.readlines()
finally:
f.close()
cpu_found = False
cpu_speed_mhz = None
for line in lines:
if line.startswith('processor'):
found_cpu_number = int(line.split(':')[-1].strip())
if found_cpu_number == current_cpu_number:
cpu_found = True
continue
if not cpu_found:
continue
if line.startswith('cpu MHz'):
cpu_speed_mhz = float(line.split(':')[-1].strip())
break
if cpu_speed_mhz is None:
raise RuntimeError('failed to detect CPU frequency')
return cpu_speed_mhz * 1000000
buffer_size = sizeof(buffer)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment