diff options
author | Jan Kiszka <jan.kiszka@siemens.com> | 2015-02-17 16:47:27 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-02-17 17:34:54 -0500 |
commit | 3d4cd9c94191f60cbb741cfbaa770d442c4680aa (patch) | |
tree | 53da922f74f37c17804a4b26da909797d8bc45e3 /scripts/gdb | |
parent | 116b47b4da037547585cebe4e3275ef68905d509 (diff) |
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/gdb')
-rw-r--r-- | scripts/gdb/linux/cpus.py | 54 |
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): | |||
50 | return pointer.cast(var_ptr.type).dereference() | 50 | return pointer.cast(var_ptr.type).dereference() |
51 | 51 | ||
52 | 52 | ||
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 | |||
53 | class PerCpu(gdb.Function): | 107 | class PerCpu(gdb.Function): |
54 | """Return per-cpu variable. | 108 | """Return per-cpu variable. |
55 | 109 | ||