[Work][Python]Spec power automation-3
By: Fatboy Slim
Tags: Cpu, Power, Servers, Python

Environment: Windows server 2019, python 2.7

This blog follows from the previous blog.

There are three steps which I want to develop for automation.

Produce related setting file SPECpower_ssj_EXPERT, SPECpower_ssj_config_sut1, runssj.batch automatically. Run spec power, related stress, record related power consumption and ambient temperature. Plot chart and output report value automatically.

In the section one of this blog, the target is create SPECpower_ssj_config_sut1 file automatically. It shows system config and spec power setting. We can use “wmic” related command to get what config file need.

a. CPU: wmic cpu get name, NumberOfCores, NumberOfLogicalProcessors, L2Cachesize, L3Cachesize, CurrentClockSpeed/Format:List

b. DIMM:wmic MEMORYCHIP get capacity, manufacturer, partnumber, speed/Format:List

c. disk: wmic diskdrive get size

d. Power option: powercfg /getactivescheme

e. BIOS: mic bios get name

Solution:

import os

import subprocess

#=======================================================================================Cpu

Cpu=os.popen('wmic cpu get name, NumberOfCores, NumberOfLogicalProcessors, L2Cachesize, L3Cachesize, CurrentClockSpeed/Format:List').readlines()

Cpu_name, Cpu_core, Cpu_logical,Cpu_speed = Cpu[5][5:48], Cpu[6][14:16],Cpu[7][26:29].strip(),Cpu[2][18:22]

Cpu_number=len(Cpu)/9

Cpu_l3,Cpu_l2 = (float(Cpu[4][12:])/1024)*(Cpu_number),(float(Cpu[3][12:])/1024)*(Cpu_number)

Cpu_11=Cpu_l2/(4*Cpu_number*Cpu_number)

#=======================================================================================Nic

input_i=open(r'C:\specpower_D\TestInput.txt').readlines()

Nic_FW, Nic_speed= input_i[3].strip(), input_i[4].strip()

#=======================================================================================Dimm

Dimm=os.popen('wmic MEMORYCHIP get capacity, manufacturer, partnumber, speed/Format:List').readlines()

Dimm_size,Dimm_m,Dimm_p,Dimm_s=int(int(Dimm[2][9:])/(1024**3)),Dimm[3][13:].strip(), Dimm[4][11:].strip(), Dimm[5][6:].strip()

Dimm_slot=os.popen('wmic MEMORYCHIP get devicelocator').readlines()

slot=""

Dimm_n=len(Dimm_slot)-2

for i in range(1,len(Dimm_slot)-1):slot+=Dimm_slot[i][5:7]+" "

#=======================================================================================disk

disk=os.popen('wmic diskdrive get size').readlines()

disk_n, disk_c = len(disk)-2, int(int(disk[1])/(1024*1024*1024*0.93125))

#=======================================================================================spec power setting

Jvm=int(Cpu_logical)*Cpu_number/4

spec_c=0.83

if (Dimm_size*Dimm_n)<70:

spec_c=0.8

xmx=int((Dimm_size*Dimm_n*spec_c)/(int(Cpu_logical)*Cpu_number/4)*1024)

ff=[]

if Cpu_number==2:aff=Jvm/2

if Cpu_number==1:aff=Jvm

for i in range(0,aff): ff.append("F"+"0"*i)

#=======================================================================================Power option

power=os.popen('powercfg /getactivescheme').readlines()

power_s=power[0][57:]

#=======================================================================================BIOS & BMC

Bios=os.popen('wmic bios get name').readlines()[1][1:20]

Bmc= subprocess.check_output("c:\\ipmitool\\BMC_version.bat").rsplit()[12]

#=======================================================================================update config

h=open(r'C:\specpower_D\SPECpower_ssj_config_sut1.props')

sut_config=h.readlines()

sut_config[52]="config.hw.cpu="+Cpu_name+'

'

sut_config[55]="config.hw.cpu.characteristics=Cores: Cores: "+Cpu_core+" LogicalCores: "+Cpu_logical+" L3: "+str(int(Cpu_l3))+" MiB"+'

'

sut_config[58]="config.hw.cpu.mhz= "+Cpu_speed+'

'

sut_config[61]="config.hw.cpu.chips= "+str(Cpu_number)+'

'

sut_config[64]="config.hw.cpu.cores= "+str(int(Cpu_core)*Cpu_number)+'

'

sut_config[67]="config.hw.cpu.cores_per_chip= "+Cpu_core+'

'

sut_config[70]="config.hw.cpu.threads_per_core="+str(Cpu_number)+'

'

sut_config[73]="config.hw.cpu.orderable="+str(Cpu_number)+" chips"+'

'

sut_config[76]="config.hw.memory.gb="+str(Dimm_size*Dimm_n)+"GB"+'

'

sut_config[79]="config.hw.memory.dimms="+str(Dimm_n)+" x "+str(Dimm_size)+" GB"+'

'

sut_config[84]="config.hw.memory.description="+str(Dimm_size)+"GB "+ Dimm_m+" "+Dimm_p+" Speed: "+Dimm_s+" ;"+" slots "+slot+'

'

sut_config[88]="config.hw.cache.primary="+str(Cpu_11)+"MB"+'

'

sut_config[92]="config.hw.cache.secondary="+str(Cpu_l2)+"MB"+'

'

sut_config[95]="config.hw.cache.tertiary="+str(Cpu_l3)+"MB"+'

'

sut_config[102]="config.hw.disk="+str(disk_n)+" x "+str(disk_c)+"GB M.2 SSD"+'

'

sut_config[112]="config.hw.network.controller.enabled.firmware="+Nic_FW+'

'

sut_config[121]="config.hw.network.speed="+str(Nic_speed)+"GB"+'

'

sut_config[169]="config.sw.jvm.options=-Xmx"+str(xmx)+"m -Xms"+str(xmx)+"m -XX:ParallelGCThreads=2 -XX:SurvivorRatio=60 -XX:TargetSurvivorRatio=90 -XX:InlineSmallCode=3900 -XX:MaxInlineSize=270 -XX:FreqInlineSize=2500 -XX:AllocatePrefetchDistance=256 -XX:AllocatePrefetchLines=4 -XX:InitialTenuringThreshold=12 -XX:MaxTenuringThreshold=15 -XX:LoopUnrollLimit=45 -XX:+AggressiveOpts -XX:+UseLargePages -XX:+UseParallelOldGC"+'

'

sut_config[173]="config.sw.jvm.affinity=start /affinity "+str(ff) +'

'

sut_config[177]="config.sw.jvm.heap.initial="+str(xmx)+'

'

sut_config[181]="config.sw.jvm.heap.max="+str(xmx)+'

'

sut_config[196]="config.sw.power_management="+power_s+'

'

sut_config[200]="config.sw.boot_firmware.version="+Bios+'

'

sut_config[209]="config.sw.mgmt_firmware.version="+Bmc+'

'

h=open(r'C:\specpower_D\SPECpower_ssj_config_sut1.props','w+')

h.writelines(sut_config)

h.close()

Reference:

http://www.spec.org/power_ssj2008/