Skip to content

Commit 7722e84

Browse files
imran-knbrenns10
authored andcommitted
workqueue: make some improvements in workqueue helper module.
1. Allow for a workqueue name to be passed to show_all_workqueues, and in that case only show specified workqueue. 2. Make show_pwq handle the case of bad pwq addresses. This is useful on live systems. Signed-off-by: Imran Khan <[email protected]>
1 parent 2f4f1ce commit 7722e84

File tree

1 file changed

+58
-38
lines changed

1 file changed

+58
-38
lines changed

drgn_tools/workqueue.py

Lines changed: 58 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -456,26 +456,29 @@ def show_pwq(pwq: Object) -> None:
456456

457457
mayday = False if list_empty(pwq.pwqs_node.address_of_()) else True
458458

459-
print(f"pwq: ({pwq.type_.type_name()})0x{pwq.value_():x}")
460-
print("pool id:", pwq.pool.id.value_())
461-
# v6.9: a045a272d887 ("workqueue: Move pwq->max_active to wq->max_active")
462-
# Note that this commit appears to have been backported into stable trees,
463-
# and then also reverted...
464-
if hasattr(pwq, "max_active"):
465-
max_active = pwq.max_active
466-
else:
467-
max_active = pwq.wq.max_active
468-
print(
469-
"active/max_active ",
470-
pwq.nr_active.value_(),
471-
"/",
472-
max_active.value_(),
473-
)
474-
print(f"refcnt: {pwq.refcnt.value_()} Mayday: {mayday}")
459+
try:
460+
print(f"pwq: ({pwq.type_.type_name()})0x{pwq.value_():x}")
461+
print("pool id:", pwq.pool.id.value_())
462+
# v6.9: a045a272d887 ("workqueue: Move pwq->max_active to wq->max_active")
463+
# Note that this commit appears to have been backported into stable trees,
464+
# and then also reverted...
465+
if hasattr(pwq, "max_active"):
466+
max_active = pwq.max_active
467+
else:
468+
max_active = pwq.wq.max_active
469+
print(
470+
"active/max_active ",
471+
pwq.nr_active.value_(),
472+
"/",
473+
max_active.value_(),
474+
)
475+
print(f"refcnt: {pwq.refcnt.value_()} Mayday: {mayday}")
475476

476-
show_pwq_in_flight(pwq)
477-
show_pwq_pending(pwq)
478-
show_pwq_inactive(pwq)
477+
show_pwq_in_flight(pwq)
478+
show_pwq_pending(pwq)
479+
show_pwq_inactive(pwq)
480+
except FaultError:
481+
print(f"Could not dump pwq: 0x{pwq.value_():x}")
479482

480483

481484
def workqueue_idle(workqueue: Object) -> bool:
@@ -508,20 +511,27 @@ def show_one_workqueue(workqueue: Object) -> None:
508511
name = escape_ascii_string(workqueue.name.string_(), escape_backslash=True)
509512
print(f"{name} ({workqueue.type_.type_name()})0x{workqueue.value_():x}")
510513

511-
idle = workqueue_idle(workqueue)
514+
try:
515+
idle = workqueue_idle(workqueue)
512516

513-
if idle:
514-
print(" workqueue is idle")
515-
else:
516-
for pwq in for_each_pwq(workqueue):
517-
inactive_works_attr = (
518-
"inactive_works"
519-
if hasattr(pwq, "inactive_works")
520-
else "delayed_works"
521-
)
522-
inactive_works = getattr(pwq, inactive_works_attr).address_of_()
523-
if pwq.nr_active or not list_empty(inactive_works):
524-
show_pwq(pwq)
517+
if idle:
518+
print(" workqueue is idle")
519+
else:
520+
for pwq in for_each_pwq(workqueue):
521+
inactive_works_attr = (
522+
"inactive_works"
523+
if hasattr(pwq, "inactive_works")
524+
else "delayed_works"
525+
)
526+
inactive_works = getattr(
527+
pwq, inactive_works_attr
528+
).address_of_()
529+
if pwq.nr_active or not list_empty(inactive_works):
530+
show_pwq(pwq)
531+
except FaultError:
532+
print(
533+
f"Could not dump workqueue: {name} ({workqueue.type_.type_name()})0x{workqueue.value_():x}"
534+
)
525535

526536

527537
def worker_pool_idle(worker_pool: Object) -> bool:
@@ -561,17 +571,27 @@ def show_one_worker_pool(worker_pool: Object) -> None:
561571
print(" idle worker pids: ", idle_workers)
562572

563573

564-
def show_all_workqueues(prog: Program, showidle: bool = False) -> None:
574+
def show_all_workqueues(
575+
prog: Program, showidle: bool = False, wqname: Union[str, bytes] = ""
576+
) -> None:
565577
"""Dump state of all workqueues and worker_pools"""
566578

567-
for workqueue in for_each_workqueue(prog):
568-
if workqueue_idle(workqueue):
569-
if showidle:
570-
show_one_workqueue(workqueue)
579+
if wqname:
580+
workqueue = find_workqueue(prog, wqname)
581+
if not workqueue:
582+
print("Specified workqueue not found")
571583
else:
572584
show_one_workqueue(workqueue)
573585

574-
print("\n")
586+
else:
587+
for workqueue in for_each_workqueue(prog):
588+
if workqueue_idle(workqueue):
589+
if showidle:
590+
show_one_workqueue(workqueue)
591+
else:
592+
show_one_workqueue(workqueue)
593+
594+
print("\n")
575595

576596
for pool in for_each_pool(prog):
577597
if worker_pool_idle(pool):

0 commit comments

Comments
 (0)