Skip to content

Commit

Permalink
scripts/gdb: add cpu iterators
Browse files Browse the repository at this point in the history
The linux kernel provides macro's for iterating against values from the
cpu_list masks.  By providing some commonly used masks, we can mirror
the kernels helper macros with easy to use generators.

Link: http://lkml.kernel.org/r/d045c6599771ada1999d49612ee30fd2f9acf17f.1462865983.git.jan.kiszka@siemens.com
Signed-off-by: Kieran Bingham <kieran.bingham@linaro.org>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Kieran Bingham authored and Linus Torvalds committed May 24, 2016
1 parent c1a1539 commit b150393
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions scripts/gdb/linux/cpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,44 @@ def cpu_list(mask_name):
yield cpu


def each_online_cpu():
for cpu in cpu_list("__cpu_online_mask"):
yield cpu


def each_present_cpu():
for cpu in cpu_list("__cpu_present_mask"):
yield cpu


def each_possible_cpu():
for cpu in cpu_list("__cpu_possible_mask"):
yield cpu


def each_active_cpu():
for cpu in cpu_list("__cpu_active_mask"):
yield cpu


class LxCpus(gdb.Command):
"""List CPU status arrays
Displays the known state of each CPU based on the kernel masks
and can help identify the state of hotplugged CPUs"""

def __init__(self):
super(LxCpus, self).__init__("lx-cpus", gdb.COMMAND_DATA)

def invoke(self, arg, from_tty):
gdb.write("Possible CPUs : {}\n".format(list(each_possible_cpu())))
gdb.write("Present CPUs : {}\n".format(list(each_present_cpu())))
gdb.write("Online CPUs : {}\n".format(list(each_online_cpu())))
gdb.write("Active CPUs : {}\n".format(list(each_active_cpu())))

LxCpus()


class PerCpu(gdb.Function):
"""Return per-cpu variable.
Expand Down

0 comments on commit b150393

Please sign in to comment.