|
Packit Service |
8a4b7a |
################################################################################
|
|
Packit Service |
8a4b7a |
# BSD LICENSE
|
|
Packit Service |
8a4b7a |
#
|
|
Packit Service |
8a4b7a |
# Copyright(c) 2019-2020 Intel Corporation. All rights reserved.
|
|
Packit Service |
8a4b7a |
# All rights reserved.
|
|
Packit Service |
8a4b7a |
#
|
|
Packit Service |
8a4b7a |
# Redistribution and use in source and binary forms, with or without
|
|
Packit Service |
8a4b7a |
# modification, are permitted provided that the following conditions
|
|
Packit Service |
8a4b7a |
# are met:
|
|
Packit Service |
8a4b7a |
#
|
|
Packit Service |
8a4b7a |
# * Redistributions of source code must retain the above copyright
|
|
Packit Service |
8a4b7a |
# notice, this list of conditions and the following disclaimer.
|
|
Packit Service |
8a4b7a |
# * Redistributions in binary form must reproduce the above copyright
|
|
Packit Service |
8a4b7a |
# notice, this list of conditions and the following disclaimer in
|
|
Packit Service |
8a4b7a |
# the documentation and/or other materials provided with the
|
|
Packit Service |
8a4b7a |
# distribution.
|
|
Packit Service |
8a4b7a |
# * Neither the name of Intel Corporation nor the names of its
|
|
Packit Service |
8a4b7a |
# contributors may be used to endorse or promote products derived
|
|
Packit Service |
8a4b7a |
# from this software without specific prior written permission.
|
|
Packit Service |
8a4b7a |
#
|
|
Packit Service |
8a4b7a |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
Packit Service |
8a4b7a |
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
Packit Service |
8a4b7a |
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
Packit Service |
8a4b7a |
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
Packit Service |
8a4b7a |
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
Packit Service |
8a4b7a |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
Packit Service |
8a4b7a |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
Packit Service |
8a4b7a |
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
Packit Service |
8a4b7a |
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
Packit Service |
8a4b7a |
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
Packit Service |
8a4b7a |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
Packit Service |
8a4b7a |
################################################################################
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
Power common functions module
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
import pwr
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
def get_pwr_sys():
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
Returns list of CPU objects or None on error
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
try:
|
|
Packit Service |
8a4b7a |
pwr_sys = pwr.get_system()
|
|
Packit Service |
8a4b7a |
except (IOError, ValueError):
|
|
Packit Service |
8a4b7a |
return None
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
return pwr_sys
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
def get_pwr_cpus():
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
Returns list of CPU objects or None on error
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
try:
|
|
Packit Service |
8a4b7a |
cpus = pwr.get_cpus()
|
|
Packit Service |
8a4b7a |
except (IOError, ValueError):
|
|
Packit Service |
8a4b7a |
return None
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
return cpus
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
def get_pwr_cores():
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
Returns list of CORE objects or None on error
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
try:
|
|
Packit Service |
8a4b7a |
cores = pwr.get_cores()
|
|
Packit Service |
8a4b7a |
except (IOError, ValueError):
|
|
Packit Service |
8a4b7a |
return None
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
return cores
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
def get_pwr_lowest_freq():
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
Returns lowest supported freq or None on error
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
cpus = get_pwr_cpus()
|
|
Packit Service |
8a4b7a |
if not cpus:
|
|
Packit Service |
8a4b7a |
return None
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
return cpus[0].lowest_freq
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
def get_pwr_base_freq():
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
Returns base freq or None on error
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
cpus = get_pwr_cpus()
|
|
Packit Service |
8a4b7a |
if not cpus:
|
|
Packit Service |
8a4b7a |
return None
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
return cpus[0].base_freq
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
def get_pwr_highest_freq():
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
Returns highest supported freq or None on error
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
cpus = get_pwr_cpus()
|
|
Packit Service |
8a4b7a |
if not cpus:
|
|
Packit Service |
8a4b7a |
return None
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
return cpus[0].highest_freq
|