From nobody Sun May 19 15:58:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1682969473; cv=none; d=zohomail.com; s=zohoarc; b=FKvGS6bigYRm+0kGURUTywuZoaijGab26Hp9F/V7PmETY7T2f1VfSf6QXrNzu3Y2QKtoHSJMb23t/ELivmTmiVp0RxtJ77sNivA5rPCFYiaE0sRHQCKe7U7LLo4UXY4UoiKMZEXVVYaAAbjoT+JWOfWjoIqt6G6utbYoeFBSoxY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682969473; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7VFwxnOVM/nUJWo2+kFJfbzF53GX8dfaVA+R5Uyazpc=; b=Bht9wOlXrBrz/hESQTIWZaRaCX62srpVu2VN171xTFbVxw6cvf2BD3cB9peFF0LeoXTw39dYh6sctsYnqmEwGxZOWXijxT6Y0MCWns79oaSI97cgBazFo/7GuSCA3ChEVEhzS1hH8GPa5dyjKhBMoPB7lSfPpHnHIOFDiy9lJDA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1682969473851765.0011330759397; Mon, 1 May 2023 12:31:13 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.528102.820866 (Exim 4.92) (envelope-from ) id 1ptZEX-00015W-GU; Mon, 01 May 2023 19:30:49 +0000 Received: by outflank-mailman (output) from mailman id 528102.820866; Mon, 01 May 2023 19:30:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptZEX-00015P-Dp; Mon, 01 May 2023 19:30:49 +0000 Received: by outflank-mailman (input) for mailman id 528102; Mon, 01 May 2023 19:30:48 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptZEW-000149-0Q for xen-devel@lists.xenproject.org; Mon, 01 May 2023 19:30:48 +0000 Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [2607:f8b0:4864:20::731]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ab36cae7-e856-11ed-8611-37d641c3527e; Mon, 01 May 2023 21:30:46 +0200 (CEST) Received: by mail-qk1-x731.google.com with SMTP id af79cd13be357-74e0180b7d3so129184485a.2 for ; Mon, 01 May 2023 12:30:46 -0700 (PDT) Received: from pm2-ws13.praxislan02.com (207-172-141-204.s8906.c3-0.slvr-cbr1.lnh-slvr.md.cable.rcncustomer.com. [207.172.141.204]) by smtp.gmail.com with ESMTPSA id d6-20020ac80606000000b003bf9f9f1844sm9351784qth.71.2023.05.01.12.30.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 12:30:43 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ab36cae7-e856-11ed-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682969444; x=1685561444; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7VFwxnOVM/nUJWo2+kFJfbzF53GX8dfaVA+R5Uyazpc=; b=r9j9BPVz3/laZA8dsDmxZe7TRv0yNCtj/Xbsb4WpqDXgx/fA0HOTxNUrvpQf+C4t2T YNYN206A0eGrKe1qAym9I5p7tG8XdEGiJaLW8/t6JkTJFkIT0pzBFXS/iIkCO56wJn3J pUjquCuW3n9+l6STbY/dk/Ilm9zT/scjBTbtK0COm2KbSl8FAiXw+kNZWbpx0W2WhcG0 xkKJVYBUTb1RNwa7L8EPhULHZE9DzKHmCK095rERWUvFMoy1jZyxhh3f0Ve6Bc7Dd9u0 RXDpYSvLxEtoWzrauTp25svhJmvdF5OfkwS+uKrmB1iBB7Lcit4b94RhLAlA38eqUI8l eUEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682969444; x=1685561444; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7VFwxnOVM/nUJWo2+kFJfbzF53GX8dfaVA+R5Uyazpc=; b=e5YLgoL599yP+Xdv0THAgss77WW4BQBhNDGUt27NFu/yV8d6Hk2Xd9U7aftqQ9dfzF oxkCghMUyRzel1clzQJRcVM5vahCRhg5CezxVDGDhNsiIXrczwnAnja7up9ZnNSqsirz Xk0Vz8cjOfJwbJDcv0EbU8WPQS4pz0PV5AmBG55CQXJwBZo4R77v1SRPl7B8hHOGyuux fW7j/gmJRqw+qC1Kd8bmqB+lyEOOsb8WaTgPQNv/o086SviJ2xaEg6yIef5ubaSMo0/4 rYTqB6y/H3gTJVZ2si5QbqwIoOXZfqyUHXaWgQ8j2LM2Pri5RCygi/gtiVwLfOhr2+Op pcqA== X-Gm-Message-State: AC+VfDwFiDMZoBVws863mnqB/YZLQslfknsbY4EPLNA1QijkGfK4cKVZ 0hNoj1dGBrCCfasguw8ZeKCvACa/Zlk= X-Google-Smtp-Source: ACHHUZ73X7XhEV+VKk/WhUuhmrdce/HnekpsrCHDFejO2dmdia7/TP7F2pse7XFmNwI5RC0Ffs/PlA== X-Received: by 2002:ac8:7c50:0:b0:3f0:df4d:40b7 with SMTP id o16-20020ac87c50000000b003f0df4d40b7mr24378132qtv.7.1682969444425; Mon, 01 May 2023 12:30:44 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Jan Beulich Subject: [PATCH v3 01/14 RESEND] cpufreq: Allow restricting to internal governors only Date: Mon, 1 May 2023 15:30:21 -0400 Message-Id: <20230501193034.88575-2-jandryuk@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230501193034.88575-1-jandryuk@gmail.com> References: <20230501193034.88575-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1682969474098100001 Content-Type: text/plain; charset="utf-8" For hwp, the standard governors are not usable, and only the internal one is applicable. Add the cpufreq_governor_internal boolean to indicate when an internal governor, like hwp-internal, will be used. This is set during presmp_initcall, so that it can suppress governor registration during initcall. Only a governor with a name containing "-internal" will be allowed in that case. This way, the unuseable governors are not registered, so the internal one is the only one returned to userspace. This means incompatible governors won't be advertised to userspace. Signed-off-by: Jason Andryuk Acked-by: Jan Beulich --- v3: Switch to initdata Add Jan Acked-by Commit message s/they/the/ typo Don't register hwp-internal when running non-hwp - Marek v2: Switch to "-internal" Add blank line in header --- xen/drivers/cpufreq/cpufreq.c | 8 ++++++++ xen/include/acpi/cpufreq/cpufreq.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/xen/drivers/cpufreq/cpufreq.c b/xen/drivers/cpufreq/cpufreq.c index 2321c7dd07..7bd81680da 100644 --- a/xen/drivers/cpufreq/cpufreq.c +++ b/xen/drivers/cpufreq/cpufreq.c @@ -56,6 +56,7 @@ struct cpufreq_dom { }; static LIST_HEAD_READ_MOSTLY(cpufreq_dom_list_head); =20 +bool __initdata cpufreq_governor_internal; struct cpufreq_governor *__read_mostly cpufreq_opt_governor; LIST_HEAD_READ_MOSTLY(cpufreq_governor_list); =20 @@ -121,6 +122,13 @@ int __init cpufreq_register_governor(struct cpufreq_go= vernor *governor) if (!governor) return -EINVAL; =20 + if (cpufreq_governor_internal && + strstr(governor->name, "-internal") =3D=3D NULL) + return -EINVAL; + + if (!cpufreq_governor_internal && strstr(governor->name, "-internal")) + return -EINVAL; + if (__find_governor(governor->name) !=3D NULL) return -EEXIST; =20 diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/= cpufreq.h index 35dcf21e8f..0da32ef519 100644 --- a/xen/include/acpi/cpufreq/cpufreq.h +++ b/xen/include/acpi/cpufreq/cpufreq.h @@ -114,6 +114,8 @@ extern struct cpufreq_governor cpufreq_gov_userspace; extern struct cpufreq_governor cpufreq_gov_performance; extern struct cpufreq_governor cpufreq_gov_powersave; =20 +extern bool cpufreq_governor_internal; + extern struct list_head cpufreq_governor_list; =20 extern int cpufreq_register_governor(struct cpufreq_governor *governor); --=20 2.40.0 From nobody Sun May 19 15:58:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1682969477; cv=none; d=zohomail.com; s=zohoarc; b=kJxZIO6KVPcz9fFTJtDgIhu53aXd3DReVX5IlZlyNW9EKbl2OVDvmozlJdkcgoMHQopQuqP1aT+/BksHv7SZ3bta10fvFVPrZS4UVT9oTiiPifNC8xROjoHNh2D6z4oDwGdYzuyMy0WAg5fdmRqRYFUj89mGzfftD8AwEWw5s2Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682969477; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=txBzmZlgf2a5ZApasbIDD2P8VUrWanxh/ZCZKapkSd4=; b=QwksCKjUlorN8qN1bT6g5bDTARQoVwD3pRuDeiU4NEO7knIVK5EvL7smjO+Bc34BRFAY0HEkRytsYylF+UstVQMXduyukICDZLT3FUn5iQs4zEfML3G1nlOWEHJIc3k7C5nUUsRK5jGINRJ9P05cJLVMC5tV5f2rDnzb8ZbwObY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1682969477451401.47735406716515; Mon, 1 May 2023 12:31:17 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.528103.820877 (Exim 4.92) (envelope-from ) id 1ptZEa-0001Nv-Ou; Mon, 01 May 2023 19:30:52 +0000 Received: by outflank-mailman (output) from mailman id 528103.820877; Mon, 01 May 2023 19:30:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptZEa-0001NW-Lb; Mon, 01 May 2023 19:30:52 +0000 Received: by outflank-mailman (input) for mailman id 528103; Mon, 01 May 2023 19:30:51 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptZEZ-0000m4-Bd for xen-devel@lists.xenproject.org; Mon, 01 May 2023 19:30:51 +0000 Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [2607:f8b0:4864:20::836]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id adfbb034-e856-11ed-b225-6b7b168915f2; Mon, 01 May 2023 21:30:50 +0200 (CEST) Received: by mail-qt1-x836.google.com with SMTP id d75a77b69052e-3ef302a642eso13479981cf.1 for ; Mon, 01 May 2023 12:30:50 -0700 (PDT) Received: from pm2-ws13.praxislan02.com (207-172-141-204.s8906.c3-0.slvr-cbr1.lnh-slvr.md.cable.rcncustomer.com. [207.172.141.204]) by smtp.gmail.com with ESMTPSA id d6-20020ac80606000000b003bf9f9f1844sm9351784qth.71.2023.05.01.12.30.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 12:30:48 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: adfbb034-e856-11ed-b225-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682969449; x=1685561449; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=txBzmZlgf2a5ZApasbIDD2P8VUrWanxh/ZCZKapkSd4=; b=ruWWxubqxWEfgknzCeHfuioXix3neQCmP3+a25TdXUf2lY/OXFPt8Fw7bOACTmeMj9 W6lzbRO4CQm8VUxPYOZhHZE9MAixtoaCcKrnatX2CtjIGctgcqhiDy42JfMp7IiwQsJ2 pJORAvC5p1oFLI9ZU2fPomLTuylha83HfbB0PRFixRqg6vC0BYsOt3O8hjTzKeInVEdB xETcc6syUMfOhifQLASnke2KU3HfyTwJkOGtQEYC2WBE1K5fATNr2/dHtxgsu261Kbce +eSDtdfkJ8r4k8f/c73OadVqX97fNky9tSHYk/+MBR2Gh0dmKpPjUK3U/1WOM4cjGqT8 qyEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682969449; x=1685561449; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=txBzmZlgf2a5ZApasbIDD2P8VUrWanxh/ZCZKapkSd4=; b=lRDxUe0u80tEBUo92bxCtRWM89Hy/Fw3aGEIRyMdP2PTUrIr2heCD6Tw0J1ELx2T+k kvzOWfk7ttslKi9QWHDo17AiiosT1bsSntJo1bjoA9d/M7UH9ItDYQf60f+qtFKtQfBJ a1sUADMWndydb1dJS44dp6IdNuPVzkmFshlM1JUM4MSQCDDoq6OyIPR4btn9Rsja0vUU TmWsF3DWL6kgbprf/92dHaQaifLGalJ3WXJ380y8hthwzRKi7Uhukrq+llE5lhGWYUMx 3LI0cKVLhbRJwBWb3VZuvoDju4ALAyYcbpj6q64dLqyRBgOMWnaZXnIWcB26PyJMCMTo DNZQ== X-Gm-Message-State: AC+VfDz2ZyXgNv5NVJHbm+h+AJUvo12iPoBEfAROIVdOAPKtibh8Xq7Q E1q2aR2C8nus3W2KoD2ACU8ntOmiLfQ= X-Google-Smtp-Source: ACHHUZ6w3eawFGc/l9nZiVmnOOvz/C0aG06cvY9N0n+NkCEj6Vg7LQZ4xbldKhhvalrOwWvRbT6aDw== X-Received: by 2002:ac8:7c50:0:b0:3f0:df4d:40b7 with SMTP id o16-20020ac87c50000000b003f0df4d40b7mr24378669qtv.7.1682969449211; Mon, 01 May 2023 12:30:49 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH v3 02/14 RESEND] cpufreq: Add perf_freq to cpuinfo Date: Mon, 1 May 2023 15:30:22 -0400 Message-Id: <20230501193034.88575-3-jandryuk@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230501193034.88575-1-jandryuk@gmail.com> References: <20230501193034.88575-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1682969478106100001 Content-Type: text/plain; charset="utf-8" acpi-cpufreq scales the aperf/mperf measurements by max_freq, but HWP needs to scale by base frequency. Settings max_freq to base_freq "works" but the code is not obvious, and returning values to userspace is tricky. Add an additonal perf_freq member which is used for scaling aperf/mperf measurements. Signed-off-by: Jason Andryuk Acked-by: Jan Beulich --- v3: Add Jan's Ack I don't like this, but it seems the best way to re-use the common aperf/mperf code. The other option would be to add wrappers that then do the acpi vs. hwp scaling. --- xen/arch/x86/acpi/cpufreq/cpufreq.c | 2 +- xen/drivers/cpufreq/utility.c | 1 + xen/include/acpi/cpufreq/cpufreq.h | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/acpi/cpufreq/cpufreq.c b/xen/arch/x86/acpi/cpufre= q/cpufreq.c index 2e0067fbe5..6c70d04395 100644 --- a/xen/arch/x86/acpi/cpufreq/cpufreq.c +++ b/xen/arch/x86/acpi/cpufreq/cpufreq.c @@ -316,7 +316,7 @@ unsigned int get_measured_perf(unsigned int cpu, unsign= ed int flag) else perf_percent =3D 0; =20 - return policy->cpuinfo.max_freq * perf_percent / 100; + return policy->cpuinfo.perf_freq * perf_percent / 100; } =20 static unsigned int cf_check get_cur_freq_on_cpu(unsigned int cpu) diff --git a/xen/drivers/cpufreq/utility.c b/xen/drivers/cpufreq/utility.c index 9eb7ecedcd..6831f62851 100644 --- a/xen/drivers/cpufreq/utility.c +++ b/xen/drivers/cpufreq/utility.c @@ -236,6 +236,7 @@ int cpufreq_frequency_table_cpuinfo(struct cpufreq_poli= cy *policy, =20 policy->min =3D policy->cpuinfo.min_freq =3D min_freq; policy->max =3D policy->cpuinfo.max_freq =3D max_freq; + policy->cpuinfo.perf_freq =3D max_freq; policy->cpuinfo.second_max_freq =3D second_max_freq; =20 if (policy->min =3D=3D ~0) diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/= cpufreq.h index 0da32ef519..a06aa92f62 100644 --- a/xen/include/acpi/cpufreq/cpufreq.h +++ b/xen/include/acpi/cpufreq/cpufreq.h @@ -37,6 +37,9 @@ extern struct acpi_cpufreq_data *cpufreq_drv_data[NR_CPUS= ]; struct cpufreq_cpuinfo { unsigned int max_freq; unsigned int second_max_freq; /* P1 if Turbo Mode is on */ + unsigned int perf_freq; /* Scaling freq for aperf/mpref. + acpi-cpufreq uses max_freq, but HWP = uses + base_freq.*/ unsigned int min_freq; unsigned int transition_latency; /* in 10^(-9) s =3D nanosecond= s */ }; --=20 2.40.0 From nobody Sun May 19 15:58:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1682969481; cv=none; d=zohomail.com; s=zohoarc; b=XExx8Wplk0A7fP3XWGUuS5//fpzXJXfshvRYWQrHZTpsquBaTS0x057R8TgFhTjPZosSKBbHijYAb2qwN9OfBedffPaUMMJo/hEDTTqEm38oZmSsTl11qNOZppfO/eO7pgLhQtzGM4MQvun5V7bNpuApqOmoTAVzASjQNLF85ek= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682969481; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=H9MXL508WAYhYYKIHs8d77jkKwZyoTe/WztjxZedAQ8=; b=NwhlIIE1fwZWgLrEULBYcaeoLCLe+bJjJQXcgRJsa0OlOuFLo2kPKp7tmuIut6eqfJs082JtUh1PtxOKwtOxq8pUqY6LgwabXzPW70VQ0/maYemVlo31LEJuGk+/yG4+B6xhauUrHJY2AlT5e5lBoUc/fcppUFsPFzdjgSBQwsw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1682969481838275.1400859293665; Mon, 1 May 2023 12:31:21 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.528104.820886 (Exim 4.92) (envelope-from ) id 1ptZEe-0001iY-1N; Mon, 01 May 2023 19:30:56 +0000 Received: by outflank-mailman (output) from mailman id 528104.820886; Mon, 01 May 2023 19:30:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptZEd-0001iM-U2; Mon, 01 May 2023 19:30:55 +0000 Received: by outflank-mailman (input) for mailman id 528104; Mon, 01 May 2023 19:30:55 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptZEd-000149-7d for xen-devel@lists.xenproject.org; Mon, 01 May 2023 19:30:55 +0000 Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [2607:f8b0:4864:20::82b]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id afbb5f8e-e856-11ed-8611-37d641c3527e; Mon, 01 May 2023 21:30:53 +0200 (CEST) Received: by mail-qt1-x82b.google.com with SMTP id d75a77b69052e-3ee339e8c2fso12897371cf.0 for ; Mon, 01 May 2023 12:30:53 -0700 (PDT) Received: from pm2-ws13.praxislan02.com (207-172-141-204.s8906.c3-0.slvr-cbr1.lnh-slvr.md.cable.rcncustomer.com. [207.172.141.204]) by smtp.gmail.com with ESMTPSA id d6-20020ac80606000000b003bf9f9f1844sm9351784qth.71.2023.05.01.12.30.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 12:30:51 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: afbb5f8e-e856-11ed-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682969452; x=1685561452; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=H9MXL508WAYhYYKIHs8d77jkKwZyoTe/WztjxZedAQ8=; b=CxdCiWP1SUv+Yp9hcpkzl92fy/yJPA8ybi4F68aLbr7SImDVwdbkjA8fYrnKQtXs+V pyIBxunNJdDUmJu3GU08SVoJY6+AUIzlYw8Hp/YQNccxMy5ld9JuVsWUxj5x49H+ujHO VIieK+/4WpGVxK+rnYj1gYs2kAL8VpqO7ajvJjsKCiAZUeKosYnkXATmvGwpKqOi5mx6 COc3zbTQyMnNL4+dvc51sNW/sIZgrauQWsGX/+84BZCDmKNjVqvNfj1VCJo+X01cSs32 pAT8wfI6COmTC1J5jd8FIwODj9GF/tVGjc1pKqiQ8bgdYYRdSKgJeaG6kECUY3aWLl2j bwQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682969452; x=1685561452; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=H9MXL508WAYhYYKIHs8d77jkKwZyoTe/WztjxZedAQ8=; b=epUQ+HPRXrzEXbAqQbc+o/XsL9i7CUbgvGl+IgjQMp1ZpotUerBNXs1DdNq2iF2cEc a6ozq+PnBexrR5+OFSKztpOFa7T0ejWrrhMK/nezT5DwLrwK8/G7HCaW6+NZ4AghBlba 1d1ZUHfTBovnkM8JwtayqRZfqc1aTpPjkvWgyFvvUPUJyh921R0LFiJuFXX6/o7TeU1P 8jjlrQ9p5wxMZKx1PVal+s71elFTKmAGVm9ou5RNdL6syiPmAz0UO0/d2OALP35GaKVm 1TMblTve55P+1EQae2MfiZ4CmBd7KhKD2c42sD1MSqCrrwvZlF4oHKPXKzDi4fWDTdAR g7YA== X-Gm-Message-State: AC+VfDyqOUuNo9XQTsPtnA31+l+MJGd9w/hQBW0ytFVLfd/uvpZp56UG mPcFNF+96U+vtgJ2M0MjM4loGWCsvVI= X-Google-Smtp-Source: ACHHUZ61Lw9FNIzq0S8Unejn3bdDcd2bR/GRbFtZ1Rd6OIkz4KwanSmye/RkOvAVRjQPpb2hLgwA8Q== X-Received: by 2002:ac8:5d89:0:b0:3e8:1903:ab05 with SMTP id d9-20020ac85d89000000b003e81903ab05mr22968522qtx.64.1682969452035; Mon, 01 May 2023 12:30:52 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH v3 03/14 RESEND] cpufreq: Export intel_feature_detect Date: Mon, 1 May 2023 15:30:23 -0400 Message-Id: <20230501193034.88575-4-jandryuk@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230501193034.88575-1-jandryuk@gmail.com> References: <20230501193034.88575-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1682969482393100001 Content-Type: text/plain; charset="utf-8" Export feature_detect as intel_feature_detect so it can be re-used by HWP. Signed-off-by: Jason Andryuk Acked-by: Jan Beulich --- v3: Remove void * cast when calling intel_feature_detect v2: export intel_feature_detect with typed pointer Move intel_feature_detect to acpi/cpufreq/cpufreq.h since the declaration now contains struct cpufreq_policy *. --- xen/arch/x86/acpi/cpufreq/cpufreq.c | 8 ++++++-- xen/include/acpi/cpufreq/cpufreq.h | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/acpi/cpufreq/cpufreq.c b/xen/arch/x86/acpi/cpufre= q/cpufreq.c index 6c70d04395..f1cc473b4f 100644 --- a/xen/arch/x86/acpi/cpufreq/cpufreq.c +++ b/xen/arch/x86/acpi/cpufreq/cpufreq.c @@ -339,9 +339,8 @@ static unsigned int cf_check get_cur_freq_on_cpu(unsign= ed int cpu) return extract_freq(get_cur_val(cpumask_of(cpu)), data); } =20 -static void cf_check feature_detect(void *info) +void intel_feature_detect(struct cpufreq_policy *policy) { - struct cpufreq_policy *policy =3D info; unsigned int eax; =20 eax =3D cpuid_eax(6); @@ -353,6 +352,11 @@ static void cf_check feature_detect(void *info) } } =20 +static void cf_check feature_detect(void *info) +{ + intel_feature_detect(info); +} + static unsigned int check_freqs(const cpumask_t *mask, unsigned int freq, struct acpi_cpufreq_data *data) { diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/= cpufreq.h index a06aa92f62..0f334d2a43 100644 --- a/xen/include/acpi/cpufreq/cpufreq.h +++ b/xen/include/acpi/cpufreq/cpufreq.h @@ -243,4 +243,6 @@ int write_userspace_scaling_setspeed(unsigned int cpu, = unsigned int freq); void cpufreq_dbs_timer_suspend(void); void cpufreq_dbs_timer_resume(void); =20 +void intel_feature_detect(struct cpufreq_policy *policy); + #endif /* __XEN_CPUFREQ_PM_H__ */ --=20 2.40.0 From nobody Sun May 19 15:58:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1682969487; cv=none; d=zohomail.com; s=zohoarc; b=lJFxFt5luBhsn1yn5Srf8ErPyepqXPK6pcDWXkHK4itHJVm3qqOt02IBkfSh7gB8/F9PhwIs6JTQJoUFefg6OtFnNkGyVfZYnSwhkDRWjBKSAs1jWqqeKdEoz5WQ5RDz1GpyqajtDLQWuIoG+QaQw2H1JyNoI2cD/J+WPDlT27Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682969487; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Hym2Jx5Z8r7rrhqAfu+8xxIV/nnrCdXHwFgph7V69FQ=; b=cgyyoXb5TI3IytdRRrj2+xwEmkj/Uj5E8H/4lg07MsoMSb7MO1DFXHPgqak75UfjwMdOh+DAO2IDiWXFE1fRWcpnETiJzlJGISxVUDOv7ChzUpR9meA7G0B86Ptn32Z+B3YBOyCT+pvSJINlPJCMqsLC8D6jRD9LONvBEjNlEyc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1682969487313396.9826181921899; Mon, 1 May 2023 12:31:27 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.528105.820897 (Exim 4.92) (envelope-from ) id 1ptZEi-0002AI-Ce; Mon, 01 May 2023 19:31:00 +0000 Received: by outflank-mailman (output) from mailman id 528105.820897; Mon, 01 May 2023 19:31:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptZEi-0002A1-8b; Mon, 01 May 2023 19:31:00 +0000 Received: by outflank-mailman (input) for mailman id 528105; Mon, 01 May 2023 19:30:58 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptZEg-0000m4-EJ for xen-devel@lists.xenproject.org; Mon, 01 May 2023 19:30:58 +0000 Received: from mail-qk1-x736.google.com (mail-qk1-x736.google.com [2607:f8b0:4864:20::736]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b1a01d17-e856-11ed-b225-6b7b168915f2; Mon, 01 May 2023 21:30:56 +0200 (CEST) Received: by mail-qk1-x736.google.com with SMTP id af79cd13be357-7515631b965so676444985a.0 for ; Mon, 01 May 2023 12:30:56 -0700 (PDT) Received: from pm2-ws13.praxislan02.com (207-172-141-204.s8906.c3-0.slvr-cbr1.lnh-slvr.md.cable.rcncustomer.com. [207.172.141.204]) by smtp.gmail.com with ESMTPSA id d6-20020ac80606000000b003bf9f9f1844sm9351784qth.71.2023.05.01.12.30.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 12:30:54 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b1a01d17-e856-11ed-b225-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682969455; x=1685561455; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Hym2Jx5Z8r7rrhqAfu+8xxIV/nnrCdXHwFgph7V69FQ=; b=eFLLq7533G3AnlY/uK7JfettQ+iRAVTRvVGoCC70QyQnroXyxJDlomnil6MLU0E2DA jhQTA/f36QeSqDRdqwjwFcxcqn4JCYAQkwHADfatxLrVUFBiDC+/w78PmV+e7fs7jzJT FNxKneHnD7iFgYBzeJc8Cg4MxNqtOBNDA+1+2FQGd737UubPzGypVrZ18DfT02/HqgNu GVN1Nf9WZVBrPbiAfuRkiETrycnYVgCKKBo9wWVsx4Huq9l2oroPhemhECPYaBplzCT3 Hh1OOYVk78PzWfR+CEZTvVDb9pcGrar29yGM8SyXw2Fogtp0xoASga9uWVcqCr+dERqD IBUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682969455; x=1685561455; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Hym2Jx5Z8r7rrhqAfu+8xxIV/nnrCdXHwFgph7V69FQ=; b=O78QZNNAzyIBvRSi66VQB3uMnz2d1zEWIsJJNglMeh0rkKGAa7llo11z4r5vQKBWZd gLnd1x89gMxGYdr1s2dmu2nTf2spBT8Rtxm/sEBdNI6WK8VsaONnEU3L+V9Z2LHN+R39 mG6s6VoVm9Yyb0etDXeXdb7rvLIlCc0qn3kB1nydN/FOYV//J2qHliRaZJmN+qEO9Ywc 9rWLBw7tH1L0IxPXgAUnCEVeXh/wF3BvDDp6yjF+GsTOWcEvz5R+LPpq7rYcURTb7gkt iAcWPM4PzVjVhaSXMDWbnenj7i4p+byA2rmR+Vip4t/rcsOpw3r5g4krm5TyT4YSTgzx RMRQ== X-Gm-Message-State: AC+VfDzplqNVmnRYhCmpDBbWfBb0MUQm815JOD1LQ3m7PxZtrABzIPt2 ywRNCX91rsgqUuwIhgr6UFNUONdWDNk= X-Google-Smtp-Source: ACHHUZ6QbNWTkiVCscld5Z5s1zw5gwOZxJEuSKsuwgvQq7Nmmk/GhBWAz0RBbxsfRy3SwJJxRchdFA== X-Received: by 2002:ac8:5c85:0:b0:3e8:e986:b20a with SMTP id r5-20020ac85c85000000b003e8e986b20amr30735751qta.16.1682969455231; Mon, 01 May 2023 12:30:55 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v3 04/14 RESEND] cpufreq: Add Hardware P-State (HWP) driver Date: Mon, 1 May 2023 15:30:24 -0400 Message-Id: <20230501193034.88575-5-jandryuk@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230501193034.88575-1-jandryuk@gmail.com> References: <20230501193034.88575-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1682969488517100001 Content-Type: text/plain; charset="utf-8" From the Intel SDM: "Hardware-Controlled Performance States (HWP), which autonomously selects performance states while utilizing OS supplied performance guidance hints." Enable HWP to run in autonomous mode by poking the correct MSRs. cpufreq=3Dxen:hwp enables and cpufreq=3Dxen:hwp=3D0 disables. The same for hdc. There is no interface to configure - xen_sysctl_pm_op/xenpm will be to be extended to configure in subsequent patches. It will run with the default values, which should be the default 0x80 (out of 0x0-0xff) energy/performance preference. Unscientific powertop measurement of an mostly idle, customized OpenXT install: A 10th gen 6-core laptop showed battery discharge drop from ~9.x to ~7.x watts. A 8th gen 4-core laptop dropped from ~10 to ~9 Power usage depends on many factors, especially display brightness, but this does show an power saving in balanced mode when CPU utilization is low. HWP isn't compatible with an external governor - it doesn't take explicit frequency requests. Therefore a minimal internal governor, hwp-internal, is also added as a placeholder. While adding to the xen-command-line.pandoc entry, un-nest verbose from minfreq. They are independent. Signed-off-by: Jason Andryuk --- We disable on cpuid_level < 0x16. cpuid(0x16) is used to get the cpu frequencies for calculating the APERF/MPERF. Without it, things would still work, but the averge cpufrequency output would be wrong. My 8th & 10th gen test systems both report: (XEN) HWP: 1 notify: 1 act_window: 1 energy_perf: 1 pkg_level: 0 peci: 0 (XEN) HWP: Hardware Duty Cycling (HDC) supported (XEN) HWP: HW_FEEDBACK not supported IA32_ENERGY_PERF_BIAS has not been tested. For cpufreq=3Dxen:hwp, placing the option inside the governor wouldn't work. Users would have to select the hwp-internal governor to turn off hwp support. hwp-internal isn't usable without hwp, and users wouldn't be able to select a different governor. That doesn't matter while hwp defaults off, but it would if or when hwp defaults to enabled. We can't use parse_boolean() since it requires a single name=3Dval string and cpufreq_handle_common_option is provided two strings. Use parse_bool() and manual handle no-hwp. Write to disable the interrupt - the linux pstate driver does this. We don't use the interrupts, so we can just turn them off. We aren't ready to handle them, so we don't want any. Unclear if this is necessary. SDM says it's default disabled. FAST_IA32_HWP_REQUEST was removed in v2. The check in v1 was wrong, it's a model specific feature and the CPUID bit is only available after enabling via the MSR. Support was untested since I don't have hardware with the feature. Writes are expected to be infrequent, so just leave it out. --- v2: Alphabetize headers Re-work driver registration name hwp_drv_data anonymous union "hw" Drop hwp_verbose_cont style cleanups Condense hwp_governor switch hwp_cpufreq_target remove .raw from hwp_req assignment Use typed-pointer in a few functions Pass type to xzalloc Add HWP_ENERGY_PERF_BALANCE/IA32_ENERGY_BIAS_BALANCE defines Add XEN_HWP_GOVERNOR define for "hwp-internal" Capitalize CPUID and MSR defines Change '_' to '-' for energy-perf & act-window Read-modify-write MSRs updates Use FAST_IA32_HWP_REQUEST_MSR_ENABLE define constify pointer in hwp_set_misc_turbo Add space after non-fallthrough break in governor switch Add IA32_ENERGY_BIAS_MASK define Check CPUID_PM_LEAK for energy bias when needed Fail initialization with curr_req =3D -1 Fold hwp_read_capabilities into hwp_init_msrs Add command line cpufreq=3Dxen:hwp Add command line cpufreq=3Dxen:hdc Use per_cpu for hwp_drv_data pointers Move hwp_energy_perf_bias call into hwp_write_request energy_perf 0 is valid, so hwp_energy_perf_bias cannot be skipped Ensure we don't generate interrupts Remove Fast Write of Uncore MSR Initialize hwp_drv_data from curr_req Use SPDX line instead of license text in hwp.c v3: Add cf_check to cpufreq_gov_hwp_init() - Marek Print cpuid_level with %#x - Marek --- docs/misc/xen-command-line.pandoc | 8 +- xen/arch/x86/acpi/cpufreq/Makefile | 1 + xen/arch/x86/acpi/cpufreq/cpufreq.c | 5 +- xen/arch/x86/acpi/cpufreq/hwp.c | 506 ++++++++++++++++++++++ xen/arch/x86/include/asm/cpufeature.h | 13 +- xen/arch/x86/include/asm/msr-index.h | 13 + xen/drivers/cpufreq/cpufreq.c | 32 ++ xen/include/acpi/cpufreq/cpufreq.h | 3 + xen/include/acpi/cpufreq/processor_perf.h | 3 + xen/include/public/sysctl.h | 1 + 10 files changed, 581 insertions(+), 4 deletions(-) create mode 100644 xen/arch/x86/acpi/cpufreq/hwp.c diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line= .pandoc index e0b89b7d33..aaa31f444b 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -499,7 +499,7 @@ If set, force use of the performance counters for oprof= ile, rather than detectin available support. =20 ### cpufreq -> `=3D none | {{ | xen } [:[powersave|performance|ondemand|users= pace][,][,[][,[verbose]]]]} | dom0-kernel` +> `=3D none | {{ | xen } [:[powersave|performance|ondemand|users= pace][,][,[]][,[]][,[]][,[verbose]]]} | dom0-ke= rnel` =20 > Default: `xen` =20 @@ -510,6 +510,12 @@ choice of `dom0-kernel` is deprecated and not supporte= d by all Dom0 kernels. * `` and `` are integers which represent max and min pro= cessor frequencies respectively. * `verbose` option can be included as a string or also as `verbose=3D` +* `` is a boolean to enable Hardware-Controlled Performance States (H= WP) + on supported Intel hardware. HWP is a Skylake+ feature which provides b= etter + CPU power management. The default is disabled. +* `` is a boolean to enable Hardware Duty Cycling (HDC). HDC enables= the + processor to autonomously force physical package components into idle st= ate. + The default is enabled, but the option only applies when `` is enab= led. =20 ### cpuid (x86) > `=3D List of comma separated booleans` diff --git a/xen/arch/x86/acpi/cpufreq/Makefile b/xen/arch/x86/acpi/cpufreq= /Makefile index f75da9b9ca..db83aa6b14 100644 --- a/xen/arch/x86/acpi/cpufreq/Makefile +++ b/xen/arch/x86/acpi/cpufreq/Makefile @@ -1,2 +1,3 @@ obj-y +=3D cpufreq.o +obj-y +=3D hwp.o obj-y +=3D powernow.o diff --git a/xen/arch/x86/acpi/cpufreq/cpufreq.c b/xen/arch/x86/acpi/cpufre= q/cpufreq.c index f1cc473b4f..56816b1aee 100644 --- a/xen/arch/x86/acpi/cpufreq/cpufreq.c +++ b/xen/arch/x86/acpi/cpufreq/cpufreq.c @@ -642,7 +642,10 @@ static int __init cf_check cpufreq_driver_init(void) switch ( boot_cpu_data.x86_vendor ) { case X86_VENDOR_INTEL: - ret =3D cpufreq_register_driver(&acpi_cpufreq_driver); + if ( hwp_available() ) + ret =3D hwp_register_driver(); + else + ret =3D cpufreq_register_driver(&acpi_cpufreq_driver); break; =20 case X86_VENDOR_AMD: diff --git a/xen/arch/x86/acpi/cpufreq/hwp.c b/xen/arch/x86/acpi/cpufreq/hw= p.c new file mode 100644 index 0000000000..57f13867d3 --- /dev/null +++ b/xen/arch/x86/acpi/cpufreq/hwp.c @@ -0,0 +1,506 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * hwp.c cpufreq driver to run Intel Hardware P-States (HWP) + * + * Copyright (C) 2021 Jason Andryuk + */ + +#include +#include +#include +#include +#include +#include +#include + +static bool feature_hwp; +static bool feature_hwp_notification; +static bool feature_hwp_activity_window; +static bool feature_hwp_energy_perf; +static bool feature_hwp_pkg_level_ctl; +static bool feature_hwp_peci; + +static bool feature_hdc; + +__initdata bool opt_cpufreq_hwp =3D false; +__initdata bool opt_cpufreq_hdc =3D true; + +#define HWP_ENERGY_PERF_BALANCE 0x80 +#define IA32_ENERGY_BIAS_BALANCE 0x7 +#define IA32_ENERGY_BIAS_MAX_POWERSAVE 0xf +#define IA32_ENERGY_BIAS_MASK 0xf + +union hwp_request +{ + struct + { + uint64_t min_perf:8; + uint64_t max_perf:8; + uint64_t desired:8; + uint64_t energy_perf:8; + uint64_t activity_window:10; + uint64_t package_control:1; + uint64_t reserved:16; + uint64_t activity_window_valid:1; + uint64_t energy_perf_valid:1; + uint64_t desired_valid:1; + uint64_t max_perf_valid:1; + uint64_t min_perf_valid:1; + }; + uint64_t raw; +}; + +struct hwp_drv_data +{ + union + { + uint64_t hwp_caps; + struct + { + uint64_t highest:8; + uint64_t guaranteed:8; + uint64_t most_efficient:8; + uint64_t lowest:8; + uint64_t reserved:32; + } hw; + }; + union hwp_request curr_req; + uint16_t activity_window; + uint8_t minimum; + uint8_t maximum; + uint8_t desired; + uint8_t energy_perf; +}; +DEFINE_PER_CPU_READ_MOSTLY(struct hwp_drv_data *, hwp_drv_data); + +#define hwp_err(...) printk(XENLOG_ERR __VA_ARGS__) +#define hwp_info(...) printk(XENLOG_INFO __VA_ARGS__) +#define hwp_verbose(...) \ +({ \ + if ( cpufreq_verbose ) \ + printk(XENLOG_DEBUG __VA_ARGS__); \ +}) + +static int cf_check hwp_governor(struct cpufreq_policy *policy, + unsigned int event) +{ + int ret; + + if ( policy =3D=3D NULL ) + return -EINVAL; + + switch ( event ) + { + case CPUFREQ_GOV_START: + case CPUFREQ_GOV_LIMITS: + ret =3D 0; + break; + + case CPUFREQ_GOV_STOP: + default: + ret =3D -EINVAL; + break; + } + + return ret; +} + +static struct cpufreq_governor hwp_cpufreq_governor =3D +{ + .name =3D XEN_HWP_GOVERNOR, + .governor =3D hwp_governor, +}; + +static int __init cf_check cpufreq_gov_hwp_init(void) +{ + return cpufreq_register_governor(&hwp_cpufreq_governor); +} +__initcall(cpufreq_gov_hwp_init); + +bool __init hwp_available(void) +{ + unsigned int eax, ecx, unused; + bool use_hwp; + + if ( boot_cpu_data.cpuid_level < CPUID_PM_LEAF ) + { + hwp_verbose("cpuid_level (%#x) lacks HWP support\n", + boot_cpu_data.cpuid_level); + return false; + } + + if ( boot_cpu_data.cpuid_level < 0x16 ) + { + hwp_info("HWP disabled: cpuid_level %#x < 0x16 lacks CPU freq info= \n", + boot_cpu_data.cpuid_level); + return false; + } + + cpuid(CPUID_PM_LEAF, &eax, &unused, &ecx, &unused); + + if ( !(eax & CPUID6_EAX_HWP_ENERGY_PERFORMANCE_PREFERENCE) && + !(ecx & CPUID6_ECX_IA32_ENERGY_PERF_BIAS) ) + { + hwp_verbose("HWP disabled: No energy/performance preference availa= ble"); + return false; + } + + feature_hwp =3D eax & CPUID6_EAX_HWP; + feature_hwp_notification =3D eax & CPUID6_EAX_HWP_NOTIFICATION; + feature_hwp_activity_window =3D eax & CPUID6_EAX_HWP_ACTIVITY_WINDOW; + feature_hwp_energy_perf =3D + eax & CPUID6_EAX_HWP_ENERGY_PERFORMANCE_PREFERENCE; + feature_hwp_pkg_level_ctl =3D eax & CPUID6_EAX_HWP_PACKAGE_LEVEL_REQ= UEST; + feature_hwp_peci =3D eax & CPUID6_EAX_HWP_PECI; + + hwp_verbose("HWP: %d notify: %d act-window: %d energy-perf: %d pkg-lev= el: %d peci: %d\n", + feature_hwp, feature_hwp_notification, + feature_hwp_activity_window, feature_hwp_energy_perf, + feature_hwp_pkg_level_ctl, feature_hwp_peci); + + if ( !feature_hwp ) + return false; + + feature_hdc =3D eax & CPUID6_EAX_HDC; + + hwp_verbose("HWP: Hardware Duty Cycling (HDC) %ssupported%s\n", + feature_hdc ? "" : "not ", + feature_hdc ? opt_cpufreq_hdc ? ", enabled" : ", disabled" + : ""); + + feature_hdc =3D feature_hdc && opt_cpufreq_hdc; + + hwp_verbose("HWP: HW_FEEDBACK %ssupported\n", + (eax & CPUID6_EAX_HW_FEEDBACK) ? "" : "not "); + + use_hwp =3D feature_hwp && opt_cpufreq_hwp; + cpufreq_governor_internal =3D use_hwp; + + if ( use_hwp ) + hwp_info("Using HWP for cpufreq\n"); + + return use_hwp; +} + +static void hdc_set_pkg_hdc_ctl(bool val) +{ + uint64_t msr; + + if ( rdmsr_safe(MSR_IA32_PKG_HDC_CTL, msr) ) + { + hwp_err("error rdmsr_safe(MSR_IA32_PKG_HDC_CTL)\n"); + + return; + } + + if ( val ) + msr |=3D IA32_PKG_HDC_CTL_HDC_PKG_ENABLE; + else + msr &=3D ~IA32_PKG_HDC_CTL_HDC_PKG_ENABLE; + + if ( wrmsr_safe(MSR_IA32_PKG_HDC_CTL, msr) ) + hwp_err("error wrmsr_safe(MSR_IA32_PKG_HDC_CTL): %016lx\n", msr); +} + +static void hdc_set_pm_ctl1(bool val) +{ + uint64_t msr; + + if ( rdmsr_safe(MSR_IA32_PM_CTL1, msr) ) + { + hwp_err("error rdmsr_safe(MSR_IA32_PM_CTL1)\n"); + + return; + } + + if ( val ) + msr |=3D IA32_PM_CTL1_HDC_ALLOW_BLOCK; + else + msr &=3D ~IA32_PM_CTL1_HDC_ALLOW_BLOCK; + + if ( wrmsr_safe(MSR_IA32_PM_CTL1, msr) ) + hwp_err("error wrmsr_safe(MSR_IA32_PM_CTL1): %016lx\n", msr); +} + +static void hwp_get_cpu_speeds(struct cpufreq_policy *policy) +{ + uint32_t base_khz, max_khz, bus_khz, edx; + + cpuid(0x16, &base_khz, &max_khz, &bus_khz, &edx); + + /* aperf/mperf scales base. */ + policy->cpuinfo.perf_freq =3D base_khz * 1000; + policy->cpuinfo.min_freq =3D base_khz * 1000; + policy->cpuinfo.max_freq =3D max_khz * 1000; + policy->min =3D base_khz * 1000; + policy->max =3D max_khz * 1000; + policy->cur =3D 0; +} + +static void cf_check hwp_init_msrs(void *info) +{ + struct cpufreq_policy *policy =3D info; + struct hwp_drv_data *data =3D this_cpu(hwp_drv_data); + uint64_t val; + + /* + * Package level MSR, but we don't have a good idea of packages here, = so + * just do it everytime. + */ + if ( rdmsr_safe(MSR_IA32_PM_ENABLE, val) ) + { + hwp_err("CPU%u: error rdmsr_safe(MSR_IA32_PM_ENABLE)\n", policy->c= pu); + data->curr_req.raw =3D -1; + return; + } + + /* Ensure we don't generate interrupts */ + if ( feature_hwp_notification ) + wrmsr_safe(MSR_IA32_HWP_INTERRUPT, 0); + + hwp_verbose("CPU%u: MSR_IA32_PM_ENABLE: %016lx\n", policy->cpu, val); + if ( !(val & IA32_PM_ENABLE_HWP_ENABLE) ) + { + val |=3D IA32_PM_ENABLE_HWP_ENABLE; + if ( wrmsr_safe(MSR_IA32_PM_ENABLE, val) ) + { + hwp_err("CPU%u: error wrmsr_safe(MSR_IA32_PM_ENABLE, %lx)\n", + policy->cpu, val); + data->curr_req.raw =3D -1; + return; + } + } + + if ( rdmsr_safe(MSR_IA32_HWP_CAPABILITIES, data->hwp_caps) ) + { + hwp_err("CPU%u: error rdmsr_safe(MSR_IA32_HWP_CAPABILITIES)\n", + policy->cpu); + data->curr_req.raw =3D -1; + return; + } + + if ( rdmsr_safe(MSR_IA32_HWP_REQUEST, data->curr_req.raw) ) + { + hwp_err("CPU%u: error rdmsr_safe(MSR_IA32_HWP_REQUEST)\n", policy-= >cpu); + data->curr_req.raw =3D -1; + return; + } + + if ( !feature_hwp_energy_perf ) { + if ( rdmsr_safe(MSR_IA32_ENERGY_PERF_BIAS, val) ) + { + hwp_err("error rdmsr_safe(MSR_IA32_ENERGY_PERF_BIAS)\n"); + data->curr_req.raw =3D -1; + + return; + } + + data->energy_perf =3D val & IA32_ENERGY_BIAS_MASK; + } + + /* + * Check for APERF/MPERF support in hardware + * also check for boost/turbo support + */ + intel_feature_detect(policy); + + if ( feature_hdc ) + { + hdc_set_pkg_hdc_ctl(true); + hdc_set_pm_ctl1(true); + } + + hwp_get_cpu_speeds(policy); +} + +static int cf_check hwp_cpufreq_verify(struct cpufreq_policy *policy) +{ + struct hwp_drv_data *data =3D per_cpu(hwp_drv_data, policy->cpu); + + if ( !feature_hwp_energy_perf && data->energy_perf ) + { + if ( data->energy_perf > IA32_ENERGY_BIAS_MAX_POWERSAVE ) + { + hwp_err("energy_perf %d exceeds IA32_ENERGY_PERF_BIAS range 0-= 15\n", + data->energy_perf); + + return -EINVAL; + } + } + + if ( !feature_hwp_activity_window && data->activity_window ) + { + hwp_err("HWP activity window not supported\n"); + + return -EINVAL; + } + + return 0; +} + +/* val 0 - highest performance, 15 - maximum energy savings */ +static void hwp_energy_perf_bias(const struct hwp_drv_data *data) +{ + uint64_t msr; + uint8_t val =3D data->energy_perf; + + ASSERT(val <=3D IA32_ENERGY_BIAS_MAX_POWERSAVE); + + if ( rdmsr_safe(MSR_IA32_ENERGY_PERF_BIAS, msr) ) + { + hwp_err("error rdmsr_safe(MSR_IA32_ENERGY_PERF_BIAS)\n"); + + return; + } + + msr &=3D ~IA32_ENERGY_BIAS_MASK; + msr |=3D val; + + if ( wrmsr_safe(MSR_IA32_ENERGY_PERF_BIAS, msr) ) + hwp_err("error wrmsr_safe(MSR_IA32_ENERGY_PERF_BIAS): %016lx\n", m= sr); +} + +static void cf_check hwp_write_request(void *info) +{ + struct cpufreq_policy *policy =3D info; + struct hwp_drv_data *data =3D this_cpu(hwp_drv_data); + union hwp_request hwp_req =3D data->curr_req; + + BUILD_BUG_ON(sizeof(union hwp_request) !=3D sizeof(uint64_t)); + if ( wrmsr_safe(MSR_IA32_HWP_REQUEST, hwp_req.raw) ) + { + hwp_err("CPU%u: error wrmsr_safe(MSR_IA32_HWP_REQUEST, %lx)\n", + policy->cpu, hwp_req.raw); + rdmsr_safe(MSR_IA32_HWP_REQUEST, data->curr_req.raw); + } + + if ( !feature_hwp_energy_perf ) + hwp_energy_perf_bias(data); + +} + +static int cf_check hwp_cpufreq_target(struct cpufreq_policy *policy, + unsigned int target_freq, + unsigned int relation) +{ + unsigned int cpu =3D policy->cpu; + struct hwp_drv_data *data =3D per_cpu(hwp_drv_data, cpu); + /* Zero everything to ensure reserved bits are zero... */ + union hwp_request hwp_req =3D { .raw =3D 0 }; + + /* .. and update from there */ + hwp_req.min_perf =3D data->minimum; + hwp_req.max_perf =3D data->maximum; + hwp_req.desired =3D data->desired; + if ( feature_hwp_energy_perf ) + hwp_req.energy_perf =3D data->energy_perf; + if ( feature_hwp_activity_window ) + hwp_req.activity_window =3D data->activity_window; + + if ( hwp_req.raw =3D=3D data->curr_req.raw ) + return 0; + + data->curr_req =3D hwp_req; + + hwp_verbose("CPU%u: wrmsr HWP_REQUEST %016lx\n", cpu, hwp_req.raw); + on_selected_cpus(cpumask_of(cpu), hwp_write_request, policy, 1); + + return 0; +} + +static int cf_check hwp_cpufreq_cpu_init(struct cpufreq_policy *policy) +{ + unsigned int cpu =3D policy->cpu; + struct hwp_drv_data *data; + + data =3D xzalloc(struct hwp_drv_data); + if ( !data ) + return -ENOMEM; + + if ( cpufreq_opt_governor ) + printk(XENLOG_WARNING + "HWP: governor \"%s\" is incompatible with hwp. Using defau= lt \"%s\"\n", + cpufreq_opt_governor->name, hwp_cpufreq_governor.name); + policy->governor =3D &hwp_cpufreq_governor; + + per_cpu(hwp_drv_data, cpu) =3D data; + + on_selected_cpus(cpumask_of(cpu), hwp_init_msrs, policy, 1); + + if ( data->curr_req.raw =3D=3D -1 ) + { + hwp_err("CPU%u: Could not initialize HWP properly\n", cpu); + XFREE(per_cpu(hwp_drv_data, cpu)); + return -ENODEV; + } + + data->minimum =3D data->curr_req.min_perf; + data->maximum =3D data->curr_req.max_perf; + data->desired =3D data->curr_req.desired; + /* the !feature_hwp_energy_perf case was handled in hwp_init_msrs(). */ + if ( feature_hwp_energy_perf ) + data->energy_perf =3D data->curr_req.energy_perf; + + hwp_verbose("CPU%u: IA32_HWP_CAPABILITIES: %016lx\n", cpu, data->hwp_c= aps); + + hwp_verbose("CPU%u: rdmsr HWP_REQUEST %016lx\n", cpu, data->curr_req.r= aw); + + return 0; +} + +static int cf_check hwp_cpufreq_cpu_exit(struct cpufreq_policy *policy) +{ + XFREE(per_cpu(hwp_drv_data, policy->cpu)); + + return 0; +} + +/* + * The SDM reads like turbo should be disabled with MSR_IA32_PERF_CTL and + * PERF_CTL_TURBO_DISENGAGE, but that does not seem to actually work, at l= east + * with my HWP testing. MSR_IA32_MISC_ENABLE and MISC_ENABLE_TURBO_DISENG= AGE + * is what Linux uses and seems to work. + */ +static void cf_check hwp_set_misc_turbo(void *info) +{ + const struct cpufreq_policy *policy =3D info; + uint64_t msr; + + if ( rdmsr_safe(MSR_IA32_MISC_ENABLE, msr) ) + { + hwp_err("CPU%u: error rdmsr_safe(MSR_IA32_MISC_ENABLE)\n", policy-= >cpu); + + return; + } + + if ( policy->turbo =3D=3D CPUFREQ_TURBO_ENABLED ) + msr &=3D ~MSR_IA32_MISC_ENABLE_TURBO_DISENGAGE; + else + msr |=3D MSR_IA32_MISC_ENABLE_TURBO_DISENGAGE; + + if ( wrmsr_safe(MSR_IA32_MISC_ENABLE, msr) ) + hwp_err("CPU%u: error wrmsr_safe(MSR_IA32_MISC_ENABLE): %016lx\n", + policy->cpu, msr); +} + +static int cf_check hwp_cpufreq_update(int cpuid, struct cpufreq_policy *p= olicy) +{ + on_selected_cpus(cpumask_of(cpuid), hwp_set_misc_turbo, policy, 1); + + return 0; +} + +static const struct cpufreq_driver __initconstrel hwp_cpufreq_driver =3D +{ + .name =3D "hwp-cpufreq", + .verify =3D hwp_cpufreq_verify, + .target =3D hwp_cpufreq_target, + .init =3D hwp_cpufreq_cpu_init, + .exit =3D hwp_cpufreq_cpu_exit, + .update =3D hwp_cpufreq_update, +}; + +int __init hwp_register_driver(void) +{ + return cpufreq_register_driver(&hwp_cpufreq_driver); +} diff --git a/xen/arch/x86/include/asm/cpufeature.h b/xen/arch/x86/include/a= sm/cpufeature.h index 4140ec0938..f2ff1d5fde 100644 --- a/xen/arch/x86/include/asm/cpufeature.h +++ b/xen/arch/x86/include/asm/cpufeature.h @@ -46,8 +46,17 @@ extern struct cpuinfo_x86 boot_cpu_data; #define cpu_has(c, bit) test_bit(bit, (c)->x86_capability) #define boot_cpu_has(bit) test_bit(bit, boot_cpu_data.x86_capability) =20 -#define CPUID_PM_LEAF 6 -#define CPUID6_ECX_APERFMPERF_CAPABILITY 0x1 +#define CPUID_PM_LEAF 6 +#define CPUID6_EAX_HWP (_AC(1, U) << 7) +#define CPUID6_EAX_HWP_NOTIFICATION (_AC(1, U) << 8) +#define CPUID6_EAX_HWP_ACTIVITY_WINDOW (_AC(1, U) << 9) +#define CPUID6_EAX_HWP_ENERGY_PERFORMANCE_PREFERENCE (_AC(1, U) << 10) +#define CPUID6_EAX_HWP_PACKAGE_LEVEL_REQUEST (_AC(1, U) << 11) +#define CPUID6_EAX_HDC (_AC(1, U) << 13) +#define CPUID6_EAX_HWP_PECI (_AC(1, U) << 16) +#define CPUID6_EAX_HW_FEEDBACK (_AC(1, U) << 19) +#define CPUID6_ECX_APERFMPERF_CAPABILITY 0x1 +#define CPUID6_ECX_IA32_ENERGY_PERF_BIAS 0x8 =20 /* CPUID level 0x00000001.edx */ #define cpu_has_fpu 1 diff --git a/xen/arch/x86/include/asm/msr-index.h b/xen/arch/x86/include/as= m/msr-index.h index fa771ed0b5..a2a22339e4 100644 --- a/xen/arch/x86/include/asm/msr-index.h +++ b/xen/arch/x86/include/asm/msr-index.h @@ -151,6 +151,13 @@ =20 #define MSR_PKRS 0x000006e1 =20 +#define MSR_IA32_PM_ENABLE 0x00000770 +#define IA32_PM_ENABLE_HWP_ENABLE (_AC(1, ULL) << 0) + +#define MSR_IA32_HWP_CAPABILITIES 0x00000771 +#define MSR_IA32_HWP_INTERRUPT 0x00000773 +#define MSR_IA32_HWP_REQUEST 0x00000774 + #define MSR_X2APIC_FIRST 0x00000800 #define MSR_X2APIC_LAST 0x000008ff =20 @@ -165,6 +172,11 @@ #define PASID_PASID_MASK 0x000fffff #define PASID_VALID (_AC(1, ULL) << 31) =20 +#define MSR_IA32_PKG_HDC_CTL 0x00000db0 +#define IA32_PKG_HDC_CTL_HDC_PKG_ENABLE (_AC(1, ULL) << 0) +#define MSR_IA32_PM_CTL1 0x00000db1 +#define IA32_PM_CTL1_HDC_ALLOW_BLOCK (_AC(1, ULL) << 0) + #define MSR_UARCH_MISC_CTRL 0x00001b01 #define UARCH_CTRL_DOITM (_AC(1, ULL) << 0) =20 @@ -500,6 +512,7 @@ #define MSR_IA32_MISC_ENABLE_LIMIT_CPUID (1<<22) #define MSR_IA32_MISC_ENABLE_XTPR_DISABLE (1<<23) #define MSR_IA32_MISC_ENABLE_XD_DISABLE (1ULL << 34) +#define MSR_IA32_MISC_ENABLE_TURBO_DISENGAGE (1ULL << 38) =20 #define MSR_IA32_TSC_DEADLINE 0x000006E0 #define MSR_IA32_ENERGY_PERF_BIAS 0x000001b0 diff --git a/xen/drivers/cpufreq/cpufreq.c b/xen/drivers/cpufreq/cpufreq.c index 7bd81680da..9470eb7230 100644 --- a/xen/drivers/cpufreq/cpufreq.c +++ b/xen/drivers/cpufreq/cpufreq.c @@ -565,6 +565,38 @@ static void cpufreq_cmdline_common_para(struct cpufreq= _policy *new_policy) =20 static int __init cpufreq_handle_common_option(const char *name, const cha= r *val) { + if (!strcmp(name, "hdc")) { + if (val) { + int ret =3D parse_bool(val, NULL); + if (ret !=3D -1) { + opt_cpufreq_hdc =3D ret; + return 1; + } + } else { + opt_cpufreq_hdc =3D true; + return 1; + } + } else if (!strcmp(name, "no-hdc")) { + opt_cpufreq_hdc =3D false; + return 1; + } + + if (!strcmp(name, "hwp")) { + if (val) { + int ret =3D parse_bool(val, NULL); + if (ret !=3D -1) { + opt_cpufreq_hwp =3D ret; + return 1; + } + } else { + opt_cpufreq_hwp =3D true; + return 1; + } + } else if (!strcmp(name, "no-hwp")) { + opt_cpufreq_hwp =3D false; + return 1; + } + if (!strcmp(name, "maxfreq") && val) { usr_max_freq =3D simple_strtoul(val, NULL, 0); return 1; diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/= cpufreq.h index 0f334d2a43..29a712a4f1 100644 --- a/xen/include/acpi/cpufreq/cpufreq.h +++ b/xen/include/acpi/cpufreq/cpufreq.h @@ -245,4 +245,7 @@ void cpufreq_dbs_timer_resume(void); =20 void intel_feature_detect(struct cpufreq_policy *policy); =20 +extern bool opt_cpufreq_hwp; +extern bool opt_cpufreq_hdc; + #endif /* __XEN_CPUFREQ_PM_H__ */ diff --git a/xen/include/acpi/cpufreq/processor_perf.h b/xen/include/acpi/c= pufreq/processor_perf.h index d8a1ba68a6..b751ca4937 100644 --- a/xen/include/acpi/cpufreq/processor_perf.h +++ b/xen/include/acpi/cpufreq/processor_perf.h @@ -7,6 +7,9 @@ =20 #define XEN_PX_INIT 0x80000000 =20 +bool hwp_available(void); +int hwp_register_driver(void); + int powernow_cpufreq_init(void); unsigned int powernow_register_driver(void); unsigned int get_measured_perf(unsigned int cpu, unsigned int flag); diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index 2b24d6bfd0..b448f13b75 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -292,6 +292,7 @@ struct xen_ondemand { uint32_t up_threshold; }; =20 +#define XEN_HWP_GOVERNOR "hwp-internal" /* * cpufreq para name of this structure named * same as sysfs file name of native linux --=20 2.40.0 From nobody Sun May 19 15:58:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1682969492; cv=none; d=zohomail.com; s=zohoarc; b=ejzl988lA6wIRtF8Csu/wtEfpdYeikTOHPSrP9CO5L1J3i2q8AhjXxLvUud+mplD+Wn+hUmUafhgFmmc4IKfwsbm11OADwJI0Z4VMEwDyeqFZwW0y9JSz+00R3H49CywUv3jCwlL9hBb3ENkLeQ29B41V7CZJjEd+Dk8Ako/Ir8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682969492; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hA8U/InM9EEJxsTtEJ4pQE8Dle8MV2Sm7m6DjaGLFBw=; b=dUhLo50FWnI4iLipw/tvuDVJngoBATbre/VuFzQNRtS2RPUh0ZntIzZa08Z/UdURcYElqAIcl1J3++eWWl8x3e23+0unU/0qOSAIwSqnWnxRoL28+Co4mY4hFjIrf6304KIe80ETbslGPKwA/4N/ke9FZhuAdt9+b1MFBEaYc7w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1682969492536941.0129453522042; Mon, 1 May 2023 12:31:32 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.528107.820907 (Exim 4.92) (envelope-from ) id 1ptZEl-0002dr-Tn; Mon, 01 May 2023 19:31:03 +0000 Received: by outflank-mailman (output) from mailman id 528107.820907; Mon, 01 May 2023 19:31:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptZEl-0002dg-OU; Mon, 01 May 2023 19:31:03 +0000 Received: by outflank-mailman (input) for mailman id 528107; Mon, 01 May 2023 19:31:03 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptZEk-000149-UP for xen-devel@lists.xenproject.org; Mon, 01 May 2023 19:31:02 +0000 Received: from mail-qt1-x833.google.com (mail-qt1-x833.google.com [2607:f8b0:4864:20::833]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b44a29e3-e856-11ed-8611-37d641c3527e; Mon, 01 May 2023 21:31:01 +0200 (CEST) Received: by mail-qt1-x833.google.com with SMTP id d75a77b69052e-3ef64d8b2b4so13236131cf.2 for ; Mon, 01 May 2023 12:31:01 -0700 (PDT) Received: from pm2-ws13.praxislan02.com (207-172-141-204.s8906.c3-0.slvr-cbr1.lnh-slvr.md.cable.rcncustomer.com. [207.172.141.204]) by smtp.gmail.com with ESMTPSA id d6-20020ac80606000000b003bf9f9f1844sm9351784qth.71.2023.05.01.12.30.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 12:30:59 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b44a29e3-e856-11ed-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682969460; x=1685561460; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hA8U/InM9EEJxsTtEJ4pQE8Dle8MV2Sm7m6DjaGLFBw=; b=cqYdElAgv017E/RPw2IfPj2RWa7HBP5wPUoivkXxfKl7Wcrhcl0iwOuzZphMkXGrmq wXCkHA8JltP+awApYh8wW61giM/5P2zyNIoHj3q9YmwRfaTUXFVZakg8TrC8FV/WoDGZ mo9IaeB6VUPChzAspWP9VcAsfV+TlO8Y/3cNML4q+Pu36JsDdpapVSvhvzxmzur3X5kb iYsf3odUJqBk7a9Ou/Bf4vu/nG3w22mo0+ol5vCDLc5dYSOaknjfd3TwNd4KjydszEDR jyy1FovHqAsAjtuqX9giS6oKxRxgZXnd68neZX3LzXl3USX2N/zFujA6OIMOGGjtAGZz xCkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682969460; x=1685561460; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hA8U/InM9EEJxsTtEJ4pQE8Dle8MV2Sm7m6DjaGLFBw=; b=lymf5mbhwTrLPRooCSX7O3oPwZlGnMHiAdCT5aleAen8xbkQ3ahlWEqgWp2HASkWKZ Tf6aTDH/6VnBlmZG1Oum6xHimWPpMW9AulbOs+TJXMfpxhg8Rps/oM6HPJdJGmoOLd5W zJ1iXp6Wg2/4P9chlZD0SfusTNpqEDDLhRbBmnrUEFQML//lMBmgrfnmRBNlNCgz8A7J 10htRuiX5GmIJMtq9fDJinNlyt69NjVjb4GOsGOHKfuH4z5KPvZfvA0iRIy9v4F9oZ57 wxlxmvF/1yjJL192Hmt0oG+DXa+q48XuDm1tVUerdQ9A0Dt6Lxxo6D6HJBzX409YbeO7 zIDw== X-Gm-Message-State: AC+VfDxn7qAj80dvYOzVdxfsbUfBEGwBYyBRr4iwtY5XgUxrH4NivQVW MVKSSioemicMgE0WJBn/SdZg6aIbCPA= X-Google-Smtp-Source: ACHHUZ56JSvdUTnYPJIqqSMnTeyqiLw1eNi/3MYuwdvmwUt+ZTaf7S1mFfukjjdCf4lp2bgDkUEqQQ== X-Received: by 2002:ac8:5f54:0:b0:3e4:3f79:9d7b with SMTP id y20-20020ac85f54000000b003e43f799d7bmr23571957qta.55.1682969459739; Mon, 01 May 2023 12:30:59 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Wei Liu , Anthony PERARD Subject: [PATCH v3 05/14 RESEND] xenpm: Change get-cpufreq-para output for internal Date: Mon, 1 May 2023 15:30:25 -0400 Message-Id: <20230501193034.88575-6-jandryuk@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230501193034.88575-1-jandryuk@gmail.com> References: <20230501193034.88575-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1682969494191100001 Content-Type: text/plain; charset="utf-8" When using HWP, some of the returned data is not applicable. In that case, we should just omit it to avoid confusing the user. So switch to printing the base and turbo frequencies since those are relevant to HWP. Similarly, stop printing the CPU frequencies since those do not apply. Signed-off-by: Jason Andryuk --- v2: Use full governor name XEN_HWP_GOVERNOR to change output Style fixes --- tools/misc/xenpm.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index 1bb6187e56..ce8d7644d0 100644 --- a/tools/misc/xenpm.c +++ b/tools/misc/xenpm.c @@ -711,6 +711,7 @@ void start_gather_func(int argc, char *argv[]) /* print out parameters about cpu frequency */ static void print_cpufreq_para(int cpuid, struct xc_get_cpufreq_para *p_cp= ufreq) { + bool internal =3D strstr(p_cpufreq->scaling_governor, XEN_HWP_GOVERNOR= ); int i; =20 printf("cpu id : %d\n", cpuid); @@ -720,10 +721,15 @@ static void print_cpufreq_para(int cpuid, struct xc_g= et_cpufreq_para *p_cpufreq) printf(" %d", p_cpufreq->affected_cpus[i]); printf("\n"); =20 - printf("cpuinfo frequency : max [%u] min [%u] cur [%u]\n", - p_cpufreq->cpuinfo_max_freq, - p_cpufreq->cpuinfo_min_freq, - p_cpufreq->cpuinfo_cur_freq); + if ( internal ) + printf("cpuinfo frequency : base [%u] turbo [%u]\n", + p_cpufreq->cpuinfo_min_freq, + p_cpufreq->cpuinfo_max_freq); + else + printf("cpuinfo frequency : max [%u] min [%u] cur [%u]\n", + p_cpufreq->cpuinfo_max_freq, + p_cpufreq->cpuinfo_min_freq, + p_cpufreq->cpuinfo_cur_freq); =20 printf("scaling_driver : %s\n", p_cpufreq->scaling_driver); =20 @@ -750,19 +756,22 @@ static void print_cpufreq_para(int cpuid, struct xc_g= et_cpufreq_para *p_cpufreq) p_cpufreq->u.ondemand.up_threshold); } =20 - printf("scaling_avail_freq :"); - for ( i =3D 0; i < p_cpufreq->freq_num; i++ ) - if ( p_cpufreq->scaling_available_frequencies[i] =3D=3D - p_cpufreq->scaling_cur_freq ) - printf(" *%d", p_cpufreq->scaling_available_frequencies[i]); - else - printf(" %d", p_cpufreq->scaling_available_frequencies[i]); - printf("\n"); + if ( !internal ) + { + printf("scaling_avail_freq :"); + for ( i =3D 0; i < p_cpufreq->freq_num; i++ ) + if ( p_cpufreq->scaling_available_frequencies[i] =3D=3D + p_cpufreq->scaling_cur_freq ) + printf(" *%d", p_cpufreq->scaling_available_frequencies[i]= ); + else + printf(" %d", p_cpufreq->scaling_available_frequencies[i]); + printf("\n"); =20 - printf("scaling frequency : max [%u] min [%u] cur [%u]\n", - p_cpufreq->scaling_max_freq, - p_cpufreq->scaling_min_freq, - p_cpufreq->scaling_cur_freq); + printf("scaling frequency : max [%u] min [%u] cur [%u]\n", + p_cpufreq->scaling_max_freq, + p_cpufreq->scaling_min_freq, + p_cpufreq->scaling_cur_freq); + } =20 printf("turbo mode : %s\n", p_cpufreq->turbo_enabled ? "enabled" : "disabled or n/a"); --=20 2.40.0 From nobody Sun May 19 15:58:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1682969493; cv=none; d=zohomail.com; s=zohoarc; b=DLrabV71spluXShGb9zwQ2fuslB+8s6O2fbKQpvQNWAYOwNH8xyn2rJc1H4jGL6Rp3SMLKxlYpM+5ORoy/TIIHnYXRLWJQo9ax8yeirxxKpdqeotfxdzARuGHsGs3aWLypoaLr5wgn5dAOZcCkS1XZ17nAH4/2ieU9UORLIBJI4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682969493; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AClKrOg8M97t4+1HhqAtzZODxTQ5H9SUOQWpW1JlGKM=; b=axDuzLSR8D4o9h8BG3/0c0VhSI+B+i5Kb6tmoBT1tRsll9Z6eE0MJ7FeEW7fuXrhc3iATjV418XjkHZQWdo5UeODwuyHyy18OEem5RI87kDj4EQd71FcwziaaUdHrNMuAVrKjOXEoopNqGWIpkDrF2m2Snp987YDM5J/CwNvuwU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1682969493986142.91472154304495; Mon, 1 May 2023 12:31:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.528109.820917 (Exim 4.92) (envelope-from ) id 1ptZEp-00036m-5I; Mon, 01 May 2023 19:31:07 +0000 Received: by outflank-mailman (output) from mailman id 528109.820917; Mon, 01 May 2023 19:31:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptZEp-00036X-1N; Mon, 01 May 2023 19:31:07 +0000 Received: by outflank-mailman (input) for mailman id 528109; Mon, 01 May 2023 19:31:06 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptZEo-000149-3A for xen-devel@lists.xenproject.org; Mon, 01 May 2023 19:31:06 +0000 Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [2607:f8b0:4864:20::82f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b61e0f36-e856-11ed-8611-37d641c3527e; Mon, 01 May 2023 21:31:04 +0200 (CEST) Received: by mail-qt1-x82f.google.com with SMTP id d75a77b69052e-3ef38bea86aso13223701cf.3 for ; Mon, 01 May 2023 12:31:04 -0700 (PDT) Received: from pm2-ws13.praxislan02.com (207-172-141-204.s8906.c3-0.slvr-cbr1.lnh-slvr.md.cable.rcncustomer.com. [207.172.141.204]) by smtp.gmail.com with ESMTPSA id d6-20020ac80606000000b003bf9f9f1844sm9351784qth.71.2023.05.01.12.31.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 12:31:02 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b61e0f36-e856-11ed-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682969463; x=1685561463; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AClKrOg8M97t4+1HhqAtzZODxTQ5H9SUOQWpW1JlGKM=; b=YaGuiAS9skGtNqMMYIs2izeJbZk9tjGRToKR7izraEPPKc5z3vDnPbYPZTMX9SPIu2 9hEoyC+hQrBI0Au9ULyOsD0lzBzqhfpe3fmOUvtwsKoqOyiyRWgcObksuugY0iJ/6oJo Gr2bq0+Qr7BpDyDnjjtIaOqmt+9IImpmB/tmGF3TWsDBKlNezlhRfW5UV6vIAOF420WE K+ll91Lxlyg8ArMyp5vI/yJi3DnXpPzdn3IEmd4Xpp6BBLZCDpX5lPNO2kh1XAl2iheK /NBX+Vgt+eOocF/A2c26q8nSO5AerNn+zRDoWvx8Ptzxx08z1cJ6vk8JpTjfJXFP3xLA 1Brg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682969463; x=1685561463; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AClKrOg8M97t4+1HhqAtzZODxTQ5H9SUOQWpW1JlGKM=; b=JQzUmKQCSJEEMvwUz/pBRyC3rWy0SooUxZfQOsmzq78sB0DNGnstGgUcK4ZvhKpE6v RwNwYzaRcJDHwYBxp7ZaCCMMVzxdEGNAi5Fksz8pjbRFcjux9pdkpwaUNZv0qDyh/vOq jcnhi5Oxjhd5mvtLG5WCwZg6TLXuWzwHRwLK91kLiZ/dvzQIhVH82+AmVMGOASXdyDim 4F6WWOZke0sutPS/ZqgXLGbzwcmv3ufBWxZu54iIa+F1AZ0Q+eaxZ0XnXM4lTYIFL/X1 VzCS+Rr4YUWa4cI80KZzmelrAU4UU9FBxNtBFRpp7uu1S3RtNuSuygaZHTABq51vSe9/ 52xQ== X-Gm-Message-State: AC+VfDy0j+9cdFFfsGn6qypEnAf4IS7d6+rCvHmk8VQTPyW3QOk1M0B6 2K2LI5Ium/ZBSfxOelbyczUIVxXCLiA= X-Google-Smtp-Source: ACHHUZ5cQ2cgJdSAh0zgGf+/+ZF/Ml22GYGgHkn6nhGuZflecOxzamQB3CxZ4cxbFlh83Usj9WeWAw== X-Received: by 2002:a05:622a:199d:b0:3ef:3bad:6d12 with SMTP id u29-20020a05622a199d00b003ef3bad6d12mr20428194qtc.5.1682969462760; Mon, 01 May 2023 12:31:02 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH v3 06/14 RESEND] xen/x86: Tweak PDC bits when using HWP Date: Mon, 1 May 2023 15:30:26 -0400 Message-Id: <20230501193034.88575-7-jandryuk@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230501193034.88575-1-jandryuk@gmail.com> References: <20230501193034.88575-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1682969494467100003 Content-Type: text/plain; charset="utf-8" Qubes testing of HWP support had a report of a laptop, Thinkpad X1 Carbon Gen 4 with a Skylake processor, locking up during boot when HWP is enabled. A user found a kernel bug that seems to be the same issue: https://bugzilla.kernel.org/show_bug.cgi?id=3D110941. That bug was fixed by Linux commit a21211672c9a ("ACPI / processor: Request native thermal interrupt handling via _OSC"). The tl;dr is SMM crashes when it receives thermal interrupts, so Linux calls the ACPI _OSC method to take over interrupt handling. The Linux fix looks at the CPU features to decide whether or not to call _OSC with bit 12 set to take over native interrupt handling. Xen needs some way to communicate HWP to Dom0 for making an equivalent call. Xen exposes modified PDC bits via the platform_op set_pminfo hypercall. Expand that to set bit 12 when HWP is present and in use. Any generated interrupt would be handled by Xen's thermal drive, which clears the status. Bit 12 isn't named in the linux header and is open coded in Linux's usage. This will need a corresponding linux patch to pick up and apply the PDC bits. Signed-off-by: Jason Andryuk Reviewed-by: Jan Beulich --- New in v3 xen/arch/x86/acpi/cpufreq/hwp.c | 16 +++++++++++----- xen/arch/x86/acpi/lib.c | 5 +++++ xen/arch/x86/cpu/mcheck/mce_intel.c | 6 ++++++ xen/arch/x86/include/asm/msr-index.h | 1 + xen/include/acpi/cpufreq/processor_perf.h | 1 + xen/include/acpi/pdc_intel.h | 1 + 6 files changed, 25 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/acpi/cpufreq/hwp.c b/xen/arch/x86/acpi/cpufreq/hw= p.c index 57f13867d3..f84abe1386 100644 --- a/xen/arch/x86/acpi/cpufreq/hwp.c +++ b/xen/arch/x86/acpi/cpufreq/hwp.c @@ -13,6 +13,8 @@ #include #include =20 +static bool hwp_in_use; + static bool feature_hwp; static bool feature_hwp_notification; static bool feature_hwp_activity_window; @@ -117,10 +119,14 @@ static int __init cf_check cpufreq_gov_hwp_init(void) } __initcall(cpufreq_gov_hwp_init); =20 +bool hwp_active(void) +{ + return hwp_in_use; +} + bool __init hwp_available(void) { unsigned int eax, ecx, unused; - bool use_hwp; =20 if ( boot_cpu_data.cpuid_level < CPUID_PM_LEAF ) { @@ -173,13 +179,13 @@ bool __init hwp_available(void) hwp_verbose("HWP: HW_FEEDBACK %ssupported\n", (eax & CPUID6_EAX_HW_FEEDBACK) ? "" : "not "); =20 - use_hwp =3D feature_hwp && opt_cpufreq_hwp; - cpufreq_governor_internal =3D use_hwp; + hwp_in_use =3D feature_hwp && opt_cpufreq_hwp; + cpufreq_governor_internal =3D hwp_in_use; =20 - if ( use_hwp ) + if ( hwp_in_use ) hwp_info("Using HWP for cpufreq\n"); =20 - return use_hwp; + return hwp_in_use; } =20 static void hdc_set_pkg_hdc_ctl(bool val) diff --git a/xen/arch/x86/acpi/lib.c b/xen/arch/x86/acpi/lib.c index 43831b92d1..20d6115ba9 100644 --- a/xen/arch/x86/acpi/lib.c +++ b/xen/arch/x86/acpi/lib.c @@ -26,6 +26,8 @@ #include #include =20 +#include + u32 __read_mostly acpi_smi_cmd; u8 __read_mostly acpi_enable_value; u8 __read_mostly acpi_disable_value; @@ -140,5 +142,8 @@ int arch_acpi_set_pdc_bits(u32 acpi_id, u32 *pdc, u32 m= ask) !(ecx & CPUID5_ECX_INTERRUPT_BREAK)) pdc[2] &=3D ~(ACPI_PDC_C_C1_FFH | ACPI_PDC_C_C2C3_FFH); =20 + if (hwp_active()) + pdc[2] |=3D ACPI_PDC_CPPC_NTV_INT; + return 0; } diff --git a/xen/arch/x86/cpu/mcheck/mce_intel.c b/xen/arch/x86/cpu/mcheck/= mce_intel.c index 2f23f02923..d430342924 100644 --- a/xen/arch/x86/cpu/mcheck/mce_intel.c +++ b/xen/arch/x86/cpu/mcheck/mce_intel.c @@ -15,6 +15,9 @@ #include #include #include + +#include + #include "mce.h" #include "x86_mca.h" #include "barrier.h" @@ -64,6 +67,9 @@ static void cf_check intel_thermal_interrupt(struct cpu_u= ser_regs *regs) =20 ack_APIC_irq(); =20 + if ( hwp_active() ) + wrmsr_safe(MSR_IA32_HWP_STATUS, 0); + if ( NOW() < per_cpu(next, cpu) ) return; =20 diff --git a/xen/arch/x86/include/asm/msr-index.h b/xen/arch/x86/include/as= m/msr-index.h index a2a22339e4..f5269022da 100644 --- a/xen/arch/x86/include/asm/msr-index.h +++ b/xen/arch/x86/include/asm/msr-index.h @@ -157,6 +157,7 @@ #define MSR_IA32_HWP_CAPABILITIES 0x00000771 #define MSR_IA32_HWP_INTERRUPT 0x00000773 #define MSR_IA32_HWP_REQUEST 0x00000774 +#define MSR_IA32_HWP_STATUS 0x00000777 =20 #define MSR_X2APIC_FIRST 0x00000800 #define MSR_X2APIC_LAST 0x000008ff diff --git a/xen/include/acpi/cpufreq/processor_perf.h b/xen/include/acpi/c= pufreq/processor_perf.h index b751ca4937..dd8ec36ba7 100644 --- a/xen/include/acpi/cpufreq/processor_perf.h +++ b/xen/include/acpi/cpufreq/processor_perf.h @@ -8,6 +8,7 @@ #define XEN_PX_INIT 0x80000000 =20 bool hwp_available(void); +bool hwp_active(void); int hwp_register_driver(void); =20 int powernow_cpufreq_init(void); diff --git a/xen/include/acpi/pdc_intel.h b/xen/include/acpi/pdc_intel.h index 4fb719d6f5..e8332898fc 100644 --- a/xen/include/acpi/pdc_intel.h +++ b/xen/include/acpi/pdc_intel.h @@ -17,6 +17,7 @@ #define ACPI_PDC_C_C1_FFH (0x0100) #define ACPI_PDC_C_C2C3_FFH (0x0200) #define ACPI_PDC_SMP_P_HWCOORD (0x0800) +#define ACPI_PDC_CPPC_NTV_INT (0x1000) =20 #define ACPI_PDC_EST_CAPABILITY_SMP (ACPI_PDC_SMP_C1PT | \ ACPI_PDC_C_C1_HALT | \ --=20 2.40.0 From nobody Sun May 19 15:58:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1682969498; cv=none; d=zohomail.com; s=zohoarc; b=UUMgiRi9blnRhgG9pdbscfiuv+hpVvKUbGzr6wB3C96Tv/WunPIM7nBU/N6i//Gyl5CniMkVL35I94q5J0mUR2U5ruXitNmf31ny0ZfbAK8SpbPfwt8hsgFDZSRK/HE4Qn8m15mBeaSHzj3dsuAwM6JUs8/n0XsS5GuFPBlMZow= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682969498; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dJbA+BcuMsWkD5WxDhYLUpTvdE3qh/C4Qmxcz85bGeo=; b=DDEDBFwIChR7zsKM9y5TsuaMRj7c/SifNY2MGw5fynGcMhFddmgOyE/grz4IGq7h2zGlqUNqweyeXwCXGDm/5v5yPvDuqLlDggbzMbzqS8mvfOvHXtNVbFure8hHhyTeDRbpWQv+LsdmDV+QOnS6vhxr7oA7Zy9m35QH7hmUqqg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1682969498729798.5062390250002; Mon, 1 May 2023 12:31:38 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.528111.820927 (Exim 4.92) (envelope-from ) id 1ptZEs-0003ZG-Fd; Mon, 01 May 2023 19:31:10 +0000 Received: by outflank-mailman (output) from mailman id 528111.820927; Mon, 01 May 2023 19:31:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptZEs-0003Z5-C5; Mon, 01 May 2023 19:31:10 +0000 Received: by outflank-mailman (input) for mailman id 528111; Mon, 01 May 2023 19:31:09 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptZEq-000149-Vx for xen-devel@lists.xenproject.org; Mon, 01 May 2023 19:31:08 +0000 Received: from mail-qk1-x734.google.com (mail-qk1-x734.google.com [2607:f8b0:4864:20::734]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b7cb34ef-e856-11ed-8611-37d641c3527e; Mon, 01 May 2023 21:31:07 +0200 (CEST) Received: by mail-qk1-x734.google.com with SMTP id af79cd13be357-74e12e93384so121163085a.3 for ; Mon, 01 May 2023 12:31:07 -0700 (PDT) Received: from pm2-ws13.praxislan02.com (207-172-141-204.s8906.c3-0.slvr-cbr1.lnh-slvr.md.cable.rcncustomer.com. [207.172.141.204]) by smtp.gmail.com with ESMTPSA id d6-20020ac80606000000b003bf9f9f1844sm9351784qth.71.2023.05.01.12.31.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 12:31:04 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b7cb34ef-e856-11ed-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682969465; x=1685561465; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dJbA+BcuMsWkD5WxDhYLUpTvdE3qh/C4Qmxcz85bGeo=; b=nPWlTQA1AjIKcrvqph4r2lWQaecwmL0x3jr52qhY18Eh/tj6AwisM64Uf5AQI6tDP6 +SHB6kT3hgPFzYFuPSiZdnezeuvRqRWklk6JbJwPnYXYJbiqijAAN73gfC6F2KQ72EM6 S/WRuCg+Qj79DNx629ZznAmgIMCLFtAaTKnc/saoTH6BdXF/uSDpTQLtAL19IYtku7Qr TfzVmWYYvO2v2vCS6L9GfUYjTluKmU+tKekrWsmI0v37A1B6cVvfI5NwNK4xxvxBpOt8 BlRjgQ7IhaWZBBqlScTZy3R7VDxW6QfZxKvbgKIcen7kq3fhlMEwWUIHssUGtO3tUD4/ FUSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682969465; x=1685561465; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dJbA+BcuMsWkD5WxDhYLUpTvdE3qh/C4Qmxcz85bGeo=; b=cQx7lRyvtUz+bVqmhLqdnDXUM6eiKzVugVDf1Hcc8mqD0sJKGxtISdyegXLIGi9LT/ egKYG4eKcRb0BNrBPoNBmvPt7OqWq+yTzbFoq5G90dnCERGupYN8tYhXGGdIe0CzBJ0T 5UTEWvoRVmvg4Ii3ouaoeK5E8s8WIrgvrMEwU95iHdBjPeEN5mf6ckd+HzDmoHJvR/Mn gGc5aaBtbytUqEFedN3sg+HPTZGmLPgkSvDslA2ajeLiQvg+O3BEO4q7FE8w7cex9xrv JDilodbUH/M7JwiQyPum3O7tntvxqFyRtl8IfIAX+xh415bviSXs8JqaglpJGtVKhVBH LUsg== X-Gm-Message-State: AC+VfDyVNDBtQv17JRHMam2wb/9ykLhrIk1dgkggIoSVtv8ezS7te8hG a5PZBod1xAPZlDIQk4kzU+nvnpAjTGA= X-Google-Smtp-Source: ACHHUZ4yIAxtLHY8htulS6SPC+QNZq8i1LbhxAtAihfEzMKjPNr6hbZgwyHOFtp1cGuiuvKuMhWGew== X-Received: by 2002:ac8:5e10:0:b0:3ef:34e1:d380 with SMTP id h16-20020ac85e10000000b003ef34e1d380mr24529806qtx.11.1682969465465; Mon, 01 May 2023 12:31:05 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , George Dunlap , Julien Grall , Stefano Stabellini Subject: [PATCH v3 07/14 RESEND] cpufreq: Export HWP parameters to userspace Date: Mon, 1 May 2023 15:30:27 -0400 Message-Id: <20230501193034.88575-8-jandryuk@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230501193034.88575-1-jandryuk@gmail.com> References: <20230501193034.88575-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1682969499335100001 Content-Type: text/plain; charset="utf-8" Extend xen_get_cpufreq_para to return hwp parameters. These match the hardware rather closely. We need the features bitmask to indicated fields supported by the actual hardware. The use of uint8_t parameters matches the hardware size. uint32_t entries grows the sysctl_t past the build assertion in setup.c. The uint8_t ranges are supported across multiple generations, so hopefully they won't change. Signed-off-by: Jason Andryuk --- v2: Style fixes Don't bump XEN_SYSCTL_INTERFACE_VERSION Drop cpufreq.h comment divider Expand xen_hwp_para comment Add HWP activity window mantissa/exponent defines Handle union rename Add const to get_hwp_para Remove hw_ prefix from xen_hwp_para members Use XEN_HWP_GOVERNOR Use per_cpu for hwp_drv_data --- xen/arch/x86/acpi/cpufreq/hwp.c | 25 +++++++++++++++++++++++++ xen/drivers/acpi/pmstat.c | 5 +++++ xen/include/acpi/cpufreq/cpufreq.h | 2 ++ xen/include/public/sysctl.h | 26 ++++++++++++++++++++++++++ 4 files changed, 58 insertions(+) diff --git a/xen/arch/x86/acpi/cpufreq/hwp.c b/xen/arch/x86/acpi/cpufreq/hw= p.c index f84abe1386..cb52918799 100644 --- a/xen/arch/x86/acpi/cpufreq/hwp.c +++ b/xen/arch/x86/acpi/cpufreq/hwp.c @@ -506,6 +506,31 @@ static const struct cpufreq_driver __initconstrel hwp_= cpufreq_driver =3D .update =3D hwp_cpufreq_update, }; =20 +int get_hwp_para(const struct cpufreq_policy *policy, + struct xen_hwp_para *hwp_para) +{ + unsigned int cpu =3D policy->cpu; + const struct hwp_drv_data *data =3D per_cpu(hwp_drv_data, cpu); + + if ( data =3D=3D NULL ) + return -EINVAL; + + hwp_para->features =3D + (feature_hwp_activity_window ? XEN_SYSCTL_HWP_FEAT_ACT_WINDOW : 0= ) | + (feature_hwp_energy_perf ? XEN_SYSCTL_HWP_FEAT_ENERGY_PERF : 0= ); + hwp_para->lowest =3D data->hw.lowest; + hwp_para->most_efficient =3D data->hw.most_efficient; + hwp_para->guaranteed =3D data->hw.guaranteed; + hwp_para->highest =3D data->hw.highest; + hwp_para->minimum =3D data->minimum; + hwp_para->maximum =3D data->maximum; + hwp_para->energy_perf =3D data->energy_perf; + hwp_para->activity_window =3D data->activity_window; + hwp_para->desired =3D data->desired; + + return 0; +} + int __init hwp_register_driver(void) { return cpufreq_register_driver(&hwp_cpufreq_driver); diff --git a/xen/drivers/acpi/pmstat.c b/xen/drivers/acpi/pmstat.c index 1bae635101..67fd9dabd4 100644 --- a/xen/drivers/acpi/pmstat.c +++ b/xen/drivers/acpi/pmstat.c @@ -290,6 +290,11 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *o= p) &op->u.get_para.u.ondemand.sampling_rate, &op->u.get_para.u.ondemand.up_threshold); } + + if ( !strncasecmp(op->u.get_para.scaling_governor, XEN_HWP_GOVERNOR, + CPUFREQ_NAME_LEN) ) + ret =3D get_hwp_para(policy, &op->u.get_para.u.hwp_para); + op->u.get_para.turbo_enabled =3D cpufreq_get_turbo_status(op->cpuid); =20 return ret; diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/= cpufreq.h index 29a712a4f1..92b4c7e79c 100644 --- a/xen/include/acpi/cpufreq/cpufreq.h +++ b/xen/include/acpi/cpufreq/cpufreq.h @@ -247,5 +247,7 @@ void intel_feature_detect(struct cpufreq_policy *policy= ); =20 extern bool opt_cpufreq_hwp; extern bool opt_cpufreq_hdc; +int get_hwp_para(const struct cpufreq_policy *policy, + struct xen_hwp_para *hwp_para); =20 #endif /* __XEN_CPUFREQ_PM_H__ */ diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index b448f13b75..bf7e6594a7 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -292,6 +292,31 @@ struct xen_ondemand { uint32_t up_threshold; }; =20 +struct xen_hwp_para { + /* + * bits 6:0 - 7bit mantissa + * bits 9:7 - 3bit base-10 exponent + * btis 15:10 - Unused - must be 0 + */ +#define HWP_ACT_WINDOW_MANTISSA_MASK 0x7f +#define HWP_ACT_WINDOW_EXPONENT_MASK 0x7 +#define HWP_ACT_WINDOW_EXPONENT_SHIFT 7 + uint16_t activity_window; + /* energy_perf range 0-255 if 1. Otherwise 0-15 */ +#define XEN_SYSCTL_HWP_FEAT_ENERGY_PERF (1 << 0) + /* activity_window supported if 1 */ +#define XEN_SYSCTL_HWP_FEAT_ACT_WINDOW (1 << 1) + uint8_t features; /* bit flags for features */ + uint8_t lowest; + uint8_t most_efficient; + uint8_t guaranteed; + uint8_t highest; + uint8_t minimum; + uint8_t maximum; + uint8_t desired; + uint8_t energy_perf; +}; + #define XEN_HWP_GOVERNOR "hwp-internal" /* * cpufreq para name of this structure named @@ -324,6 +349,7 @@ struct xen_get_cpufreq_para { union { struct xen_userspace userspace; struct xen_ondemand ondemand; + struct xen_hwp_para hwp_para; } u; =20 int32_t turbo_enabled; --=20 2.40.0 From nobody Sun May 19 15:58:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1682969499; cv=none; d=zohomail.com; s=zohoarc; b=E1CXEGuBsudJhv6Sa//wksUBeLftrVbrVAo9KWJimj3ldbzjK//2gzlFNSTryxhkBu0VvK1fKZ3qRz3hiP5X48iZ88gXdA5MKnrtM3Xz9P/wMXl+dHUHAzmKNLMNHTLlI6gL647S7ieOxaztGgIIo7y7jF1njGPptFwJGFZ1p7A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682969499; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7SMitIr3/lPLI3ESf+JT4clE3jKHCc578aryTjCi/TM=; b=bRfkDys446wov5+MAKWhZAgl2KfdZae4y/eRGyggTCjYwIbWAjPQF5wxwKXvCD4RYg8iv11TFNdiiNLWfM/L0448adHzQiHUtjDvRK2dT2iwH2LaVYSKyQ5Ic50R6yoUzocHaGrT8vqLLiO0ps2ZcViMUX91HVI4CUHfCI1dAnI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1682969499542700.4604437386488; Mon, 1 May 2023 12:31:39 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.528113.820937 (Exim 4.92) (envelope-from ) id 1ptZEu-0003zl-Qb; Mon, 01 May 2023 19:31:12 +0000 Received: by outflank-mailman (output) from mailman id 528113.820937; Mon, 01 May 2023 19:31:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptZEu-0003zc-M2; Mon, 01 May 2023 19:31:12 +0000 Received: by outflank-mailman (input) for mailman id 528113; Mon, 01 May 2023 19:31:11 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptZEt-000149-19 for xen-devel@lists.xenproject.org; Mon, 01 May 2023 19:31:11 +0000 Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [2607:f8b0:4864:20::836]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b922eb57-e856-11ed-8611-37d641c3527e; Mon, 01 May 2023 21:31:09 +0200 (CEST) Received: by mail-qt1-x836.google.com with SMTP id d75a77b69052e-3eab1f2ba18so13396801cf.0 for ; Mon, 01 May 2023 12:31:09 -0700 (PDT) Received: from pm2-ws13.praxislan02.com (207-172-141-204.s8906.c3-0.slvr-cbr1.lnh-slvr.md.cable.rcncustomer.com. [207.172.141.204]) by smtp.gmail.com with ESMTPSA id d6-20020ac80606000000b003bf9f9f1844sm9351784qth.71.2023.05.01.12.31.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 12:31:07 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b922eb57-e856-11ed-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682969468; x=1685561468; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7SMitIr3/lPLI3ESf+JT4clE3jKHCc578aryTjCi/TM=; b=fiGDFAOgA/yRwd4eCcCOYq1b+8La77hlcXxxVYY11Jk3ndSYohpbOgDWzMc+ef2i7y MZUw4a2bVpYlLbvPg0AkKIkzn/jZOC0/fSkrMmVCbF5iNv+gD5CzIpL9eKIXO4A4IWOY zO5I+Gppui1NvJrXDFx5WHy4gH9DsTROqREvqQVl0rpr2FiWZ8JRj9AD29fcdwqL7mOu UenAFx6F2pAc7I+Z0qFd2qyUwx2BXVG4ZsRItUDTqLk6dI9yNwsqHk3OWC0hmzQW/cDz klfjzF7uS9KkQhdVoDE3D2XHzi//AoVJg5Gt783IE/hqKELm00ios7PJhaABv269uSGX nNlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682969468; x=1685561468; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7SMitIr3/lPLI3ESf+JT4clE3jKHCc578aryTjCi/TM=; b=Jin5OuPOQdz8Jh887hbY6gzPZGH5y9Cc095NUQiEse0T7JJLcMiOnGZj+ZVgIx75Ke 6MedX/5QdFyFcUiftjLOMjR6w8Dahp9PLyNjygRya4Tdb9U1ym0JcSTJKUHkpl3lu6rl QmU8gVvrFuqtVbVur1E32AzCR8S3P90g4cVVdsncJw0Qt+N1jAkA359EwHv+ZD80XIaW oRdCim4VZ4fycer0ZphWR5XkSr8/jPjpHVz2jUyr2BCFcMDEWz04qrGG1LYduza7pF88 db8F+zcTViI+amomQkJLr9pLrpyUOWeQk6i1aHd8D3Wv6kJzm4ZhhHtCazPmdzmLsqsT De8Q== X-Gm-Message-State: AC+VfDzdwcu5opoyq/xs7T86F7RJgDc8HIq1+aQba8XAHRQ6IlwPVyHO iba1AHNuw+Ka7hQNk1ahK8IjsqBkC2g= X-Google-Smtp-Source: ACHHUZ4zfsPnNVWoI6gOx5jVThON5YPlKizbp+7vW0T78d3g1rUxzlLc/WN/8uL2RyHM2Eexervnuw== X-Received: by 2002:a05:622a:1a8c:b0:3a8:a84:7ffa with SMTP id s12-20020a05622a1a8c00b003a80a847ffamr24778833qtc.57.1682969467897; Mon, 01 May 2023 12:31:07 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Wei Liu , Anthony PERARD , Juergen Gross Subject: [PATCH v3 08/14 RESEND] libxc: Include hwp_para in definitions Date: Mon, 1 May 2023 15:30:28 -0400 Message-Id: <20230501193034.88575-9-jandryuk@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230501193034.88575-1-jandryuk@gmail.com> References: <20230501193034.88575-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1682969500097100003 Content-Type: text/plain; charset="utf-8" Expose the hwp_para fields through libxc. Signed-off-by: Jason Andryuk Acked-by: Anthony PERARD --- tools/include/xenctrl.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 05967ecc92..437001d713 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1903,6 +1903,7 @@ int xc_smt_disable(xc_interface *xch); */ typedef struct xen_userspace xc_userspace_t; typedef struct xen_ondemand xc_ondemand_t; +typedef struct xen_hwp_para xc_hwp_para_t; =20 struct xc_get_cpufreq_para { /* IN/OUT variable */ @@ -1930,6 +1931,7 @@ struct xc_get_cpufreq_para { union { xc_userspace_t userspace; xc_ondemand_t ondemand; + xc_hwp_para_t hwp_para; } u; =20 int32_t turbo_enabled; --=20 2.40.0 From nobody Sun May 19 15:58:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1682969502; cv=none; d=zohomail.com; s=zohoarc; b=UIFBipAkIrRSbYhZddDIya6uDEVgCpinXZh+NgZ+8QSEHqkfU7JVbIIOeiQ+7aZXiGNBmLzBS3pULrYxC5q53uCRJkOVL0HEqegY45UsM4XkqMiQHTGGO4k+nZGpKKD2sSZVI+aYN6OIeoEFyqF5l9VpfgswadTeuCST6LtLi70= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682969502; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eu+1+LIcVcy6gjOVYvjWRf1phVWRYdUosVQFp9Yv6+Y=; b=LFroGAB1KPoDEP/RdBPwvSTP61ErwZCoJfB3cFrMAh4Jt5j8K+jOiczY+n299WAYa29yjBUpziMHRlwLetMjFMpN/UGiMxBsrsO55ulRI3F+3ujnlra9jlhlpOfuRKLsJT32CKTpqEzt3D4IJ83nCNzLLcMhATOT/6CW43WJ20A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1682969502888711.9943560111991; Mon, 1 May 2023 12:31:42 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.528115.820947 (Exim 4.92) (envelope-from ) id 1ptZEw-0004Nk-DC; Mon, 01 May 2023 19:31:14 +0000 Received: by outflank-mailman (output) from mailman id 528115.820947; Mon, 01 May 2023 19:31:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptZEw-0004Md-73; Mon, 01 May 2023 19:31:14 +0000 Received: by outflank-mailman (input) for mailman id 528115; Mon, 01 May 2023 19:31:13 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptZEu-000149-Vf for xen-devel@lists.xenproject.org; Mon, 01 May 2023 19:31:12 +0000 Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [2607:f8b0:4864:20::836]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id bab86444-e856-11ed-8611-37d641c3527e; Mon, 01 May 2023 21:31:11 +0200 (CEST) Received: by mail-qt1-x836.google.com with SMTP id d75a77b69052e-3eab1f2ba18so13397041cf.0 for ; Mon, 01 May 2023 12:31:11 -0700 (PDT) Received: from pm2-ws13.praxislan02.com (207-172-141-204.s8906.c3-0.slvr-cbr1.lnh-slvr.md.cable.rcncustomer.com. [207.172.141.204]) by smtp.gmail.com with ESMTPSA id d6-20020ac80606000000b003bf9f9f1844sm9351784qth.71.2023.05.01.12.31.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 12:31:09 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: bab86444-e856-11ed-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682969470; x=1685561470; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eu+1+LIcVcy6gjOVYvjWRf1phVWRYdUosVQFp9Yv6+Y=; b=ql4ZCfHL4hQ0YAqSbKsTQKwnIs1cococeDaD457Nd/sfN5/9p3XqlZSXQSmhYvdmBP W7yppqkFqdkjvLPtUOedeKRhze+niKiPC42xH8rLzDf/TDD9lhegO79YtMMwfXGQ3iwR 5ZIQu0fUlo+SGW4BCPKFqLK9ZeNE4ntJZrtDe8B2UGjfD9ViFOSsQmWsesd0/Ag6TOuu ryHfod/UGi6YB9XTT8mlVX2YJGkndLYiBrAyEJO3/P92P4qKqWpUGoCRGSVjuNSNPPfR GoijsvrKi55fyZrP9J0BYmDW6CFG3rS3pA9ysF+snUGXJjIOq4jupDAkynLScU7AaUAQ jpXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682969470; x=1685561470; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eu+1+LIcVcy6gjOVYvjWRf1phVWRYdUosVQFp9Yv6+Y=; b=KVsx/qHi083GcvYFA+XFXNhb1GbDqJmB8x6KuPxeLc/TydkvfAjkYzRlv5Z0Q2DJrP DwD2xTHERN9bmliu94BHjsU90jQsvc7zqIn8Wj8Ze0whcYB4isCoDLA4sZljYX1Ksp9w qGIj8mWUnG0fIcM6+LoAE8FXsAO+d+q/Mjkh9YjxghkQAc7/kAUqQ8hI+gWL7y+92WVP 8YRZh8+E6s8BZH+Vpzc/yrTYlZZP6Yr9C7oMy2NkuMlVglZhmmtH6L2eK5+l8YK8TkUv ABOyE5IXAhe9zNiYt3tc/jRGPuIghjpUidB/mIYeVp95hkIrJxd6/CSbCl2hiyqveVY3 NxOQ== X-Gm-Message-State: AC+VfDyh/+midfWynqigiu/+cviRjgubegJM7Hl97EWRcyJ81oSAGLiD KzGIbfC1smZYySf0DKhI3JIqianQDLc= X-Google-Smtp-Source: ACHHUZ75umoQyE6/G5AilWu+IH7PSPRSc9wk3YctqTMZOoMg4HPknC2FZ+DYgYcgnIQ1PIyrcoZ8AA== X-Received: by 2002:a05:622a:646:b0:3eb:9b03:b5ba with SMTP id a6-20020a05622a064600b003eb9b03b5bamr23146173qtb.37.1682969470417; Mon, 01 May 2023 12:31:10 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Wei Liu , Anthony PERARD Subject: [PATCH v3 09/14 RESEND] xenpm: Print HWP parameters Date: Mon, 1 May 2023 15:30:29 -0400 Message-Id: <20230501193034.88575-10-jandryuk@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230501193034.88575-1-jandryuk@gmail.com> References: <20230501193034.88575-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1682969503158100001 Content-Type: text/plain; charset="utf-8" Print HWP-specific parameters. Some are always present, but others depend on hardware support. Signed-off-by: Jason Andryuk --- v2: Style fixes Declare i outside loop Replace repearted hardware/configured limits with spaces Fixup for hw_ removal Use XEN_HWP_GOVERNOR Use HWP_ACT_WINDOW_EXPONENT_* Remove energy_perf hw autonomous - 0 doesn't mean autonomous --- tools/misc/xenpm.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index ce8d7644d0..b2defde0d4 100644 --- a/tools/misc/xenpm.c +++ b/tools/misc/xenpm.c @@ -708,6 +708,44 @@ void start_gather_func(int argc, char *argv[]) pause(); } =20 +static void calculate_hwp_activity_window(const xc_hwp_para_t *hwp, + unsigned int *activity_window, + const char **units) +{ + unsigned int mantissa =3D hwp->activity_window & HWP_ACT_WINDOW_MANTIS= SA_MASK; + unsigned int exponent =3D + (hwp->activity_window >> HWP_ACT_WINDOW_EXPONENT_SHIFT) & + HWP_ACT_WINDOW_EXPONENT_MASK; + unsigned int multiplier =3D 1; + unsigned int i; + + if ( hwp->activity_window =3D=3D 0 ) + { + *units =3D "hardware selected"; + *activity_window =3D 0; + + return; + } + + if ( exponent >=3D 6 ) + { + *units =3D "s"; + exponent -=3D 6; + } + else if ( exponent >=3D 3 ) + { + *units =3D "ms"; + exponent -=3D 3; + } + else + *units =3D "us"; + + for ( i =3D 0; i < exponent; i++ ) + multiplier *=3D 10; + + *activity_window =3D mantissa * multiplier; +} + /* print out parameters about cpu frequency */ static void print_cpufreq_para(int cpuid, struct xc_get_cpufreq_para *p_cp= ufreq) { @@ -773,6 +811,33 @@ static void print_cpufreq_para(int cpuid, struct xc_ge= t_cpufreq_para *p_cpufreq) p_cpufreq->scaling_cur_freq); } =20 + if ( strcmp(p_cpufreq->scaling_governor, XEN_HWP_GOVERNOR) =3D=3D 0 ) + { + const xc_hwp_para_t *hwp =3D &p_cpufreq->u.hwp_para; + + printf("hwp variables :\n"); + printf(" hardware limits : lowest [%u] most_efficient [%u]\n", + hwp->lowest, hwp->most_efficient); + printf(" : guaranteed [%u] highest [%u]\n", + hwp->guaranteed, hwp->highest); + printf(" configured limits : min [%u] max [%u] energy_perf [%u]\= n", + hwp->minimum, hwp->maximum, hwp->energy_perf); + + if ( hwp->features & XEN_SYSCTL_HWP_FEAT_ACT_WINDOW ) + { + unsigned int activity_window; + const char *units; + + calculate_hwp_activity_window(hwp, &activity_window, &units); + printf(" : activity_window [%u %s]\n", + activity_window, units); + } + + printf(" : desired [%u%s]\n", + hwp->desired, + hwp->desired ? "" : " hw autonomous"); + } + printf("turbo mode : %s\n", p_cpufreq->turbo_enabled ? "enabled" : "disabled or n/a"); printf("\n"); --=20 2.40.0 From nobody Sun May 19 15:58:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1682969506; cv=none; d=zohomail.com; s=zohoarc; b=j9ccpM4AxSqYP7t6t0WVknwl1LUzY2rYVCGELMIOAAbVaYSfzJr0P/SQEmBNoer8IHMLo21eLqZuwGK8qE37WkNHRoZlbfvUFwuGOqiXW/Jq1K88F7Djpu75qLMn4lqh6I/8K4tBY5GNYRuAvmBqc/G7HjuuTuti+QHFzzTdq/4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682969506; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YO0WsYuSOYLWQPRYhV/xiXSnog1IJZfbXjjJjaPzhyY=; b=dpVVZ8ybCVsD9BguZoLiK+kTIs8H2Knpc361jc8CkAo1UhjxGOsUlPJ94qxg5H5qsNiPT9Wcfooh1wSa6IUfMJwD2i6ZkWt8iWZ4QmNWspDKNEERZll+12NOMrH7GUPqJKDrRus6gLrExvfqwhV0CDk6UQweiuF5ky+GgvWihDc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1682969506729715.8082378156196; Mon, 1 May 2023 12:31:46 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.528117.820957 (Exim 4.92) (envelope-from ) id 1ptZEy-0004nF-QO; Mon, 01 May 2023 19:31:16 +0000 Received: by outflank-mailman (output) from mailman id 528117.820957; Mon, 01 May 2023 19:31:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptZEy-0004mj-Jh; Mon, 01 May 2023 19:31:16 +0000 Received: by outflank-mailman (input) for mailman id 528117; Mon, 01 May 2023 19:31:15 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptZEx-0000m4-7L for xen-devel@lists.xenproject.org; Mon, 01 May 2023 19:31:15 +0000 Received: from mail-qt1-x834.google.com (mail-qt1-x834.google.com [2607:f8b0:4864:20::834]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id bc136e52-e856-11ed-b225-6b7b168915f2; Mon, 01 May 2023 21:31:14 +0200 (CEST) Received: by mail-qt1-x834.google.com with SMTP id d75a77b69052e-3ef588dcf7aso30763471cf.1 for ; Mon, 01 May 2023 12:31:14 -0700 (PDT) Received: from pm2-ws13.praxislan02.com (207-172-141-204.s8906.c3-0.slvr-cbr1.lnh-slvr.md.cable.rcncustomer.com. [207.172.141.204]) by smtp.gmail.com with ESMTPSA id d6-20020ac80606000000b003bf9f9f1844sm9351784qth.71.2023.05.01.12.31.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 12:31:12 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: bc136e52-e856-11ed-b225-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682969473; x=1685561473; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YO0WsYuSOYLWQPRYhV/xiXSnog1IJZfbXjjJjaPzhyY=; b=p6B+B6XpWfwKWnoxvpW5gtX5oGjDvEZdCLriLQQadIJV+J3ljmoPJcH4bPIuL2ucfz mtHlnETg0UUF5jByhu/mM9kCyYkjt9P0hrQo1BqQXzxoyHqAN/zU/4cLUegdhqJGFW3t QztH/fVaAxhlryJfCG8yyT2BR+q8MjaDHQ1k8RBkJvq7VwlkvwAzt64TqlMQRtaJLSlX B9OciZJscFFBbj8sJxWeij9ItpbyraeDBE61NstR0lmm+WYl7PVusJFMbrY+siLj8pf9 Ra5w3MhcVc+FspJuTOmCPDMSjYTp6lK70LZtyG2s2KTPyCZWrz8TqB30M8y+BTPNtocN BQzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682969473; x=1685561473; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YO0WsYuSOYLWQPRYhV/xiXSnog1IJZfbXjjJjaPzhyY=; b=QpuBVmnais08zJSPDCUqVlgC/Hx8zXpAmue0WlvQCqLNznlb47OM5qWwpvtHhJKgI3 pNDIu5QQM5CZHmZV3zPIaAxs72097gv3hm9V/mMg8YO70MtNHHE7VJ16zpQBayUWkJf2 wqYOcH7phRpoVtDvYEUeCqYruaVFGkKlCrSTIAXa2dBArn9H6lbKzTA8JtBkVRjiQV7I W05zriV0EnE09HlAoU5K58Ba9BMUrw+d7XiVXv8HhwF6b8Xo984uv722mJxNVoX1v6K6 sy1ePIFiAeIONA0US/X9ZV0nffTXvml64BP8530FXkSbbzYxS4TXLgZi19kuxzvaKtPX DNaw== X-Gm-Message-State: AC+VfDxcJS26HCAvfpwbsNFu1ysfH3FWzlwba98dHqpLmrzDOfv3NicB DOaBH6h6IRhYu4h37lRpPKWMuMHN0hE= X-Google-Smtp-Source: ACHHUZ6b2qw5XxkOLyjOcqjlFfogIYKVNHV7rj6p+aoYwVx36V4SPAB0ZWkXmKy5FGmMsIXEVVUykQ== X-Received: by 2002:a05:622a:13cc:b0:3ef:6c09:edcc with SMTP id p12-20020a05622a13cc00b003ef6c09edccmr23837085qtk.22.1682969472810; Mon, 01 May 2023 12:31:12 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , George Dunlap , Julien Grall , Stefano Stabellini Subject: [PATCH v3 10/14 RESEND] xen: Add SET_CPUFREQ_HWP xen_sysctl_pm_op Date: Mon, 1 May 2023 15:30:30 -0400 Message-Id: <20230501193034.88575-11-jandryuk@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230501193034.88575-1-jandryuk@gmail.com> References: <20230501193034.88575-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1682969507232100001 Content-Type: text/plain; charset="utf-8" Add SET_CPUFREQ_HWP xen_sysctl_pm_op to set HWP parameters. The sysctl supports setting multiple values simultaneously as indicated by the set_params bits. This allows atomically applying new HWP configuration via a single wrmsr. XEN_SYSCTL_HWP_SET_PRESET_BALANCE/PERFORMANCE/POWERSAVE provide three common presets. Setting them depends on hardware limits which the hypervisor is already caching. So using them allows skipping a hypercall to query the limits (lowest/highest) to then set those same values. The code is organized to allow a preset to be refined with additional stuff if desired. "most_efficient" and "guaranteed" could be additional presets in the future, but the are not added now. Those levels can change at runtime, but we don't have code in place to monitor and update for those events. Signed-off-by: Jason Andryuk --- v3: Remove cpufreq_governor_internal from set_cpufreq_hwp v2: Update for naming anonymous union Drop hwp_err for invalid input in set_hwp_para() Drop uint16_t cast in XEN_SYSCTL_HWP_SET_PARAM_MASK Drop parens for HWP_SET_PRESET defines Reference activity_window format comment Place SET_CPUFREQ_HWP after SET_CPUFREQ_PARA Add {HWP,IA32}_ENERGY_PERF_MAX_{PERFORMANCE,POWERSAVE} defines Order defines before fields in sysctl.h Use XEN_HWP_GOVERNOR Use per_cpu for hwp_drv_data --- xen/arch/x86/acpi/cpufreq/hwp.c | 96 ++++++++++++++++++++++++++++++ xen/drivers/acpi/pmstat.c | 18 ++++++ xen/include/acpi/cpufreq/cpufreq.h | 2 + xen/include/public/sysctl.h | 30 ++++++++++ 4 files changed, 146 insertions(+) diff --git a/xen/arch/x86/acpi/cpufreq/hwp.c b/xen/arch/x86/acpi/cpufreq/hw= p.c index cb52918799..3d15875dc1 100644 --- a/xen/arch/x86/acpi/cpufreq/hwp.c +++ b/xen/arch/x86/acpi/cpufreq/hwp.c @@ -27,7 +27,9 @@ static bool feature_hdc; __initdata bool opt_cpufreq_hwp =3D false; __initdata bool opt_cpufreq_hdc =3D true; =20 +#define HWP_ENERGY_PERF_MAX_PERFORMANCE 0 #define HWP_ENERGY_PERF_BALANCE 0x80 +#define HWP_ENERGY_PERF_MAX_POWERSAVE 0xff #define IA32_ENERGY_BIAS_BALANCE 0x7 #define IA32_ENERGY_BIAS_MAX_POWERSAVE 0xf #define IA32_ENERGY_BIAS_MASK 0xf @@ -531,6 +533,100 @@ int get_hwp_para(const struct cpufreq_policy *policy, return 0; } =20 +int set_hwp_para(struct cpufreq_policy *policy, + struct xen_set_hwp_para *set_hwp) +{ + unsigned int cpu =3D policy->cpu; + struct hwp_drv_data *data =3D per_cpu(hwp_drv_data, cpu); + + if ( data =3D=3D NULL ) + return -EINVAL; + + /* Validate all parameters first */ + if ( set_hwp->set_params & ~XEN_SYSCTL_HWP_SET_PARAM_MASK ) + return -EINVAL; + + if ( set_hwp->activity_window & ~XEN_SYSCTL_HWP_ACT_WINDOW_MASK ) + return -EINVAL; + + if ( !feature_hwp_energy_perf && + (set_hwp->set_params & XEN_SYSCTL_HWP_SET_ENERGY_PERF) && + set_hwp->energy_perf > IA32_ENERGY_BIAS_MAX_POWERSAVE ) + return -EINVAL; + + if ( (set_hwp->set_params & XEN_SYSCTL_HWP_SET_DESIRED) && + set_hwp->desired !=3D 0 && + (set_hwp->desired < data->hw.lowest || + set_hwp->desired > data->hw.highest) ) + return -EINVAL; + + /* + * minimum & maximum are not validated as hardware doesn't seem to care + * and the SDM says CPUs will clip internally. + */ + + /* Apply presets */ + switch ( set_hwp->set_params & XEN_SYSCTL_HWP_SET_PRESET_MASK ) + { + case XEN_SYSCTL_HWP_SET_PRESET_POWERSAVE: + data->minimum =3D data->hw.lowest; + data->maximum =3D data->hw.lowest; + data->activity_window =3D 0; + if ( feature_hwp_energy_perf ) + data->energy_perf =3D HWP_ENERGY_PERF_MAX_POWERSAVE; + else + data->energy_perf =3D IA32_ENERGY_BIAS_MAX_POWERSAVE; + data->desired =3D 0; + break; + + case XEN_SYSCTL_HWP_SET_PRESET_PERFORMANCE: + data->minimum =3D data->hw.highest; + data->maximum =3D data->hw.highest; + data->activity_window =3D 0; + data->energy_perf =3D HWP_ENERGY_PERF_MAX_PERFORMANCE; + data->desired =3D 0; + break; + + case XEN_SYSCTL_HWP_SET_PRESET_BALANCE: + data->minimum =3D data->hw.lowest; + data->maximum =3D data->hw.highest; + data->activity_window =3D 0; + if ( feature_hwp_energy_perf ) + data->energy_perf =3D HWP_ENERGY_PERF_BALANCE; + else + data->energy_perf =3D IA32_ENERGY_BIAS_BALANCE; + data->desired =3D 0; + break; + + case XEN_SYSCTL_HWP_SET_PRESET_NONE: + break; + + default: + return -EINVAL; + } + + /* Further customize presets if needed */ + if ( set_hwp->set_params & XEN_SYSCTL_HWP_SET_MINIMUM ) + data->minimum =3D set_hwp->minimum; + + if ( set_hwp->set_params & XEN_SYSCTL_HWP_SET_MAXIMUM ) + data->maximum =3D set_hwp->maximum; + + if ( set_hwp->set_params & XEN_SYSCTL_HWP_SET_ENERGY_PERF ) + data->energy_perf =3D set_hwp->energy_perf; + + if ( set_hwp->set_params & XEN_SYSCTL_HWP_SET_DESIRED ) + data->desired =3D set_hwp->desired; + + if ( set_hwp->set_params & XEN_SYSCTL_HWP_SET_ACT_WINDOW ) + data->activity_window =3D set_hwp->activity_window & + XEN_SYSCTL_HWP_ACT_WINDOW_MASK; + + hwp_cpufreq_target(policy, 0, 0); + + return 0; +} + int __init hwp_register_driver(void) { return cpufreq_register_driver(&hwp_cpufreq_driver); diff --git a/xen/drivers/acpi/pmstat.c b/xen/drivers/acpi/pmstat.c index 67fd9dabd4..12c76f5e57 100644 --- a/xen/drivers/acpi/pmstat.c +++ b/xen/drivers/acpi/pmstat.c @@ -398,6 +398,20 @@ static int set_cpufreq_para(struct xen_sysctl_pm_op *o= p) return ret; } =20 +static int set_cpufreq_hwp(struct xen_sysctl_pm_op *op) +{ + struct cpufreq_policy *policy =3D per_cpu(cpufreq_cpu_policy, op->cpui= d); + + if ( !policy || !policy->governor ) + return -EINVAL; + + if ( strncasecmp(policy->governor->name, XEN_HWP_GOVERNOR, + CPUFREQ_NAME_LEN) ) + return -EINVAL; + + return set_hwp_para(policy, &op->u.set_hwp); +} + int do_pm_op(struct xen_sysctl_pm_op *op) { int ret =3D 0; @@ -470,6 +484,10 @@ int do_pm_op(struct xen_sysctl_pm_op *op) break; } =20 + case SET_CPUFREQ_HWP: + ret =3D set_cpufreq_hwp(op); + break; + case GET_CPUFREQ_AVGFREQ: { op->u.get_avgfreq =3D cpufreq_driver_getavg(op->cpuid, USR_GETAVG); diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/= cpufreq.h index 92b4c7e79c..b8831b2cd3 100644 --- a/xen/include/acpi/cpufreq/cpufreq.h +++ b/xen/include/acpi/cpufreq/cpufreq.h @@ -249,5 +249,7 @@ extern bool opt_cpufreq_hwp; extern bool opt_cpufreq_hdc; int get_hwp_para(const struct cpufreq_policy *policy, struct xen_hwp_para *hwp_para); +int set_hwp_para(struct cpufreq_policy *policy, + struct xen_set_hwp_para *set_hwp); =20 #endif /* __XEN_CPUFREQ_PM_H__ */ diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index bf7e6594a7..3242472cbe 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -317,6 +317,34 @@ struct xen_hwp_para { uint8_t energy_perf; }; =20 +/* set multiple values simultaneously when set_args bit is set */ +struct xen_set_hwp_para { +#define XEN_SYSCTL_HWP_SET_DESIRED (1U << 0) +#define XEN_SYSCTL_HWP_SET_ENERGY_PERF (1U << 1) +#define XEN_SYSCTL_HWP_SET_ACT_WINDOW (1U << 2) +#define XEN_SYSCTL_HWP_SET_MINIMUM (1U << 3) +#define XEN_SYSCTL_HWP_SET_MAXIMUM (1U << 4) +#define XEN_SYSCTL_HWP_SET_PRESET_MASK 0xf000 +#define XEN_SYSCTL_HWP_SET_PRESET_NONE 0x0000 +#define XEN_SYSCTL_HWP_SET_PRESET_BALANCE 0x1000 +#define XEN_SYSCTL_HWP_SET_PRESET_POWERSAVE 0x2000 +#define XEN_SYSCTL_HWP_SET_PRESET_PERFORMANCE 0x3000 +#define XEN_SYSCTL_HWP_SET_PARAM_MASK ( \ + XEN_SYSCTL_HWP_SET_PRESET_MASK | \ + XEN_SYSCTL_HWP_SET_DESIRED | \ + XEN_SYSCTL_HWP_SET_ENERGY_PERF | \ + XEN_SYSCTL_HWP_SET_ACT_WINDOW | \ + XEN_SYSCTL_HWP_SET_MINIMUM | \ + XEN_SYSCTL_HWP_SET_MAXIMUM ) + uint16_t set_params; /* bitflags for valid values */ +#define XEN_SYSCTL_HWP_ACT_WINDOW_MASK 0x03ff + uint16_t activity_window; /* See comment in struct xen_hwp_para */ + uint8_t minimum; + uint8_t maximum; + uint8_t desired; + uint8_t energy_perf; /* 0-255 or 0-15 depending on HW support */ +}; + #define XEN_HWP_GOVERNOR "hwp-internal" /* * cpufreq para name of this structure named @@ -379,6 +407,7 @@ struct xen_sysctl_pm_op { #define SET_CPUFREQ_GOV (CPUFREQ_PARA | 0x02) #define SET_CPUFREQ_PARA (CPUFREQ_PARA | 0x03) #define GET_CPUFREQ_AVGFREQ (CPUFREQ_PARA | 0x04) + #define SET_CPUFREQ_HWP (CPUFREQ_PARA | 0x05) =20 /* set/reset scheduler power saving option */ #define XEN_SYSCTL_pm_op_set_sched_opt_smt 0x21 @@ -405,6 +434,7 @@ struct xen_sysctl_pm_op { struct xen_get_cpufreq_para get_para; struct xen_set_cpufreq_gov set_gov; struct xen_set_cpufreq_para set_para; + struct xen_set_hwp_para set_hwp; uint64_aligned_t get_avgfreq; uint32_t set_sched_opt_smt; #define XEN_SYSCTL_CX_UNLIMITED 0xffffffff --=20 2.40.0 From nobody Sun May 19 15:58:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1682969511; cv=none; d=zohomail.com; s=zohoarc; b=FmMtG3V6ONop7FMuK6/7kVpzpcIxb1Tsp5L2gkKgTFIol9Luzsf94Ao+ezkDnWvdL8DWJT2FpE+EM+5Thm+OVnc97ybkpRmfr+nhHvh18jg6SLaebXf4vu1zQ6HSFSHb/zUGoWAhLSZuOWRJD07Z2ufX+a5mIP1K3BDMEwNsKvw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682969511; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0JAKWHRmes/OZ2QqxthbDdVSth+8gV1gmiT1eY6OQAU=; b=MxKgyBBL1MkylUIataXgb4YMGflrHS2TCC0JHfQrvAJdJRRLRYKX00WykDYxb7J5PReLLWuwq160TFB5shxGAbf7HnR6nAS3+ywnY2BnxVipfiCI8F5DJbwvE3ZspR6MRuaTGL0BSww/+iiuiSdAitJ2SQj+mytrqQw0OLCfA94= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1682969511529776.3515570405234; Mon, 1 May 2023 12:31:51 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.528120.820966 (Exim 4.92) (envelope-from ) id 1ptZF2-0005Mw-4d; Mon, 01 May 2023 19:31:20 +0000 Received: by outflank-mailman (output) from mailman id 528120.820966; Mon, 01 May 2023 19:31:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptZF2-0005MZ-1F; Mon, 01 May 2023 19:31:20 +0000 Received: by outflank-mailman (input) for mailman id 528120; Mon, 01 May 2023 19:31:18 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptZF0-000149-N3 for xen-devel@lists.xenproject.org; Mon, 01 May 2023 19:31:18 +0000 Received: from mail-qt1-x82c.google.com (mail-qt1-x82c.google.com [2607:f8b0:4864:20::82c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id bd953b45-e856-11ed-8611-37d641c3527e; Mon, 01 May 2023 21:31:17 +0200 (CEST) Received: by mail-qt1-x82c.google.com with SMTP id d75a77b69052e-3ef38864360so32531821cf.2 for ; Mon, 01 May 2023 12:31:17 -0700 (PDT) Received: from pm2-ws13.praxislan02.com (207-172-141-204.s8906.c3-0.slvr-cbr1.lnh-slvr.md.cable.rcncustomer.com. [207.172.141.204]) by smtp.gmail.com with ESMTPSA id d6-20020ac80606000000b003bf9f9f1844sm9351784qth.71.2023.05.01.12.31.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 12:31:14 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: bd953b45-e856-11ed-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682969475; x=1685561475; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0JAKWHRmes/OZ2QqxthbDdVSth+8gV1gmiT1eY6OQAU=; b=agUYa27f+iQLWMNxlFEc2K+VW9/TDwM3m+jQfvXTxvXZbmzGAjWm0wsvu8JqtR207U t1t5hRwO5XCaNJeBc88seuaxK9iWobMhqaMFalduGXrSd1fuN4jpHX1uq0hiw73GxLxa QbJ0eOzdWZOowX39nQau708W4gepwI7smAEBwsHyb73JAshCTh2+k0inXyBLfFQROQjn kVZLmA8d83RtY1EFNGFyqPmD8NoRnV7padsi+zu+hjkMVIvAnO4R1lui3cpMG8T7Y8DP FqjAkbwmR1Ss3yV18+dB6lolo03B2Ai2r90qUQENivonfb8k4P3/JMrwXX/E19b/M6vA YtxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682969475; x=1685561475; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0JAKWHRmes/OZ2QqxthbDdVSth+8gV1gmiT1eY6OQAU=; b=UlaklaRnKMH45rH2nnOqbKi5d+lnyRb0FeK2gNj7bSMajod8f/mQ29nKj5PAhsOB8k 4CePo6DrzAjDo0DVPvQcKhMiulxc/uIuGRf0aXI5Prq4HOLVSrpX5iTxYrBGatHRW/bK X6APhppKC6Lnfd/Jj9HouwnH6yLs9hNij2buwRLX2S6qNl5Lb6djIxcgvr+K8GAoLPSW nO6A2AXanDtZOaLgSVxtHudXr4WUFXiVikWssmeG1MxKoU1zuBiEK5ZNkWWktcX+sI5Y 7Xp+2t91IaVMhz3azgV4TSfyeNtEa+4dTqdZlcFQm1XgGU8Qva5nTpBmuhaQe9BRJ5rd V0SQ== X-Gm-Message-State: AC+VfDx45hYpx6vN6LN+G7gg5A2qoI+uqewsi5UXTQcy/BWmlJstqCgt d7FAT32sa+7T5HlYEdmPRXHdTtLleIw= X-Google-Smtp-Source: ACHHUZ7q7E2b3NRT8r2PP7bqWrRHuqumQRwO8VPJV/bucabXWhGvM2lctIFgM6saOuOeuyBtdclxKQ== X-Received: by 2002:ac8:5c08:0:b0:3ef:7975:99d0 with SMTP id i8-20020ac85c08000000b003ef797599d0mr24307476qti.31.1682969475143; Mon, 01 May 2023 12:31:15 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Wei Liu , Anthony PERARD , Juergen Gross Subject: [PATCH v3 11/14 RESEND] libxc: Add xc_set_cpufreq_hwp Date: Mon, 1 May 2023 15:30:31 -0400 Message-Id: <20230501193034.88575-12-jandryuk@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230501193034.88575-1-jandryuk@gmail.com> References: <20230501193034.88575-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1682969512119100001 Content-Type: text/plain; charset="utf-8" Add xc_set_cpufreq_hwp to allow calling xen_systctl_pm_op SET_CPUFREQ_HWP. Signed-off-by: Jason Andryuk Acked-by: Anthony PERARD --- v2: Mark xc_set_hwp_para_t const --- tools/include/xenctrl.h | 4 ++++ tools/libs/ctrl/xc_pm.c | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 437001d713..cd367d9d8f 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1937,11 +1937,15 @@ struct xc_get_cpufreq_para { int32_t turbo_enabled; }; =20 +typedef struct xen_set_hwp_para xc_set_hwp_para_t; + int xc_get_cpufreq_para(xc_interface *xch, int cpuid, struct xc_get_cpufreq_para *user_para); int xc_set_cpufreq_gov(xc_interface *xch, int cpuid, char *govname); int xc_set_cpufreq_para(xc_interface *xch, int cpuid, int ctrl_type, int ctrl_value); +int xc_set_cpufreq_hwp(xc_interface *xch, int cpuid, + const xc_set_hwp_para_t *set_hwp); int xc_get_cpufreq_avgfreq(xc_interface *xch, int cpuid, int *avg_freq); =20 int xc_set_sched_opt_smt(xc_interface *xch, uint32_t value); diff --git a/tools/libs/ctrl/xc_pm.c b/tools/libs/ctrl/xc_pm.c index c3a9864bf7..a747ab053c 100644 --- a/tools/libs/ctrl/xc_pm.c +++ b/tools/libs/ctrl/xc_pm.c @@ -330,6 +330,24 @@ int xc_set_cpufreq_para(xc_interface *xch, int cpuid, return xc_sysctl(xch, &sysctl); } =20 +int xc_set_cpufreq_hwp(xc_interface *xch, int cpuid, + const xc_set_hwp_para_t *set_hwp) +{ + DECLARE_SYSCTL; + + if ( !xch ) + { + errno =3D EINVAL; + return -1; + } + sysctl.cmd =3D XEN_SYSCTL_pm_op; + sysctl.u.pm_op.cmd =3D SET_CPUFREQ_HWP; + sysctl.u.pm_op.cpuid =3D cpuid; + sysctl.u.pm_op.u.set_hwp =3D *set_hwp; + + return xc_sysctl(xch, &sysctl); +} + int xc_get_cpufreq_avgfreq(xc_interface *xch, int cpuid, int *avg_freq) { int ret =3D 0; --=20 2.40.0 From nobody Sun May 19 15:58:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1682969999; cv=none; d=zohomail.com; s=zohoarc; b=Lxsj9zsjnfRLGQMHh8XbzUecbtDaG26qr+b+cogFeSz9ZLAwgbZ1pNlJ4niCGZZAGBBsqYaVixqek9ESdq11//pNNj17i8xMgH7t8pFIvC3APDEVhMeAp3+yxRsXmb8NmtPlAM7S3+KNtofp7/nacCdzyhTbe1RHTb8onhBq+nQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682969999; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Bnmwx4JL4zzfpoAgNv41/x6mI5Sl5Tvy0no2deSD0O4=; b=EYRUKFztQGC1blNDVFIK9e++aRP5s0bf9+S+S75KrJqbVo9BeHuNqvfCOnlRtyzExNf7Br15m1MvFPX1YBlK0t6rwweQLFRMM+VzOWeMzUS9MXz93FQm9VVK5v6j9HAT2T+CcFH81UAGP7Z4AV+YdNfX1rpwoH9b+7P+wP1iD2U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1682969999109481.9429113043524; Mon, 1 May 2023 12:39:59 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.528145.821017 (Exim 4.92) (envelope-from ) id 1ptZMl-0000ij-CV; Mon, 01 May 2023 19:39:19 +0000 Received: by outflank-mailman (output) from mailman id 528145.821017; Mon, 01 May 2023 19:39:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptZMl-0000iY-8B; Mon, 01 May 2023 19:39:19 +0000 Received: by outflank-mailman (input) for mailman id 528145; Mon, 01 May 2023 19:39:18 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptZF1-0000m4-81 for xen-devel@lists.xenproject.org; Mon, 01 May 2023 19:31:19 +0000 Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [2607:f8b0:4864:20::732]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id be9f0d3b-e856-11ed-b225-6b7b168915f2; Mon, 01 May 2023 21:31:18 +0200 (CEST) Received: by mail-qk1-x732.google.com with SMTP id af79cd13be357-75131c2997bso1451854885a.1 for ; Mon, 01 May 2023 12:31:18 -0700 (PDT) Received: from pm2-ws13.praxislan02.com (207-172-141-204.s8906.c3-0.slvr-cbr1.lnh-slvr.md.cable.rcncustomer.com. [207.172.141.204]) by smtp.gmail.com with ESMTPSA id d6-20020ac80606000000b003bf9f9f1844sm9351784qth.71.2023.05.01.12.31.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 12:31:16 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: be9f0d3b-e856-11ed-b225-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682969477; x=1685561477; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Bnmwx4JL4zzfpoAgNv41/x6mI5Sl5Tvy0no2deSD0O4=; b=CbOoWqTSk3uKbjzelG8yqnld5byWglvqESK7A5ayA7t7shLwdOeyy9pYr2h0dHZ4sw Ioebaoj5c+mUhs5R428HbAlgESy36wct7HvPU+oF2sighIIgNW2S/bMhrwz2G2bU7eAR PzmvfvNi5zQlFQbN2MU0tjZW9ZGQ2YrqYPpfUK353KT9AyIsPVIIWXUt0bf5KdeuKy4r 7ttyjdCx983mA5YglTw1av0sK693taU4SPfn7jm3Xk/tPYsgPA/bWeAXUDACZE5DCRsI HPGPu/bDWsw9EvYxBiodD1s8ObxO8fmcp+DI9gRq0PdosiMcfYJh0fkyFQCSwdkoHQTx BOCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682969477; x=1685561477; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Bnmwx4JL4zzfpoAgNv41/x6mI5Sl5Tvy0no2deSD0O4=; b=OQI8i/AibKzefLly3forRo3Vn51hGG72o0vOyamOejU3/TDG5XhHc/VckUYbFj6Bxv v8uxi9H0XekL3O/e6pp31yt9jUCNMTUfHrFrFSr0HjLtCJTMkphOD3KYegnLjsd/XkOL Cjz5nBe+yZb7BFLKEYugoUkhXIKNqpuMJR2qgrIPUdWBhbIVZV0sjN1X6zadsi21a8p0 ffbfONklGA45eTuerewA3aylN8sENt2PdwN/vsvdOCjsrTFcU+rU0ID4Q2l/zIGy4RkI rj8z37aEQXLYAiVr1Ljg5aoZ61XxrH/mpf3z0a5PSyexZ78aepW28FmtqeOFAFUwIubi t2ig== X-Gm-Message-State: AC+VfDwQjYN7BdUfKRbPznmeI2FGNy7z7uN618QopAZwL/Rwe7Qiy5Bc 5RK/Xg1qig/bZkFkPFO3DlAosfsSEks= X-Google-Smtp-Source: ACHHUZ7BLXGnIebUIbZnncmPO+ryFBqQfenJ7JOTBDj0u5O37zFK/qjVSkLkOTcSG87sWV42QOYX7Q== X-Received: by 2002:ac8:4e4c:0:b0:3d4:17dc:3fcf with SMTP id e12-20020ac84e4c000000b003d417dc3fcfmr27298811qtw.5.1682969477226; Mon, 01 May 2023 12:31:17 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Wei Liu , Anthony PERARD Subject: [PATCH v3 12/14 RESEND] xenpm: Factor out a non-fatal cpuid_parse variant Date: Mon, 1 May 2023 15:30:32 -0400 Message-Id: <20230501193034.88575-13-jandryuk@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230501193034.88575-1-jandryuk@gmail.com> References: <20230501193034.88575-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1682970000343100001 Content-Type: text/plain; charset="utf-8" Allow cpuid_parse to be re-used without terminating xenpm. HWP will re-use it to optionally parse a cpuid. Unlike other uses of cpuid_parse, parse_hwp_opts will take a variable number of arguments and cannot just check argc. Signed-off-by: Jason Andryuk --- v2: Retained because cpuid_parse handles numeric cpu numbers and "all". --- tools/misc/xenpm.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index b2defde0d4..6e74606970 100644 --- a/tools/misc/xenpm.c +++ b/tools/misc/xenpm.c @@ -79,17 +79,26 @@ void help_func(int argc, char *argv[]) show_help(); } =20 -static void parse_cpuid(const char *arg, int *cpuid) +static int parse_cpuid_non_fatal(const char *arg, int *cpuid) { if ( sscanf(arg, "%d", cpuid) !=3D 1 || *cpuid < 0 ) { if ( strcasecmp(arg, "all") ) - { - fprintf(stderr, "Invalid CPU identifier: '%s'\n", arg); - exit(EINVAL); - } + return -1; + *cpuid =3D -1; } + + return 0; +} + +static void parse_cpuid(const char *arg, int *cpuid) +{ + if ( parse_cpuid_non_fatal(arg, cpuid) ) + { + fprintf(stderr, "Invalid CPU identifier: '%s'\n", arg); + exit(EINVAL); + } } =20 static void parse_cpuid_and_int(int argc, char *argv[], --=20 2.40.0 From nobody Sun May 19 15:58:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1682970040; cv=none; d=zohomail.com; s=zohoarc; b=Yx+b7or9YsgKbGfRAyl2PaDaWbY/EL+MlQTfchjQLRdP4CjP/E69411ReUZRQ13LO+6RRHy2aTqGg8j9gWF6LIX7Iw3cR7vAllMI7d8jDEwvovXnDzd87oA63MoeR9PPKBWgEOk91/Ob5OswyJFVux+S3NdNU0DhRPe5AXzsCDc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682970040; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8XlrjFSqYpzQJQGdwHcwomspneq906r3odg2YJyUcgo=; b=JYdCcAyz9r1oBhSUTR9t0aX6v8J6whbqN4WxuIyyNOWRV/TAXt4sJNBGkamYbH+hDXtvN85ZI0EIa0CxLWpgeGiJwrjPsR+04szEnpwFW6JD/5N0yF9iByG44JIvQG1g0HJt5OGj05eenB9x/BX23DGOVKVBIqZNPl3b7OvGBdc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1682970040622190.7614736529515; Mon, 1 May 2023 12:40:40 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.528215.821137 (Exim 4.92) (envelope-from ) id 1ptZNT-0006tx-9U; Mon, 01 May 2023 19:40:03 +0000 Received: by outflank-mailman (output) from mailman id 528215.821137; Mon, 01 May 2023 19:40:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptZNT-0006tV-1S; Mon, 01 May 2023 19:40:03 +0000 Received: by outflank-mailman (input) for mailman id 528215; Mon, 01 May 2023 19:40:02 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptZF5-0000m4-8M for xen-devel@lists.xenproject.org; Mon, 01 May 2023 19:31:23 +0000 Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [2607:f8b0:4864:20::835]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id c00e31df-e856-11ed-b225-6b7b168915f2; Mon, 01 May 2023 21:31:21 +0200 (CEST) Received: by mail-qt1-x835.google.com with SMTP id d75a77b69052e-3ef3ce7085bso12846761cf.2 for ; Mon, 01 May 2023 12:31:21 -0700 (PDT) Received: from pm2-ws13.praxislan02.com (207-172-141-204.s8906.c3-0.slvr-cbr1.lnh-slvr.md.cable.rcncustomer.com. [207.172.141.204]) by smtp.gmail.com with ESMTPSA id d6-20020ac80606000000b003bf9f9f1844sm9351784qth.71.2023.05.01.12.31.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 12:31:18 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c00e31df-e856-11ed-b225-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682969479; x=1685561479; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8XlrjFSqYpzQJQGdwHcwomspneq906r3odg2YJyUcgo=; b=ZIuYdu87cYcvUsSs9yRHdMP3Pm5GSwQX7w9kuI8lr30khecKw3o+OlElMPhyvABnrJ gmluE6uLnPxk7UG7YCcfHZ09VskA++s/5lNwNcL8uBI0ygSsE2yd/FAs/L4wPA/dADmj mz/pSaazJpvVfYBRmBPkf3yQIsyEtzTmHyiK6wFKzQIoUuy0eFTX95lH4LryFdZ8QlGc mpUhuxMhCZdalTvv135QKyZ5RBBJvgLVLI3EnjIJvrmqcrxpG5dAjwH1fRJm8b+q/mio DbsTwq7u5gfWM34SXiQxaAhatFXAMrRKNliQleEENClFijB/4MxYCoKTnPiDtgNawdSN yMIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682969479; x=1685561479; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8XlrjFSqYpzQJQGdwHcwomspneq906r3odg2YJyUcgo=; b=BIz8e8BYpRK/c0MmjhLaisW85pkMujWutMchCow0M7by8mI/HpOY0xlmWmESh4jOq+ j+gL8zqXgX6gXoANRfccvJwB8Z1/xqt6vU8AB2SaFD0MPZvjGxtxZ0NC4VZFhFKLorCH wYU5bzQEEbpDranua9UUv2vDehJuIN1JI5qRN/C/YYBocqFsEqq56wchzPlUQt7PmSkr 56tfKTl7Rx0E8FYlEzxcQZsLdzy2LK4QQSMyT6cU7gag7fnpKf//NENPR5Ps7kXtubL6 rWtLRD0cyi/nUXnh17jaw5vSIuCe4FJ666nunpdo+ctDuh2KqX1XoNI6vLR1W0AmH2Er 1C6g== X-Gm-Message-State: AC+VfDxre9MGUTBmyXcDwfddT5WW4Xxh3VcUZFa4QwQRWFTU78zg2w22 Foh1aqqiskBsBx2WCEFr7ayGo/kZaF4= X-Google-Smtp-Source: ACHHUZ6s7TAWu0GGiaRBOmaYwJA7QeeEcnz3hfdXYDb9SCnyiJRNs+k3LepojJZ5B4tKUB1oeC0+xQ== X-Received: by 2002:ac8:5a54:0:b0:3ef:380a:d7bc with SMTP id o20-20020ac85a54000000b003ef380ad7bcmr22971561qta.54.1682969479398; Mon, 01 May 2023 12:31:19 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Wei Liu , Anthony PERARD Subject: [PATCH v3 13/14 RESEND] xenpm: Add set-cpufreq-hwp subcommand Date: Mon, 1 May 2023 15:30:33 -0400 Message-Id: <20230501193034.88575-14-jandryuk@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230501193034.88575-1-jandryuk@gmail.com> References: <20230501193034.88575-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1682970041878100003 Content-Type: text/plain; charset="utf-8" set-cpufreq-hwp allows setting the Hardware P-State (HWP) parameters. It can be run on all or just a single cpu. There are presets of balance, powersave & performance. Those can be further tweaked by param:val arguments as explained in the usage description. Parameter names are just checked to the first 3 characters to shorten typing. Some options are hardware dependent, and ranges can be found in get-cpufreq-para. Signed-off-by: Jason Andryuk --- v2: Compare provided parameter name and not just 3 characters. Use "-" in parameter names Remove hw_ Replace sscanf with strchr & strtoul. Remove toplevel error message with lower level ones. Help text s/127/128/ Help text mention truncation. Avoid some truncation rounding down by adding 5 before division. Help test mention default microseconds Also comment the limit check written to avoid overflow. --- tools/misc/xenpm.c | 230 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 230 insertions(+) diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index 6e74606970..8d99c78670 100644 --- a/tools/misc/xenpm.c +++ b/tools/misc/xenpm.c @@ -16,6 +16,7 @@ */ #define MAX_NR_CPU 512 =20 +#include #include #include #include @@ -67,6 +68,27 @@ void show_help(void) " set-max-cstate |'unlimited' [|'unlimited']= \n" " set the C-State limitati= on ( >=3D 0) and\n" " optionally the C-sub-sta= te limitation ( >=3D 0)\n" + " set-cpufreq-hwp [cpuid] [balance|performance|powersave= ] *\n" + " set Hardware P-State (HW= P) parameters\n" + " optionally a preset of o= ne of\n" + " balance|performance|po= wersave\n" + " an optional list of para= m:val arguments\n" + " minimum:N lowest ... = highest\n" + " maximum:N lowest ... = highest\n" + " desired:N lowest ... = highest\n" + " Set explicit perfo= rmance target.\n" + " non-zero disables = auto-HWP mode.\n" + " energy-perf:0-255 (or = 0-15)\n" + " energy/per= formance hint\n" + " lower - fa= vor performance\n" + " higher - f= avor powersave\n" + " 128 (or 7)= - balance\n" + " act-window:N{,m,u}s ra= nge 1us-1270s\n" + " window for interna= l calculations.\n" + " Defaults to us wit= hout units.\n" + " Truncates un-repre= sentable values.\n" + " 0 lets the hardwar= e decide.\n" + " get-cpufreq-para returns= lowest/highest.\n" " start [seconds] start collect Cx/Px stat= istics,\n" " output after CTRL-C or S= IGINT or several seconds.\n" " enable-turbo-mode [cpuid] enable Turbo Mode for pr= ocessors that support it.\n" @@ -1299,6 +1321,213 @@ void disable_turbo_mode(int argc, char *argv[]) errno, strerror(errno)); } =20 +/* + * Parse activity_window:NNN{us,ms,s} and validate range. + * + * Activity window is a 7bit mantissa (0-127) with a 3bit exponent (0-7) b= ase + * 10 in microseconds. So the range is 1 microsecond to 1270 seconds. A = value + * of 0 lets the hardware autonomously select the window. + * + * Return 0 on success + * -1 on error + */ +static int parse_activity_window(xc_set_hwp_para_t *set_hwp, unsigned long= u, + const char *suffix) +{ + unsigned int exponent =3D 0; + unsigned int multiplier =3D 1; + + if ( suffix && suffix[0] ) + { + if ( strcasecmp(suffix, "s") =3D=3D 0 ) + { + multiplier =3D 1000 * 1000; + exponent =3D 6; + } + else if ( strcasecmp(suffix, "ms") =3D=3D 0 ) + { + multiplier =3D 1000; + exponent =3D 3; + } + else if ( strcasecmp(suffix, "us") =3D=3D 0 ) + { + multiplier =3D 1; + exponent =3D 0; + } + else + { + fprintf(stderr, "invalid activity window units: \"%s\"\n", suf= fix); + + return -1; + } + } + + /* u * multipler > 1270 * 1000 * 1000 transformed to avoid overflow. */ + if ( u > 1270 * 1000 * 1000 / multiplier ) + { + fprintf(stderr, "activity window is too large\n"); + + return -1; + } + + /* looking for 7 bits of mantissa and 3 bits of exponent */ + while ( u > 127 ) + { + u +=3D 5; /* Round up to mitigate truncation rounding down + e.g. 128 -> 120 vs 128 -> 130. */ + u /=3D 10; + exponent +=3D 1; + } + + set_hwp->activity_window =3D (exponent & HWP_ACT_WINDOW_EXPONENT_MASK)= << + HWP_ACT_WINDOW_EXPONENT_SHIFT | + (u & HWP_ACT_WINDOW_MANTISSA_MASK); + set_hwp->set_params |=3D XEN_SYSCTL_HWP_SET_ACT_WINDOW; + + return 0; +} + +static int parse_hwp_opts(xc_set_hwp_para_t *set_hwp, int *cpuid, + int argc, char *argv[]) +{ + int i =3D 0; + + if ( argc < 1 ) { + fprintf(stderr, "Missing arguments\n"); + return -1; + } + + if ( parse_cpuid_non_fatal(argv[i], cpuid) =3D=3D 0 ) + { + i++; + } + + if ( i =3D=3D argc ) { + fprintf(stderr, "Missing arguments\n"); + return -1; + } + + if ( strcasecmp(argv[i], "powersave") =3D=3D 0 ) + { + set_hwp->set_params =3D XEN_SYSCTL_HWP_SET_PRESET_POWERSAVE; + i++; + } + else if ( strcasecmp(argv[i], "performance") =3D=3D 0 ) + { + set_hwp->set_params =3D XEN_SYSCTL_HWP_SET_PRESET_PERFORMANCE; + i++; + } + else if ( strcasecmp(argv[i], "balance") =3D=3D 0 ) + { + set_hwp->set_params =3D XEN_SYSCTL_HWP_SET_PRESET_BALANCE; + i++; + } + + for ( ; i < argc; i++) + { + unsigned long val; + char *param =3D argv[i]; + char *value; + char *suffix; + int ret; + + value =3D strchr(param, ':'); + if ( value =3D=3D NULL ) + { + fprintf(stderr, "\"%s\" is an invalid hwp parameter\n", argv[i= ]); + return -1; + } + + value[0] =3D '\0'; + value++; + + errno =3D 0; + val =3D strtoul(value, &suffix, 10); + if ( (errno && val =3D=3D ULONG_MAX) || value =3D=3D suffix ) + { + fprintf(stderr, "Could not parse number \"%s\"\n", value); + return -1; + } + + if ( strncasecmp(param, "act-window", strlen(param)) =3D=3D 0 ) + { + ret =3D parse_activity_window(set_hwp, val, suffix); + if (ret) + return -1; + + continue; + } + + if ( val > 255 ) + { + fprintf(stderr, "\"%s\" value \"%lu\" is out of range\n", para= m, + val); + return -1; + } + + if ( suffix && suffix[0] ) + { + fprintf(stderr, "Suffix \"%s\" is invalid\n", suffix); + return -1; + } + + if ( strncasecmp(param, "minimum", MAX(2, strlen(param))) =3D=3D 0= ) + { + set_hwp->minimum =3D val; + set_hwp->set_params |=3D XEN_SYSCTL_HWP_SET_MINIMUM; + } + else if ( strncasecmp(param, "maximum", MAX(2, strlen(param))) =3D= =3D 0 ) + { + set_hwp->maximum =3D val; + set_hwp->set_params |=3D XEN_SYSCTL_HWP_SET_MAXIMUM; + } + else if ( strncasecmp(param, "desired", strlen(param)) =3D=3D 0 ) + { + set_hwp->desired =3D val; + set_hwp->set_params |=3D XEN_SYSCTL_HWP_SET_DESIRED; + } + else if ( strncasecmp(param, "energy-perf", strlen(param)) =3D=3D = 0 ) + { + set_hwp->energy_perf =3D val; + set_hwp->set_params |=3D XEN_SYSCTL_HWP_SET_ENERGY_PERF; + } + else + { + fprintf(stderr, "\"%s\" is an invalid parameter\n", param); + return -1; + } + } + + if ( set_hwp->set_params =3D=3D 0 ) + { + fprintf(stderr, "No parameters set in request\n"); + return -1; + } + + return 0; +} + +static void hwp_set_func(int argc, char *argv[]) +{ + xc_set_hwp_para_t set_hwp =3D {}; + int cpuid =3D -1; + int i =3D 0; + + if ( parse_hwp_opts(&set_hwp, &cpuid, argc, argv) ) + exit(EINVAL); + + if ( cpuid !=3D -1 ) + { + i =3D cpuid; + max_cpu_nr =3D i + 1; + } + + for ( ; i < max_cpu_nr; i++ ) + if ( xc_set_cpufreq_hwp(xc_handle, i, &set_hwp) ) + fprintf(stderr, "[CPU%d] failed to set hwp params (%d - %s)\n", + i, errno, strerror(errno)); +} + struct { const char *name; void (*function)(int argc, char *argv[]); @@ -1309,6 +1538,7 @@ struct { { "get-cpufreq-average", cpufreq_func }, { "start", start_gather_func }, { "get-cpufreq-para", cpufreq_para_func }, + { "set-cpufreq-hwp", hwp_set_func }, { "set-scaling-maxfreq", scaling_max_freq_func }, { "set-scaling-minfreq", scaling_min_freq_func }, { "set-scaling-governor", scaling_governor_func }, --=20 2.40.0 From nobody Sun May 19 15:58:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1682970042; cv=none; d=zohomail.com; s=zohoarc; b=V8+SDVdBvK+jfDq3astLCsBrAeuqX322rHDtQYXKZuE1KdeSumLQM0K+wP5lPyCInGiQ9QLpeV/hbC4mZ5uGcqOHeouvISg6sIg9DqiWvgI+l14qb84waTta9J+nnt4I2R6AA9taEoU1T9Ihjii6pG+B5mAcGxFZHcA+GEnfCS4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682970042; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/Y4+dyjBVr8IC4wKpAH33RVK4Uwk38u6mRfHXdnUc88=; b=H9Ul0QlOXxJVQ786oDH6ptu0nZUcg/VD15wtr6eVPATPX41V82QmfzBZsPY40n8XZBMMfp1jJ/3nFoIkH4GpZxxJb4E02aJo8zNQWJ8EW6JBcQDCEWVupWtah4npeG9Cj67hM9P93sVAH4vyVV4lTomvxXZgpeNpc+GY3ax1ytY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1682970042348903.656278422457; Mon, 1 May 2023 12:40:42 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.528216.821145 (Exim 4.92) (envelope-from ) id 1ptZNV-0007K6-0K; Mon, 01 May 2023 19:40:05 +0000 Received: by outflank-mailman (output) from mailman id 528216.821145; Mon, 01 May 2023 19:40:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptZNU-0007II-PJ; Mon, 01 May 2023 19:40:04 +0000 Received: by outflank-mailman (input) for mailman id 528216; Mon, 01 May 2023 19:40:03 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptZF7-0000m4-8s for xen-devel@lists.xenproject.org; Mon, 01 May 2023 19:31:25 +0000 Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [2607:f8b0:4864:20::72d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id c1497016-e856-11ed-b225-6b7b168915f2; Mon, 01 May 2023 21:31:23 +0200 (CEST) Received: by mail-qk1-x72d.google.com with SMTP id af79cd13be357-74e1745356dso122713385a.0 for ; Mon, 01 May 2023 12:31:23 -0700 (PDT) Received: from pm2-ws13.praxislan02.com (207-172-141-204.s8906.c3-0.slvr-cbr1.lnh-slvr.md.cable.rcncustomer.com. [207.172.141.204]) by smtp.gmail.com with ESMTPSA id d6-20020ac80606000000b003bf9f9f1844sm9351784qth.71.2023.05.01.12.31.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 12:31:20 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c1497016-e856-11ed-b225-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682969481; x=1685561481; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/Y4+dyjBVr8IC4wKpAH33RVK4Uwk38u6mRfHXdnUc88=; b=El+j9CYH92/VkKvU0xX/iezFblXzbQBrsLh2hY6wa/mKGGMU40Uw1TuWpMCuy0pgxJ 5j25wvX86m18bmSl4JWCZOcYJgk4pkihBGHshqS6ZFUQ3VIwp5N3Sx3TYb8/S1ZWaUXX gi9MXhzcIjciT/IIbb4Y2gqBo4BOTJvuvt1CgX8wloUt0Cha3xzpy4q068L65lQYB+0O goNpAjrDRmeJjVeFBsddApKCxJ5eMSmOy5WS24SN7q1UKc5j3TwAvJKKYLQod5Fyz23R p0iYFyedNbgM2llrYVboI5n03letvmTsNNr+ABaInQsOGR85gbcJJeGWwNcalW1N833h C7FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682969481; x=1685561481; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/Y4+dyjBVr8IC4wKpAH33RVK4Uwk38u6mRfHXdnUc88=; b=cQEWzQZcnc3tyGx2ESF2u1OO5bHyg7fA220AhbA1id46OJ1SZnzdWq8bncFcmOEOXJ SY73NsjvdjD2G+uSabkXcTmQYMeh+g+MsPxIAWSQLgxa/RDhxBc+gfZ9iDH369VRACT/ 5Qn8KPOAWV5o8y+OlYWcPGLVqn9g8h/R9hO6DpJ6Wve2jcNs89byEcPsGHKOO3/C7imO LNJHu0JRd52Ht6l7Jtr+P1EC2k3XJLkS4RlqMojsUEcpM9Rk/bXBq7/abh2p3JgqynPB oVZrdyHx+D/tqQmaCBGnaBkQLhS/O+fvQbiBLWxtXNHTHZzaoLUiJ5XdTdJOxHWFakEG VsAA== X-Gm-Message-State: AC+VfDwdl+hoM7Bsspho8fSWT16oionsMF0VrdstzPl/jE4x3U2w7U6V Hyu7LDggm3APUEAIyuEsJvbaSPCqByQ= X-Google-Smtp-Source: ACHHUZ7oF2OrgJXKm39RGRVXI1vKWuuYqbfsPQUZk89HXKREDFLA2mFb9YF3y3DhBgK9OOK1C/WqCg== X-Received: by 2002:ac8:5747:0:b0:3f2:1f2f:dc80 with SMTP id 7-20020ac85747000000b003f21f2fdc80mr6028725qtx.9.1682969481554; Mon, 01 May 2023 12:31:21 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Henry Wang , Community Manager Subject: [PATCH v3 14/14 RESEND] CHANGELOG: Add Intel HWP entry Date: Mon, 1 May 2023 15:30:34 -0400 Message-Id: <20230501193034.88575-15-jandryuk@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230501193034.88575-1-jandryuk@gmail.com> References: <20230501193034.88575-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1682970043848100005 Content-Type: text/plain; charset="utf-8" Signed-off-by: Jason Andryuk Acked-by: Henry Wang --- v3: Position under existing Added section Add Henry's Ack v2: Add blank line --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dbf8b06d7..2eb9e2cfd0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepach= angelog.com/en/1.0.0/) - Bus-lock detection, used by Xen to mitigate (by rate-limiting) the sy= stem wide impact of a guest misusing atomic instructions. - xl/libxl can customize SMBIOS strings for HVM guests. + - Add Intel Hardware P-States (HWP) cpufreq driver. =20 ## [4.17.0](https://xenbits.xen.org/gitweb/?p=3Dxen.git;a=3Dshortlog;h=3DR= ELEASE-4.17.0) - 2022-12-12 =20 --=20 2.40.0