1*66047526SJohn B. Wyatt IV#!/usr/bin/env python3 2*66047526SJohn B. Wyatt IV# SPDX-License-Identifier: GPL-2.0-only 3*66047526SJohn B. Wyatt IV 4*66047526SJohn B. Wyatt IVimport raw_pylibcpupower as p 5*66047526SJohn B. Wyatt IV 6*66047526SJohn B. Wyatt IV# Simple function call 7*66047526SJohn B. Wyatt IV 8*66047526SJohn B. Wyatt IV""" 9*66047526SJohn B. Wyatt IVGet cstate count 10*66047526SJohn B. Wyatt IV""" 11*66047526SJohn B. Wyatt IVcpu_cstates_count = p.cpuidle_state_count(0) 12*66047526SJohn B. Wyatt IVif cpu_cstates_count > -1: 13*66047526SJohn B. Wyatt IV print(f"CPU 0 has {cpu_cstates_count} c-states") 14*66047526SJohn B. Wyatt IVelse: 15*66047526SJohn B. Wyatt IV print(f"cstate count error: return code: {cpu_cstates_count}") 16*66047526SJohn B. Wyatt IV 17*66047526SJohn B. Wyatt IV""" 18*66047526SJohn B. Wyatt IVDisable cstate (will fail if the above is 0, ex: a virtual machine) 19*66047526SJohn B. Wyatt IV""" 20*66047526SJohn B. Wyatt IVcstate_disabled = p.cpuidle_state_disable(0, 0, 1) 21*66047526SJohn B. Wyatt IVif cpu_cstates_count == 0: 22*66047526SJohn B. Wyatt IV print(f"CPU 0 has {cpu_cstates_count} c-states") 23*66047526SJohn B. Wyatt IVelse: 24*66047526SJohn B. Wyatt IV print(f"cstate count error: return code: {cpu_cstates_count}") 25*66047526SJohn B. Wyatt IV 26*66047526SJohn B. Wyatt IVmatch cstate_disabled: 27*66047526SJohn B. Wyatt IV case 0: 28*66047526SJohn B. Wyatt IV print(f"CPU state disabled") 29*66047526SJohn B. Wyatt IV case -1: 30*66047526SJohn B. Wyatt IV print(f"Idlestate not available") 31*66047526SJohn B. Wyatt IV case _: 32*66047526SJohn B. Wyatt IV print(f"Not documented") 33*66047526SJohn B. Wyatt IV 34*66047526SJohn B. Wyatt IV 35*66047526SJohn B. Wyatt IV# Pointer example 36*66047526SJohn B. Wyatt IV 37*66047526SJohn B. Wyatt IVtopo = p.cpupower_topology() 38*66047526SJohn B. Wyatt IVtotal_cpus = p.get_cpu_topology(topo) 39*66047526SJohn B. Wyatt IVif total_cpus > 0: 40*66047526SJohn B. Wyatt IV print(f"Number of total cpus: {total_cpus} and number of cores: {topo.cores}") 41*66047526SJohn B. Wyatt IVelse: 42*66047526SJohn B. Wyatt IV print(f"Error: could not get cpu topology") 43