From patchwork Wed May 12 22:15:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 12254889 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51CFDC43460 for ; Wed, 12 May 2021 23:12:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 32F88613BD for ; Wed, 12 May 2021 23:12:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242006AbhELXNW (ORCPT ); Wed, 12 May 2021 19:13:22 -0400 Received: from mail-sn1anam02on2053.outbound.protection.outlook.com ([40.107.96.53]:60098 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1443141AbhELWQk (ORCPT ); Wed, 12 May 2021 18:16:40 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=D/bVneCSMmDudH/dsXbS6HjybMyyF7d5ORjtm1RqUOZNOZTWmRQANlGM86j3e2c94w3o0R3sccudqA/944NpIBqKsAfRw2GAHhNuzFfGzIq9pHow9kluzWimdu70uuP5mecIu+LKDm+BdQ64cJiG/fVv6wYFoPzf3IM2U44k+rsF7jxxM2DoBor2pPzBrVodXXm/Jm31YqWrmjhjKf++PYee5PPggPZ+RYtYOtwvS/t+hUhVwrCOUi36ELVESVi9PNXCjYVKaY53mGjo2BCggvr6f5bsui7MUeMGjUItec4TAfHMTA6GLYieu24Y0CmKBczvYbNPWY/ufJsqERYD7g== 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-SenderADCheck; bh=ZHGwal23M2Akhd+VIY6eFT58qLrDXf2K/w3/Cco05d4=; b=HtVpfFi8qJn6DxhwuZMVUGQeu7/blix/Ru5T3GCVN933KZeNj77ttzD/jEFdaJgaB1Tkzj+VNBWESrkpGZwWwSWKrzFHRR3HUeb+n8+7NAeWX6gKPagFwRQ4xbG/xE/ozyUj7/hP0Ho+QR8o3xdMhxmgzZYVJf1Od0Oj6UYrgjf42mrQc+39d7Tn/l9hSyA8aKS1/HFBdQLMwyp/EJTsVUILA7nLeWbDbo7slk3ZyIldQe323OfpycwU7fqZ+2nIa49W83pb+hf4aPFFf0RjmTnFUQuholXaBxruScAMLXOc6bju3U8fJdCTQsOujSZ9RyLmOhj7d9Kz5xsxASX7XA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; 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=ZHGwal23M2Akhd+VIY6eFT58qLrDXf2K/w3/Cco05d4=; b=wuYzyaFHIlbk7uDIUE3c3VvNndcmORE3Yuy5/qBMxhvfYOacbnWV67tU9nRN/i6Rk8cGJt8OjvMM0l6MqOYPomTJQxLUfEu1wqmd6V6+LKuAGGPBNZdpYmi2NdUt096qh43Oj0rKWKpnPSzQwe+87hKtIs3hm7FNWsrsVUgJkNg= Authentication-Results: rjwysocki.net; dkim=none (message not signed) header.d=none;rjwysocki.net; dmarc=none action=none header.from=amd.com; Received: from BYAPR12MB2693.namprd12.prod.outlook.com (2603:10b6:a03:6a::33) by BYAPR12MB2774.namprd12.prod.outlook.com (2603:10b6:a03:71::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4129.25; Wed, 12 May 2021 22:15:18 +0000 Received: from BYAPR12MB2693.namprd12.prod.outlook.com ([fe80::c0c3:7247:a767:f5b6]) by BYAPR12MB2693.namprd12.prod.outlook.com ([fe80::c0c3:7247:a767:f5b6%3]) with mapi id 15.20.4129.026; Wed, 12 May 2021 22:15:18 +0000 From: Mario Limonciello To: "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org Cc: Mario Limonciello , Prike Liang , Alex Deucher Subject: [PATCH v3] ACPI / idle: override c-state latency when not in conformance with s0ix Date: Wed, 12 May 2021 17:15:14 -0500 Message-Id: <20210512221514.32038-1-mario.limonciello@amd.com> X-Mailer: git-send-email 2.25.1 X-Originating-IP: [165.204.78.25] X-ClientProxiedBy: SA9PR13CA0144.namprd13.prod.outlook.com (2603:10b6:806:27::29) To BYAPR12MB2693.namprd12.prod.outlook.com (2603:10b6:a03:6a::33) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from AUS-LX-MLIMONCI.amd.com (165.204.78.25) by SA9PR13CA0144.namprd13.prod.outlook.com (2603:10b6:806:27::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.11 via Frontend Transport; Wed, 12 May 2021 22:15:17 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 89c7f79f-fe9c-42da-4e2a-08d915936d13 X-MS-TrafficTypeDiagnostic: BYAPR12MB2774: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:298; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Wg47XJ/OA5LyL0MnSNmwr4vVqLHRGFr6b8k3yKVaCeXgcOTM+gthYMrhepIO0sP6SJQx3jnksAROLg8yV9Jcr0JFeMb+0uKL5cK1F5nuLqLlvGXpH/WFQltX+QnwBHaaaS6BPUlMQXyiuXv90xAtfPzOsjrwPQ0sDlV58f7XM+TZPnhJr6GXhS/j1dytuf5BPcvWYVuQI+3YY4mlgdIlp2KLDpV0ePB7pNS/zIz6qHqO6cq8oIPDea+Es6YQnxboVnd9IgwyjAWF7Soi/g3dphBt4yo9NrJ1BaMqFIJGqP469oCGzYXsuUVfPEufQ73ROzPN/WiHmRHN2dYHDusGglsH6nG0Yr85MjEyn/9y4U7BAOWRrCDX7w3A6JtCgZ/7/0RzIv2CjHICNGRR1rOnpP15klZur1Xk38cuEr6N+xw471eKv9EawBVq9lsDonXsZqvkOPzBROvg8QIkbyVfWrP2tR4F6G7TH5sO7pxVY2Ljq80A/5drEuPewpejTxggzA5/uau6FBU01cyO/VzDGDHVcY3zIHOJ53TsiJ+isVijvHFiMLzrJgyEDPDWewMRi4o9YpwRA0MDXobztbfukpILxv8j0uLaK+u+BWgJ9Bfj46kl3NINNMBzjdw9FqF4n1Gw3yuquqW9QPn08xDsKs9Wv1MP5oHdzCm8kESDcFQl0XdhfBDDw1hN1YkSIkHbz50mJhqH1vxMyOh8/yupPw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR12MB2693.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(346002)(39860400002)(376002)(396003)(136003)(2616005)(4326008)(956004)(44832011)(66556008)(66476007)(38100700002)(8676002)(2906002)(38350700002)(86362001)(8936002)(83380400001)(26005)(7696005)(52116002)(5660300002)(186003)(16526019)(966005)(66946007)(6486002)(478600001)(36756003)(316002)(110136005)(54906003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rsiaJXZgnCNRBM3cTsmopAGhMSH/fgVfVEAKkAsxt3VuHV5zMyWmnAmiaEadcgsaeIMu/IjhtOlKSY3gAwaOuLqEv0IGdPtioNSWKpzlwr+h0AVkSKNyrtc07fp5/QR02LFcjHEIVnAFVCBK1Y8xbbJ2AR5Hv2/vGecYnu/bnLuJnTRDEG0WAVDLvmg7A6z/Berbd45+8Eqr4oU7Fz0Bnh3W+ZalY+1u3RjnFKd6ix+hPdbq5yCoaldYcjr2py3p78MOxvPVgmZmAVpL2LnmDDpK5KjdkaeD4K9X2QJ58UwLPCjE0B5lnnfejXSv5 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 89c7f79f-fe9c-42da-4e2a-08d915936d13 X-MS-Exchange-CrossTenant-AuthSource: BYAPR12MB2693.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 May 2021 22:15:18.5322 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: E60NYR7hQncaeuP5sNbKDOGwBoFK3GPVOwT5yLtn94cOk5/UHSlhOaQTjiNEVz1MYROSAwiwYcbPJgus6RYnpw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB2774 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Generally the C-state latency is provided by the _CST method or FADT but some OEM platforms using AMD Picasso, Renoir, Van Gogh, and Cezanne set the C2 latency greater than C3's which causes the C2 state to be skipped. That will block the core entering PC6, which prevents s0ix working properly on Linux systems. In other operating systems the latency values are not validated and this does not cause problems by skipping states. To avoid this issue happening on Linux, detect when latencies are not an arithmetic progression and sort them. Link: https://gitlab.freedesktop.org/agd5f/linux/-/commit/026d186e4592c1ee9c1cb44295912d0294508725 Link: https://gitlab.freedesktop.org/drm/amd/-/issues/1230#note_712174 Suggested-by: Prike Liang Suggested-by: Alex Deucher Signed-off-by: Mario Limonciello --- drivers/acpi/processor_idle.c | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index 4e2d76b8b697..6790df5a2462 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c @@ -16,6 +16,7 @@ #include #include #include /* need_resched() */ +#include #include #include #include @@ -388,10 +389,37 @@ static void acpi_processor_power_verify_c3(struct acpi_processor *pr, return; } +static int acpi_cst_latency_cmp(const void *a, const void *b) +{ + const struct acpi_processor_cx *x = a, *y = b; + + if (!(x->valid && y->valid)) + return 0; + if (x->latency > y->latency) + return 1; + if (x->latency < y->latency) + return -1; + return 0; +} +static void acpi_cst_latency_swap(void *a, void *b, int n) +{ + struct acpi_processor_cx *x = a, *y = b; + u32 tmp; + + if (!(x->valid && y->valid)) + return; + tmp = x->latency; + x->latency = y->latency; + y->latency = tmp; +} + static int acpi_processor_power_verify(struct acpi_processor *pr) { unsigned int i; unsigned int working = 0; + unsigned int last_latency = 0; + unsigned int last_type = 0; + bool buggy_latency = false; pr->power.timer_broadcast_on_state = INT_MAX; @@ -415,12 +443,24 @@ static int acpi_processor_power_verify(struct acpi_processor *pr) } if (!cx->valid) continue; + if (cx->type >= last_type && cx->latency < last_latency) + buggy_latency = true; + last_latency = cx->latency; + last_type = cx->type; lapic_timer_check_state(i, pr, cx); tsc_check_state(cx->type); working++; } + if (buggy_latency) { + pr_notice("FW issue: working around C-state latencies out of order\n"); + sort(&pr->power.states[1], max_cstate, + sizeof(struct acpi_processor_cx), + acpi_cst_latency_cmp, + acpi_cst_latency_swap); + } + lapic_timer_propagate_broadcast(pr); return (working);