1 ##############################################################################
2 # Copyright (c) 2015 Ericsson AB and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 from __future__ import absolute_import
10 from __future__ import print_function
15 from oslo_serialization import jsonutils
17 import yardstick.ssh as ssh
18 from yardstick.benchmark.scenarios import base
20 LOG = logging.getLogger(__name__)
23 class Lmbench(base.Scenario):
24 """Execute lmbench memory read latency or memory bandwidth benchmark in a host
27 test_type - specifies whether to measure memory latency or bandwidth
32 Parameters for memory read latency benchmark
33 stride - number of locations in memory between starts of array elements
37 stop_size - maximum array size to test (minimum value is 0.000512)
42 Results are accurate to the ~2-5 nanosecond range.
44 Parameters for memory bandwidth benchmark
45 size - the amount of memory to test
49 benchmark - the name of the memory bandwidth benchmark test to execute.
50 Valid test names are rd, wr, rdwr, cp, frd, fwr, fcp, bzero, bcopy
54 warmup - the number of repetitons to perform before taking measurements
58 more info http://manpages.ubuntu.com/manpages/trusty/lmbench.8.html
60 __scenario_type__ = "Lmbench"
62 LATENCY_BENCHMARK_SCRIPT = "lmbench_latency_benchmark.bash"
63 BANDWIDTH_BENCHMARK_SCRIPT = "lmbench_bandwidth_benchmark.bash"
64 LATENCY_CACHE_SCRIPT = "lmbench_latency_for_cache.bash"
66 def __init__(self, scenario_cfg, context_cfg):
67 self.scenario_cfg = scenario_cfg
68 self.context_cfg = context_cfg
69 self.setup_done = False
73 self.bandwidth_target_script = pkg_resources.resource_filename(
74 "yardstick.benchmark.scenarios.compute",
75 Lmbench.BANDWIDTH_BENCHMARK_SCRIPT)
76 self.latency_target_script = pkg_resources.resource_filename(
77 "yardstick.benchmark.scenarios.compute",
78 Lmbench.LATENCY_BENCHMARK_SCRIPT)
79 self.latency_for_cache_script = pkg_resources.resource_filename(
80 "yardstick.benchmark.scenarios.compute",
81 Lmbench.LATENCY_CACHE_SCRIPT)
82 host = self.context_cfg["host"]
84 self.client = ssh.SSH.from_node(host, defaults={"user": "ubuntu"})
85 self.client.wait(timeout=600)
87 # copy scripts to host
88 self.client._put_file_shell(
89 self.latency_target_script, '~/lmbench_latency.sh')
90 self.client._put_file_shell(
91 self.bandwidth_target_script, '~/lmbench_bandwidth.sh')
92 self.client._put_file_shell(
93 self.latency_for_cache_script, '~/lmbench_latency_for_cache.sh')
94 self.setup_done = True
96 def run(self, result):
97 """execute the benchmark"""
99 if not self.setup_done:
102 options = self.scenario_cfg['options']
103 test_type = options.get('test_type', 'latency')
105 if test_type == 'latency':
106 stride = options.get('stride', 128)
107 stop_size = options.get('stop_size', 16.0)
108 cmd = "sudo bash lmbench_latency.sh %f %d" % (stop_size, stride)
109 elif test_type == 'bandwidth':
110 size = options.get('size', 128)
111 benchmark = options.get('benchmark', 'rd')
112 warmup_repetitions = options.get('warmup', 0)
113 cmd = "sudo bash lmbench_bandwidth.sh %d %s %d" % \
114 (size, benchmark, warmup_repetitions)
115 elif test_type == 'latency_for_cache':
116 repetition = options.get('repetition', 1)
117 warmup = options.get('warmup', 0)
118 cmd = "sudo bash lmbench_latency_for_cache.sh %d %d" % \
121 raise RuntimeError("No such test_type: %s for Lmbench scenario",
124 LOG.debug("Executing command: %s", cmd)
125 status, stdout, stderr = self.client.execute(cmd)
128 raise RuntimeError(stderr)
130 if test_type == 'latency':
132 {"latencies": jsonutils.loads(stdout)})
134 result.update(jsonutils.loads(stdout))
136 if "sla" in self.scenario_cfg:
138 if test_type == 'latency':
139 sla_max_latency = int(self.scenario_cfg['sla']['max_latency'])
140 for t_latency in result["latencies"]:
141 latency = t_latency['latency']
142 if latency > sla_max_latency:
143 sla_error += "latency %f > sla:max_latency(%f); " \
144 % (latency, sla_max_latency)
145 elif test_type == 'bandwidth':
146 sla_min_bw = int(self.scenario_cfg['sla']['min_bandwidth'])
147 bw = result["bandwidth(MBps)"]
149 sla_error += "bandwidth %f < " \
150 "sla:min_bandwidth(%f)" % (bw, sla_min_bw)
151 elif test_type == 'latency_for_cache':
152 sla_latency = float(self.scenario_cfg['sla']['max_latency'])
153 cache_latency = float(result['L1cache'])
154 if sla_latency < cache_latency:
155 sla_error += "latency %f > sla:max_latency(%f); " \
156 % (cache_latency, sla_latency)
157 assert sla_error == "", sla_error
161 """internal test function"""
162 key_filename = pkg_resources.resource_filename('yardstick.resources',
163 'files/yardstick_key')
166 'ip': '10.229.47.137',
168 'key_filename': key_filename
172 logger = logging.getLogger('yardstick')
173 logger.setLevel(logging.DEBUG)
176 'test_type': 'latency',
181 sla = {'max_latency': 35, 'action': 'monitor'}
182 args = {'options': options, 'sla': sla}
185 p = Lmbench(args, ctx)
190 if __name__ == '__main__':