From: Ido Yariv <ido@wizery.com>
To: Ohad Ben-Cohen <ohad@wizery.com>,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, linux-omap@vger.kernel.org
Cc: Ido Yariv <ido@wizery.com>
Subject: [PATCH] hwspinlock/core: Add testing capabilities
Date: Wed, 12 Dec 2012 22:27:06 +0200 [thread overview]
Message-ID: <1355344026-17222-1-git-send-email-ido@wizery.com> (raw)
Add testing capabilities for verifying correctness of the underlying
hwspinlock layers. This can be handy especially during development.
These tests are performed only once as part of the hwspinlock
registration.
Signed-off-by: Ido Yariv <ido@wizery.com>
---
drivers/hwspinlock/Kconfig | 9 +++++
drivers/hwspinlock/hwspinlock_core.c | 54 ++++++++++++++++++++++++++++++++++
2 files changed, 63 insertions(+), 0 deletions(-)
diff --git a/drivers/hwspinlock/Kconfig b/drivers/hwspinlock/Kconfig
index c7c3128..ad632cd 100644
--- a/drivers/hwspinlock/Kconfig
+++ b/drivers/hwspinlock/Kconfig
@@ -8,6 +8,15 @@ config HWSPINLOCK
menu "Hardware Spinlock drivers"
+config HWSPINLOCK_TEST
+ bool "Verify underlying hwspinlock implementation"
+ depends on HWSPINLOCK
+ help
+ Say Y here to perform tests on the underlying hwspinlock
+ implementation. The tests are only performed once per implementation.
+
+ Say N, unless you absolutely know what you are doing.
+
config HWSPINLOCK_OMAP
tristate "OMAP Hardware Spinlock device"
depends on ARCH_OMAP4
diff --git a/drivers/hwspinlock/hwspinlock_core.c b/drivers/hwspinlock/hwspinlock_core.c
index 085e28e..1874e85 100644
--- a/drivers/hwspinlock/hwspinlock_core.c
+++ b/drivers/hwspinlock/hwspinlock_core.c
@@ -307,6 +307,53 @@ out:
return hwlock;
}
+#ifdef CONFIG_HWSPINLOCK_TEST
+#define NUM_OF_TEST_ITERATIONS 100
+static int hwspin_lock_tests(const struct hwspinlock_ops *ops,
+ struct hwspinlock *hwlock)
+{
+ int i;
+ int ret;
+
+ for (i = 0; i < NUM_OF_TEST_ITERATIONS; i++) {
+ ret = ops->trylock(hwlock);
+ if (!ret) {
+ pr_err("%s: Initial lock failed\n", __func__);
+ return -EFAULT;
+ }
+
+ /* Verify lock actually works - re-acquiring it should fail */
+ ret = ops->trylock(hwlock);
+ if (ret) {
+ /* Keep locks balanced even in failure cases */
+ ops->unlock(hwlock);
+ ops->unlock(hwlock);
+ pr_err("%s: Recursive lock succeeded unexpectedly\n",
+ __func__);
+ return -EFAULT;
+ }
+
+ /* Verify unlock by re-acquiring the lock after releasing it */
+ ops->unlock(hwlock);
+ ret = ops->trylock(hwlock);
+ if (!ret) {
+ pr_err("%s: Unlock failed\n", __func__);
+ return -EINVAL;
+ }
+
+ ops->unlock(hwlock);
+ }
+
+ return 0;
+}
+#else /* CONFIG_HWSPINLOCK_TEST*/
+static int hwspin_lock_tests(const struct hwspinlock_ops *ops,
+ struct hwspinlock *hwlock)
+{
+ return 0;
+}
+#endif
+
/**
* hwspin_lock_register() - register a new hw spinlock device
* @bank: the hwspinlock device, which usually provides numerous hw locks
@@ -345,6 +392,13 @@ int hwspin_lock_register(struct hwspinlock_device *bank, struct device *dev,
spin_lock_init(&hwlock->lock);
hwlock->bank = bank;
+ ret = hwspin_lock_tests(ops, hwlock);
+ if (ret) {
+ pr_err("hwspinlock tests failed on lock %d\n",
+ base_id + i);
+ goto reg_failed;
+ }
+
ret = hwspin_lock_register_single(hwlock, base_id + i);
if (ret)
goto reg_failed;
--
1.7.7.6
next reply other threads:[~2012-12-12 20:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-12 20:27 Ido Yariv [this message]
-- strict thread matches above, loose matches on Subject: below --
2012-12-29 9:19 Re:[PATCH] hwspinlock/core: Add testing capabilities steve.zhan
2012-12-30 11:20 ` [PATCH] " Ido Yariv
2012-12-30 14:13 ` steve.zhan
2012-12-30 14:27 ` Ido Yariv
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1355344026-17222-1-git-send-email-ido@wizery.com \
--to=ido@wizery.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=ohad@wizery.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).