Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp3134849rwl; Mon, 27 Mar 2023 09:39:12 -0700 (PDT) X-Google-Smtp-Source: AK7set/QU11OENxX1TjLEqpn/gjVRZUl9NF7InDGWGCbTx99GYMmiYX5rYKd4TuLjqi0+g8WoZpE X-Received: by 2002:a05:6a20:6ca6:b0:d6:26a3:98d with SMTP id em38-20020a056a206ca600b000d626a3098dmr11700073pzb.46.1679935152216; Mon, 27 Mar 2023 09:39:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679935152; cv=none; d=google.com; s=arc-20160816; b=ROcHwPnn1n5JWtBEZ9hg2uONOWQUX7hyJf3cc8eDvHI7fES80R9zUpTUCQSftRnMn2 cfSUmB70l27OcKxs1P6YgNyZSlt6t7gC0LLNrfq/bhqcm4RdG5wsINHEat3/e2kFLSFS +gUKEF3UBE06C/yD6XYUAKq8RxCtdxSccTBSaEySReSVzrEu7PO8fyrvlGhv4irMXwgX T1z3OFxq1dpNl+EDaoLYW0OWjDpOgPMk3gfOi7PDW+5ZHWNHYad+kN74Ndv2Sk45RkO+ DULd9tT8iQ2JHWjsMVcJkSC/zgkjCOcko9tYB7qH/2MsCqhIoALphOUvscjq7UHqUSl0 oRvA== 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=NBxg0nlT4V595EjFXjyB+U6yK4WqNUj50iWJeRo7l4U=; b=n9WN3calRonmvo8HRjQ4b+QdYB8Y/2DqP09SPsmOQGHLzQgNKYlqonZsWXAF1MMsyk B2iNd/YItVzU31YcV5idSynl9iBkf/iII9gWpRiIlcwqpWtNtAbmD6e8et6NPJ8rHi3r 3Qg+4hawF7BeE8TlmRK5yeAkJuIgaWuqG87sWcnZiDBPWAXD8x2Vqldf6T9p5AL6fI54 XI0yYabqBcj39AKwq85Zqkkn+fCXKZR5LhWCqawnfh9ZrFRMyGEGv/TnOYEEgk3z8CHi XZuBhBJiEVMSlsVnsBSo7gyG4NINR942yhgfc59KXQRooy+hzAomHA4Sc21i8rq5Vbw5 2kYA== 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 t70-20020a638149000000b00513237db74asi8665441pgd.494.2023.03.27.09.39.00; Mon, 27 Mar 2023 09:39:12 -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 S232208AbjC0Qhs convert rfc822-to-8bit (ORCPT + 99 others); Mon, 27 Mar 2023 12:37:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232132AbjC0Qhq (ORCPT ); Mon, 27 Mar 2023 12:37:46 -0400 Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFC0C268F; Mon, 27 Mar 2023 09:37:44 -0700 (PDT) Received: by mail-ed1-f42.google.com with SMTP id y4so38798017edo.2; Mon, 27 Mar 2023 09:37:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679935063; 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=LCUgcNjEyWvD6sTwdUsnBUalyH9Ao6KbTN9qB87isrs=; b=liZ09ojyiPa/c3FjJXr7uEle7/0fEtLJTJjVcwQh9+788V7S+MGzRhq1EwpiAQSmpV QFO8HFNpEQjZIQ5yeVt5vm7DSawuphA+rHoiPsTi+CrnHNaPcXXSeJSxYcmimuSzLZnB lhwZ+rv4mAD1QyVlRH57cca9PKh0cjG+tC9oIFQbytFOWMXqc/OiZIngRaShoI3YJWT3 bQbecOVD/O6czpSlBfNXZKNxsdSkwIUegG7kUYncQAY7kmW1TCy+IKKUqqvizDi4UFsK G3W8gAv9xbxlGsQX35DV+VqbK2rjQbJBG2/uCX+KOxkUgscSOJxLVn96I4Y2HBche0EX OLhw== X-Gm-Message-State: AAQBX9eTYWUDeiUvkmpjTZBv3eGPJL0iP36vApX7uCOVvcNPE1zWagOX SJ4AR+G0orFAVvabSM4q2o2KJIIlxhsCOnPT+KU= X-Received: by 2002:a17:907:d48d:b0:93e:c1ab:ae67 with SMTP id vj13-20020a170907d48d00b0093ec1abae67mr5066951ejc.2.1679935063106; Mon, 27 Mar 2023 09:37:43 -0700 (PDT) MIME-Version: 1.0 References: <20230207051105.11575-1-ricardo.neri-calderon@linux.intel.com> <20230207051105.11575-14-ricardo.neri-calderon@linux.intel.com> In-Reply-To: <20230207051105.11575-14-ricardo.neri-calderon@linux.intel.com> From: "Rafael J. Wysocki" Date: Mon, 27 Mar 2023 18:37:32 +0200 Message-ID: Subject: Re: [PATCH v3 13/24] thermal: intel: hfi: Store per-CPU IPCC scores To: Ricardo Neri Cc: "Peter Zijlstra (Intel)" , Juri Lelli , Vincent Guittot , 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 , Lukasz Luba , Ionela Voinescu , x86@kernel.org, "Joel Fernandes (Google)" , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, "Tim C . Chen" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=0.5 required=5.0 tests=FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS 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, Feb 7, 2023 at 6:02 AM Ricardo Neri wrote: > > 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 lock 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: Ionela Voinescu > Cc: Joel Fernandes (Google) > Cc: Len Brown > Cc: Lukasz Luba > 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 v2: > * Only create these per-CPU variables when Intel Thread Director is > supported. > > Changes since v1: > * Added this patch. > --- > drivers/thermal/intel/intel_hfi.c | 46 +++++++++++++++++++++++++++++++ > 1 file changed, 46 insertions(+) > > diff --git a/drivers/thermal/intel/intel_hfi.c b/drivers/thermal/intel/intel_hfi.c > index 2527ae3836c7..b06021828892 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 > @@ -170,6 +171,43 @@ static struct workqueue_struct *hfi_updates_wq; > #define HFI_UPDATE_INTERVAL HZ > #define HFI_MAX_THERM_NOTIFY_COUNT 16 > > +#ifdef CONFIG_IPC_CLASSES It would be good to provide a (concise) description of this variable. > +static int __percpu *hfi_ipcc_scores; > + > +static int alloc_hfi_ipcc_scores(void) > +{ > + if (!cpu_feature_enabled(X86_FEATURE_ITD)) > + return 0; > + > + hfi_ipcc_scores = __alloc_percpu(sizeof(*hfi_ipcc_scores) * > + hfi_features.nr_classes, > + sizeof(*hfi_ipcc_scores)); > + > + return !hfi_ipcc_scores; I would do if (!hfi_ipcc_scores) return -ENOMEM; return 0; Or make the function return bool. > +} > + > +static void set_hfi_ipcc_score(void *caps, int cpu) > +{ > + int i, *hfi_class; > + > + if (!cpu_feature_enabled(X86_FEATURE_ITD)) > + return; > + > + 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); As it stands, it is unclear why WRITE_ONCE() is needed here. > + } > +} > + > +#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) > { > @@ -192,6 +230,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); > } > @@ -580,8 +620,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]; > --