diff options
author | Jan Kiszka <jan.kiszka@siemens.com> | 2015-02-17 16:47:47 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-02-17 17:34:55 -0500 |
commit | a77e15e8b4ccaf43b3a527cbb882bf816c5a629d (patch) | |
tree | 848992343da0aa7607b939229d36711090c88073 /scripts | |
parent | fffb944c4e6d3882a7a15c494bd4cde36c68c39c (diff) |
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>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/gdb/linux/cpus.py | 71 | ||||
-rw-r--r-- | scripts/gdb/linux/modules.py | 2 |
2 files changed, 33 insertions, 40 deletions
diff --git a/scripts/gdb/linux/cpus.py b/scripts/gdb/linux/cpus.py index 8045871e2840..4297b83fedef 100644 --- a/scripts/gdb/linux/cpus.py +++ b/scripts/gdb/linux/cpus.py | |||
@@ -61,50 +61,43 @@ def cpu_mask_invalidate(event): | |||
61 | gdb.events.new_objfile.disconnect(cpu_mask_invalidate) | 61 | gdb.events.new_objfile.disconnect(cpu_mask_invalidate) |
62 | 62 | ||
63 | 63 | ||
64 | class CpuList(): | 64 | def cpu_list(mask_name): |
65 | def __init__(self, mask_name): | 65 | global cpu_mask |
66 | global cpu_mask | 66 | mask = None |
67 | self.mask = None | 67 | if mask_name in cpu_mask: |
68 | if mask_name in cpu_mask: | 68 | mask = cpu_mask[mask_name] |
69 | self.mask = cpu_mask[mask_name] | 69 | if mask is None: |
70 | if self.mask is None: | 70 | mask = gdb.parse_and_eval(mask_name + ".bits") |
71 | self.mask = gdb.parse_and_eval(mask_name + ".bits") | 71 | if hasattr(gdb, 'events'): |
72 | if hasattr(gdb, 'events'): | 72 | cpu_mask[mask_name] = mask |
73 | cpu_mask[mask_name] = self.mask | 73 | gdb.events.stop.connect(cpu_mask_invalidate) |
74 | gdb.events.stop.connect(cpu_mask_invalidate) | 74 | if hasattr(gdb.events, 'new_objfile'): |
75 | if hasattr(gdb.events, 'new_objfile'): | 75 | gdb.events.new_objfile.connect(cpu_mask_invalidate) |
76 | gdb.events.new_objfile.connect(cpu_mask_invalidate) | 76 | bits_per_entry = mask[0].type.sizeof * 8 |
77 | self.bits_per_entry = self.mask[0].type.sizeof * 8 | 77 | num_entries = mask.type.sizeof * 8 / bits_per_entry |
78 | self.num_entries = self.mask.type.sizeof * 8 / self.bits_per_entry | 78 | entry = -1 |
79 | self.entry = -1 | 79 | bits = 0 |
80 | self.bits = 0 | 80 | |
81 | 81 | while True: | |
82 | def __iter__(self): | 82 | while bits == 0: |
83 | return self | 83 | entry += 1 |
84 | 84 | if entry == num_entries: | |
85 | def __next__(self): | 85 | return |
86 | while self.bits == 0: | 86 | bits = mask[entry] |
87 | self.entry += 1 | 87 | if bits != 0: |
88 | if self.entry == self.num_entries: | 88 | bit = 0 |
89 | raise StopIteration | ||
90 | self.bits = self.mask[self.entry] | ||
91 | if self.bits != 0: | ||
92 | self.bit = 0 | ||
93 | break | 89 | break |
94 | 90 | ||
95 | while self.bits & 1 == 0: | 91 | while bits & 1 == 0: |
96 | self.bits >>= 1 | 92 | bits >>= 1 |
97 | self.bit += 1 | 93 | bit += 1 |
98 | |||
99 | cpu = self.entry * self.bits_per_entry + self.bit | ||
100 | 94 | ||
101 | self.bits >>= 1 | 95 | cpu = entry * bits_per_entry + bit |
102 | self.bit += 1 | ||
103 | 96 | ||
104 | return cpu | 97 | bits >>= 1 |
98 | bit += 1 | ||
105 | 99 | ||
106 | def next(self): | 100 | yield cpu |
107 | return self.__next__() | ||
108 | 101 | ||
109 | 102 | ||
110 | class PerCpu(gdb.Function): | 103 | class PerCpu(gdb.Function): |
diff --git a/scripts/gdb/linux/modules.py b/scripts/gdb/linux/modules.py index 6d497229d026..a1504c4f1900 100644 --- a/scripts/gdb/linux/modules.py +++ b/scripts/gdb/linux/modules.py | |||
@@ -75,7 +75,7 @@ class LxLsmod(gdb.Command): | |||
75 | for module in module_list(): | 75 | for module in module_list(): |
76 | ref = 0 | 76 | ref = 0 |
77 | module_refptr = module['refptr'] | 77 | module_refptr = module['refptr'] |
78 | for cpu in cpus.CpuList("cpu_possible_mask"): | 78 | for cpu in cpus.cpu_list("cpu_possible_mask"): |
79 | refptr = cpus.per_cpu(module_refptr, cpu) | 79 | refptr = cpus.per_cpu(module_refptr, cpu) |
80 | ref += refptr['incs'] | 80 | ref += refptr['incs'] |
81 | ref -= refptr['decs'] | 81 | ref -= refptr['decs'] |