|
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 |
PQoS API module.
|
|
Packit Service |
8a4b7a |
Provides RDT related helper functions used to configure RDT.
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
from pqos import Pqos
|
|
Packit Service |
8a4b7a |
from pqos.capability import PqosCap
|
|
Packit Service |
8a4b7a |
from pqos.l3ca import PqosCatL3
|
|
Packit Service |
8a4b7a |
from pqos.mba import PqosMba
|
|
Packit Service |
8a4b7a |
from pqos.allocation import PqosAlloc
|
|
Packit Service |
8a4b7a |
from pqos.cpuinfo import PqosCpuInfo
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
import common
|
|
Packit Service |
8a4b7a |
import log
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
class PqosApi:
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
Wrapper for libpqos wrapper.
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
def __init__(self):
|
|
Packit Service |
8a4b7a |
self.pqos = Pqos()
|
|
Packit Service |
8a4b7a |
self.cap = None
|
|
Packit Service |
8a4b7a |
self.l3ca = None
|
|
Packit Service |
8a4b7a |
self.mba = None
|
|
Packit Service |
8a4b7a |
self.alloc = None
|
|
Packit Service |
8a4b7a |
self.cpuinfo = None
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
def init(self):
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
Initializes libpqos
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
Returns:
|
|
Packit Service |
8a4b7a |
0 on success
|
|
Packit Service |
8a4b7a |
-1 otherwise
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
try:
|
|
Packit Service |
8a4b7a |
self.pqos.init('MSR')
|
|
Packit Service |
8a4b7a |
self.cap = PqosCap()
|
|
Packit Service |
8a4b7a |
self.l3ca = PqosCatL3()
|
|
Packit Service |
8a4b7a |
self.mba = PqosMba()
|
|
Packit Service |
8a4b7a |
self.alloc = PqosAlloc()
|
|
Packit Service |
8a4b7a |
self.cpuinfo = PqosCpuInfo()
|
|
Packit Service |
8a4b7a |
except Exception as ex:
|
|
Packit Service |
8a4b7a |
log.error(str(ex))
|
|
Packit Service |
8a4b7a |
return -1
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
return 0
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
def fini(self):
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
De-initializes libpqos
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
self.pqos.fini()
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
return 0
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
def release(self, cores):
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
Release cores, assigns cores to CoS#0
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
Parameters:
|
|
Packit Service |
8a4b7a |
cores: list of cores to be released
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
Returns:
|
|
Packit Service |
8a4b7a |
0 on success
|
|
Packit Service |
8a4b7a |
-1 otherwise
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
if cores is None:
|
|
Packit Service |
8a4b7a |
return 0
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
try:
|
|
Packit Service |
8a4b7a |
self.alloc.release(cores)
|
|
Packit Service |
8a4b7a |
except Exception as ex:
|
|
Packit Service |
8a4b7a |
log.error(str(ex))
|
|
Packit Service |
8a4b7a |
return -1
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
return 0
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
def alloc_assoc_set(self, cores, cos):
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
Assigns cores to CoS
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
Parameters:
|
|
Packit Service |
8a4b7a |
cores: list of cores to be assigned to cos
|
|
Packit Service |
8a4b7a |
cos: Class of Service
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
Returns:
|
|
Packit Service |
8a4b7a |
0 on success
|
|
Packit Service |
8a4b7a |
-1 otherwise
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
if not cores:
|
|
Packit Service |
8a4b7a |
return 0
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
try:
|
|
Packit Service |
8a4b7a |
for core in cores:
|
|
Packit Service |
8a4b7a |
self.alloc.assoc_set(core, cos)
|
|
Packit Service |
8a4b7a |
except Exception as ex:
|
|
Packit Service |
8a4b7a |
log.error(str(ex))
|
|
Packit Service |
8a4b7a |
return -1
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
return 0
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
def l3ca_set(self, sockets, cos_id, ways_mask):
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
Configures L3 CAT for CoS
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
Parameters:
|
|
Packit Service |
8a4b7a |
sockets: sockets list on which to configure L3 CAT
|
|
Packit Service |
8a4b7a |
cos_id: Class of Service
|
|
Packit Service |
8a4b7a |
ways_mask: L3 CAT CBM to set
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
Returns:
|
|
Packit Service |
8a4b7a |
0 on success
|
|
Packit Service |
8a4b7a |
-1 otherwise
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
try:
|
|
Packit Service |
8a4b7a |
cos = self.l3ca.COS(cos_id, ways_mask)
|
|
Packit Service |
8a4b7a |
for socket in sockets:
|
|
Packit Service |
8a4b7a |
self.l3ca.set(socket, [cos])
|
|
Packit Service |
8a4b7a |
except Exception as ex:
|
|
Packit Service |
8a4b7a |
log.error(str(ex))
|
|
Packit Service |
8a4b7a |
return -1
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
return 0
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
def mba_set(self, sockets, cos_id, mb_max):
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
Configures MBA rate for CoS
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
Parameters:
|
|
Packit Service |
8a4b7a |
sockets: sockets list on which to configure L3 CAT
|
|
Packit Service |
8a4b7a |
cos_id: Class of Service
|
|
Packit Service |
8a4b7a |
mb_max: MBA rate to set
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
Returns:
|
|
Packit Service |
8a4b7a |
0 on success
|
|
Packit Service |
8a4b7a |
-1 otherwise
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
try:
|
|
Packit Service |
8a4b7a |
cos = self.mba.COS(cos_id, mb_max)
|
|
Packit Service |
8a4b7a |
for socket in sockets:
|
|
Packit Service |
8a4b7a |
self.mba.set(socket, [cos])
|
|
Packit Service |
8a4b7a |
except Exception as ex:
|
|
Packit Service |
8a4b7a |
log.error(str(ex))
|
|
Packit Service |
8a4b7a |
return -1
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
return 0
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
def is_mba_supported(self):
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
Checks for MBA support
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
Returns:
|
|
Packit Service |
8a4b7a |
True if supported
|
|
Packit Service |
8a4b7a |
False otherwise
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
try:
|
|
Packit Service |
8a4b7a |
return bool(self.get_mba_num_cos())
|
|
Packit Service |
8a4b7a |
except Exception as ex:
|
|
Packit Service |
8a4b7a |
log.error(str(ex))
|
|
Packit Service |
8a4b7a |
return False
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
def is_l3_cat_supported(self):
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
Checks for L3 CAT support
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
Returns:
|
|
Packit Service |
8a4b7a |
True if supported
|
|
Packit Service |
8a4b7a |
False otherwise
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
try:
|
|
Packit Service |
8a4b7a |
return bool(self.get_l3ca_num_cos())
|
|
Packit Service |
8a4b7a |
except Exception as ex:
|
|
Packit Service |
8a4b7a |
log.error(str(ex))
|
|
Packit Service |
8a4b7a |
return False
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
def is_multicore(self):
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
Checks if system is multicore
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
Returns:
|
|
Packit Service |
8a4b7a |
True if multicore
|
|
Packit Service |
8a4b7a |
False otherwise
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
return self.get_num_cores() > 1
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
def get_num_cores(self):
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
Gets number of cores in system
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
Returns:
|
|
Packit Service |
8a4b7a |
num of cores
|
|
Packit Service |
8a4b7a |
None otherwise
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
try:
|
|
Packit Service |
8a4b7a |
sockets = self.cpuinfo.get_sockets()
|
|
Packit Service |
8a4b7a |
return sum([len(self.cpuinfo.get_cores(socket)) for socket in sockets])
|
|
Packit Service |
8a4b7a |
except Exception as ex:
|
|
Packit Service |
8a4b7a |
log.error(str(ex))
|
|
Packit Service |
8a4b7a |
return None
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
def check_core(self, core):
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
Verifies if a specified core is a valid logical core ID.
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
Parameters:
|
|
Packit Service |
8a4b7a |
core: core ID
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
Returns:
|
|
Packit Service |
8a4b7a |
True/False a given core number is valid/invalid
|
|
Packit Service |
8a4b7a |
None otherwise
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
try:
|
|
Packit Service |
8a4b7a |
return self.cpuinfo.check_core(core)
|
|
Packit Service |
8a4b7a |
except Exception as ex:
|
|
Packit Service |
8a4b7a |
log.error(str(ex))
|
|
Packit Service |
8a4b7a |
return None
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
def get_sockets(self):
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
Gets list of sockets
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
Returns:
|
|
Packit Service |
8a4b7a |
sockets list,
|
|
Packit Service |
8a4b7a |
None otherwise
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
try:
|
|
Packit Service |
8a4b7a |
return self.cpuinfo.get_sockets()
|
|
Packit Service |
8a4b7a |
except Exception as ex:
|
|
Packit Service |
8a4b7a |
log.error(str(ex))
|
|
Packit Service |
8a4b7a |
return None
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
def get_l3ca_num_cos(self):
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
Gets number of COS for L3 CAT
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
Returns:
|
|
Packit Service |
8a4b7a |
num of COS for L3 CAT
|
|
Packit Service |
8a4b7a |
None otherwise
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
try:
|
|
Packit Service |
8a4b7a |
return self.cap.get_l3ca_cos_num()
|
|
Packit Service |
8a4b7a |
except Exception as ex:
|
|
Packit Service |
8a4b7a |
log.error(str(ex))
|
|
Packit Service |
8a4b7a |
return None
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
def get_mba_num_cos(self):
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
Gets number of COS for MBA
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
Returns:
|
|
Packit Service |
8a4b7a |
num of COS for MBA
|
|
Packit Service |
8a4b7a |
None otherwise
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
try:
|
|
Packit Service |
8a4b7a |
return self.cap.get_mba_cos_num()
|
|
Packit Service |
8a4b7a |
except Exception as ex:
|
|
Packit Service |
8a4b7a |
log.error(str(ex))
|
|
Packit Service |
8a4b7a |
return None
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
def get_max_cos_id(self, alloc_type):
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
Gets max COS# (id) that can be used to configure set of allocation technologies
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
Returns:
|
|
Packit Service |
8a4b7a |
Available COS# to be used
|
|
Packit Service |
8a4b7a |
None otherwise
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
max_cos_num = None
|
|
Packit Service |
8a4b7a |
max_cos_cat = self.get_l3ca_num_cos()
|
|
Packit Service |
8a4b7a |
max_cos_mba = self.get_mba_num_cos()
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
if common.CAT_CAP not in alloc_type and common.MBA_CAP not in alloc_type:
|
|
Packit Service |
8a4b7a |
return None
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
if common.CAT_CAP in alloc_type and not max_cos_cat:
|
|
Packit Service |
8a4b7a |
return None
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
if common.MBA_CAP in alloc_type and not max_cos_mba:
|
|
Packit Service |
8a4b7a |
return None
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
if common.CAT_CAP in alloc_type:
|
|
Packit Service |
8a4b7a |
max_cos_num = max_cos_cat
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
if common.MBA_CAP in alloc_type:
|
|
Packit Service |
8a4b7a |
if max_cos_num is not None:
|
|
Packit Service |
8a4b7a |
max_cos_num = min(max_cos_mba, max_cos_num)
|
|
Packit Service |
8a4b7a |
else:
|
|
Packit Service |
8a4b7a |
max_cos_num = max_cos_mba
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
return max_cos_num - 1
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
def get_max_l3_cat_cbm(self):
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
Gets Max L3 CAT CBM
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
Returns:
|
|
Packit Service |
8a4b7a |
Max L3 CAT CBM
|
|
Packit Service |
8a4b7a |
None otherwise
|
|
Packit Service |
8a4b7a |
"""
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
if not self.is_l3_cat_supported():
|
|
Packit Service |
8a4b7a |
return None
|
|
Packit Service |
8a4b7a |
|
|
Packit Service |
8a4b7a |
try:
|
|
Packit Service |
8a4b7a |
l3ca_caps = self.cap.get_type("l3ca")
|
|
Packit Service |
8a4b7a |
return 2**l3ca_caps.num_ways - 1
|
|
Packit Service |
8a4b7a |
except Exception as ex:
|
|
Packit Service |
8a4b7a |
log.error(str(ex))
|
|
Packit Service |
8a4b7a |
return None
|