Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp552126ybf; Fri, 28 Feb 2020 03:13:08 -0800 (PST) X-Google-Smtp-Source: APXvYqxNCexeS3pPMv9aQ0/0hYynDJsBJAHfExyEufbdnRm8urMNfBWsiKyRQjqtZQr+o8lGnEIC X-Received: by 2002:a9d:48d:: with SMTP id 13mr2664683otm.249.1582888388003; Fri, 28 Feb 2020 03:13:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582888387; cv=none; d=google.com; s=arc-20160816; b=VyK+w7DkHW6mcF0aA18hZfd9yuQYpK15rTcQ19aT41mvTS6cxk70tOEoMUzsYyvKah GKlrc/k4SW18lamJAKcHExIRYqhHmtRk+yBeNciNEUrmpjBPHNNLOwxAUwu5sUmEB4AK qoSMqhMhvgUxU/II+kfiVSku2LDDOJ+81Z89Jh5KemRShJaAUcCS81qP9hXOoO5QrDFM P/y2QHkcB3iYPwFgilbA7wg2cNY/P83g7RBZBJrI801wCXVusHA0MZttIHIoUbj5ca2T wdCIbrcY9JHrS01Zn2x3zHQp8Ej5/kqMvXRwI+PJ93zUJiHhPHoPkhn+Sr/crVmSLBl+ pb2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dmarc-filter :dkim-signature; bh=IVZ6CtP5L6xsu8bf6zRg6TkuiYbPIlAzMCNphwbcOsE=; b=dCjyb4tx3AsYdb8vMvs0Lu3a35pQURFrjaAVIMimBmXmwABdleNVUfNMwwR1vjhJqo zVLMDuagep0uyUX5ZeaDKxH3vQi8mFl5+atfE2iPB2n3HfoHrp8/rVkeesf7TMWt6HQp VyqXzrf5gEbiBGzupx/V/K4k1uoPze59Dgb+WgPtbcRK1t2GKoJJWNbtm5cAYr4WPgRO 7ffKQSXwg0SNH9hpt+F41mulcYQ0kvmuMxSIHIsJ+FqNWzRsQLY0XREYf0zehg/5lG97 CZ0chP0vdqAcBtyqQzI1w2UAI6ffVWCd2fih30F7+NALeTXshgmTiH1DUrdGtHO9UAsl vvQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=INb3PM54; 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 193si1704633oie.51.2020.02.28.03.12.55; Fri, 28 Feb 2020 03:13:07 -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=fail header.i=@mg.codeaurora.org header.s=smtp header.b=INb3PM54; 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 S1726871AbgB1LMn (ORCPT + 99 others); Fri, 28 Feb 2020 06:12:43 -0500 Received: from mail26.static.mailgun.info ([104.130.122.26]:10476 "EHLO mail26.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726700AbgB1LMm (ORCPT ); Fri, 28 Feb 2020 06:12:42 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1582888361; h=Content-Transfer-Encoding: Content-Type: In-Reply-To: MIME-Version: Date: Message-ID: From: References: Cc: To: Subject: Sender; bh=IVZ6CtP5L6xsu8bf6zRg6TkuiYbPIlAzMCNphwbcOsE=; b=INb3PM54afcSpsfAooNbpb+H7Oy6anOmEWuQAZmbqKXi3csORsuSAdvIvnWOa8r6OSr9nLMm 7+WOKh7xkVFbjx0H26inSWZmGBmmpGBWa5qOdB5OgHE+1Y90yzWxtBEl1ymurx9MqA46WhMQ H4vzlis65vCHgWk/xcWE7Nu7Jss= X-Mailgun-Sending-Ip: 104.130.122.26 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by mxa.mailgun.org with ESMTP id 5e58f5a8.7fabedcc6b58-smtp-out-n01; Fri, 28 Feb 2020 11:12:40 -0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 1CDDAC4479D; Fri, 28 Feb 2020 11:12:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=2.0 tests=ALL_TRUSTED,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.0 Received: from [10.206.13.37] (blr-c-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: mkshah) by smtp.codeaurora.org (Postfix) with ESMTPSA id 38AE7C43383; Fri, 28 Feb 2020 11:12:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 38AE7C43383 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=mkshah@codeaurora.org Subject: Re: [PATCH v8 2/3] soc: qcom: rpmh: Update dirty flag only when data changes To: Evan Green Cc: Stephen Boyd , Matthias Kaehlcke , Bjorn Andersson , LKML , linux-arm-msm , Andy Gross , Doug Anderson , Rajendra Nayak , Lina Iyer , lsrao@codeaurora.org References: <1582793785-22423-1-git-send-email-mkshah@codeaurora.org> <1582793785-22423-3-git-send-email-mkshah@codeaurora.org> From: Maulik Shah Message-ID: <9120b876-d7bb-7e74-f1e4-0ff6f2c6c939@codeaurora.org> Date: Fri, 28 Feb 2020 16:42:32 +0530 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/27/2020 11:48 PM, Evan Green wrote: > On Thu, Feb 27, 2020 at 12:57 AM Maulik Shah wrote: >> Currently rpmh ctrlr dirty flag is set for all cases regardless of data >> is really changed or not. Add changes to update dirty flag when data is >> changed to newer values. >> >> Also move dirty flag updates to happen from within cache_lock and remove >> unnecessary INIT_LIST_HEAD() call and a default case from switch. >> >> Fixes: 600513dfeef3 ("drivers: qcom: rpmh: cache sleep/wake state requests") >> Signed-off-by: Maulik Shah >> Reviewed-by: Srinivas Rao L >> --- >> drivers/soc/qcom/rpmh.c | 29 ++++++++++++++++------------- >> 1 file changed, 16 insertions(+), 13 deletions(-) >> >> diff --git a/drivers/soc/qcom/rpmh.c b/drivers/soc/qcom/rpmh.c >> index eb0ded0..3f5d9eb 100644 >> --- a/drivers/soc/qcom/rpmh.c >> +++ b/drivers/soc/qcom/rpmh.c >> @@ -133,26 +133,30 @@ static struct cache_req *cache_rpm_request(struct rpmh_ctrlr *ctrlr, >> >> req->addr = cmd->addr; >> req->sleep_val = req->wake_val = UINT_MAX; >> - INIT_LIST_HEAD(&req->list); > Thanks! > >> list_add_tail(&req->list, &ctrlr->cache); >> >> existing: >> switch (state) { >> case RPMH_ACTIVE_ONLY_STATE: >> - if (req->sleep_val != UINT_MAX) >> + if (req->sleep_val != UINT_MAX) { >> req->wake_val = cmd->data; >> + ctrlr->dirty = true; >> + } >> break; >> case RPMH_WAKE_ONLY_STATE: >> - req->wake_val = cmd->data; >> + if (req->wake_val != cmd->data) { >> + req->wake_val = cmd->data; >> + ctrlr->dirty = true; >> + } >> break; >> case RPMH_SLEEP_STATE: >> - req->sleep_val = cmd->data; >> - break; >> - default: >> + if (req->sleep_val != cmd->data) { >> + req->sleep_val = cmd->data; >> + ctrlr->dirty = true; >> + } >> break; >> } >> >> - ctrlr->dirty = true; >> unlock: >> spin_unlock_irqrestore(&ctrlr->cache_lock, flags); >> >> @@ -287,6 +291,7 @@ static void cache_batch(struct rpmh_ctrlr *ctrlr, struct batch_cache_req *req) >> >> spin_lock_irqsave(&ctrlr->cache_lock, flags); >> list_add_tail(&req->list, &ctrlr->batch_cache); >> + ctrlr->dirty = true; >> spin_unlock_irqrestore(&ctrlr->cache_lock, flags); >> } >> >> @@ -323,6 +328,7 @@ static void invalidate_batch(struct rpmh_ctrlr *ctrlr) >> list_for_each_entry_safe(req, tmp, &ctrlr->batch_cache, list) >> kfree(req); >> INIT_LIST_HEAD(&ctrlr->batch_cache); >> + ctrlr->dirty = true; >> spin_unlock_irqrestore(&ctrlr->cache_lock, flags); >> } >> >> @@ -456,13 +462,9 @@ static int send_single(struct rpmh_ctrlr *ctrlr, enum rpmh_state state, >> int rpmh_flush(struct rpmh_ctrlr *ctrlr) >> { >> struct cache_req *p; >> + unsigned long flags; >> int ret; >> >> - if (!ctrlr->dirty) { >> - pr_debug("Skipping flush, TCS has latest data.\n"); >> - return 0; >> - } >> - >> /* First flush the cached batch requests */ >> ret = flush_batch(ctrlr); >> if (ret) >> @@ -488,7 +490,9 @@ int rpmh_flush(struct rpmh_ctrlr *ctrlr) >> return ret; >> } >> >> + spin_lock_irqsave(&ctrlr->cache_lock, flags); >> ctrlr->dirty = false; >> + spin_unlock_irqrestore(&ctrlr->cache_lock, flags); > You're acquiring a lock around an operation that's already inherently > atomic, which is not right. If the comment earlier in this function is > still correct that "Nobody else should be calling this function other > than system PM, hence we can run without locks", then you can simply > remove this hunk and the part moving ->dirty = true into > invalidate_batch. > > However, if rpmh_flush() can now be called in a scenario where > pre-emption is enabled or multiple cores are alive, then ctrlr->cache > is no longer adequately protected. You'd need to add a lock > acquire/release around the list iteration above, and fix up the > comment. > -Evan Hi Evan, Right, rpmh_flush() now can be called from any cpu. i will remove comments from above. part for rpmh_flush(),  flush_batch()  and ctrlr->dirty update was already covered within cache lock, however its needed to protect entire rpmh_flush() in cache_lock now. updates in v9. Thanks, Maulik -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation