Received: by 10.192.165.148 with SMTP id m20csp1046527imm; Fri, 27 Apr 2018 11:41:51 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrHM7LOMD3iMgw5X9U97wXEsgdZEImeDuOBA4ncBAJyZngtc8blZWk9HPNjHvY+2TLRLVpR X-Received: by 2002:a63:7e4e:: with SMTP id o14-v6mr2987828pgn.18.1524854511058; Fri, 27 Apr 2018 11:41:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524854511; cv=none; d=google.com; s=arc-20160816; b=IFGXvpnZAF5FW37+Uh7C89Uw1fc6v2fBPysntodyWloqQYIuBy2Kv9txzxwyH3teqR SxTJtmT8Z0Z1oEwwnnrcluFxiVNwqv1oLvdVODLSYk23PsTEVcVcm1JP/dpyT6Mzs06g JMJck3y195R1q7dyLgzv1IazUmpVxdS+RgcohiyXg3UTYZaukuCDMC1jGjpvCwd+NsT6 8JaMNOYdfstJ5XA4zS16Da7cje4osk073hsT3aYSalfcmuuG35KuaUMfm2EVQW/W+PC1 YmfRFqazQ+l6lSaNsJIWMCjgT45SP0fopI8CmvCKcmS0u8MGqv4ZC9Pj8vzaLI+fCUjK wQgA== 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=cO1tdDMdWfr+smDyZAWRUV4V6AH9ewtefq3uCTXRcmo=; b=gtfROupU8loUxv7xfl7BBba4UMttV9nj4E3GehRd8ctPPP/gqloI4IBl/7oezsrnQ5 v0bk9A30xPtrX3NSyEpAC/O53fpM4QhGju8pNp4YhMMogG55patM+4V5ZghhS8IK68b1 Cn9r4KLt3SY23XQqTKmfGs4cgg5uWSCxcZCn1qaiytaFOvRYLo3rLimQG7iS5OIFQVQH 8dUIZpKKkGFGxjgXEuNV7S6hHROZIDzz1CWd5xSw5oZZKXBU8/n/yBAuxIjlBCuJRPAO Zh2P8hOfqD7/twuh2ClY3pWEaudnF5OooqEwwxwt0fy+d+1u8hL3+2QBy/mJSmerDYMT zGsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Cg4Sl0OH; 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 d16-v6si1737865plj.57.2018.04.27.11.41.35; Fri, 27 Apr 2018 11:41:51 -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=Cg4Sl0OH; 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 S1757961AbeD0SkV (ORCPT + 99 others); Fri, 27 Apr 2018 14:40:21 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:43960 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753079AbeD0SkT (ORCPT ); Fri, 27 Apr 2018 14:40:19 -0400 Received: by mail-pg0-f65.google.com with SMTP id k11-v6so1070499pgo.10 for ; Fri, 27 Apr 2018 11:40:19 -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=cO1tdDMdWfr+smDyZAWRUV4V6AH9ewtefq3uCTXRcmo=; b=Cg4Sl0OH7Q1LkkGu/hG4wWpcS9Mh4pI2zhvouZda4/pA2fq/0q/gkwAMEGX3WMDI+d hETMHyh1T3FTKUb7vhR1vio1Sh3oIcAlFfGegBSOrw0OtHQFCIzETz3VicQ/yTgAj5tH 3cYRgUu24RBq+U3ZDsIEJ7zUle33LrlbEon9g= 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=cO1tdDMdWfr+smDyZAWRUV4V6AH9ewtefq3uCTXRcmo=; b=i6q86kbdrtYr0wddgFXc7RfrRQj7WtTGcU+UbpInfv04bPSc5UCggB5psLf2F8+fly BtAyW6m/O7spmms9wJvg6w++CABryJx/rtIeK2ZELKCntOLjE7YTCyAzIiya/8n7/Dyn PiK7UyPyAAgwPVECFXiq73cY55RUoLvpHaxHXTlo5K28Uj760RxZ8nv/DSbTxkXAmIAi jB7aaJ8/C7QmJYlR5M1pOaYZC63GyrhFvpGqid38vBnx+vAQpN5s556B3BUYCeI7XqAc BGp2kbFdV5DLZcywU5vKUQbhsmgi7oxfMREyb9Mw0zxBSVvDobbEQbOHzPP1aaIAG0Uu eRZQ== X-Gm-Message-State: ALQs6tConZF4P0/4Jh892hPAOeI25UOVXoNseuCr8Unr9MPMaDkX0FEN gzp/0YAGjslgURVB96rt8M0kzg== X-Received: by 2002:a63:5f0e:: with SMTP id t14-v6mr2913975pgb.94.1524854419020; Fri, 27 Apr 2018 11:40:19 -0700 (PDT) Received: from localhost ([2620:0:1000:1501:8e2d:4727:1211:622]) by smtp.gmail.com with ESMTPSA id 81sm3659299pfl.92.2018.04.27.11.40.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 27 Apr 2018 11:40:18 -0700 (PDT) Date: Fri, 27 Apr 2018 11:40:17 -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: <20180427184017.GI243180@google.com> References: <20180419221635.17849-1-ilina@codeaurora.org> <20180419221635.17849-6-ilina@codeaurora.org> <20180425214111.GC243180@google.com> <20180427173943.GD6380@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20180427173943.GD6380@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 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. Please correct me if I'm just confused, I think the negative logic of 'tcs->cmd_cache[i] != cmd[0].addr' doesn't help the readability of the code.