• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python
2''' This Python script interprets various sched stats values.
3    Validates cpu consolidation for given sched_mc_power_saving value
4'''
5
6import os
7import sys
8import time
9from optparse import OptionParser
10from pm_sched_mc import *
11
12__author__ = "Poornima Nayak <mpnayak@linux.vnet.ibm.com>"
13
14class Usage(Exception):
15    def __init__(self, msg):
16        self.msg = msg
17
18def main(argv=None):
19    if argv is None:
20        argv = sys.argv
21
22    usage = "-w"
23    parser = OptionParser(usage)
24    parser.add_option("-v", "--variation_test", dest="vary_mc_smt",
25        default=False, action="store_true", help="Vary sched_mc & sched_smt. \
26            -c and -t inputs are initial value of sched_mc & sched_smt")
27    parser.add_option("-c", "--mc_value", dest="mc_value",
28        default=0, help="Sched mc power saving value 0/1/2")
29    parser.add_option("-t", "--smt_value", dest="smt_value",
30        default=0, help="Sched smt power saving value 0/1/2")
31    parser.add_option("-w", "--workload", dest="work_ld",
32        default="ebizzy", help="Workload can be ebizzy/kernbench")
33    parser.add_option("-s", "--stress", dest="stress",
34        default="partial", help="Load on system is full/partial [i.e 50%]/thread")
35    parser.add_option("-p", "--performance", dest="perf_test",
36        default=False, action="store_true", help="Enable performance test")
37    (options, args) = parser.parse_args()
38
39    try:
40        count_num_cpu()
41        count_num_sockets()
42        if is_hyper_threaded():
43            generate_sibling_list()
44
45        # User should set option -v to test cpu consolidation
46        # resets when sched_mc &(/) sched_smt is disabled when
47        # workload is already running in the system
48
49        if options.vary_mc_smt:
50
51            # Since same code is used for testing package consolidation and core
52            # consolidation is_multi_socket & is_hyper_threaded check is done
53            if is_multi_socket() and is_multi_core() and options.mc_value:
54                set_sched_mc_power(options.mc_value)
55
56            if is_hyper_threaded() and options.smt_value:
57                set_sched_smt_power(options.smt_value)
58
59            #Generate arguments for trigger workload, run workload in background
60            map_cpuid_pkgid()
61            background="yes"
62            duration=360
63            pinned="no"
64            if int(options.mc_value) < 2 and int(options.smt_value) < 2:
65                trigger_ebizzy (options.smt_value, "partial", duration, background, pinned)
66                work_ld="ebizzy"
67                #Wait for 120 seconds and then validate cpu consolidation works
68                #When sched_mc & sched_smt is set
69                import time
70                time.sleep(120)
71            else:
72                #Wait for 120 seconds and then validate cpu consolidation works
73                #When sched_mc & sched_smt is set
74                trigger_kernbench (options.smt_value, "partial", background, pinned, "no")
75                work_ld="kernbench"
76                import time
77                time.sleep(300)
78
79            generate_report()
80            status = validate_cpu_consolidation("partial", work_ld, options.mc_value, options.smt_value)
81            if status == 0:
82                print "INFO: Consolidation worked sched_smt &(/) sched_mc is set"
83                #Disable sched_smt & sched_mc interface values
84                if options.vary_mc_smt and options.mc_value > 0:
85                    set_sched_mc_power(0)
86                    mc_value = options.mc_value
87                else:
88                    mc_value = 0
89                if options.vary_mc_smt and options.smt_value > 0 and is_hyper_threaded():
90                    set_sched_smt_power(0)
91                    smt_value = options.smt_value
92                else:
93                    smt_value = 0
94
95                if work_ld == "kernbench":
96                    time.sleep(240)
97                else:
98                    time.sleep(120)
99
100                generate_report()
101                status = validate_cpu_consolidation("partial", work_ld, mc_value, smt_value)
102                if background == "yes":
103                    stop_wkld(work_ld)
104                #CPU consolidation should fail as sched_mc &(/) sched_smt is disabled
105                if status == 1:
106                    return(0)
107                else:
108                    return(1)
109            else:
110                print "INFO: CPU consolidation failed when sched_mc &(/) \
111sched_smt was enabled. This is pre-requisite to proceed"
112                return(status)
113        else:
114            #The else part of the code validates behaviour of sched_mc
115            # and sched_smt set to 0, 1 & 2
116            if is_multi_socket():
117                set_sched_mc_power(options.mc_value)
118            if is_hyper_threaded():
119                set_sched_smt_power(options.smt_value)
120            map_cpuid_pkgid()
121            print "INFO: Created table mapping cpu to package"
122            background="no"
123            duration=60
124            pinned ="no"
125
126            if options.perf_test:
127                perf_test="yes"
128            else:
129                perf_test="no"
130
131            trigger_workld( options.smt_value, options.work_ld, options.stress, duration, background, pinned, perf_test)
132            generate_report()
133            status = validate_cpu_consolidation(options.stress, options.work_ld,options.mc_value, options.smt_value)
134            reset_schedmc()
135            if is_hyper_threaded():
136                reset_schedsmt()
137            return(status)
138    except Exception, details:
139        print "INFO: CPU consolidation failed", details
140        return(1)
141
142if __name__ == "__main__":
143    sys.exit(main())
144