Skip to content

Commit a77e15e

Browse files
jan-kiszkatorvalds
authored andcommitted
scripts/gdb: convert CpuList to generator function
Yet another code simplification. 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 fffb944 commit a77e15e

2 files changed

Lines changed: 33 additions & 40 deletions

File tree

‎scripts/gdb/linux/cpus.py‎

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -61,50 +61,43 @@ def cpu_mask_invalidate(event):
6161
gdb.events.new_objfile.disconnect(cpu_mask_invalidate)
6262

6363

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
64+
def cpu_list(mask_name):
65+
global cpu_mask
66+
mask = None
67+
if mask_name in cpu_mask:
68+
mask = cpu_mask[mask_name]
69+
if mask is None:
70+
mask = gdb.parse_and_eval(mask_name + ".bits")
71+
if hasattr(gdb, 'events'):
72+
cpu_mask[mask_name] = mask
73+
gdb.events.stop.connect(cpu_mask_invalidate)
74+
if hasattr(gdb.events, 'new_objfile'):
75+
gdb.events.new_objfile.connect(cpu_mask_invalidate)
76+
bits_per_entry = mask[0].type.sizeof * 8
77+
num_entries = mask.type.sizeof * 8 / bits_per_entry
78+
entry = -1
79+
bits = 0
80+
81+
while True:
82+
while bits == 0:
83+
entry += 1
84+
if entry == num_entries:
85+
return
86+
bits = mask[entry]
87+
if bits != 0:
88+
bit = 0
9389
break
9490

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
91+
while bits & 1 == 0:
92+
bits >>= 1
93+
bit += 1
10094

101-
self.bits >>= 1
102-
self.bit += 1
95+
cpu = entry * bits_per_entry + bit
10396

104-
return cpu
97+
bits >>= 1
98+
bit += 1
10599

106-
def next(self):
107-
return self.__next__()
100+
yield cpu
108101

109102

110103
class PerCpu(gdb.Function):

‎scripts/gdb/linux/modules.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def invoke(self, arg, from_tty):
7575
for module in module_list():
7676
ref = 0
7777
module_refptr = module['refptr']
78-
for cpu in cpus.CpuList("cpu_possible_mask"):
78+
for cpu in cpus.cpu_list("cpu_possible_mask"):
7979
refptr = cpus.per_cpu(module_refptr, cpu)
8080
ref += refptr['incs']
8181
ref -= refptr['decs']

0 commit comments

Comments
 (0)