torture.c (1443ec850448d98005ffbd1539dceced1a754c42) torture.c (5268d95c06152dc73e673de284d128c76e9ce895)
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Common functions for in-kernel torture tests.
4 *
5 * Copyright (C) IBM Corporation, 2014
6 *
7 * Author: Paul E. McKenney <paulmck@linux.ibm.com>
8 * Based on kernel/rcu/torture.c.

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

716}
717
718/*
719 * Variables for stuttering, which means to periodically pause and
720 * restart testing in order to catch bugs that appear when load is
721 * suddenly applied to or removed from the system.
722 */
723static struct task_struct *stutter_task;
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Common functions for in-kernel torture tests.
4 *
5 * Copyright (C) IBM Corporation, 2014
6 *
7 * Author: Paul E. McKenney <paulmck@linux.ibm.com>
8 * Based on kernel/rcu/torture.c.

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

716}
717
718/*
719 * Variables for stuttering, which means to periodically pause and
720 * restart testing in order to catch bugs that appear when load is
721 * suddenly applied to or removed from the system.
722 */
723static struct task_struct *stutter_task;
724static int stutter_pause_test;
724static ktime_t stutter_till_abs_time;
725static int stutter;
726static int stutter_gap;
727
728/*
729 * Block until the stutter interval ends. This must be called periodically
730 * by all running kthreads that need to be subject to stuttering.
731 */
732bool stutter_wait(const char *title)
733{
725static int stutter;
726static int stutter_gap;
727
728/*
729 * Block until the stutter interval ends. This must be called periodically
730 * by all running kthreads that need to be subject to stuttering.
731 */
732bool stutter_wait(const char *title)
733{
734 unsigned int i = 0;
735 bool ret = false;
734 bool ret = false;
736 int spt;
735 ktime_t till_ns;
737
738 cond_resched_tasks_rcu_qs();
736
737 cond_resched_tasks_rcu_qs();
739 spt = READ_ONCE(stutter_pause_test);
740 for (; spt; spt = READ_ONCE(stutter_pause_test)) {
741 if (!ret && !rt_task(current)) {
742 sched_set_normal(current, MAX_NICE);
743 ret = true;
744 }
745 if (spt == 1) {
746 torture_hrtimeout_jiffies(1, NULL);
747 } else if (spt == 2) {
748 while (READ_ONCE(stutter_pause_test)) {
749 if (!(i++ & 0xffff))
750 torture_hrtimeout_us(10, 0, NULL);
751 cond_resched();
752 }
753 } else {
754 torture_hrtimeout_jiffies(round_jiffies_relative(HZ), NULL);
755 }
756 torture_shutdown_absorb(title);
738 till_ns = READ_ONCE(stutter_till_abs_time);
739 if (till_ns && ktime_before(ktime_get(), till_ns)) {
740 torture_hrtimeout_ns(till_ns, 0, HRTIMER_MODE_ABS, NULL);
741 ret = true;
757 }
742 }
743 torture_shutdown_absorb(title);
758 return ret;
759}
760EXPORT_SYMBOL_GPL(stutter_wait);
761
762/*
763 * Cause the torture test to "stutter", starting and stopping all
764 * threads periodically.
765 */
766static int torture_stutter(void *arg)
767{
744 return ret;
745}
746EXPORT_SYMBOL_GPL(stutter_wait);
747
748/*
749 * Cause the torture test to "stutter", starting and stopping all
750 * threads periodically.
751 */
752static int torture_stutter(void *arg)
753{
768 DEFINE_TORTURE_RANDOM(rand);
769 int wtime;
754 ktime_t till_ns;
770
771 VERBOSE_TOROUT_STRING("torture_stutter task started");
772 do {
773 if (!torture_must_stop() && stutter > 1) {
755
756 VERBOSE_TOROUT_STRING("torture_stutter task started");
757 do {
758 if (!torture_must_stop() && stutter > 1) {
774 wtime = stutter;
775 if (stutter > 2) {
776 WRITE_ONCE(stutter_pause_test, 1);
777 wtime = stutter - 3;
778 torture_hrtimeout_jiffies(wtime, &rand);
779 wtime = 2;
780 }
781 WRITE_ONCE(stutter_pause_test, 2);
782 torture_hrtimeout_jiffies(wtime, NULL);
759 till_ns = ktime_add_ns(ktime_get(),
760 jiffies_to_nsecs(stutter));
761 WRITE_ONCE(stutter_till_abs_time, till_ns);
762 torture_hrtimeout_jiffies(stutter - 1, NULL);
783 }
763 }
784 WRITE_ONCE(stutter_pause_test, 0);
785 if (!torture_must_stop())
786 torture_hrtimeout_jiffies(stutter_gap, NULL);
787 torture_shutdown_absorb("torture_stutter");
788 } while (!torture_must_stop());
789 torture_kthread_stopping("torture_stutter");
790 return 0;
791}
792

--- 180 unchanged lines hidden ---
764 if (!torture_must_stop())
765 torture_hrtimeout_jiffies(stutter_gap, NULL);
766 torture_shutdown_absorb("torture_stutter");
767 } while (!torture_must_stop());
768 torture_kthread_stopping("torture_stutter");
769 return 0;
770}
771

--- 180 unchanged lines hidden ---