Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp1608001imp; Fri, 22 Feb 2019 07:05:56 -0800 (PST) X-Google-Smtp-Source: AHgI3IZfTcu7Ms9hY3plY3NtdsNcrKwplm5fY99EdMoGWNJiJWndm1TAwkip3LsP2A79ldV9tMbW X-Received: by 2002:a63:4924:: with SMTP id w36mr985929pga.227.1550847956899; Fri, 22 Feb 2019 07:05:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550847956; cv=none; d=google.com; s=arc-20160816; b=0kJa3ROe/bF5ozdQeKVuTges3gjsK6BLa9EA67oPtl0f/65kO40M1ya7cJCEwURKNC Z+4WE9HlTinZulK8a19md6gLVjhfHUk6nlDrXxkI7YpNjR8bs2OZ/h797mUCSDYA4VXN 6OysRdEOppfIH8OvOrOBhp6EANhY4pjCxwdjeqQRoi8N1B2KjvkPVox1FPmBtLRbqJhe 0cEz1iRXawRZMvIem/gtNZr0W6XtNJzrHB8PShY+7MYZGHWtmPaeQjvNvTQferZmBs0K NXNL5+Inq9z5agGRWyZowtEDDs+DC0oaZQfyr96OExJiHdQ2i6K/Tx4Iry//0okhcAKg aWZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=bs41C6e40jW6DBJcFUsoYh0Y0vb2m23Z1UbNF13hplk=; b=V7JTLUEkSLyr4oU/cGCZrsDYxGGHyESC51YGPNoog9RgPoCtB9qcXIMMA2D2WzNXh1 lAKXFQ3Smfaf4NYfp4UYSTh8I3ekdzbeM1DyGrwki+7eQscUZbzEVdbCFxhoT8olLwn7 2om6j5R/zHLlLTBYHrZT5J3L57JZJ14yKu5Gp0l57mohny1d2/U1YoJKCx5CmHI0S8EL sh/87ItRJRHQ7YAuAM5AjlCou11Z8CHxweMZ47M11dfXzmGRGFKjqhhwhdgRIuXFAzHk jOqlP3W7nk9WIYcBy+3gtCVbhlscD8voEm0vmSRIN2oT8V3PeiS9aL1O7fd/1GJBHo8u mC5A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z3si1552402plb.35.2019.02.22.07.05.40; Fri, 22 Feb 2019 07:05:56 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727349AbfBVPEw (ORCPT + 99 others); Fri, 22 Feb 2019 10:04:52 -0500 Received: from 61-228-50-252.dynamic-ip.hinet.net ([61.228.50.252]:48592 "EHLO E6440.gar.corp.intel.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726352AbfBVPEu (ORCPT ); Fri, 22 Feb 2019 10:04:50 -0500 X-Greylist: delayed 598 seconds by postgrey-1.27 at vger.kernel.org; Fri, 22 Feb 2019 10:04:49 EST Received: from E6440.gar.corp.intel.com (localhost [127.0.0.1]) by E6440.gar.corp.intel.com (Postfix) with ESMTP id BBCC8C0358; Fri, 22 Feb 2019 22:54:49 +0800 (CST) From: Harry Pan To: LKML Cc: gs0622@gmail.com, Harry Pan , rjw@rjwysocki.net, pavel@ucw.cz, len.brown@intel.com, linux-pm@vger.kernel.org Subject: [PATCH v5] PM / sleep: measure the time of filesystem syncing Date: Fri, 22 Feb 2019 22:54:45 +0800 Message-Id: <20190222145445.12360-1-harry.pan@intel.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20190220161840.994-1-harry.pan@intel.com> References: <20190220161840.994-1-harry.pan@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch gives the reader an intuitive metric of the time cost by the kernel issuing a filesystem sync during system sleep; although developer can guess by the timestamp of next log or enable the ftrace power event for manual calculation, this manner is easier to read and benefits the automatic script. v2: simplify the variables, apply the simplest form of ktime API. v3: reduce conditional compilation, rectify profiling in better syntax v4: avoid interposition, profile on hibernation, rectify printk format v5: introduce sync helper shared by suspend, hibernate, and snapshot Signed-off-by: Harry Pan --- include/linux/suspend.h | 3 +++ kernel/power/hibernate.c | 4 +--- kernel/power/main.c | 15 +++++++++++++++ kernel/power/suspend.c | 13 +++++-------- kernel/power/user.c | 4 +--- 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/include/linux/suspend.h b/include/linux/suspend.h index 3f529ad9a9d2..6b3ea9ea6a9e 100644 --- a/include/linux/suspend.h +++ b/include/linux/suspend.h @@ -425,6 +425,7 @@ void restore_processor_state(void); /* kernel/power/main.c */ extern int register_pm_notifier(struct notifier_block *nb); extern int unregister_pm_notifier(struct notifier_block *nb); +extern void ksys_sync_helper(void); #define pm_notifier(fn, pri) { \ static struct notifier_block fn##_nb = \ @@ -462,6 +463,8 @@ static inline int unregister_pm_notifier(struct notifier_block *nb) return 0; } +static inline void ksys_sync_helper(void) {} + #define pm_notifier(fn, pri) do { (void)(fn); } while (0) static inline bool pm_wakeup_pending(void) { return false; } diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c index abef759de7c8..895f43a5f10c 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c @@ -709,9 +709,7 @@ int hibernate(void) goto Exit; } - pr_info("Syncing filesystems ... \n"); - ksys_sync(); - pr_info("done.\n"); + ksys_sync_helper(); error = freeze_processes(); if (error) diff --git a/kernel/power/main.c b/kernel/power/main.c index 35b50823d83b..a08dcc743f31 100644 --- a/kernel/power/main.c +++ b/kernel/power/main.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "power.h" @@ -51,6 +52,20 @@ void unlock_system_sleep(void) } EXPORT_SYMBOL_GPL(unlock_system_sleep); +void ksys_sync_helper(void) +{ + ktime_t start; + s64 elapsed_msecs; + + start = ktime_get(); + ksys_sync(); + elapsed_msecs = ktime_to_ms(ktime_sub(ktime_get(), start)); + pr_info("Filesystems sync: %lld.%03lld seconds\n", + elapsed_msecs / MSEC_PER_SEC, + elapsed_msecs % MSEC_PER_SEC); +} +EXPORT_SYMBOL_GPL(ksys_sync_helper); + /* Routines for PM-transition notifications */ static BLOCKING_NOTIFIER_HEAD(pm_chain_head); diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c index 0bd595a0b610..e39059dea38b 100644 --- a/kernel/power/suspend.c +++ b/kernel/power/suspend.c @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -568,13 +567,11 @@ static int enter_state(suspend_state_t state) if (state == PM_SUSPEND_TO_IDLE) s2idle_begin(); -#ifndef CONFIG_SUSPEND_SKIP_SYNC - trace_suspend_resume(TPS("sync_filesystems"), 0, true); - pr_info("Syncing filesystems ... "); - ksys_sync(); - pr_cont("done.\n"); - trace_suspend_resume(TPS("sync_filesystems"), 0, false); -#endif + if (!IS_ENABLED(CONFIG_SUSPEND_SKIP_SYNC)) { + trace_suspend_resume(TPS("sync_filesystems"), 0, true); + ksys_sync_helper(); + trace_suspend_resume(TPS("sync_filesystems"), 0, false); + } pm_pr_dbg("Preparing system for sleep (%s)\n", mem_sleep_labels[state]); pm_suspend_clear_flags(); diff --git a/kernel/power/user.c b/kernel/power/user.c index 2d8b60a3c86b..68dbd9eac8e1 100644 --- a/kernel/power/user.c +++ b/kernel/power/user.c @@ -228,9 +228,7 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd, if (data->frozen) break; - printk("Syncing filesystems ... "); - ksys_sync(); - printk("done.\n"); + ksys_sync_helper(); error = freeze_processes(); if (error) -- 2.18.1