151b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney/* 251b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney * Common functions for in-kernel torture tests. 351b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney * 451b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney * This program is free software; you can redistribute it and/or modify 551b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney * it under the terms of the GNU General Public License as published by 651b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney * the Free Software Foundation; either version 2 of the License, or 751b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney * (at your option) any later version. 851b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney * 951b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney * This program is distributed in the hope that it will be useful, 1051b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney * but WITHOUT ANY WARRANTY; without even the implied warranty of 1151b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1251b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney * GNU General Public License for more details. 1351b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney * 1451b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney * You should have received a copy of the GNU General Public License 1551b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney * along with this program; if not, you can access it online at 1651b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney * http://www.gnu.org/licenses/gpl-2.0.html. 1751b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney * 1851b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney * Copyright IBM Corporation, 2014 1951b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney * 2051b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney * Author: Paul E. McKenney <paulmck@linux.vnet.ibm.com> 2151b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney */ 2251b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney 2351b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney#ifndef __LINUX_TORTURE_H 2451b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney#define __LINUX_TORTURE_H 2551b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney 2651b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney#include <linux/types.h> 2751b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney#include <linux/cache.h> 2851b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney#include <linux/spinlock.h> 2951b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney#include <linux/threads.h> 3051b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney#include <linux/cpumask.h> 3151b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney#include <linux/seqlock.h> 3251b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney#include <linux/lockdep.h> 3351b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney#include <linux/completion.h> 3451b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney#include <linux/debugobjects.h> 3551b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney#include <linux/bug.h> 3651b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney#include <linux/compiler.h> 3751b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney 389e2502254132261e0ea8010692fd447b1cedf627Paul E. McKenney/* Definitions for a non-string torture-test module parameter. */ 399e2502254132261e0ea8010692fd447b1cedf627Paul E. McKenney#define torture_param(type, name, init, msg) \ 409e2502254132261e0ea8010692fd447b1cedf627Paul E. McKenney static type name = init; \ 419e2502254132261e0ea8010692fd447b1cedf627Paul E. McKenney module_param(name, type, 0444); \ 429e2502254132261e0ea8010692fd447b1cedf627Paul E. McKenney MODULE_PARM_DESC(name, msg); 439e2502254132261e0ea8010692fd447b1cedf627Paul E. McKenney 44c2884de38e01134ae040d55aa5644049d1bb850fPaul E. McKenney#define TORTURE_FLAG "-torture:" 45c2884de38e01134ae040d55aa5644049d1bb850fPaul E. McKenney#define TOROUT_STRING(s) \ 46c2884de38e01134ae040d55aa5644049d1bb850fPaul E. McKenney pr_alert("%s" TORTURE_FLAG s "\n", torture_type) 47c2884de38e01134ae040d55aa5644049d1bb850fPaul E. McKenney#define VERBOSE_TOROUT_STRING(s) \ 487fafaac5b9ce22cc57777865390520476ad2262dPaul E. McKenney do { if (verbose) pr_alert("%s" TORTURE_FLAG " %s\n", torture_type, s); } while (0) 49c2884de38e01134ae040d55aa5644049d1bb850fPaul E. McKenney#define VERBOSE_TOROUT_ERRSTRING(s) \ 5047cf29b9e721967aac95ebda9e50408219755852Paul E. McKenney do { if (verbose) pr_alert("%s" TORTURE_FLAG "!!! %s\n", torture_type, s); } while (0) 51c2884de38e01134ae040d55aa5644049d1bb850fPaul E. McKenney 522e9e8081d2e7a4efb582a240aa7fee991bbbabb0Paul E. McKenney/* Definitions for online/offline exerciser. */ 532e9e8081d2e7a4efb582a240aa7fee991bbbabb0Paul E. McKenneyint torture_onoff_init(long ooholdoff, long oointerval); 54eea203fea3484598280a07fe503e025e886297fbJoe Perchesvoid torture_onoff_stats(void); 552e9e8081d2e7a4efb582a240aa7fee991bbbabb0Paul E. McKenneybool torture_onoff_failures(void); 562e9e8081d2e7a4efb582a240aa7fee991bbbabb0Paul E. McKenney 579e2502254132261e0ea8010692fd447b1cedf627Paul E. McKenney/* Low-rider random number generator. */ 5851b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenneystruct torture_random_state { 5951b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney unsigned long trs_state; 6051b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney long trs_count; 6151b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney}; 6251b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney#define DEFINE_TORTURE_RANDOM(name) struct torture_random_state name = { 0, 0 } 6351b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenneyunsigned long torture_random(struct torture_random_state *trsp); 6451b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney 653808dc9fab05913060626d7f0edd0f195cb9dcabPaul E. McKenney/* Task shuffler, which causes CPUs to occasionally go idle. */ 663808dc9fab05913060626d7f0edd0f195cb9dcabPaul E. McKenneyvoid torture_shuffle_task_register(struct task_struct *tp); 673808dc9fab05913060626d7f0edd0f195cb9dcabPaul E. McKenneyint torture_shuffle_init(long shuffint); 683808dc9fab05913060626d7f0edd0f195cb9dcabPaul E. McKenney 69e991dbc0770b01b7dc7d6d7660442e83ebd11828Paul E. McKenney/* Test auto-shutdown handling. */ 70f67a33561e6e5463b548219df98130da95f2e4a7Paul E. McKenneyvoid torture_shutdown_absorb(const char *title); 71e991dbc0770b01b7dc7d6d7660442e83ebd11828Paul E. McKenneyint torture_shutdown_init(int ssecs, void (*cleanup)(void)); 72f67a33561e6e5463b548219df98130da95f2e4a7Paul E. McKenney 73628edaa5062282b6e3d76c886fd2cbccae5cb87bPaul E. McKenney/* Task stuttering, which forces load/no-load transitions. */ 74628edaa5062282b6e3d76c886fd2cbccae5cb87bPaul E. McKenneyvoid stutter_wait(const char *title); 75628edaa5062282b6e3d76c886fd2cbccae5cb87bPaul E. McKenneyint torture_stutter_init(int s); 76628edaa5062282b6e3d76c886fd2cbccae5cb87bPaul E. McKenney 77b5daa8f3b3b2b0133ad40e13d4f722070119ce36Paul E. McKenney/* Initialization and cleanup. */ 785228084eed8d54c426c7abde3be66daf8e1b0e57Paul E. McKenneybool torture_init_begin(char *ttype, bool v, int *runnable); 79b5daa8f3b3b2b0133ad40e13d4f722070119ce36Paul E. McKenneyvoid torture_init_end(void); 80d36a7a0d5e8b5bff1671723d733eb61621b0cee4Davidlohr Buesobool torture_cleanup_begin(void); 81d36a7a0d5e8b5bff1671723d733eb61621b0cee4Davidlohr Buesovoid torture_cleanup_end(void); 8236970bb91d89618d3495babf44b934e9c9db6bbcPaul E. McKenneybool torture_must_stop(void); 8336970bb91d89618d3495babf44b934e9c9db6bbcPaul E. McKenneybool torture_must_stop_irq(void); 847fafaac5b9ce22cc57777865390520476ad2262dPaul E. McKenneyvoid torture_kthread_stopping(char *title); 8547cf29b9e721967aac95ebda9e50408219755852Paul E. McKenneyint _torture_create_kthread(int (*fn)(void *arg), void *arg, char *s, char *m, 8647cf29b9e721967aac95ebda9e50408219755852Paul E. McKenney char *f, struct task_struct **tp); 879c029b86098decd4660eec511b8d2d42da3e7dd9Paul E. McKenneyvoid _torture_stop_kthread(char *m, struct task_struct **tp); 8847cf29b9e721967aac95ebda9e50408219755852Paul E. McKenney 8947cf29b9e721967aac95ebda9e50408219755852Paul E. McKenney#define torture_create_kthread(n, arg, tp) \ 9047cf29b9e721967aac95ebda9e50408219755852Paul E. McKenney _torture_create_kthread(n, (arg), #n, "Creating " #n " task", \ 9147cf29b9e721967aac95ebda9e50408219755852Paul E. McKenney "Failed to create " #n, &(tp)) 929c029b86098decd4660eec511b8d2d42da3e7dd9Paul E. McKenney#define torture_stop_kthread(n, tp) \ 939c029b86098decd4660eec511b8d2d42da3e7dd9Paul E. McKenney _torture_stop_kthread("Stopping " #n " task", &(tp)) 94b5daa8f3b3b2b0133ad40e13d4f722070119ce36Paul E. McKenney 9551b1130eb5823ddb90a9ad07d243031d8cb7ecf2Paul E. McKenney#endif /* __LINUX_TORTURE_H */ 96