Skip to content

Commit 58281b0

Browse files
pridhivirajstewartsmith
authored andcommitted
OpTestEM: Add testcase for boost frequencies(WoF)
This patch adds new testcase to test CPU WoF/boost frequencies, and also it fixes the failure of CPU freq governor change tests which will now properly verify the frequency for each governor. And also it separates all freq pstates test into three tests so that all three will be run. cpu_freq_states_host --> Tests CPU frequency in b/w Pmin to P(turbo) cpu_boost_freqs_host --> Tests CPU frequency in b/w Pturbo to P(ultra-turbo) or Pmax cpu_freq_gov_host --> Tests CPU frequency vs each governor. Signed-off-by: Pridhiviraj Paidipeddi <ppaidipe@linux.vnet.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
1 parent 94a3ed7 commit 58281b0

1 file changed

Lines changed: 101 additions & 14 deletions

File tree

testcases/OpTestEM.py

Lines changed: 101 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,20 @@ def verify_cpu_freq(self, i_freq, and_measure=True):
151151
msg="Set and measured CPU frequency differ too greatly")
152152

153153

154+
def verify_cpu_freq_almost(self, i_freq):
155+
l_cmd = "cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq"
156+
cur_freq = self.c.run_command(l_cmd)
157+
if not cur_freq[0] == i_freq:
158+
time.sleep(0.2)
159+
cur_freq = self.c.run_command(l_cmd)
160+
161+
if int(cur_freq[0]) == int(i_freq):
162+
return
163+
164+
delta = int(i_freq) / (100)
165+
self.assertAlmostEqual(int(cur_freq[0]), int(i_freq), delta=delta,
166+
msg="CPU frequency not changed to %s" % i_freq)
167+
154168
##
155169
# @brief sets the cpu governer with i_gov governer
156170
#
@@ -275,20 +289,6 @@ def runTest(self):
275289
freq_list = l_res[0].split(' ')[:-1] # remove empty entry at end
276290
print freq_list
277291

278-
pstate_min, pstate_max, pstate_nom = self.get_pstate_limits()
279-
print pstate_min,pstate_max, pstate_nom
280-
# performance(Pstate_max),
281-
# ondemand(Workload based),
282-
# userspace(User request),
283-
# powersave(Pstate_min)
284-
self.set_cpu_gov("performance")
285-
self.verify_cpu_gov("performance")
286-
self.verify_cpu_freq(pstate_max, True)
287-
self.set_cpu_gov("powersave")
288-
self.verify_cpu_gov("powersave")
289-
self.verify_cpu_freq(pstate_min, True)
290-
self.set_cpu_gov("performance")
291-
292292
# Set the cpu governer to userspace
293293
self.set_cpu_gov("userspace")
294294
self.verify_cpu_gov("userspace")
@@ -307,6 +307,90 @@ def setUp(self):
307307
self.test = "skiroot"
308308
super(cpu_freq_states_host, self).setUp()
309309

310+
class cpu_freq_gov_host(OpTestEM, unittest.TestCase):
311+
def setUp(self):
312+
self.test = "host"
313+
super(cpu_freq_gov_host, self).setUp()
314+
315+
def runTest(self):
316+
self.c = self.set_up()
317+
self.c.run_command("stty cols 300;stty rows 30")
318+
self.c.run_command("uname -a")
319+
self.c.run_command("cat /etc/os-release")
320+
pstate_min, pstate_max, pstate_nom = self.get_pstate_limits()
321+
print pstate_min,pstate_max, pstate_nom
322+
323+
# performance(Pstate_max),
324+
# ondemand(Workload based),
325+
# userspace(User request),
326+
# powersave(Pstate_min)
327+
self.set_cpu_gov("performance")
328+
self.verify_cpu_gov("performance")
329+
self.verify_cpu_freq_almost(pstate_max)
330+
self.set_cpu_gov("powersave")
331+
self.verify_cpu_gov("powersave")
332+
self.verify_cpu_freq_almost(pstate_min)
333+
self.set_cpu_gov("performance")
334+
335+
class cpu_freq_gov_skiroot(cpu_freq_gov_host):
336+
def setUp(self):
337+
self.test = "skiroot"
338+
super(cpu_freq_gov_host, self).setUp()
339+
340+
class cpu_boost_freqs_host(OpTestEM, unittest.TestCase):
341+
def setUp(self):
342+
self.test = "host"
343+
super(cpu_boost_freqs_host, self).setUp()
344+
345+
def runTest(self):
346+
self.c = self.set_up()
347+
self.c.run_command("stty cols 300;stty rows 30")
348+
self.c.run_command("uname -a")
349+
self.c.run_command("cat /etc/os-release")
350+
pstate_min, pstate_max, pstate_nom = self.get_pstate_limits()
351+
352+
cpu_num = self.get_first_available_cpu()
353+
354+
# Check cpufreq driver enabled
355+
self.c.run_command("ls /sys/devices/system/cpu/cpu%s/cpufreq/" % cpu_num)
356+
357+
# Get available cpu boost frequencies
358+
l_res = self.c.run_command("cat /sys/devices/system/cpu/cpu%s/cpufreq/scaling_boost_frequencies" % cpu_num)
359+
print l_res
360+
freq_list = l_res[0].split(' ')[:-1] # remove empty entry at end
361+
print freq_list
362+
363+
# Boost frequencies will achieve only when cpufreq governor is performance
364+
self.set_cpu_gov("performance")
365+
self.verify_cpu_gov("performance")
366+
367+
achieved_freq = ""
368+
# Run the workload only on one active core so it should achieve one of boost frequencies
369+
res = self.c.run_command_ignore_fail("perf stat timeout 10 yes > /dev/null")
370+
for line in res:
371+
if "cycles" in line and "GHz" in line:
372+
achieved_freq = int(decimal.Decimal(line.split()[3]) * 1000000)
373+
break
374+
375+
if not achieved_freq:
376+
self.assertTrue(False, "Failed to get CPU achieved frequency")
377+
378+
achieved = False
379+
for freq in freq_list:
380+
delta = int(freq) / (100)
381+
try:
382+
self.assertAlmostEqual(int(freq), achieved_freq, delta=delta,
383+
msg="Set and measured CPU frequency differ too greatly")
384+
achieved = True
385+
break
386+
except AssertionError:
387+
pass
388+
389+
self.assertTrue(achieved, "CPU failed to achieve any one of the frequency in boost frequenies(WoF) range")
390+
print "CPU successfully achieved one of the boost freuency"
391+
print "Achieved freq: %d, near by WoF freq: %d" % (int(achieved_freq), int(freq))
392+
393+
310394
class cpu_idle_states_host(OpTestEM, unittest.TestCase):
311395
def setUp(self):
312396
self.test = "host"
@@ -389,11 +473,14 @@ def host_suite():
389473
s = unittest.TestSuite()
390474
s.addTest(slw_info())
391475
s.addTest(cpu_freq_states_host())
476+
s.addTest(cpu_freq_gov_host())
477+
s.addTest(cpu_boost_freqs_host())
392478
s.addTest(cpu_idle_states_host())
393479
return s
394480

395481
def skiroot_suite():
396482
s = unittest.TestSuite()
397483
s.addTest(cpu_freq_states_skiroot())
484+
s.addTest(cpu_freq_gov_skiroot())
398485
s.addTest(cpu_idle_states_skiroot())
399486
return s

0 commit comments

Comments
 (0)