Commit 901a1319 authored by Alejandro Homs Puron's avatar Alejandro Homs Puron
Browse files

Merge branch 'fix-and-improve-scripts' into 'master'

parents 33d4a81a 52d869a7
......@@ -10,7 +10,7 @@
},
"environment": {
"*": {
"setup_script": "/users/blissadm/local/sls_detectors/eiger/scripts/det_env_setup.sh",
"setup_script": [". /users/blissadm/local/sls_detectors/common/scripts/det_env_setup.sh"],
"ssh_agent": true,
"cpu_affinity": {
"cpufreq_governor": "performance",
......
......@@ -97,13 +97,15 @@ class Environment:
else:
print(f'Warning: error in EXEC access to {ld_preload}')
script = self.config.get('setup_script', {})
if script:
cmd = f'. {script} && {cmd}'
script = self.config.get('setup_script', [])
if len(script) == 1:
cmd = f'{script[0]} && {cmd}'
elif script:
cmd = '\n'.join(script + [cmd])
conda = self.config.get('conda', {})
if conda:
conda_base = conda.get('base', '')
conda_base = conda.get('base', '/users/blissadm/conda/miniconda')
env = conda.get('environment', '')
if conda_base and env:
activate = os.path.join(conda_base, 'bin/activate')
......@@ -111,13 +113,14 @@ class Environment:
else:
print(f'Warning: missing conda base/environment')
cmd = ['bash', '-c', cmd]
cmd = ['bash', '-ec', cmd]
ssh_agent = self.config.get('ssh_agent', False)
if ssh_agent:
cmd.insert(0, 'ssh-agent')
print('Executing:', ' '.join(cmd), '...')
print_cmd = ' '.join(cmd[:-1] + [f"'{cmd[-1]}'"])
print(f'Executing: {print_cmd} ...')
sys.stdout.flush()
global running_proc
running_proc = subprocess.Popen(cmd)
......
......@@ -131,11 +131,11 @@ class CPUFreqRawFileSetter:
@classmethod
def getAvailableGovernorsFile(klass, cpu):
return os.path.join(klass.getBaseDir(cpu), 'scaling_available_governor')
return os.path.join(klass.getBaseDir(cpu), 'scaling_available_governors')
@classmethod
def getAvailableGovernors(klass, cpu):
fname = klass.getAvailableGovernorsFile()
fname = klass.getAvailableGovernorsFile(cpu)
cmd = SystemCmd(['cat', fname], try_sudo=False)
cat = cmd.doPopen(stdout=PIPE, text=True)
return cat.stdout.readline().strip().split()
......@@ -144,7 +144,7 @@ class CPUFreqRawFileSetter:
def getCurrGovernor(klass, cpu_list):
governor_list = []
for cpu in cpu_list:
fname = klass.getScalingGovernorFile()
fname = klass.getScalingGovernorFile(cpu)
cmd = SystemCmd(['cat', fname], try_sudo=False)
cat = cmd.doPopen(stdout=PIPE, text=True)
governor_list.append(cat.stdout.readline().strip())
......@@ -154,7 +154,7 @@ class CPUFreqRawFileSetter:
def setCurrGovernor(klass, cpu_list, governor):
cpu_cmds = []
for cpu in cpu_list:
fname = klass.getScalingGovernorFile()
fname = klass.getScalingGovernorFile(cpu)
cpu_cmds.append(f'echo {governor} > {fname}')
bash_cmd = ' && '.join(cpu_cmds)
cmd = SystemCmd(['bash', '-c', bash_cmd])
......@@ -206,30 +206,28 @@ class CPUFreqMgr:
PerformanceGovernors = ['performance']
PowerSaveGovernors = ['ondemand', 'powersave']
def __init__(self, target_governors=None,
def __init__(self, target_governors=[None],
default_governors=PowerSaveGovernors, setter=None):
self.m_setter = setter or self.getSetter()
if target_governors:
if not self.m_setter:
raise RuntimeError('No available CPUFreq setter: '
'install cpufreq-utils or provide '
'sudo privileges')
available_targets = self.getAvailableGovernorsFrom(target_governors)
if not available_targets:
raise ValueError(f'None of the target governors '
f'{target_governors} is available')
self.m_target_governor = available_targets[0]
else:
if not target_governors or not target_governors[0]:
self.m_target_governor = None
return
elif not self.m_setter:
raise RuntimeError('No available CPUFreq setter: install '
'cpufreq-utils or provide sudo privileges')
available_targets = self.getAvailableGovernorsFrom(target_governors)
if not available_targets:
raise ValueError(f'None of the target governors '
f'{target_governors} is available')
self.m_target_governor = available_targets[0]
available_defaults = self.getAvailableGovernorsFrom(default_governors)
if not available_defaults:
raise ValueError(f'None of the default governors '
f'{default_governors} is available')
self.m_default_governor = available_defaults[0]
print(f'default_governor={self.m_default_governor}')
def getSetter(self):
for klass in [CPUFreqUtilsSetter, CPUFreqRawFileSetter]:
......@@ -244,14 +242,13 @@ class CPUFreqMgr:
return None
def getAvailableGovernorsFrom(self, governors):
available_governors = None
for cpu in range(SMPSystem.getNbCPUs()):
available_governors = self.m_setter.getAvailableGovernors(0)
for cpu in range(1, SMPSystem.getNbCPUs()):
available_for_this = self.m_setter.getAvailableGovernors(cpu)
if available_governors is None:
available_governors = available_for_this
else:
available_governors = [g for g in available_for_this
if g in available_governors]
available_governors = [g for g in available_for_this
if g in available_governors]
if not available_governors:
break
return [g for g in governors if g in available_governors]
def setAllGovernors(self, governor):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment