tools/workqueue/wq_dump.py

Source file repositories/reference/linux-study-clean/tools/workqueue/wq_dump.py

File Facts

System
Linux kernel
Corpus path
tools/workqueue/wq_dump.py
Extension
.py
Size
8554 bytes
Lines
250
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: tools
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

#!/usr/bin/env drgn
#
# Copyright (C) 2023 Tejun Heo <tj@kernel.org>
# Copyright (C) 2023 Meta Platforms, Inc. and affiliates.

desc = """
This is a drgn script to show the current workqueue configuration. For more
info on drgn, visit https://github.com/osandov/drgn.

Affinity Scopes
===============

Shows the CPUs that can be used for unbound workqueues and how they will be
grouped by each available affinity type. For each type:

  nr_pods   number of CPU pods in the affinity type
  pod_cpus  CPUs in each pod
  pod_node  NUMA node for memory allocation for each pod
  cpu_pod   pod that each CPU is associated to

Worker Pools
============

Lists all worker pools indexed by their ID. For each pool:

  ref       number of pool_workqueue's associated with this pool
  nice      nice value of the worker threads in the pool
  idle      number of idle workers
  workers   number of all workers
  cpu       CPU the pool is associated with (per-cpu pool)
  cpus      CPUs the workers in the pool can run on (unbound pool)

Workqueue CPU -> pool
=====================

Lists all workqueues along with their type and worker pool association. For
each workqueue:

  NAME TYPE[,FLAGS] POOL_ID...

  NAME      name of the workqueue
  TYPE      percpu, unbound or ordered
  FLAGS     S: strict affinity scope
  POOL_ID   worker pool ID associated with each possible CPU
"""

import sys

import drgn
from drgn.helpers.linux.list import list_for_each_entry,list_empty
from drgn.helpers.linux.percpu import per_cpu_ptr
from drgn.helpers.linux.cpumask import for_each_cpu,for_each_possible_cpu
from drgn.helpers.linux.nodemask import for_each_node
from drgn.helpers.linux.idr import idr_for_each

import argparse
parser = argparse.ArgumentParser(description=desc,
                                 formatter_class=argparse.RawTextHelpFormatter)
args = parser.parse_args()

def err(s):
    print(s, file=sys.stderr, flush=True)
    sys.exit(1)

def cpumask_str(cpumask):
    output = ""
    base = 0
    v = 0
    for cpu in for_each_cpu(cpumask[0]):
        while cpu - base >= 32:

Annotation

Implementation Notes