Commit a77e15e8 authored by Jan Kiszka's avatar Jan Kiszka Committed by Linus Torvalds

scripts/gdb: convert CpuList to generator function

Yet another code simplification.
Signed-off-by: default avatarJan 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: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent fffb944c
...@@ -61,50 +61,43 @@ def cpu_mask_invalidate(event): ...@@ -61,50 +61,43 @@ def cpu_mask_invalidate(event):
gdb.events.new_objfile.disconnect(cpu_mask_invalidate) gdb.events.new_objfile.disconnect(cpu_mask_invalidate)
class CpuList(): def cpu_list(mask_name):
def __init__(self, mask_name):
global cpu_mask global cpu_mask
self.mask = None mask = None
if mask_name in cpu_mask: if mask_name in cpu_mask:
self.mask = cpu_mask[mask_name] mask = cpu_mask[mask_name]
if self.mask is None: if mask is None:
self.mask = gdb.parse_and_eval(mask_name + ".bits") mask = gdb.parse_and_eval(mask_name + ".bits")
if hasattr(gdb, 'events'): if hasattr(gdb, 'events'):
cpu_mask[mask_name] = self.mask cpu_mask[mask_name] = mask
gdb.events.stop.connect(cpu_mask_invalidate) gdb.events.stop.connect(cpu_mask_invalidate)
if hasattr(gdb.events, 'new_objfile'): if hasattr(gdb.events, 'new_objfile'):
gdb.events.new_objfile.connect(cpu_mask_invalidate) gdb.events.new_objfile.connect(cpu_mask_invalidate)
self.bits_per_entry = self.mask[0].type.sizeof * 8 bits_per_entry = mask[0].type.sizeof * 8
self.num_entries = self.mask.type.sizeof * 8 / self.bits_per_entry num_entries = mask.type.sizeof * 8 / bits_per_entry
self.entry = -1 entry = -1
self.bits = 0 bits = 0
def __iter__(self): while True:
return self while bits == 0:
entry += 1
def __next__(self): if entry == num_entries:
while self.bits == 0: return
self.entry += 1 bits = mask[entry]
if self.entry == self.num_entries: if bits != 0:
raise StopIteration bit = 0
self.bits = self.mask[self.entry]
if self.bits != 0:
self.bit = 0
break break
while self.bits & 1 == 0: while bits & 1 == 0:
self.bits >>= 1 bits >>= 1
self.bit += 1 bit += 1
cpu = self.entry * self.bits_per_entry + self.bit cpu = entry * bits_per_entry + bit
self.bits >>= 1 bits >>= 1
self.bit += 1 bit += 1
return cpu yield cpu
def next(self):
return self.__next__()
class PerCpu(gdb.Function): class PerCpu(gdb.Function):
......
...@@ -75,7 +75,7 @@ class LxLsmod(gdb.Command): ...@@ -75,7 +75,7 @@ class LxLsmod(gdb.Command):
for module in module_list(): for module in module_list():
ref = 0 ref = 0
module_refptr = module['refptr'] module_refptr = module['refptr']
for cpu in cpus.CpuList("cpu_possible_mask"): for cpu in cpus.cpu_list("cpu_possible_mask"):
refptr = cpus.per_cpu(module_refptr, cpu) refptr = cpus.per_cpu(module_refptr, cpu)
ref += refptr['incs'] ref += refptr['incs']
ref -= refptr['decs'] ref -= refptr['decs']
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment