Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752795AbaFFRVQ (ORCPT ); Fri, 6 Jun 2014 13:21:16 -0400 Received: from david.siemens.de ([192.35.17.14]:35963 "EHLO david.siemens.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752501AbaFFRTn (ORCPT ); Fri, 6 Jun 2014 13:19:43 -0400 From: Jan Kiszka To: Thomas Gleixner , Andrew Morton , linux-kernel@vger.kernel.org Cc: Jason Wessel , kgdb-bugreport@lists.sourceforge.net, Andi Kleen , Tom Tromey , Ben Widawsky , Borislav Petkov , Tatiana Al-Chueyr Martins Subject: [PATCH v8 19/22] scripts/gdb: Add class to iterate over CPU masks Date: Fri, 6 Jun 2014 19:19:00 +0200 Message-Id: <69b20dba882df37ba7d5d3b48041db12925132fa.1402075141.git.jan.kiszka@siemens.com> X-Mailer: git-send-email 1.8.1.1.298.ge7eed54 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Will be used first to count module references. It is optimized to read the mask only once per stop. Signed-off-by: Jan Kiszka --- 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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/