From patchwork Fri Sep 9 16:45:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yuan, Perry" X-Patchwork-Id: 604507 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6E9EECAAD5 for ; Fri, 9 Sep 2022 16:47:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231502AbiIIQrZ (ORCPT ); Fri, 9 Sep 2022 12:47:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230411AbiIIQrM (ORCPT ); Fri, 9 Sep 2022 12:47:12 -0400 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2078.outbound.protection.outlook.com [40.107.237.78]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB760145FD7; Fri, 9 Sep 2022 09:47:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XOlekUrbLM+JNNhLXp6qOuIdbMRRXJfiBWaV5mYuZYxRxg6d2Xmn6YI7EGsnTFYHBETZU2rRCXGFLd8qzl8oE9qayxBogwKD1C7mOvAaFTEOJxz9PSi0XdFr3VQceFx5eJw9+/uPWkcrV9cqBNp5Slj+2pc1sJl17tMJE9zKrHcAzt0Gk/EOJsKhba3dEcvt1mN0wt+1IeUrf35JcgRoR98iOT0c0m11e9hE1jCvW0f6CI2eL5iPU+fyVD7vcdDk+rhEH7w9rvVckDFUelMmCb1LDZjgQRIfRj8ncvHP7oFDK2qEYXUSRbvYaDTY7HsJ94FTAfcksveVWffKvdSGlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Z/cGtf9+VESY5wZ93GklyFOBnmXyxals8K0wmhUcUXY=; b=XX0UlTebJ+VEVV/ar2ohqGc8T2I+uQrRR8CVKColWnH8LteNhdLgfJaZgMR6KxIh5DAH99rEzi1vD1kM1rUibD3VeTsKh8Z9hdyccDBOQyKFJgoqEFJcVap8YRyiLfsWOX1crCwovBdJ7Ct37j0ZYv9nK38+Kqlg1TPOPhIh47H6ojfTocP8GogPk83sVt2HskQpqZchUOcIT7VgKLZM6ocnVNQuYDC6FLoewbhhJuUO9bxiVCf/rdlhFVC7ItaQo7osK10zI/byD3ELZ0MFV8p0DY43B2IFww9KobUEdZAksYtCc0kyn5Wa6paIRYtY2ZBDp591SMSOgFBDpUZ5Hw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Z/cGtf9+VESY5wZ93GklyFOBnmXyxals8K0wmhUcUXY=; b=qOQLw92GVafMSmHuHD/Sd07z13o/xGzYiKW2Rp1+wWvWzvC7SXYQ3vuf+TRGp4PZTWj8Fks1SOz0kzLjjpJkC3t8DcQBeoO6BrpIMp4AmbFnXnOBOyrrtMWEze3LFoLDh5OWSG/O/OQ3vrKjTwAQISRzjNM1A1nR4SJqen3r8DQ= Received: from BN9PR03CA0361.namprd03.prod.outlook.com (2603:10b6:408:f7::6) by DS0PR12MB6438.namprd12.prod.outlook.com (2603:10b6:8:ca::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5588.11; Fri, 9 Sep 2022 16:47:05 +0000 Received: from BN8NAM11FT025.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f7:cafe::db) by BN9PR03CA0361.outlook.office365.com (2603:10b6:408:f7::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.14 via Frontend Transport; Fri, 9 Sep 2022 16:47:04 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT025.mail.protection.outlook.com (10.13.177.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5612.13 via Frontend Transport; Fri, 9 Sep 2022 16:47:04 +0000 Received: from pyuan-Cloudripper.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Fri, 9 Sep 2022 11:46:59 -0500 From: Perry Yuan To: , , CC: , , , , , , , , , , Perry Yuan Subject: [PATCH 2/7] cpufreq: amd_pstate: add module parameter to load amd pstate EPP driver Date: Sat, 10 Sep 2022 00:45:29 +0800 Message-ID: <20220909164534.71864-3-Perry.Yuan@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220909164534.71864-1-Perry.Yuan@amd.com> References: <20220909164534.71864-1-Perry.Yuan@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT025:EE_|DS0PR12MB6438:EE_ X-MS-Office365-Filtering-Correlation-Id: 0acbfed9-cec1-439f-0def-08da9282ed25 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: w97IpLXTO+ovwcIfBrmkAs/0v35DpK0NxJFOMh7Eth5prkh/C5hBv0GaQmuUI5+LDAKNJ3bv3McfBX/2CQS8FLGOYa2hJ6BlZf7rUfp2elqft6QHbjvMESWLMj5qwtNXc4jmDGKZHJzLU8ys02g5xURBG3tXgrXBRLbx5+rNUfnRRD+qIKy5JHBdfUdW6xM1eqJf2Q3etrP2QKwyDoiwj6w26QqDHIYduh1WEkO/Zfe93uxCvxATglfhKlVDSSZ9dE1qWBjq2uiNFYAnlS7wMpYBL6JGrVIKIPJI4UIXDWVtDlLxSROEDCSbqRyMtDkhTiVCX+uCl8qC0YcY1eBEHGo8dH16OcqRsYSKv8vVIn5URnQFAwTms8+iTgV1StubzzlKvlTK+2EXNaf9GdpVC80B63qy6D2403JdTGsFLDKrQDGiNI1E6H/J3zFmmGZsRhUChmk2K3JorsU/28YfbZCrALsDV1MRBglxNo47hqiI42ecuf3frfbWr0lrRwSgOoxEv8GOVIgbpXssf7yIei81EM/uct27tKx2wZ44NtHztKbB08TA6Aq0M2HcdwiC+kLT3jXaqgdqiK2wLH/oMO1/qrxG4qEP7M5IuxdvuB1UktJ2xcvo9iIr9V8Kl7U/bHybFn6u+IJ6Ti4bbh4miwdh46pEx6kbrJTjbvkmXtOox09qL8F1hXI7I9U9WT18xmD6sE98oGOQLayUMMJ+iJSsjSfI5zvuq3gHz2J/Ypmq0CZL7uDW4+W/MvzhpA13+4i6pmJFlofMkkxwc+XLbA+a1oYa6kF98iGSgcJ6EbscI/I7lLA/YqQ99nvGDM7u91acHB2r5ymUeR62ar8bjA== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230016)(4636009)(376002)(346002)(396003)(136003)(39860400002)(36840700001)(40470700004)(46966006)(83380400001)(82310400005)(36860700001)(40480700001)(82740400003)(36756003)(4326008)(110136005)(316002)(54906003)(70586007)(478600001)(70206006)(8676002)(5660300002)(336012)(16526019)(1076003)(47076005)(186003)(40460700003)(6666004)(426003)(8936002)(26005)(41300700001)(81166007)(356005)(7696005)(86362001)(2616005)(2906002)(36900700001)(2101003); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2022 16:47:04.7753 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0acbfed9-cec1-439f-0def-08da9282ed25 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT025.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB6438 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The amd_pstate mode parameter will allow user to select which amd pstate working mode as booting mode, amd_pstate instance or amd_pstate_epp instance. 1) amd_pstate instance is depending on the target operation mode. 2) amd_pstate_epp instance is depending on the set_policy operation mode.It is also called active mode that AMD SMU has EPP algorithm to control the CPU runtime frequency according to the EPP set value and workload. Signed-off-by: Perry Yuan --- drivers/cpufreq/amd-pstate.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index a2463f785322..451295284a26 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -58,6 +58,12 @@ module_param(shared_mem, bool, 0444); MODULE_PARM_DESC(shared_mem, "enable amd-pstate on processors with shared memory solution (false = disabled (default), true = enabled)"); +static bool epp_enabled = true; +module_param(epp_enabled, bool, 0444); +MODULE_PARM_DESC(epp_enabled, + "load amd_pstate or amd_pstate_epp (true = amd_pstate_epp driver instance (default), false = amd_pstate driver instance)"); + + static struct cpufreq_driver amd_pstate_driver; /** From patchwork Fri Sep 9 16:45:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yuan, Perry" X-Patchwork-Id: 604506 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F96CC6FA89 for ; Fri, 9 Sep 2022 16:47:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230411AbiIIQr3 (ORCPT ); Fri, 9 Sep 2022 12:47:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231410AbiIIQrY (ORCPT ); Fri, 9 Sep 2022 12:47:24 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2058.outbound.protection.outlook.com [40.107.93.58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C87CF146718; Fri, 9 Sep 2022 09:47:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TIH7Bc1oLkiMXxC6a4FG+SKum7MiQnW9uWJIi8QbIvDvMs6ZLiMvTe0w0fOR1lPZ0RcEYm0n55yu3gPiaR57TcVc3e8mrGc1xO6WRjuXzavSzN/jTj/BQoLkm+O+VznIYe95ASmCrvDPU1k+SpY5bOmpPDupoiP+ayeu1EMYT+6BEqWskNYLPQlM0TFg7/GwEZT6KoqVcZK7d2q/Op3RBdxuxYb3HTLMUPv72OQHfkjgrmR3uubtJkwDvwvaP32CD9O45A3gt6yo4AIHntpjqlinBHXpiMnWrrcg1+jPh2DMgIEQuBs2uzZEdUpdredENq8b2aNmy+zHuTXHU6x0Ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=kC69undPd9prgDfk2+oDR8hnkoDqMpO/heJpaVlZFMY=; b=hJGofMJ/sl9875fn/pXvZ2fJuYU9FSFMbs92wyFjSOlhV5c37YE4IXW2MOjuvFejkKBsC1CWljcI5ArmtLirM4HfGajCW2VB2Z3QdpP9RXRW34ewZK7fnmaugYEyL5FvjRiY7d7itrpv4nxd4WsUhWQrI1/wROjmA/7KpiU7EGi21lLAz3Uq52DLwlFfJyp84MTO9MnYj1ZuQ1RcX9kSbKIXgOV/iyhv3B3Qz0aDvqIWgX2ptYbfV9w+gZcSoLIlLPHkzXlnGTmNkyQcvE6CEV3CPSvaxQdJQi8UutaZyQK7Itq3AJSX3sY+QU0AKAW47fQMZ3XsEELfknBoGPT55w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kC69undPd9prgDfk2+oDR8hnkoDqMpO/heJpaVlZFMY=; b=LMOpu4h2NdOL9OAJ4pRhzNIlpt0tqocGkzSkFhU7wOwuKGem/uhDmelJA6TizaspNYw6BB9WZwfkhezcwJBu9iv0Y6nZj8gYXbj9bOe75hjcbDodB+jqJiHu0HTIPpXN9GISMN614dZ3aRY3DKQI7R3KLRYgPHgYoAs4emG0YoE= Received: from BN8PR04CA0024.namprd04.prod.outlook.com (2603:10b6:408:70::37) by DS0PR12MB6583.namprd12.prod.outlook.com (2603:10b6:8:d1::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5588.17; Fri, 9 Sep 2022 16:47:12 +0000 Received: from BN8NAM11FT078.eop-nam11.prod.protection.outlook.com (2603:10b6:408:70:cafe::c2) by BN8PR04CA0024.outlook.office365.com (2603:10b6:408:70::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.14 via Frontend Transport; Fri, 9 Sep 2022 16:47:12 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT078.mail.protection.outlook.com (10.13.176.251) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5612.13 via Frontend Transport; Fri, 9 Sep 2022 16:47:11 +0000 Received: from pyuan-Cloudripper.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Fri, 9 Sep 2022 11:47:07 -0500 From: Perry Yuan To: , , CC: , , , , , , , , , , Perry Yuan Subject: [PATCH 4/7] cpufreq: amd_pstate: add AMD pstate EPP support for shared memory type processor Date: Sat, 10 Sep 2022 00:45:31 +0800 Message-ID: <20220909164534.71864-5-Perry.Yuan@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220909164534.71864-1-Perry.Yuan@amd.com> References: <20220909164534.71864-1-Perry.Yuan@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT078:EE_|DS0PR12MB6583:EE_ X-MS-Office365-Filtering-Correlation-Id: 4531172b-5706-4f9e-fb9f-08da9282f16a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AcUD3TzWfmXHdrPmzT6eG3I7HcC+JVZQdEHXcIyQnRKv/eRV4CNWQdF9xRECj1n2c4EnHI3E6J76icC6LPZXQ0hJ2w03o58zYM/HuOlCbjOYiiE12ad/PYbyA1jez7qK7//RPkXLOhb0wF9Uuhf4XNTpGApYAM5RBWXVp5qyLA2UiV6JVSVAkBrn+bsGOoMtU3KhKwbEpR1Saq3YGfpsyNTRVcpa6NPXNzcO6cd3raeMXSN1fjY3dRXWeeyKJ4prmN+BKgkh1zySuQ5YsuSjmud+WE5VG3NB4grzF8u3CrPJAM/+IOFXgbTFBJy/ACAZo5YLhTWt1Nl7lAt9mMtwPqh8EeFJv7sBLUdilehbKewxNAXFHeB3h4gvdaz/Mru4Xaicyn9do5Egb5czGsCAtuQQgdZ+Hn6MztU6xR3t7Fq9OEESCQ0pZ/QYSx8dW4tVYLiTI9HQwd7wnX4IJ6yWeXa3aGPyTnSyte1PjNUftq09AyCoMrlEY6sJmx4w4DJDNFYl3tAYTPPK0SGXhjFqaXt+L0spsgDFNbM46PfPqM/2ywnsDHBngr9brepmWSgd1/9cqKcVBuCFYccOWha9JrriCivjc9M+cpQbTapD/K80N5FBkghW170sGUZgKqOj9Mmg4WT+mSKWzY0GSjYUHfRBHMGO+EHc1iXHnSY0Sn7lIcT1JzVAqoPcmVfeYE5jqpWcAUcj3LQjG6MkENCqmf/qgtq5ClLDX1X8eDqI/XKcNmDJZ1RGqKCMfh+Bqb0T0rMEYtqHeKrzjJTOck2KloJGdrMqen+WpqkjFHUYZx/18pWqtf1VKS13rp/EexSuUStSaLNqleoH8EW3WgRRvQ== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230016)(4636009)(346002)(376002)(136003)(396003)(39860400002)(36840700001)(40470700004)(46966006)(5660300002)(8936002)(16526019)(54906003)(316002)(336012)(356005)(40460700003)(110136005)(6666004)(41300700001)(186003)(2616005)(36756003)(82310400005)(478600001)(70586007)(86362001)(70206006)(26005)(426003)(47076005)(2906002)(36860700001)(8676002)(82740400003)(1076003)(4326008)(7696005)(40480700001)(81166007)(36900700001)(2101003); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2022 16:47:11.9445 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4531172b-5706-4f9e-fb9f-08da9282f16a X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT078.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB6583 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Add Energy Performance Preference support for AMD SOCs which only support the shared memory interface that implemented on Zen2 and Zen3 processors, because this type CPU has no MSR supported, it will use ACPI PCC channel to enable EPP and reset desired perf to be zero. Signed-off-by: Perry Yuan --- drivers/cpufreq/amd-pstate.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index 451295284a26..fff298744a8e 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -133,12 +133,24 @@ static inline int pstate_enable(bool enable) static int cppc_enable(bool enable) { + struct cppc_perf_ctrls perf_ctrls; int cpu, ret = 0; for_each_present_cpu(cpu) { ret = cppc_set_enable(cpu, enable); if (ret) return ret; + + /* Enable active mode for EPP */ + ret = cppc_set_auto_epp(cpu, enable); + if (ret) + return ret; + + /* Set zero to desired perf to enable EPP control*/ + perf_ctrls.desired_perf = 0; + ret = cppc_set_perf(cpu, &perf_ctrls); + if (ret) + return ret; } return ret; From patchwork Fri Sep 9 16:45:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yuan, Perry" X-Patchwork-Id: 604505 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ACD52ECAAD3 for ; Fri, 9 Sep 2022 16:48:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232010AbiIIQr5 (ORCPT ); Fri, 9 Sep 2022 12:47:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231709AbiIIQr0 (ORCPT ); Fri, 9 Sep 2022 12:47:26 -0400 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38D11146D02; Fri, 9 Sep 2022 09:47:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Pm6Hrbz511lxE9lupJKyu8U0WZdYMEmW+tSf5Tm1RKYvM8LlOC9XRU1x0tCyEQDFq50xmmV6Vg89lPqQgqTC9xUVPnR1RpcqF4LFdvOWA7sCOCtl6MF6P22Nf3QPsjyvUsYxaa0FLIuWxnM1r40lbsR6kk1y5yM5lZG8oWUezITd/aSAbWZ1bWRiFAtrVhOhtG2D6y0PVCL1sL4K/n6XC3jLZQmkBfXAnBRnoWPdJyUbq+GuHK7XJLHQBox1hcsr7foDyp8KVaSwaXz5y6yaz+eVETtygZvQ4hc2SJL8ofZJ+QwJ2DDmPc7rZ0djYc5aFMZVvgewNvOAgiKGX2AR1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Mwba5O6u2AqiwszJ7wr2LfLQjiVhEK0hCMWXy3TYOmM=; b=Gho8SYBO0ymD01advwDMbwqbdjmQ87g6tQ8MHtB+mEpbcW4rnv9NQYnf27jaVorcAUBoNwacpFWEvsPtHstYFXVvh7lLKUbH40xRb7jcNnhA7rprm3AobAYPWUmZgKElHrDTT13N0XGs60Jx2IBurdwXP/6RerfQVFoXdTxuCMPSx922dF0SKnU2fJP2UyoO3cNGu/TgJAZGfEU7YeRE3PKUed4t+j6JJMKBwilfhslzHKe3GXrpufSO5Bu4UEpDIHY6jQK7ceEIMcWuJGEX1ltvz0uTe29pRU6uDjgRthsDKBOa7SqS8VSjfhsgGS5gW1ei5d0d/herFZDopaDxow== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Mwba5O6u2AqiwszJ7wr2LfLQjiVhEK0hCMWXy3TYOmM=; b=Vyc7EvjWdazVE0AYMV61mDaKWaez1R0xaqBFdAt8JrIupSlCyzZY5fAzMtkgsQ9PozXaTIiL2MBhf88cLhUN53XUfA2MwTZU3yG2pxsOoOibPeKkHmPJbp4ezC/+TLoVf5Zn99qn3iAWnYmk7bXuxgOf/QMsp4HvqIvujOcm774= Received: from BN0PR02CA0020.namprd02.prod.outlook.com (2603:10b6:408:e4::25) by SJ1PR12MB6291.namprd12.prod.outlook.com (2603:10b6:a03:456::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5588.12; Fri, 9 Sep 2022 16:47:17 +0000 Received: from BN8NAM11FT091.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e4:cafe::83) by BN0PR02CA0020.outlook.office365.com (2603:10b6:408:e4::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.12 via Frontend Transport; Fri, 9 Sep 2022 16:47:16 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT091.mail.protection.outlook.com (10.13.176.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5612.13 via Frontend Transport; Fri, 9 Sep 2022 16:47:16 +0000 Received: from pyuan-Cloudripper.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Fri, 9 Sep 2022 11:47:10 -0500 From: Perry Yuan To: , , CC: , , , , , , , , , , Perry Yuan Subject: [PATCH 5/7] cpufreq: amd_pstate: add AMD Pstate EPP support for the MSR based processors Date: Sat, 10 Sep 2022 00:45:32 +0800 Message-ID: <20220909164534.71864-6-Perry.Yuan@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220909164534.71864-1-Perry.Yuan@amd.com> References: <20220909164534.71864-1-Perry.Yuan@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT091:EE_|SJ1PR12MB6291:EE_ X-MS-Office365-Filtering-Correlation-Id: ea909c96-7ed9-4180-043d-08da9282f44a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: od7KROi2Fv6Qzy5f1bQtjCHA37cRCkOgNy+v/2DlWi5du+6t5vInIeDK4NLSK8YnMLkPLmwnUHr4yL1oxhcTEUC6bnidxNFC6+8YVFzPn3sRLcAIh3hT2eNEy4jdIc6PUTyLVLwfCpguO3HoZh7bWFPDTbapXqNpSYHjgybIs7PXGg5Mk1KXva9G0H+kjQqRQvZE3GyCFEHIids5OO3lur42gNNacsp/Gvo8X1GrWcovB0HpIX+juvgYETkWoHvOhuSTnyW+cPvPfq0Aq78dV5Yi3UpmVjzwTIhNuprlMolBYZ+YsHIy/2a4gFPsWr5HdXrA02oFEuRGKat6SxSZjxZycUJcH+lB1EWaLi/cpjG6UwUUfKkc4zFoA2JZvbIJWFEFaN8INpMRIMLfecDMrxJq+z/JGkJVrZmYx6ioUU8rKKfPDy6GSMaP9YGWoCDxS32hzTB49/8MLBmSgAIlkzVZeuQ1a6z8tdu2lCwUTRiLw9mLna9chuwEnciE8E4T6mN1ifyXEWG2Q55L7DUBYe0iK59oEC8gcmeSO2APNAGZY2KRTlucy6Hf8ORwum73A9P0/7I+/H6HDDLzLICmC76fDLKn/eLEuXOpe1qUDonVrKSiyzvcQBTuh6mnB5EzY08zNQvhQxkcnJFWc34qiIZqu358PUsU5jKDcHyOLsbyVrE5beChZtgE8GukKphy4cJSLwB+fiU8AsXFCDzFO715ioH/BTZSqiEIn1xuXTb4055HrRQzpr8BWyYJwEC+fW1egB9PvRqJ7CKIVnPBvoYdUn/9tjsVhrmnICiq+HO/EM45/JPDjxsPIa3X2tHBYH45/hBt//6TP6f/FbRw967BWrMkbWf0pHnx2+lCTbU= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230016)(4636009)(346002)(376002)(136003)(396003)(39860400002)(40470700004)(46966006)(36840700001)(83380400001)(1076003)(356005)(81166007)(36756003)(16526019)(86362001)(6666004)(47076005)(26005)(336012)(186003)(2616005)(7696005)(41300700001)(426003)(40480700001)(82310400005)(316002)(54906003)(4326008)(70206006)(110136005)(8676002)(478600001)(8936002)(30864003)(70586007)(2906002)(5660300002)(36860700001)(82740400003)(40460700003)(36900700001)(2101003)(309714004); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2022 16:47:16.7304 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ea909c96-7ed9-4180-043d-08da9282f44a X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT091.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6291 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Add EPP driver support for those AMD CPUs which has full MSR feature enabled, The EPP is used in the DPM controller to drive the frequency that a core is going to operate during short periods of activity. EPP values will be utilized for different OS profiles (balanced, performance, power savings). cppc performance can be controlled by the user space interface sys attributes for min and max frequency limits, when pstate driver is working under power save policy. EPP scale is 0 - 255, 0 is the max performance and 255 is min level. balance_performance (0x80) can provide best balance performance and watt for most of system, meanwhile user can choose performance policy on needs. $ cat /sys/devices/system/cpu/cpufreq/policy0/energy_performance_available_preferences default performance balance_performance balance_power power $ cat /sys/devices/system/cpu/cpufreq/policy0/energy_performance_preference balance_performance Signed-off-by: Perry Yuan --- arch/x86/include/asm/msr-index.h | 4 + drivers/cpufreq/amd-pstate.c | 818 ++++++++++++++++++++++++++++++- 2 files changed, 804 insertions(+), 18 deletions(-) diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h index 43a3d8e4eb9a..4c540badab4e 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -577,6 +577,10 @@ #define MSR_AMD64_PERF_CNTR_GLOBAL_CTL 0xc0000301 #define MSR_AMD64_PERF_CNTR_GLOBAL_STATUS_CLR 0xc0000302 +#define AMD_CPPC_EPP_PERFORMANCE 0x00 +#define AMD_CPPC_EPP_BALANCE_PERFORMANCE 0x80 +#define AMD_CPPC_EPP_BALANCE_POWERSAVE 0xBF +#define AMD_CPPC_EPP_POWERSAVE 0xFF /* Fam 17h MSRs */ #define MSR_F17H_IRPERF 0xc00000e9 diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index fff298744a8e..e71b06e20050 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -63,8 +63,8 @@ module_param(epp_enabled, bool, 0444); MODULE_PARM_DESC(epp_enabled, "load amd_pstate or amd_pstate_epp (true = amd_pstate_epp driver instance (default), false = amd_pstate driver instance)"); - -static struct cpufreq_driver amd_pstate_driver; +static struct cpufreq_driver *default_pstate_driver; +static struct amd_cpudata **all_cpu_data; /** * struct amd_aperf_mperf @@ -76,6 +76,7 @@ struct amd_aperf_mperf { u64 aperf; u64 mperf; u64 tsc; + u64 time; }; /** @@ -98,7 +99,19 @@ struct amd_aperf_mperf { * @prev: Last Aperf/Mperf/tsc count value read from register * @freq: current cpu frequency value * @boost_supported: check whether the Processor or SBIOS supports boost mode - * + * @epp_powersave: Last saved CPPC energy performance preference + when policy switched to performance + * @epp_policy: Last saved policy used to set energy-performance preference + * @epp_cached: Cached CPPC energy-performance preference value + * @policy: Cpufreq policy value + * @sched_flags: Store scheduler flags for possible cross CPU update + * @update_util_set: CPUFreq utility callback is set + * @last_update: Time stamp of the last performance state update + * @cppc_boost_min: Last CPPC boosted min performance state + * @cppc_cap1_cached: Cached value of the last CPPC Capabilities MSR + * @update_util: Cpufreq utility callback information + * @sample: the stored performance sample + * The amd_cpudata is key private data for each CPU thread in AMD P-State, and * represents all the attributes and goals that AMD P-State requests at runtime. */ @@ -124,8 +137,195 @@ struct amd_cpudata { u64 freq; bool boost_supported; u64 cppc_hw_conf_cached; + + /* EPP feature related attributes*/ + s16 epp_powersave; + s16 epp_policy; + s16 epp_cached; + u32 policy; + u32 sched_flags; + bool update_util_set; + u64 last_update; + u64 last_io_update; + u32 cppc_boost_min; + u64 cppc_cap1_cached; + struct update_util_data update_util; + struct amd_aperf_mperf sample; +}; + +/** + * struct amd_pstate_params - global parameters for the performance control + * @ cppc_boost_disabled Wheter or not the core performance boost disabled + */ +struct amd_pstate_params { + bool cppc_boost_disabled; +}; + +/* + * AMD Energy Preference Performance (EPP) + * The EPP is used in the CCLK DPM controller to drive + * the frequency that a core is going to operate during + * short periods of activity. EPP values will be utilized for + * different OS profiles (balanced, performance, power savings) + * display strings corresponding to EPP index in the + * energy_perf_strings[] + * index String + *------------------------------------- + * 0 default + * 1 performance + * 2 balance_performance + * 3 balance_power + * 4 power + */ + enum energy_perf_value_index { + EPP_INDEX_DEFAULT = 0, + EPP_INDEX_PERFORMANCE, + EPP_INDEX_BALANCE_PERFORMANCE, + EPP_INDEX_BALANCE_POWERSAVE, + EPP_INDEX_POWERSAVE, +}; + +static const char * const energy_perf_strings[] = { + [EPP_INDEX_DEFAULT] = "default", + [EPP_INDEX_PERFORMANCE] = "performance", + [EPP_INDEX_BALANCE_PERFORMANCE] = "balance_performance", + [EPP_INDEX_BALANCE_POWERSAVE] = "balance_power", + [EPP_INDEX_POWERSAVE] = "power", + NULL }; +static unsigned int epp_values[] = { + [EPP_INDEX_DEFAULT] = 0, + [EPP_INDEX_PERFORMANCE] = AMD_CPPC_EPP_PERFORMANCE, + [EPP_INDEX_BALANCE_PERFORMANCE] = AMD_CPPC_EPP_BALANCE_PERFORMANCE, + [EPP_INDEX_BALANCE_POWERSAVE] = AMD_CPPC_EPP_BALANCE_POWERSAVE, + [EPP_INDEX_POWERSAVE] = AMD_CPPC_EPP_POWERSAVE, +}; + +static struct amd_pstate_params global; + +static DEFINE_MUTEX(amd_pstate_limits_lock); +static DEFINE_MUTEX(amd_pstate_driver_lock); +static DEFINE_SPINLOCK(amd_pstate_cpu_lock); + +static bool cppc_boost __read_mostly; +struct kobject *amd_pstate_kobj; + +#ifdef CONFIG_ACPI_CPPC_LIB +static s16 amd_pstate_get_epp(struct amd_cpudata *cpudata, u64 cppc_req_cached) +{ + s16 epp; + struct cppc_perf_caps perf_caps; + int ret; + + if (boot_cpu_has(X86_FEATURE_CPPC)) { + if (!cppc_req_cached) { + epp = rdmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, + &cppc_req_cached); + if (epp) + return epp; + } + epp = (cppc_req_cached >> 24) & 0xFF; + } else { + ret = cppc_get_epp_caps(cpudata->cpu, &perf_caps); + if (ret < 0) { + pr_debug("Could not retrieve energy perf value (%d)\n", ret); + return -EIO; + } + epp = (s16) perf_caps.energy_perf; + } + + return epp; +} +#endif + +static int amd_pstate_get_energy_pref_index(struct amd_cpudata *cpudata, int *raw_epp) +{ + s16 epp; + int index = -EINVAL; + + *raw_epp = 0; + epp = amd_pstate_get_epp(cpudata, 0); + if (epp < 0) + return epp; + + switch (epp) { + case AMD_CPPC_EPP_PERFORMANCE: + index = EPP_INDEX_PERFORMANCE; + break; + case AMD_CPPC_EPP_BALANCE_PERFORMANCE: + index = EPP_INDEX_BALANCE_PERFORMANCE; + break; + case AMD_CPPC_EPP_BALANCE_POWERSAVE: + index = EPP_INDEX_BALANCE_POWERSAVE; + break; + case AMD_CPPC_EPP_POWERSAVE: + index = EPP_INDEX_POWERSAVE; + break; + default: + *raw_epp = epp; + index = 0; + } + + return index; +} + +#ifdef CONFIG_ACPI_CPPC_LIB +static int amd_pstate_set_epp(struct amd_cpudata *cpudata, u32 epp) +{ + int ret; + struct cppc_perf_ctrls perf_ctrls; + + if (boot_cpu_has(X86_FEATURE_CPPC)) { + u64 value = READ_ONCE(cpudata->cppc_req_cached); + + value &= ~GENMASK_ULL(31, 24); + value |= (u64)epp << 24; + WRITE_ONCE(cpudata->cppc_req_cached, value); + ret = wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, value); + if (!ret) { + cpudata->epp_cached = epp; + } + } else { + perf_ctrls.energy_perf = epp; + ret = cppc_set_epp_perf(cpudata->cpu, &perf_ctrls); + if (ret){ + pr_debug("failed to set energy perf value (%d)\n", ret); + return ret; + } + cpudata->epp_cached = epp; + } + return ret; +} + +static int amd_pstate_set_energy_pref_index(struct amd_cpudata *cpudata, + int pref_index, bool use_raw, + u32 raw_epp) +{ + int epp = -EINVAL; + int ret; + + if (!pref_index) { + pr_debug("EPP pref_index is invaid\n"); + return -EINVAL; + } + + if (use_raw) + epp = raw_epp; + else if (epp == -EINVAL) + epp = epp_values[pref_index]; + + if (epp > 0 && cpudata->policy == CPUFREQ_POLICY_PERFORMANCE) { + pr_debug("EPP cannot be set under performance policy\n"); + return -EBUSY; + } + + ret = amd_pstate_set_epp(cpudata, epp); + + return ret; +} +#endif + static inline int pstate_enable(bool enable) { return wrmsrl_safe(MSR_AMD_CPPC_ENABLE, enable); @@ -141,16 +341,18 @@ static int cppc_enable(bool enable) if (ret) return ret; - /* Enable active mode for EPP */ - ret = cppc_set_auto_epp(cpu, enable); - if (ret) - return ret; - - /* Set zero to desired perf to enable EPP control*/ - perf_ctrls.desired_perf = 0; - ret = cppc_set_perf(cpu, &perf_ctrls); - if (ret) - return ret; + if (epp_enabled) { + /* Enable autonomous mode for EPP */ + ret = cppc_set_auto_epp(cpu, enable); + if (ret) + return ret; + + /* Set zero to desired perf to allow EPP firmware control*/ + perf_ctrls.desired_perf = 0; + ret = cppc_set_perf(cpu, &perf_ctrls); + if (ret) + return ret; + } } return ret; @@ -496,7 +698,7 @@ static void amd_pstate_boost_init(struct amd_cpudata *cpudata) return; cpudata->boost_supported = true; - amd_pstate_driver.boost_enabled = true; + default_pstate_driver->boost_enabled = true; } static int amd_pstate_cpu_init(struct cpufreq_policy *policy) @@ -671,10 +873,108 @@ static ssize_t show_amd_pstate_highest_perf(struct cpufreq_policy *policy, return sprintf(&buf[0], "%u\n", perf); } +static ssize_t show_energy_performance_available_preferences( + struct cpufreq_policy *policy, char *buf) +{ + int i = 0; + int ret = 0; + + while (energy_perf_strings[i] != NULL) + ret += sprintf(&buf[ret], "%s ", energy_perf_strings[i++]); + + ret += sprintf(&buf[ret], "\n"); + + return ret; +} + +static ssize_t store_energy_performance_preference( + struct cpufreq_policy *policy, const char *buf, size_t count) +{ + struct amd_cpudata *cpudata = policy->driver_data; + char str_preference[21]; + bool raw = false; + ssize_t ret; + u32 epp = 0; + + ret = sscanf(buf, "%20s", str_preference); + if (ret != 1) + return -EINVAL; + + ret = match_string(energy_perf_strings, -1, str_preference); + if (ret < 0) { + ret = kstrtouint(buf, 10, &epp); + if (ret) + return ret; + + if ((epp > 255) || (epp < 0)) + return -EINVAL; + + raw = true; + } + + mutex_lock(&amd_pstate_limits_lock); + ret = amd_pstate_set_energy_pref_index(cpudata, ret, raw, epp); + mutex_unlock(&amd_pstate_limits_lock); + + return ret ?: count; +} + +static ssize_t show_energy_performance_preference( + struct cpufreq_policy *policy, char *buf) +{ + struct amd_cpudata *cpudata = policy->driver_data; + int preference, raw_epp; + + preference = amd_pstate_get_energy_pref_index(cpudata, &raw_epp); + if (preference < 0) + return preference; + + if (raw_epp) + return sprintf(buf, "%d\n", raw_epp); + else + return sprintf(buf, "%s\n", energy_perf_strings[preference]); +} + +static void amd_pstate_update_policies(void) +{ + int cpu; + + for_each_possible_cpu(cpu) + cpufreq_update_policy(cpu); +} + +static ssize_t show_pstate_dynamic_boost(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return sprintf(buf, "%u\n", cppc_boost); +} + +static ssize_t store_pstate_dynamic_boost(struct kobject *a, + struct kobj_attribute *b, + const char *buf, size_t count) +{ + unsigned int input; + int ret; + + ret = kstrtouint(buf, 10, &input); + if (ret) + return ret; + + mutex_lock(&amd_pstate_driver_lock); + cppc_boost = !!input; + amd_pstate_update_policies(); + mutex_unlock(&amd_pstate_driver_lock); + + return count; +} + cpufreq_freq_attr_ro(amd_pstate_max_freq); cpufreq_freq_attr_ro(amd_pstate_lowest_nonlinear_freq); cpufreq_freq_attr_ro(amd_pstate_highest_perf); +cpufreq_freq_attr_rw(energy_performance_preference); +cpufreq_freq_attr_ro(energy_performance_available_preferences); +define_one_global_rw(pstate_dynamic_boost); static struct freq_attr *amd_pstate_attr[] = { &amd_pstate_max_freq, @@ -683,6 +983,424 @@ static struct freq_attr *amd_pstate_attr[] = { NULL, }; +static struct freq_attr *amd_pstate_epp_attr[] = { + &amd_pstate_max_freq, + &amd_pstate_lowest_nonlinear_freq, + &amd_pstate_highest_perf, + &energy_performance_preference, + &energy_performance_available_preferences, + NULL, +}; + +static struct attribute *pstate_global_attributes[] = { + &pstate_dynamic_boost.attr, + NULL +}; + +static const struct attribute_group amd_pstate_global_attr_group = { + .attrs = pstate_global_attributes, +}; + +static inline void update_boost_state(void) +{ + u64 misc_en; + struct amd_cpudata *cpudata; + + cpudata = all_cpu_data[0]; + rdmsrl(MSR_AMD_CPPC_HW_CTL, misc_en); + global.cppc_boost_disabled = misc_en & AMD_CPPC_PRECISION_BOOST_ENABLED; +} + +static int amd_pstate_init_cpu(unsigned int cpunum) +{ + struct amd_cpudata *cpudata; + + cpudata = all_cpu_data[cpunum]; + if (!cpudata) { + cpudata = kzalloc(sizeof(*cpudata), GFP_KERNEL); + if (!cpudata) + return -ENOMEM; + WRITE_ONCE(all_cpu_data[cpunum], cpudata); + + cpudata->cpu = cpunum; + } + cpudata->epp_powersave = -EINVAL; + cpudata->epp_policy = 0; + pr_debug("controlling: cpu %d\n", cpunum); + return 0; +} + +static int __amd_pstate_cpu_init(struct cpufreq_policy *policy) +{ + int min_freq, max_freq, nominal_freq, lowest_nonlinear_freq, ret; + struct amd_cpudata *cpudata; + struct device *dev; + int rc; + u64 value; + + rc = amd_pstate_init_cpu(policy->cpu); + if (rc) + return rc; + + cpudata = all_cpu_data[policy->cpu]; + + dev = get_cpu_device(policy->cpu); + if (!dev) + goto free_cpudata1; + + rc = amd_pstate_init_perf(cpudata); + if (rc) + goto free_cpudata1; + + min_freq = amd_get_min_freq(cpudata); + max_freq = amd_get_max_freq(cpudata); + nominal_freq = amd_get_nominal_freq(cpudata); + lowest_nonlinear_freq = amd_get_lowest_nonlinear_freq(cpudata); + if (min_freq < 0 || max_freq < 0 || min_freq > max_freq) { + dev_err(dev, "min_freq(%d) or max_freq(%d) value is incorrect\n", + min_freq, max_freq); + ret = -EINVAL; + goto free_cpudata1; + } + + policy->min = min_freq; + policy->max = max_freq; + + policy->cpuinfo.min_freq = min_freq; + policy->cpuinfo.max_freq = max_freq; + /* It will be updated by governor */ + policy->cur = policy->cpuinfo.min_freq; + + /* Initial processor data capability frequencies */ + cpudata->max_freq = max_freq; + cpudata->min_freq = min_freq; + cpudata->nominal_freq = nominal_freq; + cpudata->lowest_nonlinear_freq = lowest_nonlinear_freq; + + policy->driver_data = cpudata; + + update_boost_state(); + cpudata->epp_cached = amd_pstate_get_epp(cpudata, value); + + policy->min = policy->cpuinfo.min_freq; + policy->max = policy->cpuinfo.max_freq; + + if (boot_cpu_has(X86_FEATURE_CPPC)) + policy->fast_switch_possible = true; + + if (!shared_mem && boot_cpu_has(X86_FEATURE_CPPC)) { + ret = rdmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, &value); + if (ret) + return ret; + WRITE_ONCE(cpudata->cppc_req_cached, value); + + ret = rdmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_CAP1, &value); + if (ret) + return ret; + WRITE_ONCE(cpudata->cppc_cap1_cached, value); + } + amd_pstate_boost_init(cpudata); + + return 0; + +free_cpudata1: + kfree(cpudata); + return ret; +} + +static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy) +{ + int ret; + + ret = __amd_pstate_cpu_init(policy); + if (ret) + return ret; + /* + * Set the policy to powersave to provide a valid fallback value in case + * the default cpufreq governor is neither powersave nor performance. + */ + policy->policy = CPUFREQ_POLICY_POWERSAVE; + + return 0; +} + +static int amd_pstate_epp_cpu_exit(struct cpufreq_policy *policy) +{ + pr_debug("amd-pstate: CPU %d exiting\n", policy->cpu); + policy->fast_switch_possible = false; + return 0; +} + +static void amd_pstate_update_max_freq(unsigned int cpu) +{ + struct cpufreq_policy *policy = cpufreq_cpu_acquire(cpu); + + if (!policy) + return; + + refresh_frequency_limits(policy); + cpufreq_cpu_release(policy); +} + +static void amd_pstate_epp_update_limits(unsigned int cpu) +{ + mutex_lock(&amd_pstate_driver_lock); + update_boost_state(); + if (global.cppc_boost_disabled) { + for_each_possible_cpu(cpu) + amd_pstate_update_max_freq(cpu); + } else { + cpufreq_update_policy(cpu); + } + mutex_unlock(&amd_pstate_driver_lock); +} + +static int cppc_boost_hold_time_ns = 3 * NSEC_PER_MSEC; + +static inline void amd_pstate_boost_up(struct amd_cpudata *cpudata) +{ + u64 hwp_req = READ_ONCE(cpudata->cppc_req_cached); + u64 hwp_cap = READ_ONCE(cpudata->cppc_cap1_cached); + u32 max_limit = (hwp_req & 0xff); + u32 min_limit = (hwp_req & 0xff00) >> 8; + u32 boost_level1; + + /* If max and min are equal or already at max, nothing to boost */ + if (max_limit == min_limit) + return; + + /* Set boost max and min to initial value */ + if (!cpudata->cppc_boost_min) + cpudata->cppc_boost_min = min_limit; + + boost_level1 = ((AMD_CPPC_NOMINAL_PERF(hwp_cap) + min_limit) >> 1); + + if (cpudata->cppc_boost_min < boost_level1) + cpudata->cppc_boost_min = boost_level1; + else if (cpudata->cppc_boost_min < AMD_CPPC_NOMINAL_PERF(hwp_cap)) + cpudata->cppc_boost_min = AMD_CPPC_NOMINAL_PERF(hwp_cap); + else if (cpudata->cppc_boost_min == AMD_CPPC_NOMINAL_PERF(hwp_cap)) + cpudata->cppc_boost_min = max_limit; + else + return; + + hwp_req &= ~AMD_CPPC_MIN_PERF(~0L); + hwp_req |= AMD_CPPC_MIN_PERF(cpudata->cppc_boost_min); + wrmsrl_safe_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, hwp_req); + cpudata->last_update = cpudata->sample.time; +} + +static inline void amd_pstate_boost_down(struct amd_cpudata *cpudata) +{ + bool expired; + + if (cpudata->cppc_boost_min) { + expired = time_after64(cpudata->sample.time, cpudata->last_update + + cppc_boost_hold_time_ns); + + if (expired) { + wrmsrl_safe_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, cpudata->cppc_req_cached); + cpudata->cppc_boost_min = 0; + } + } + + cpudata->last_update = cpudata->sample.time; +} + +static inline void amd_pstate_boost_update_util(struct amd_cpudata *cpudata, + u64 time) +{ + cpudata->sample.time = time; + if (smp_processor_id() != cpudata->cpu) + return; + + if (cpudata->sched_flags & SCHED_CPUFREQ_IOWAIT) { + bool do_io = false; + + cpudata->sched_flags = 0; + /* + * Set iowait_boost flag and update time. Since IO WAIT flag + * is set all the time, we can't just conclude that there is + * some IO bound activity is scheduled on this CPU with just + * one occurrence. If we receive at least two in two + * consecutive ticks, then we treat as boost candidate. + * This is leveraged from Intel Pstate driver. + */ + if (time_before64(time, cpudata->last_io_update + 2 * TICK_NSEC)) + do_io = true; + + cpudata->last_io_update = time; + + if (do_io) + amd_pstate_boost_up(cpudata); + + } else { + amd_pstate_boost_down(cpudata); + } +} + +static inline void amd_pstate_cppc_update_hook(struct update_util_data *data, + u64 time, unsigned int flags) +{ + struct amd_cpudata *cpudata = container_of(data, + struct amd_cpudata, update_util); + + cpudata->sched_flags |= flags; + + if (smp_processor_id() == cpudata->cpu) + amd_pstate_boost_update_util(cpudata, time); +} + +static void amd_pstate_clear_update_util_hook(unsigned int cpu) +{ + struct amd_cpudata *cpudata = all_cpu_data[cpu]; + + if (!cpudata->update_util_set) + return; + + cpufreq_remove_update_util_hook(cpu); + cpudata->update_util_set = false; + synchronize_rcu(); +} + +static void amd_pstate_set_update_util_hook(unsigned int cpu_num) +{ + struct amd_cpudata *cpudata = all_cpu_data[cpu_num]; + + if (!cppc_boost) { + if (cpudata->update_util_set) + amd_pstate_clear_update_util_hook(cpudata->cpu); + return; + } + + if (cpudata->update_util_set) + return; + + cpudata->sample.time = 0; + cpufreq_add_update_util_hook(cpu_num, &cpudata->update_util, + amd_pstate_cppc_update_hook); + cpudata->update_util_set = true; +} + +static void amd_pstate_epp_init(unsigned int cpu) +{ + struct amd_cpudata *cpudata = all_cpu_data[cpu]; + u32 max_perf, min_perf; + u64 value; + s16 epp; + int ret; + + max_perf = READ_ONCE(cpudata->highest_perf); + min_perf = READ_ONCE(cpudata->lowest_perf); + + value = READ_ONCE(cpudata->cppc_req_cached); + + if (cpudata->policy == CPUFREQ_POLICY_PERFORMANCE) + min_perf = max_perf; + + /* Initial min/max values for CPPC Performance Controls Register */ + value &= ~AMD_CPPC_MIN_PERF(~0L); + value |= AMD_CPPC_MIN_PERF(min_perf); + + value &= ~AMD_CPPC_MAX_PERF(~0L); + value |= AMD_CPPC_MAX_PERF(max_perf); + + /* CPPC EPP feature require to set zero to the desire perf bit */ + value &= ~AMD_CPPC_DES_PERF(~0L); + value |= AMD_CPPC_DES_PERF(0); + + if (cpudata->epp_policy == cpudata->policy) + goto skip_epp; + + cpudata->epp_policy = cpudata->policy; + + if (cpudata->policy == CPUFREQ_POLICY_PERFORMANCE) { + epp = amd_pstate_get_epp(cpudata, value); + cpudata->epp_powersave = epp; + if (epp < 0) + goto skip_epp; + + epp = 0; + } else { + if (cpudata->epp_powersave < 0) + goto skip_epp; + /* Get BIOS pre-defined epp value */ + epp = amd_pstate_get_epp(cpudata, value); + if (epp) + goto skip_epp; + epp = cpudata->epp_powersave; + } + /* Set initial EPP value */ + if (boot_cpu_has(X86_FEATURE_CPPC)) { + value &= ~GENMASK_ULL(31, 24); + value |= (u64)epp << 24; + } + +skip_epp: + WRITE_ONCE(cpudata->cppc_req_cached, value); + ret = wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, value); + if (!ret) { + cpudata->epp_cached = epp; + } +} + +static void amd_pstate_set_max_limits(struct amd_cpudata *cpudata) +{ + u64 hwp_cap = READ_ONCE(cpudata->cppc_cap1_cached); + u64 hwp_req = READ_ONCE(cpudata->cppc_req_cached); + u32 max_limit = (hwp_cap >> 24) & 0xff; + + hwp_req &= ~AMD_CPPC_MIN_PERF(~0L); + hwp_req |= AMD_CPPC_MIN_PERF(max_limit); + wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, hwp_req); +} + +static int amd_pstate_epp_set_policy(struct cpufreq_policy *policy) +{ + struct amd_cpudata *cpudata; + + if (!policy->cpuinfo.max_freq) + return -ENODEV; + + pr_debug("set_policy: cpuinfo.max %u policy->max %u\n", + policy->cpuinfo.max_freq, policy->max); + + cpudata = all_cpu_data[policy->cpu]; + cpudata->policy = policy->policy; + + if (boot_cpu_has(X86_FEATURE_CPPC)) { + mutex_lock(&amd_pstate_limits_lock); + + if (cpudata->policy == CPUFREQ_POLICY_PERFORMANCE) { + amd_pstate_clear_update_util_hook(policy->cpu); + amd_pstate_set_max_limits(cpudata); + } else { + amd_pstate_set_update_util_hook(policy->cpu); + } + + if (boot_cpu_has(X86_FEATURE_CPPC)) + amd_pstate_epp_init(policy->cpu); + + mutex_unlock(&amd_pstate_limits_lock); + } + + return 0; +} + +static void amd_pstate_verify_cpu_policy(struct amd_cpudata *cpudata, + struct cpufreq_policy_data *policy) +{ + update_boost_state(); + cpufreq_verify_within_cpu_limits(policy); +} + +static int amd_pstate_epp_verify_policy(struct cpufreq_policy_data *policy) +{ + amd_pstate_verify_cpu_policy(all_cpu_data[policy->cpu], policy); + pr_debug("policy_max =%d, policy_min=%d\n", policy->max, policy->min ); + return 0; +} + static struct cpufreq_driver amd_pstate_driver = { .flags = CPUFREQ_CONST_LOOPS | CPUFREQ_NEED_UPDATE_LIMITS, .verify = amd_pstate_verify, @@ -696,8 +1414,20 @@ static struct cpufreq_driver amd_pstate_driver = { .attr = amd_pstate_attr, }; +static struct cpufreq_driver amd_pstate_epp_driver = { + .flags = CPUFREQ_CONST_LOOPS, + .verify = amd_pstate_epp_verify_policy, + .setpolicy = amd_pstate_epp_set_policy, + .init = amd_pstate_epp_cpu_init, + .exit = amd_pstate_epp_cpu_exit, + .update_limits = amd_pstate_epp_update_limits, + .name = "amd_pstate_epp", + .attr = amd_pstate_epp_attr, +}; + static int __init amd_pstate_init(void) { + static struct amd_cpudata **cpudata; int ret; if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD) @@ -712,10 +1442,25 @@ static int __init amd_pstate_init(void) if (cpufreq_get_current_driver()) return -EEXIST; + cpudata = vzalloc(array_size(sizeof(void *), num_possible_cpus())); + if (!cpudata) + return -ENOMEM; + WRITE_ONCE(all_cpu_data, cpudata); + + if (epp_enabled) { + pr_info("AMD CPPC loading with amd_pstate_epp driver instance.\n"); + default_pstate_driver = &amd_pstate_epp_driver; + } else { + pr_info("AMD CPPC loading with amd_pstate driver instance.\n"); + default_pstate_driver = &amd_pstate_driver; + } + /* capability check */ if (boot_cpu_has(X86_FEATURE_CPPC)) { + if (!epp_enabled) { + default_pstate_driver->adjust_perf = amd_pstate_adjust_perf; + } pr_debug("AMD CPPC MSR based functionality is supported\n"); - amd_pstate_driver.adjust_perf = amd_pstate_adjust_perf; } else if (shared_mem) { static_call_update(amd_pstate_enable, cppc_enable); static_call_update(amd_pstate_init_perf, cppc_init_perf); @@ -732,19 +1477,56 @@ static int __init amd_pstate_init(void) return ret; } - ret = cpufreq_register_driver(&amd_pstate_driver); + ret = cpufreq_register_driver(default_pstate_driver); if (ret) - pr_err("failed to register amd_pstate_driver with return %d\n", + pr_err("failed to register amd pstate driver with return %d\n", ret); + amd_pstate_kobj = kobject_create_and_add("amd-pstate", &cpu_subsys.dev_root->kobj); + if (!amd_pstate_kobj) { + pr_err("amd-pstate: Global sysfs registration failed.\n"); + } + + ret = sysfs_create_group(amd_pstate_kobj, &amd_pstate_global_attr_group); + if (ret) { + pr_err("amd-pstate: Sysfs attribute export failed with error %d.\n", + ret); + } + return ret; } +static inline void amd_pstate_kobj_cleanup(struct kobject *kobj) +{ + kobject_del(kobj); + kobject_put(kobj); +} + static void __exit amd_pstate_exit(void) { - cpufreq_unregister_driver(&amd_pstate_driver); + unsigned int cpu; + + cpufreq_unregister_driver(default_pstate_driver); amd_pstate_enable(false); + + sysfs_remove_group(amd_pstate_kobj, &amd_pstate_global_attr_group); + amd_pstate_kobj_cleanup(amd_pstate_kobj); + + cpus_read_lock(); + for_each_online_cpu(cpu) { + if (all_cpu_data[cpu]) { + if (default_pstate_driver == &amd_pstate_epp_driver) + amd_pstate_clear_update_util_hook(cpu); + + spin_lock(&amd_pstate_cpu_lock); + kfree(all_cpu_data[cpu]); + WRITE_ONCE(all_cpu_data[cpu], NULL); + spin_unlock(&amd_pstate_cpu_lock); + } + } + cpus_read_unlock(); + } module_init(amd_pstate_init);