Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp4432596pxv; Tue, 29 Jun 2021 07:01:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQUGgrcdr8e/lbY0AhguXW2NMNTCSUWq+wTL5DTtbt/NEenze1gxaCz7X9qUdMLLGFucNN X-Received: by 2002:a05:6402:16:: with SMTP id d22mr14784453edu.101.1624975262163; Tue, 29 Jun 2021 07:01:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624975262; cv=none; d=google.com; s=arc-20160816; b=ZMbruniQDD6/WL7I8D0LI7J+fGNOG0KsW6Bj6R5bB1PJwvLmldAJN9ir+tPho3qDN5 tNSc0rSyxgzy1glrQFsDZ16/6/7YbmOqUOtjT+O1kzgbE5V0MSCJrzyW+8zIroAASrgU EtHnl0UoImtB/WRAxov3doTlkTRXmosRglm5qHlo8Hy52lEY9h+IcDzHuuz5PhjgXrTB t1wlmw3FgpmaVBXjkr9O163pGdrRc/KgRujpQ1b17CfS3dNQ3Ya4Kw+JjX0NGnBmHG87 ApS2Zf26cGIbIZxgmqr5gPscRP1tSIuRIFd5ASTG8l60YwDV8jZjidSx6TOXXmhQyDks f8HQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=U8jC3Z4NOxymfl0o3wyubDPnPgL2VYYqJT5yEYjtwkc=; b=YDDG7EE4W5SUdB0e20LxpzifvePmYTk1SePMV7rH6weeIdB8xv7yWPjloer1uikSdK fMEhXzGlojL/0kLpqkjk0s4oeh1ExLbsAdDlfZw0oDkUcPK7YiU6G5z/zPRiCeaFugNj T0XCceLq48MgMdA9+x/JN082fnIJ4K2O56lyIo0x4OFPM67I9GGIUjaY2x/jX3DyV7Pz Jr+dgSadjrjPzhXEwArq8C+Ya3m//B/J2+xQbZcvS/XbJBU905Z2NJAXClRvNiPEXpuJ DGyT08O8tYeaA+/yuHfAiJCY3CCa1oNOe3L01R7lPnK8W8l0r8n//K3DHX4gymXVE2xM Mf2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@me.com header.s=1a1hai header.b=qdme7DUM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=me.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c16si18322192edw.152.2021.06.29.07.00.38; Tue, 29 Jun 2021 07:01:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@me.com header.s=1a1hai header.b=qdme7DUM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=me.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234248AbhF2OB7 (ORCPT + 99 others); Tue, 29 Jun 2021 10:01:59 -0400 Received: from pv50p00im-tydg10011801.me.com ([17.58.6.52]:51581 "EHLO pv50p00im-tydg10011801.me.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233478AbhF2OB5 (ORCPT ); Tue, 29 Jun 2021 10:01:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=1a1hai; t=1624975170; bh=U8jC3Z4NOxymfl0o3wyubDPnPgL2VYYqJT5yEYjtwkc=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=qdme7DUMDA1fziS5X2m0XVyDx3vCy0QJ6qaR4I2Xu/g9mb7rQMN5gMaCfK57Lyy+J NwliffLl/veLsYy6t6ka4Uqy5D4H3H57iry6UoHft7YLPMELnxeJ5dlHceXCXQ2+Kl YMolxuO63Y0TweJYAAOMdAF0URpLVRQ1BQlslYEckQY157NoAQwzKkRj33dW3GSjhI W50bhDT40LF7wR1nXOEbnFBxMowPvFy/4iNcN/T3NQpl3CKUR3hdMQgP26iSqX69u6 HoOrouQTCHuCfvHlyqID3wZPEOjiQfihAsXtLn3DaBxY0juzvq5KCTcT46Ndj9sxes 6W5zEUMBP4ObA== Received: from xiongwei.. (unknown [120.245.2.115]) by pv50p00im-tydg10011801.me.com (Postfix) with ESMTPSA id 56254660161; Tue, 29 Jun 2021 13:59:27 +0000 (UTC) From: Xiongwei Song To: peterz@infradead.org, mingo@redhat.com, will@kernel.org, longman@redhat.com, boqun.feng@gmail.com Cc: linux-kernel@vger.kernel.org, Xiongwei Song Subject: [PATCH v3] locking/lockdep: Fix meaningless usages output of lock classes Date: Tue, 29 Jun 2021 21:59:16 +0800 Message-Id: <20210629135916.308210-1-sxwjean@me.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-06-29_06:2021-06-28,2021-06-29 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-2009150000 definitions=main-2106290095 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xiongwei Song When enabling CONFIG_LOCK_STAT, then CONFIG_LOCKDEP is forcedly enabled. We can get output from /proc/lockdep, which currently includes usages of lock classes. But the usages are meaningless, see the output below: / # cat /proc/lockdep all lock classes: ffffffff9af63350 ....: cgroup_mutex ffffffff9af54eb8 ....: (console_sem).lock ffffffff9af54e60 ....: console_lock ffffffff9ae74c38 ....: console_owner_lock ffffffff9ae74c80 ....: console_owner ffffffff9ae66e60 ....: cpu_hotplug_lock Only one usage context for each lock, this is because each usage is only changed in mark_lock() that is in CONFIG_PROVE_LOCKING defined section, however in the test situation, it's not. The fix is to move the usages reading and seq_print from CONFIG_PROVE_LOCKING undefined setcion to its defined section. Also, locks_after list of lock_class is empty when CONFIG_PROVE_LOCKING undefined, so do the same thing as what have done for usages of lock classes. With this patch with CONFIG_PROVE_LOCKING undefined, we can get the results below: / # cat /proc/lockdep all lock classes: ffffffff85163290: cgroup_mutex ffffffff85154dd8: (console_sem).lock ffffffff85154d80: console_lock ffffffff85074b58: console_owner_lock ffffffff85074ba0: console_owner ffffffff85066d60: cpu_hotplug_lock a class key and the relevant class name each line. Signed-off-by: Xiongwei Song --- v3: Improve commit log. Thank Longman very much for the comments. v2: https://lkml.org/lkml/2021/6/28/1549 --- kernel/locking/lockdep_proc.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c index 806978314496..b8d9a050c337 100644 --- a/kernel/locking/lockdep_proc.c +++ b/kernel/locking/lockdep_proc.c @@ -70,26 +70,28 @@ static int l_show(struct seq_file *m, void *v) #ifdef CONFIG_DEBUG_LOCKDEP seq_printf(m, " OPS:%8ld", debug_class_ops_read(class)); #endif -#ifdef CONFIG_PROVE_LOCKING - seq_printf(m, " FD:%5ld", lockdep_count_forward_deps(class)); - seq_printf(m, " BD:%5ld", lockdep_count_backward_deps(class)); -#endif + if (IS_ENABLED(CONFIG_PROVE_LOCKING)) { + seq_printf(m, " FD:%5ld", lockdep_count_forward_deps(class)); + seq_printf(m, " BD:%5ld", lockdep_count_backward_deps(class)); - get_usage_chars(class, usage); - seq_printf(m, " %s", usage); + get_usage_chars(class, usage); + seq_printf(m, " %s", usage); + } seq_printf(m, ": "); print_name(m, class); seq_puts(m, "\n"); - list_for_each_entry(entry, &class->locks_after, entry) { - if (entry->distance == 1) { - seq_printf(m, " -> [%p] ", entry->class->key); - print_name(m, entry->class); - seq_puts(m, "\n"); + if (IS_ENABLED(CONFIG_PROVE_LOCKING)) { + list_for_each_entry(entry, &class->locks_after, entry) { + if (entry->distance == 1) { + seq_printf(m, " -> [%p] ", entry->class->key); + print_name(m, entry->class); + seq_puts(m, "\n"); + } } + seq_puts(m, "\n"); } - seq_puts(m, "\n"); return 0; } -- 2.30.2