scripts/gdb/linux/timerlist.py
Source file repositories/reference/linux-study-clean/scripts/gdb/linux/timerlist.py
File Facts
- System
- Linux kernel
- Corpus path
scripts/gdb/linux/timerlist.py- Extension
.py- Size
- 7700 bytes
- Lines
- 217
- Domain
- Support Tooling And Documentation
- Bucket
- scripts
- Inferred role
- Support Tooling And Documentation: scripts
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
# SPDX-License-Identifier: GPL-2.0
#
# Copyright 2019 Google LLC.
import binascii
import gdb
from linux import constants
from linux import cpus
from linux import rbtree
from linux import utils
timerqueue_node_type = utils.CachedType("struct timerqueue_node").get_type()
hrtimer_type = utils.CachedType("struct hrtimer").get_type()
def ktime_get():
"""Returns the current time, but not very accurately
We can't read the hardware timer itself to add any nanoseconds
that need to be added since we last stored the time in the
timekeeper. But this is probably good enough for debug purposes."""
tk_core = gdb.parse_and_eval("&timekeeper_data[TIMEKEEPER_CORE]")
return tk_core['timekeeper']['tkr_mono']['base']
def print_timer(rb_node, idx):
timerqueue = utils.container_of(rb_node, timerqueue_node_type.pointer(),
"node")
timer = utils.container_of(timerqueue, hrtimer_type.pointer(), "node")
function = str(timer['function']).split(" ")[1].strip("<>")
softexpires = timer['_softexpires']
expires = timer['node']['expires']
now = ktime_get()
text = " #{}: <{}>, {}, ".format(idx, timer, function)
text += "S:{:02x}\n".format(int(timer['state']))
text += " # expires at {}-{} nsecs [in {} to {} nsecs]\n".format(
softexpires, expires, softexpires - now, expires - now)
return text
def print_active_timers(base):
curr = base['active']['rb_root']['rb_leftmost']
idx = 0
while curr:
yield print_timer(curr, idx)
curr = rbtree.rb_next(curr)
idx += 1
def print_base(base):
text = " .base: {}\n".format(base.address)
text += " .index: {}\n".format(base['index'])
text += " .resolution: {} nsecs\n".format(constants.LX_hrtimer_resolution)
if constants.LX_CONFIG_HIGH_RES_TIMERS:
text += " .offset: {} nsecs\n".format(base['offset'])
text += "active timers:\n"
text += "".join([x for x in print_active_timers(base)])
return text
def print_cpu(hrtimer_bases, cpu, max_clock_bases):
cpu_base = cpus.per_cpu(hrtimer_bases, cpu)
jiffies = gdb.parse_and_eval("jiffies_64")
tick_sched_ptr = gdb.parse_and_eval("&tick_cpu_sched")
ts = cpus.per_cpu(tick_sched_ptr, cpu)
Annotation
- Atlas domain: Support Tooling And Documentation / scripts.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.