Received: by 10.192.165.148 with SMTP id m20csp1211374imm; Fri, 27 Apr 2018 14:57:23 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpIAUsiBBKnH9wht+G6r4gKqbyYd7zFpylqIgAgVA8Xu26w5mkMj1mMVXbZILYkOli4Nteg X-Received: by 2002:a63:7341:: with SMTP id d1-v6mr3374520pgn.404.1524866243219; Fri, 27 Apr 2018 14:57:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524866243; cv=none; d=google.com; s=arc-20160816; b=Oi0t8LMrm3mFe1RGtvbKK45wECQtndLzVfTw7oeiefE4+7iBeP7cMdE0KAlkgpVMh7 yeB9iTM6w0rNprOPW3fWiJFM9nSF+/bl6M/o0Zir/trcZEjGzzSjPasgjAkIIb7yb6DB 44KOHnI4B1eUfJLNBWz1kozfucihPALNYpb69ci/zNQwqwky2afLB8J/Hj4YLcLmta3m ElLHce3YQPJTLVJcRMEJNOQKzwXifvwsJ7+la1+g/NLgKM8/OhNcT+kGWEXBAuREVDms dLUk99yfRfNhQy3VBJVBZUQo7aLUYFjQaEXqwrm3kcZVDAV9zdcFPWVGGIfkTomu+Zyq zMlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=lIowuokMZmZtHwIwr+9HEy55HhOKfTdzry0DHikLGfc=; b=KN4uHnLHtiapy1nQMwB9h+WH/QFjp5C/IGEAo1MWe98pGRHF9adC+v5NXkDtP3MKHC VJUkpn42NIowKbKLf11aeFYMQuvA92nDYPzBpcwqc/pS8HBZ2zD6YpKVr1nsDDE8Kvae c0tRefDqvUr0ADV7z9cB5R8mz0Uwk7kaPAmsl1wjIkxHuXseaC6k4YSaKjr6E9fU9l5K +oR0dV6UASnYKv/K8AtuW5c1w3Hoq9uTUMkPp4ijLyoSsXkoPLPES0B/U1u8OtiOKkIq H3zW8pBm12xoKtYqIzrtR59H3qidkufMEA2pbmjoA92h6JjNi13fa8TUSoABiKHV6mE6 8m/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=RNMBln2i; 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 c1-v6si2019498pld.510.2018.04.27.14.57.07; Fri, 27 Apr 2018 14:57:23 -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=RNMBln2i; 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 S1759349AbeD0Vyx (ORCPT + 99 others); Fri, 27 Apr 2018 17:54:53 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:41345 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759307AbeD0Vyv (ORCPT ); Fri, 27 Apr 2018 17:54:51 -0400 Received: by mail-pg0-f66.google.com with SMTP id m21-v6so2460364pgv.8 for ; Fri, 27 Apr 2018 14:54:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=lIowuokMZmZtHwIwr+9HEy55HhOKfTdzry0DHikLGfc=; b=RNMBln2ikjEd/9NHUhhqp65rheN5RfD20zt27OirxZ/5jlknj0N+qJnJZocmRIvOg2 G91diDILNgf0NiY6r1lcHX2KwEnRqdC37tTUYE0weolY3Tonr5VhpZiKgXlBR5ZBcWMQ Msj+LAPgRf+g7PCvtLnReGttHYilARwrI+0dw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=lIowuokMZmZtHwIwr+9HEy55HhOKfTdzry0DHikLGfc=; b=AQcLAkC1bWaf9vVLemybjLioI/J//ViGE2EItkygprC89WthxmopAcVXSzl2k1M5MG 2qAQc8btZkasF/tALrZ/pZwPHgNyiOIsbvQyBzgxvRbjJDWlrL4RBnvFyruUKk80vrOH rDyhTXyDjoZzH9j6C10bg6xbygcB6jpG1pE60qojd3Qhg7qBkqjbE/jIU9Fgw28jsA0A nDjJM2NlUjnySsTrxUIqut+A7WKhlB+sM5X49ne6EhwxERydSE+ppo7xDeoP4uFA+rXK 7E8+wOKZKvJsRSdo7cKDsFNK2XSPMBLmGrQxZ61BfOGoI6e/FQr21WDM/tkyo1XjjPwi cG/w== X-Gm-Message-State: ALQs6tA9kkfAdXKHh/0TT+CoeSbAek1VBYdkus4j/5uSAAnyWzE6ieVX qqvoYd0Z8IADkiVSa+SvdWl1BQ== X-Received: by 10.98.204.8 with SMTP id a8mr3582939pfg.219.1524866090495; Fri, 27 Apr 2018 14:54:50 -0700 (PDT) Received: from localhost ([2620:0:1000:1501:8e2d:4727:1211:622]) by smtp.gmail.com with ESMTPSA id t68-v6sm4048955pgc.62.2018.04.27.14.54.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 27 Apr 2018 14:54:49 -0700 (PDT) Date: Fri, 27 Apr 2018 14:54:49 -0700 From: Matthias Kaehlcke To: Lina Iyer Cc: andy.gross@linaro.org, david.brown@linaro.org, linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org, rnayak@codeaurora.org, bjorn.andersson@linaro.org, linux-kernel@vger.kernel.org, sboyd@kernel.org, evgreen@chromium.org, dianders@chromium.org Subject: Re: [PATCH v6 05/10] drivers: qcom: rpmh-rsc: write sleep/wake requests to TCS Message-ID: <20180427215449.GA133494@google.com> References: <20180419221635.17849-1-ilina@codeaurora.org> <20180419221635.17849-6-ilina@codeaurora.org> <20180425214111.GC243180@google.com> <20180427173943.GD6380@codeaurora.org> <20180427184017.GI243180@google.com> <20180427194559.GE6380@codeaurora.org> <20180427200605.GJ243180@google.com> <20180427213201.GA23157@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20180427213201.GA23157@codeaurora.org> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 27, 2018 at 03:32:01PM -0600, Lina Iyer wrote: > On Fri, Apr 27 2018 at 14:06 -0600, Matthias Kaehlcke wrote: > > On Fri, Apr 27, 2018 at 01:45:59PM -0600, Lina Iyer wrote: > > > On Fri, Apr 27 2018 at 12:40 -0600, Matthias Kaehlcke wrote: > > > > On Fri, Apr 27, 2018 at 11:39:43AM -0600, Lina Iyer wrote: > > > > > On Wed, Apr 25 2018 at 15:41 -0600, Matthias Kaehlcke wrote: > > > > > > On Thu, Apr 19, 2018 at 04:16:30PM -0600, Lina Iyer wrote: > > > > > > > Sleep and wake requests are sent when the application processor > > > > > > > subsystem of the SoC is entering deep sleep states like in suspend. > > > > > > > These requests help lower the system power requirements when the > > > > > > > resources are not in use. > > > > > > > > > > > > > > Sleep and wake requests are written to the TCS slots but are not > > > > > > > triggered at the time of writing. The TCS are triggered by the firmware > > > > > > > after the last of the CPUs has executed its WFI. Since these requests > > > > > > > may come in different batches of requests, it is the job of this > > > > > > > controller driver to find and arrange the requests into the available > > > > > > > TCSes. > > > > > > > > > > > > > > Signed-off-by: Lina Iyer > > > > > > > Reviewed-by: Evan Green > > > > > > > --- > > > > > > > drivers/soc/qcom/rpmh-internal.h | 8 +++ > > > > > > > drivers/soc/qcom/rpmh-rsc.c | 120 +++++++++++++++++++++++++++++++ > > > > > > > 2 files changed, 128 insertions(+) > > > > > > > > > > > > > > diff --git a/drivers/soc/qcom/rpmh-internal.h b/drivers/soc/qcom/rpmh-internal.h > > > > > > > index d9a21726e568..6e19fe458c31 100644 > > > > > > > --- a/drivers/soc/qcom/rpmh-internal.h > > > > > > > +++ b/drivers/soc/qcom/rpmh-internal.h > > > > > > > > > > > > > > > > > > > > > > > > > +static int find_match(const struct tcs_group *tcs, const struct tcs_cmd *cmd, > > > > > > > + int len) > > > > > > > +{ > > > > > > > + int i, j; > > > > > > > + > > > > > > > + /* Check for already cached commands */ > > > > > > > + for_each_set_bit(i, tcs->slots, MAX_TCS_SLOTS) { > > > > > > > + for (j = 0; j < len; j++) { > > > > > > > + if (tcs->cmd_cache[i] != cmd[0].addr) { > > > > > > > > > > > > Shouldn't the condition be 'tcs->cmd_cache[i + j] != cmd[j].addr'? > > > > > > > > > > > Here, we are trying to find the first address from the request and its > > > > > position 'i' in the cmd_cache. > > > > > > > > > > > Otherwise the code below the following if branch will never be > > > > > > executed. Either the 'tcs->cmd_cache[i] != cmd[0].addr' branch isn't > > > > > > entered because the addresses match, or the addresses don't match > > > > > > and the inner loop is aborted after the first iteration. > > > > > > > > > > > > > + if (j == 0) > > > > > > > + break; > > > > > > > + WARN(tcs->cmd_cache[i + j] != cmd[j].addr, > > > > > > > + "Message does not match previous sequence.\n"); > > > > > We now check for the sequence using the iterator 'j' only after we have > > > > > found 'i' (the beginning of our request). > > > > > > > > > > I hope that helps clear the concern. > > > > > > > > It doesn't, maybe I'm just confused, the driver has a certain > > > > complexity and I don't claim to have a comprehensive understanding :) > > > > > > > > If I understand correctly find_match() is used to find a sequence of > > > > commands of length 'len' in the command cache. If that is correct I > > > > would expect it to do the following: > > > > > > > > 1. iterate through the commands in the command cache and find a > > > > command that matches the first command in the sequence > > > > > > > > 2. verify that the (len - 1) subsequent commands match those in the > > > > sequence, otherwise bail out > > > > > > > > If I'm not mistaken the current version of find_match() only checks > > > > that the first command exists. After that it happily increases the > > > > command index, but doesn't perform any checks (after finding the first > > > > command 'tcs->cmd_cache[i] != cmd[0].addr' remains false for the > > > > subsequent values of j). When j reaches (len - 1) the function > > > > returns the index of the first command in the cache, regardless of > > > > whether the other commands match or not. > > > > > > > Did you miss the check inside the WARN? > > > WARN(tcs->cmd_cache[i + j] != cmd[j].addr, > > > > My point is that this code is never reached, also regardless of the > > condition, the branch would always return -EINVAL. > > > > for (j = 0; j < len; j++) { > > if (tcs->cmd_cache[i] != cmd[0].addr) { > > if (j == 0) > > break; > > WARN(tcs->cmd_cache[i + j] != cmd[j].addr, > > "Message does not match previous sequence.\n"); > > return -EINVAL; > > } else if (j == len - 1) { > > return i; > > } > > } > > > > Let's single step through this, assuming the sequence of len=3 is in > > the cache: > > > > 1. j=0 > > 2. (tcs->cmd_cache[i] != cmd[0].addr): false > > => branch with WARN + EINVAL not executed (good, this is the first > > command we are looking for) > > 3. (j == len - 1): false > > > > 4. j=1 > > 5. (tcs->cmd_cache[i] != cmd[0].addr): false > > => branch with WARN + EINVAL not executed > > 6. (j == len - 1): false > > > > 7. j=2 > > 8. (tcs->cmd_cache[i] != cmd[0].addr): false > > => branch with WARN + EINVAL not executed > > 9. (j == len - 1): true > > => return i > > > > Am I getting something wrong here? > > The for_each_set_bit() should increment the 'i' and we would attempt to > compare the first address in the request with the next command in the > TCS cache. If they don't match we repeat the process again. If it does, > then we loop through 'j' to find if the sequence matches. > > Did I miss something? One of us is clearly in need of more caffeine or ready for the weekend, it might be me :) Maybe another pair of eyeballs could help to resolve this deadlock ... My single stepping above assumes that tcs->cmd_cache[i] matches cmd[0].addr, i.e. we either found the start of the sequence we are looking for or another sequence that starts with the same address. My claim is that the code returns i in either case, whether the subsequent addresses match or not.