From patchwork Mon Jul 18 01:16:04 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 985342 Received: from smtp1.linux-foundation.org (smtp1.linux-foundation.org [140.211.169.13]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p6I1JukV022985 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Mon, 18 Jul 2011 01:20:17 GMT Received: from daredevil.linux-foundation.org (localhost [127.0.0.1]) by smtp1.linux-foundation.org (8.14.2/8.13.5/Debian-3ubuntu1.1) with ESMTP id p6I1IQsm019420; Sun, 17 Jul 2011 18:18:26 -0700 Received: from mail-pv0-f175.google.com (mail-pv0-f175.google.com [74.125.83.175]) by smtp1.linux-foundation.org (8.14.2/8.13.5/Debian-3ubuntu1.1) with ESMTP id p6I1EZjf018451 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=FAIL) for ; Sun, 17 Jul 2011 18:14:36 -0700 Received: by pvf24 with SMTP id 24so2573764pvf.6 for ; Sun, 17 Jul 2011 18:14:35 -0700 (PDT) Received: by 10.68.10.163 with SMTP id j3mr7152143pbb.3.1310951675094; Sun, 17 Jul 2011 18:14:35 -0700 (PDT) Received: from localhost.localdomain (p1095-adsao03yokonib2-acca.kanagawa.ocn.ne.jp [219.165.64.95]) by mx.google.com with ESMTPS id b4sm2215888pba.27.2011.07.17.18.14.32 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 17 Jul 2011 18:14:34 -0700 (PDT) From: Akinobu Mita To: linux-kernel@vger.kernel.org, akpm@linux-foundation.org Date: Mon, 18 Jul 2011 10:16:04 +0900 Message-Id: <1310951766-3840-4-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: <1310951766-3840-1-git-send-email-akinobu.mita@gmail.com> References: <1310951766-3840-1-git-send-email-akinobu.mita@gmail.com> Received-SPF: pass (localhost is always allowed.) X-Spam-Status: No, hits=-4.27 required=5 tests=AWL, BAYES_00, OSDL_HEADER_SPF_PASS, OSDL_HEADER_SUBJECT_BRACKETED X-Spam-Checker-Version: SpamAssassin 3.2.4-osdl_revision__1.47__ X-MIMEDefang-Filter: lf$Revision: 1.188 $ X-Scanned-By: MIMEDefang 2.63 on 140.211.169.21 Cc: linux-pm@lists.linux-foundation.org, Akinobu Mita Subject: [linux-pm] [PATCH v2 3/5] PM: PM notifier error injection X-BeenThere: linux-pm@lists.linux-foundation.org X-Mailman-Version: 2.1.9 Precedence: list List-Id: Linux power management List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-pm-bounces@lists.linux-foundation.org Errors-To: linux-pm-bounces@lists.linux-foundation.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 18 Jul 2011 01:20:17 +0000 (UTC) This provides the ability to inject artifical errors to PM notifier chain callbacks. It is controlled through debugfs interface under /sys/kernel/debug/pm-notifier-error-inject/ Each of the files in the directory represents an event which can be failed and contains the error code. If the notifier call chain should be failed with some events notified, write the error code to the files. Example: Inject PM suspend error (-12 = -ENOMEM) # cd /sys/kernel/debug/pm-notifier-error-inject # echo -12 > PM_SUSPEND_PREPARE # echo mem > /sys/power/state bash: echo: write error: Cannot allocate memory Signed-off-by: Akinobu Mita Cc: Pavel Machek Cc: "Rafael J. Wysocki" Cc: linux-pm@lists.linux-foundation.org --- * v2 - improve Kconfig help text - make CONFIG_PM_NOTIFIER_ERROR_INJECTION visible even if PM_DEBUG is disabled - make CONFIG_PM_NOTIFIER_ERROR_INJECTION default if PM_DEBUG is enabled kernel/power/main.c | 30 ++++++++++++++++++++++++++++++ lib/Kconfig.debug | 16 ++++++++++++++++ 2 files changed, 46 insertions(+), 0 deletions(-) diff --git a/kernel/power/main.c b/kernel/power/main.c index 6c601f8..04b3774 100644 --- a/kernel/power/main.c +++ b/kernel/power/main.c @@ -42,6 +42,36 @@ int pm_notifier_call_chain(unsigned long val) return notifier_to_errno(ret); } +#ifdef CONFIG_PM_NOTIFIER_ERROR_INJECTION + +static struct err_inject_notifier_block err_inject_pm_notifier = { + .actions = { + { ERR_INJECT_NOTIFIER_ACTION(PM_HIBERNATION_PREPARE) }, + { ERR_INJECT_NOTIFIER_ACTION(PM_SUSPEND_PREPARE) }, + { ERR_INJECT_NOTIFIER_ACTION(PM_RESTORE_PREPARE) }, + {} + } +}; + +static int __init err_inject_pm_notifier_init(void) +{ + int err; + + err = err_inject_notifier_block_init(&err_inject_pm_notifier, + "pm-notifier-error-inject", -1); + if (err) + return err; + + err = register_pm_notifier(&err_inject_pm_notifier.nb); + if (err) + err_inject_notifier_block_cleanup(&err_inject_pm_notifier); + + return err; +} +late_initcall(err_inject_pm_notifier_init); + +#endif /* CONFIG_PM_NOTIFIER_ERROR_INJECTION */ + /* If set, devices may be suspended and resumed asynchronously. */ int pm_async_enabled = 1; diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index d1bbedd..e5671ba 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -1049,6 +1049,22 @@ config CPU_NOTIFIER_ERROR_INJECTION # echo 0 > /sys/devices/system/cpu/cpu1/online bash: echo: write error: Operation not permitted +config PM_NOTIFIER_ERROR_INJECTION + bool "PM notifier error injection" + depends on PM && NOTIFIER_ERROR_INJECTION + default PM_DEBUG + help + This option provides the ability to inject artifical errors to + PM notifier chain callbacks. It is controlled through debugfs + interface. + + Example: Inject PM suspend error (-12 = -ENOMEM) + + # cd /sys/kernel/debug/pm-notifier-error-inject + # echo -12 > PM_SUSPEND_PREPARE + # echo mem > /sys/power/state + bash: echo: write error: Cannot allocate memory + config CPU_NOTIFIER_ERROR_INJECT tristate "CPU notifier error injection module" depends on HOTPLUG_CPU && DEBUG_KERNEL