Skip to content

Commit 7a6e8d3

Browse files
committed
Styling fixes
1 parent 9e31ac4 commit 7a6e8d3

2 files changed

Lines changed: 74 additions & 16 deletions

File tree

sos/report/mellanox_firmware_suite/collectors/collector_manager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ def collect_cable_info(self):
3232
def collect_pcc_info(self):
3333
if not self.plugin.get_option("pcc", default=False):
3434
return
35+
3536
for ctx in self.device_contexts:
3637
PccCollector().run(self.plugin, ctx)

sos/report/mellanox_firmware_suite/collectors/pcc_collector.py

Lines changed: 73 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def _make_filename_for_ppcc_get(
6666
f"{key}_{value}" for key, value in command_options.items()
6767
)
6868
index_part = register_indexes.replace("=", "_").replace(",", "_")
69+
6970
return (
7071
f"{collection_file_prefix}--reg_name_PPCC_--get_"
7172
f"--op_{op_part}_--indexes_{index_part}"
@@ -75,11 +76,15 @@ def _make_filename_for_ppcc_get(
7576
def _get_algo_slot_indices(cls, mlxreg_output: str) -> List[int]:
7677
slot_count = cls._ALGO_SLOT_TEXT_INDEX_COUNT
7778
values_per_slot = [0] * slot_count
79+
7880
for match in cls._TEXT_TABLE_LINE_PATTERN.finditer(mlxreg_output):
7981
text_index = int(match.group(1))
82+
8083
if text_index >= slot_count:
8184
continue
85+
8286
values_per_slot[text_index] = int(match.group(2), 16)
87+
8388
return [
8489
text_index
8590
for text_index, value in enumerate(values_per_slot)
@@ -89,27 +94,36 @@ def _get_algo_slot_indices(cls, mlxreg_output: str) -> List[int]:
8994
@classmethod
9095
def _extract_value_field(cls, mlxreg_output: str) -> Optional[int]:
9196
match = cls._VALUE_FIELD_PATTERN.search(mlxreg_output)
97+
9298
if not match:
9399
return None
100+
94101
return int(match.group(1), 16)
95102

96103
@classmethod
97104
def _counter_en_enabled(cls, mlxreg_output: str) -> Optional[bool]:
98105
"""LSB of counter_en from algo status dump; None if field missing."""
99106
match = cls._COUNTER_EN_FIELD_PATTERN.search(mlxreg_output)
107+
100108
if not match:
101109
return None
110+
102111
v = int(match.group(1), 16)
112+
103113
return (v & 1) != 0
104114

105115
@classmethod
106116
def _clip_command_output(cls, text: str) -> str:
107117
raw = (text or "").strip()
118+
108119
if not raw:
109120
return "(empty)"
121+
110122
limit = cls._COMMAND_OUTPUT_LOG_MAX_CHARS
123+
111124
if len(raw) <= limit:
112125
return raw
126+
113127
return raw[:limit]
114128

115129
def _ppcc_get(
@@ -122,24 +136,29 @@ def _ppcc_get(
122136
command_options: PpccCommandOptions,
123137
register_indexes: str,
124138
) -> Tuple[int, str]:
139+
filename = self._make_filename_for_ppcc_get(
140+
collection_file_prefix,
141+
command_options,
142+
register_indexes,
143+
)
144+
125145
return_code, output = tool.ppcc_get(
126146
command_options,
127147
register_indexes,
128-
filename=self._make_filename_for_ppcc_get(
129-
collection_file_prefix,
130-
command_options,
131-
register_indexes,
132-
),
148+
filename=filename,
133149
subdir=output_subdir,
134150
)
151+
135152
if return_code != 0:
136153
op = command_options.get("cmd_type", "?")
154+
clipped_output = self._clip_command_output(output)
137155
plugin._log_info(
138156
"PPCC command failed "
139157
f"device={device_label} cmd_type={op} "
140158
f"indexes={register_indexes!r} rc={return_code} "
141-
f"output:\n{self._clip_command_output(output)}"
159+
f"output:\n{clipped_output}"
142160
)
161+
143162
return return_code, output
144163

145164
def _collect_counters_for_algo_slot(
@@ -152,26 +171,32 @@ def _collect_counters_for_algo_slot(
152171
register_indexes: str,
153172
) -> None:
154173
device_label = ctx.pci
174+
get_num_counters_op = self._op_for_cmd_type(
175+
PpccCommand.GET_NUM_COUNTERS
176+
)
155177

156178
return_code, output = self._ppcc_get(
157179
plugin,
158180
device_label,
159181
tool,
160182
collection_file_prefix,
161183
output_subdir,
162-
self._op_for_cmd_type(PpccCommand.GET_NUM_COUNTERS),
184+
get_num_counters_op,
163185
register_indexes,
164186
)
187+
165188
if return_code != 0:
166189
return
167190

168191
counter_count = self._extract_value_field(output)
192+
169193
if counter_count is None:
170194
return
171195

172196
counter_info_op = self._op_for_cmd_type(
173197
PpccCommand.GET_COUNTER_INFO
174198
)
199+
175200
for counter_index in range(counter_count):
176201
counter_indexes = (
177202
f"{register_indexes},algo_param_index={counter_index}"
@@ -189,13 +214,17 @@ def _collect_counters_for_algo_slot(
189214
if counter_count == 0:
190215
return
191216

217+
bulk_get_counters_op = self._op_for_cmd_type(
218+
PpccCommand.BULK_GET_COUNTERS
219+
)
220+
192221
self._ppcc_get(
193222
plugin,
194223
device_label,
195224
tool,
196225
collection_file_prefix,
197226
output_subdir,
198-
self._op_for_cmd_type(PpccCommand.BULK_GET_COUNTERS),
227+
bulk_get_counters_op,
199228
register_indexes,
200229
)
201230

@@ -209,26 +238,32 @@ def _collect_params_for_algo_slot(
209238
register_indexes: str,
210239
) -> None:
211240
device_label = ctx.pci
241+
get_num_params_op = self._op_for_cmd_type(
242+
PpccCommand.GET_NUM_PARAMS
243+
)
212244

213245
return_code, output = self._ppcc_get(
214246
plugin,
215247
device_label,
216248
tool,
217249
collection_file_prefix,
218250
output_subdir,
219-
self._op_for_cmd_type(PpccCommand.GET_NUM_PARAMS),
251+
get_num_params_op,
220252
register_indexes,
221253
)
254+
222255
if return_code != 0:
223256
return
224257

225258
param_count = self._extract_value_field(output)
259+
226260
if param_count is None:
227261
return
228262

229263
param_info_op = self._op_for_cmd_type(
230264
PpccCommand.GET_PARAM_INFO
231265
)
266+
232267
for param_index in range(param_count):
233268
param_indexes = (
234269
f"{register_indexes},algo_param_index={param_index}"
@@ -246,20 +281,25 @@ def _collect_params_for_algo_slot(
246281
if param_count == 0:
247282
return
248283

284+
bulk_get_params_op = self._op_for_cmd_type(
285+
PpccCommand.BULK_GET_PARAMS
286+
)
287+
249288
return_code, _ = self._ppcc_get(
250289
plugin,
251290
device_label,
252291
tool,
253292
collection_file_prefix,
254293
output_subdir,
255-
self._op_for_cmd_type(PpccCommand.BULK_GET_PARAMS),
294+
bulk_get_params_op,
256295
register_indexes,
257296
)
258297

259298
if return_code == 0:
260299
return
261300

262301
get_param_op = self._op_for_cmd_type(PpccCommand.GET_PARAM)
302+
263303
for param_index in range(param_count):
264304
param_indexes = (
265305
f"{register_indexes},algo_param_index={param_index}"
@@ -287,6 +327,9 @@ def _collect_single_algo_slot(
287327
algo_slot_index
288328
)
289329
device_label = ctx.pci
330+
get_algo_status_op = self._op_for_cmd_type(
331+
PpccCommand.GET_ALGO_STATUS
332+
)
290333

291334
if algo_slot_index in self._ALGO_SLOTS_COLLECT_STATUS_CMD_ONLY:
292335
self._ppcc_get(
@@ -295,18 +338,23 @@ def _collect_single_algo_slot(
295338
tool,
296339
collection_file_prefix,
297340
output_subdir,
298-
self._op_for_cmd_type(PpccCommand.GET_ALGO_STATUS),
341+
get_algo_status_op,
299342
register_indexes,
300343
)
344+
301345
return
302346

347+
get_algo_info_op = self._op_for_cmd_type(
348+
PpccCommand.GET_ALGO_INFO
349+
)
350+
303351
self._ppcc_get(
304352
plugin,
305353
device_label,
306354
tool,
307355
collection_file_prefix,
308356
output_subdir,
309-
self._op_for_cmd_type(PpccCommand.GET_ALGO_INFO),
357+
get_algo_info_op,
310358
register_indexes,
311359
)
312360

@@ -316,17 +364,20 @@ def _collect_single_algo_slot(
316364
tool,
317365
collection_file_prefix,
318366
output_subdir,
319-
self._op_for_cmd_type(PpccCommand.GET_ALGO_STATUS),
367+
get_algo_status_op,
320368
register_indexes,
321369
)
370+
322371
if return_code != 0:
323372
return
324373

325374
algo_status = self._extract_value_field(output)
375+
326376
if algo_status is not None and algo_status != 1:
327377
return
328378

329379
counter_en_on = self._counter_en_enabled(output)
380+
330381
if counter_en_on:
331382
self._collect_counters_for_algo_slot(
332383
plugin,
@@ -336,6 +387,7 @@ def _collect_single_algo_slot(
336387
ctx,
337388
register_indexes,
338389
)
390+
339391
self._collect_params_for_algo_slot(
340392
plugin,
341393
tool,
@@ -349,22 +401,27 @@ def _collect_ppcc_data(self, plugin, tool, tool_name: str, ctx) -> None:
349401
collection_file_prefix = f"{tool_name}_{ctx.bdf}_"
350402
output_subdir = "pcc_info"
351403
device_label = ctx.pci
404+
algo_info_array_op = self._op_for_cmd_type(
405+
PpccCommand.ALGO_INFO_ARRAY
406+
)
352407

353408
return_code, output = self._ppcc_get(
354409
plugin,
355410
device_label,
356411
tool,
357412
collection_file_prefix,
358413
output_subdir,
359-
self._op_for_cmd_type(PpccCommand.ALGO_INFO_ARRAY),
414+
algo_info_array_op,
360415
self._BASE_REGISTER_INDEXES,
361416
)
417+
362418
if return_code != 0:
363419
return
364420

421+
algo_slots = self._get_algo_slot_indices(output)
422+
365423
present_algo_slots = sorted(
366-
frozenset(self._get_algo_slot_indices(output))
367-
| self._ALGO_SLOTS_COLLECT_STATUS_CMD_ONLY,
424+
frozenset(algo_slots) | self._ALGO_SLOTS_COLLECT_STATUS_CMD_ONLY,
368425
)
369426

370427
for algo_slot_index in present_algo_slots:

0 commit comments

Comments
 (0)