Skip to content

Commit a6b48c8

Browse files
committed
tools/workqueue/wq_dump.py: Clean up code and drop duplicate information
- Factor out wq_type_str() - Improve formatting so that it adapts to actual field widths. - Drop duplicate information from "Workqueue -> rescuer" section. If anything, we should add more rescuer-specific info - e.g. the number of work items rescued. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Juri Lelli <juri.lelli@redhat.com>
1 parent 7bd20b6 commit a6b48c8

1 file changed

Lines changed: 35 additions & 34 deletions

File tree

tools/workqueue/wq_dump.py

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,20 @@ def cpumask_str(cpumask):
7575
output += f'{v:08x}'
7676
return output.strip()
7777

78+
wq_type_len = 9
79+
80+
def wq_type_str(wq):
81+
if wq.flags & WQ_UNBOUND:
82+
if wq.flags & WQ_ORDERED:
83+
return f'{"ordered":{wq_type_len}}'
84+
else:
85+
if wq.unbound_attrs.affn_strict:
86+
return f'{"unbound,S":{wq_type_len}}'
87+
else:
88+
return f'{"unbound":{wq_type_len}}'
89+
else:
90+
return f'{"percpu":{wq_type_len}}'
91+
7892
worker_pool_idr = prog['worker_pool_idr']
7993
workqueues = prog['workqueues']
8094
wq_unbound_cpumask = prog['wq_unbound_cpumask']
@@ -92,6 +106,10 @@ def cpumask_str(cpumask):
92106
WQ_AFFN_NUMA = prog['WQ_AFFN_NUMA']
93107
WQ_AFFN_SYSTEM = prog['WQ_AFFN_SYSTEM']
94108

109+
WQ_NAME_LEN = prog['WQ_NAME_LEN'].value_()
110+
111+
cpumask_str_len = len(cpumask_str(wq_unbound_cpumask))
112+
95113
print('Affinity Scopes')
96114
print('===============')
97115

@@ -148,24 +166,13 @@ def print_pod_type(pt):
148166
print('Workqueue CPU -> pool')
149167
print('=====================')
150168

151-
print('[ workqueue \ type CPU', end='')
169+
print(f'[{"workqueue":^{WQ_NAME_LEN-2}}\\ {"type CPU":{wq_type_len}}', end='')
152170
for cpu in for_each_possible_cpu(prog):
153171
print(f' {cpu:{max_pool_id_len}}', end='')
154172
print(' dfl]')
155173

156174
for wq in list_for_each_entry('struct workqueue_struct', workqueues.address_of_(), 'list'):
157-
print(f'{wq.name.string_().decode()[-24:]:24}', end='')
158-
if wq.flags & WQ_UNBOUND:
159-
if wq.flags & WQ_ORDERED:
160-
print(' ordered ', end='')
161-
else:
162-
print(' unbound', end='')
163-
if wq.unbound_attrs.affn_strict:
164-
print(',S ', end='')
165-
else:
166-
print(' ', end='')
167-
else:
168-
print(' percpu ', end='')
175+
print(f'{wq.name.string_().decode():{WQ_NAME_LEN}} {wq_type_str(wq):10}', end='')
169176

170177
for cpu in for_each_possible_cpu(prog):
171178
pool_id = per_cpu_ptr(wq.cpu_pwq, cpu)[0].pool.id.value_()
@@ -178,29 +185,23 @@ def print_pod_type(pt):
178185

179186
print('')
180187
print('Workqueue -> rescuer')
181-
print('=====================')
182-
print(f'wq_unbound_cpumask={cpumask_str(wq_unbound_cpumask)}')
183-
print('')
184-
print('[ workqueue \ type unbound_cpumask rescuer pid cpumask]')
188+
print('====================')
189+
190+
ucpus_len = max(cpumask_str_len, len("unbound_cpus"))
191+
rcpus_len = max(cpumask_str_len, len("rescuer_cpus"))
192+
193+
print(f'[{"workqueue":^{WQ_NAME_LEN-2}}\\ {"unbound_cpus":{ucpus_len}} pid {"rescuer_cpus":{rcpus_len}} ]')
185194

186195
for wq in list_for_each_entry('struct workqueue_struct', workqueues.address_of_(), 'list'):
187-
print(f'{wq.name.string_().decode()[-24:]:24}', end='')
188-
if wq.flags & WQ_UNBOUND:
189-
if wq.flags & WQ_ORDERED:
190-
print(' ordered ', end='')
191-
else:
192-
print(' unbound', end='')
193-
if wq.unbound_attrs.affn_strict:
194-
print(',S ', end='')
195-
else:
196-
print(' ', end='')
197-
print(f' {cpumask_str(wq.unbound_attrs.cpumask):24}', end='')
196+
if not (wq.flags & WQ_MEM_RECLAIM):
197+
continue
198+
199+
print(f'{wq.name.string_().decode():{WQ_NAME_LEN}}', end='')
200+
if wq.unbound_attrs.value_() != 0:
201+
print(f' {cpumask_str(wq.unbound_attrs.cpumask):{ucpus_len}}', end='')
198202
else:
199-
print(' percpu ', end='')
200-
print(' ', end='')
203+
print(f' {"":{ucpus_len}}', end='')
201204

202-
if wq.flags & WQ_MEM_RECLAIM:
203-
print(f' {wq.rescuer.task.comm.string_().decode()[-24:]:24}', end='')
204-
print(f' {wq.rescuer.task.pid.value_():5}', end='')
205-
print(f' {cpumask_str(wq.rescuer.task.cpus_ptr)}', end='')
205+
print(f' {wq.rescuer.task.pid.value_():6}', end='')
206+
print(f' {cpumask_str(wq.rescuer.task.cpus_ptr):{rcpus_len}}', end='')
206207
print('')

0 commit comments

Comments
 (0)