All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@Siemens.com>
To: Andrew Morton <akpm@linux-foundation.org>, linux-kernel@vger.kernel.org
Cc: Jason Wessel <jason.wessel@windriver.com>,
	kgdb-bugreport@lists.sourceforge.net,
	Andi Kleen <andi@firstfloor.org>, Tom Tromey <tromey@redhat.com>,
	Ben Widawsky <ben@bwidawsk.net>, Borislav Petkov <bp@suse.de>,
	Tatiana Al-Chueyr Martins <tatiana.alchueyr@gmail.com>
Subject: [PATCH v6 19/21] scripts/gdb: Add class to iterate over CPU masks
Date: Mon, 28 Oct 2013 09:58:56 +0100	[thread overview]
Message-ID: <118dd28a6bdb9f3a644f09fb17f27eaee37f1174.1382950737.git.jan.kiszka@siemens.com> (raw)
In-Reply-To: <cover.1382950737.git.jan.kiszka@siemens.com>
In-Reply-To: <cover.1382950737.git.jan.kiszka@siemens.com>

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>
---
 scripts/gdb/linux/cpus.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/scripts/gdb/linux/cpus.py b/scripts/gdb/linux/cpus.py
index b683da9..c1441f2 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.
 
-- 
1.8.1.1.298.ge7eed54


  parent reply	other threads:[~2013-10-28  9:38 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-28  8:58 [PATCH v6 00/21] Add gdb python scripts as kernel debugging helpers Jan Kiszka
2013-10-28  8:58 ` Jan Kiszka
2013-10-28  8:58 ` [PATCH v6 01/21] scripts/gdb: Add infrastructure Jan Kiszka
2013-10-30  5:35   ` Andi Kleen
2013-10-30 10:28     ` Jan Kiszka
2013-10-28  8:58 ` [PATCH v6 02/21] scripts/gdb: Add cache for type objects Jan Kiszka
2013-10-28  8:58 ` [PATCH v6 03/21] scripts/gdb: Add container_of helper and convenience function Jan Kiszka
2013-10-28  8:58 ` [PATCH v6 04/21] scripts/gdb: Add module iteration class Jan Kiszka
2013-10-28  8:58 ` [PATCH v6 05/21] scripts/gdb: Add lx-symbols command Jan Kiszka
2013-10-28  8:58 ` [PATCH v6 06/21] module: Do not inline do_init_module Jan Kiszka
2013-10-28  8:58 ` [PATCH v6 07/21] scripts/gdb: Add automatic symbol reloading on module insertion Jan Kiszka
2013-10-28  8:58 ` [PATCH v6 08/21] scripts/gdb: Add internal helper and convenience function to look up a module Jan Kiszka
2013-10-28  8:58 ` [PATCH v6 09/21] scripts/gdb: Add get_target_endianness helper Jan Kiszka
2013-10-28  8:58 ` [PATCH v6 10/21] scripts/gdb: Add read_u16/32/64 helpers Jan Kiszka
2013-10-28  8:58 ` [PATCH v6 11/21] scripts/gdb: Add lx-dmesg command Jan Kiszka
2013-10-28  8:58 ` [PATCH v6 12/21] scripts/gdb: Add task iteration class Jan Kiszka
2013-10-28  8:58 ` [PATCH v6 13/21] scripts/gdb: Add helper and convenience function to look up tasks Jan Kiszka
2013-10-28  8:58 ` [PATCH v6 14/21] scripts/gdb: Add is_target_arch helper Jan Kiszka
2013-10-28  8:58 ` [PATCH v6 15/21] scripts/gdb: Add internal helper and convenience function to retrieve thread_info Jan Kiszka
2013-10-28  8:58   ` Jan Kiszka
2013-10-28  8:58 ` [PATCH v6 16/21] scripts/gdb: Add get_gdbserver_type helper Jan Kiszka
2013-10-28  8:58 ` [PATCH v6 17/21] scripts/gdb: Add internal helper and convenience function for per-cpu lookup Jan Kiszka
2013-10-28  8:58   ` Jan Kiszka
2013-10-28  8:58 ` [PATCH v6 18/21] scripts/gdb: Add lx_current convenience function Jan Kiszka
2013-10-28  8:58 ` Jan Kiszka [this message]
2013-10-28  8:58 ` [PATCH v6 20/21] scripts/gdb: Add lx-lsmod command Jan Kiszka
2013-10-28  8:58 ` [PATCH v6 21/21] scripts/gdb: Add basic documentation Jan Kiszka
2013-10-30 11:17   ` Borislav Petkov
2013-10-30 11:22     ` Jan Kiszka
2013-10-30 11:46       ` Borislav Petkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=118dd28a6bdb9f3a644f09fb17f27eaee37f1174.1382950737.git.jan.kiszka@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=akpm@linux-foundation.org \
    --cc=andi@firstfloor.org \
    --cc=ben@bwidawsk.net \
    --cc=bp@suse.de \
    --cc=jason.wessel@windriver.com \
    --cc=kgdb-bugreport@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tatiana.alchueyr@gmail.com \
    --cc=tromey@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.