Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp186908pxj; Wed, 23 Jun 2021 19:24:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxt2VA1q/s7bwtnRwYS7TEbEj+C/B0p8Bub3N++4MnuU0ygpquM2jX4Wsx075QkD/wIt7B7 X-Received: by 2002:a92:9509:: with SMTP id y9mr1836595ilh.18.1624501458622; Wed, 23 Jun 2021 19:24:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624501458; cv=none; d=google.com; s=arc-20160816; b=yr0o8Qid4V9VdBrwUZ5LGgK656DDq4PhG0qNM6OM5IPPUPBB0qF8lYyl+SkHg2C8Ta M5Q/NMZBF1uDUffOURl9vNakjMRSmfzJcdW6AO5R4GHN0gel8WW8l/L6z+TsFfwJpF6Y N1dKBWRH46Qun9Tt8qjCfQmUkfudm/KeHgwHN9c8eZPnjYcMq1Y6w9krZGtg9y97RxBz 9Ciq8qkSHYb0hWM8EhR4d8vrGGmfBdn3s7+FSd9FNQ1gQxyQtz8VHtZvP5bcv/ow1VOf jxmfoeoDMrmIY6hZ2czc3fM+pEphE7g3+M48qQBc0I5WRBTdawSu4Ph8pHR/jl12kRpa DTqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=8E0w6EUy5FYV/ZXtFIifZuvspQzbp8qJ/1Ru+U5hWb0=; b=rC6KHK+k3Os+m9KGRnZJMchIQZrtaupqJt7u4fUGjMihIbtsT9Sjx3pr9CZjgCW+gr wJ6jtjfZ8NsLdrLObiV/MQUaZbJvnXIpwoyKvVJ1p2iJZSXIm3Ytcd2uKpl9oNH1tQiI M+oUa1nxikYudrbwUuqNtZz60uWBYY+jJiDOcxAbuc+Ib+f8sGpxMkzSvoC2sVK1UfNO OzrW+W5GUl7nsbK3kqVg2eyVFV63h5M/jNkSyc7/CXD8jyS+5FFbgXlev2Od5+Plew0N Mp50gP0bu8yrlTV/5s+aUHD5AvTYdHsOrZ/hPKLVYF3fE+/LZdaRUN5W7R//M0n+HktT me1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rhcqG5bX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z8si1943992jao.3.2021.06.23.19.23.56; Wed, 23 Jun 2021 19:24:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rhcqG5bX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229881AbhFXCZP (ORCPT + 99 others); Wed, 23 Jun 2021 22:25:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229826AbhFXCZP (ORCPT ); Wed, 23 Jun 2021 22:25:15 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2728BC061756 for ; Wed, 23 Jun 2021 19:22:56 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id k6so3855770pfk.12 for ; Wed, 23 Jun 2021 19:22:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=8E0w6EUy5FYV/ZXtFIifZuvspQzbp8qJ/1Ru+U5hWb0=; b=rhcqG5bXRF+/qQu+0PcRAAaZjK7SrDV3G9a1cbYR8BT5Mz2pFl+hUUdvZN0NYn6yVE GGfr2K1IpqQGqoiqk1Wedr2+J4pei2krzolrPowwvr55Vw869by7D5gG/ARMdd0b/qmY AJwdORvXSghESA+PSbE6ve6KEfC7HZ1HG6OLjYqEAg1HE0LXiKWw1J05kuIkSbXYnF// 9ekQ5f7BhLj9LqEKdI/OnqMm4WZGXQorynfiOvZMZRnIkn+xWCvNzgs7Ge55Klc6Dr4y M2t6VjCl/BKGoYFThOFYFy/EE4IAfDAjvk5s3Yq7HiOpylTAu45ceA5qquUy5lbxMdHg xBrA== 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=8E0w6EUy5FYV/ZXtFIifZuvspQzbp8qJ/1Ru+U5hWb0=; b=V6jt+PYZEuQSlx1aTJN0OxRPHxj6nW84RCiAxiJXu97lslek/mEzXFGYA6Mif1l46x Lw3GKmJ8U4pP+2YRtS8KBKdP/nY40aHiz9VHSwlDf/5vRHgwwrA/aOP634GPE2xHJr8m YG/U00FMN3mEzoE0jV6ysYXKe24BuCBGulLVslU231XXs1uJ83KCMjqnY2KcV48RSB30 0rs1nM5KsuOJ/t8Z8uUusP1BmHhBpRz8RjfbeQcS+/NwMw4rQBQu/cTDaM6Qu3ZRlhI9 FRN6+as0qRSzBFH3z1JZYPfRYxFB5k5tCDv3AhHlM9EzHGoX2gpsTUofuy81Fm/Ow1fo GD1g== X-Gm-Message-State: AOAM532qL0DWgE7X3sXrw2JP4HgyZkvIUr2TJ5bqYZqwo3hju95PwbpK Oljtuvc4E2Ty7BjTCVuH/VbvSg== X-Received: by 2002:a63:1143:: with SMTP id 3mr2553834pgr.166.1624501375726; Wed, 23 Jun 2021 19:22:55 -0700 (PDT) Received: from localhost ([136.185.134.182]) by smtp.gmail.com with ESMTPSA id j2sm1022237pfb.53.2021.06.23.19.22.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Jun 2021 19:22:54 -0700 (PDT) Date: Thu, 24 Jun 2021 07:52:52 +0530 From: Viresh Kumar To: Ionela Voinescu Cc: Rafael Wysocki , linux-pm@vger.kernel.org, Vincent Guittot , Qian Cai , linux-kernel@vger.kernel.org Subject: Re: [PATCH V3 2/4] cpufreq: cppc: Pass structure instance by reference Message-ID: <20210624022252.zrxsftrvcd43eqra@vireshk-i7> References: <20210623134533.GB12411@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210623134533.GB12411@arm.com> User-Agent: NeoMutt/20180716-391-311a52 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23-06-21, 14:45, Ionela Voinescu wrote: > On Monday 21 Jun 2021 at 14:49:35 (+0530), Viresh Kumar wrote: > > Don't pass structure instance by value, pass it by reference instead. > > > > Might be best to justify the change a bit :) I had it and removed later as I thought it would be obvious :) > For me this is a judgement call, and I don't really see the reasons for > changing it: we don't care if the structure is modified or not, as we're > not reusing the data after the call to cppc_get_rate_from_fbctrs(). > More so, in this scenario we might not even want for the called function > to modify the counter values. Also there is no further call to a function > in cppc_get_rate_from_fbctrs(), that might require references to the > fb_ctrs. > > So what is the reason behind this change? How about this commit log then: Theoretically speaking, call by reference is cheaper/faster than call by value for structures as the later requires the compiler to make a new copy of the whole structure (which has four u64 values here), to be used by the called function, while with call by reference we just need to pass a single pointer (u64 on 64-bit architectures) to the existing structure. Yes, on modern architectures, the compilers will likely end up using the processor registers for passing this structure as it isn't doesn't have lot of fields and it shouldn't be bad eventually, but nevertheless the code should do the right thing without assuming about the compiler's or architecture's optimizations. Don't pass structure instance by value, pass it by reference instead. -- viresh