From patchwork Mon Jan 9 03:33:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungchul Park X-Patchwork-Id: 13092907 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 784DAC5479D for ; Mon, 9 Jan 2023 03:34:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6E16490000A; Sun, 8 Jan 2023 22:34:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1624F90000E; Sun, 8 Jan 2023 22:34:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 63F8690000C; Sun, 8 Jan 2023 22:34:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 16A1390000D for ; Sun, 8 Jan 2023 22:33:58 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E9D94C032D for ; Mon, 9 Jan 2023 03:33:57 +0000 (UTC) X-FDA: 80333841714.15.8058E9F Received: from lgeamrelo11.lge.com (lgeamrelo13.lge.com [156.147.23.53]) by imf23.hostedemail.com (Postfix) with ESMTP id 464E7140006 for ; Mon, 9 Jan 2023 03:33:53 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf23.hostedemail.com: domain of byungchul.park@lge.com designates 156.147.23.53 as permitted sender) smtp.mailfrom=byungchul.park@lge.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673235235; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=kDM01mVUyG0nm+7fp4xhiYAPnxOIZAaDECTeapl5xbs=; b=EAZdqj2P8FW3wrArZ+TQTuZkhtGd9wgF5M9heuRalOVlmQjDP+tkFdKnV3nAI9WUUQV06z 4wl0+W+rKT1iuB8xpTGyrU4bIeZ4wjIkz++YXIPBTJjP5fYsB4aRXvBxuZfsLHGVcR53ET drtorK6MphKesEs/P2YojN9W6Ft4WEw= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf23.hostedemail.com: domain of byungchul.park@lge.com designates 156.147.23.53 as permitted sender) smtp.mailfrom=byungchul.park@lge.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673235235; a=rsa-sha256; cv=none; b=X1GU+Jby3d42COfOb6NWCeNElvdtnMuCGjNgStoVYBkWYtDZOxleYg4SncnufU36KB0nPR 6lckUuxsDiA9R5LL0wTc1JtmlTNCn8MfJARvkr0DoOiLsnjx2XjlUasRFdnY++jyb0Zri1 SGJVBVQGp/7EzPtUROzmOqw0EndJk5U= Received: from unknown (HELO lgemrelse6q.lge.com) (156.147.1.121) by 156.147.23.53 with ESMTP; 9 Jan 2023 12:33:52 +0900 X-Original-SENDERIP: 156.147.1.121 X-Original-MAILFROM: byungchul.park@lge.com Received: from unknown (HELO localhost.localdomain) (10.177.244.38) by 156.147.1.121 with ESMTP; 9 Jan 2023 12:33:52 +0900 X-Original-SENDERIP: 10.177.244.38 X-Original-MAILFROM: byungchul.park@lge.com From: Byungchul Park To: linux-kernel@vger.kernel.org Cc: torvalds@linux-foundation.org, damien.lemoal@opensource.wdc.com, linux-ide@vger.kernel.org, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, mingo@redhat.com, peterz@infradead.org, will@kernel.org, tglx@linutronix.de, rostedt@goodmis.org, joel@joelfernandes.org, sashal@kernel.org, daniel.vetter@ffwll.ch, duyuyang@gmail.com, johannes.berg@intel.com, tj@kernel.org, tytso@mit.edu, willy@infradead.org, david@fromorbit.com, amir73il@gmail.com, gregkh@linuxfoundation.org, kernel-team@lge.com, linux-mm@kvack.org, akpm@linux-foundation.org, mhocko@kernel.org, minchan@kernel.org, hannes@cmpxchg.org, vdavydov.dev@gmail.com, sj@kernel.org, jglisse@redhat.com, dennis@kernel.org, cl@linux.com, penberg@kernel.org, rientjes@google.com, vbabka@suse.cz, ngupta@vflare.org, linux-block@vger.kernel.org, paolo.valente@linaro.org, josef@toxicpanda.com, linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk, jack@suse.cz, jlayton@kernel.org, dan.j.williams@intel.com, hch@infradead.org, djwong@kernel.org, dri-devel@lists.freedesktop.org, rodrigosiqueiramelo@gmail.com, melissa.srw@gmail.com, hamohammed.sa@gmail.com, 42.hyeyoo@gmail.com, chris.p.wilson@intel.com, gwan-gyeong.mun@intel.com Subject: [PATCH RFC v7 04/23] dept: Add lock dependency tracker APIs Date: Mon, 9 Jan 2023 12:33:32 +0900 Message-Id: <1673235231-30302-5-git-send-email-byungchul.park@lge.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1673235231-30302-1-git-send-email-byungchul.park@lge.com> References: <1673235231-30302-1-git-send-email-byungchul.park@lge.com> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 464E7140006 X-Stat-Signature: fkmoq5hit3s1aj4wrsym4taofncpeg3z X-Rspam-User: X-HE-Tag: 1673235233-190282 X-HE-Meta: U2FsdGVkX1/Kcz8X7oOC2Od6ba1wn83OTjnAQAQbOpPur+CZ30DtfKvnjP+UnPewVqryKxLdIhFT1E0Vk7yVI0w6v1P3aqT89IlIt2gg782nWC/pPcaC/nAwtDIWNLsonO9EdIKYEU1/wH4v20sHirx1ydQTbZziI9OPx8x2udANzwdvJpN8VU26LOTfiiV6CEV/U7C+W105EOXqRRhkwkLOTLkO0hC5TNk6bUUbE52vfPvLGqUVfOHUjniGB0Vp4Bzq5a66XfmyqK0oOTwP33cNZlUGUBFdoXNDqjBecrvXExeCgmlbTLII+rCAEC1q936yhDrv326f3UupJiklpsvoiq3HAilIoVSD9dovEkgxpDhweNou1CXynb8BaJ5q8+Pk410xDL0UfJCWb8H9d7+H1Y6FqsPEbp+a8ZUMn0CKw4LJ+QDOxgHy/2pJh1HX0Uc8e1hSJta+sqRMCT4ILvwmAYGU8+SeU6cejL3OzQA2eK/Ia6QOZcLFSXODHIbD+xOC59rFMitpyX2H+y8NokWTISVU3iNum99UlzyuAYW9NYx2jEGyvMzgS8fJcZvePZTF0+Myb83bSJlVeOjO0UfQqIY3Rx24bA7wDx9fWR5YoUWoHkhqbe1koXNemL5w6/Lr53LIN8G6p6iZsJ7s3aN9cH7qG465ThhWVqSqGf31d+05eMrS7tYYoybsVjtFcHROEY6OCRAmqj6VlkhujdDn9kwE4L90n2Fa6XTi6tuAx2CF3HhPbfTH/LufICCchbaYFakFugkOapSedW1O76ESHJkb4uzuamQJgnHf2rLdR4HmN2VFJumyP5ywHL1QsBjpJtHSrXQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Wrapped the base APIs for easier annotation on typical lock. Signed-off-by: Byungchul Park --- include/linux/dept_ldt.h | 77 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 include/linux/dept_ldt.h diff --git a/include/linux/dept_ldt.h b/include/linux/dept_ldt.h new file mode 100644 index 00000000..b8c00bc --- /dev/null +++ b/include/linux/dept_ldt.h @@ -0,0 +1,77 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Lock Dependency Tracker + * + * Started by Byungchul Park : + * + * Copyright (c) 2020 LG Electronics, Inc., Byungchul Park + */ + +#ifndef __LINUX_DEPT_LDT_H +#define __LINUX_DEPT_LDT_H + +#include + +#ifdef CONFIG_DEPT +#define LDT_EVT_L 1UL +#define LDT_EVT_R 2UL +#define LDT_EVT_W 4UL +#define LDT_EVT_RW (LDT_EVT_R | LDT_EVT_W) +#define LDT_EVT_ALL (LDT_EVT_L | LDT_EVT_RW) + +#define ldt_init(m, k, su, n) dept_map_init(m, k, su, n) +#define ldt_lock(m, sl, t, n, i) \ + do { \ + if (n) \ + dept_ecxt_enter_nokeep(m); \ + else if (t) \ + dept_ecxt_enter(m, LDT_EVT_L, i, "trylock", "unlock", sl);\ + else { \ + dept_wait(m, LDT_EVT_L, i, "lock", sl); \ + dept_ecxt_enter(m, LDT_EVT_L, i, "lock", "unlock", sl);\ + } \ + } while (0) + +#define ldt_rlock(m, sl, t, n, i) \ + do { \ + if (n) \ + dept_ecxt_enter_nokeep(m); \ + else if (t) \ + dept_ecxt_enter(m, LDT_EVT_R, i, "read_trylock", "read_unlock", sl);\ + else { \ + dept_wait(m, LDT_EVT_W, i, "read_lock", sl); \ + dept_ecxt_enter(m, LDT_EVT_R, i, "read_lock", "read_unlock", sl);\ + } \ + } while (0) + +#define ldt_wlock(m, sl, t, n, i) \ + do { \ + if (n) \ + dept_ecxt_enter_nokeep(m); \ + else if (t) \ + dept_ecxt_enter(m, LDT_EVT_W, i, "write_trylock", "write_unlock", sl);\ + else { \ + dept_wait(m, LDT_EVT_RW, i, "write_lock", sl); \ + dept_ecxt_enter(m, LDT_EVT_W, i, "write_lock", "write_unlock", sl);\ + } \ + } while (0) + +#define ldt_unlock(m, i) dept_ecxt_exit(m, LDT_EVT_ALL, i) + +#define ldt_downgrade(m, i) \ + do { \ + if (dept_ecxt_holding(m, LDT_EVT_W)) \ + dept_map_ecxt_modify(m, LDT_EVT_W, NULL, LDT_EVT_R, i, "downgrade", "read_unlock", -1);\ + } while (0) + +#define ldt_set_class(m, n, k, sl, i) dept_map_ecxt_modify(m, LDT_EVT_ALL, k, 0UL, i, "lock_set_class", "(any)unlock", sl) +#else /* !CONFIG_DEPT */ +#define ldt_init(m, k, su, n) do { (void)(k); } while (0) +#define ldt_lock(m, sl, t, n, i) do { } while (0) +#define ldt_rlock(m, sl, t, n, i) do { } while (0) +#define ldt_wlock(m, sl, t, n, i) do { } while (0) +#define ldt_unlock(m, i) do { } while (0) +#define ldt_downgrade(m, i) do { } while (0) +#define ldt_set_class(m, n, k, sl, i) do { } while (0) +#endif +#endif /* __LINUX_DEPT_LDT_H */