summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorJan Kiszka <jan.kiszka@siemens.com>2015-02-17 13:47:27 -0800
committerLinus Torvalds <torvalds@linux-foundation.org>2015-02-17 14:34:54 -0800
commit3d4cd9c94191f60cbb741cfbaa770d442c4680aa (patch)
tree53da922f74f37c17804a4b26da909797d8bc45e3 /scripts
parent116b47b4da037547585cebe4e3275ef68905d509 (diff)
downloadlinux-stable-3d4cd9c94191f60cbb741cfbaa770d442c4680aa.tar.gz
linux-stable-3d4cd9c94191f60cbb741cfbaa770d442c4680aa.tar.bz2
linux-stable-3d4cd9c94191f60cbb741cfbaa770d442c4680aa.zip
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>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/gdb/linux/cpus.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/scripts/gdb/linux/cpus.py b/scripts/gdb/linux/cpus.py
index b683da92f194..c1441f23c0c2 100644
--- a/scripts/gdb/linux/cpus.py
+++ b/scripts/gdb/linux/cpus.py
@@ -50,6 +50,60 @@ def per_cpu(var_ptr, cpu):
return pointer.cast(var_ptr.type).dereference()
+cpu_mask = {}
+
+
+def cpu_mask_invalidate(event):
+ global cpu_mask
+ cpu_mask = {}
+ gdb.events.stop.disconnect(cpu_mask_invalidate)
+ if hasattr(gdb.events, 'new_objfile'):
+ gdb.events.new_objfile.disconnect(cpu_mask_invalidate)
+
+
+class CpuList():
+ def __init__(self, mask_name):
+ global cpu_mask
+ self.mask = None
+ if mask_name in cpu_mask:
+ self.mask = cpu_mask[mask_name]
+ if self.mask is None:
+ self.mask = gdb.parse_and_eval(mask_name + ".bits")
+ if hasattr(gdb, 'events'):
+ cpu_mask[mask_name] = self.mask
+ gdb.events.stop.connect(cpu_mask_invalidate)
+ if hasattr(gdb.events, 'new_objfile'):
+ gdb.events.new_objfile.connect(cpu_mask_invalidate)
+ self.bits_per_entry = self.mask[0].type.sizeof * 8
+ self.num_entries = self.mask.type.sizeof * 8 / self.bits_per_entry
+ self.entry = -1
+ self.bits = 0
+
+ def __iter__(self):
+ return self
+
+ def next(self):
+ while self.bits == 0:
+ self.entry += 1
+ if self.entry == self.num_entries:
+ raise StopIteration
+ self.bits = self.mask[self.entry]
+ if self.bits != 0:
+ self.bit = 0
+ break
+
+ while self.bits & 1 == 0:
+ self.bits >>= 1
+ self.bit += 1
+
+ cpu = self.entry * self.bits_per_entry + self.bit
+
+ self.bits >>= 1
+ self.bit += 1
+
+ return cpu
+
+
class PerCpu(gdb.Function):
"""Return per-cpu variable.