root_domains_dump.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env drgn
  2. # SPDX-License-Identifier: GPL-2.0
  3. # Copyright (C) 2025 Juri Lelli <juri.lelli@redhat.com>
  4. # Copyright (C) 2025 Red Hat, Inc.
  5. desc = """
  6. This is a drgn script to show the current root domains configuration. For more
  7. info on drgn, visit https://github.com/osandov/drgn.
  8. Root domains are only printed once, as multiple CPUs might be attached to the
  9. same root domain.
  10. """
  11. import os
  12. import argparse
  13. import drgn
  14. from drgn import FaultError
  15. from drgn.helpers.common import *
  16. from drgn.helpers.linux import *
  17. def print_root_domains_info():
  18. # To store unique root domains found
  19. seen_root_domains = set()
  20. print("Retrieving (unique) Root Domain Information:")
  21. runqueues = prog['runqueues']
  22. def_root_domain = prog['def_root_domain']
  23. for cpu_id in for_each_possible_cpu(prog):
  24. try:
  25. rq = per_cpu(runqueues, cpu_id)
  26. root_domain = rq.rd
  27. # Check if we've already processed this root domain to avoid duplicates
  28. # Use the memory address of the root_domain as a unique identifier
  29. root_domain_cast = int(root_domain)
  30. if root_domain_cast in seen_root_domains:
  31. continue
  32. seen_root_domains.add(root_domain_cast)
  33. if root_domain_cast == int(def_root_domain.address_):
  34. print(f"\n--- Root Domain @ def_root_domain ---")
  35. else:
  36. print(f"\n--- Root Domain @ 0x{root_domain_cast:x} ---")
  37. print(f" From CPU: {cpu_id}") # This CPU belongs to this root domain
  38. # Access and print relevant fields from struct root_domain
  39. print(f" Span : {cpumask_to_cpulist(root_domain.span[0])}")
  40. print(f" Online : {cpumask_to_cpulist(root_domain.span[0])}")
  41. except drgn.FaultError as fe:
  42. print(f" (CPU {cpu_id}: Fault accessing kernel memory: {fe})")
  43. except AttributeError as ae:
  44. print(f" (CPU {cpu_id}: Missing attribute for root_domain (kernel struct change?): {ae})")
  45. except Exception as e:
  46. print(f" (CPU {cpu_id}: An unexpected error occurred: {e})")
  47. if __name__ == "__main__":
  48. parser = argparse.ArgumentParser(description=desc,
  49. formatter_class=argparse.RawTextHelpFormatter)
  50. args = parser.parse_args()
  51. print_root_domains_info()