From patchwork Fri Feb 18 08:35:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 12751079 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AF9E7C433EF for ; Fri, 18 Feb 2022 08:35:35 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.275216.470985 (Exim 4.92) (envelope-from ) id 1nKyjZ-0006cE-Sp; Fri, 18 Feb 2022 08:35:21 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 275216.470985; Fri, 18 Feb 2022 08:35:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nKyjZ-0006c7-OF; Fri, 18 Feb 2022 08:35:21 +0000 Received: by outflank-mailman (input) for mailman id 275216; Fri, 18 Feb 2022 08:35:21 +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 1nKyjZ-0006c1-1Q for xen-devel@lists.xenproject.org; Fri, 18 Feb 2022 08:35:21 +0000 Received: from de-smtp-delivery-102.mimecast.com (de-smtp-delivery-102.mimecast.com [194.104.109.102]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b31d1eb3-9095-11ec-8eb8-a37418f5ba1a; Fri, 18 Feb 2022 09:35:17 +0100 (CET) Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04lp2050.outbound.protection.outlook.com [104.47.12.50]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id de-mta-31-htTExiZbPtevkipbiCnJyw-2; Fri, 18 Feb 2022 09:35:16 +0100 Received: from VI1PR04MB5600.eurprd04.prod.outlook.com (2603:10a6:803:e7::16) by AM6PR04MB5813.eurprd04.prod.outlook.com (2603:10a6:20b:ab::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4995.14; Fri, 18 Feb 2022 08:35:12 +0000 Received: from VI1PR04MB5600.eurprd04.prod.outlook.com ([fe80::d479:b728:345c:bd65]) by VI1PR04MB5600.eurprd04.prod.outlook.com ([fe80::d479:b728:345c:bd65%5]) with mapi id 15.20.4995.016; Fri, 18 Feb 2022 08:35:12 +0000 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: b31d1eb3-9095-11ec-8eb8-a37418f5ba1a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1645173076; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RRyQl3XXjMIkv3EC1aE9ooEVH9T0PmKRPMUQxTpYUAA=; b=g8jRxyqEI+Z/65MuUhp1vFtbRykS/0jfcIO2Tbrj6JM+98YYPN3gC45HGiYWZQ/B/sLEPw ApNB4fHXp0xsaYfFc3N79SC+6dUGiEN69tNvRzfVP63cYpAHyqjpUmXhCmJVrU5hMo5xfc yzOXumrF4OuSSvzedHwreAtpCuBraA0= X-MC-Unique: htTExiZbPtevkipbiCnJyw-2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PfYXQ8Be+P4mdNmoFO2gEb6w7qUgIsPWjM3spf/rNqqgl4A2rt792eHxSkuc5Y8gEPwBEUxO9XzbqproJDyi+dUOwoMWqPU55KG7ry2w+e9D6UsBW7cInp/lQq3zt25pdG3e4ahxEtwyr8FhVvjTIa2EMaMVB1T2RWvtT97smhTCbg9yg48wmah5mAX+79GKFITrdAhUBrFqRVgXla5gA3CkVW9ci2Gj7nR9n4PynDGEZF04h/CuWLcSdRQ4sT55fbLAutDQuQFB/1eMlXKHoPd86iUeWDVstweGZ0nod7IzZWXi2L6EtnA6CT3a+jUi7x5i0LBiN4ZnIvIwIpLvLA== 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=RRyQl3XXjMIkv3EC1aE9ooEVH9T0PmKRPMUQxTpYUAA=; b=N8nJxz3IcEAzSafOE3q/41uXsB9mn9fzfBIKKQCQMJMWaR4YG59E/Q6ieKvLbVbvWLHSW3ZwzQTxDP1RRH+pfuMEav6gVRowEGCMXcrBRn2m2UFtA2xOnvn7Mix4DE3BDlBYTZWr//SQDiGk7RogD1lipAL5i0TdCmR6rCDnCKV3a0c90cyqs9TBeLUm298Bub8QYZOi3VInIhQ+burB2ep+LqGgKwyr0Bv+JJ1KgJYE9Lw7WGCaJby76QsoANZjEXcsmzsWIB2I7YJZJ8Wj5NFml7Ls8FltWGYPg2TZxCoEMhxPZ192ndVNo0LJ+GTiZe29v0Rqh1z+4a6STEjCcA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <2db7bc79-4fe4-abf6-9e5a-83055af9a78a@suse.com> Date: Fri, 18 Feb 2022 09:35:10 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 From: Jan Beulich Subject: [PATCH v4] x86/mwait-idle: re-order state entry/exit code a little To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= References: Content-Language: en-US In-Reply-To: X-ClientProxiedBy: AS8P189CA0026.EURP189.PROD.OUTLOOK.COM (2603:10a6:20b:31f::30) To VI1PR04MB5600.eurprd04.prod.outlook.com (2603:10a6:803:e7::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e163a9d8-b02e-47ee-1910-08d9f2b99485 X-MS-TrafficTypeDiagnostic: AM6PR04MB5813:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3lwXCsR/576G0CT/xY2Xuq5Eq8BXlNefjwPfqVuoahKDv4GlipwlACH3ybxf4Wmjrhr1Juu/Dmzxd+bzqpz9dDHWbQCc0RhExGKULeBs4CuYDCbwVzNdJZHJfv3cACwx5eIW/ZX92Na6GXi9rAIUvjMt4/CP5PBpVOKwPdX3RXtSGccUxiLaqDBWnhoZBYdnnKpc2Nj/OIWq8xr4eIb7N/Ww/cN6UM63undbLxOX+BgpD/ckcyUFTS3AnKWsS5EedY4ICV0Eg2Zx2Mn6FIyf7kscnwfxYzfVU1jE/aUmMLjSJ/CBvxzjAsfqeF6Tldhxrb4a+rFdpgjs6N3YUK4xpjIDUCP+AEr+NOuFE57UlvBBPpW0cNKiCy4WgZEvw3FNX2lhze+mqEEGYEvU5fYKhDMXxDual90Rc8g1FfuYQju/wUVV4lKvK6j2zbbdCGJ1EALc8Tn+kaPXfLMYSD7VWkIISmaJnLRfiIIpcMb/5kqttpidPA4X+EkRPFuhC8eQhUXYeIEjqNNhUyT3ru2XHz1GquQr+fjtSb9FUqxyUvv43+OuC8x3Hj4Tkaf1nbm0oX34QpY/LJkmBJ0GOxrPZg1atlAnLJFDGFP8KxK13ehIMWGcr0XjnfGNzBO4Wk2h+O4VVuQTQAEkMRxZ7KWkddh80ja/eE8I1Kce+Zf8xZdAlR+/43tRxXTE3ET0IipYdFjqUCLCUIr/p5EbmHCETW0UrC2pBUU+yEPLuzEcSMZPNJIGUPpNEj16JS/ac0KLqQbrbRTT9fW+0bhisWVFcw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB5600.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(4326008)(66476007)(508600001)(2616005)(66556008)(8676002)(2906002)(316002)(31686004)(83380400001)(86362001)(66946007)(54906003)(8936002)(186003)(6916009)(5660300002)(6506007)(26005)(6512007)(31696002)(36756003)(6486002)(38100700002)(169823001)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?dB0n1m0BiRTfoI/4gEBzh41mE+vh?= =?utf-8?q?OToLi4dFpR7N4/dBFp7QPMqDlXZvgteJkfrFOw55VuTJP+JaN6johwAaZo2twuI15?= =?utf-8?q?pNLL4VItmWQLSFNE+OkfTS5u5E38JM5Qc6MX8RsI8FH5ad5Nccis2c/Q/+Hnl6ood?= =?utf-8?q?K+ZQNUM5HSO5hnLet56OVVEuOQ36YjbrbV94rRT4XVqDqt6Gb1zEfh4Wks5bjCXSd?= =?utf-8?q?h/CL5K0n9io+YKnHZS38wf/iPC6ffi9fLJRMYfk3ijLR7X8aRifmZcIswqruwyMBK?= =?utf-8?q?9/BbDnzlLjAsvCcRx6eJRi/2VwpAZHt9nV5u7DCMf/a+jvLtC6F+PAu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pVMwIoeyWjKUP1WslmpKLr?= =?utf-8?q?uzLtsEIOni/c3HJGCSjNcPjpytS1+1CqYxxx0XyxMXpoNLr4rCZt8/chnKKA985st?= =?utf-8?q?y4LH3a/G85Amp2itUO/bVtrrKTWeBNO/Er2N8hg5FLlQRrsnO4hlhrky9/qOhJcCy?= =?utf-8?q?2/nR16s2Hkdx1JhN/QndZ+ZOECqNDefJX53xJfUX+GtBq8mxAJ5fJL1McfcKEn1gb?= =?utf-8?q?xwz9Dq9Lp5rniCYerFOE/DDLDcfHEAkpkOz9LKeLsCPYG3SOADB/vu+t3X1hB9S5j?= =?utf-8?q?C5+22ClspkHzNti1N+u8AQaZ9xHDpHWgNuPkwrshJfbvx9uoezSmgRveZaJeU67TQ?= =?utf-8?q?tKFZeXJE3HazQyguUy20E9in4orTaQH9bu3Afg27wzJcT8yug2tky5s=3D?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: e163a9d8-b02e-47ee-1910-08d9f2b99485 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5600.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Feb 2022 08:35:12.5507 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: yvDyd028BHTXDZwt5ofSqeGrFP1Keon+xr1qgLlpNj9uttLAPBHHUeE695YMYSSDZ8FLHt0xTd+hjsMCZi9lHw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR04MB5813 The initial observation is that unlike the original ACPI idle driver we have a 2nd cpu_is_haltable() in here. By making the actual state entry conditional, the emitted trace records as well as the subsequent stats update are at least misleading in case the state wasn't actually entered. Hence they would want moving inside the conditional. At which point the cpuidle_get_tick() invocations could (and hence should) move as well. cstate_restore_tsc() also isn't needed if we didn't actually enter the state. This leaves only the errata_c6_workaround() and lapic_timer_off() invocations outside the conditional. As a result it looks easier to drop the conditional (and come back in sync with the other driver again) than to move almost everything into the conditional. While there also move the TRACE_6D() out of the IRQ-disabled region. Signed-off-by: Jan Beulich Reviewed-by: Roger Pau Monné --- Moving the TRACE_6D() may be a little controversial, as this could lead to a sequence of trace records not actually representing the sequence of events, in case further records get emitted by interrupt handlers. But with us now conditionally enabling interrupts around MWAIT, that issue exists already anyway. Unlike said in the earlier outline of the alternative approach, errata_c6_workaround() cannot be moved: cpu_has_pending_apic_eoi() needs to be called when IRQs are already off. --- v4: Different approach (and title), as was previously outlined as an alternative. v3: Also move cstate_restore_tsc() invocation and split ones to update_idle_stats(). v2: New. --- a/xen/arch/x86/cpu/mwait-idle.c +++ b/xen/arch/x86/cpu/mwait-idle.c @@ -847,26 +847,25 @@ static void mwait_idle(void) update_last_cx_stat(power, cx, before); - if (cpu_is_haltable(cpu)) { - if (cx->irq_enable_early) - local_irq_enable(); + if (cx->irq_enable_early) + local_irq_enable(); - mwait_idle_with_hints(cx->address, MWAIT_ECX_INTERRUPT_BREAK); + mwait_idle_with_hints(cx->address, MWAIT_ECX_INTERRUPT_BREAK); - local_irq_disable(); - } + local_irq_disable(); after = alternative_call(cpuidle_get_tick); cstate_restore_tsc(); trace_exit_reason(irq_traced); - TRACE_6D(TRC_PM_IDLE_EXIT, cx->type, after, - irq_traced[0], irq_traced[1], irq_traced[2], irq_traced[3]); /* Now back in C0. */ update_idle_stats(power, cx, before, after); local_irq_enable(); + TRACE_6D(TRC_PM_IDLE_EXIT, cx->type, after, + irq_traced[0], irq_traced[1], irq_traced[2], irq_traced[3]); + if (!(lapic_timer_reliable_states & (1 << cx->type))) lapic_timer_on();