Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp10339368rwl; Mon, 2 Jan 2023 00:18:25 -0800 (PST) X-Google-Smtp-Source: AMrXdXtuZ0jxvJQsl+zHnAyLLqg0U8SywWI7o39fRNgFBq962CrVRMrktFseN4LnfoOAscO3wnbn X-Received: by 2002:a05:6402:754:b0:485:9d0f:6193 with SMTP id p20-20020a056402075400b004859d0f6193mr20801597edy.38.1672647505269; Mon, 02 Jan 2023 00:18:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672647505; cv=none; d=google.com; s=arc-20160816; b=Z7FbvubUJxq+Usj4upnmLVy5hH/wljbxzclLrMSo1W9Ay4qtAueSu+m6G/PHQszR8C A9tQx8VKSYn3PUZEAAvO8KG9kPUBV+9UxOS4UMp7tIMlsv2KY3Nmq0mEN6I9ni6KNM8Q gbp1FbV58wKPUX9iYpxVmaCWNxwAtGyty2zk2dyCjdiFariEo6ceJ3NK0MnAX7r8msHO FH/luJbJ/WHlz+NuhR+cQWlDDZFfUqgfxA37xSZeEGS+OA/dppfcsYai7pOigWm8uacP QOaDfzIV2/dyLbqoJQ5hJZmqzOvA80TSf5dpkNXYMAzgtqOJONiY91E3L7d+PlFV4Jil KgBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=W0vTPkL5vUjq9OfCD2rgfGoJAxazOlZRH4CFOUoi5Kc=; b=UgkTDrXzePh3dIoZEEefXyqHyiUCME6XrYucSCtbMhvS4MR3qBX377jEHEQWtmpT3e f36hwZgRLMnLf0dUlIgKoO83M1vmk3wrY8yBxPapCPk+u+uKBGPWheOTJzkt0InCHhg5 9YLTussjWH1WLiqammRsIA7ROWWsMFpj4PuJy3QgW3ftg5Fl8+tAGpbBYahGRi6EkaqT wduKDIx2mjXk3Eigf41+1KiQULpB4+v5aM65u0qk3K4JYKz/G22ilnD7DAWKjyGAJFZu G9LN0cs+itnbEn7m/fNh7dYB4G6euLGBKxE9ICaLnlAIbAOZAlArbIwEdic2NFUbDajL FK0g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h5-20020a0564020e8500b0048b4f11fbfdsi6863723eda.117.2023.01.02.00.18.09; Mon, 02 Jan 2023 00:18:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229744AbjABHnv (ORCPT + 59 others); Mon, 2 Jan 2023 02:43:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229447AbjABHnt (ORCPT ); Mon, 2 Jan 2023 02:43:49 -0500 Received: from zju.edu.cn (spam.zju.edu.cn [61.164.42.155]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 253C91121 for ; Sun, 1 Jan 2023 23:43:46 -0800 (PST) Received: from localhost.localdomain (unknown [10.12.77.33]) by mail-app3 (Coremail) with SMTP id cC_KCgB3Xagsi7Jj6Xt5Cw--.5552S4; Mon, 02 Jan 2023 15:43:40 +0800 (CST) From: Lin Ma To: jan.kiszka@siemens.com, kbingham@kernel.org, linux-kernel@vger.kernel.org Cc: Lin Ma Subject: [PATCH] scripts/gdb: fix 'lx-timerlist' on newer kernel Date: Mon, 2 Jan 2023 15:43:40 +0800 Message-Id: <20230102074340.17459-1-linma@zju.ed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2KfnxnUUI43ZEXa7VUbXdbUUUUUU== X-CM-SenderInfo: qtrwiiyqvtljo62m3hxhgxhubq/ X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org After commit 511885d7061e ("lib/timerqueue: Rely on rbtree semantics for next timer"), the struct timerqueue_head changes internal field hence causes the old lx-timerlist command keeps reporting errors. This fix addes a simple version comparison and necessary code for traversing timerqueue on a newer kernel. Moreover, it fixes some python 3.X compatibility bugs. Test with python 2.7 and python 3.6 Test with * commit 442284a89a65 ("scripts/gdb: add a timer list command") and * commit 88603b6dc419 ("Linux 6.2-rc2") kernel Signed-off-by: Lin Ma --- scripts/gdb/linux/timerlist.py | 41 ++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/scripts/gdb/linux/timerlist.py b/scripts/gdb/linux/timerlist.py index 071d0dd5a634..65d035df253d 100644 --- a/scripts/gdb/linux/timerlist.py +++ b/scripts/gdb/linux/timerlist.py @@ -4,6 +4,7 @@ import binascii import gdb +import re from linux import constants from linux import cpus @@ -42,9 +43,15 @@ def print_timer(rb_node, idx): return text -def print_active_timers(base): - curr = base['active']['next']['node'] - curr = curr.address.cast(rbtree.rb_node_type.get_type().pointer()) +def print_active_timers(base, oldver): + # 511885d7061e ("lib/timerqueue: Rely on rbtree semantics for next timer") + if oldver: + curr = base['active']['next']['node'] + curr = curr.address.cast(rbtree.rb_node_type.get_type().pointer()) + else: + leftmost = base['active']['rb_root']['rb_leftmost'] + curr = leftmost.cast(rbtree.rb_node_type.get_type().pointer()) + idx = 0 while curr: yield print_timer(curr, idx) @@ -52,7 +59,7 @@ def print_active_timers(base): idx += 1 -def print_base(base): +def print_base(base, oldver): text = " .base: {}\n".format(base.address) text += " .index: {}\n".format(base['index']) @@ -62,21 +69,20 @@ def print_base(base): 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)]) + text += "".join([x for x in print_active_timers(base, oldver)]) return text -def print_cpu(hrtimer_bases, cpu, max_clock_bases): +def print_cpu(hrtimer_bases, cpu, max_clock_bases, oldver): 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) text = "cpu: {}\n".format(cpu) - for i in xrange(max_clock_bases): + for i in range(max_clock_bases): text += " clock {}:\n".format(i) - text += print_base(cpu_base['clock_base'][i]) - + text += print_base(cpu_base['clock_base'][i], oldver) if constants.LX_CONFIG_HIGH_RES_TIMERS: fmts = [(" .{} : {} nsecs", 'expires_next'), (" .{} : {}", 'hres_active'), @@ -165,7 +171,7 @@ def pr_cpumask(mask): i -= 1 start = i * 2 end = start + 2 - chunks.append(buf[start:end]) + chunks.append(str(buf[start:end])) if i != 0 and i % 4 == 0: chunks.append(',') @@ -184,14 +190,21 @@ class LxTimerList(gdb.Command): def invoke(self, arg, from_tty): hrtimer_bases = gdb.parse_and_eval("&hrtimer_bases") - max_clock_bases = gdb.parse_and_eval("HRTIMER_MAX_CLOCK_BASES") - - text = "Timer List Version: gdb scripts\n" + max_clock_bases = gdb.parse_and_eval("(int)HRTIMER_MAX_CLOCK_BASES") + banner = gdb.parse_and_eval("(char *)linux_banner").string() + r = re.match(r"^Linux version (.+) \(.*@.*$", banner) + if not r: + gdb.write("failed to load image version") + return + lver = r.group(1) + oldver = lver < '5.3.0-rc1' + + text = "Timer List Version: gdb scripts, old version: {}\n".format(oldver) text += "HRTIMER_MAX_CLOCK_BASES: {}\n".format(max_clock_bases) text += "now at {} nsecs\n".format(ktime_get()) for cpu in cpus.each_online_cpu(): - text += print_cpu(hrtimer_bases, cpu, max_clock_bases) + text += print_cpu(hrtimer_bases, cpu, max_clock_bases, oldver) if constants.LX_CONFIG_GENERIC_CLOCKEVENTS: if constants.LX_CONFIG_GENERIC_CLOCKEVENTS_BROADCAST: -- 2.17.1