Skip to content

Commit

Permalink
Do all governor setting from autojack not systemd
Browse files Browse the repository at this point in the history
  • Loading branch information
ovenwerks committed Oct 17, 2022
1 parent 2a20f04 commit db134fa
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 210 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
studio-controls version 2.3.8

[ Len Ovens ]
- Do all governor setting from autojack not systemd
- Do all Boost setting from autojack not systemd

studio-controls version 2.3.7

[ Len Ovens ]
Expand Down
16 changes: 0 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ install:

install -d $(DESTDIR)$(BINDIR)
install -d $(DESTDIR)$(SBINDIR)
install -d $(DESTDIR)$(LIBDIR)/systemd/system/ondemand.service.d
install -d $(DESTDIR)$(LIBDIR)/systemd/system/multi-user.target.wants
install -d $(DESTDIR)$(LIBDIR)/systemd/user/default.target.wants
install -d $(DESTDIR)$(LIBDIR)/systemd/user/indicator-messages.service.wants
install -d $(DESTDIR)$(LIBDIR)/python3/dist-packages
Expand Down Expand Up @@ -79,22 +77,12 @@ install:
install -m 655 usr/sbin/* \
$(DESTDIR)$(SBINDIR)

install -m 655 usr/lib/systemd/studio \
$(DESTDIR)$(LIBDIR)/systemd
install -m 644 usr/lib/systemd/system/studio-system.service \
$(DESTDIR)$(LIBDIR)/systemd/system
install -m 644 usr/lib/systemd/system/ondemand.service.d/studio.conf \
$(DESTDIR)$(LIBDIR)/systemd/system/ondemand.service.d
install -m 644 usr/lib/systemd/user/session-monitor.service \
$(DESTDIR)$(LIBDIR)/systemd/user
install -m 644 usr/lib/systemd/user/studio.service \
$(DESTDIR)$(LIBDIR)/systemd/user
install -m 655 usr/lib/python3/dist-packages/* \
$(DESTDIR)$(LIBDIR)/python3/dist-packages

# make links
ln -s $(DESTDIR)$(LIBDIR)/systemd/system/studio-system.service \
$(DESTDIR)$(LIBDIR)/systemd/system/multi-user.target.wants/studio-system.service
ln -s $(DESTDIR)$(LIBDIR)/systemd/user/session-monitor.service \
$(DESTDIR)$(LIBDIR)/systemd/user/indicator-messages.service.wants/session-monitor.service

Expand Down Expand Up @@ -131,10 +119,6 @@ uninstall:

rm -f $(DESTDIR)$(SBINDIR)/studio-system

rm -f $(DESTDIR)$(LIBDIR)/systemd/studio
rm -f $(DESTDIR)$(LIBDIR)/systemd/system/studio-system.service
rm -rf $(DESTDIR)$(LIBDIR)/systemd/system/ondemand.service.d
rm -f $(DESTDIR)$(LIBDIR)/systemd/system/multi-user.target.wants/studio-system.service
rm -f $(DESTDIR)$(LIBDIR)/python3/dist-packages/auto_jack.py

rm -f $(DESTDIR)$(LIBDIR)/systemd/user/session-monitor.service
Expand Down
41 changes: 36 additions & 5 deletions usr/bin/autojack
Original file line number Diff line number Diff line change
Expand Up @@ -957,14 +957,15 @@ def check_jack_status(user_data):
that is run on a timer that checks for various things to do.
'''
global con_dirty
global jack_client
global conf_db
global control_signal
global device_signal
global jack_alive
global jack_died
global jack_count
global jack_client
global jack_died
global last_status
global phone_port
global control_signal
global device_signal
global phone_signal

if control_signal != []:
Expand Down Expand Up @@ -997,6 +998,8 @@ def check_jack_status(user_data):

jack_count = jack_count + 1
if jack_count == 200:
# maintain logfiles and other things that don't need to
# be looked at so often
logging.log(7, f"Jack_status: {str(jack_alive)}")
jack_count = 0

Expand Down Expand Up @@ -1028,6 +1031,35 @@ def check_jack_status(user_data):
os.replace(logfile, f"{logfile}.1")
logging.debug("JACK Log File rotated")

rgov, rboost = auto_jack.get_gvnr_hw()
pk = shutil.which("pkexec")
if pk is None:
logging.warning(
"pexec is missing... unable to change"
" cpu-governor or boost")
else:
if conf_db['cpu-governor'] != rgov:
if conf_db['cpu-governor']:
gov = "performance"
else:
if os.path.exists("/sys/devices/system/cpu/intel_pstate"):
gov = "powersave"
else:
gov = "ondemand"
logging.info(f"Setting CPU Governor to {gov}")
subprocess.run(
[pk, f"{install_path}/sbin/studio-system", gov], shell=False)

if conf_db['boost'] != rboost:
if conf_db['boost']:
boost = "noboost"
logging.info("Setting Intel Boost to disable")
else:
boost = 'boost'
logging.info("Setting Intel Boost to enable")
subprocess.run(
[pk, f"{install_path}/sbin/studio-system", boost], shell=False)

if con_dirty and jack_alive:
logging.debug("Connection changed")
if phones and 'phone_port' in globals() and phone_port != 'none':
Expand Down Expand Up @@ -1971,7 +2003,6 @@ def main():
ses_cb_command, dbus_interface='org.studio.control.command',
signal_name='signal')

time.sleep(1) # avoid race condition with plasma-pa
sendbs.signal('start')

jack_stat("Undetermined")
Expand Down
2 changes: 1 addition & 1 deletion usr/bin/studio-cmd
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def goodbye(dummy):


def main(argv):
''' Control-cl takes either start or stop as a command line
''' Control-cmd takes either start or stop as a command line
parameter to send to auto jack '''
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
sendbs = sendbus()
Expand Down
114 changes: 22 additions & 92 deletions usr/bin/studio-controls
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class SysInfo:
return False

def check_pam_files(self):
'''Checks for the existence of two files'''
'''Checks for the existence of files'''
if os.path.isfile("/etc/security/limits.d/audio.conf"):
return True
return False
Expand All @@ -69,67 +69,6 @@ class SysInfo:
return {resource.getrlimit(resource.RLIMIT_RTPRIO)[1],
resource.getrlimit(resource.RLIMIT_MEMLOCK)[1]}

# System tweaks
def get_performance(self):
'''Checks for current cpu governor'''
if os.path.isfile("/sys/devices/system/cpu/cpufreq"
"/policy0/scaling_governor"):
with open("/sys/devices/system/cpu/cpufreq"
"/policy0/scaling_governor",
"r") as perform_file_test:
for line in perform_file_test:
if re.match("performance", line.rstrip()):
return True
return False

def get_boosted(self):
'''Checks for Intel boost state'''
boost_path = "/sys/devices/system/cpu/intel_pstate/no_turbo"
if os.path.exists(boost_path):
with open(boost_path, "r") as boost_test:
for line in boost_test:
if re.match("0", line.rstrip()):
return True
return False

# Audio stuff


class RTSetup:
# defs for doing things
def __init__(self):
self.enabled_path = "/etc/security/limits.d/audio.conf"
self.disabled_path = "/etc/security/limits.d/audio.conf.disabled"
self.backup_file = f"{install_path}/share/studio-controls/audio.conf"
self.pke = shutil.which("pkexec")
if self.pke is None:
print("no pkexec, Fail")

def set_governor(self, enable):
if enable:
gov = "performance"
else:
if os.path.exists("/sys/devices/system/cpu/intel_pstate"):
gov = "powersave"
else:
gov = "ondemand"
subprocess.run(
[self.pke, f"{install_path}/sbin/studio-system", gov], shell=False)

def set_boost(self, enable):
boost_path = "/sys/devices/system/cpu/intel_pstate/no_turbo"
if os.path.exists(boost_path):
if enable:
subprocess.run(
[self.pke,
f"{install_path}/sbin/studio-system", "boost"],
shell=False)
else:
subprocess.run(
[self.pke,
f"{install_path}/sbin/studio-system", "noboost"],
shell=False)


class StudioControls:
global lock_file
Expand Down Expand Up @@ -307,25 +246,28 @@ class StudioControls:
self.rt_button.set_label("Real Time Permissions Enabled")
self.rt_button.set_sensitive(False)

# read in autojack config file
self.conf_db = auto_jack.convert()
self.jackdb = self.conf_db['jack']
self.extra = self.conf_db['extra']

# show current CPU Governor
self.combo_governor.append_text("Performance")
if os.path.exists("/sys/devices/system/cpu/intel_pstate/"):
self.combo_governor.append_text("Powersave")
else:
self.combo_governor.append_text("Ondemand")
self.in_performance = self.sysinfo.get_performance()
if self.in_performance:
if self.conf_db['cpu-governor']:
self.combo_governor.set_active(0)
else:
self.combo_governor.set_active(1)

# show boost state
if os.path.exists("/sys/devices/system/cpu/intel_pstate/no_turbo"):
self.boosted = self.sysinfo.get_boosted()
if self.boosted:
self.combo_boost.set_active(1)
else:
if self.conf_db['boost']:
self.combo_boost.set_active(0)
else:
self.combo_boost.set_active(1)
else:
self.combo_boost.set_sensitive(False)

Expand Down Expand Up @@ -354,11 +296,6 @@ class StudioControls:
jack.set_error_function(callback=self.jack_error)
jack.set_info_function(callback=self.jack_info)

# read in autojack config file
self.conf_db = auto_jack.convert()
self.jackdb = self.conf_db['jack']
self.extra = self.conf_db['extra']

self.logging_comb.set_active_id(str(self.conf_db['log-level']))
# fill in Jack master widgets
self.combo_periods.set_sensitive(False)
Expand Down Expand Up @@ -480,7 +417,6 @@ class StudioControls:
}
builder.connect_signals(handlers)

self.rtsetup = RTSetup()
self.timeout_id = GLib.timeout_add(500, self.check_jack_status, None)
self.signal_autojack("ping")
autojack = False
Expand Down Expand Up @@ -805,21 +741,21 @@ class StudioControls:
# system tweaks

def combo_governor_changed_cb(self, button):
newval = False
if button.get_active_text() == "Performance":
self.rtsetup.set_governor(True)
else:
self.rtsetup.set_governor(False)
newval = True
if self.conf_db['cpu-governor'] != newval:
self.conf_db['cpu-governor'] = newval
self.cb_audio_apply(button)


def combo_boost_changed_cb(self, button):
if button.get_active_text() == "on":
self.rtsetup.set_boost(True)
else:
self.rtsetup.set_boost(False)
self.boosted = self.sysinfo.get_boosted()
if self.boosted:
self.combo_boost.set_active(1)
else:
self.combo_boost.set_active(0)
newval = False
if button.get_active_text() == "off":
newval = True
if self.conf_db['boost'] != newval:
self.conf_db['boost'] = newval
self.cb_audio_apply(button)

def logging_changed(self, widget):
newval = widget.get_active_id()
Expand Down Expand Up @@ -1150,7 +1086,6 @@ class StudioControls:
self.pj_count.set_value(1)
self.pj_con.set_active_id('none')
self.pj_direction.set_active_id('out')
# self.pj_direction.set_active_id('none')
self.pj_bridge = ''
else:
for bridge in out_db:
Expand All @@ -1165,19 +1100,16 @@ class StudioControls:
if new_bridge in out_db:
our_db = out_db
self.pj_direction.set_active_id('out')
# self.pj_direct.set_text('Output (Pulse to JACK)')
if new_bridge in in_db:
our_db = in_db
self.pj_direction.set_active_id('in')
# self.pj_direct.set_text('Input (JACK to Pulse)')
self.pj_combo.set_active_id(new_bridge)
self.pj_name.set_text(new_bridge)
self.pj_count.set_value(our_db[new_bridge]['count'])
self.pj_con.set_active_id(our_db[new_bridge]['connection'])
self.pj_bridge = new_bridge

self.pj_combo.set_sensitive(True)
# self.pj_direction.set_sensitive(True)
self.pj_name.set_sensitive(True)
self.pj_count.set_sensitive(True)
self.pj_con.set_sensitive(True)
Expand Down Expand Up @@ -1349,8 +1281,6 @@ class StudioControls:
if znet_db[new_bridge]['direction'] == 'out':
self.znet_bits.set_sensitive(True)
self.znet_bridge.set_sensitive(True)
# self.znet_direction.set_sensitive(True)
# should never be true
self.znet_count.set_sensitive(True)
self.znet_ip.set_sensitive(True)
self.znet_port.set_sensitive(True)
Expand Down
Loading

0 comments on commit db134fa

Please sign in to comment.