Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2202643yba; Mon, 6 May 2019 01:23:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqycVQVjB+/jnUsgYl1JEMzQ0hpsoaMtEo60+zzkUnTQUlFkqTfYwIRSZfDlPsv7lG6jmhN7 X-Received: by 2002:a65:644e:: with SMTP id s14mr31160994pgv.290.1557131038477; Mon, 06 May 2019 01:23:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557131038; cv=none; d=google.com; s=arc-20160816; b=JobQSLlKxAtNr3GPHIcOjK6QjxErgj0yMvdYg2uSIJpAnx6t7I0sbQuf/VRRw9F14D +iJsyH0clro/wESFvQrpfiKrSGM69iMN5hH1We9kka39dPCf0xy50sVcsZuMGNczA7sK tUb90hvk2asoCFIqyjylIvcD7iw4+fkaRMSEI35OcNmYR14C5MggAGoTP5vqF8zHVuq4 EwtLHTNse0U3VED3c91429Cg0sL/bdm6dS3R61z6gB21lc1o1HZOjZ2gw5o64DMXh+eJ YU8m+Qtk9INwrmrLEdxBZSbKOOuK9Zx7Sz2AU7D35n5ACaMScO+DHWXqShLPKnID6W0L m0iA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8oVvJ9mj35Lp12Pvnx1rYrM9wXOWQruIs8G8w3waPxY=; b=vL6xeCMOVgg+spKa88oMvZSZwkVuEhgQX9TsrwonRH9ufiaOrzhs/d8dZvE/3z/K1q +nS+cF6cosZTeAirKLZddCUpBXPzVTNpU5yMox1GG3iFhZyYYfECmM6BYNCH5NoKu2Z6 HGykgP++4F+PxrqGPiOzhwoIodv4bLSJxzQefbO9/5UhEGFPv05Bz9LWyf88mj+RwPHf q+hOK4Dx7P3S1kq1uvMAp1IYaXY2IEvyjMPMw/f6KBEj/CeXFexsgJV+wRWyiDg88IK0 ReInOACgQxEE4La/zYU12jzj/vO45n4x0xBeGoTT6V+HrW7jmrhiuCTEyUPkzm6bOtwJ Ltsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Hv00WVo5; 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 e7si14204929pfc.152.2019.05.06.01.23.43; Mon, 06 May 2019 01:23:58 -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=Hv00WVo5; 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 S1726560AbfEFIU3 (ORCPT + 99 others); Mon, 6 May 2019 04:20:29 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:44636 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726520AbfEFIU2 (ORCPT ); Mon, 6 May 2019 04:20:28 -0400 Received: by mail-pg1-f195.google.com with SMTP id z16so6081048pgv.11 for ; Mon, 06 May 2019 01:20:27 -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 :mime-version:content-transfer-encoding; bh=8oVvJ9mj35Lp12Pvnx1rYrM9wXOWQruIs8G8w3waPxY=; b=Hv00WVo5hgfQYhK/g33jV6jD7uZtD18fCtp+V11I//o27F4G8pmpRuSwdCRafyPyfB 1MU7A0CyOcwqTjHClv/SFN4ufVwl6aBkI5MTpN1NYpQcvxWxhMRJZ1oPz3G13M8cW/Ji vUZjnqVk7fEuuDLl2DDs1chBHRoh8VcuIes3CI/RFayxbjxEkg4x3O0+8GLxcq5P00Z8 SWdfy0R+j87dkZ1m8F8OyL/u58D0NfJ0DDz2x73RZNUO9bPfr2s2qv0oSCBbh+Yb2efT +l1rEWiXqVOlReGOh5LmOW3iJQHJPGJ8MphZv/LO2b42oijB4puz0duKNSLEXOtVkVCS EXGQ== 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:mime-version:content-transfer-encoding; bh=8oVvJ9mj35Lp12Pvnx1rYrM9wXOWQruIs8G8w3waPxY=; b=UuH6qKsZiEgoPSh9rml4KymPgfczHPk0INflsxaqPPPwffFgQEBxTYwUwHEOVXZ+63 DoW64rdb/jLIIqoPufeZHFpIHTser6TgEHlIw3JEjEAv0oIDHFe3ULzcLejUDfdB9nuN JtWbOeRJsW0YIAv7TsjOwoUFOVI350fhEOK6tWxsW1Q307M9XZfRSBaaktl1x8eMbtz4 uvf1D/wmaFiVQE/gr/5hh7sQzAnFm6vwGNBcIIt2w0pea6WkzXkzG9eFUup5JMiQXdmI hlnoYOGk0rWCTJ79bTN3VS891J2aCa0O95TjU/t/CyqfwNml+fxtLfIatIzX8XreXwzZ 47gg== X-Gm-Message-State: APjAAAWV7VbnDuLrXrqys0QcNnKvNSQw1jM6Ds8WIotEkmFluw1FyZG3 lNQ5oZQ8Whejbrqs+bH6GeY= X-Received: by 2002:a62:4602:: with SMTP id t2mr31626278pfa.26.1557130827633; Mon, 06 May 2019 01:20:27 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id v19sm20958013pfa.138.2019.05.06.01.20.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 01:20:27 -0700 (PDT) From: Yuyang Du To: peterz@infradead.org, will.deacon@arm.com, mingo@kernel.org Cc: bvanassche@acm.org, ming.lei@redhat.com, frederic@kernel.org, tglx@linutronix.de, linux-kernel@vger.kernel.org, Yuyang Du Subject: [PATCH v2 12/23] locking/lockdep: Change type of the element field in circular_queue Date: Mon, 6 May 2019 16:19:28 +0800 Message-Id: <20190506081939.74287-13-duyuyang@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: <20190506081939.74287-1-duyuyang@gmail.com> References: <20190506081939.74287-1-duyuyang@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The element field is an array in struct circular_queue to keep track of locks in the search. Making it the same type as the locks avoids type cast. Also fix a typo and elaborate the comment above struct circular_queue. No functional change. Reviewed-by: Bart Van Assche Signed-off-by: Yuyang Du --- kernel/locking/lockdep.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index b8e6ba3..eb8b190 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -1257,13 +1257,17 @@ static int add_lock_to_list(struct lock_class *this, #define CQ_MASK (MAX_CIRCULAR_QUEUE_SIZE-1) /* - * The circular_queue and helpers is used to implement the - * breadth-first search(BFS)algorithem, by which we can build - * the shortest path from the next lock to be acquired to the - * previous held lock if there is a circular between them. + * The circular_queue and helpers are used to implement graph + * breadth-first search (BFS) algorithm, by which we can determine + * whether there is a path from a lock to another. In deadlock checks, + * a path from the next lock to be acquired to a previous held lock + * indicates that adding the -> lock dependency will + * produce a circle in the graph. Breadth-first search instead of + * depth-first search is used in order to find the shortest (circular) + * path. */ struct circular_queue { - unsigned long element[MAX_CIRCULAR_QUEUE_SIZE]; + struct lock_list *element[MAX_CIRCULAR_QUEUE_SIZE]; unsigned int front, rear; }; @@ -1289,7 +1293,7 @@ static inline int __cq_full(struct circular_queue *cq) return ((cq->rear + 1) & CQ_MASK) == cq->front; } -static inline int __cq_enqueue(struct circular_queue *cq, unsigned long elem) +static inline int __cq_enqueue(struct circular_queue *cq, struct lock_list *elem) { if (__cq_full(cq)) return -1; @@ -1299,7 +1303,7 @@ static inline int __cq_enqueue(struct circular_queue *cq, unsigned long elem) return 0; } -static inline int __cq_dequeue(struct circular_queue *cq, unsigned long *elem) +static inline int __cq_dequeue(struct circular_queue *cq, struct lock_list **elem) { if (__cq_empty(cq)) return -1; @@ -1377,12 +1381,12 @@ static int __bfs(struct lock_list *source_entry, goto exit; __cq_init(cq); - __cq_enqueue(cq, (unsigned long)source_entry); + __cq_enqueue(cq, source_entry); while (!__cq_empty(cq)) { struct lock_list *lock; - __cq_dequeue(cq, (unsigned long *)&lock); + __cq_dequeue(cq, &lock); if (!lock->class) { ret = -2; @@ -1406,7 +1410,7 @@ static int __bfs(struct lock_list *source_entry, goto exit; } - if (__cq_enqueue(cq, (unsigned long)entry)) { + if (__cq_enqueue(cq, entry)) { ret = -1; goto exit; } -- 1.8.3.1