Allow setting scheduler & priority from systemd service

This commit is contained in:
desbma
2019-01-13 23:13:23 +01:00
parent c8e17796b5
commit e666629aaa
2 changed files with 17 additions and 9 deletions
+13 -9
View File
@@ -497,19 +497,23 @@ def signal_handler(sig, frame):
def set_high_priority(logger):
""" Change process priority to the highest possible. """
""" Change process scheduler and priority. """
# use "real time" scheduler
done = False
sched = os.SCHED_RR
prio = os.sched_get_priority_max(sched)
param = os.sched_param(prio)
try:
os.sched_setscheduler(0, sched, param)
except OSError:
logger.warning("Failed to set real time process scheduler to %u, priority %u" % (sched, prio))
else:
if os.sched_getscheduler(0) == sched:
# already running with RR scheduler, likely set from init system, don't touch priority
done = True
logger.info("Process real time scheduler set to %u, priority %u" % (sched, prio))
else:
prio = (os.sched_get_priority_max(sched) - os.sched_get_priority_min(sched)) // 2
param = os.sched_param(prio)
try:
os.sched_setscheduler(0, sched, param)
except OSError:
logger.warning("Failed to set real time process scheduler to %u, priority %u" % (sched, prio))
else:
done = True
logger.info("Process real time scheduler set to %u, priority %u" % (sched, prio))
if not done:
# renice to highest priority
+4
View File
@@ -5,5 +5,9 @@ Description=HDD fan control
EnvironmentFile=/etc/conf.d/hddfancontrol
ExecStart=/usr/bin/hddfancontrol $HDDFANCONTROL_ARGS
# Scheduler priority
CPUSchedulingPolicy=rr
CPUSchedulingPriority=49
[Install]
WantedBy=multi-user.target