xref: /linux/tools/sched_ext/scx_show_state.py (revision 3fd6c59042dbba50391e30862beac979491145fe)
11c3ae1cbSTejun Heo#!/usr/bin/env drgn
21c3ae1cbSTejun Heo#
31c3ae1cbSTejun Heo# Copyright (C) 2024 Tejun Heo <tj@kernel.org>
41c3ae1cbSTejun Heo# Copyright (C) 2024 Meta Platforms, Inc. and affiliates.
51c3ae1cbSTejun Heo
61c3ae1cbSTejun Heodesc = """
71c3ae1cbSTejun HeoThis is a drgn script to show the current sched_ext state.
81c3ae1cbSTejun HeoFor more info on drgn, visit https://github.com/osandov/drgn.
91c3ae1cbSTejun Heo"""
101c3ae1cbSTejun Heo
111c3ae1cbSTejun Heoimport drgn
121c3ae1cbSTejun Heoimport sys
131c3ae1cbSTejun Heo
141c3ae1cbSTejun Heodef err(s):
151c3ae1cbSTejun Heo    print(s, file=sys.stderr, flush=True)
161c3ae1cbSTejun Heo    sys.exit(1)
171c3ae1cbSTejun Heo
181c3ae1cbSTejun Heodef read_int(name):
191c3ae1cbSTejun Heo    return int(prog[name].value_())
201c3ae1cbSTejun Heo
211c3ae1cbSTejun Heodef read_atomic(name):
221c3ae1cbSTejun Heo    return prog[name].counter.value_()
231c3ae1cbSTejun Heo
241c3ae1cbSTejun Heodef read_static_key(name):
251c3ae1cbSTejun Heo    return prog[name].key.enabled.counter.value_()
261c3ae1cbSTejun Heo
271c3ae1cbSTejun Heodef ops_state_str(state):
281c3ae1cbSTejun Heo    return prog['scx_ops_enable_state_str'][state].string_().decode()
291c3ae1cbSTejun Heo
301c3ae1cbSTejun Heoops = prog['scx_ops']
311c3ae1cbSTejun Heoenable_state = read_atomic("scx_ops_enable_state_var")
321c3ae1cbSTejun Heo
331c3ae1cbSTejun Heoprint(f'ops           : {ops.name.string_().decode()}')
341c3ae1cbSTejun Heoprint(f'enabled       : {read_static_key("__scx_ops_enabled")}')
351c3ae1cbSTejun Heoprint(f'switching_all : {read_int("scx_switching_all")}')
361c3ae1cbSTejun Heoprint(f'switched_all  : {read_static_key("__scx_switched_all")}')
371c3ae1cbSTejun Heoprint(f'enable_state  : {ops_state_str(enable_state)} ({enable_state})')
381c3ae1cbSTejun Heoprint(f'in_softlockup : {prog["scx_in_softlockup"].value_()}')
391c3ae1cbSTejun Heoprint(f'breather_depth: {read_atomic("scx_ops_breather_depth")}')
40*431844b6SAndrea Righiprint(f'bypass_depth  : {prog["scx_ops_bypass_depth"].value_()}')
41print(f'nr_rejected   : {read_atomic("scx_nr_rejected")}')
42print(f'enable_seq    : {read_atomic("scx_enable_seq")}')
43