torture.c (57a2fe90fcdaa812ac1aa6c91ba0e591c30f461a) torture.c (e991dbc0770b01b7dc7d6d7660442e83ebd11828)
1/*
2 * Common functions for in-kernel torture tests.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *

--- 405 unchanged lines hidden (view full) ---

414 kthread_stop(shuffler_task);
415 free_cpumask_var(shuffle_tmp_mask);
416 }
417 shuffler_task = NULL;
418}
419EXPORT_SYMBOL_GPL(torture_shuffle_cleanup);
420
421/*
1/*
2 * Common functions for in-kernel torture tests.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *

--- 405 unchanged lines hidden (view full) ---

414 kthread_stop(shuffler_task);
415 free_cpumask_var(shuffle_tmp_mask);
416 }
417 shuffler_task = NULL;
418}
419EXPORT_SYMBOL_GPL(torture_shuffle_cleanup);
420
421/*
422 * Variables for auto-shutdown. This allows "lights out" torture runs
423 * to be fully scripted.
424 */
425static int shutdown_secs; /* desired test duration in seconds. */
426static struct task_struct *shutdown_task;
427static unsigned long shutdown_time; /* jiffies to system shutdown. */
428static void (*torture_shutdown_hook)(void);
429
430/*
422 * Absorb kthreads into a kernel function that won't return, so that
423 * they won't ever access module text or data again.
424 */
425void torture_shutdown_absorb(const char *title)
426{
427 while (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
428 pr_notice("torture thread %s parking due to system shutdown\n",
429 title);
430 schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT);
431 }
432}
433EXPORT_SYMBOL_GPL(torture_shutdown_absorb);
434
435/*
431 * Absorb kthreads into a kernel function that won't return, so that
432 * they won't ever access module text or data again.
433 */
434void torture_shutdown_absorb(const char *title)
435{
436 while (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
437 pr_notice("torture thread %s parking due to system shutdown\n",
438 title);
439 schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT);
440 }
441}
442EXPORT_SYMBOL_GPL(torture_shutdown_absorb);
443
444/*
445 * Cause the torture test to shutdown the system after the test has
446 * run for the time specified by the shutdown_secs parameter.
447 */
448static int torture_shutdown(void *arg)
449{
450 long delta;
451 unsigned long jiffies_snap;
452
453 VERBOSE_TOROUT_STRING("torture_shutdown task started");
454 jiffies_snap = jiffies;
455 while (ULONG_CMP_LT(jiffies_snap, shutdown_time) &&
456 !torture_must_stop()) {
457 delta = shutdown_time - jiffies_snap;
458 if (verbose)
459 pr_alert("%s" TORTURE_FLAG
460 "torture_shutdown task: %lu jiffies remaining\n",
461 torture_type, delta);
462 schedule_timeout_interruptible(delta);
463 jiffies_snap = jiffies;
464 }
465 if (torture_must_stop()) {
466 VERBOSE_TOROUT_STRING("torture_shutdown task stopping");
467 return 0;
468 }
469
470 /* OK, shut down the system. */
471
472 VERBOSE_TOROUT_STRING("torture_shutdown task shutting down system");
473 shutdown_task = NULL; /* Avoid self-kill deadlock. */
474 torture_shutdown_hook();/* Shut down the enclosing torture test. */
475 kernel_power_off(); /* Shut down the system. */
476 return 0;
477}
478
479/*
480 * Start up the shutdown task.
481 */
482int torture_shutdown_init(int ssecs, void (*cleanup)(void))
483{
484 int ret;
485
486 shutdown_secs = ssecs;
487 torture_shutdown_hook = cleanup;
488 if (shutdown_secs > 0) {
489 shutdown_time = jiffies + shutdown_secs * HZ;
490 shutdown_task = kthread_create(torture_shutdown, NULL,
491 "torture_shutdown");
492 if (IS_ERR(shutdown_task)) {
493 ret = PTR_ERR(shutdown_task);
494 VERBOSE_TOROUT_ERRSTRING("Failed to create shutdown");
495 shutdown_task = NULL;
496 return ret;
497 }
498 torture_shuffle_task_register(shutdown_task);
499 wake_up_process(shutdown_task);
500 }
501 return 0;
502}
503EXPORT_SYMBOL_GPL(torture_shutdown_init);
504
505/*
506 * Shut down the shutdown task. Say what??? Heh! This can happen if
507 * the torture module gets an rmmod before the shutdown time arrives. ;-)
508 */
509void torture_shutdown_cleanup(void)
510{
511 if (shutdown_task != NULL) {
512 VERBOSE_TOROUT_STRING("Stopping torture_shutdown task");
513 kthread_stop(shutdown_task);
514 }
515 shutdown_task = NULL;
516}
517EXPORT_SYMBOL_GPL(torture_shutdown_cleanup);
518
519/*
436 * Detect and respond to a system shutdown.
437 */
438static int torture_shutdown_notify(struct notifier_block *unused1,
439 unsigned long unused2, void *unused3)
440{
441 mutex_lock(&fullstop_mutex);
442 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
443 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");

--- 167 unchanged lines hidden ---
520 * Detect and respond to a system shutdown.
521 */
522static int torture_shutdown_notify(struct notifier_block *unused1,
523 unsigned long unused2, void *unused3)
524{
525 mutex_lock(&fullstop_mutex);
526 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
527 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");

--- 167 unchanged lines hidden ---