"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "cyborg/accelerator/drivers/fpga/intel/sysinfo.py" between
openstack-cyborg-8.0.0.tar.gz and openstack-cyborg-9.0.0.tar.gz

About: OpenStack Cyborg provides a general purpose management framework for acceleration resources.
The "Zed" series (latest release).

sysinfo.py  (openstack-cyborg-8.0.0):sysinfo.py  (openstack-cyborg-9.0.0)
skipping to change at line 87 skipping to change at line 87
def get_link_targets(links): def get_link_targets(links):
return map( return map(
lambda p: lambda p:
os.path.realpath( os.path.realpath(
os.path.join(os.path.dirname(p), os.readlink(p))), os.path.join(os.path.dirname(p), os.readlink(p))),
links) links)
def all_fpgas(): def all_fpgas():
# glob.glob1("/sys/class/fpga", "*") # glob.glob("/sys/class/fpga", "*")
return set(get_link_targets(find_fpgas_by_know_list())) | set( return set(get_link_targets(find_fpgas_by_know_list())) | set(
map(lambda p: p.rsplit("/", 2)[0], map(lambda p: p.rsplit("/", 2)[0],
get_link_targets(glob.glob(os.path.join(SYS_FPGA, "*"))))) get_link_targets(glob.glob(os.path.join(SYS_FPGA, "*")))))
def all_vf_fpgas(): def all_vf_fpgas():
return [dev.rsplit("/", 2)[0] for dev in return [dev.rsplit("/", 2)[0] for dev in
glob.glob(os.path.join(SYS_FPGA, "*/device/physfn"))] glob.glob(os.path.join(SYS_FPGA, "*/device/physfn"))]
def all_pfs_have_vf(): def all_pfs_have_vf():
return list(filter(lambda p: glob.glob(os.path.join(p, "virtfn0")), return list(filter(lambda p: glob.glob(os.path.join(p, "virtfn0")),
skipping to change at line 117 skipping to change at line 117
return dict(map(lambda f: (os.path.basename(f), f), all_fpgas())) return dict(map(lambda f: (os.path.basename(f), f), all_fpgas()))
def all_vfs_in_pf_fpgas(pf_path): def all_vfs_in_pf_fpgas(pf_path):
return get_link_targets( return get_link_targets(
glob.glob(os.path.join(pf_path, "virtfn*"))) glob.glob(os.path.join(pf_path, "virtfn*")))
def all_pf_fpgas(): def all_pf_fpgas():
return filter(lambda p: glob.glob(os.path.join(p, "sriov_totalvfs")), return filter(lambda p: glob.glob(os.path.join(p, "sriov_totalvfs")),
all_fpgas()) all_fpgas())
def is_vf(path):
return True if (
glob.glob(os.path.join(path, "device/physfn")) or
glob.glob(os.path.join(path, "physfn"))) else False
def find_pf_by_vf(path):
if glob.glob(os.path.join(path, "physfn")):
return link_real_path(os.path.join(path, "physfn"))
def is_bdf(bdf): def is_bdf(bdf):
return True if BDF_PATTERN.match(bdf) else False return True if BDF_PATTERN.match(bdf) else False
def get_bdf_by_path(path): def get_bdf_by_path(path):
bdf = os.path.basename(path) bdf = os.path.basename(path)
if is_bdf(bdf): if is_bdf(bdf):
return bdf return bdf
return os.path.basename(os.readlink(os.path.join(path, "device"))) return os.path.basename(os.readlink(os.path.join(path, "device")))
def split_bdf(bdf):
return ["0x" + v for v in bdf.replace(".", ":").rsplit(":")[1:]]
def get_pf_bdf(bdf):
paths = glob.glob0(PCI_DEVICES_PATH, bdf)
if paths:
p0 = paths[0]
path = find_pf_by_vf(p0) if is_vf(p0) else p0
return get_bdf_by_path(path)
return bdf
def get_afu_ids(device_name): def get_afu_ids(device_name):
return map( return map(
read_line, read_line,
glob.glob( glob.glob(
os.path.join( os.path.join(
device_name, "intel-fpga-port.*", "afu_id") device_name, "intel-fpga-port.*", "afu_id")
) )
) )
skipping to change at line 205 skipping to change at line 185
infos[key] = DEVICE_FILE_HANDLER(key)( infos[key] = DEVICE_FILE_HANDLER(key)(
os.path.join(dirpath, filename)) os.path.join(dirpath, filename))
else: else:
infos[key] = read_line(os.path.join(dirpath, filename)) infos[key] = read_line(os.path.join(dirpath, filename))
return infos return infos
def fpga_tree(): def fpga_tree():
def gen_fpga_infos(path, vf=True): def gen_fpga_infos(path, vf=True):
bdf = get_bdf_by_path(path) bdf = get_bdf_by_path(path)
names = glob.glob1(os.path.join(path, "fpga"), "*") names = glob.glob1(os.path.join(path, "fpga"), "*")
# name = os.path.basename(path)
fpga = {"type": constants.DEVICE_FPGA, fpga = {"type": constants.DEVICE_FPGA,
"devices": bdf, "stub": True, "devices": bdf, "stub": True,
"name": "_".join((socket.gethostname(), bdf))} "name": "_".join((socket.gethostname(), bdf))}
d_info = fpga_device(path) d_info = fpga_device(path)
fpga.update(d_info) fpga.update(d_info)
if names: if names:
name = names[0] name = names[0]
fpga["stub"] = False fpga["stub"] = False
traits = get_traits(name, fpga["product_id"], vf) traits = get_traits(name, fpga["product_id"], vf)
fpga.update(traits) fpga.update(traits)
skipping to change at line 241 skipping to change at line 220
devs.append(_generate_driver_device(fpga, pf in pf_has_vf)) devs.append(_generate_driver_device(fpga, pf in pf_has_vf))
return devs return devs
def _generate_driver_device(fpga, pf_has_vf): def _generate_driver_device(fpga, pf_has_vf):
driver_device_obj = driver_device.DriverDevice() driver_device_obj = driver_device.DriverDevice()
driver_device_obj.vendor = fpga["vendor"] driver_device_obj.vendor = fpga["vendor"]
driver_device_obj.stub = fpga["stub"] driver_device_obj.stub = fpga["stub"]
driver_device_obj.model = fpga.get('model', "miss_model_info") driver_device_obj.model = fpga.get('model', "miss_model_info")
driver_device_obj.vendor_board_info = fpga.get('vendor_board_info', driver_device_obj.vendor_board_info = fpga.get('vendor_board_info',
"miss_vb_info") "miss_vb_info")
std_board_info = {'product_id': fpga.get('product_id', None)} std_board_info = {'product_id': fpga.get('product_id')}
driver_device_obj.std_board_info = jsonutils.dumps(std_board_info) driver_device_obj.std_board_info = jsonutils.dumps(std_board_info)
driver_device_obj.type = fpga["type"] driver_device_obj.type = fpga["type"]
driver_device_obj.controlpath_id = _generate_controlpath_id(fpga) driver_device_obj.controlpath_id = _generate_controlpath_id(fpga)
driver_device_obj.deployable_list = _generate_dep_list(fpga, pf_has_vf) driver_device_obj.deployable_list = _generate_dep_list(fpga, pf_has_vf)
return driver_device_obj return driver_device_obj
def _generate_controlpath_id(fpga): def _generate_controlpath_id(fpga):
driver_cpid = driver_controlpath_id.DriverControlPathID() driver_cpid = driver_controlpath_id.DriverControlPathID()
driver_cpid.cpid_type = "PCI" driver_cpid.cpid_type = "PCI"
driver_cpid.cpid_info = utils.pci_str_to_json(fpga["devices"]) driver_cpid.cpid_info = utils.pci_str_to_json(fpga["devices"])
skipping to change at line 266 skipping to change at line 245
driver_dep.attribute_list = _generate_attribute_list(fpga) driver_dep.attribute_list = _generate_attribute_list(fpga)
driver_dep.attach_handle_list = [] driver_dep.attach_handle_list = []
# pf without sriov enabled. # pf without sriov enabled.
if not pf_has_vf: if not pf_has_vf:
driver_dep.num_accelerators = 1 driver_dep.num_accelerators = 1
driver_dep.attach_handle_list = \ driver_dep.attach_handle_list = \
[_generate_attach_handle(fpga)] [_generate_attach_handle(fpga)]
driver_dep.name = fpga["name"] driver_dep.name = fpga["name"]
driver_dep.driver_name = DRIVER_NAME driver_dep.driver_name = DRIVER_NAME
# pf with sriov enabled, may have several regions and several vfs. # pf with sriov enabled, may have several regions and several vfs.
# For now, there is only region, this maybe improve in next release. # For now, there is only one region, this maybe improve in next release.
else: else:
driver_dep.num_accelerators = len(fpga["regions"]) driver_dep.num_accelerators = len(fpga["regions"])
for vf in fpga["regions"]: for vf in fpga["regions"]:
# Only vfs in regions can be attach, no pf. # Only vfs in regions can be attach, no pf.
driver_dep.attach_handle_list.append( driver_dep.attach_handle_list.append(
_generate_attach_handle(vf)) _generate_attach_handle(vf))
driver_dep.name = vf["name"] driver_dep.name = vf["name"]
driver_dep.driver_name = DRIVER_NAME driver_dep.driver_name = DRIVER_NAME
return [driver_dep] return [driver_dep]
def _generate_attach_handle(fpga): def _generate_attach_handle(fpga):
driver_ah = driver_attach_handle.DriverAttachHandle() driver_ah = driver_attach_handle.DriverAttachHandle()
driver_ah.attach_type = constants.AH_TYPE_PCI driver_ah.attach_type = constants.AH_TYPE_PCI
driver_ah.attach_info = utils.pci_str_to_json(fpga["devices"]) driver_ah.attach_info = utils.pci_str_to_json(fpga["devices"])
driver_ah.in_use = False driver_ah.in_use = False
return driver_ah return driver_ah
def _generate_attribute_list(fpga): def _generate_attribute_list(fpga):
attr_list = [] attr_list = []
count_pf_traits = 0
for k, v in fpga.items(): for k, v in fpga.items():
if k == "rc": if k == "rc":
driver_attr = driver_attribute.DriverAttribute() driver_attr = driver_attribute.DriverAttribute()
driver_attr.key, driver_attr.value = k, v driver_attr.key, driver_attr.value = k, v
attr_list.append(driver_attr) attr_list.append(driver_attr)
if k == "traits": if k == "traits":
values = fpga.get(k, []) values = fpga.get(k, [])
for index_pf, val in enumerate(values): for index_pf, val in enumerate(values):
driver_attr = driver_attribute.DriverAttribute() driver_attr = driver_attribute.DriverAttribute()
driver_attr.key = "trait" + str(index_pf) driver_attr.key = "trait" + str(index_pf)
driver_attr.value = val driver_attr.value = val
attr_list.append(driver_attr) attr_list.append(driver_attr)
if fpga.get("regions"): count_pf_traits = index_pf
for vf in fpga["regions"]: vfs = fpga.get('regions', [])
for k, values in vf.items(): for vf in vfs:
if k == "traits": for k, values in vf.items():
for index_vf, val in enumerate(values): if k == "traits":
driver_attr = driver_attribute.DriverAttribute( for index_vf, val in enumerate(values):
key="trait" + str(index_vf + index_pf), value=val) driver_attr = driver_attribute.DriverAttribute()
attr_list.append(driver_attr) driver_attr.key = "trait" + str(index_vf + count_pf_traits)
driver_attr.value = val
return attr_list return attr_list
 End of changes. 8 change blocks. 
32 lines changed or deleted 14 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)