[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <328d5aa5badc05674d82feb678fd0288a903a8e3.1359463075.git.jan.kiszka@siemens.com>
Date: Tue, 29 Jan 2013 13:38:01 +0100
From: Jan Kiszka <jan.kiszka@...mens.com>
To: Andrew Morton <akpm@...ux-foundation.org>,
linux-kernel@...r.kernel.org
Cc: Jason Wessel <jason.wessel@...driver.com>,
kgdb-bugreport@...ts.sourceforge.net,
Andi Kleen <andi@...stfloor.org>,
Tom Tromey <tromey@...hat.com>,
Ben Widawsky <ben@...dawsk.net>, Borislav Petkov <bp@...en8.de>
Subject: [PATCH v5 18/20] scripts/gdb: Add helper to iterate over CPU masks
Will be used first to count module references. It is optimized to read
the mask only once per stop and to minimize the loop lengths.
Signed-off-by: Jan Kiszka <jan.kiszka@...mens.com>
---
scripts/gdb/percpu.py | 33 +++++++++++++++++++++++++++++++++
1 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/scripts/gdb/percpu.py b/scripts/gdb/percpu.py
index 4dab8d3..bc04188 100644
--- a/scripts/gdb/percpu.py
+++ b/scripts/gdb/percpu.py
@@ -43,6 +43,39 @@ def per_cpu(var_ptr, cpu):
pointer = var_ptr.cast(get_long_type()) + offset
return pointer.cast(var_ptr.type).dereference()
+cpu_mask = { }
+
+def for_each_cpu(mask_name, func, arg = None):
+ def invalidate_handler(event):
+ global cpu_online_mask
+ cpu_mask = { }
+ gdb.events.stop.disconnect(invalidate_handler)
+ gdb.events.new_objfile.disconnect(invalidate_handler)
+
+ global cpu_mask
+ mask = None
+ if mask_name in cpu_mask:
+ mask = cpu_mask[mask_name]
+ if mask == None:
+ mask = gdb.parse_and_eval(mask_name + ".bits")
+ cpu_mask[mask_name] = mask
+ gdb.events.stop.connect(invalidate_handler)
+ gdb.events.new_objfile.connect(invalidate_handler)
+
+ max_cpu_id = mask.type.sizeof * 8
+ bits_per_entry = mask[0].type.sizeof * 8
+ for entry in range(max_cpu_id / bits_per_entry):
+ bits = mask[entry]
+ if bits == 0:
+ continue
+ for bit in range(bits_per_entry):
+ if bits & 1:
+ cpu = entry * bits_per_entry + bit
+ func(cpu, arg)
+ bits >>= 1
+ if bits == 0:
+ break
+
class PerCpu(gdb.Function):
__doc__ = "Return per-cpu variable.\n" \
--
1.7.3.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists