From patchwork Tue Aug 8 10:31:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Hu X-Patchwork-Id: 1818578 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=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=fwts-devel-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=u22U2DG2; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (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 4RKqGx1v2Jz1yVt for ; Tue, 8 Aug 2023 20:31:20 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1qTJze-00061K-8T; Tue, 08 Aug 2023 10:31:14 +0000 Received: from smtp-relay-canonical-0.internal ([10.131.114.83] helo=smtp-relay-canonical-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1qTJzd-00061D-Bd for fwts-devel@lists.ubuntu.com; Tue, 08 Aug 2023 10:31:13 +0000 Received: from canonical.com (unknown [106.104.136.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id 88AE641536 for ; Tue, 8 Aug 2023 10:31:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1691490673; bh=nls7zHmwqDbVu3Pffsd2QyR1h/RtWrQDn0SFdtWpeNs=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=u22U2DG29UfLwAgtcBLJXRxh5n5EN7rVBEDe0VqL9hqGv3Xt7Ex7t7g+X8hBuH+Ne qckrzMxlQQ66cNtak4v3IA05bsvtj/BK08wdPzV1/zWA7TkIqdIXSJId+9hqq9KbxQ ms0pMXLjDT2cIqdniO+fcG81l90AUjjDJ8SFrrPhHI8e0OXwuEOa3DHjK/G2XTthMq vquu/V2H/bRiSXLWq+SXSpbSaxjZgzxIvOZPzkF30U/iCJ5tsM8iWkfbsL2F1QIQ0t IUMf4RQ38xEwrGhiOusgVxM1LdTI3+6IgtuRwh1jg4LYNqfCCb/YBaVzHNNlM7T/WI UHPtK1CDxrs4Q== From: Ivan Hu To: fwts-devel@lists.ubuntu.com Subject: [PATCH 1/2] s3: add checking the device signed wakeup events Date: Tue, 8 Aug 2023 18:31:08 +0800 Message-Id: <20230808103109.31376-1-ivan.hu@canonical.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 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: , Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: "fwts-devel" BugLink: https://bugs.launchpad.net/fwts/+bug/2029452 The file, /sys/kernel/debug/wakeup_sources, lists wakeup source for all wakeup devices. It could be used to check the devices which wakeup event signed. Signed-off-by: Ivan Hu --- src/acpi/s3/s3.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/src/acpi/s3/s3.c b/src/acpi/s3/s3.c index ba009426..a4775cd4 100644 --- a/src/acpi/s3/s3.c +++ b/src/acpi/s3/s3.c @@ -34,6 +34,7 @@ #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 WAKEUP_SOURCE_PATH "/sys/kernel/debug/wakeup_sources" static char sleep_type[7]; static char sleep_type_orig[7]; @@ -53,6 +54,103 @@ static bool s3_hybrid = false; static char *s3_hook = NULL; /* Hook to run after each S3 */ static char *s3_sleep_type = NULL; /* The sleep type(s3 or s2idle) */ +typedef struct { + char name[32]; + uint64_t active_count; + uint64_t event_count; + uint64_t wakeup_count; + uint64_t expire_count; + int64_t active_since; + int64_t total_time; + int64_t max_time; + int64_t last_change; + int64_t prevent_suspend_time; +} wakeup_source; + +static int read_wakeup_source(fwts_list *source) +{ + FILE *fp; + char name[32]; + uint64_t active_count; + uint64_t event_count; + uint64_t wakeup_count; + uint64_t expire_count; + int64_t active_since; + int64_t total_time; + int64_t max_time; + int64_t last_change; + int64_t prevent_suspend_time; + int c; + + fwts_list_init(source); + + if ((fp = fopen(WAKEUP_SOURCE_PATH, "r")) == NULL) + return FWTS_ERROR; + + /* skip first line */ + while (c = fgetc(fp), c != '\n' && c != EOF); + + while (fscanf(fp, "%s\t%lu\t\t%lu\t\t%lu\t\t%lu\t\t%ld\t\t%ld\t\t%ld\t\t%ld\t\t%ld\n", + name, &active_count, &event_count, + &wakeup_count, &expire_count, &active_since, + &total_time, &max_time, &last_change, + &prevent_suspend_time) == 10) { + wakeup_source *wakeup_source_data; + + wakeup_source_data = calloc(1, sizeof(wakeup_source)); + if (wakeup_source_data == NULL) { + fwts_list_free_items(source, free); + (void)fclose(fp); + return FWTS_ERROR; + } + + memcpy(wakeup_source_data->name , name, sizeof(name)); + wakeup_source_data->active_count = active_count; + wakeup_source_data->event_count = event_count; + wakeup_source_data->wakeup_count = wakeup_count; + wakeup_source_data->expire_count = expire_count; + wakeup_source_data->active_since = active_since; + wakeup_source_data->total_time = total_time; + wakeup_source_data->max_time = max_time; + wakeup_source_data->last_change = last_change; + wakeup_source_data->prevent_suspend_time = prevent_suspend_time; + + fwts_list_append(source, wakeup_source_data); + + } + + (void)fclose(fp); + + return FWTS_OK; +} + + +static void wakeup_source_cmp(fwts_framework *fw, fwts_list *suspend_source, fwts_list *resume_source) +{ + + fwts_list_link *item1; + fwts_list_link *item2; + + if (fwts_list_len(suspend_source) != fwts_list_len(resume_source)) { + fwts_log_info_verbatim(fw, "wakeup source list length differ, cannot get wakeup sources.\n"); + return; + } + + item1 = fwts_list_head(suspend_source); + item2 = fwts_list_head(resume_source); + + while ((item1 != NULL) && (item2 != NULL)) { + wakeup_source *data1 = fwts_list_data(wakeup_source *, item1); + wakeup_source *data2 = fwts_list_data(wakeup_source *, item2); + if (data1->event_count < data2->event_count) { + fwts_log_info_verbatim(fw, "wakeup source name: \"%s\" wakeup event was signaled.\n", data1->name); + + } + item1 = fwts_list_next(item1); + item2 = fwts_list_next(item2); + } +} + static int s3_init(fwts_framework *fw) { char *str; @@ -267,6 +365,9 @@ static int s3_do_suspend_resume(fwts_framework *fw, char *command = NULL; char *quirks = NULL; fwts_pm_method_vars *fwts_settings; + fwts_list suspend_wakeup_soure; + fwts_list resume_wakeup_soure; + bool wk_src_found = false; int (*do_suspend)(fwts_pm_method_vars *, const int, int*, const char*); @@ -344,9 +445,19 @@ static int s3_do_suspend_resume(fwts_framework *fw, fwts_wakealarm_trigger(fw, delay); + if (read_wakeup_source(&suspend_wakeup_soure) != FWTS_ERROR) { + wk_src_found = true; + } + /* Do S3 / S2idle here */ status = do_suspend(fwts_settings, percent, &duration, command); + if (wk_src_found) { + if (read_wakeup_source(&resume_wakeup_soure) != FWTS_ERROR) { + (void)wakeup_source_cmp(fw, &suspend_wakeup_soure, &resume_wakeup_soure); + } + } + fwts_log_info(fw, "pm-action returned %d after %d seconds.", status, duration); if (s3_device_check) { @@ -433,6 +544,9 @@ static int s3_do_suspend_resume(fwts_framework *fw, "enter the requested power saving state."); } + fwts_list_free_items(&suspend_wakeup_soure, free); + fwts_list_free_items(&resume_wakeup_soure, free); + tidy: free(command); free(quirks); From patchwork Tue Aug 8 10:31:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Hu X-Patchwork-Id: 1818579 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=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=fwts-devel-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=VSCRcAZF; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (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 4RKqGy65B9z1yVt for ; Tue, 8 Aug 2023 20:31:22 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1qTJzj-000624-DN; Tue, 08 Aug 2023 10:31:19 +0000 Received: from smtp-relay-canonical-0.internal ([10.131.114.83] helo=smtp-relay-canonical-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1qTJzh-00061m-D9 for fwts-devel@lists.ubuntu.com; Tue, 08 Aug 2023 10:31:17 +0000 Received: from canonical.com (unknown [106.104.136.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id 9D5DB41536 for ; Tue, 8 Aug 2023 10:31:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1691490677; bh=kOnhpxg/Dh4hMcHUHgKHlrskikgtXiJGlMH9wxoAI1o=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VSCRcAZFSNq9iQ5g9Mnj+TmEPTl2l8zaci1NF2MIb3954ZGNify1wUSte24QqsoNG U5SqWxec2q3HAOHOaFJH1AUj37rQ6wGDEVZs0H6grX/1nN7oC+bxc7GLOd7B0N9N+m JTwOV8srI0VwAFS5mm7DyImFCl5372tPI1tF9miCdMJ9xqzACu23+uLkGxBjw/8/QL T+ZwfAokqK2LlAB9s5FM5q57ACYbpikM133S1ebcZ630n5qcDmDh7YDyeFcvja+NVM LnpFkv0UmptvMlB226FEBczr1ju9fZIn4C1Gq23sT1dIbocjjPs+xVy+v2SSq4D7dn T0riMrZM9GPYg== From: Ivan Hu To: fwts-devel@lists.ubuntu.com Subject: [PATCH 2/2] s3: add dumping the all devices and signed wakeup sources Date: Tue, 8 Aug 2023 18:31:09 +0800 Message-Id: <20230808103109.31376-2-ivan.hu@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230808103109.31376-1-ivan.hu@canonical.com> References: <20230808103109.31376-1-ivan.hu@canonical.com> MIME-Version: 1.0 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: , Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: "fwts-devel" Add s3-dump-wakeup-src option for dumping the wakeup sources for debug. Signed-off-by: Ivan Hu --- src/acpi/s3/s3.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/src/acpi/s3/s3.c b/src/acpi/s3/s3.c index a4775cd4..93686155 100644 --- a/src/acpi/s3/s3.c +++ b/src/acpi/s3/s3.c @@ -53,6 +53,7 @@ static float s3_resume_time = 15.0; /* Maximum allowed resume time */ static bool s3_hybrid = false; static char *s3_hook = NULL; /* Hook to run after each S3 */ static char *s3_sleep_type = NULL; /* The sleep type(s3 or s2idle) */ +static bool s3_wakeup_src = false; /* dump wakeup source for debug */ typedef struct { char name[32]; @@ -124,6 +125,25 @@ static int read_wakeup_source(fwts_list *source) return FWTS_OK; } +static void dump_wakeup_source(fwts_framework *fw, fwts_list *source) +{ + if (fwts_list_len(source) > 0) { + fwts_list_link *item; + + + fwts_list_foreach(item, source) { + wakeup_source *wakeup_source_data = + fwts_list_data(wakeup_source *, item); + + fwts_log_info_verbatim(fw, "%s\t%lu\t%lu\t%lu\t%lu\t%ld\t%ld\t%ld\t%ld\t%ld\n", + wakeup_source_data->name, wakeup_source_data->active_count, wakeup_source_data->event_count, + wakeup_source_data->wakeup_count, wakeup_source_data->expire_count, wakeup_source_data->active_since, + wakeup_source_data->total_time, wakeup_source_data->max_time, wakeup_source_data->last_change, + wakeup_source_data->prevent_suspend_time); + } + } else + fwts_log_info(fw, "No wakeup source found."); +} static void wakeup_source_cmp(fwts_framework *fw, fwts_list *suspend_source, fwts_list *resume_source) { @@ -144,7 +164,19 @@ static void wakeup_source_cmp(fwts_framework *fw, fwts_list *suspend_source, fwt wakeup_source *data2 = fwts_list_data(wakeup_source *, item2); if (data1->event_count < data2->event_count) { fwts_log_info_verbatim(fw, "wakeup source name: \"%s\" wakeup event was signaled.\n", data1->name); - + if (s3_wakeup_src) { + fwts_log_info_verbatim(fw, "%s %lu %lu %lu %lu %ld %ld %ld %ld %ld\n", + data1->name, data1->active_count, data1->event_count, + data1->wakeup_count, data1->expire_count, data1->active_since, + data1->total_time, data1->max_time, data1->last_change, + data1->prevent_suspend_time); + + fwts_log_info_verbatim(fw, "%s %lu %lu %lu %lu %ld %ld %ld %ld %ld\n", + data2->name, data2->active_count, data2->event_count, + data2->wakeup_count, data2->expire_count, data2->active_since, + data2->total_time, data2->max_time, data2->last_change, + data2->prevent_suspend_time); + } } item1 = fwts_list_next(item1); item2 = fwts_list_next(item2); @@ -455,6 +487,11 @@ static int s3_do_suspend_resume(fwts_framework *fw, if (wk_src_found) { if (read_wakeup_source(&resume_wakeup_soure) != FWTS_ERROR) { (void)wakeup_source_cmp(fw, &suspend_wakeup_soure, &resume_wakeup_soure); + if (s3_wakeup_src) { + (void)dump_wakeup_source(fw, &suspend_wakeup_soure); + fwts_log_info(fw, "versus after:"); + (void)dump_wakeup_source(fw, &resume_wakeup_soure); + } } } @@ -950,6 +987,9 @@ static int s3_options_handler(fwts_framework *fw, int argc, char * const argv[], case 12: s3_sleep_type = optarg; break; + case 13: + s3_wakeup_src = true; + break; } } return FWTS_OK; @@ -968,7 +1008,8 @@ static fwts_option s3_options[] = { { "s3-resume-time", "", 1, "Maximum expected resume time in seconds, e.g. --s3-resume-time=5.1" }, { "s3-hybrid", "", 0, "Run S3 with hybrid sleep, i.e. saving system states as S4 does." }, { "s3-resume-hook hook","", 1, "Run a hook script after each S3 resume, 0 exit indicates success." }, - { "s3-sleep-type" ,"", 1, "Set the sleep type for testing S3 or s2idle." }, + { "s3-sleep-type", "", 1, "Set the sleep type for testing S3 or s2idle." }, + { "s3-dump-wakeup-src", "", 0, "dump the all device wakeup sources suspend/resume.(For debug)"}, { NULL, NULL, 0, NULL } };