[PATCH] torture: use ktime_t consistently

Arnd Bergmann
2016-06-20T15:56:37Z

A recent change accidentally introduced a 64-bit division in torture_shutdown,
which fails to build on 32-bit architectures:

kernel/built-in.o: In function `torture_shutdown':
:(.text+0x4b29a): undefined reference to `__aeabi_uldivmod'

This converts the function to use ktime_t instead, which also simplifies
it a little.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Fixes: b4aa201e0c7c ("torture: Convert torture_shutdown() to hrtimer")
---
kernel/torture.c | 25 ++++++++++---------------
1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/kernel/torture.c b/kernel/torture.c
index 55f0a317fbb5..bbcc92088bf9 100644
--- a/kernel/torture.c
+++ b/kernel/torture.c
@@ -448,7 +448,7 @@ EXPORT_SYMBOL_GPL(torture_shuffle_cleanup);
*/
static int shutdown_secs; /* desired test duration in seconds. */
static struct task_struct *shutdown_task;
-static unsigned long shutdown_time; /* jiffies to system shutdown. */
+static ktime_t shutdown_time; /* time of system shutdown. */
static void (*torture_shutdown_hook)(void);

/*
@@ -471,24 +471,19 @@ EXPORT_SYMBOL_GPL(torture_shutdown_absorb);
*/
static int torture_shutdown(void *arg)
{
- unsigned long long delta;
- unsigned long jiffies_snap;
- ktime_t wait_duration;
+ ktime_t now, delta;

VERBOSE_TOROUT_STRING("torture_shutdown task started");
- jiffies_snap = jiffies;
- while (ULONG_CMP_LT(jiffies_snap, shutdown_time) &&
- !torture_must_stop()) {
- delta = shutdown_time - jiffies_snap;
+ now = ktime_get();
+ while (ktime_before(now, shutdown_time) && !torture_must_stop()) {
+ delta = ktime_sub(shutdown_time, now);
if (verbose)
pr_alert("%s" TORTURE_FLAG
- "torture_shutdown task: %llu jiffies remaining\n",
- torture_type, delta);
- delta = delta * 1000ULL * 1000ULL * 1000ULL / HZ;
- wait_duration = ns_to_ktime(delta);
+ "torture_shutdown task: %llu ms remaining\n",
+ torture_type, ktime_to_ms(delta));
set_current_state(TASK_INTERRUPTIBLE);
- schedule_hrtimeout(&wait_duration, HRTIMER_MODE_REL);
- jiffies_snap = jiffies;
+ schedule_hrtimeout(&delta, HRTIMER_MODE_REL);
+ now = ktime_get();
}
if (torture_must_stop()) {
torture_kthread_stopping("torture_shutdown");
@@ -518,7 +513,7 @@ int torture_shutdown_init(int ssecs, void (*cleanup)(void))
shutdown_secs = ssecs;
torture_shutdown_hook = cleanup;
if (shutdown_secs > 0) {
- shutdown_time = jiffies + shutdown_secs * HZ;
+ shutdown_time = ktime_add(ktime_get(), ktime_set(ssecs, 0));
ret = torture_create_kthread(torture_shutdown, NULL,
shutdown_task);
}
--
2.9.0