torture.c (8e8c668927b029f6ccc350eb1aa936864cc4eb6f) | torture.c (d95f5ba90fa6043a366958897fdef705af968b70) |
---|---|
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 * --- 68 unchanged lines hidden (view full) --- 77static int max_offline; 78static long n_online_attempts; 79static long n_online_successes; 80static unsigned long sum_online; 81static int min_online = -1; 82static int max_online; 83 84/* | 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 * --- 68 unchanged lines hidden (view full) --- 77static int max_offline; 78static long n_online_attempts; 79static long n_online_successes; 80static unsigned long sum_online; 81static int min_online = -1; 82static int max_online; 83 84/* |
85 * Attempt to take a CPU offline. Return false if the CPU is already 86 * offline or if it is not subject to CPU-hotplug operations. The 87 * caller can detect other failures by looking at the statistics. 88 */ 89bool torture_offline(int cpu, long *n_offl_attempts, long *n_offl_successes, 90 unsigned long *sum_offl, int *min_offl, int *max_offl) 91{ 92 unsigned long delta; 93 int ret; 94 unsigned long starttime; 95 96 if (!cpu_online(cpu) || !cpu_is_hotpluggable(cpu)) 97 return false; 98 99 if (verbose) 100 pr_alert("%s" TORTURE_FLAG 101 "torture_onoff task: offlining %d\n", 102 torture_type, cpu); 103 starttime = jiffies; 104 (*n_offl_attempts)++; 105 ret = cpu_down(cpu); 106 if (ret) { 107 if (verbose) 108 pr_alert("%s" TORTURE_FLAG 109 "torture_onoff task: offline %d failed: errno %d\n", 110 torture_type, cpu, ret); 111 } else { 112 if (verbose) 113 pr_alert("%s" TORTURE_FLAG 114 "torture_onoff task: offlined %d\n", 115 torture_type, cpu); 116 (*n_offl_successes)++; 117 delta = jiffies - starttime; 118 sum_offl += delta; 119 if (*min_offl < 0) { 120 *min_offl = delta; 121 *max_offl = delta; 122 } 123 if (*min_offl > delta) 124 *min_offl = delta; 125 if (*max_offl < delta) 126 *max_offl = delta; 127 } 128 129 return true; 130} 131EXPORT_SYMBOL_GPL(torture_offline); 132 133/* 134 * Attempt to bring a CPU online. Return false if the CPU is already 135 * online or if it is not subject to CPU-hotplug operations. The 136 * caller can detect other failures by looking at the statistics. 137 */ 138bool torture_online(int cpu, long *n_onl_attempts, long *n_onl_successes, 139 unsigned long *sum_onl, int *min_onl, int *max_onl) 140{ 141 unsigned long delta; 142 int ret; 143 unsigned long starttime; 144 145 if (cpu_online(cpu) || !cpu_is_hotpluggable(cpu)) 146 return false; 147 148 if (verbose) 149 pr_alert("%s" TORTURE_FLAG 150 "torture_onoff task: onlining %d\n", 151 torture_type, cpu); 152 starttime = jiffies; 153 (*n_onl_attempts)++; 154 ret = cpu_up(cpu); 155 if (ret) { 156 if (verbose) 157 pr_alert("%s" TORTURE_FLAG 158 "torture_onoff task: online %d failed: errno %d\n", 159 torture_type, cpu, ret); 160 } else { 161 if (verbose) 162 pr_alert("%s" TORTURE_FLAG 163 "torture_onoff task: onlined %d\n", 164 torture_type, cpu); 165 (*n_onl_successes)++; 166 delta = jiffies - starttime; 167 *sum_onl += delta; 168 if (*min_onl < 0) { 169 *min_onl = delta; 170 *max_onl = delta; 171 } 172 if (*min_onl > delta) 173 *min_onl = delta; 174 if (*max_onl < delta) 175 *max_onl = delta; 176 } 177 178 return true; 179} 180EXPORT_SYMBOL_GPL(torture_online); 181 182/* |
|
85 * Execute random CPU-hotplug operations at the interval specified 86 * by the onoff_interval. 87 */ 88static int 89torture_onoff(void *arg) 90{ 91 int cpu; | 183 * Execute random CPU-hotplug operations at the interval specified 184 * by the onoff_interval. 185 */ 186static int 187torture_onoff(void *arg) 188{ 189 int cpu; |
92 unsigned long delta; | |
93 int maxcpu = -1; 94 DEFINE_TORTURE_RANDOM(rand); | 190 int maxcpu = -1; 191 DEFINE_TORTURE_RANDOM(rand); |
95 int ret; 96 unsigned long starttime; | |
97 98 VERBOSE_TOROUT_STRING("torture_onoff task started"); 99 for_each_online_cpu(cpu) 100 maxcpu = cpu; 101 WARN_ON(maxcpu < 0); 102 if (onoff_holdoff > 0) { 103 VERBOSE_TOROUT_STRING("torture_onoff begin holdoff"); 104 schedule_timeout_interruptible(onoff_holdoff); 105 VERBOSE_TOROUT_STRING("torture_onoff end holdoff"); 106 } 107 while (!torture_must_stop()) { 108 cpu = (torture_random(&rand) >> 4) % (maxcpu + 1); | 192 193 VERBOSE_TOROUT_STRING("torture_onoff task started"); 194 for_each_online_cpu(cpu) 195 maxcpu = cpu; 196 WARN_ON(maxcpu < 0); 197 if (onoff_holdoff > 0) { 198 VERBOSE_TOROUT_STRING("torture_onoff begin holdoff"); 199 schedule_timeout_interruptible(onoff_holdoff); 200 VERBOSE_TOROUT_STRING("torture_onoff end holdoff"); 201 } 202 while (!torture_must_stop()) { 203 cpu = (torture_random(&rand) >> 4) % (maxcpu + 1); |
109 if (cpu_online(cpu) && cpu_is_hotpluggable(cpu)) { 110 if (verbose) 111 pr_alert("%s" TORTURE_FLAG 112 "torture_onoff task: offlining %d\n", 113 torture_type, cpu); 114 starttime = jiffies; 115 n_offline_attempts++; 116 ret = cpu_down(cpu); 117 if (ret) { 118 if (verbose) 119 pr_alert("%s" TORTURE_FLAG 120 "torture_onoff task: offline %d failed: errno %d\n", 121 torture_type, cpu, ret); 122 } else { 123 if (verbose) 124 pr_alert("%s" TORTURE_FLAG 125 "torture_onoff task: offlined %d\n", 126 torture_type, cpu); 127 n_offline_successes++; 128 delta = jiffies - starttime; 129 sum_offline += delta; 130 if (min_offline < 0) { 131 min_offline = delta; 132 max_offline = delta; 133 } 134 if (min_offline > delta) 135 min_offline = delta; 136 if (max_offline < delta) 137 max_offline = delta; 138 } 139 } else if (cpu_is_hotpluggable(cpu)) { 140 if (verbose) 141 pr_alert("%s" TORTURE_FLAG 142 "torture_onoff task: onlining %d\n", 143 torture_type, cpu); 144 starttime = jiffies; 145 n_online_attempts++; 146 ret = cpu_up(cpu); 147 if (ret) { 148 if (verbose) 149 pr_alert("%s" TORTURE_FLAG 150 "torture_onoff task: online %d failed: errno %d\n", 151 torture_type, cpu, ret); 152 } else { 153 if (verbose) 154 pr_alert("%s" TORTURE_FLAG 155 "torture_onoff task: onlined %d\n", 156 torture_type, cpu); 157 n_online_successes++; 158 delta = jiffies - starttime; 159 sum_online += delta; 160 if (min_online < 0) { 161 min_online = delta; 162 max_online = delta; 163 } 164 if (min_online > delta) 165 min_online = delta; 166 if (max_online < delta) 167 max_online = delta; 168 } 169 } | 204 if (!torture_offline(cpu, 205 &n_offline_attempts, &n_offline_successes, 206 &sum_offline, &min_offline, &max_offline)) 207 torture_online(cpu, 208 &n_online_attempts, &n_online_successes, 209 &sum_online, &min_online, &max_online); |
170 schedule_timeout_interruptible(onoff_interval); 171 } 172 torture_kthread_stopping("torture_onoff"); 173 return 0; 174} 175 176#endif /* #ifdef CONFIG_HOTPLUG_CPU */ 177 --- 567 unchanged lines hidden --- | 210 schedule_timeout_interruptible(onoff_interval); 211 } 212 torture_kthread_stopping("torture_onoff"); 213 return 0; 214} 215 216#endif /* #ifdef CONFIG_HOTPLUG_CPU */ 217 --- 567 unchanged lines hidden --- |