From 610a6546aada3b7dbd682035993262c37ba25d06 Mon Sep 17 00:00:00 2001 From: Patrick Bellasi Date: Fri, 9 Sep 2016 10:05:17 +0100 Subject: [PATCH 1/4] libs/wlgen/workload: cosmetics Signed-off-by: Patrick Bellasi --- libs/wlgen/wlgen/workload.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libs/wlgen/wlgen/workload.py b/libs/wlgen/wlgen/workload.py index 3b2212e46..0f837dcaf 100644 --- a/libs/wlgen/wlgen/workload.py +++ b/libs/wlgen/wlgen/workload.py @@ -199,18 +199,18 @@ class Workload(object): # Prepend eventually required taskset command if self.cpus: cpus_mask = self.getCpusMask(self.cpus) - self.taskset_cmd = '{0:s}/taskset 0x{1:X}'\ + self.taskset_cmd = '{}/taskset 0x{:X}'\ .format(self.target.executables_directory, cpus_mask) - self.command = '{0:s} {1:s}'\ + self.command = '{} {}'\ .format(self.taskset_cmd, self.command) - # Prepend eventually required taskset command + # Prepend eventually required cgroup command if self.cgroup and self.cgroup_cmd == '': - self.cgroup_cmd = 'cgroups_run_into {1:s}'\ + self.cgroup_cmd = 'cgroups_run_into {}'\ .format(self.target.executables_directory, self.cgroup) - self.command = '{0:s} \'{1:s} \''\ + self.command = '{} \'{}\''\ .format(self.cgroup_cmd, self.command) # Start FTrace (if required) -- GitLab From 62928fba61f374f201d775a66053cb4b80310353 Mon Sep 17 00:00:00 2001 From: Patrick Bellasi Date: Tue, 30 Aug 2016 14:50:22 +0100 Subject: [PATCH 2/4] libs/wlgen/workload: allows different CGroups and CPUs for each run In the current implementation, the CPUs and on CGroups where a workload has to be executed at each run() call it's somehow defined either at configuration time or at its first execution. This is due to the way we add the taskset and/or cgroup_run_into prefixes. This patch builds a new _command at each run() invocation which allows each time to prefix the workload command with the proper taskset and/or cgroup_run_into. This allows to use different CPUs and/or CGroups each time we run a preconfigured workload. Signed-off-by: Patrick Bellasi --- libs/wlgen/wlgen/workload.py | 43 +++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/libs/wlgen/wlgen/workload.py b/libs/wlgen/wlgen/workload.py index 0f837dcaf..eeeb25af4 100644 --- a/libs/wlgen/wlgen/workload.py +++ b/libs/wlgen/wlgen/workload.py @@ -151,6 +151,7 @@ class Workload(object): def run(self, ftrace=None, cgroup=None, + cpus=None, background=False, out_dir='./', as_root=False, @@ -167,6 +168,11 @@ class Workload(object): run :type cgroup: str + :param cpus: the CPUs on which to run the workload. + NOTE: if specified it overrides the CPUs specified at + configuration time + :type cpus: list(int) + :param background: run the workload in background. In this case the method will not return a result. When used with ftrace it is up to the caller to stop trace @@ -193,25 +199,26 @@ class Workload(object): self.cgroup = cgroup - if self.command is None: + # Compose the actual execution command starting from the base command + # defined by the base class + _command = self.command + + if not _command: logging.error('%14s - Error: empty executor command', 'WlGen') # Prepend eventually required taskset command - if self.cpus: - cpus_mask = self.getCpusMask(self.cpus) + if cpus or self.cpus: + cpus_mask = self.getCpusMask(cpus if cpus else self.cpus) self.taskset_cmd = '{}/taskset 0x{:X}'\ .format(self.target.executables_directory, cpus_mask) - self.command = '{} {}'\ - .format(self.taskset_cmd, self.command) + _command = '{} {}'\ + .format(self.taskset_cmd, _command) # Prepend eventually required cgroup command - if self.cgroup and self.cgroup_cmd == '': - self.cgroup_cmd = 'cgroups_run_into {}'\ - .format(self.target.executables_directory, - self.cgroup) - self.command = '{} \'{}\''\ - .format(self.cgroup_cmd, self.command) + if self.cgroup: + self.cgroup_cmd = 'cgroups_run_into {}'.format(self.cgroup) + _command = '{} \'{}\''.format(self.cgroup_cmd, _command) # Start FTrace (if required) if ftrace: @@ -225,23 +232,23 @@ class Workload(object): # Start task in background if required if background: - logging.debug('%14s - WlGen [background]: %s', 'WlGen', self.command) - self.target.kick_off(self.command, as_root=as_root) + logging.debug('%14s - WlGen [background]: %s', 'WlGen', _command) + self.target.kick_off(_command, as_root=as_root) self.output['executor'] = '' # Start task in foreground else: logging.info('%14s - Workload execution START:', 'WlGen') - logging.info('%14s - %s', 'WlGen', self.command) + logging.info('%14s - %s', 'WlGen', _command) # Run command and wait for it to complete if cgroup: - results = self.target._execute_util(self.command, - as_root=True) + results = self.target._execute_util(_command, + as_root=True) else: - results = self.target.execute(self.command, - timeout=None, as_root=as_root) + results = self.target.execute(_command, timeout=None, + as_root=as_root) # print type(results) self.output['executor'] = results -- GitLab From 9885107862d553e757fa0da09d2a72a1dcc7c1a7 Mon Sep 17 00:00:00 2001 From: Patrick Bellasi Date: Tue, 30 Aug 2016 14:53:07 +0100 Subject: [PATCH 3/4] libs/wlgen/workload: fix execution within a CGroup The quoting of the command to pass to "shutils cgroup_run_into" seems to confuse the quite escaping code of devlib. By removing it we still can run a workload using both taskset and CGroups, thus it is quite likely not really required, let's remove it. Signed-off-by: Patrick Bellasi --- libs/wlgen/wlgen/workload.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/wlgen/wlgen/workload.py b/libs/wlgen/wlgen/workload.py index eeeb25af4..e52fec119 100644 --- a/libs/wlgen/wlgen/workload.py +++ b/libs/wlgen/wlgen/workload.py @@ -218,7 +218,7 @@ class Workload(object): # Prepend eventually required cgroup command if self.cgroup: self.cgroup_cmd = 'cgroups_run_into {}'.format(self.cgroup) - _command = '{} \'{}\''.format(self.cgroup_cmd, _command) + _command = '{} {}'.format(self.cgroup_cmd, _command) # Start FTrace (if required) if ftrace: -- GitLab From a57aceb86273b66951cc7dc2499cd9e31c867999 Mon Sep 17 00:00:00 2001 From: Patrick Bellasi Date: Tue, 30 Aug 2016 15:30:11 +0100 Subject: [PATCH 4/4] libs/wlgen/workload: avoid special case for CGroups into execution Currently we have a special case for execution of a workload within a CGroup which makes the code odd with many if cases. This patch simplifies the code by formatting the shutils based command when we define the CGroup run-into command. Moreover, all execution commands honour the as_root parameter specified by the run call. Signed-off-by: Patrick Bellasi --- libs/wlgen/wlgen/workload.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/libs/wlgen/wlgen/workload.py b/libs/wlgen/wlgen/workload.py index e52fec119..47708a330 100644 --- a/libs/wlgen/wlgen/workload.py +++ b/libs/wlgen/wlgen/workload.py @@ -217,7 +217,8 @@ class Workload(object): # Prepend eventually required cgroup command if self.cgroup: - self.cgroup_cmd = 'cgroups_run_into {}'.format(self.cgroup) + self.cgroup_cmd = '{} cgroups_run_into {}'\ + .format(self.target.shutils, self.cgroup.name) _command = '{} {}'.format(self.cgroup_cmd, _command) # Start FTrace (if required) @@ -233,23 +234,15 @@ class Workload(object): # Start task in background if required if background: logging.debug('%14s - WlGen [background]: %s', 'WlGen', _command) - self.target.kick_off(_command, as_root=as_root) + self.target.background(_command, as_root=as_root) self.output['executor'] = '' # Start task in foreground else: - logging.info('%14s - Workload execution START:', 'WlGen') logging.info('%14s - %s', 'WlGen', _command) - # Run command and wait for it to complete - if cgroup: - results = self.target._execute_util(_command, - as_root=True) - else: - results = self.target.execute(_command, timeout=None, - as_root=as_root) - # print type(results) + results = self.target.execute(_command, as_root=as_root) self.output['executor'] = results # Wait `end_pause` seconds before stopping ftrace -- GitLab