Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4350569rwd; Tue, 23 May 2023 06:42:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6peCYuzKqFoKBNF9VYI/1vDUWZGlqVTf8yII4+TcuqeBOA0LW0P9hqY6/zf0cqjAI5tc/9 X-Received: by 2002:a17:902:9686:b0:1a6:a6e7:8846 with SMTP id n6-20020a170902968600b001a6a6e78846mr12751046plp.40.1684849323010; Tue, 23 May 2023 06:42:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684849322; cv=none; d=google.com; s=arc-20160816; b=fXSrVtGlqQTxHFCHWgUMOgAHmJFVeBuUfdDINTeKQbrX2Qe/n34b5c85z8ZrTriFfg JU2RsG/dPG5tomrw2bo/5/iHMyCfBPT19M/nx5ZfwZn8I4x8K5+Hk9vGJRP5/AI9VX1Q 6N9uxTkoqib39pQ8bwD5S1sLt4Qyibe+0zgTdNzdxsS/KCocRYCwGD5T+EBFY1PCPe+s u+Lhnr/14ZOeHz3126ep9NMekLCe6CKWrQVyYJFk65siLdNjKXAyPpl5Jm34DCpPA26T oQRvhwwxJj4DQZ+Q69jqCa6S1UbkCmvzMtG98rP+6HvEtQp6HzI8JlemB7LMftbenrkp Iulw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=kCOVI8q7O3CBvq0lNbEbRiAXtulhxzs+5Dq3Z5f/Kz0=; b=r6ryiH4BJ8IeFl7QBeFVBB7GBSwi6lrTsI+NfMMTWOMvZbpkt1yaDv9ou4Wp/jSJMk G7wLFGEY1O423w47YmEezxpDBZws07A8hbwjvui8nq/oDTSYiu3Uh98e56n//PzFrEMX moC3YcEaV8HAwgd+NoM7WRq7Q/ZT5uk5+5G7ov4MaEBFGDVLE0lOP2gAcmGMeYJ7GKBy WxO6wOkWxGV9E2MQYmlASce19A6Wt7m0tLf450TfG0bPDhg+LdEGUVEQYSArx7H2Z9fR t2CMCqSlXiWJBhEyCt2oeiXD680bUEdDC9I8EZ+qghTjPCea/CsBaOzIH0NB/hnWAMgW vjQA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z7-20020a170903018700b001ab18eb1764si5301324plg.131.2023.05.23.06.41.50; Tue, 23 May 2023 06:42:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236726AbjEWNhl convert rfc822-to-8bit (ORCPT + 99 others); Tue, 23 May 2023 09:37:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236664AbjEWNhj (ORCPT ); Tue, 23 May 2023 09:37:39 -0400 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F61DCA; Tue, 23 May 2023 06:37:38 -0700 (PDT) Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-96ffba243b1so52377366b.0; Tue, 23 May 2023 06:37:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684849057; x=1687441057; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lTOVQSwHwdcqFwCeAzjs0914zunxaGgHWWXc+AF0OJE=; b=QQ5PZ3+lerpuhhbqdaubz2QdUnxhcypeTEJz/CRiK7FNamO14RJ4Gt+BSJdrH/8+5U MfeeBaOsklbULdmTPG4n60tya8i1Fl6wcsqJSNm2vUJ275xHq8vZfxUg0xXMko0CRFh6 19cDoB/uxyES+6w7FOZf6O4koJYDzetPHt/Kel+b2dBw4x4akrqIT8RknLkVEUWSkQi8 B2AMBq3XKlKHfU9NN9SdIej4+mIHCAnjCP9Ws3PwcD39jrV798DrS5BJAXX5NXXuEvBi aqRZBpcvpZKL9WmorwP39kdwbQAh7+glGm9E8s/hTtmAcLWfdVEtRtuypTNNl2Llo3e5 HA4A== X-Gm-Message-State: AC+VfDwNYFrz5KHoKrZFnIRUgZKA50qPUlTMLUSVljY3ATrX75oCWq5i PCf8oFFwczOTpXhHmr0KrJ1sNrEm5i0hwMz8cZk= X-Received: by 2002:a17:906:7a50:b0:94a:5f0d:d9d6 with SMTP id i16-20020a1709067a5000b0094a5f0dd9d6mr10904249ejo.4.1684849056661; Tue, 23 May 2023 06:37:36 -0700 (PDT) MIME-Version: 1.0 References: <20230523085045.29391-1-kweifat@gmail.com> In-Reply-To: From: "Rafael J. Wysocki" Date: Tue, 23 May 2023 15:37:25 +0200 Message-ID: Subject: Re: [PATCH v2] cpufreq: intel_pstate: Avoid initializing variables prematurely To: srinivas pandruvada Cc: "Rafael J. Wysocki" , Fieah Lim , lenb@kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 23, 2023 at 2:20 PM srinivas pandruvada wrote: > > On Tue, 2023-05-23 at 13:08 +0200, Rafael J. Wysocki wrote: > > On Tue, May 23, 2023 at 10:51 AM Fieah Lim wrote: > > > > > > We should avoid initializing some rather expensive data > > > when the function has a chance to bail out earlier > > > before actually using it. > > > This applies to the following initializations: > > > > > > - cpudata *cpu = all_cpu_data; (in everywhere) > > > - this_cpu = smp_processor_id(); (in notify_hwp_interrupt) > > > - hwp_cap = READ_ONCE(cpu->hwp_cap_cached); (in > > > intel_pstate_hwp_boost_up) > > > > > > These initializations are premature because there is a chance > > > that the function will bail out before actually using the data. > > > I think this qualifies as a micro-optimization, > > > especially in such a hot path. > > > > > > While at it, tidy up how and when we initialize > > > all of the cpu_data pointers, for the sake of consistency. > > > > > > A side note on the intel_pstate_cpu_online change: > > > we simply don't have to initialize cpudata just > > > for the pr_debug, while policy->cpu is being there. > > > > > > Signed-off-by: Fieah Lim > > > --- > > > V1 -> V2: Rewrite changelog for better explanation. > > > > > [...] > > > > void notify_hwp_interrupt(void) > > > { > > > - unsigned int this_cpu = smp_processor_id(); > > > + unsigned int this_cpu; > > > struct cpudata *cpudata; > > > unsigned long flags; > > > u64 value; > > > @@ -1591,6 +1593,8 @@ void notify_hwp_interrupt(void) > > > if (!(value & 0x01)) > > > return; > > > > > > + this_cpu = smp_processor_id(); > > > + > > > spin_lock_irqsave(&hwp_notify_lock, flags); > > > > > > if (!cpumask_test_cpu(this_cpu, &hwp_intr_enable_mask)) > > > > This is a place where it may really matter for performance, but how > > much? Can you actually estimate this? > > If DEBUG_PREEMPT is defined > ~12 instructions (most of them with latency = 1 in dependency chain) I really meant "estimate the effect of this change on performance", because I'm not sure if it is going to be visible in any test. But yes, skipping it if not needed at least makes some sense.