Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4386140rwd; Tue, 23 May 2023 07:07:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6MKVuARu3G099UiBH8R6f7eszK/JS/eGaCi+P9AdKc/qi4HCLnz6/4I9k96xrUCcruEfBK X-Received: by 2002:a17:90a:1601:b0:23b:3699:b8a9 with SMTP id n1-20020a17090a160100b0023b3699b8a9mr13909901pja.17.1684850863839; Tue, 23 May 2023 07:07:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684850863; cv=none; d=google.com; s=arc-20160816; b=H8v7pwiBfvLwrLpq9npBZGWczRR2biCorq+X+NDmwL6A09JbDjX0fM+jBnEw5sy4gS 0FCAM0BBxhl2rseeF/Ezj1faAz8n04EbxtA6NMxCeSmB3+Lhjl1nlH0VLEfzPj98g7on Re9JDJyhbQ6AJe0zIpID7rhntvYje7b5tBx/RVh2rPHaxaVSUKzF3fCXbR0UnXAjDZjh q4Yq4PWuUOXKnjIle1qB6FcujEiFwSN2gK1qAcMgJesHBvK6HXjpYAouuhOsmcie+JxM /LndA8WFLGpUGbKqUjStrvN+jU0mJr6W22NY/4dtM0sIrUS8hXmlbQToxcegr517Hw6A gIoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=WLNhzR90A7tJzYCLLb9hmz+gz4puSaamVCLyH9bdbTM=; b=jyjfvASHZrlo+WWAjco6UJ1K0kB2PBPp8B2TUaskGb9Utg39wBCSmEM+FMkR3uBNP9 0LMBH9Oj8KIA/6qhsUa3VBAuOCvYBJuB/h/PinLAo+37mKBFuV5Ig/TghKLHS8KUvULb qGutrN1mXnIfTS+9kkl/8haZndfwTpPEVPRli+1ClR7LSuD84Nzcvkem05W9WEPTuL2w T/kNNkAP+gDP2nd264hELuVuGqe0fcOO+fTTXx4+qrrTEcBxezSHX2HlLj7kJQtUGntx Pyp8qB82PtSxMCQiQcvwIxs14FutsJ3LnqrYdBWoAfLr93RQEVF1MASCkKOWPoPqEtbv azwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Uu7fRLqm; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pf16-20020a17090b1d9000b00255813b0d96si3007180pjb.179.2023.05.23.07.07.31; Tue, 23 May 2023 07:07:43 -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; dkim=pass header.i=@intel.com header.s=Intel header.b=Uu7fRLqm; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236216AbjEWOCc (ORCPT + 99 others); Tue, 23 May 2023 10:02:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229628AbjEWOCb (ORCPT ); Tue, 23 May 2023 10:02:31 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51DB0CA; Tue, 23 May 2023 07:02:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1684850550; x=1716386550; h=message-id:subject:from:to:cc:date:in-reply-to: references:content-transfer-encoding:mime-version; bh=WLNhzR90A7tJzYCLLb9hmz+gz4puSaamVCLyH9bdbTM=; b=Uu7fRLqmMZBvL15fS3vtBFpDqNr7alS16ooWPOLg8JtiMEsbIX88Wzl4 fJeDoCO7ARbXGEqYzLSsKoXDgTg1yZJYMKLF4Dg2syHDRXTutYZMT0yeq G7WhBP4osC+rVCn+0fNXhjhuMdS+XF1H/ltbmcPWhx4bqPmzqJC1sg7lt +HjRS4P1LBBX3aEZWrkjiSBPg6yaLyCbZO+0hjPAlpmIDr5bj5KWGjK3C YNwjhGPAtfNBSjGyzRpCj7PJzLyhG92niRHH7ed9iTD1jTF0xcFBxLBP+ 399t1qTL7q0P3lnAd7ZWQANWZoXRZVC9kvXLAuSPaJuwJAjM0Wz4EwDF5 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10719"; a="332856169" X-IronPort-AV: E=Sophos;i="6.00,186,1681196400"; d="scan'208";a="332856169" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 May 2023 07:02:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10719"; a="878220406" X-IronPort-AV: E=Sophos;i="6.00,186,1681196400"; d="scan'208";a="878220406" Received: from pkgolcon-mobl2.amr.corp.intel.com ([10.209.168.218]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 May 2023 07:02:27 -0700 Message-ID: <96d81ba4c501134c77869a08b843b39fc1bf7526.camel@linux.intel.com> Subject: Re: [PATCH v2] cpufreq: intel_pstate: Avoid initializing variables prematurely From: srinivas pandruvada To: "Rafael J. Wysocki" Cc: Fieah Lim , lenb@kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 23 May 2023 07:02:26 -0700 In-Reply-To: References: <20230523085045.29391-1-kweifat@gmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4-0ubuntu1 MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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, 2023-05-23 at 15:37 +0200, Rafael J. Wysocki wrote: > On Tue, May 23, 2023 at 2:20=E2=80=AFPM srinivas pandruvada > wrote: > >=20 > > On Tue, 2023-05-23 at 13:08 +0200, Rafael J. Wysocki wrote: > > > On Tue, May 23, 2023 at 10:51=E2=80=AFAM Fieah Lim > > > wrote: > > > >=20 > > > > 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: > > > >=20 > > > > =C2=A0- cpudata *cpu =3D all_cpu_data; (in everywhere) > > > > =C2=A0- this_cpu =3D smp_processor_id(); (in notify_hwp_interrupt) > > > > =C2=A0- hwp_cap =3D READ_ONCE(cpu->hwp_cap_cached); (in > > > > intel_pstate_hwp_boost_up) > > > >=20 > > > > 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. > > > >=20 > > > > While at it, tidy up how and when we initialize > > > > all of the cpu_data pointers, for the sake of consistency. > > > >=20 > > > > 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. > > > >=20 > > > > Signed-off-by: Fieah Lim > > > > --- > > > > V1 -> V2: Rewrite changelog for better explanation. > > > >=20 > >=20 > > [...] > >=20 > > > > =C2=A0void notify_hwp_interrupt(void) > > > > =C2=A0{ > > > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 unsigned int this_cpu =3D smp= _processor_id(); > > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 unsigned int this_cpu; > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct cpudata *cpudata; > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 unsigned long flags; > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 u64 value; > > > > @@ -1591,6 +1593,8 @@ void notify_hwp_interrupt(void) > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (!(value & 0x01)) > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 return; > > > >=20 > > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 this_cpu =3D smp_processor_id= (); > > > > + > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 spin_lock_irqsave(&hwp_n= otify_lock, flags); > > > >=20 > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (!cpumask_test_cpu(th= is_cpu, &hwp_intr_enable_mask)) > > >=20 > > > This is a place where it may really matter for performance, but > > > how > > > much?=C2=A0 Can you actually estimate this? > >=20 > > If DEBUG_PREEMPT is defined > > ~12 instructions (most of them with latency =3D 1 in dependency > > chain) >=20 > 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. >=20 > But yes, skipping it if not needed at least makes some sense. It will have neglible effect. I can measure it, but may be next week. Thanks, Srinivas