Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
shrapnel
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
shrapnel
Commits
ae662f33
Commit
ae662f33
authored
Mar 05, 2013
by
Sergiy Galaburda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed ticks per second detection for Linux.
parent
e58830f1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
11 deletions
+41
-11
coro/clocks/tsc_time.pyx
coro/clocks/tsc_time.pyx
+41
-11
No files found.
coro/clocks/tsc_time.pyx
View file @
ae662f33
...
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment