MCPcopy Create free account
hub / github.com/F-Stack/f-stack / LogicalCoreList

Class LogicalCoreList

dpdk/dts/framework/testbed_model/hw/cpu.py:28–86  ·  view source on GitHub ↗

Convert these options into a list of logical core ids. lcore_list=[LogicalCore1, LogicalCore2] - a list of LogicalCores lcore_list=[0,1,2,3] - a list of int indices lcore_list=['0','1','2-3'] - a list of str indices; ranges are supported lcore_list='0,1,2-3' - a comma delimited

Source from the content-addressed store, hash-verified

26
27
28class LogicalCoreList(object):
29 """
30 Convert these options into a list of logical core ids.
31 lcore_list=[LogicalCore1, LogicalCore2] - a list of LogicalCores
32 lcore_list=[0,1,2,3] - a list of int indices
33 lcore_list=['0','1','2-3'] - a list of str indices; ranges are supported
34 lcore_list='0,1,2-3' - a comma delimited str of indices; ranges are supported
35
36 The class creates a unified format used across the framework and allows
37 the user to use either a str representation (using str(instance) or directly
38 in f-strings) or a list representation (by accessing instance.lcore_list).
39 Empty lcore_list is allowed.
40 """
41
42 _lcore_list: list[int]
43 _lcore_str: str
44
45 def __init__(self, lcore_list: list[int] | list[str] | list[LogicalCore] | str):
46 self._lcore_list = []
47 if isinstance(lcore_list, str):
48 lcore_list = lcore_list.split(",")
49 for lcore in lcore_list:
50 if isinstance(lcore, str):
51 self._lcore_list.extend(expand_range(lcore))
52 else:
53 self._lcore_list.append(int(lcore))
54
55 # the input lcores may not be sorted
56 self._lcore_list.sort()
57 self._lcore_str = f'{",".join(self._get_consecutive_lcores_range(self._lcore_list))}'
58
59 @property
60 def lcore_list(self) -> list[int]:
61 return self._lcore_list
62
63 def _get_consecutive_lcores_range(self, lcore_ids_list: list[int]) -> list[str]:
64 formatted_core_list = []
65 segment = lcore_ids_list[:1]
66 for lcore_id in lcore_ids_list[1:]:
67 if lcore_id - segment[-1] == 1:
68 segment.append(lcore_id)
69 else:
70 formatted_core_list.append(
71 f"{segment[0]}-{segment[-1]}" if len(segment) > 1 else f"{segment[0]}"
72 )
73 current_core_index = lcore_ids_list.index(lcore_id)
74 formatted_core_list.extend(
75 self._get_consecutive_lcores_range(lcore_ids_list[current_core_index:])
76 )
77 segment.clear()
78 break
79 if len(segment) > 0:
80 formatted_core_list.append(
81 f"{segment[0]}-{segment[-1]}" if len(segment) > 1 else f"{segment[0]}"
82 )
83 return formatted_core_list
84
85 def __str__(self) -> str:

Callers 3

__init__Method · 0.85
create_eal_parametersMethod · 0.85

Calls

no outgoing calls

Tested by 1