Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp402655img; Tue, 26 Feb 2019 02:04:26 -0800 (PST) X-Google-Smtp-Source: AHgI3IbbUlGGhCXU/xMa5PTQRj+t/AN1d2EBO0adoU7/iTMeqvhcBcy/KQ2H+0EHlosIN6V4jQwW X-Received: by 2002:a63:d904:: with SMTP id r4mr23711574pgg.207.1551175466754; Tue, 26 Feb 2019 02:04:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551175466; cv=none; d=google.com; s=arc-20160816; b=qiFyaFCN8BJ6on43lGgFYZoOfGkerE4FmBHEsg1arpPxRXrohNcjoyZFImsWX+IKGX fbgo/0dTlm8idpaAujp6P0WCpJVrdLwhu6gjpwFex5SRp6vSmaEjQ+jZT9Iy2WjU/wAP UyfcaLoUIeadtZXNbBlCYODsAPkhS20WeNq7oa658qolDK3HcxHNW59upQompkD/j1Sc yzYcVhQqv+IRWrmeAhRUiSdSJs2BmX+oe6l/+Q4zfS6E9zUqjP5+pVldwj2uDZd0N/r8 FDIrazVNpVRzZZTGhcBsS2ZZQnSRGmnS5CHMGoAdMcAvzj1MeusM7YymtdXoi5BDG+cE nZoA== 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=iKgSR3pgBbxBFbm4Ql4W6QsvFtlkjW+qw2rlTVlUse8=; b=N2NhXALCBUyE3OREJo/bqz1WFFaX98haQaiPcBp2Xe3lKjDiSofpMBzICoH/fVuMGb sE6AJQGOV4qF1kDPo2Dhprwzix1U5iLhgnL5CNU928oNsN4yGjtgznm2GGT8BAued0I8 tfu+G0SWTTcaWSL8Z4VPTk34BPdF1fLc2DAW5XxW2m25hnJbmcTRGHTz9MKWnyzeeK9k AZtIFxRhe0qXq7NTgP9c27E4nIxOel1/RxdawROWr+07Wtt9As+RoyG46+InWzpnVuMm 2O4dFCDJY6HFAknvcpyok3Q8o9nDBWOhEUJZ9/JSZ9cPzz9YpzBg34z/MCOmkyFN/5td wyfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=XNerrDyo; 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 a89si12228809pla.362.2019.02.26.02.04.11; Tue, 26 Feb 2019 02:04:26 -0800 (PST) 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=XNerrDyo; 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 S1728025AbfBZKDq (ORCPT + 99 others); Tue, 26 Feb 2019 05:03:46 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:43457 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727813AbfBZKDo (ORCPT ); Tue, 26 Feb 2019 05:03:44 -0500 Received: by mail-pl1-f194.google.com with SMTP id m10so5987216plt.10 for ; Tue, 26 Feb 2019 02:03:44 -0800 (PST) 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=iKgSR3pgBbxBFbm4Ql4W6QsvFtlkjW+qw2rlTVlUse8=; b=XNerrDyomy7JLG77HEmJHx9s0r0RH/KfGNiMdgDGtkHfd5/6/F46oEVdSK1Stlpk0F IhkXp6d/2g47nyAxMDyw2kqLUCZFjbPUYaXgU0aglwHnDAGoGsY/zLVToZxkK0z+25zg g9MbZLN6z66bbPWty+afg1eiEM8l14mnX+haIomj2SYD9OyoScDZK/6frlpMOPeh/bLQ GTspI4byHD7ZyVULgyckoxs/qBE8ItyV4Mjl7VT9tYE3F1dkhS+YRjcy0+8foV0UntqT kiVnlKshIdd1LCPHGI9tcN6Bu4CJcclyyTqKwBcedLEVuRAXf8D11hzjT98kaAVYaq0/ c20Q== 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=iKgSR3pgBbxBFbm4Ql4W6QsvFtlkjW+qw2rlTVlUse8=; b=RKJj2NQG3SPd6iq6twrqww4NCo0GPrNN9jgvLb1DftQ6IfHQ6k5yiHBjRsiLfbEEUE /xDMo7xC9UzlzIK7WrprYP82R3xYADSDGc1TC/9Kap5cTqIbNXDeCvI1OFK8w3pAK3MS MOiU7OMsTBCyNzoNPr+aYaJLdZAt8T2kVefRxKtzIdy/RTdW2bUKfFIdatxtERUE1QMz HYDiK/NZlTadTjWwJYg+k5PcbaLNiOpp++xZaT83cU5k326HcjTclt4WZK/LnoybUwP8 ETZs7dU8IPRiIRIzQ0zrDAF7XNlO5i68U7PY8z8k35q2ZWcnM1lR6g1dK6UpsNcl4OEA SvYA== X-Gm-Message-State: AHQUAuYcvGKwoO65jqDE5WkoiyNdiK7CwPrKF33lmGN2juEtCzrP7rVl dg9B965UTOzIgIxN+TCXsZc7qefu1Ts= X-Received: by 2002:a17:902:7782:: with SMTP id o2mr25616885pll.315.1551175423846; Tue, 26 Feb 2019 02:03:43 -0800 (PST) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id y6sm12045520pfy.87.2019.02.26.02.03.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Feb 2019 02:03:43 -0800 (PST) From: Yuyang Du To: peterz@infradead.org, mingo@kernel.org Cc: linux-kernel@vger.kernel.org, Yuyang Du Subject: [PATCH 3/8] locking/lockdep: Adjust lock usage bit character checks Date: Tue, 26 Feb 2019 18:03:22 +0800 Message-Id: <20190226100327.19340-4-duyuyang@gmail.com> X-Mailer: git-send-email 2.17.2 (Apple Git-113) In-Reply-To: <20190226100327.19340-1-duyuyang@gmail.com> References: <20190226100327.19340-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 more clear. 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 41eab3d..8b8495e 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -471,15 +471,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 2ebb9d0..2815e85 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