-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from JuliaData/jps/mem-reserve-opt
Memory reservation optimizations
- Loading branch information
Showing
5 changed files
with
79 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
## | ||
# This file is a part of MemPool.jl. License is MIT | ||
# | ||
# Based upon https://github.com/google/benchmark, which is licensed under Apache v2: | ||
# https://github.com/google/benchmark/blob/master/LICENSE | ||
# | ||
# In compliance with the Apache v2 license, here are the original copyright notices: | ||
# Copyright 2015 Google Inc. All rights reserved. | ||
## | ||
|
||
struct TimeSpec | ||
tv_sec::UInt64 # time_t | ||
tv_nsec::UInt64 | ||
end | ||
|
||
maketime(ts) = ts.tv_sec * UInt(1e9) + ts.tv_nsec | ||
|
||
# From bits/times.h on a Linux system | ||
# Check if those are the same on BSD | ||
if Sys.islinux() | ||
const CLOCK_MONOTONIC = Cint(1) | ||
const CLOCK_PROCESS_CPUTIME_ID = Cint(2) | ||
const CLOCK_THREAD_CPUTIME_ID = Cint(3) | ||
const CLOCK_MONOTONIC_COARSE = Cint(6) | ||
elseif Sys.isfreebsd() # atleast on FreeBSD 11.1 | ||
const CLOCK_MONOTONIC = Cint(4) | ||
const CLOCK_PROCESS_CPUTIME_ID = Cint(14) | ||
elseif Sys.isapple() # Version 10.12 required | ||
const CLOCK_MONOTONIC = Cint(6) | ||
const CLOCK_PROCESS_CPUTIME_ID = Cint(12) | ||
end | ||
|
||
@static if Sys.isunix() | ||
@inline function clock_gettime(cid) | ||
ts = Ref{TimeSpec}() | ||
ccall(:clock_gettime, Cint, (Cint, Ref{TimeSpec}), cid, ts) | ||
return ts[] | ||
end | ||
|
||
@inline function realtime() | ||
maketime(clock_gettime(CLOCK_MONOTONIC)) | ||
end | ||
|
||
@inline function cputime() | ||
maketime(clock_gettime(CLOCK_PROCESS_CPUTIME_ID)) | ||
end | ||
end | ||
|
||
@static if Sys.islinux() | ||
@inline function cputhreadtime() | ||
maketime(clock_gettime(CLOCK_THREAD_CPUTIME_ID)) | ||
end | ||
@inline function fasttime() | ||
maketime(clock_gettime(CLOCK_MONOTONIC_COARSE)) | ||
end | ||
else | ||
@inline cputhreadtime() = time_ns() # HACK | ||
@inline fasttime() = time_ns() # HACK | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters