From patchwork Mon Nov 28 13:20:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Neri X-Patchwork-Id: 26763 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5657799wrr; Mon, 28 Nov 2022 05:15:41 -0800 (PST) X-Google-Smtp-Source: AA0mqf4nStr6G9RCBHvF45hnMnZvRrdvfBqg7pS6wFdq0XOVVQNxC7RZm/7xyfaJ+8c7PJ3tqo8a X-Received: by 2002:a63:4726:0:b0:478:1c87:7fe3 with SMTP id u38-20020a634726000000b004781c877fe3mr4389964pga.233.1669641341567; Mon, 28 Nov 2022 05:15:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669641341; cv=none; d=google.com; s=arc-20160816; b=DC8QCf3q7Y5WX6ZEapj6XtM1mVkgW5DKfkhzJq4uEUhQRZ3knzvPRCbbvmXiuK8c6L MO8oFQCcwJmIcn8rgTHfqzD6Ni3jTYdNhidpFBkYxqVS0eCjxD0Eq+g2NOeceb5CbVqs cVJ0eJz9UdpSBwnEdp6GPXBcvlSi2HNeDfSAtJaLO4BVzavYUSKHVRmFcX9ieov2YFLN qybEW+v9e8hoVDOnhiptDr4cbL56We9lmeUab0Ta7seZd0PIvBHkQSJ2b1OB0jYeIJqB sEBX6hLZ5FYPPPIgpTepgEr+iyB9Vz2gvsrudDp2o8DxYHxGgwK9Gd54l1pMOWxw1Wui LLLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=77Ne8ZGc84HF+iHm8c8ICSuI+Uc7CNCZjIVGtiQ5axM=; b=gCzcrWHnwWPNWSPMRS9P3bd6ieicsH/6M2C6AiFUEbn8/fJDXC8f4IEL/ydJQeCB/3 0t5EGOWTVZKUmYEZjot1aYu7h6BE7l8EGlQLXfwxuUTHMkzLxX3b8ivDX2Qg0QJtc7FO 8ibQAKVDbgfxxsZ6WmgVsRxtpD31QXyV+ouofjAbtlTiOe/nAzurZY2r/bKApw5LK+3s oy5w7miGlthLR1jL0+b1m9yhriDLBaV+TglXhxEHakih2IMXJJW6Xy4WyPcdSQsJ6FJp 9nOGQInQ8/VRlrvN6Ye4e6CjWpPY3Fepzd+32ndBUEpmBJGnjMXM3x4T84eBJEsOJ2qT u6GA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="eP3if2/1"; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cl10-20020a056a0032ca00b00562fc008395si10102890pfb.341.2022.11.28.05.14.53; Mon, 28 Nov 2022 05:15:41 -0800 (PST) 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="eP3if2/1"; 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 S231852AbiK1NO1 (ORCPT + 99 others); Mon, 28 Nov 2022 08:14:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229896AbiK1NNj (ORCPT ); Mon, 28 Nov 2022 08:13:39 -0500 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F1A51DA53; Mon, 28 Nov 2022 05:13:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669641218; x=1701177218; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=xRdgNgGdXQiORGcgdnIBmgL4e1VMD8FuTc66jRXlDMQ=; b=eP3if2/17XG58Aa8gCs/yoHPvTQLjlMwsRb/GHZZrNwMSJXhaeb6x5+r uUDoskJFU7j9fkN1QVb7UR4UUy7SsC7JH3IIRwqG7T6gFXG90nEA43f64 mpc+3oJeU8kKtKxxhS+zq1JAfrT7X9cL76ewDU7rMMKQoctRL7iXmgbIm DM/HTwt5k0aVt5fwSJOcEuqaia37mB6umldvwazWGZQM1lpP3DKqg4OjR 9NAsMwIROJJb0MkzT+O2TCop5NfHvBjRkl3QMfAAM7a3T0hgiEbSjbF2M SPBJukrmxYQBZKfWUb3tpNHLQf/+6OMfoPp5EFbuR0SApUEwFuFgs3p9s Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10544"; a="401117159" X-IronPort-AV: E=Sophos;i="5.96,200,1665471600"; d="scan'208";a="401117159" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Nov 2022 05:13:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10544"; a="749381363" X-IronPort-AV: E=Sophos;i="5.96,200,1665471600"; d="scan'208";a="749381363" Received: from ranerica-svr.sc.intel.com ([172.25.110.23]) by fmsmga002.fm.intel.com with ESMTP; 28 Nov 2022 05:13:33 -0800 From: Ricardo Neri To: "Peter Zijlstra (Intel)" , Juri Lelli , Vincent Guittot Cc: Ricardo Neri , "Ravi V. Shankar" , Ben Segall , Daniel Bristot de Oliveira , Dietmar Eggemann , Len Brown , Mel Gorman , "Rafael J. Wysocki" , Srinivas Pandruvada , Steven Rostedt , Tim Chen , Valentin Schneider , x86@kernel.org, "Joel Fernandes (Google)" , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Ricardo Neri , "Tim C . Chen" Subject: [PATCH v2 11/22] thermal: intel: hfi: Store per-CPU IPCC scores Date: Mon, 28 Nov 2022 05:20:49 -0800 Message-Id: <20221128132100.30253-12-ricardo.neri-calderon@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221128132100.30253-1-ricardo.neri-calderon@linux.intel.com> References: <20221128132100.30253-1-ricardo.neri-calderon@linux.intel.com> 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_NONE, SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750745839513748319?= X-GMAIL-MSGID: =?utf-8?q?1750745839513748319?= The scheduler reads the IPCC scores when balancing load. These reads can be quite frequent. Hardware can also update the HFI table frequently. Concurrent access may cause a lot of contention. It gets worse as the number of CPUs increases. Instead, create separate per-CPU IPCC scores that the scheduler can read without the HFI table lock. Cc: Ben Segall Cc: Daniel Bristot de Oliveira Cc: Dietmar Eggemann Cc: Joel Fernandes (Google) Cc: Len Brown Cc: Mel Gorman Cc: Rafael J. Wysocki Cc: Srinivas Pandruvada Cc: Steven Rostedt Cc: Tim C. Chen Cc: Valentin Schneider Cc: x86@kernel.org Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Suggested-by: Peter Zijlstra (Intel) Signed-off-by: Ricardo Neri --- Changes since v1: * Added this patch. --- drivers/thermal/intel/intel_hfi.c | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/drivers/thermal/intel/intel_hfi.c b/drivers/thermal/intel/intel_hfi.c index df4dc50e19fb..56dba967849c 100644 --- a/drivers/thermal/intel/intel_hfi.c +++ b/drivers/thermal/intel/intel_hfi.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -172,6 +173,35 @@ static struct workqueue_struct *hfi_updates_wq; #define HFI_UPDATE_INTERVAL HZ #define HFI_MAX_THERM_NOTIFY_COUNT 16 +#ifdef CONFIG_IPC_CLASSES +static int __percpu *hfi_ipcc_scores; + +static int alloc_hfi_ipcc_scores(void) +{ + hfi_ipcc_scores = __alloc_percpu(sizeof(*hfi_ipcc_scores) * + hfi_features.nr_classes, + sizeof(*hfi_ipcc_scores)); + + return !hfi_ipcc_scores; +} + +static void set_hfi_ipcc_score(void *caps, int cpu) +{ + int i, *hfi_class = per_cpu_ptr(hfi_ipcc_scores, cpu); + + for (i = 0; i < hfi_features.nr_classes; i++) { + struct hfi_cpu_data *class_caps; + + class_caps = caps + i * hfi_features.class_stride; + WRITE_ONCE(hfi_class[i], class_caps->perf_cap); + } +} + +#else +static int alloc_hfi_ipcc_scores(void) { return 0; } +static void set_hfi_ipcc_score(void *caps, int cpu) { } +#endif /* CONFIG_IPC_CLASSES */ + static void get_hfi_caps(struct hfi_instance *hfi_instance, struct thermal_genl_cpu_caps *cpu_caps) { @@ -194,6 +224,8 @@ static void get_hfi_caps(struct hfi_instance *hfi_instance, cpu_caps[i].efficiency = caps->ee_cap << 2; ++i; + + set_hfi_ipcc_score(caps, cpu); } raw_spin_unlock_irq(&hfi_instance->table_lock); } @@ -572,8 +604,14 @@ void __init intel_hfi_init(void) if (!hfi_updates_wq) goto err_nomem; + if (alloc_hfi_ipcc_scores()) + goto err_ipcc; + return; +err_ipcc: + destroy_workqueue(hfi_updates_wq); + err_nomem: for (j = 0; j < i; ++j) { hfi_instance = &hfi_instances[j];