From patchwork Thu Dec 7 10:19:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 1873560 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=fwts-devel-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SmX7n3bBwz23yk for ; Fri, 8 Dec 2023 11:29:09 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1rBOjn-0003LC-Qz; Fri, 08 Dec 2023 00:29:04 +0000 Received: from mail-mw2nam12on2071.outbound.protection.outlook.com ([40.107.244.71] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1rBOji-0003Ji-S5 for fwts-devel@lists.ubuntu.com; Fri, 08 Dec 2023 00:28:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SNlHmETso3cCITmQSJknbST9VscsAnGv5fvz/ifJheSVVMH3Lx4vyAgbWezKnheJjm8OLA4Gys3tRq/Jgpssj75KTMItJMR55wnAVNh92eGvP2Na1t9MyUe8rLjwDQbPZA+tQoUSG1Bl9Rgg0RTEJF/TCJlsDXB6kYmjNInNDbV9OXxyp3pwpm30dx6/IbTfkgQHX3qo6zgWgAZYfXcKhNUo39ORk8OnDMMW3QYW3/bVgTXkIy7DFs8fPPNmeeVsBXN5N+t3z8YFfNuUCy+Cr6jDiFhGfzPYyIBK9Fb9/xjvQcTWFOr4DX03tlNwtML69eN6LXeFg4UrNGuefvvsTw== 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=1cWQfQabCdyNtBp4Eil1OgLtFeW7wYb5xBeJi0WIqLw=; b=WlRGcQHpwpK3w/R9WkOZSYgIV6pI92DNRpKxHKbzCwY3rJwjplFOgW0FaXMbjc4ZefClAyYGAjDfVCcqPexv0f9ydKEMf09LSAyughoQ7jsg7na/p831VuekxEGu62NOzos0ZcokErG2yxHB6CA874l8Lz6eyggtwTmoYsbMCNfiI/kdXVJFRwQGEsg4TSd5PslFHogbaNgt3kSyArd9ecvRcxaaDvw0T92hsCY/ECAOrrWe0Qh+QBm/ozTemc9s21xlCOGQT9kERozuJX6XLgrYn99I3OwzNiewRnIRRBLNKgawIFlUMtGi7q/oYvfz+guUSnjC2s4Gsc54xtDZcg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.ubuntu.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 (0) Received: from SA1P222CA0019.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:22c::20) by MN0PR12MB6101.namprd12.prod.outlook.com (2603:10b6:208:3cb::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.28; Fri, 8 Dec 2023 00:28:53 +0000 Received: from SA2PEPF00001509.namprd04.prod.outlook.com (2603:10b6:806:22c:cafe::c8) by SA1P222CA0019.outlook.office365.com (2603:10b6:806:22c::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.27 via Frontend Transport; Fri, 8 Dec 2023 00:28:52 +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 SA2PEPF00001509.mail.protection.outlook.com (10.167.242.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7068.20 via Frontend Transport; Fri, 8 Dec 2023 00:28:52 +0000 Received: from AUS-P9-MLIMONCI.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.2507.34; Thu, 7 Dec 2023 18:28:49 -0600 From: Mario Limonciello To: Subject: [PATCH 1/3] s3: Add support for reading total s2idle residency from generic API Date: Thu, 7 Dec 2023 04:19:25 -0600 Message-ID: <20231207101927.9378-2-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231207101927.9378-1-mario.limonciello@amd.com> References: <20231207101927.9378-1-mario.limonciello@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: SA2PEPF00001509:EE_|MN0PR12MB6101:EE_ X-MS-Office365-Filtering-Correlation-Id: 37c23190-91fd-4c8e-5c34-08dbf784a787 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: p77ioEQtGtbhdGJwkopN42Q5Qg9t6DCCqaFPgLX1yCjKPwvtGPYFoDwlODzCVaiq8pS/5meafvKu+3oD5GRLPczQD3q+YhS2UfXu5RjSZv7+l9FBfnjBfIJ/uKGcQXKULDFWPDBqy9svCy9+5MwuAD8vAFQyY5wrhc5S41uPxgh82mNaDTAgglu4ykO46D/cmAsiaNj8oC9RUs60QY+7CB2jxFTj22IgxYMNVdukUfOZwXsjUPu8mYpCzJrEQko3wlKEjBlZwcjQzsQWOssX3gGXtOl6t+nO4AShuplJN9qu10qJfFLjbJi4xtYmfqY5w0/+OSoguXfA0DguHZblC79wwMu1Rykfo720zEJ5d4dXRRSiLdP35oCRwejBKheuoR+sdHAxos0pf3V4S8/X0ekhGAe+rI0EF7XbGdfEoK8ZqkqGJp4D0yUWYA0A/MmoXY0BhIbDkOazjVVq4iMOnzMtN5Op7bKyn0ZzOThGFYT0cC8+e9s0LR0rqq6lWhJXLxiIITqDKZ4STGfSexG5cTajOmcAng6yAGh9GNMGHxNDwZa/63xY1Xv1xIpRZu6C5lB04flwGonN7MDr8ZAdS0puhgY7wsqjkDIcp3ggFvg7tXjUHmSIucGkKnnuENQsNDyPXxMtLTaPZCTctLlLvq9rJzGTLoYNd6/jIsZKWTz4A0xv6gZgtxrkqX2PUCKgO3fib9K5jwL+6wDXJX5jtyWcz+zs61i5Ppb0bV5GkZ2FU0c/QWuXeU9JgKvpkq2lPVAX4JSB3Ew8i2MYVZH6eHMAwc8eIqGvPYWBXSMxchM= 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:(13230031)(4636009)(396003)(39860400002)(376002)(136003)(346002)(230922051799003)(451199024)(186009)(64100799003)(1800799012)(82310400011)(40470700004)(46966006)(36840700001)(36860700001)(356005)(16526019)(26005)(1076003)(5660300002)(47076005)(41300700001)(86362001)(2616005)(81166007)(83380400001)(336012)(82740400003)(40480700001)(426003)(6666004)(7696005)(478600001)(8676002)(40460700003)(70586007)(4326008)(6916009)(70206006)(316002)(8936002)(44832011)(2906002)(36756003)(41533002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2023 00:28:52.0841 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 37c23190-91fd-4c8e-5c34-08dbf784a787 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: SA2PEPF00001509.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6101 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mario Limonciello Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: "fwts-devel" A generic API has been introduced in the kernel for reading s2idle residency. It works for AMD as well. Use this API if present, fall back to the properietary Intel specific API otherwise. Signed-off-by: Mario Limonciello Acked-by: Ivan Hu --- src/acpi/s3/s3.c | 61 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/src/acpi/s3/s3.c b/src/acpi/s3/s3.c index 7c2da431..ba705441 100644 --- a/src/acpi/s3/s3.c +++ b/src/acpi/s3/s3.c @@ -33,8 +33,9 @@ #define PM_SUSPEND_PMUTILS "pm-suspend" #define PM_SUSPEND_HYBRID_PMUTILS "pm-suspend-hybrid" #define PM_SUSPEND_PATH "/sys/power/mem_sleep" -#define PM_S2IDLE_SLP_S0 "/sys/kernel/debug/pmc_core/slp_s0_residency_usec" +#define PM_SUSPEND_TOTAL_HW_SLEEP "/sys/power/suspend_stats/total_hw_sleep" #define WAKEUP_SOURCE_PATH "/sys/kernel/debug/wakeup_sources" +#define INTEL_PM_S2IDLE_SLP_S0 "/sys/kernel/debug/pmc_core/slp_s0_residency_usec" static char sleep_type[7]; static char sleep_type_orig[7]; @@ -361,16 +362,12 @@ static int wrap_pmutils_do_suspend(fwts_pm_method_vars *fwts_settings, return status; } -/* - * get_s2_idle_residency() - * read PM_S2IDLE_SLP_S0, return 0 if it is not available - */ -static uint64_t get_s2_idle_residency(void) +static uint64_t get_uint64_sysfs(const char *path) { - char *str; uint64_t val; + char *str; - str = fwts_get(PM_S2IDLE_SLP_S0); + str = fwts_get(path); if (!str) return 0; @@ -380,12 +377,39 @@ static uint64_t get_s2_idle_residency(void) return val; } +/* + * get_total_s2idle_residency() + * @fname: Optional parameter to set the filename used to check residency + * + * Returns: + * - Total hardware sleep residency since the system was booted + * - 0 if it is not available + * + */ +static uint64_t get_total_s2idle_residency(const char **fname) +{ + const char *check; + uint64_t val; + + if (access(PM_SUSPEND_TOTAL_HW_SLEEP, F_OK) == 0) + check = PM_SUSPEND_TOTAL_HW_SLEEP; + else + check = INTEL_PM_S2IDLE_SLP_S0; + + val = get_uint64_sysfs(check); + + if (fname) + *fname = check; + + return val; +} + static int s3_do_suspend_resume(fwts_framework *fw, int *hw_errors, int *pm_errors, int *hook_errors, int *s2idle_errors, - uint64_t *s2idle_residency, + uint64_t *total_s2idle_residency, int delay, int percent) { @@ -528,15 +552,16 @@ static int s3_do_suspend_resume(fwts_framework *fw, } if (!strncmp(sleep_type, "s2idle", strlen("s2idle"))) { - uint64_t residency = get_s2_idle_residency(); - bool intel; - if (fwts_cpu_is_Intel(&intel) == FWTS_OK && intel && residency <= *s2idle_residency) { + const char *fname; + uint64_t residency = get_total_s2idle_residency(&fname); + + if (residency <= *total_s2idle_residency) { (*s2idle_errors)++; - fwts_failed(fw, LOG_LEVEL_HIGH, "S2idleNotDeepest", - "Expected %s to increase from %" PRIu64 ", got %" PRIu64 ".", - PM_S2IDLE_SLP_S0, *s2idle_residency, residency); + fwts_failed(fw, LOG_LEVEL_CRITICAL, "S2idleNotDeepest", + "Expected %s to increase from %" PRIu64 ", got %" PRIu64 ".", + fname, *total_s2idle_residency, residency); } - *s2idle_residency = residency; + *total_s2idle_residency = residency; } if (duration < delay) { @@ -740,7 +765,7 @@ static int s3_test_multiple(fwts_framework *fw) int resume_too_long = 0; int awake_delay = s3_min_delay * 1000; int delta = (int)(s3_delay_delta * 1000.0); - uint64_t s2idle_residency = get_s2_idle_residency(); + uint64_t total_s2idle_residency = get_total_s2idle_residency(NULL); int pm_debug; #if FWTS_ENABLE_LOGIND @@ -766,7 +791,7 @@ static int s3_test_multiple(fwts_framework *fw) fwts_log_error(fw, "Cannot read kernel log."); ret = s3_do_suspend_resume(fw, &hw_errors, &pm_errors, &hook_errors, - &s2idle_errors, &s2idle_residency, + &s2idle_errors, &total_s2idle_residency, s3_sleep_delay, percent); if (ret == FWTS_OUT_OF_MEMORY) { fwts_log_error(fw, "%s cycle %d failed - out of memory error.", sleep_type, i+1);