Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp241837img; Mon, 18 Mar 2019 02:01:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqwsf6ivUv2stWHiCnYoK6OFwHzWPnqTfczYkE4MY3pjKlIEnd1afDiYjc5DRlOOWO3Hnxxa X-Received: by 2002:a63:9752:: with SMTP id d18mr16946127pgo.0.1552899713942; Mon, 18 Mar 2019 02:01:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552899713; cv=none; d=google.com; s=arc-20160816; b=N8qdw7+PLkdbt894fAObECFhiBP4wBEFAQBz7Mj/LgyezFRMKksdPmEjTUSV/gw5bT kLbe+KQvlCq9G1YuUks0nlMV0kaq7JxqaNf+SEV4lQ+XqVKlIs8mbGuRJOZBTlTHwUES SqmIvVMkybVxxTkLBF7mlfoxqCC4FdZUbg430xLkAF12ToRDFoNgniHv/8taepEKi8Uo fDtebkmR5RX1Rk7GzXz3yz7gLKtBQMBfxCznCUlb8vHyfk0V8mc6rePotHh0rxfpY3QZ 5+M9TJd/JPKA8Qj9WZl4JPjgSSK0dCaMcKFnSUDWGyJtFGG6xIZZFN6V/ZR7ZADa4PyZ 6oTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=a28sVP+44q7iWCcjuw3hwp2P++bKgYYvw2MgXjP7Hz8=; b=uPsZbcTRz4l9xTy3lKx8zMralpec6wTc9jHIno/0mBFznQt1awhEV/CFeOoLo6y2wU 0s6o0jbKOupYEH1Iz5NshEGcS/TsFOWgnqFpyilbSDbr8WsRC2GARTn9beSkQrPivaBo DIo9Z7jNXv+C7fjNQBSBfNunOwWRBA9sZZzV4/WZvYL/8OGSQ33i+7zszQiKqCYHLV7d 2a2Qa054xtZMmGKbsPWJgr7UqVm+B+EFgy+PA2N3hwSX85ID4kBy54LsAtuiuKTg5gzC h1/BI25IvxnJ+r6M4RcZLPLMrRhcoHLI93ZW7dKto5W49PN7RtV1cDGQlHvHXrS4czpd 7KvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WALvay8T; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a5si1848236pln.225.2019.03.18.02.01.39; Mon, 18 Mar 2019 02:01:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WALvay8T; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727174AbfCRI5z (ORCPT + 99 others); Mon, 18 Mar 2019 04:57:55 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:42831 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727132AbfCRI5x (ORCPT ); Mon, 18 Mar 2019 04:57:53 -0400 Received: by mail-pg1-f195.google.com with SMTP id b2so10894430pgl.9 for ; Mon, 18 Mar 2019 01:57:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=a28sVP+44q7iWCcjuw3hwp2P++bKgYYvw2MgXjP7Hz8=; b=WALvay8TF29d6RStO9aJvOGN2gEAf/t1teJIDI5Cdg4+cW8zUg2wf2O4v1I51xezRp qEOEUNwjk76d+E4Hx4zbJtex8OYGxhq1+fC+IN5nvArrlD24ZrGaiMCTkWI1VkJNqPBW 7N7nBqxpG203906AM+NYbwsNKOh4CtXt2z7FH8nHXV51fluhr4kV8HV5D35x+/4mBj9A ECIBGf4lLQW3JrWQNbVVH7uFq2mQHYbaHYjj+9XVwbydQbfcnh7vObRf4hDnFOthY8m8 p6SG2VbWjOvoZ+AC/F2+ubyn80iAoy9GBijZULUuw/8pWc43zqDpc3CRblLB2dhXCAqG vl8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=a28sVP+44q7iWCcjuw3hwp2P++bKgYYvw2MgXjP7Hz8=; b=ZBH0MaVgdwkO/ckQJ1O9YHIq15VDIPNPWDJpDVxg+teTWWN26JfJ9jmWhGduOoJLh+ y4kYnGy/uf8zq2IcucEyAGzCK3QgE56N1sP74KIZ7Rsu4u2s5JPW9Mn5l5zNox9C5/Ts Og594mzHWh44QbV0itum2q+uqTFAH1+RJdXauXTfHnD7nAcW5mdv5ca4/Pv/uV5Ngilc VRqawcpp3GjSZuhMaTLsJmhWMXdwQQgFxp4Gei66MFBaEGkEnor1u62LON2mvC1rvlOb v4vCvgt5B2DllOX5pHExlXeoT1Hyz9Au9TEZLpeAoozFi1xjYsfdXdSVm2Y+iDpcL5Ru mi7A== X-Gm-Message-State: APjAAAXfl0uAnM7c/7ntX9gp6n5g7G8v2dWnhGtUmEXTviFqxJzuCDKV fc+Bmh5lVFRq2A1hgAdxZB0= X-Received: by 2002:a65:410a:: with SMTP id w10mr16289028pgp.206.1552899471948; Mon, 18 Mar 2019 01:57:51 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id k8sm11147024pgq.37.2019.03.18.01.57.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Mar 2019 01:57:51 -0700 (PDT) From: Yuyang Du To: peterz@infradead.org, will.deacon@arm.com, mingo@kernel.org Cc: bvanassche@acm.org, ming.lei@redhat.com, linux-kernel@vger.kernel.org, Yuyang Du Subject: [PATCH v2 03/19] locking/lockdep: Adjust lock usage bit character checks Date: Mon, 18 Mar 2019 16:57:17 +0800 Message-Id: <20190318085733.3143-4-duyuyang@gmail.com> X-Mailer: git-send-email 2.17.2 (Apple Git-113) In-Reply-To: <20190318085733.3143-1-duyuyang@gmail.com> References: <20190318085733.3143-1-duyuyang@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The lock usage bit characters are defined and determined with tricks. Use a macro and add some explanation to make it a bit clearer. Then adjust the logic to check the usage, which optimizes the code a bit. No functional change. Signed-off-by: Yuyang Du --- kernel/locking/lockdep.c | 21 ++++++++++++++++----- kernel/locking/lockdep_internals.h | 1 + 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 1c5e947..d5b66cf 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -514,15 +514,26 @@ static inline unsigned long lock_flag(enum lock_usage_bit bit) static char get_usage_char(struct lock_class *class, enum lock_usage_bit bit) { + /* + * The usage character defaults to '.' (i.e., irqs disabled and not in + * irq context), which is the safest usage category. + */ char c = '.'; - if (class->usage_mask & lock_flag(bit + 2)) + /* + * The order of the following usage checks matters, which will + * result in the outcome character as follows: + * + * - '+': irq is enabled and not in irq context + * - '-': in irq context and irq is disabled + * - '?': in irq context and irq is enabled + */ + if (class->usage_mask & lock_flag(bit + LOCK_USAGE_TO_ENABLED_STEP)) { c = '+'; - if (class->usage_mask & lock_flag(bit)) { - c = '-'; - if (class->usage_mask & lock_flag(bit + 2)) + if (class->usage_mask & lock_flag(bit)) c = '?'; - } + } else if (class->usage_mask & lock_flag(bit)) + c = '-'; return c; } diff --git a/kernel/locking/lockdep_internals.h b/kernel/locking/lockdep_internals.h index d4c1974..2fd31d5 100644 --- a/kernel/locking/lockdep_internals.h +++ b/kernel/locking/lockdep_internals.h @@ -25,6 +25,7 @@ enum lock_usage_bit { #define LOCK_USAGE_READ_MASK 1 #define LOCK_USAGE_DIR_MASK 2 #define LOCK_USAGE_STATE_MASK (~(LOCK_USAGE_READ_MASK | LOCK_USAGE_DIR_MASK)) +#define LOCK_USAGE_TO_ENABLED_STEP 2 /* * Usage-state bitmasks: -- 1.8.3.1