Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp745047imu; Tue, 20 Nov 2018 06:22:09 -0800 (PST) X-Google-Smtp-Source: AFSGD/UjHgSE9SvtJhsLJJVPxjKKBCh9meEen0r0jqIFF4RvFZOT2QEkJJsy7bsaPZ2gRzw+QrkC X-Received: by 2002:a63:9809:: with SMTP id q9mr2067616pgd.109.1542723729172; Tue, 20 Nov 2018 06:22:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542723729; cv=none; d=google.com; s=arc-20160816; b=WFCBQLKfh7cYd8c9YQ1k21BJjoO4GyDA/CZsu+9F8OKZFtFkAnQYHkovXQ65YsWw80 IWgbH5x5jKhf1Urm6fo7me17kbttZQRNE6E5PVtlLVGt8tyvfthYn5dqT/Zimx3r62fK c1CoLWk/sr61M9OW+IBs7mk5D/92eQOSJMKuLoT21DbjMLzl6lRPn/ODi83AzqkSibI2 V2Bf/a53700CmL8QxTLn0Gq9LfeMVgDlgGQ0Fae0Fy42vo7DSPOW09jIV2YBPeNkdkW8 eH3QWx3lNK05VstOLRoWmdZMZLJECNqa7BmKo5zwa8dinK1BRU2/81ACwsmb7gyuP4Rd 3t8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=Km60i1gkDgYK67fbQNKAPcAmmbEPmXyrDnSfgZsqAwg=; b=WXOH6VQrzVJc7c48dvn9nQkX8DVs4R+aAt4OeaboKh89c9BAEuZ2Io9FBtQqtYoaD2 LET1NmowB8b1wvSG5vI3K/hN/Xa5lNXFC1TpykkR7ZpsV971DPfzWcz3hiCC13YVehzp 08VjzFZNKt7ECv8TueBRJbKyGB5fVuuScmTotkZEs5vFYO11bZtDcdc6jOqLo+co/MZ+ sI4Q/24NVSS6lse2Diytbg8/9AQOEB7ghO9NGI8eE6aFzf3+LVNygLKIa/NQ6UU3ER4H ecoGWP23gnbhy0XFuBLUIOkP8U4R8iYU+JbQ9yMEkxNFsvXS4ta2Da2gLh0/zLeMzMnq wOqA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f4si25036686plf.364.2018.11.20.06.21.54; Tue, 20 Nov 2018 06:22:09 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729636AbeKUAuE (ORCPT + 99 others); Tue, 20 Nov 2018 19:50:04 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:41724 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726005AbeKUAuE (ORCPT ); Tue, 20 Nov 2018 19:50:04 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 276697643F042; Tue, 20 Nov 2018 22:20:39 +0800 (CST) Received: from localhost.localdomain (10.175.124.28) by smtp.huawei.com (10.3.19.204) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 20 Nov 2018 22:20:32 +0800 From: Gao Xiang To: Greg Kroah-Hartman , CC: LKML , , "Chao Yu" , Miao Xie , , Gao Xiang Subject: [PATCH 03/10] staging: erofs: atomic_cond_read_relaxed on ref-locked workgroup Date: Tue, 20 Nov 2018 22:34:18 +0800 Message-ID: <20181120143425.43637-4-gaoxiang25@huawei.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20181120143425.43637-1-gaoxiang25@huawei.com> References: <20181120143425.43637-1-gaoxiang25@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.124.28] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It's better to use atomic_cond_read_relaxed, which is implemented in hardware instructions to monitor a variable changes currently for ARM64, instead of open-coded busy waiting. Reviewed-by: Chao Yu Signed-off-by: Gao Xiang --- drivers/staging/erofs/internal.h | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/drivers/staging/erofs/internal.h b/drivers/staging/erofs/internal.h index 89dbd0888e53..eb80ba44d072 100644 --- a/drivers/staging/erofs/internal.h +++ b/drivers/staging/erofs/internal.h @@ -221,23 +221,29 @@ static inline void erofs_workgroup_unfreeze( preempt_enable(); } +#if defined(CONFIG_SMP) +static inline int erofs_wait_on_workgroup_freezed(struct erofs_workgroup *grp) +{ + return atomic_cond_read_relaxed(&grp->refcount, + VAL != EROFS_LOCKED_MAGIC); +} +#else +static inline int erofs_wait_on_workgroup_freezed(struct erofs_workgroup *grp) +{ + int v = atomic_read(&grp->refcount); + + /* workgroup is never freezed on uniprocessor systems */ + DBG_BUGON(v == EROFS_LOCKED_MAGIC); + return v; +} +#endif + static inline bool erofs_workgroup_get(struct erofs_workgroup *grp, int *ocnt) { - const int locked = (int)EROFS_LOCKED_MAGIC; int o; repeat: - o = atomic_read(&grp->refcount); - - /* spin if it is temporarily locked at the reclaim path */ - if (unlikely(o == locked)) { -#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK) - do - cpu_relax(); - while (atomic_read(&grp->refcount) == locked); -#endif - goto repeat; - } + o = erofs_wait_on_workgroup_freezed(grp); if (unlikely(o <= 0)) return -1; -- 2.14.4