Skip to content

Commit 3d4cd9c

Browse files
jan-kiszkatorvalds
authored andcommitted
scripts/gdb: add class to iterate over CPU masks
Will be used first to count module references. It is optimized to read the mask only once per stop. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Jason Wessel <jason.wessel@windriver.com> Cc: Andi Kleen <andi@firstfloor.org> Cc: Ben Widawsky <ben@bwidawsk.net> Cc: Borislav Petkov <bp@suse.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 116b47b commit 3d4cd9c

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

‎scripts/gdb/linux/cpus.py‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,60 @@ def per_cpu(var_ptr, cpu):
5050
return pointer.cast(var_ptr.type).dereference()
5151

5252

53+
cpu_mask = {}
54+
55+
56+
def cpu_mask_invalidate(event):
57+
global cpu_mask
58+
cpu_mask = {}
59+
gdb.events.stop.disconnect(cpu_mask_invalidate)
60+
if hasattr(gdb.events, 'new_objfile'):
61+
gdb.events.new_objfile.disconnect(cpu_mask_invalidate)
62+
63+
64+
class CpuList():
65+
def __init__(self, mask_name):
66+
global cpu_mask
67+
self.mask = None
68+
if mask_name in cpu_mask:
69+
self.mask = cpu_mask[mask_name]
70+
if self.mask is None:
71+
self.mask = gdb.parse_and_eval(mask_name + ".bits")
72+
if hasattr(gdb, 'events'):
73+
cpu_mask[mask_name] = self.mask
74+
gdb.events.stop.connect(cpu_mask_invalidate)
75+
if hasattr(gdb.events, 'new_objfile'):
76+
gdb.events.new_objfile.connect(cpu_mask_invalidate)
77+
self.bits_per_entry = self.mask[0].type.sizeof * 8
78+
self.num_entries = self.mask.type.sizeof * 8 / self.bits_per_entry
79+
self.entry = -1
80+
self.bits = 0
81+
82+
def __iter__(self):
83+
return self
84+
85+
def next(self):
86+
while self.bits == 0:
87+
self.entry += 1
88+
if self.entry == self.num_entries:
89+
raise StopIteration
90+
self.bits = self.mask[self.entry]
91+
if self.bits != 0:
92+
self.bit = 0
93+
break
94+
95+
while self.bits & 1 == 0:
96+
self.bits >>= 1
97+
self.bit += 1
98+
99+
cpu = self.entry * self.bits_per_entry + self.bit
100+
101+
self.bits >>= 1
102+
self.bit += 1
103+
104+
return cpu
105+
106+
53107
class PerCpu(gdb.Function):
54108
"""Return per-cpu variable.
55109

0 commit comments

Comments
 (0)