Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9980119ybi; Wed, 24 Jul 2019 13:27:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqz3EsNWdUjBA34Bdy8MKVFgcv6WV0gmhFU87QcKFxhlDO71s4MwJg2ac6laDCAakfKyLvT8 X-Received: by 2002:a65:57ca:: with SMTP id q10mr85658580pgr.52.1564000060292; Wed, 24 Jul 2019 13:27:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564000060; cv=none; d=google.com; s=arc-20160816; b=0tKLcOUXEWi8u66JeZPm4MiTZy/F8i4MFgKpNLOHMCMdOsvQelksbvhCA5YDTyy6qn GGLv7iJUnS3u3Gw/zfel7qeXhdLDwyyODRp8Pi+S5MYb4qFHDbmqqXMdgssQr5ocNUqs OaAb58s8KFv3qTGHiVFaYJRwZnTFYPc8k6W+MaHO/IS4SUpBd8z1j+cbbhbhrAiy9Fq7 YRfSo2vLPJv4s+esfBQbeBfHZA5ao67O8Qx38iMsSAVkSgwHq4/6mKRG/y2iGF7F0EGn M0SuKDLiHp55tsbDtSN6FSPY7gLTVT0B5rYx2X89r0OQA05Ui88RPQU+Y4HgXwivuWXI 3+yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:user-agent:from:cc:to:subject :references:in-reply-to:content-transfer-encoding:mime-version :message-id:dkim-signature; bh=QFJC3GS7SLbhEX9yLYIlfgrpJlGsNCGKHcxux2RXL8U=; b=gC9NbpHEpFiGTVPxxSq5ebHKEgqnRTb7n0i5TBbjXdtfJFf2R5EYAfx+tB0Q5L45Dt 9H49BgW3ykqKOd7l9U2p2XrGxkQJuZu63mdsuR9B/1O/brHyQapWAGO7DzA1cUN/KtmZ TA0R5QZgnRaf6tCKBduKDrX3vy/8WY33gHd2xZCaVtiYCJKQTQfEY3QXcbW5MKlREAjI pc0VFjTj0wgcGMRZzo3AeDX7+Jy8kjrqx/D0Uq5FdD7ZoNk2R7BI6vrQz7j9eZpaMkm3 rwDKthIxRuhlMyvbLC+eBVSxm5zWrrzmMGN8YxFfvJtRkQs1ITR0euw+8Kcnb7fMQuRV T3bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dY9QfISi; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e90si14492342plb.309.2019.07.24.13.27.25; Wed, 24 Jul 2019 13:27:40 -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=@chromium.org header.s=google header.b=dY9QfISi; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390458AbfGXU0N (ORCPT + 99 others); Wed, 24 Jul 2019 16:26:13 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:34096 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389199AbfGXThv (ORCPT ); Wed, 24 Jul 2019 15:37:51 -0400 Received: by mail-pg1-f195.google.com with SMTP id n9so15492691pgc.1 for ; Wed, 24 Jul 2019 12:37:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=message-id:mime-version:content-transfer-encoding:in-reply-to :references:subject:to:cc:from:user-agent:date; bh=QFJC3GS7SLbhEX9yLYIlfgrpJlGsNCGKHcxux2RXL8U=; b=dY9QfISi0mzz6dT2+u7lTmTaFJqWVPPE2AvBBL37m53aXiWDaGr7kR9QlJVDHbRTEh ATjhVFJsyDmAuE96/iaGX2t7d72ebA+veCDxFMlM0aPo2qXoEmzBXOLigAUahjSr2IjC llI517jBkBnLLKkP+GfvnjFsKRltJ6WuuHp84= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:mime-version :content-transfer-encoding:in-reply-to:references:subject:to:cc:from :user-agent:date; bh=QFJC3GS7SLbhEX9yLYIlfgrpJlGsNCGKHcxux2RXL8U=; b=Ok+rJgDFuyRrzes+Y0sEo3KVHFm+vyN757KTuAhq12uOmBz0vH4GdyDxeBG9vR3VT9 EtHB8r1xFbdjN5IvWVyPxwcAENXmLinMp5K+sAnedAwrM1NzCV2v0xOmNRCJxhC6PIxc e73lbIVr7PkCrIfohXSaMwdbqciDpDXPnTAUf1cdxCPQDdWq6qYzeSMTOl6Q9nqocC7O LuTW7qndncCL0zzrKJq7Ln10om69uk8WfgfqTzYTUh43K2pMm04viyJHUBPa5tFPMq4O QCCH/VgPc9IDn/JJEMrKQ65bMEQGXeL6i1PTl+VYt1/IbB63GEHcI/NSC/AxmK0igZmG 264g== X-Gm-Message-State: APjAAAWHCJ51ct2YTyXOUiP2ohvGwAlux4QiXIcmDkxe7bBlrdCUYZ+V 8DLpKxUtg5cPPRPcPXHgC1XxiA== X-Received: by 2002:a65:52c5:: with SMTP id z5mr68804383pgp.118.1563997070692; Wed, 24 Jul 2019 12:37:50 -0700 (PDT) Received: from chromium.org ([2620:15c:202:1:fa53:7765:582b:82b9]) by smtp.gmail.com with ESMTPSA id 185sm47926192pfd.125.2019.07.24.12.37.50 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 24 Jul 2019 12:37:50 -0700 (PDT) Message-ID: <5d38b38e.1c69fb81.e8e5d.035b@mx.google.com> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: <20190724145251.GB18620@codeaurora.org> References: <20190722215340.3071-1-ilina@codeaurora.org> <20190722215340.3071-2-ilina@codeaurora.org> <5d3769df.1c69fb81.55d03.aa33@mx.google.com> <20190724145251.GB18620@codeaurora.org> Subject: Re: [PATCH V2 2/4] drivers: qcom: rpmh-rsc: avoid locking in the interrupt handler To: Lina Iyer Cc: agross@kernel.org, bjorn.andersson@linaro.org, linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org, rnayak@codeaurora.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, dianders@chromium.org, mkshah@codeaurora.org From: Stephen Boyd User-Agent: alot/0.8.1 Date: Wed, 24 Jul 2019 12:37:49 -0700 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Lina Iyer (2019-07-24 07:52:51) > On Tue, Jul 23 2019 at 14:11 -0600, Stephen Boyd wrote: > >Quoting Lina Iyer (2019-07-22 14:53:38) > >> Avoid locking in the interrupt context to improve latency. Since we > >> don't lock in the interrupt context, it is possible that we now could > >> race with the DRV_CONTROL register that writes the enable register and > >> cleared by the interrupt handler. For fire-n-forget requests, the > >> interrupt may be raised as soon as the TCS is triggered and the IRQ > >> handler may clear the enable bit before the DRV_CONTROL is read back. > >> > >> Use the non-sync variant when enabling the TCS register to avoid readi= ng > >> back a value that may been cleared because the interrupt handler ran > >> immediately after triggering the TCS. > >> > >> Signed-off-by: Lina Iyer > >> --- > > > >I have to read this patch carefully. The commit text isn't convincing me > >that it is actually safe to make this change. It mostly talks about the > >performance improvements and how we need to fix __tcs_trigger(), which > >is good, but I was hoping to be convinced that not grabbing the lock > >here is safe. > > > >How do we ensure that drv->tcs_in_use is cleared before we call > >tcs_write() and try to look for a free bit? Isn't it possible that we'll > >get into a situation where the bitmap is all used up but the hardware > >has just received an interrupt and is going to clear out a bit and then > >an rpmh write fails with -EBUSY? > > > If we have a situation where there are no available free bits, we retry > and that is part of the function. Since we have only 2 TCSes avaialble > to write to the hardware and there could be multiple requests coming in, > it is a very common situation. We try and acquire the drv->lock and if > there are free TCS available and if available mark them busy and send > our requests. If there are none available, we keep retrying. >=20 Ok. I wonder if we need some sort of barriers here too, like an smp_mb__after_atomic()? That way we can make sure that the write to clear the bit is seen by another CPU that could be spinning forever waiting for that bit to be cleared? Before this change the spinlock would be guaranteed to make these barriers for us, but now that doesn't seem to be the case. I really hope that this whole thing can be changed to be a mutex though, in which case we can use the bit_wait() API, etc. to put tasks to sleep while RPMh is processing things. =20