Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp4435989pxv; Tue, 29 Jun 2021 07:04:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzODVjTl8mueH75exSr0qLQR1xBCF9B4GLCqZO42jpKW+5eHxXegnEpxiS2jbJwXRlerOb X-Received: by 2002:a17:906:52d6:: with SMTP id w22mr30347872ejn.512.1624975460415; Tue, 29 Jun 2021 07:04:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624975460; cv=none; d=google.com; s=arc-20160816; b=MWwAwueiZdY3rL7N2R9Atrd+SIYseU9pvHMvPreO/a8H9dphJoE8lLxzVk55awew7b KAkSSXhlXiq87VVX6HuHXFq82bUyNt1iI+JHnSAgCU30vlaIYWGN8fgqlB66GnuM0MVw N8M2NWRcMKSfdmXCmZUfpz10RhfAQg+TTJ/3EMLu8lZ1xzrdzbaVd847aYE1Eo54e19y U+Bk4FLDGhFgysawVxRr5UlUsJ39e9NdqVbuD2QouIhw0WsOzuaBAn8y7J3ivpGccx7l N/HDcMbtodil7VYyInzLTwdOMTN2ErHiYfYhTLVRwsmxVYvVGSSFANdSCvnozP1otKH+ No0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:references:cc :to:subject:from:dkim-signature; bh=iA1uo0m3sRct3Ya71uX6YiW4SUGH49yF4PP2R0fN0DM=; b=Zl1wZHWa097rLKnjRVlNkRd7QESf56wzUquhdtEnNUY0W0r3WWZCP1Fxs5KIyP16fO 3FThvkDhVr3H8wCpAxnZiNgI4kYKSt/DRW4qVddshRBSfOcHk6D+awBXPAjQ6qv8Q8Ht 1F1gE+atjhZ7DuIinDm2EFfBkyC4jXGSz5LDNGOABXMry2n6EV49hqzY463N5pb3yU7R 0iF1TPlcB3ASImitRknEmtOqnYXHSHo4P5+C+yXY9zLzdWSQmOVQ27nExTAWazIV51fb zVEIqMdpRGq59JJbS3cvZZyDRqcIcFhiLN95U1p6NvrDaEgNqac1YzwiksnsI7a6SCvi NcFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QFXKsUxd; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b6si18470361edu.115.2021.06.29.07.03.52; Tue, 29 Jun 2021 07:04:20 -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=@redhat.com header.s=mimecast20190719 header.b=QFXKsUxd; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229933AbhF2OFD (ORCPT + 99 others); Tue, 29 Jun 2021 10:05:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:31883 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229705AbhF2OE7 (ORCPT ); Tue, 29 Jun 2021 10:04:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624975351; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iA1uo0m3sRct3Ya71uX6YiW4SUGH49yF4PP2R0fN0DM=; b=QFXKsUxdKTHmPgAqXqK2z80su8U9Fx/wRQzer2ngXZaXNAOdIJXINSTr72e5R9hjdprb2R S5+fAvQHFGdCzbz9DbfcLfvSdEqd/OSgl7mc5dApWmxP3f0W0MtWBNRDKoYy8fxe23aQjX cl0JPPV1dHlgxg6D6VbfFPlzdxE3pD0= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-354-AME1K1NcMpqQ4JOu7Wng8g-1; Tue, 29 Jun 2021 10:02:30 -0400 X-MC-Unique: AME1K1NcMpqQ4JOu7Wng8g-1 Received: by mail-qv1-f69.google.com with SMTP id m11-20020ad45dcb0000b029027aeaa8ae9dso20609301qvh.12 for ; Tue, 29 Jun 2021 07:02:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=iA1uo0m3sRct3Ya71uX6YiW4SUGH49yF4PP2R0fN0DM=; b=An2nTS9jAdJ8R0ViyueNYwK2XCtO5Rb+gzq1Lry5aMEnB2835s1NOBeXKtXtZyTzAG ioEDAl5QuvPS+GhDIvhLleBF95TxYDVQmhxB7jelefs4QJsdMv/eiVT37pUELjW96IiQ ct+R8PD2FqUBau9mFR4G7uidMn3qKjqdNTpZQYxvHesKdcIwBQBsJWg5wkf1pYAy3fNf sL5EysftsZxvePuHGlchAhCNgAFRsjRfdrODye4h/bze3MRXOti9ixbrlvPqkeDs3Qvv GwEk2eCpXVkHbcgx3T1AIY85T0U42n/J0SC/aKcCHCiAfjWnL96I991pD0dWhWDUlliw HG3Q== X-Gm-Message-State: AOAM530leebueegq1D+Xk8yrl9rxUEsI3ysA75esAKH2MMdEfN8sPsV3 CIYvgjKXLlCQIv3Rl12VoAy204o0mXkobRVMhWBd0IP4KwsMJoOj4KnmtQm+vkDKM47s6a5AUNa ST3Qo/R8Rz4VtuYgN+nKLY6NG X-Received: by 2002:a05:622a:1303:: with SMTP id v3mr26966770qtk.185.1624975348070; Tue, 29 Jun 2021 07:02:28 -0700 (PDT) X-Received: by 2002:a05:622a:1303:: with SMTP id v3mr26966616qtk.185.1624975346443; Tue, 29 Jun 2021 07:02:26 -0700 (PDT) Received: from llong.remote.csb ([2601:191:8500:76c0::cdbc]) by smtp.gmail.com with ESMTPSA id m189sm11926860qkd.107.2021.06.29.07.02.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 29 Jun 2021 07:02:25 -0700 (PDT) From: Waiman Long X-Google-Original-From: Waiman Long Subject: Re: [PATCH v3] locking/lockdep: Fix meaningless usages output of lock classes To: Xiongwei Song , peterz@infradead.org, mingo@redhat.com, will@kernel.org, boqun.feng@gmail.com Cc: linux-kernel@vger.kernel.org, Xiongwei Song References: <20210629135916.308210-1-sxwjean@me.com> Message-ID: <0894c552-41f1-a9dc-a319-67233c751a1f@redhat.com> Date: Tue, 29 Jun 2021 10:02:24 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: <20210629135916.308210-1-sxwjean@me.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/29/21 9:59 AM, Xiongwei Song wrote: > 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; > } Looks good to me. Acked-by: Waiman Long