Skip to content

Commit

Permalink
Merge pull request snabbco#1213 from Igalia/irqbalance-check
Browse files Browse the repository at this point in the history
Detect irqbalance presence and suggest remedy
  • Loading branch information
wingo authored Mar 6, 2019
2 parents 89e855c + 9f7177b commit 7ab4ff9
Showing 1 changed file with 34 additions and 22 deletions.
56 changes: 34 additions & 22 deletions src/lib/numa.lua
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,39 @@ function check_affinity_for_pci_addresses (addrs)
end
end

local irqbalanced_checked = false
local function assert_irqbalanced_disabled (warn)
if irqbalanced_checked then return end
irqbalanced_checked = true
for path in os.getenv('PATH'):split(':') do
if S.stat(path..'/irqbalance') then
if S.stat('/etc/default/irqbalance') then
for line in io.lines('/etc/default/irqbalance') do
if line:match('^ENABLED=0') then return end
end
end
warn('Irqbalanced detected; this will hurt performance! %s',
'Consider uninstalling via "sudo apt-get remove irqbalance" and rebooting.')
end
end
end

local function check_cpu_performance_tuning (cpu, strict)
local warn = warn
if strict then warn = die end
assert_irqbalanced_disabled(warn)
local path = '/sys/devices/system/cpu/cpu'..cpu..'/cpufreq/scaling_governor'
local gov = assert(io.open(path)):read()
if not gov:match('performance') then
warn('Expected performance scaling governor for CPU %s, but got "%s"',
cpu, gov)
end

if not isolated_cpus()[cpu] then
warn('Expected dedicated core, but CPU %s is not in isolcpus set', cpu)
end
end

function unbind_cpu ()
local cpu_set = S.sched_getaffinity()
cpu_set:zero()
Expand Down Expand Up @@ -169,13 +202,7 @@ function bind_to_cpu (cpu, skip_perf_checks)

bind_to_numa_node (cpu_and_node.node)

if not skip_perf_checks then
local ok, err = pcall(check_cpu_performance_tuning, bound_cpu)
if not ok then
warn("Error checking performance tuning on CPU %s: %s",
bound_cpu, tostring(err))
end
end
if not skip_perf_checks then check_cpu_performance_tuning(bound_cpu) end
end

function unbind_numa_node ()
Expand Down Expand Up @@ -210,21 +237,6 @@ function prevent_preemption(priority)
'Failed to enable real-time scheduling. Try running as root.')
end

function check_cpu_performance_tuning (cpu, strict)
local warn = warn
if strict then warn = die end
local path = '/sys/devices/system/cpu/cpu'..cpu..'/cpufreq/scaling_governor'
local gov = assert(io.open(path)):read()
if not gov:match('performance') then
warn('Expected performance scaling governor for CPU %s, but got "%s"',
cpu, gov)
end

if not isolated_cpus()[cpu] then
warn('Expected dedicated core, but CPU %s is not in isolcpus set', cpu)
end
end

function selftest ()

local cpus = parse_cpuset("0-5,7")
Expand Down

0 comments on commit 7ab4ff9

Please sign in to comment.