From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 387FB42967; Mon, 17 Apr 2023 06:34:39 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1F7EC40DFB; Mon, 17 Apr 2023 06:34:39 +0200 (CEST) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2073.outbound.protection.outlook.com [40.107.237.73]) by mails.dpdk.org (Postfix) with ESMTP id EA99E40698 for ; Mon, 17 Apr 2023 06:34:37 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Enf6MgXbSDoHg2p94SEv5nzuggrNY1FyNuAKfSltjsYoYiMYaWjafozX4BKuSb6800MuMiZWwOgk4TB7Bs+MKrPSpzQOaoWH2Www7elUV3FmEXrg5bi3hoj0ITurHpZM2xRyFj6tWl82/51Qh/AnvmxRQ0Rbi6YzidsdmLj6fg1ctYE3tDQQlKw34S2Yc8InmB7m/5HCLQgYbf4n/q/v/OqqNieOlay6OEyhAFUaZcR3OeravtX2WBlgZhzOEqSiSMkTAebIyJl4ss0zph9PhJDEXMFnXHlU/KZ1Mo39XZBiimkOXE+9Jk5gpS9QV0qCVjsF1SJ7khrgGw7+W2fOdg== 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=kDmlMEPAOfSVV+j5JFKTzeZYLPqp+u/Cq9uu0cThPGo=; b=jsQ26u7ETHxj52YARzCVedtMZz7fF5ng4GYPvpIA2V7LhGuCsbaJwgR30uGD3RFCOUY7o4HhRHG3wnM6fVztYqTIuOVkxdztP/aGyUVlRkhjps70IYRIdiDsQdkuLCPvfcR4r/JdJm8BA224iqteoLzB8kpPM+RUCx8bYlBWnkTzoEyLHaHA5O5LI/Tv+zPFKA8N9AFSgAg3gyvfq6jdSZ41Bxth4YrkSAZYOjuzrcVu3ppyC5joI58ttnWgT9jdr0mv5yPJIqnZd3NRfeq/ws+I6c4E0HGI3Bmh69FlQgub6JQK7iYrlY40bXhMOUKU8UA5jiYvb/o/+E73Gg9ttg== 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=kDmlMEPAOfSVV+j5JFKTzeZYLPqp+u/Cq9uu0cThPGo=; b=trlfjvCqfFVEON65cMUOsY/W1gOW9a0rlFT2xq5AfbJ0Xn3WM//nBlBnBpV+q++fRCTRxGzNM1DEb72haD+C+/VJBvRtcnPmoVuBUiV7JOm6OGhvM8rBnMdOIqTNKMHWtbHl2KIHK1h6NtWKJvyNZPnD95x6eic922+JXN8sHXE= Received: from DM6PR03CA0033.namprd03.prod.outlook.com (2603:10b6:5:40::46) by CH0PR12MB5235.namprd12.prod.outlook.com (2603:10b6:610:d2::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.45; Mon, 17 Apr 2023 04:34:36 +0000 Received: from DM6NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:5:40:cafe::24) by DM6PR03CA0033.outlook.office365.com (2603:10b6:5:40::46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.46 via Frontend Transport; Mon, 17 Apr 2023 04:34:36 +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 DM6NAM11FT066.mail.protection.outlook.com (10.13.173.179) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6319.19 via Frontend Transport; Mon, 17 Apr 2023 04:34:36 +0000 Received: from telco-siena.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.34; Sun, 16 Apr 2023 23:34:32 -0500 From: Sivaprasad Tummala To: CC: Subject: [PATCH v3 4/4] power: amd power monitor support Date: Sun, 16 Apr 2023 21:34:14 -0700 Message-ID: <20230417043414.470173-1-sivaprasad.tummala@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230413115334.43172-3-sivaprasad.tummala@amd.com> References: <20230413115334.43172-3-sivaprasad.tummala@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT066:EE_|CH0PR12MB5235:EE_ X-MS-Office365-Filtering-Correlation-Id: b1aa27c3-37ae-4a7f-1b85-08db3efd0c87 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EFHBA1MVl3XCUbwcrbFhzdzvXuO49MWVuH2sZ6sIzt1TFcOGRKHBsluLo01eb6AQV9X+wHQ6y1RTqGA3kJYcrI18EEETwAWlNy5HYfqfQWHrFJGe6ZKzzq4BnTxVQAeQG3IbUaMjliCAfvCMjGM67f20LxBC54UQs43qr2zJwiW92hxZUHELDNIlKgNgZyEaEUM1kYlBUzbE5mInSNb3CbeV9OELZDWGFoqU9EFL9B234dg6Pyyj87tevNekSQswtNaRQKGFnt8QI04sYCcQvxJnOT3n9WKRbNoJ4lbUXqDdV+ASRyjS2AQbikgwtoxXvtctOwL1acFetnZINVa2xrji3T1Ov4TuwRFqnizNkzXSqgASyCzXgR+U6LxD3oxVhxGbfEhrBR6Wx7w1jkZPaFnBs7XgZ6ba+PhJIUqZQkiM7TztUUxjmYpcvf/VmmHqx9MauTJNIQGkX2WMgNT7kUyt9DhreerEwgR8+6AbjtcbYhDdRqmnFoFUBItndayjqcFEwn2fTPfk1O3aD9VKrNBhEBLa7Qd6TayEAN1NdHLP0o8h5wlvT+ywDMvsgyn1g0XjyiEZUgY1rbEGCuoJH8BX2FOVLUwA0V9bG6TQO9GtSg4kGY/MhFsl5zjoBPXJavQq/uTXOGVfwynlSImXxqKJz8tVQW+ZC4hh4+7vkrWAFY7eP1X4t7JWQURkqAbEjlUrYNSiB1kqxhGBabu6J2C84bHgQgfT0Ks0oi1YD1s= 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:(13230028)(4636009)(396003)(376002)(136003)(39860400002)(346002)(451199021)(46966006)(40470700004)(36840700001)(36860700001)(2616005)(26005)(1076003)(478600001)(82740400003)(70206006)(70586007)(47076005)(83380400001)(316002)(7696005)(6666004)(186003)(16526019)(336012)(426003)(6916009)(4326008)(8676002)(356005)(41300700001)(8936002)(5660300002)(2906002)(81166007)(44832011)(36756003)(82310400005)(40460700003)(40480700001)(86362001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2023 04:34:36.0104 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b1aa27c3-37ae-4a7f-1b85-08db3efd0c87 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: DM6NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5235 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org mwaitx allows EPYC processors to enter a implementation dependent power/performance optimized state (C1 state) for a specific period or until a store to the monitored address range. Signed-off-by: Sivaprasad Tummala --- lib/eal/x86/rte_power_intrinsics.c | 77 +++++++++++++++++++++++++----- 1 file changed, 66 insertions(+), 11 deletions(-) diff --git a/lib/eal/x86/rte_power_intrinsics.c b/lib/eal/x86/rte_power_intrinsics.c index 6eb9e50807..27055bab52 100644 --- a/lib/eal/x86/rte_power_intrinsics.c +++ b/lib/eal/x86/rte_power_intrinsics.c @@ -17,6 +17,60 @@ static struct power_wait_status { volatile void *monitor_addr; /**< NULL if not currently sleeping */ } __rte_cache_aligned wait_status[RTE_MAX_LCORE]; +/** + * These functions uses UMONITOR/UMWAIT instructions and will enter C0.2 state. + * For more information about usage of these instructions, please refer to + * Intel(R) 64 and IA-32 Architectures Software Developer's Manual. + */ +static void intel_umonitor(volatile void *addr) +{ + /* UMONITOR */ + asm volatile(".byte 0xf3, 0x0f, 0xae, 0xf7;" + : + : "D"(addr)); +} + +static void intel_umwait(const uint64_t timeout) +{ + const uint32_t tsc_l = (uint32_t)timeout; + const uint32_t tsc_h = (uint32_t)(timeout >> 32); + /* UMWAIT */ + asm volatile(".byte 0xf2, 0x0f, 0xae, 0xf7;" + : /* ignore rflags */ + : "D"(0), /* enter C0.2 */ + "a"(tsc_l), "d"(tsc_h)); +} + +/** + * These functions uses MONITORX/MWAITX instructions and will enter C1 state. + * For more information about usage of these instructions, please refer to + * AMD64 Architecture Programmer’s Manual. + */ +static void amd_monitorx(volatile void *addr) +{ + /* MONITORX */ + asm volatile(".byte 0x0f, 0x01, 0xfa;" + : + : "a"(addr), + "c"(0), /* no extensions */ + "d"(0)); /* no hints */ +} + +static void amd_mwaitx(const uint64_t timeout) +{ + /* MWAITX */ + asm volatile(".byte 0x0f, 0x01, 0xfb;" + : /* ignore rflags */ + : "a"(0), /* enter C1 */ + "c"(2), /* enable timer */ + "b"(timeout)); +} + +static struct { + void (*mmonitor)(volatile void *addr); + void (*mwait)(const uint64_t timeout); +} __rte_cache_aligned power_monitor_ops; + static inline void __umwait_wakeup(volatile void *addr) { @@ -75,8 +129,6 @@ int rte_power_monitor(const struct rte_power_monitor_cond *pmc, const uint64_t tsc_timestamp) { - const uint32_t tsc_l = (uint32_t)tsc_timestamp; - const uint32_t tsc_h = (uint32_t)(tsc_timestamp >> 32); const unsigned int lcore_id = rte_lcore_id(); struct power_wait_status *s; uint64_t cur_value; @@ -109,10 +161,8 @@ rte_power_monitor(const struct rte_power_monitor_cond *pmc, * versions support this instruction natively. */ - /* set address for UMONITOR */ - asm volatile(".byte 0xf3, 0x0f, 0xae, 0xf7;" - : - : "D"(pmc->addr)); + /* set address for mmonitor */ + power_monitor_ops.mmonitor(pmc->addr); /* now that we've put this address into monitor, we can unlock */ rte_spinlock_unlock(&s->lock); @@ -123,11 +173,8 @@ rte_power_monitor(const struct rte_power_monitor_cond *pmc, if (pmc->fn(cur_value, pmc->opaque) != 0) goto end; - /* execute UMWAIT */ - asm volatile(".byte 0xf2, 0x0f, 0xae, 0xf7;" - : /* ignore rflags */ - : "D"(0), /* enter C0.2 */ - "a"(tsc_l), "d"(tsc_h)); + /* execute mwait */ + power_monitor_ops.mwait(tsc_timestamp); end: /* erase sleep address */ @@ -173,6 +220,14 @@ RTE_INIT(rte_power_intrinsics_init) { wait_multi_supported = 1; if (i.power_monitor) monitor_supported = 1; + + if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_MONITORX)) { /* AMD */ + power_monitor_ops.mmonitor = &amd_monitorx; + power_monitor_ops.mwait = &amd_mwaitx; + } else { /* Intel */ + power_monitor_ops.mmonitor = &intel_umonitor; + power_monitor_ops.mwait = &intel_umwait; + } } int -- 2.34.1