Skip to content

Commit c7df8e8

Browse files
committed
liblikwid_available check + minor code reorg (2)
1 parent 36f9346 commit c7df8e8

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

src/LIKWID.jl

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export OrderedDict
1111
const liblikwid = "liblikwid"
1212
include("LibLikwid.jl")
1313

14+
const perf_paranoid_path = "/proc/sys/kernel/perf_event_paranoid"
15+
1416
# Julia types
1517
include("types.jl")
1618

@@ -75,27 +77,23 @@ import .GPUMarker: gpumarker, @gpumarker
7577
export GPUMarker, gpumarker, @gpumarker
7678
include("frequency.jl")
7779

78-
const perf_paranoid_path = "/proc/sys/kernel/perf_event_paranoid"
79-
80-
function perf_event_paranoid()
81-
open(perf_paranoid_path, "r") do io
82-
parse(Int, readline(io))
83-
end
84-
end
85-
8680
function __init__()
87-
if gpusupport()
88-
init_topology_gpu()
89-
end
90-
if accessmode() == LibLikwid.ACCESSMODE_PERF && ispath(perf_paranoid_path)
91-
perf_paranoid = perf_event_paranoid()
92-
uid = Libc.getuid()
93-
@debug "/proc/sys/kernel/perf_event_paranoid is set to" perf_paranoid uid
94-
if perf_paranoid > 0 && uid != 0 && !haskey(ENV, "LIKWID_PERF_PID")
95-
pid = getpid()
96-
@debug "Setting environment variable LIKWID_PERF_PID" pid
97-
ENV["LIKWID_PERF_PID"] = pid
81+
if liblikwid_available()
82+
if gpusupport()
83+
init_topology_gpu()
84+
end
85+
if accessmode() == LibLikwid.ACCESSMODE_PERF && ispath(perf_paranoid_path)
86+
perf_paranoid = perf_event_paranoid()
87+
uid = Libc.getuid()
88+
@debug "/proc/sys/kernel/perf_event_paranoid is set to" perf_paranoid uid
89+
if perf_paranoid > 0 && uid != 0 && !haskey(ENV, "LIKWID_PERF_PID")
90+
pid = getpid()
91+
@debug "Setting environment variable LIKWID_PERF_PID" pid
92+
ENV["LIKWID_PERF_PID"] = pid
93+
end
9894
end
95+
else
96+
@warn("The library `liblikwid`` couldn't be found. Don't expect anything to work.", liblikwid)
9997
end
10098
return nothing
10199
end

0 commit comments

Comments
 (0)