"Fossies" - the Fresh Open Source Software Archive

Member "stress-ng-0.09.56/stress-ng.c" (15 Mar 2019, 133144 Bytes) of package /linux/privat/stress-ng-0.09.56.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "stress-ng.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 0.09.55_vs_0.09.56.

    1 /*
    2  * Copyright (C) 2013-2019 Canonical, Ltd.
    3  *
    4  * This program is free software; you can redistribute it and/or
    5  * modify it under the terms of the GNU General Public License
    6  * as published by the Free Software Foundation; either version 2
    7  * of the License, or (at your option) any later version.
    8  *
    9  * This program is distributed in the hope that it will be useful,
   10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12  * GNU General Public License for more details.
   13  *
   14  * You should have received a copy of the GNU General Public License
   15  * along with this program; if not, write to the Free Software
   16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
   17  *
   18  * This code is a complete clean re-write of the stress tool by
   19  * Colin Ian King <colin.king@canonical.com> and attempts to be
   20  * backwardly compatible with the stress tool by Amos Waterland
   21  * <apw@rossby.metr.ou.edu> but has more stress tests and more
   22  * functionality.
   23  *
   24  */
   25 #include "stress-ng.h"
   26 
   27 /* Help information for options */
   28 typedef struct {
   29     const char *opt_s;      /* short option */
   30     const char *opt_l;      /* long option */
   31     const char *description;    /* description */
   32 } help_t;
   33 
   34 typedef struct {
   35     const int opt;          /* optarg option */
   36     const uint64_t opt_flag;    /* global options flag bit setting */
   37 } opt_flag_t;
   38 
   39 typedef struct {
   40     const int opt;              /* optarg option*/
   41     int (*opt_set_func)(const char *optarg); /* function to set it */
   42 } opt_set_func_t;
   43 
   44 /* Per stressor process information */
   45 static proc_info_t *procs_head, *procs_tail;
   46 proc_info_t *proc_current;
   47 
   48 /* Various option settings and flags */
   49 static volatile bool wait_flag = true;      /* false = exit run wait loop */
   50 static int terminate_signum;            /* signal sent to process */
   51 
   52 /* Globals */
   53 int32_t g_opt_sequential = DEFAULT_SEQUENTIAL;  /* # of sequential stressors */
   54 int32_t g_opt_parallel = DEFAULT_PARALLEL;  /* # of parallel stressors */
   55 uint64_t g_opt_timeout = TIMEOUT_NOT_SET;   /* timeout in seconds */
   56 uint64_t g_opt_flags = PR_ERROR | PR_INFO | OPT_FLAGS_MMAP_MADVISE;
   57 volatile bool g_keep_stressing_flag = true; /* false to exit stressor */
   58 volatile bool g_caught_sigint = false;      /* true if stopped by SIGINT */
   59 pid_t g_pgrp;                   /* process group leader */
   60 const char *g_app_name = "stress-ng";       /* Name of application */
   61 shared_t *g_shared;             /* shared memory */
   62 jmp_buf g_error_env;                /* parsing error env */
   63 put_val_t g_put_val;                /* sync data to somewhere */
   64 bool g_unsupported = false;         /* true if stressors are unsupported */
   65 
   66 /*
   67  *  optarg option to global setting option flags
   68  */
   69 static const opt_flag_t opt_flags[] = {
   70     { OPT_abort,        OPT_FLAGS_ABORT },
   71     { OPT_affinity_rand,    OPT_FLAGS_AFFINITY_RAND },
   72     { OPT_aggressive,   OPT_FLAGS_AGGRESSIVE_MASK },
   73     { OPT_brk_notouch,  OPT_FLAGS_BRK_NOTOUCH },
   74     { OPT_cache_prefetch,   OPT_FLAGS_CACHE_PREFETCH },
   75     { OPT_cache_flush,  OPT_FLAGS_CACHE_FLUSH },
   76     { OPT_cache_fence,  OPT_FLAGS_CACHE_FENCE },
   77     { OPT_cache_no_affinity, OPT_FLAGS_CACHE_NOAFF },
   78     { OPT_cpu_online_all,   OPT_FLAGS_CPU_ONLINE_ALL },
   79     { OPT_dry_run,      OPT_FLAGS_DRY_RUN },
   80     { OPT_ignite_cpu,   OPT_FLAGS_IGNITE_CPU },
   81     { OPT_keep_name,    OPT_FLAGS_KEEP_NAME },
   82     { OPT_lockf_nonblock,   OPT_FLAGS_LOCKF_NONBLK },
   83     { OPT_log_brief,    OPT_FLAGS_LOG_BRIEF },
   84     { OPT_maximize,     OPT_FLAGS_MAXIMIZE },
   85     { OPT_metrics,      OPT_FLAGS_METRICS },
   86     { OPT_metrics_brief,    OPT_FLAGS_METRICS_BRIEF | OPT_FLAGS_METRICS },
   87     { OPT_mincore_rand,     OPT_FLAGS_MINCORE_RAND },
   88     { OPT_minimize,     OPT_FLAGS_MINIMIZE },
   89     { OPT_mmap_async,   OPT_FLAGS_MMAP_FILE | OPT_FLAGS_MMAP_ASYNC },
   90     { OPT_mmap_file,    OPT_FLAGS_MMAP_FILE },
   91     { OPT_mmap_mprotect,    OPT_FLAGS_MMAP_MPROTECT },
   92     { OPT_no_rand_seed, OPT_FLAGS_NO_RAND_SEED },
   93     { OPT_oomable,      OPT_FLAGS_OOMABLE },
   94     { OPT_page_in,      OPT_FLAGS_MMAP_MINCORE },
   95     { OPT_pathological, OPT_FLAGS_PATHOLOGICAL },
   96 #if defined(STRESS_PERF_STATS) && defined(HAVE_LINUX_PERF_EVENT_H)
   97     { OPT_perf_stats,   OPT_FLAGS_PERF_STATS },
   98 #endif
   99     { OPT_seek_punch,   OPT_FLAGS_SEEK_PUNCH },
  100     { OPT_stack_fill,   OPT_FLAGS_STACK_FILL },
  101     { OPT_sock_nodelay, OPT_FLAGS_SOCKET_NODELAY },
  102 #if defined(HAVE_SYSLOG_H)
  103     { OPT_syslog,       OPT_FLAGS_SYSLOG },
  104 #endif
  105     { OPT_thrash,       OPT_FLAGS_THRASH },
  106     { OPT_timer_rand,   OPT_FLAGS_TIMER_RAND },
  107     { OPT_timer_slack,  OPT_FLAGS_TIMER_SLACK },
  108     { OPT_timerfd_rand, OPT_FLAGS_TIMERFD_RAND },
  109     { OPT_times,        OPT_FLAGS_TIMES },
  110     { OPT_timestamp,    OPT_FLAGS_TIMESTAMP },
  111     { OPT_thermal_zones,    OPT_FLAGS_THERMAL_ZONES },
  112     { OPT_udp_lite,     OPT_FLAGS_UDP_LITE },
  113     { OPT_utime_fsync,  OPT_FLAGS_UTIME_FSYNC },
  114     { OPT_verbose,      PR_ALL },
  115     { OPT_verify,       OPT_FLAGS_VERIFY | PR_FAIL },
  116     { OPT_vm_keep,      OPT_FLAGS_VM_KEEP },
  117 };
  118 
  119 /*
  120  *  optarg option to stressor setting options
  121  */
  122 static const opt_set_func_t opt_set_funcs[] = {
  123     { OPT_aio_requests,     stress_set_aio_requests },
  124     { OPT_aiol_requests,        stress_set_aio_linux_requests },
  125     { OPT_bigheap_growth,       stress_set_bigheap_growth },
  126     { OPT_bsearch_size,     stress_set_bsearch_size },
  127     { OPT_chdir_dirs,       stress_set_chdir_dirs },
  128     { OPT_clone_max,        stress_set_clone_max },
  129     { OPT_copy_file_bytes,      stress_set_copy_file_bytes },
  130     { OPT_cpu_load,         stress_set_cpu_load },
  131     { OPT_cpu_load_slice,       stress_set_cpu_load_slice },
  132     { OPT_cpu_method,       stress_set_cpu_method },
  133     { OPT_cyclic_dist,      stress_set_cyclic_dist },
  134     { OPT_cyclic_method,        stress_set_cyclic_method },
  135     { OPT_cyclic_policy,        stress_set_cyclic_policy },
  136     { OPT_cyclic_prio,      stress_set_cyclic_prio },
  137     { OPT_cyclic_sleep,     stress_set_cyclic_sleep },
  138     { OPT_dccp_domain,      stress_set_dccp_domain },
  139     { OPT_dccp_opts,        stress_set_dccp_opts },
  140     { OPT_dccp_port,        stress_set_dccp_port },
  141     { OPT_dentries,         stress_set_dentries },
  142     { OPT_dentry_order,     stress_set_dentry_order },
  143     { OPT_dir_dirs,         stress_set_dir_dirs },
  144     { OPT_dirdeep_dirs,         stress_set_dirdeep_dirs },
  145     { OPT_dirdeep_inodes,       stress_set_dirdeep_inodes },
  146     { OPT_epoll_domain,     stress_set_epoll_domain },
  147     { OPT_epoll_port,       stress_set_epoll_port },
  148     { OPT_exec_max,         stress_set_exec_max },
  149     { OPT_fallocate_bytes,      stress_set_fallocate_bytes },
  150     { OPT_fiemap_bytes,     stress_set_fiemap_bytes },
  151     { OPT_fifo_readers,     stress_set_fifo_readers },
  152     { OPT_filename_opts,        stress_set_filename_opts },
  153     { OPT_fork_max,         stress_set_fork_max },
  154     { OPT_fstat_dir,        stress_set_fstat_dir },
  155     { OPT_funccall_method,      stress_set_funccall_method },
  156     { OPT_hdd_bytes,        stress_set_hdd_bytes },
  157     { OPT_hdd_opts,         stress_set_hdd_opts },
  158     { OPT_hdd_write_size,       stress_set_hdd_write_size },
  159     { OPT_heapsort_integers,    stress_set_heapsort_size },
  160     { OPT_hsearch_size,     stress_set_hsearch_size },
  161     { OPT_iomix_bytes,      stress_set_iomix_bytes },
  162     { OPT_ioport_opts,      stress_set_ioport_opts },
  163     { OPT_itimer_freq,      stress_set_itimer_freq },
  164     { OPT_lease_breakers,       stress_set_lease_breakers },
  165     { OPT_lsearch_size,     stress_set_lsearch_size },
  166     { OPT_malloc_bytes,     stress_set_malloc_bytes },
  167     { OPT_malloc_max,       stress_set_malloc_max },
  168     { OPT_malloc_threshold,     stress_set_malloc_threshold },
  169 #if defined(HAVE_VLA_ARG)
  170     { OPT_matrix_method,        stress_set_matrix_method },
  171     { OPT_matrix_size,      stress_set_matrix_size },
  172     { OPT_matrix_yx,        stress_set_matrix_yx },
  173 #if !defined(__PCC__)
  174     { OPT_matrix_3d_method,     stress_set_matrix_3d_method },
  175     { OPT_matrix_3d_size,       stress_set_matrix_3d_size },
  176     { OPT_matrix_3d_zyx,        stress_set_matrix_3d_zyx },
  177 #endif
  178 #endif
  179     { OPT_memcpy_method,        stress_set_memcpy_method },
  180     { OPT_memfd_bytes,      stress_set_memfd_bytes },
  181     { OPT_memfd_fds,        stress_set_memfd_fds },
  182     { OPT_memrate_bytes,        stress_set_memrate_bytes },
  183     { OPT_memrate_rd_mbs,       stress_set_memrate_rd_mbs },
  184     { OPT_memrate_wr_mbs,       stress_set_memrate_wr_mbs },
  185     { OPT_memthrash_method,     stress_set_memthrash_method },
  186     { OPT_mergesort_integers,   stress_set_mergesort_size },
  187     { OPT_mmap_bytes,       stress_set_mmap_bytes },
  188     { OPT_mq_size,          stress_set_mq_size },
  189     { OPT_mremap_bytes,     stress_set_mremap_bytes },
  190     { OPT_msync_bytes,      stress_set_msync_bytes },
  191     { OPT_opcode_method,        stress_set_opcode_method },
  192     { OPT_pipe_data_size,       stress_set_pipe_data_size },
  193 #if defined(F_SETPIPE_SZ)
  194     { OPT_pipe_size,        stress_set_pipe_size },
  195 #endif
  196     { OPT_pthread_max,      stress_set_pthread_max },
  197     { OPT_pty_max,          stress_set_pty_max },
  198     { OPT_qsort_integers,       stress_set_qsort_size },
  199     { OPT_radixsort_size,       stress_set_radixsort_size },
  200     { OPT_rawdev_method,        stress_set_rawdev_method },
  201     { OPT_readahead_bytes,      stress_set_readahead_bytes },
  202     { OPT_revio_bytes,      stress_set_revio_bytes },
  203     { OPT_revio_opts,       stress_set_revio_opts },
  204     { OPT_sctp_port,        stress_set_sctp_port },
  205     { OPT_seek_size,        stress_set_seek_size },
  206     { OPT_sem_procs,        stress_set_semaphore_posix_procs },
  207     { OPT_sem_sysv_procs,       stress_set_semaphore_sysv_procs },
  208     { OPT_sendfile_size,        stress_set_sendfile_size },
  209     { OPT_shm_bytes,        stress_set_shm_posix_bytes },
  210     { OPT_shm_objects,      stress_set_shm_posix_objects },
  211     { OPT_shm_bytes,        stress_set_shm_sysv_bytes },
  212     { OPT_shm_sysv_segments,    stress_set_shm_sysv_segments },
  213     { OPT_sleep_max,        stress_set_sleep_max },
  214     { OPT_sock_domain,      stress_set_socket_domain },
  215     { OPT_sock_opts,        stress_set_socket_opts },
  216     { OPT_sock_type,        stress_set_socket_type },
  217     { OPT_stream_madvise,       stress_set_stream_madvise },
  218     { OPT_str_method,       stress_set_str_method },
  219     { OPT_switch_freq,      stress_set_switch_freq },
  220     { OPT_taskset,          stress_set_cpu_affinity },
  221     { OPT_temp_path,        stress_set_temp_path },
  222     { OPT_timer_freq,       stress_set_timer_freq },
  223     { OPT_timer_slack,      stress_set_timer_slack_ns },
  224     { OPT_timerfd_freq,     stress_set_timerfd_freq },
  225     { OPT_tree_method,      stress_set_tree_method },
  226     { OPT_tree_size,        stress_set_tree_size },
  227     { OPT_tsearch_size,     stress_set_tsearch_size },
  228     { OPT_udp_domain,       stress_set_udp_domain },
  229     { OPT_udp_port,         stress_set_udp_port },
  230     { OPT_udp_flood_domain,     stress_set_udp_flood_domain },
  231     { OPT_userfaultfd_bytes,    stress_set_userfaultfd_bytes },
  232     { OPT_vdso_func,        stress_set_vdso_func },
  233     { OPT_vfork_max,        stress_set_vfork_max },
  234     { OPT_sctp_domain,      stress_set_sctp_domain },
  235     { OPT_sock_port,        stress_set_socket_port },
  236     { OPT_sockfd_port,      stress_set_socket_fd_port },
  237     { OPT_splice_bytes,     stress_set_splice_bytes },
  238     { OPT_stream_index,     stress_set_stream_index },
  239     { OPT_stream_l3_size,       stress_set_stream_L3_size },
  240     { OPT_sync_file_bytes,      stress_set_sync_file_bytes },
  241     { OPT_vm_addr_method,       stress_set_vm_addr_method },
  242     { OPT_vm_bytes,         stress_set_vm_bytes },
  243     { OPT_vm_hang,          stress_set_vm_hang },
  244     { OPT_vm_madvise,       stress_set_vm_madvise },
  245     { OPT_vm_method,        stress_set_vm_method },
  246     { OPT_vm_rw_bytes,      stress_set_vm_rw_bytes },
  247     { OPT_vm_splice_bytes,      stress_set_vm_splice_bytes },
  248     { OPT_wcs_method,       stress_set_wcs_method },
  249 #if defined(HAVE_LIB_Z)
  250     { OPT_zlib_level,       stress_set_zlib_level },
  251     { OPT_zlib_method,      stress_set_zlib_method },
  252 #endif
  253     { OPT_zombie_max,       stress_set_zombie_max },
  254 };
  255 
  256 /*
  257  *  Attempt to catch a range of signals so
  258  *  we can clean up rather than leave
  259  *  cruft everywhere.
  260  */
  261 static const int terminate_signals[] = {
  262     /* POSIX.1-1990 */
  263 #if defined(SIGHUP)
  264     SIGHUP,
  265 #endif
  266 #if defined(SIGINT)
  267     SIGINT,
  268 #endif
  269 #if defined(SIGQUIT)
  270     SIGQUIT,
  271 #endif
  272 #if defined(SIGABRT)
  273     SIGABRT,
  274 #endif
  275 #if defined(SIGFPE)
  276     SIGFPE,
  277 #endif
  278 #if defined(SIGTERM)
  279     SIGTERM,
  280 #endif
  281 #if defined(SIGXCPU)
  282     SIGXCPU,
  283 #endif
  284 #if defined(SIGXFSZ)
  285     SIGXFSZ,
  286 #endif
  287     /* Linux various */
  288 #if defined(SIGIOT)
  289     SIGIOT,
  290 #endif
  291 #if defined(SIGSTKFLT)
  292     SIGSTKFLT,
  293 #endif
  294 #if defined(SIGPWR)
  295     SIGPWR,
  296 #endif
  297 #if defined(SIGINFO)
  298     SIGINFO,
  299 #endif
  300 #if defined(SIGVTALRM)
  301     SIGVTALRM,
  302 #endif
  303     -1,
  304 };
  305 
  306 #define STRESSOR(name)          \
  307 {                   \
  308     &stress_ ## name ## _info,  \
  309     STRESS_ ## name,        \
  310     OPT_ ## name,           \
  311     OPT_ ## name  ## _ops,      \
  312     # name              \
  313 }
  314 
  315 /*
  316  *  Human readable stress test names.
  317  */
  318 static const stress_t stressors[] = {
  319     STRESSOR(access),
  320     STRESSOR(af_alg),
  321     STRESSOR(affinity),
  322     STRESSOR(aio),
  323     STRESSOR(aiol),
  324     STRESSOR(apparmor),
  325     STRESSOR(atomic),
  326     STRESSOR(bad_altstack),
  327     STRESSOR(bigheap),
  328     STRESSOR(bind_mount),
  329     STRESSOR(branch),
  330     STRESSOR(brk),
  331     STRESSOR(bsearch),
  332     STRESSOR(cache),
  333     STRESSOR(cap),
  334     STRESSOR(chdir),
  335     STRESSOR(chmod),
  336     STRESSOR(chown),
  337     STRESSOR(chroot),
  338     STRESSOR(clock),
  339     STRESSOR(clone),
  340     STRESSOR(close),
  341     STRESSOR(context),
  342     STRESSOR(copy_file),
  343     STRESSOR(cpu),
  344     STRESSOR(cpu_online),
  345     STRESSOR(crypt),
  346     STRESSOR(cyclic),
  347     STRESSOR(daemon),
  348     STRESSOR(dccp),
  349     STRESSOR(dentry),
  350     STRESSOR(dev),
  351     STRESSOR(dev_shm),
  352     STRESSOR(dir),
  353     STRESSOR(dirdeep),
  354     STRESSOR(dnotify),
  355     STRESSOR(dup),
  356     STRESSOR(dynlib),
  357     STRESSOR(efivar),
  358     STRESSOR(enosys),
  359     STRESSOR(epoll),
  360     STRESSOR(eventfd),
  361     STRESSOR(exec),
  362     STRESSOR(fallocate),
  363     STRESSOR(fanotify),
  364     STRESSOR(fault),
  365     STRESSOR(fcntl),
  366     STRESSOR(fiemap),
  367     STRESSOR(fifo),
  368     STRESSOR(file_ioctl),
  369     STRESSOR(filename),
  370     STRESSOR(flock),
  371     STRESSOR(fork),
  372     STRESSOR(fp_error),
  373     STRESSOR(fstat),
  374     STRESSOR(full),
  375     STRESSOR(funccall),
  376     STRESSOR(futex),
  377     STRESSOR(get),
  378     STRESSOR(getdent),
  379     STRESSOR(getrandom),
  380     STRESSOR(handle),
  381     STRESSOR(hdd),
  382     STRESSOR(heapsort),
  383     STRESSOR(hrtimers),
  384     STRESSOR(hsearch),
  385     STRESSOR(icache),
  386     STRESSOR(icmp_flood),
  387     STRESSOR(idle_page),
  388     STRESSOR(inode_flags),
  389     STRESSOR(inotify),
  390     STRESSOR(io),
  391     STRESSOR(iomix),
  392     STRESSOR(ioport),
  393     STRESSOR(ioprio),
  394     STRESSOR(ipsec_mb),
  395     STRESSOR(itimer),
  396     STRESSOR(kcmp),
  397     STRESSOR(key),
  398     STRESSOR(kill),
  399     STRESSOR(klog),
  400     STRESSOR(lease),
  401     STRESSOR(link),
  402     STRESSOR(locka),
  403     STRESSOR(lockbus),
  404     STRESSOR(lockf),
  405     STRESSOR(lockofd),
  406     STRESSOR(longjmp),
  407     STRESSOR(loop),
  408     STRESSOR(lsearch),
  409     STRESSOR(madvise),
  410     STRESSOR(malloc),
  411     STRESSOR(matrix),
  412     STRESSOR(matrix_3d),
  413     STRESSOR(mcontend),
  414     STRESSOR(membarrier),
  415     STRESSOR(memcpy),
  416     STRESSOR(memfd),
  417     STRESSOR(memrate),
  418     STRESSOR(memthrash),
  419     STRESSOR(mergesort),
  420     STRESSOR(mincore),
  421     STRESSOR(mknod),
  422     STRESSOR(mlock),
  423     STRESSOR(mlockmany),
  424     STRESSOR(mmap),
  425     STRESSOR(mmapaddr),
  426     STRESSOR(mmapfixed),
  427     STRESSOR(mmapfork),
  428     STRESSOR(mmapmany),
  429     STRESSOR(mq),
  430     STRESSOR(mremap),
  431     STRESSOR(msg),
  432     STRESSOR(msync),
  433     STRESSOR(netdev),
  434     STRESSOR(netlink_proc),
  435     STRESSOR(nice),
  436     STRESSOR(nop),
  437     STRESSOR(null),
  438     STRESSOR(numa),
  439     STRESSOR(oom_pipe),
  440     STRESSOR(opcode),
  441     STRESSOR(open),
  442     STRESSOR(personality),
  443     STRESSOR(physpage),
  444     STRESSOR(pipe),
  445     STRESSOR(pkey),
  446     STRESSOR(poll),
  447     STRESSOR(prctl),
  448     STRESSOR(procfs),
  449     STRESSOR(pthread),
  450     STRESSOR(ptrace),
  451     STRESSOR(pty),
  452     STRESSOR(qsort),
  453     STRESSOR(quota),
  454     STRESSOR(radixsort),
  455     STRESSOR(rawdev),
  456     STRESSOR(rdrand),
  457     STRESSOR(readahead),
  458     STRESSOR(remap),
  459     STRESSOR(rename),
  460     STRESSOR(resources),
  461     STRESSOR(revio),
  462     STRESSOR(rlimit),
  463     STRESSOR(rmap),
  464     STRESSOR(rtc),
  465     STRESSOR(schedpolicy),
  466     STRESSOR(sctp),
  467     STRESSOR(seal),
  468     STRESSOR(seccomp),
  469     STRESSOR(seek),
  470     STRESSOR(sem),
  471     STRESSOR(sem_sysv),
  472     STRESSOR(sendfile),
  473     STRESSOR(set),
  474     STRESSOR(shm),
  475     STRESSOR(shm_sysv),
  476     STRESSOR(sigfd),
  477     STRESSOR(sigfpe),
  478     STRESSOR(sigio),
  479     STRESSOR(sigpending),
  480     STRESSOR(sigpipe),
  481     STRESSOR(sigq),
  482     STRESSOR(sigrt),
  483     STRESSOR(sigsegv),
  484     STRESSOR(sigsuspend),
  485     STRESSOR(sleep),
  486     STRESSOR(sock),
  487     STRESSOR(sockdiag),
  488     STRESSOR(sockfd),
  489     STRESSOR(sockpair),
  490     STRESSOR(softlockup),
  491     STRESSOR(spawn),
  492     STRESSOR(splice),
  493     STRESSOR(stack),
  494     STRESSOR(stackmmap),
  495     STRESSOR(str),
  496     STRESSOR(stream),
  497     STRESSOR(swap),
  498     STRESSOR(switch),
  499     STRESSOR(symlink),
  500     STRESSOR(sync_file),
  501     STRESSOR(sysbadaddr),
  502     STRESSOR(sysinfo),
  503     STRESSOR(sysfs),
  504     STRESSOR(tee),
  505     STRESSOR(timer),
  506     STRESSOR(timerfd),
  507     STRESSOR(tlb_shootdown),
  508     STRESSOR(tmpfs),
  509     STRESSOR(tree),
  510     STRESSOR(tsc),
  511     STRESSOR(tsearch),
  512     STRESSOR(udp),
  513     STRESSOR(udp_flood),
  514     STRESSOR(unshare),
  515     STRESSOR(urandom),
  516     STRESSOR(userfaultfd),
  517     STRESSOR(utime),
  518     STRESSOR(vdso),
  519     STRESSOR(vecmath),
  520     STRESSOR(vfork),
  521     STRESSOR(vforkmany),
  522     STRESSOR(vm),
  523     STRESSOR(vm_addr),
  524     STRESSOR(vm_rw),
  525     STRESSOR(vm_segv),
  526     STRESSOR(vm_splice),
  527     STRESSOR(wait),
  528     STRESSOR(watchdog),
  529     STRESSOR(wcs),
  530     STRESSOR(xattr),
  531     STRESSOR(yield),
  532     STRESSOR(zero),
  533     STRESSOR(zlib),
  534     STRESSOR(zombie),
  535     { NULL, STRESS_MAX, 0, 0, NULL }
  536 };
  537 
  538 STRESS_ASSERT(SIZEOF_ARRAY(stressors) != STRESS_MAX)
  539 
  540 /*
  541  *  Different stress classes
  542  */
  543 static const class_info_t classes[] = {
  544     { CLASS_CPU_CACHE,  "cpu-cache" },
  545     { CLASS_CPU,        "cpu" },
  546     { CLASS_DEV,        "device" },
  547     { CLASS_FILESYSTEM, "filesystem" },
  548     { CLASS_INTERRUPT,  "interrupt" },
  549     { CLASS_IO,     "io" },
  550     { CLASS_MEMORY,     "memory" },
  551     { CLASS_NETWORK,    "network" },
  552     { CLASS_OS,     "os" },
  553     { CLASS_PIPE_IO,    "pipe" },
  554     { CLASS_SCHEDULER,  "scheduler" },
  555     { CLASS_SECURITY,   "security" },
  556     { CLASS_VM,     "vm" },
  557 };
  558 
  559 /*
  560  *  command line options
  561  */
  562 static const struct option long_options[] = {
  563     { "abort",  0,  0,  OPT_abort },
  564     { "access", 1,  0,  OPT_access },
  565     { "access-ops", 1,  0,  OPT_access_ops },
  566     { "af-alg", 1,  0,  OPT_af_alg },
  567     { "af-alg-ops", 1,  0,  OPT_af_alg_ops },
  568     { "af-alg", 1,  0,  OPT_af_alg },
  569     { "af-alg-ops", 1,  0,  OPT_af_alg_ops },
  570     { "affinity",   1,  0,  OPT_affinity },
  571     { "affinity-ops",1, 0,  OPT_affinity_ops },
  572     { "affinity-rand",0,    0,  OPT_affinity_rand },
  573     { "aggressive", 0,  0,  OPT_aggressive },
  574     { "aio",    1,  0,  OPT_aio },
  575     { "aio-ops",    1,  0,  OPT_aio_ops },
  576     { "aio-requests",1, 0,  OPT_aio_requests },
  577     { "aiol",   1,  0,  OPT_aiol},
  578     { "aiol-ops",   1,  0,  OPT_aiol_ops },
  579     { "aiol-requests",1,    0,  OPT_aiol_requests },
  580     { "all",    1,  0,  OPT_all },
  581     { "apparmor",   1,  0,  OPT_apparmor },
  582     { "apparmor-ops",1, 0,  OPT_apparmor_ops },
  583     { "atomic", 1,  0,  OPT_atomic },
  584     { "atomic-ops", 1,  0,  OPT_atomic_ops },
  585     { "bad-altstack",1, 0,  OPT_bad_altstack },
  586     { "bad-altstack-ops",1, 0,  OPT_bad_altstack_ops },
  587     { "backoff",    1,  0,  OPT_backoff },
  588     { "bigheap",    1,  0,  OPT_bigheap },
  589     { "bigheap-ops",1,  0,  OPT_bigheap_ops },
  590     { "bigheap-growth",1,   0,  OPT_bigheap_growth },
  591     { "bind-mount", 1,  0,  OPT_bind_mount },
  592     { "bind-mount-ops",1,   0,  OPT_bind_mount_ops },
  593     { "branch", 1,  0,  OPT_branch },
  594     { "branch-ops", 1,  0,  OPT_branch_ops },
  595     { "brk",    1,  0,  OPT_brk },
  596     { "brk-ops",    1,  0,  OPT_brk_ops },
  597     { "brk-notouch",0,  0,  OPT_brk_notouch },
  598     { "bsearch",    1,  0,  OPT_bsearch },
  599     { "bsearch-ops",1,  0,  OPT_bsearch_ops },
  600     { "bsearch-size",1, 0,  OPT_bsearch_size },
  601     { "cache",  1,  0,  OPT_cache },
  602     { "cache-ops",  1,  0,  OPT_cache_ops },
  603     { "cache-prefetch",0,   0,  OPT_cache_prefetch },
  604     { "cache-flush",0,  0,  OPT_cache_flush },
  605     { "cache-fence",0,  0,  OPT_cache_fence },
  606     { "cache-level",1,  0,  OPT_cache_level},
  607     { "cache-ways",1,   0,  OPT_cache_ways},
  608     { "cache-no-affinity",0,0,  OPT_cache_no_affinity },
  609     { "cap",    1,  0,  OPT_cap },
  610     { "cap-ops",    1,  0,  OPT_cap_ops },
  611     { "chdir",  1,  0,  OPT_chdir },
  612     { "chdir-ops",  1,  0,  OPT_chdir_ops },
  613     { "chdir-dirs", 1,  0,  OPT_chdir_dirs },
  614     { "chmod",  1,  0,  OPT_chmod },
  615     { "chmod-ops",  1,  0,  OPT_chmod_ops },
  616     { "chown",  1,  0,  OPT_chown},
  617     { "chown-ops",  1,  0,  OPT_chown_ops },
  618     { "chroot", 1,  0,  OPT_chroot},
  619     { "chroot-ops", 1,  0,  OPT_chroot_ops },
  620     { "class",  1,  0,  OPT_class },
  621     { "clock",  1,  0,  OPT_clock },
  622     { "clock-ops",  1,  0,  OPT_clock_ops },
  623     { "clone",  1,  0,  OPT_clone },
  624     { "clone-ops",  1,  0,  OPT_clone_ops },
  625     { "clone-max",  1,  0,  OPT_clone_max },
  626     { "close",  1,  0,  OPT_close },
  627     { "close-ops",  1,  0,  OPT_close_ops },
  628     { "context",    1,  0,  OPT_context },
  629     { "context-ops",1,  0,  OPT_context_ops },
  630     { "copy-file",  1,  0,  OPT_copy_file },
  631     { "copy-file-ops", 1,   0,  OPT_copy_file_ops },
  632     { "copy-file-bytes", 1, 0,  OPT_copy_file_bytes },
  633     { "cpu",    1,  0,  OPT_cpu },
  634     { "cpu-ops",    1,  0,  OPT_cpu_ops },
  635     { "cpu-load",   1,  0,  OPT_cpu_load },
  636     { "cpu-load-slice",1,   0,  OPT_cpu_load_slice },
  637     { "cpu-method", 1,  0,  OPT_cpu_method },
  638     { "cpu-online", 1,  0,  OPT_cpu_online },
  639     { "cpu-online-ops",1,   0,  OPT_cpu_online_ops },
  640     { "cpu-online-all", 0,  0,  OPT_cpu_online_all },
  641     { "crypt",  1,  0,  OPT_crypt },
  642     { "crypt-ops",  1,  0,  OPT_crypt_ops },
  643     { "cyclic", 1,  0,  OPT_cyclic },
  644     { "cyclic-dist",1,  0,  OPT_cyclic_dist },
  645     { "cyclic-method",1,    0,  OPT_cyclic_method },
  646     { "cyclic-ops",1,   0,  OPT_cyclic_ops },
  647     { "cyclic-policy",1,    0,  OPT_cyclic_policy },
  648     { "cyclic-prio",1,  0,  OPT_cyclic_prio },
  649     { "cyclic-sleep",1, 0,  OPT_cyclic_sleep },
  650     { "daemon", 1,  0,  OPT_daemon },
  651     { "daemon-ops", 1,  0,  OPT_daemon_ops },
  652     { "dccp",   1,  0,  OPT_dccp },
  653     { "dccp-domain",1,  0,  OPT_dccp_domain },
  654     { "dccp-ops",   1,  0,  OPT_dccp_ops },
  655     { "dccp-opts",  1,  0,  OPT_dccp_opts },
  656     { "dccp-port",  1,  0,  OPT_dccp_port },
  657     { "dentry", 1,  0,  OPT_dentry },
  658     { "dentry-ops", 1,  0,  OPT_dentry_ops },
  659     { "dentries",   1,  0,  OPT_dentries },
  660     { "dentry-order",1, 0,  OPT_dentry_order },
  661     { "dev",    1,  0,  OPT_dev },
  662     { "dev-ops",    1,  0,  OPT_dev_ops },
  663     { "dev-shm",    1,  0,  OPT_dev_shm },
  664     { "dev-shm-ops",1,  0,  OPT_dev_shm_ops },
  665     { "dir",    1,  0,  OPT_dir },
  666     { "dir-ops",    1,  0,  OPT_dir_ops },
  667     { "dir-dirs",   1,  0,  OPT_dir_dirs },
  668     { "dirdeep",    1,  0,  OPT_dirdeep },
  669     { "dirdeep-ops",1,  0,  OPT_dirdeep_ops },
  670     { "dirdeep-dirs",1, 0,  OPT_dirdeep_dirs },
  671     { "dirdeep-inodes",1,   0,  OPT_dirdeep_inodes },
  672     { "dry-run",    0,  0,  OPT_dry_run },
  673     { "dnotify",    1,  0,  OPT_dnotify },
  674     { "dnotify-ops",1,  0,  OPT_dnotify_ops },
  675     { "dup",    1,  0,  OPT_dup },
  676     { "dup-ops",    1,  0,  OPT_dup_ops },
  677     { "dynlib", 1,  0,  OPT_dynlib },
  678     { "dyblib-ops", 1,  0,  OPT_dynlib_ops },
  679     { "efivar", 1,  0,  OPT_efivar },
  680     { "efivar-ops", 1,  0,  OPT_efivar_ops },
  681     { "enosys", 1,  0,  OPT_enosys },
  682     { "enosys-ops", 1,  0,  OPT_enosys_ops },
  683     { "epoll",  1,  0,  OPT_epoll },
  684     { "epoll-ops",  1,  0,  OPT_epoll_ops },
  685     { "epoll-port", 1,  0,  OPT_epoll_port },
  686     { "epoll-domain",1, 0,  OPT_epoll_domain },
  687     { "eventfd",    1,  0,  OPT_eventfd },
  688     { "eventfd-ops",1,  0,  OPT_eventfd_ops },
  689     { "exclude",    1,  0,  OPT_exclude },
  690     { "exec",   1,  0,  OPT_exec },
  691     { "exec-ops",   1,  0,  OPT_exec_ops },
  692     { "exec-max",   1,  0,  OPT_exec_max },
  693     { "fallocate",  1,  0,  OPT_fallocate },
  694     { "fallocate-ops",1,    0,  OPT_fallocate_ops },
  695     { "fallocate-bytes",1,  0,  OPT_fallocate_bytes },
  696     { "fault",  1,  0,  OPT_fault },
  697     { "fault-ops",  1,  0,  OPT_fault_ops },
  698     { "fcntl",  1,  0,  OPT_fcntl},
  699     { "fcntl-ops",  1,  0,  OPT_fcntl_ops },
  700     { "fiemap", 1,  0,  OPT_fiemap },
  701     { "fiemap-ops", 1,  0,  OPT_fiemap_ops },
  702     { "fiemap-bytes",1, 0,  OPT_fiemap_bytes },
  703     { "fifo",   1,  0,  OPT_fifo },
  704     { "fifo-ops",   1,  0,  OPT_fifo_ops },
  705     { "fifo-readers",1, 0,  OPT_fifo_readers },
  706     { "file-ioctl", 1,  0,  OPT_file_ioctl },
  707     { "file-ioctl-ops",1,   0,  OPT_file_ioctl_ops },
  708     { "filename",   1,  0,  OPT_filename },
  709     { "filename-ops",1, 0,  OPT_filename_ops },
  710     { "filename-opts",1,    0,  OPT_filename_opts },
  711     { "flock",  1,  0,  OPT_flock },
  712     { "flock-ops",  1,  0,  OPT_flock_ops },
  713     { "fanotify",   1,  0,  OPT_fanotify },
  714     { "fanotify-ops",1, 0,  OPT_fanotify_ops },
  715     { "fork",   1,  0,  OPT_fork },
  716     { "fork-ops",   1,  0,  OPT_fork_ops },
  717     { "fork-max",   1,  0,  OPT_fork_max },
  718     { "fp-error",   1,  0,  OPT_fp_error},
  719     { "fp-error-ops",1, 0,  OPT_fp_error_ops },
  720     { "fstat",  1,  0,  OPT_fstat },
  721     { "fstat-ops",  1,  0,  OPT_fstat_ops },
  722     { "fstat-dir",  1,  0,  OPT_fstat_dir },
  723     { "full",   1,  0,  OPT_full },
  724     { "full-ops",   1,  0,  OPT_full_ops },
  725     { "funccall",   1,  0,  OPT_funccall },
  726     { "funccall-ops",1, 0,  OPT_funccall_ops },
  727     { "funccall-method",1,  0,  OPT_funccall_method },
  728     { "futex",  1,  0,  OPT_futex },
  729     { "futex-ops",  1,  0,  OPT_futex_ops },
  730     { "get",    1,  0,  OPT_get },
  731     { "get-ops",    1,  0,  OPT_get_ops },
  732     { "getrandom",  1,  0,  OPT_getrandom },
  733     { "getrandom-ops",1,    0,  OPT_getrandom_ops },
  734     { "getdent",    1,  0,  OPT_getdent },
  735     { "getdent-ops",1,  0,  OPT_getdent_ops },
  736     { "handle", 1,  0,  OPT_handle },
  737     { "handle-ops", 1,  0,  OPT_handle_ops },
  738     { "hdd",    1,  0,  OPT_hdd },
  739     { "hdd-ops",    1,  0,  OPT_hdd_ops },
  740     { "hdd-bytes",  1,  0,  OPT_hdd_bytes },
  741     { "hdd-write-size", 1,  0,  OPT_hdd_write_size },
  742     { "hdd-opts",   1,  0,  OPT_hdd_opts },
  743     { "heapsort",   1,  0,  OPT_heapsort },
  744     { "heapsort-ops",1, 0,  OPT_heapsort_ops },
  745     { "heapsort-size",1,    0,  OPT_heapsort_integers },
  746     { "hrtimers",   1,  0,  OPT_hrtimers },
  747     { "hrtimers-ops",1, 0,  OPT_hrtimers_ops },
  748     { "help",   0,  0,  OPT_help },
  749     { "hsearch",    1,  0,  OPT_hsearch },
  750     { "hsearch-ops",1,  0,  OPT_hsearch_ops },
  751     { "hsearch-size",1, 0,  OPT_hsearch_size },
  752     { "icache", 1,  0,  OPT_icache },
  753     { "icache-ops", 1,  0,  OPT_icache_ops },
  754     { "icmp-flood", 1,  0,  OPT_icmp_flood },
  755     { "icmp-flood-ops",1,   0,  OPT_icmp_flood_ops },
  756     { "idle-page",  1,  0,  OPT_idle_page },
  757     { "idle-page-ops",1,    0,  OPT_idle_page_ops },
  758     { "ignite-cpu", 0,  0,  OPT_ignite_cpu },
  759     { "inode-flags",1,  0,  OPT_inode_flags },
  760     { "inode-flags-ops",1,  0,  OPT_inode_flags_ops },
  761     { "inotify",    1,  0,  OPT_inotify },
  762     { "inotify-ops",1,  0,  OPT_inotify_ops },
  763     { "io",     1,  0,  OPT_io },
  764     { "io-ops", 1,  0,  OPT_io_ops },
  765     { "iomix",  1,  0,  OPT_iomix },
  766     { "iomix-bytes",1,  0,  OPT_iomix_bytes },
  767     { "iomix-ops",  1,  0,  OPT_iomix_ops },
  768     { "ionice-class",1, 0,  OPT_ionice_class },
  769     { "ionice-level",1, 0,  OPT_ionice_level },
  770     { "ioport", 1,  0,  OPT_ioport },
  771     { "ioport-ops", 1,  0,  OPT_ioport_ops },
  772     { "ioport-opts",1,  0,  OPT_ioport_opts },
  773     { "ioprio", 1,  0,  OPT_ioprio },
  774     { "ioprio-ops", 1,  0,  OPT_ioprio_ops },
  775     { "ipsec-mb",   1,  0,  OPT_ipsec_mb },
  776     { "ipsec-mb-ops",1, 0,  OPT_ipsec_mb_ops },
  777     { "itimer", 1,  0,  OPT_itimer },
  778     { "itimer-ops", 1,  0,  OPT_itimer_ops },
  779     { "itimer-freq",1,  0,  OPT_itimer_freq },
  780     { "job",    1,  0,  OPT_job },
  781     { "kcmp",   1,  0,  OPT_kcmp },
  782     { "kcmp-ops",   1,  0,  OPT_kcmp_ops },
  783     { "key",    1,  0,  OPT_key },
  784     { "key-ops",    1,  0,  OPT_key_ops },
  785     { "keep-name",  0,  0,  OPT_keep_name },
  786     { "kill",   1,  0,  OPT_kill },
  787     { "kill-ops",   1,  0,  OPT_kill_ops },
  788     { "klog",   1,  0,  OPT_klog },
  789     { "klog-ops",   1,  0,  OPT_klog_ops },
  790     { "lease",  1,  0,  OPT_lease },
  791     { "lease-ops",  1,  0,  OPT_lease_ops },
  792     { "lease-breakers",1,   0,  OPT_lease_breakers },
  793     { "link",   1,  0,  OPT_link },
  794     { "link-ops",   1,  0,  OPT_link_ops },
  795     { "locka",  1,  0,  OPT_locka },
  796     { "locka-ops",  1,  0,  OPT_locka_ops },
  797     { "lockbus",    1,  0,  OPT_lockbus },
  798     { "lockbus-ops",1,  0,  OPT_lockbus_ops },
  799     { "lockf",  1,  0,  OPT_lockf },
  800     { "lockf-ops",  1,  0,  OPT_lockf_ops },
  801     { "lockf-nonblock", 0,  0,  OPT_lockf_nonblock },
  802     { "lockofd",    1,  0,  OPT_lockofd },
  803     { "lockofd-ops",1,  0,  OPT_lockofd_ops },
  804     { "log-brief",  0,  0,  OPT_log_brief },
  805     { "log-file",   1,  0,  OPT_log_file },
  806     { "longjmp",    1,  0,  OPT_longjmp },
  807     { "longjmp-ops",1,  0,  OPT_longjmp_ops },
  808     { "loop",   1,  0,  OPT_loop },
  809     { "loop-ops",   1,  0,  OPT_loop_ops },
  810     { "lsearch",    1,  0,  OPT_lsearch },
  811     { "lsearch-ops",1,  0,  OPT_lsearch_ops },
  812     { "lsearch-size",1, 0,  OPT_lsearch_size },
  813     { "madvise",    1,  0,  OPT_madvise },
  814     { "madvise-ops",1,  0,  OPT_madvise_ops },
  815     { "malloc", 1,  0,  OPT_malloc },
  816     { "malloc-bytes",1, 0,  OPT_malloc_bytes },
  817     { "malloc-max", 1,  0,  OPT_malloc_max },
  818     { "malloc-ops", 1,  0,  OPT_malloc_ops },
  819     { "malloc-thresh",1,    0,  OPT_malloc_threshold },
  820     { "matrix", 1,  0,  OPT_matrix },
  821     { "matrix-ops", 1,  0,  OPT_matrix_ops },
  822     { "matrix-method",1,    0,  OPT_matrix_method },
  823     { "matrix-size",1,  0,  OPT_matrix_size },
  824     { "matrix-yx",  0,  0,  OPT_matrix_yx },
  825     { "matrix-3d",  1,  0,  OPT_matrix_3d },
  826     { "matrix-3d-ops",1,    0,  OPT_matrix_3d_ops },
  827     { "matrix-3d-method",1, 0,  OPT_matrix_3d_method },
  828     { "matrix-3d-size",1,   0,  OPT_matrix_3d_size },
  829     { "matrix-3d-zyx",0,    0,  OPT_matrix_3d_zyx },
  830     { "maximize",   0,  0,  OPT_maximize },
  831     { "mcontend",   1,  0,  OPT_mcontend },
  832     { "mcontend-ops",1, 0,  OPT_mcontend_ops },
  833     { "membarrier", 1,  0,  OPT_membarrier },
  834     { "membarrier-ops",1,   0,  OPT_membarrier_ops },
  835     { "memcpy", 1,  0,  OPT_memcpy },
  836     { "memcpy-ops", 1,  0,  OPT_memcpy_ops },
  837     { "memcpy-method",1,    0,  OPT_memcpy_method },
  838     { "memfd",  1,  0,  OPT_memfd },
  839     { "memfd-ops",  1,  0,  OPT_memfd_ops },
  840     { "memfd-bytes",1,  0,  OPT_memfd_bytes },
  841     { "memfd-fds",  1,  0,  OPT_memfd_fds },
  842     { "memrate",    1,  0,  OPT_memrate },
  843     { "memrate-ops",1,  0,  OPT_memrate_ops },
  844     { "memrate-rd-mbs",1,   0,  OPT_memrate_rd_mbs },
  845     { "memrate-wr-mbs",1,   0,  OPT_memrate_wr_mbs },
  846     { "memrate-bytes",1,    0,  OPT_memrate_bytes },
  847     { "memthrash",  1,  0,  OPT_memthrash },
  848     { "memthrash-ops",1,    0,  OPT_memthrash_ops },
  849     { "memthrash-method",1, 0,  OPT_memthrash_method },
  850     { "mergesort",  1,  0,  OPT_mergesort },
  851     { "mergesort-ops",1,    0,  OPT_mergesort_ops },
  852     { "mergesort-size",1,   0,  OPT_mergesort_integers },
  853     { "metrics",    0,  0,  OPT_metrics },
  854     { "metrics-brief",0,    0,  OPT_metrics_brief },
  855     { "mincore",    1,  0,  OPT_mincore },
  856     { "mincore-ops",1,  0,  OPT_mincore_ops },
  857     { "mincore-random",0,   0,  OPT_mincore_rand },
  858     { "minimize",   0,  0,  OPT_minimize },
  859     { "mknod",  1,  0,  OPT_mknod },
  860     { "mknod-ops",  1,  0,  OPT_mknod_ops },
  861     { "mlock",  1,  0,  OPT_mlock },
  862     { "mlock-ops",  1,  0,  OPT_mlock_ops },
  863     { "mlockmany",  1,  0,  OPT_mlockmany },
  864     { "mlockmany-ops",1,    0,  OPT_mlockmany_ops },
  865     { "mmap",   1,  0,  OPT_mmap },
  866     { "mmap-ops",   1,  0,  OPT_mmap_ops },
  867     { "mmap-async", 0,  0,  OPT_mmap_async },
  868     { "mmap-bytes", 1,  0,  OPT_mmap_bytes },
  869     { "mmap-file",  0,  0,  OPT_mmap_file },
  870     { "mmap-mprotect",0,    0,  OPT_mmap_mprotect },
  871     { "mmapaddr",   1,  0,  OPT_mmapaddr },
  872     { "mmapaddr-ops",1, 0,  OPT_mmapaddr_ops },
  873     { "mmapfixed",  1,  0,  OPT_mmapfixed},
  874     { "mmapfixed-ops",1,    0,  OPT_mmapfixed_ops },
  875     { "mmapfork",   1,  0,  OPT_mmapfork },
  876     { "mmapfork-ops",1, 0,  OPT_mmapfork_ops },
  877     { "mmapmany",   1,  0,  OPT_mmapmany },
  878     { "mmapmany-ops",1, 0,  OPT_mmapmany_ops },
  879     { "mq",     1,  0,  OPT_mq },
  880     { "mq-ops", 1,  0,  OPT_mq_ops },
  881     { "mq-size",    1,  0,  OPT_mq_size },
  882     { "mremap", 1,  0,  OPT_mremap },
  883     { "mremap-ops", 1,  0,  OPT_mremap_ops },
  884     { "mremap-bytes",1, 0,  OPT_mremap_bytes },
  885     { "msg",    1,  0,  OPT_msg },
  886     { "msg-ops",    1,  0,  OPT_msg_ops },
  887     { "msync",  1,  0,  OPT_msync },
  888     { "msync-ops",  1,  0,  OPT_msync_ops },
  889     { "msync-bytes",1,  0,  OPT_msync_bytes },
  890     { "netdev", 1,  0,  OPT_netdev },
  891     { "netdev-ops",1,   0,  OPT_netdev_ops },
  892     { "netlink-proc",1, 0,  OPT_netlink_proc },
  893     { "netlink-proc-ops",1, 0,  OPT_netlink_proc_ops },
  894     { "nice",   1,  0,  OPT_nice },
  895     { "nice-ops",   1,  0,  OPT_nice_ops },
  896     { "no-madvise", 0,  0,  OPT_no_madvise },
  897     { "no-rand-seed", 0,    0,  OPT_no_rand_seed },
  898     { "nop",    1,  0,  OPT_nop },
  899     { "nop-ops",    1,  0,  OPT_nop_ops },
  900     { "null",   1,  0,  OPT_null },
  901     { "null-ops",   1,  0,  OPT_null_ops },
  902     { "numa",   1,  0,  OPT_numa },
  903     { "numa-ops",   1,  0,  OPT_numa_ops },
  904     { "oomable",    0,  0,  OPT_oomable },
  905     { "oom-pipe",   1,  0,  OPT_oom_pipe },
  906     { "oom-pipe-ops",1, 0,  OPT_oom_pipe_ops },
  907     { "opcode", 1,  0,  OPT_opcode },
  908     { "opcode-ops", 1,  0,  OPT_opcode_ops },
  909     { "opcode-method",1,    0,  OPT_opcode_method },
  910     { "open",   1,  0,  OPT_open },
  911     { "open-ops",   1,  0,  OPT_open_ops },
  912     { "page-in",    0,  0,  OPT_page_in },
  913     { "parallel",   1,  0,  OPT_all },
  914     { "pathological",0, 0,  OPT_pathological },
  915 #if defined(STRESS_PERF_STATS) && defined(HAVE_LINUX_PERF_EVENT_H)
  916     { "perf",   0,  0,  OPT_perf_stats },
  917 #endif
  918     { "personality",1,  0,  OPT_personality },
  919     { "personality-ops",1,  0,  OPT_personality_ops },
  920     { "physpage",   1,  0,  OPT_physpage },
  921     { "physpage-ops",1, 0,  OPT_physpage_ops },
  922     { "pipe",   1,  0,  OPT_pipe },
  923     { "pipe-ops",   1,  0,  OPT_pipe_ops },
  924     { "pipe-data-size",1,   0,  OPT_pipe_data_size },
  925 #if defined(F_SETPIPE_SZ)
  926     { "pipe-size",  1,  0,  OPT_pipe_size },
  927 #endif
  928     { "pkey",   1,  0,  OPT_pkey },
  929     { "pkey-ops",   1,  0,  OPT_pkey_ops },
  930     { "poll",   1,  0,  OPT_poll },
  931     { "poll-ops",   1,  0,  OPT_poll_ops },
  932     { "prctl",  1,  0,  OPT_prctl },
  933     { "prctl-ops",  1,  0,  OPT_prctl_ops },
  934     { "procfs", 1,  0,  OPT_procfs },
  935     { "procfs-ops", 1,  0,  OPT_procfs_ops },
  936     { "pthread",    1,  0,  OPT_pthread },
  937     { "pthread-ops",1,  0,  OPT_pthread_ops },
  938     { "pthread-max",1,  0,  OPT_pthread_max },
  939     { "ptrace", 1,  0,  OPT_ptrace },
  940     { "ptrace-ops",1,   0,  OPT_ptrace_ops },
  941     { "pty",    1,  0,  OPT_pty },
  942     { "pty-ops",    1,  0,  OPT_pty_ops },
  943     { "pty-max",    1,  0,  OPT_pty_max },
  944     { "qsort",  1,  0,  OPT_qsort },
  945     { "qsort-ops",  1,  0,  OPT_qsort_ops },
  946     { "qsort-size", 1,  0,  OPT_qsort_integers },
  947     { "quiet",  0,  0,  OPT_quiet },
  948     { "quota",  1,  0,  OPT_quota },
  949     { "quota-ops",  1,  0,  OPT_quota_ops },
  950     { "radixsort",  1,  0,  OPT_radixsort },
  951     { "radixsort-ops",1,    0,  OPT_radixsort_ops },
  952     { "radixsort-size",1,   0,  OPT_radixsort_size },
  953     { "rawdev", 1,  0,  OPT_rawdev },
  954     { "rawdev-ops",1,   0,  OPT_rawdev_ops },
  955     { "rawdev-method",1,    0,  OPT_rawdev_method },
  956     { "random", 1,  0,  OPT_random },
  957     { "rdrand", 1,  0,  OPT_rdrand },
  958     { "rdrand-ops", 1,  0,  OPT_rdrand_ops },
  959     { "readahead",  1,  0,  OPT_readahead },
  960     { "readahead-ops",1,    0,  OPT_readahead_ops },
  961     { "readahead-bytes",1,  0,  OPT_readahead_bytes },
  962     { "remap",  1,  0,  OPT_remap },
  963     { "remap-ops",  1,  0,  OPT_remap_ops },
  964     { "rename", 1,  0,  OPT_rename },
  965     { "rename-ops", 1,  0,  OPT_rename_ops },
  966     { "resources",  1,  0,  OPT_resources },
  967     { "resources-ops",1,    0,  OPT_resources_ops },
  968     { "revio",  1,  0,  OPT_revio },
  969     { "revio-ops",  1,  0,  OPT_revio_ops },
  970     { "revio-opts", 1,  0,  OPT_revio_opts },
  971     { "revio-bytes",1,  0,  OPT_revio_bytes },
  972     { "rlimit", 1,  0,  OPT_rlimit },
  973     { "rlimit-ops", 1,  0,  OPT_rlimit_ops },
  974     { "rmap",   1,  0,  OPT_rmap },
  975     { "rmap-ops",   1,  0,  OPT_rmap_ops },
  976     { "rtc",    1,  0,  OPT_rtc },
  977     { "rtc-ops",    1,  0,  OPT_rtc_ops },
  978     { "sched",  1,  0,  OPT_sched },
  979     { "sched-prio", 1,  0,  OPT_sched_prio },
  980     { "schedpolicy",1,  0,  OPT_schedpolicy },
  981     { "schedpolicy-ops",1,  0,  OPT_schedpolicy_ops },
  982     { "sctp",   1,  0,  OPT_sctp },
  983     { "sctp-ops",   1,  0,  OPT_sctp_ops },
  984     { "sctp-domain",1,  0,  OPT_sctp_domain },
  985     { "sctp-port",  1,  0,  OPT_sctp_port },
  986     { "seal",   1,  0,  OPT_seal },
  987     { "seal-ops",   1,  0,  OPT_seal_ops },
  988     { "seccomp",    1,  0,  OPT_seccomp },
  989     { "seccomp-ops",1,  0,  OPT_seccomp_ops },
  990     { "seek",   1,  0,  OPT_seek },
  991     { "seek-ops",   1,  0,  OPT_seek_ops },
  992     { "seek-punch", 0,  0,  OPT_seek_punch  },
  993     { "seek-size",  1,  0,  OPT_seek_size },
  994     { "sem",    1,  0,  OPT_sem },
  995     { "sem-ops",    1,  0,  OPT_sem_ops },
  996     { "sem-procs",  1,  0,  OPT_sem_procs },
  997     { "sem-sysv",   1,  0,  OPT_sem_sysv },
  998     { "sem-sysv-ops",1, 0,  OPT_sem_sysv_ops },
  999     { "sem-sysv-procs",1,   0,  OPT_sem_sysv_procs },
 1000     { "sendfile",   1,  0,  OPT_sendfile },
 1001     { "sendfile-ops",1, 0,  OPT_sendfile_ops },
 1002     { "sendfile-size",1,    0,  OPT_sendfile_size },
 1003     { "sequential", 1,  0,  OPT_sequential },
 1004     { "set",    1,  0,  OPT_set },
 1005     { "set-ops",    1,  0,  OPT_set_ops },
 1006     { "shm",    1,  0,  OPT_shm },
 1007     { "shm-ops",    1,  0,  OPT_shm_ops },
 1008     { "shm-bytes",  1,  0,  OPT_shm_bytes },
 1009     { "shm-objs",   1,  0,  OPT_shm_objects },
 1010     { "shm-sysv",   1,  0,  OPT_shm_sysv },
 1011     { "shm-sysv-ops",1, 0,  OPT_shm_sysv_ops },
 1012     { "shm-sysv-bytes",1,   0,  OPT_shm_sysv_bytes },
 1013     { "shm-sysv-segs",1,    0,  OPT_shm_sysv_segments },
 1014     { "sigfd",  1,  0,  OPT_sigfd },
 1015     { "sigfd-ops",  1,  0,  OPT_sigfd_ops },
 1016     { "sigio",  1,  0,  OPT_sigio },
 1017     { "sigio-ops",  1,  0,  OPT_sigio_ops },
 1018     { "sigfpe", 1,  0,  OPT_sigfpe },
 1019     { "sigfpe-ops", 1,  0,  OPT_sigfpe_ops },
 1020     { "sigpending", 1,  0,  OPT_sigpending},
 1021     { "sigpending-ops",1,   0,  OPT_sigpending_ops },
 1022     { "sigpipe",    1,  0,  OPT_sigpipe },
 1023     { "sigpipe-ops",1,  0,  OPT_sigpipe_ops },
 1024     { "sigq",   1,  0,  OPT_sigq },
 1025     { "sigq-ops",   1,  0,  OPT_sigq_ops },
 1026     { "sigrt",  1,  0,  OPT_sigrt },
 1027     { "sigrt-ops",  1,  0,  OPT_sigrt_ops },
 1028     { "sigsegv",    1,  0,  OPT_sigsegv },
 1029     { "sigsegv-ops",1,  0,  OPT_sigsegv_ops },
 1030     { "sigsuspend", 1,  0,  OPT_sigsuspend},
 1031     { "sigsuspend-ops",1,   0,  OPT_sigsuspend_ops},
 1032     { "sleep",  1,  0,  OPT_sleep },
 1033     { "sleep-ops",  1,  0,  OPT_sleep_ops },
 1034     { "sleep-max",  1,  0,  OPT_sleep_max },
 1035     { "sock",   1,  0,  OPT_sock },
 1036     { "sock-domain",1,  0,  OPT_sock_domain },
 1037     { "sock-nodelay",0, 0,  OPT_sock_nodelay },
 1038     { "sock-ops",   1,  0,  OPT_sock_ops },
 1039     { "sock-opts",  1,  0,  OPT_sock_opts },
 1040     { "sock-port",  1,  0,  OPT_sock_port },
 1041     { "sock-type",  1,  0,  OPT_sock_type },
 1042     { "sockdiag",   1,  0,  OPT_sockdiag },
 1043     { "sockdiag-ops",1, 0,  OPT_sockdiag_ops },
 1044     { "sockfd", 1,  0,  OPT_sockfd },
 1045     { "sockfd-ops",1,   0,  OPT_sockfd_ops },
 1046     { "sockfd-port",1,  0,  OPT_sockfd_port },
 1047     { "sockpair",   1,  0,  OPT_sockpair },
 1048     { "sockpair-ops",1, 0,  OPT_sockpair_ops },
 1049     { "softlockup", 1,  0,  OPT_softlockup },
 1050     { "softlockup-ops",1,   0,  OPT_softlockup_ops },
 1051     { "spawn",  1,  0,  OPT_spawn },
 1052     { "spawn-ops",  1,  0,  OPT_spawn_ops },
 1053     { "splice", 1,  0,  OPT_splice },
 1054     { "splice-bytes",1, 0,  OPT_splice_bytes },
 1055     { "splice-ops", 1,  0,  OPT_splice_ops },
 1056     { "stack",  1,  0,  OPT_stack},
 1057     { "stack-fill", 0,  0,  OPT_stack_fill },
 1058     { "stack-ops",  1,  0,  OPT_stack_ops },
 1059     { "stackmmap",  1,  0,  OPT_stackmmap },
 1060     { "stackmmap-ops",1,    0,  OPT_stackmmap_ops },
 1061     { "str",    1,  0,  OPT_str },
 1062     { "str-ops",    1,  0,  OPT_str_ops },
 1063     { "str-method", 1,  0,  OPT_str_method },
 1064     { "stressors",  0,  0,  OPT_stressors },
 1065     { "stream", 1,  0,  OPT_stream },
 1066     { "stream-ops", 1,  0,  OPT_stream_ops },
 1067     { "stream-index",1, 0,  OPT_stream_index },
 1068     { "stream-l3-size",1,   0,  OPT_stream_l3_size },
 1069     { "stream-madvise",1,   0,  OPT_stream_madvise },
 1070     { "swap",   1,  0,  OPT_swap },
 1071     { "swap-ops",   1,  0,  OPT_swap_ops },
 1072     { "switch", 1,  0,  OPT_switch },
 1073     { "switch-ops", 1,  0,  OPT_switch_ops },
 1074     { "switch-freq",1,  0,  OPT_switch_freq },
 1075     { "symlink",    1,  0,  OPT_symlink },
 1076     { "symlink-ops",1,  0,  OPT_symlink_ops },
 1077     { "sync-file",  1,  0,  OPT_sync_file },
 1078     { "sync-file-ops", 1,   0,  OPT_sync_file_ops },
 1079     { "sync-file-bytes", 1, 0,  OPT_sync_file_bytes },
 1080     { "sysbadaddr", 1,  0,  OPT_sysbadaddr },
 1081     { "sysbadaddr-ops",1,   0,  OPT_sysbadaddr_ops },
 1082     { "sysfs",  1,  0,  OPT_sysfs },
 1083     { "sysfs-ops",1,    0,  OPT_sysfs_ops },
 1084     { "sysinfo",    1,  0,  OPT_sysinfo },
 1085     { "sysinfo-ops",1,  0,  OPT_sysinfo_ops },
 1086 #if defined(HAVE_SYSLOG_H)
 1087     { "syslog", 0,  0,  OPT_syslog },
 1088 #endif
 1089     { "taskset",    1,  0,  OPT_taskset },
 1090     { "tee",    1,  0,  OPT_tee },
 1091     { "tee-ops",    1,  0,  OPT_tee_ops },
 1092     { "temp-path",  1,  0,  OPT_temp_path },
 1093     { "timeout",    1,  0,  OPT_timeout },
 1094     { "timer",  1,  0,  OPT_timer },
 1095     { "timer-ops",  1,  0,  OPT_timer_ops },
 1096     { "timer-freq", 1,  0,  OPT_timer_freq },
 1097     { "timer-rand", 0,  0,  OPT_timer_rand },
 1098     { "timerfd",    1,  0,  OPT_timerfd },
 1099     { "timerfd-ops",1,  0,  OPT_timerfd_ops },
 1100     { "timerfd-freq",1, 0,  OPT_timerfd_freq },
 1101     { "timerfd-rand",0, 0,  OPT_timerfd_rand },
 1102     { "timer-slack",1,  0,  OPT_timer_slack },
 1103     { "tlb-shootdown",1,    0,  OPT_tlb_shootdown },
 1104     { "tlb-shootdown-ops",1,0,  OPT_tlb_shootdown_ops },
 1105     { "tmpfs",  1,  0,  OPT_tmpfs },
 1106     { "tmpfs-ops",  1,  0,  OPT_tmpfs_ops },
 1107     { "tree",   1,  0,  OPT_tree },
 1108     { "tree-ops",   1,  0,  OPT_tree_ops },
 1109     { "tree-method",1,  0,  OPT_tree_method },
 1110     { "tree-size",  1,  0,  OPT_tree_size },
 1111     { "tsc",    1,  0,  OPT_tsc },
 1112     { "tsc-ops",    1,  0,  OPT_tsc_ops },
 1113     { "tsearch",    1,  0,  OPT_tsearch },
 1114     { "tsearch-ops",1,  0,  OPT_tsearch_ops },
 1115     { "tsearch-size",1, 0,  OPT_tsearch_size },
 1116     { "thrash", 0,  0,  OPT_thrash },
 1117     { "times",  0,  0,  OPT_times },
 1118     { "timestamp",  0,  0,  OPT_timestamp },
 1119     { "tz",     0,  0,  OPT_thermal_zones },
 1120     { "udp",    1,  0,  OPT_udp },
 1121     { "udp-ops",    1,  0,  OPT_udp_ops },
 1122     { "udp-domain",1,   0,  OPT_udp_domain },
 1123     { "udp-lite",   0,  0,  OPT_udp_lite },
 1124     { "udp-port",   1,  0,  OPT_udp_port },
 1125     { "udp-flood",  1,  0,  OPT_udp_flood },
 1126     { "udp-flood-domain",1, 0,  OPT_udp_flood_domain },
 1127     { "udp-flood-ops",1,    0,  OPT_udp_flood_ops },
 1128     { "userfaultfd",1,  0,  OPT_userfaultfd },
 1129     { "userfaultfd-ops",1,  0,  OPT_userfaultfd_ops },
 1130     { "userfaultfd-bytes",1,0,  OPT_userfaultfd_bytes },
 1131     { "utime",  1,  0,  OPT_utime },
 1132     { "utime-ops",  1,  0,  OPT_utime_ops },
 1133     { "utime-fsync",0,  0,  OPT_utime_fsync },
 1134     { "unshare",    1,  0,  OPT_unshare },
 1135     { "unshare-ops",1,  0,  OPT_unshare_ops },
 1136     { "urandom",    1,  0,  OPT_urandom },
 1137     { "urandom-ops",1,  0,  OPT_urandom_ops },
 1138     { "vdso",   1,  0,  OPT_vdso },
 1139     { "vdso-ops",   1,  0,  OPT_vdso_ops },
 1140     { "vdso-func",  1,  0,  OPT_vdso_func },
 1141     { "vecmath",    1,  0,  OPT_vecmath },
 1142     { "vecmath-ops",1,  0,  OPT_vecmath_ops },
 1143     { "verbose",    0,  0,  OPT_verbose },
 1144     { "verify", 0,  0,  OPT_verify },
 1145     { "version",    0,  0,  OPT_version },
 1146     { "vfork",  1,  0,  OPT_vfork },
 1147     { "vfork-ops",  1,  0,  OPT_vfork_ops },
 1148     { "vfork-max",  1,  0,  OPT_vfork_max },
 1149     { "vforkmany",  1,  0,  OPT_vforkmany },
 1150     { "vforkmany-ops", 1,   0,  OPT_vforkmany_ops },
 1151     { "vm",     1,  0,  OPT_vm },
 1152     { "vm-bytes",   1,  0,  OPT_vm_bytes },
 1153     { "vm-hang",    1,  0,  OPT_vm_hang },
 1154     { "vm-keep",    0,  0,  OPT_vm_keep },
 1155 #if defined(MAP_POPULATE)
 1156     { "vm-populate",0,  0,  OPT_vm_mmap_populate },
 1157 #endif
 1158 #if defined(MAP_LOCKED)
 1159     { "vm-locked",  0,  0,  OPT_vm_mmap_locked },
 1160 #endif
 1161     { "vm-ops", 1,  0,  OPT_vm_ops },
 1162     { "vm-madvise", 1,  0,  OPT_vm_madvise },
 1163     { "vm-method",  1,  0,  OPT_vm_method },
 1164     { "vm-addr",    1,  0,  OPT_vm_addr },
 1165     { "vm-addr-ops",1,  0,  OPT_vm_addr_ops },
 1166     { "vm-addr-method",1,   0,  OPT_vm_addr_method },
 1167     { "vm-rw",  1,  0,  OPT_vm_rw },
 1168     { "vm-rw-bytes",1,  0,  OPT_vm_rw_bytes },
 1169     { "vm-rw-ops",  1,  0,  OPT_vm_rw_ops },
 1170     { "vm-segv",    1,  0,  OPT_vm_segv },
 1171     { "vm-segv-ops",1,  0,  OPT_vm_segv_ops },
 1172     { "vm-splice",  1,  0,  OPT_vm_splice },
 1173     { "vm-splice-bytes",1,  0,  OPT_vm_splice_bytes },
 1174     { "vm-splice-ops",1,    0,  OPT_vm_splice_ops },
 1175     { "wait",   1,  0,  OPT_wait },
 1176     { "wait-ops",   1,  0,  OPT_wait_ops },
 1177     { "watchdog",   1,  0,  OPT_watchdog },
 1178     { "watchdog-ops",1, 0,  OPT_watchdog_ops },
 1179     { "wcs",    1,  0,  OPT_wcs},
 1180     { "wcs-ops",    1,  0,  OPT_wcs_ops },
 1181     { "wcs-method", 1,  0,  OPT_wcs_method },
 1182     { "xattr",  1,  0,  OPT_xattr },
 1183     { "xattr-ops",  1,  0,  OPT_xattr_ops },
 1184     { "yaml",   1,  0,  OPT_yaml },
 1185     { "yield",  1,  0,  OPT_yield },
 1186     { "yield-ops",  1,  0,  OPT_yield_ops },
 1187     { "zero",   1,  0,  OPT_zero },
 1188     { "zero-ops",   1,  0,  OPT_zero_ops },
 1189     { "zlib",   1,  0,  OPT_zlib },
 1190     { "zlib-ops",   1,  0,  OPT_zlib_ops },
 1191     { "zlib-method",1,  0,  OPT_zlib_method },
 1192     { "zlib-level", 1,  0,  OPT_zlib_level },
 1193     { "zombie", 1,  0,  OPT_zombie },
 1194     { "zombie-ops", 1,  0,  OPT_zombie_ops },
 1195     { "zombie-max", 1,  0,  OPT_zombie_max },
 1196     { NULL,     0,  0,  0 }
 1197 };
 1198 
 1199 /*
 1200  *  Generic help options
 1201  */
 1202 static const help_t help_generic[] = {
 1203     { NULL,     "abort",        "abort all stressors if any stressor fails" },
 1204     { NULL,     "aggressive",       "enable all aggressive options" },
 1205     { "a N",    "all N",        "start N workers of each stress test" },
 1206     { "b N",    "backoff N",        "wait of N microseconds before work starts" },
 1207     { NULL,     "class name",       "specify a class of stressors, use with --sequential" },
 1208     { "n",      "dry-run",      "do not run" },
 1209     { "h",      "help",         "show help" },
 1210     { NULL,     "ignite-cpu",       "alter kernel controls to make CPU run hot" },
 1211     { NULL,     "ionice-class C",   "specify ionice class (idle, besteffort, realtime)" },
 1212     { NULL,     "ionice-level L",   "specify ionice level (0 max, 7 min)" },
 1213     { "j",      "job jobfile",      "run the named jobfile" },
 1214     { "k",      "keep-name",        "keep stress worker names to be 'stress-ng'" },
 1215     { NULL,     "log-brief",        "less verbose log messages" },
 1216     { NULL,     "log-file filename",    "log messages to a log file" },
 1217     { NULL,     "maximize",     "enable maximum stress options" },
 1218     { "M",      "metrics",      "print pseudo metrics of activity" },
 1219     { NULL,     "metrics-brief",    "enable metrics and only show non-zero results" },
 1220     { NULL,     "minimize",     "enable minimal stress options" },
 1221     { NULL,     "no-madvise",       "don't use random madvise options for each mmap" },
 1222     { NULL,     "no-rand-seed",     "seed random numbers with the same constant" },
 1223     { NULL,     "page-in",      "touch allocated pages that are not in core" },
 1224     { NULL,     "parallel N",       "synonym for 'all N'" },
 1225     { NULL,     "pathological",     "enable stressors that are known to hang a machine" },
 1226 #if defined(STRESS_PERF_STATS) && defined(HAVE_LINUX_PERF_EVENT_H)
 1227     { NULL,     "perf",         "display perf statistics" },
 1228 #endif
 1229     { "q",      "quiet",        "quiet output" },
 1230     { "r",      "random N",     "start N random workers" },
 1231     { NULL,     "sched type",       "set scheduler type" },
 1232     { NULL,     "sched-prio N",     "set scheduler priority level N" },
 1233     { NULL,     "sequential N",     "run all stressors one by one, invoking N of them" },
 1234     { NULL,     "stressors",        "show available stress tests" },
 1235 #if defined(HAVE_SYSLOG_H)
 1236     { NULL,     "syslog",       "log messages to the syslog" },
 1237 #endif
 1238     { NULL,     "taskset",      "use specific CPUs (set CPU affinity)" },
 1239     { NULL,     "temp-path",        "specify path for temporary directories and files" },
 1240     { NULL,     "thrash",       "force all pages in causing swap thrashing" },
 1241     { "t N",    "timeout T",        "timeout after T seconds" },
 1242     { NULL,     "timer-slack",      "enable timer slack mode" },
 1243     { NULL,     "times",        "show run time summary at end of the run" },
 1244     { NULL,     "timestamp",        "timestamp log output " },
 1245 #if defined(STRESS_THERMAL_ZONES)
 1246     { NULL,     "tz",           "collect temperatures from thermal zones (Linux only)" },
 1247 #endif
 1248     { "v",      "verbose",      "verbose output" },
 1249     { NULL,     "verify",       "verify results (not available on all tests)" },
 1250     { "V",      "version",      "show version" },
 1251     { "Y",      "yaml",         "output results to YAML formatted filed" },
 1252     { "x",      "exclude",      "list of stressors to exclude (not run)" },
 1253     { NULL,     NULL,           NULL }
 1254 };
 1255 
 1256 /*
 1257  *  Stress test specific options
 1258  */
 1259 static const help_t help_stressors[] = {
 1260     { NULL,     "access N",     "start N workers that stress file access permissions" },
 1261     { NULL,     "access-ops N",     "stop after N file access bogo operations" },
 1262     { NULL,     "af-alg N",     "start N workers that stress AF_ALG socket domain" },
 1263     { NULL,     "af-alg-ops N",     "stop after N af-alg bogo operations" },
 1264     { NULL,     "affinity N",       "start N workers that rapidly change CPU affinity" },
 1265     { NULL,     "affinity-ops N",       "stop after N affinity bogo operations" },
 1266     { NULL,     "affinity-rand",    "change affinity randomly rather than sequentially" },
 1267     { NULL,     "aio N",        "start N workers that issue async I/O requests" },
 1268     { NULL,     "aio-ops N",        "stop after N bogo async I/O requests" },
 1269     { NULL,     "aio-requests N",   "number of async I/O requests per worker" },
 1270     { NULL,     "aiol N",       "start N workers that exercise Linux async I/O" },
 1271     { NULL,     "aiol-ops N",       "stop after N bogo Linux aio async I/O requests" },
 1272     { NULL,     "aiol-requests N",  "number of Linux aio async I/O requests per worker" },
 1273     { NULL,     "apparmor",     "start N workers exercising AppArmor interfaces" },
 1274     { NULL,     "apparmor-ops",     "stop after N bogo AppArmor worker bogo operations" },
 1275     { NULL,     "atomic",       "start N workers exercising GCC atomic operations" },
 1276     { NULL,     "atomic-ops",       "stop after N bogo atomic bogo operations" },
 1277     { NULL,     "bad-altstack N",   "start N workers exercising bad signal stacks" },
 1278     { NULL,     "bad-altstack-ops N",   "stop after N bogo signal stack SIGSEGVs" },
 1279     { "B N",    "bigheap N",        "start N workers that grow the heap using calloc()" },
 1280     { NULL,     "bigheap-ops N",    "stop after N bogo bigheap operations" },
 1281     { NULL,     "bigheap-growth N", "grow heap by N bytes per iteration" },
 1282     { NULL,     "bind-mount N",     "start N workers exercising bind mounts" },
 1283     { NULL,     "bind-mount-ops N", "stop after N bogo bind mount operations" },
 1284     { NULL,     "branch N",     "start N workers that force branch misprediction" },
 1285     { NULL,     "branch-ops N",     "stop after N branch misprediction branches" },
 1286     { NULL,     "brk N",        "start N workers performing rapid brk calls" },
 1287     { NULL,     "brk-ops N",        "stop after N brk bogo operations" },
 1288     { NULL,     "brk-notouch",      "don't touch (page in) new data segment page" },
 1289     { NULL,     "bsearch N",        "start N workers that exercise a binary search" },
 1290     { NULL,     "bsearch-ops N",    "stop after N binary search bogo operations" },
 1291     { NULL,     "bsearch-size N",   "number of 32 bit integers to bsearch" },
 1292     { "C N",    "cache N",      "start N CPU cache thrashing workers" },
 1293     { NULL,     "cache-ops N",      "stop after N cache bogo operations" },
 1294     { NULL,     "cache-prefetch",   "prefetch on memory reads/writes" },
 1295     { NULL,     "cache-flush",      "flush cache after every memory write (x86 only)" },
 1296     { NULL,     "cache-fence",      "serialize stores" },
 1297     { NULL,     "cache-level N",    "only exercise specified cache" },
 1298     { NULL,     "cache-ways N",     "only fill specified number of cache ways" },
 1299     { NULL,     "cap N",        "start N workers exercsing capget" },
 1300     { NULL,     "cap-ops N",        "stop cap workers after N bogo capget operations" },
 1301     { NULL,     "chdir N",      "start N workers thrashing chdir on many paths" },
 1302     { NULL,     "chdir-ops N",      "stop chdir workers after N bogo chdir operations" },
 1303     { NULL,     "chdir-dirs N",     "select number of directories to exercise chdir on" },
 1304     { NULL,     "chmod N",      "start N workers thrashing chmod file mode bits " },
 1305     { NULL,     "chmod-ops N",      "stop chmod workers after N bogo operations" },
 1306     { NULL,     "chown N",      "start N workers thrashing chown file ownership" },
 1307     { NULL,     "chown-ops N",      "stop chown workers after N bogo operations" },
 1308     { NULL,     "chroot N",     "start N workers thrashing chroot" },
 1309     { NULL,     "chroot-ops N",     "stop chhroot workers after N bogo operations" },
 1310     { NULL,     "clock N",      "start N workers thrashing clocks and POSIX timers" },
 1311     { NULL,     "clock-ops N",      "stop clock workers after N bogo operations" },
 1312     { NULL,     "clone N",      "start N workers that rapidly create and reap clones" },
 1313     { NULL,     "clone-ops N",      "stop after N bogo clone operations" },
 1314     { NULL,     "clone-max N",      "set upper limit of N clones per worker" },
 1315     { NULL,     "close N",      "start N workers that exercise races on close" },
 1316     { NULL,     "close-ops N",      "stop after N bogo close operations" },
 1317     { NULL,     "context N",        "start N workers exercising user context" },
 1318     { NULL,     "context-ops N",    "stop context workers after N bogo operations" },
 1319     { NULL,     "copy-file N",      "start N workers that copy file data" },
 1320     { NULL,     "copy-file-ops N",  "stop after N copy bogo operations" },
 1321     { NULL,     "copy-file-bytes N",    "specify size of file to be copied" },
 1322     { "c N",    "cpu N",        "start N workers spinning on sqrt(rand())" },
 1323     { NULL,     "cpu-ops N",        "stop after N cpu bogo operations" },
 1324     { "l P",    "cpu-load P",       "load CPU by P %%, 0=sleep, 100=full load (see -c)" },
 1325     { NULL,     "cpu-load-slice S", "specify time slice during busy load" },
 1326     { NULL,     "cpu-method M",     "specify stress cpu method M, default is all" },
 1327     { NULL,     "cpu-online N",     "start N workers offlining/onlining the CPUs" },
 1328     { NULL,     "cpu-online-ops N", "stop after N offline/online operations" },
 1329     { NULL,     "crypt N",      "start N workers performing password encryption" },
 1330     { NULL,     "crypt-ops N",      "stop after N bogo crypt operations" },
 1331     { NULL,     "daemon N",     "start N workers creating multiple daemons" },
 1332     { NULL,     "cyclic N",     "start N cyclic real time benchmark stressors" },
 1333     { NULL,     "cyclic-ops N",     "stop after N cyclic timing cycles" },
 1334     { NULL,     "cyclic-method M",  "specify cyclic method M, default is clock_ns" },
 1335     { NULL,     "cyclic-dist N",    "calculate distribution of interval N nanosecs" },
 1336     { NULL,     "cyclic-policy P",  "used rr or fifo scheduling policy" },
 1337     { NULL,     "cyclic-prio N",    "real time scheduling priority 1..100" },
 1338     { NULL,     "cyclic-sleep N",   "sleep time of real time timer in nanosecs" },
 1339     { NULL,     "daemon-ops N",     "stop when N daemons have been created" },
 1340     { NULL,     "dccp N",       "start N workers exercising network DCCP I/O" },
 1341     { NULL,     "dccp-domain D",    "specify DCCP domain, default is ipv4" },
 1342     { NULL,     "dccp-ops N",       "stop after N DCCP  bogo operations" },
 1343     { NULL,     "dccp-opts option", "DCCP data send options [send|sendmsg|sendmmsg]" },
 1344     { NULL,     "dccp-port P",      "use DCCP ports P to P + number of workers - 1" },
 1345     { "D N",    "dentry N",     "start N dentry thrashing stressors" },
 1346     { NULL,     "dentry-ops N",     "stop after N dentry bogo operations" },
 1347     { NULL,     "dentry-order O",   "specify unlink order (reverse, forward, stride)" },
 1348     { NULL,     "dentries N",       "create N dentries per iteration" },
 1349     { NULL,     "dev",          "start N device entry thrashing stressors" },
 1350     { NULL,     "dev-ops",      "stop after N device thrashing bogo ops" },
 1351     { NULL,     "dev-shm",      "start N /dev/shm file and mmap stressors" },
 1352     { NULL,     "dev-shm-ops",      "stop after N /dev/shm bogo ops" },
 1353     { NULL,     "dir N",        "start N directory thrashing stressors" },
 1354     { NULL,     "dir-ops N",        "stop after N directory bogo operations" },
 1355     { NULL,     "dir-dirs N",       "select number of directories to exercise dir on" },
 1356     { NULL,     "dirdeep N",        "start N directory depth stressors" },
 1357     { NULL,     "dirdeep-ops N",    "stop after N directory depth bogo operations" },
 1358     { NULL,     "dirdeep-dirs N",   "create N directories per level" },
 1359     { NULL,     "dirdeep-inodes N", "create a maximum N inodes (N can also be %)" },
 1360     { NULL,     "dnotify N",        "start N workers exercising dnotify events" },
 1361     { NULL,     "dnotify-ops N",    "stop dnotify workers after N bogo operations" },
 1362     { NULL,     "dup N",        "start N workers exercising dup/close" },
 1363     { NULL,     "dup-ops N",        "stop after N dup/close bogo operations" },
 1364     { NULL,     "dynlib N",     "start N workers exercising dlopen/dlclose" },
 1365     { NULL,     "dynlib-ops N",     "stop after N dlopen/dlclose bogo operations" },
 1366     { NULL,     "efivar N",     "start N workers that read EFI variables" },
 1367     { NULL,     "efivar-ops N",     "stop after N EFI variable bogo read operations" },
 1368     { NULL,     "enosys N",     "start N workers that call non-existent system calls" },
 1369     { NULL,     "enosys-ops N",     "stop after N enosys bogo operations" },
 1370     { NULL,     "epoll N",      "start N workers doing epoll handled socket activity" },
 1371     { NULL,     "epoll-ops N",      "stop after N epoll bogo operations" },
 1372     { NULL,     "epoll-port P",     "use socket ports P upwards" },
 1373     { NULL,     "epoll-domain D",   "specify socket domain, default is unix" },
 1374     { NULL,     "eventfd N",        "start N workers stressing eventfd read/writes" },
 1375     { NULL,     "eventfd-ops N",    "stop eventfd workers after N bogo operations" },
 1376     { NULL,     "exec N",       "start N workers spinning on fork() and exec()" },
 1377     { NULL,     "exec-ops N",       "stop after N exec bogo operations" },
 1378     { NULL,     "exec-max P",       "create P workers per iteration, default is 1" },
 1379     { NULL,     "fallocate N",      "start N workers fallocating 16MB files" },
 1380     { NULL,     "fallocate-ops N",  "stop after N fallocate bogo operations" },
 1381     { NULL,     "fallocate-bytes N",    "specify size of file to allocate" },
 1382     { NULL,     "fanotify N",       "start N workers exercising fanotify events" },
 1383     { NULL,     "fanotify-ops N",   "stop fanotify workers after N bogo operations" },
 1384     { NULL,     "fault N",      "start N workers producing page faults" },
 1385     { NULL,     "fault-ops N",      "stop after N page fault bogo operations" },
 1386     { NULL,     "fcntl N",      "start N workers exercising fcntl commands" },
 1387     { NULL,     "fcntl-ops N",      "stop after N fcntl bogo operations" },
 1388     { NULL,     "fiemap N",     "start N workers exercising the FIEMAP ioctl" },
 1389     { NULL,     "fiemap-ops N",     "stop after N FIEMAP ioctl bogo operations" },
 1390     { NULL,     "fiemap-bytes N",   "specify size of file to fiemap" },
 1391     { NULL,     "fifo N",       "start N workers exercising fifo I/O" },
 1392     { NULL,     "fifo-ops N",       "stop after N fifo bogo operations" },
 1393     { NULL,     "fifo-readers N",   "number of fifo reader stessors to start" },
 1394     { NULL,     "file-ioctl N",     "start N workers exercising file specific ioctls" },
 1395     { NULL,     "file-ioctl-ops N", "stop after N file ioctl bogo operations" },
 1396     { NULL,     "filename N",       "start N workers exercising filenames" },
 1397     { NULL,     "filename-ops N",   "stop after N filename bogo operations" },
 1398     { NULL,     "filename-opts opt",    "specify allowed filename options" },
 1399     { NULL,     "flock N",      "start N workers locking a single file" },
 1400     { NULL,     "flock-ops N",      "stop after N flock bogo operations" },
 1401     { "f N",    "fork N",       "start N workers spinning on fork() and exit()" },
 1402     { NULL,     "fork-ops N",       "stop after N fork bogo operations" },
 1403     { NULL,     "fork-max P",       "create P workers per iteration, default is 1" },
 1404     { NULL,     "fp-error N",       "start N workers exercising floating point errors" },
 1405     { NULL,     "fp-error-ops N",   "stop after N fp-error bogo operations" },
 1406     { NULL,     "fstat N",      "start N workers exercising fstat on files" },
 1407     { NULL,     "fstat-ops N",      "stop after N fstat bogo operations" },
 1408     { NULL,     "fstat-dir path",   "fstat files in the specified directory" },
 1409     { NULL,     "full N",       "start N workers exercising /dev/full" },
 1410     { NULL,     "full-ops N",       "stop after N /dev/full bogo I/O operations" },
 1411     { NULL,     "funccall N",       "start N workers exercising 1 to 9 arg functions" },
 1412     { NULL,     "funccall-ops N",   "stop after N function call bogo operations" },
 1413     { NULL,     "funccall-method M",    "select function call method M" },
 1414     { NULL,     "futex N",      "start N workers exercising a fast mutex" },
 1415     { NULL,     "futex-ops N",      "stop after N fast mutex bogo operations" },
 1416     { NULL,     "get N",        "start N workers exercising the get*() system calls" },
 1417     { NULL,     "get-ops N",        "stop after N get bogo operations" },
 1418     { NULL,     "getdent N",        "start N workers reading directories using getdents" },
 1419     { NULL,     "getdent-ops N",    "stop after N getdents bogo operations" },
 1420     { NULL,     "getrandom N",      "start N workers fetching random data via getrandom()" },
 1421     { NULL,     "getrandom-ops N",  "stop after N getrandom bogo operations" },
 1422     { NULL,     "handle N",     "start N workers exercising name_to_handle_at" },
 1423     { NULL,     "handle-ops N",     "stop after N handle bogo operations" },
 1424     { "d N",    "hdd N",        "start N workers spinning on write()/unlink()" },
 1425     { NULL,     "hdd-ops N",        "stop after N hdd bogo operations" },
 1426     { NULL,     "hdd-bytes N",      "write N bytes per hdd worker (default is 1GB)" },
 1427     { NULL,     "hdd-opts list",    "specify list of various stressor options" },
 1428     { NULL,     "hdd-write-size N", "set the default write size to N bytes" },
 1429     { NULL,     "heapsort N",       "start N workers heap sorting 32 bit random integers" },
 1430     { NULL,     "heapsort-ops N",   "stop after N heap sort bogo operations" },
 1431     { NULL,     "heapsort-size N",  "number of 32 bit integers to sort" },
 1432     { NULL,     "hrtimers N",       "start N workers that exercise high resolution timers" },
 1433     { NULL,     "hrtimers-ops N",   "stop after N bogo high-res timer bogo operations" },
 1434     { NULL,     "hsearch N",        "start N workers that exercise a hash table search" },
 1435     { NULL,     "hsearch-ops N",    "stop after N hash search bogo operations" },
 1436     { NULL,     "hsearch-size N",   "number of integers to insert into hash table" },
 1437     { NULL,     "icache N",     "start N CPU instruction cache thrashing workers" },
 1438     { NULL,     "icache-ops N",     "stop after N icache bogo operations" },
 1439     { NULL,     "icmp-flood N",     "start N ICMP packet flood workers" },
 1440     { NULL,     "icmp-flood-ops N", "stop after N ICMP bogo operations (ICMP packets)" },
 1441     { NULL,     "idle-page N",      "start N idle page scanning workers" },
 1442     { NULL,     "idle-page-ops N",  "stop after N idle page scan bogo operations" },
 1443     { NULL,     "inode-flags N",    "start N workers exercising various inode flags" },
 1444     { NULL,     "inode-flags-ops N",    "stop inode-flags workers after N bogo operations" },
 1445     { NULL,     "inotify N",        "start N workers exercising inotify events" },
 1446     { NULL,     "inotify-ops N",    "stop inotify workers after N bogo operations" },
 1447     { "i N",    "io N",         "start N workers spinning on sync()" },
 1448     { NULL,     "io-ops N",     "stop sync I/O after N io bogo operations" },
 1449     { NULL,     "iomix N",      "start N workers that have a mix of I/O operations" },
 1450     { NULL,     "iomix-bytes N",    "write N bytes per iomix worker (default is 1GB)" },
 1451     { NULL,     "iomix-ops N",      "stop iomix workers after N iomix bogo operations" },
 1452     { NULL,     "ioport N",     "start N workers exercising port I/O" },
 1453     { NULL,     "ioport-ops N",     "stop ioport workers after N port bogo operations" },
 1454     { NULL,     "ioprio N",     "start N workers exercising set/get iopriority" },
 1455     { NULL,     "ioprio-ops N",     "stop after N io bogo iopriority operations" },
 1456     { NULL,     "ipsec-mb N",       "start N workers exercising the IPSEC MB encoding" },
 1457     { NULL,     "ipsec-mb-ops N",   "stop after N ipsec bogo encoding operations" },
 1458     { NULL,     "itimer N",     "start N workers exercising interval timers" },
 1459     { NULL,     "itimer-ops N",     "stop after N interval timer bogo operations" },
 1460     { NULL,     "kcmp N",       "start N workers exercising kcmp" },
 1461     { NULL,     "kcmp-ops N",       "stop after N kcmp bogo operations" },
 1462     { NULL,     "key N",        "start N workers exercising key operations" },
 1463     { NULL,     "key-ops N",        "stop after N key bogo operations" },
 1464     { NULL,     "kill N",       "start N workers killing with SIGUSR1" },
 1465     { NULL,     "kill-ops N",       "stop after N kill bogo operations" },
 1466     { NULL,     "klog N",       "start N workers exercising kernel syslog interface" },
 1467     { NULL,     "klog-ops N",       "stop after N klog bogo operations" },
 1468     { NULL,     "lease N",      "start N workers holding and breaking a lease" },
 1469     { NULL,     "lease-ops N",      "stop after N lease bogo operations" },
 1470     { NULL,     "lease-breakers N", "number of lease breaking workers to start" },
 1471     { NULL,     "link N",       "start N workers creating hard links" },
 1472     { NULL,     "link-ops N",       "stop after N link bogo operations" },
 1473     { NULL,     "locka N",      "start N workers locking a file via advisory locks" },
 1474     { NULL,     "locka-ops N",      "stop after N locka bogo operations" },
 1475     { NULL,     "lockbus N",        "start N workers locking a memory increment" },
 1476     { NULL,     "lockbus-ops N",    "stop after N lockbus bogo operations" },
 1477     { NULL,     "lockf N",      "start N workers locking a single file via lockf" },
 1478     { NULL,     "lockf-ops N",      "stop after N lockf bogo operations" },
 1479     { NULL,     "lockf-nonblock",   "don't block if lock cannot be obtained, re-try" },
 1480     { NULL,     "lockofd N",        "start N workers using open file description locking" },
 1481     { NULL,     "lockofd-ops N",    "stop after N lockofd bogo operations" },
 1482     { NULL,     "longjmp N",        "start N workers exercising setjmp/longjmp" },
 1483     { NULL,     "longjmp-ops N",    "stop after N longjmp bogo operations" },
 1484     { NULL,     "loop N",       "start N workers exercising loopback devices" },
 1485     { NULL,     "loop-ops N",       "stop after N bogo loopback operations" },
 1486     { NULL,     "lsearch N",        "start N workers that exercise a linear search" },
 1487     { NULL,     "lsearch-ops N",    "stop after N linear search bogo operations" },
 1488     { NULL,     "lsearch-size N",   "number of 32 bit integers to lsearch" },
 1489     { NULL,     "madvise N",        "start N workers exercising madvise on memory" },
 1490     { NULL,     "madvise-ops N",    "stop after N bogo madvise operations" },
 1491     { NULL,     "malloc N",     "start N workers exercising malloc/realloc/free" },
 1492     { NULL,     "malloc-bytes N",   "allocate up to N bytes per allocation" },
 1493     { NULL,     "malloc-max N",     "keep up to N allocations at a time" },
 1494     { NULL,     "malloc-ops N",     "stop after N malloc bogo operations" },
 1495     { NULL,     "malloc-thresh N",  "threshold where malloc uses mmap instead of sbrk" },
 1496     { NULL,     "matrix N",     "start N workers exercising matrix operations" },
 1497     { NULL,     "matrix-ops N",     "stop after N maxtrix bogo operations" },
 1498     { NULL,     "matrix-method M",  "specify matrix stress method M, default is all" },
 1499     { NULL,     "matrix-size N",    "specify the size of the N x N matrix" },
 1500     { NULL,     "matrix-yx",        "matrix operation is y by x instread of x by y" },
 1501     { NULL,     "matrix-3d N",      "start N workers exercising 3D matrix operations" },
 1502     { NULL,     "matrix-3d-ops N",  "stop after N 3D maxtrix bogo operations" },
 1503     { NULL,     "matrix-3d-method M",   "specify 3D matrix stress method M, default is all" },
 1504     { NULL,     "matrix-3d-size N", "specify the size of the N x N x N matrix" },
 1505     { NULL,     "matrix-3d-zyx",    "matrix operation is z by y by x instread of x by y by z" },
 1506     { NULL,     "mcontend N",       "start N workers that produce memory contention" },
 1507     { NULL,     "mcontend-ops N",   "stop memory contention workers after N bogo-ops" },
 1508     { NULL,     "membarrier N",     "start N workers performing membarrier system calls" },
 1509     { NULL,     "membarrier-ops N", "stop after N membarrier bogo operations" },
 1510     { NULL,     "memcpy N",     "start N workers performing memory copies" },
 1511     { NULL,     "memcpy-ops N",     "stop after N memcpy bogo operations" },
 1512     { NULL,     "memcpy-method M",  "set memcpy method (M = all, libc, builtin, naive)" },
 1513     { NULL,     "memfd N",      "start N workers allocating memory with memfd_create" },
 1514     { NULL,     "memfd-bytes N",    "allocate N bytes for each stress iteration" },
 1515     { NULL,     "memfd-fds N",      "number of memory fds to open per stressors" },
 1516     { NULL,     "memfd-ops N",      "stop after N memfd bogo operations" },
 1517     { NULL,     "memrate N",        "start N workers exercised memory read/writes" },
 1518     { NULL,     "memrate-ops",      "stop after N memrate bogo operations" },
 1519     { NULL,     "memrate-bytes N",  "size of memory buffer being exercised" },
 1520     { NULL,     "memrate-rd-mbs N", "read rate from buffer in megabytes per second" },
 1521     { NULL,     "memrate-wr-mbs N", "write rate to buffer in megabytes per second" },
 1522     { NULL,     "memthrash N",      "start N workers thrashing a 16MB memory buffer" },
 1523     { NULL,     "memthrash-ops N",  "stop after N memthrash bogo operations" },
 1524     { NULL,     "memthrash-method M",   "specify memthrash method M, default is all" },
 1525     { NULL,     "mergesort N",      "start N workers merge sorting 32 bit random integers" },
 1526     { NULL,     "mergesort-ops N",  "stop after N merge sort bogo operations" },
 1527     { NULL,     "mergesort-size N", "number of 32 bit integers to sort" },
 1528     { NULL,     "mincore N",        "start N workers exercising mincore" },
 1529     { NULL,     "mincore-ops N",    "stop after N mincore bogo operations" },
 1530     { NULL,     "mincore-random",   "randomly select pages rather than linear scan" },
 1531     { NULL,     "mknod N",      "start N workers that exercise mknod" },
 1532     { NULL,     "mknod-ops N",      "stop after N mknod bogo operations" },
 1533     { NULL,     "mlock N",      "start N workers exercising mlock/munlock" },
 1534     { NULL,     "mlock-ops N",      "stop after N mlock bogo operations" },
 1535     { NULL,     "mlockmany N",      "start N workers exercising many mlock/munlock processes" },
 1536     { NULL,     "mlockmany-ops N",  "stop after N mlockmany bogo operations" },
 1537     { NULL,     "mmap N",       "start N workers stressing mmap and munmap" },
 1538     { NULL,     "mmap-ops N",       "stop after N mmap bogo operations" },
 1539     { NULL,     "mmap-async",       "using asynchronous msyncs for file based mmap" },
 1540     { NULL,     "mmap-bytes N",     "mmap and munmap N bytes for each stress iteration" },
 1541     { NULL,     "mmap-file",        "mmap onto a file using synchronous msyncs" },
 1542     { NULL,     "mmap-mprotect",    "enable mmap mprotect stressing" },
 1543     { NULL,     "mmapaddr N",       "start N workers stressing mmap with random addresses" },
 1544     { NULL,     "mmapaddr-ops N",   "stop after N mmapaddr bogo operations" },
 1545     { NULL,     "mmapfixed N",      "start N workers stressing mmap with fixed mappings" },
 1546     { NULL,     "mmapfixed-ops N",  "stop after N mmapfixed bogo operations" },
 1547     { NULL,     "mmapfork N",       "start N workers stressing many forked mmaps/munmaps" },
 1548     { NULL,     "mmapfork-ops N",   "stop after N mmapfork bogo operations" },
 1549     { NULL,     "mmapmany N",       "start N workers stressing many mmaps and munmaps" },
 1550     { NULL,     "mmapmany-ops N",   "stop after N mmapmany bogo operations" },
 1551     { NULL,     "mq N",         "start N workers passing messages using POSIX messages" },
 1552     { NULL,     "mq-ops N",     "stop mq workers after N bogo messages" },
 1553     { NULL,     "mq-size N",        "specify the size of the POSIX message queue" },
 1554     { NULL,     "mremap N",     "start N workers stressing mremap" },
 1555     { NULL,     "mremap-ops N",     "stop after N mremap bogo operations" },
 1556     { NULL,     "mremap-bytes N",   "mremap N bytes maximum for each stress iteration" },
 1557     { NULL,     "msg N",        "start N workers stressing System V messages" },
 1558     { NULL,     "msg-ops N",        "stop msg workers after N bogo messages" },
 1559     { NULL,     "msync N",      "start N workers syncing mmap'd data with msync" },
 1560     { NULL,     "msync-ops N",      "stop msync workers after N bogo msyncs" },
 1561     { NULL,     "msync-bytes N",    "size of file and memory mapped region to msync" },
 1562     { NULL,     "netdev N",     "start N workers exercising netdevice ioctls" },
 1563     { NULL,     "netdev-ops N",     "stop netdev workers after N bogo operations" },
 1564     { NULL,     "netlink-proc N",   "start N workers exercising netlink process events" },
 1565     { NULL,     "netlink-proc-ops N",   "stop netlink-proc workers after N bogo events" },
 1566     { NULL,     "nice N",       "start N workers that randomly re-adjust nice levels" },
 1567     { NULL,     "nice-ops N",       "stop after N nice bogo operations" },
 1568     { NULL,     "nop N",        "start N workers that burn cycles with no-ops" },
 1569     { NULL,     "nop-ops N",        "stop after N nop bogo no-op operations" },
 1570     { NULL,     "null N",       "start N workers writing to /dev/null" },
 1571     { NULL,     "null-ops N",       "stop after N /dev/null bogo write operations" },
 1572     { NULL,     "numa N",       "start N workers stressing NUMA interfaces" },
 1573     { NULL,     "numa-ops N",       "stop after N NUMA bogo operations" },
 1574     { NULL,     "oom-pipe N",       "start N workers exercising large pipes" },
 1575     { NULL,     "oom-pipe-ops N",   "stop after N oom-pipe bogo operations" },
 1576     { NULL,     "opcode N",     "start N workers exercising random opcodes" },
 1577     { NULL,     "opcode-ops N",     "stop after N opcode bogo operations" },
 1578     { NULL,     "opcode-method M",  "set opcode stress method (M = random, inc, mixed, text)" },
 1579     { "o",      "open N",       "start N workers exercising open/close" },
 1580     { NULL,     "open-ops N",       "stop after N open/close bogo operations" },
 1581     { NULL,     "personality N",    "start N workers that change their personality" },
 1582     { NULL,     "personality-ops N",    "stop after N bogo personality calls" },
 1583     { NULL,     "physpage N",       "start N workers performing physical page lookup" },
 1584     { NULL,     "physpage-ops N",   "stop after N physical page bogo operations" },
 1585     { "p N",    "pipe N",       "start N workers exercising pipe I/O" },
 1586     { NULL,     "pipe-ops N",       "stop after N pipe I/O bogo operations" },
 1587     { NULL,     "pipe-data-size N", "set pipe size of each pipe write to N bytes" },
 1588 #if defined(F_SETPIPE_SZ)
 1589     { NULL,     "pipe-size N",      "set pipe size to N bytes" },
 1590 #endif
 1591     { NULL,     "pkey",         "start N workers exercising pkey_mprotect" },
 1592     { NULL,     "pkey-ops",     "stop after N bogo pkey_mprotect bogo operations" },
 1593     { "P N",    "poll N",       "start N workers exercising zero timeout polling" },
 1594     { NULL,     "poll-ops N",       "stop after N poll bogo operations" },
 1595     { NULL,     "prctl N",      "start N workers exercising prctl(2)" },
 1596     { NULL,     "prctl-ops N",      "stop prctl workers after N bogo prctl operations" },
 1597     { NULL,     "procfs N",     "start N workers reading portions of /proc" },
 1598     { NULL,     "procfs-ops N",     "stop procfs workers after N bogo read operations" },
 1599     { NULL,     "pthread N",        "start N workers that create multiple threads" },
 1600     { NULL,     "pthread-ops N",    "stop pthread workers after N bogo threads created" },
 1601     { NULL,     "pthread-max P",    "create P threads at a time by each worker" },
 1602     { NULL,     "ptrace N",     "start N workers that trace a child using ptrace" },
 1603     { NULL,     "ptrace-ops N",     "stop ptrace workers after N system calls are traced" },
 1604     { NULL,     "pty N",        "start N workers that exercise pseudoterminals" },
 1605     { NULL,     "pty-ops N",        "stop pty workers after N pty bogo operations" },
 1606     { NULL,     "pty-max N",        "attempt to open a maximum of N ptys" },
 1607     { "Q",      "qsort N",      "start N workers qsorting 32 bit random integers" },
 1608     { NULL,     "qsort-ops N",      "stop after N qsort bogo operations" },
 1609     { NULL,     "qsort-size N",     "number of 32 bit integers to sort" },
 1610     { NULL,     "quota N",      "start N workers exercising quotactl commands" },
 1611     { NULL,     "quota-ops N",      "stop after N quotactl bogo operations" },
 1612     { NULL,     "radixsort N",      "start N workers radix sorting random strings" },
 1613     { NULL,     "radixsort-ops N",  "stop after N radixsort bogo operations" },
 1614     { NULL,     "radixsort-size N", "number of strings to sort" },
 1615     { NULL,     "rawdev N",     "start N workers that read a raw device" },
 1616     { NULL,     "rawdev-ops N",     "stop after N rawdev read operations" },
 1617     { NULL,     "rawdev-method M",  "specify the rawdev reead method to use" },
 1618     { NULL,     "rdrand N",     "start N workers exercising rdrand (x86 only)" },
 1619     { NULL,     "rdrand-ops N",     "stop after N rdrand bogo operations" },
 1620     { NULL,     "readahead N",      "start N workers exercising file readahead" },
 1621     { NULL,     "readahead-bytes N",    "size of file to readahead on (default is 1GB)" },
 1622     { NULL,     "readahead-ops N",  "stop after N readahead bogo operations" },
 1623     { NULL,     "remap N",      "start N workers exercising page remappings" },
 1624     { NULL,     "remap-ops N",      "stop after N remapping bogo operations" },
 1625     { "R",      "rename N",     "start N workers exercising file renames" },
 1626     { NULL,     "rename-ops N",     "stop after N rename bogo operations" },
 1627     { NULL,     "resources N",      "start N workers consuming system resources" },
 1628     { NULL,     "resources-ops N",  "stop after N resource bogo operations" },
 1629     { NULL,     "revio N",      "start N workers performing reverse I/O" },
 1630     { NULL,     "revio-ops N",      "stop after N revio bogo operations" },
 1631     { NULL,     "rlimit N",     "start N workers that exceed rlimits" },
 1632     { NULL,     "rlimit-ops N",     "stop after N rlimit bogo operations" },
 1633     { NULL,     "rmap N",       "start N workers that stress reverse mappings" },
 1634     { NULL,     "rmap-ops N",       "stop after N rmap bogo operations" },
 1635     { NULL,     "rtc N",        "start N workers that exercise the RTC interfaces" },
 1636     { NULL,     "rtc-ops N",        "stop after N RTC bogo operations" },
 1637     { NULL,     "schedpolicy N",    "start N workers that exercise scheduling policy" },
 1638     { NULL,     "schedpolicy-ops N",    "stop after N scheduling policy bogo operations" },
 1639     { NULL,     "sctp N",       "start N workers performing SCTP send/receives " },
 1640     { NULL,     "sctp-ops N",       "stop after N SCTP bogo operations" },
 1641     { NULL,     "sctp-domain D",    "specify sctp domain, default is ipv4" },
 1642     { NULL,     "sctp-port P",      "use SCTP ports P to P + number of workers - 1" },
 1643     { NULL,     "seal N",       "start N workers performing fcntl SEAL commands" },
 1644     { NULL,     "seal-ops N",       "stop after N SEAL bogo operations" },
 1645     { NULL,     "seccomp N",        "start N workers performing seccomp call filtering" },
 1646     { NULL,     "seccomp-ops N",    "stop after N seccomp bogo operations" },
 1647     { NULL,     "seek N",       "start N workers performing random seek r/w IO" },
 1648     { NULL,     "seek-ops N",       "stop after N seek bogo operations" },
 1649     { NULL,     "seek-punch",       "punch random holes in file to stress extents" },
 1650     { NULL,     "seek-size N",      "length of file to do random I/O upon" },
 1651     { NULL,     "sem N",        "start N workers doing semaphore operations" },
 1652     { NULL,     "sem-ops N",        "stop after N semaphore bogo operations" },
 1653     { NULL,     "sem-procs N",      "number of processes to start per worker" },
 1654     { NULL,     "sem-sysv N",       "start N workers doing System V semaphore operations" },
 1655     { NULL,     "sem-sysv-ops N",   "stop after N System V sem bogo operations" },
 1656     { NULL,     "sem-sysv-procs N", "number of processes to start per worker" },
 1657     { NULL,     "sendfile N",       "start N workers exercising sendfile" },
 1658     { NULL,     "sendfile-ops N",   "stop after N bogo sendfile operations" },
 1659     { NULL,     "sendfile-size N",  "size of data to be sent with sendfile" },
 1660     { NULL,     "set N",        "start N workers exercising the set*() system calls" },
 1661     { NULL,     "set-ops N",        "stop after N set bogo operations" },
 1662     { NULL,     "shm N",        "start N workers that exercise POSIX shared memory" },
 1663     { NULL,     "shm-ops N",        "stop after N POSIX shared memory bogo operations" },
 1664     { NULL,     "shm-bytes N",      "allocate/free N bytes of POSIX shared memory" },
 1665     { NULL,     "shm-segs N",       "allocate N POSIX shared memory segments per iteration" },
 1666     { NULL,     "shm-sysv N",       "start N workers that exercise System V shared memory" },
 1667     { NULL,     "shm-sysv-ops N",   "stop after N shared memory bogo operations" },
 1668     { NULL,     "shm-sysv-bytes N", "allocate and free N bytes of shared memory per loop" },
 1669     { NULL,     "shm-sysv-segs N",  "allocate N shared memory segments per iteration" },
 1670     { NULL,     "sigfd N",      "start N workers reading signals via signalfd reads " },
 1671     { NULL,     "sigfd-ops N",      "stop after N bogo signalfd reads" },
 1672     { NULL,     "sigfpe N",     "start N workers generating floating point math faults" },
 1673     { NULL,     "sigfpe-ops N",     "stop after N bogo floating point math faults" },
 1674     { NULL,     "sigio N",      "start N workers that exercise SIGIO signals" },
 1675     { NULL,     "sigio-ops N",      "stop after N bogo sigio signals" },
 1676     { NULL,     "sigpending N",     "start N workers exercising sigpending" },
 1677     { NULL,     "sigpending-ops N", "stop after N sigpending bogo operations" },
 1678     { NULL,     "sigpipe N",        "start N workers exercising SIGPIPE" },
 1679     { NULL,     "sigpipe-ops N",    "stop after N SIGPIPE bogo operations" },
 1680     { NULL,     "sigq N",       "start N workers sending sigqueue signals" },
 1681     { NULL,     "sigq-ops N",       "stop after N siqqueue bogo operations" },
 1682     { NULL,     "sigrt N",      "start N workers sending real time signals" },
 1683     { NULL,     "sigrt-ops N",      "stop after N real time signal bogo operations" },
 1684     { NULL,     "sigsegv N",        "start N workers generating segmentation faults" },
 1685     { NULL,     "sigsegv-ops N",    "stop after N bogo segmentation faults" },
 1686     { NULL,     "sigsuspend N",     "start N workers exercising sigsuspend" },
 1687     { NULL,     "sigsuspend-ops N", "stop after N bogo sigsuspend wakes" },
 1688     { NULL,     "sleep N",      "start N workers performing various duration sleeps" },
 1689     { NULL,     "sleep-ops N",      "stop after N bogo sleep operations" },
 1690     { NULL,     "sleep-max P",      "create P threads at a time by each worker" },
 1691     { "S N",    "sock N",       "start N workers exercising socket I/O" },
 1692     { NULL,     "sock-domain D",    "specify socket domain, default is ipv4" },
 1693     { NULL,     "sock-nodelay",     "disable Nagle algorithm, send data immediately" },
 1694     { NULL,     "sock-ops N",       "stop after N socket bogo operations" },
 1695     { NULL,     "sock-opts option", "socket options [send|sendmsg|sendmmsg]" },
 1696     { NULL,     "sock-port P",      "use socket ports P to P + number of workers - 1" },
 1697     { NULL,     "sock-type T",      "socket type (stream, seqpacket)" },
 1698     { NULL,     "sockdiag N",       "start N workers exercising sockdiag netlink" },
 1699     { NULL,     "sockdiag-ops N",   "stop sockdiag workers after N bogo messages" },
 1700     { NULL,     "sockfd N",     "start N workers sending file descriptors over sockets" },
 1701     { NULL,     "sockfd-ops N",     "stop after N sockfd bogo operations" },
 1702     { NULL,     "sockfd-port P",    "use socket fd ports P to P + number of workers - 1" },
 1703     { NULL,     "sockpair N",       "start N workers exercising socket pair I/O activity" },
 1704     { NULL,     "sockpair-ops N",   "stop after N socket pair bogo operations" },
 1705     { NULL,     "softlockup N",     "start N workers that cause softlockups" },
 1706     { NULL,     "softlockup-ops N", "stop after N softlockup bogo operations" },
 1707     { NULL,     "spawn",        "start N workers spawning stress-ng using posix_spawn" },
 1708     { NULL,     "spawn-ops N",      "stop after N spawn bogo operations" },
 1709     { NULL,     "splice N",     "start N workers reading/writing using splice" },
 1710     { NULL,     "splice-ops N",     "stop after N bogo splice operations" },
 1711     { NULL,     "splice-bytes N",   "number of bytes to transfer per splice call" },
 1712     { NULL,     "stack N",      "start N workers generating stack overflows" },
 1713     { NULL,     "stack-ops N",      "stop after N bogo stack overflows" },
 1714     { NULL,     "stack-fill",       "fill stack, touches all new pages " },
 1715     { NULL,     "stackmmap N",      "start N workers exercising a filebacked stack" },
 1716     { NULL,     "stackmmap-ops N",  "stop after N bogo stackmmap operations" },
 1717     { NULL,     "str N",        "start N workers exercising lib C string functions" },
 1718     { NULL,     "str-method func",  "specify the string function to stress" },
 1719     { NULL,     "str-ops N",        "stop after N bogo string operations" },
 1720     { NULL,     "stream N",     "start N workers exercising memory bandwidth" },
 1721     { NULL,     "stream-ops N",     "stop after N bogo stream operations" },
 1722     { NULL,     "stream-index",     "specify number of indices into the data (0..3)" },
 1723     { NULL,     "stream-l3-size N", "specify the L3 cache size of the CPU" },
 1724     { NULL,     "stream-madvise M", "specify mmap'd stream buffer madvise advice" },
 1725     { NULL,     "swap N",       "start N workers exercising swapon/swapoff" },
 1726     { NULL,     "swap-ops N",       "stop after N swapon/swapoff operations" },
 1727     { "s N",    "switch N",     "start N workers doing rapid context switches" },
 1728     { NULL,     "switch-ops N",     "stop after N context switch bogo operations" },
 1729     { NULL,     "switch-freq N",    "set frequency of context switches" },
 1730     { NULL,     "symlink N",        "start N workers creating symbolic links" },
 1731     { NULL,     "symlink-ops N",    "stop after N symbolic link bogo operations" },
 1732     { NULL,     "sync-file N",      "start N workers exercise sync_file_range" },
 1733     { NULL,     "sync-file-ops N",  "stop after N sync_file_range bogo operations" },
 1734     { NULL,     "sync-file-bytes N",    "size of file to be sync'd" },
 1735     { NULL,     "sysinfo N",        "start N workers reading system information" },
 1736     { NULL,     "sysinfo-ops N",    "stop after sysinfo bogo operations" },
 1737     { NULL,     "sysbadaddr N",     "start N workers that pass bad addresses to syscalls" },
 1738     { NULL,     "sysbadaddr-ops N", "stop after N sysbadaddr bogo syscalls" },
 1739     { NULL,     "sysfs N",      "start N workers reading files from /sys" },
 1740     { NULL,     "sysfs-ops N",      "stop after sysfs bogo operations" },
 1741     { NULL,     "tee N",        "start N workers exercising the tee system call" },
 1742     { NULL,     "tee-ops N",        "stop after N tee bogo operations" },
 1743     { "T N",    "timer N",      "start N workers producing timer events" },
 1744     { NULL,     "timer-ops N",      "stop after N timer bogo events" },
 1745     { NULL,     "timer-freq F",     "run timer(s) at F Hz, range 1 to 1000000000" },
 1746     { NULL,     "timer-rand",       "enable random timer frequency" },
 1747     { NULL,     "timerfd N",        "start N workers producing timerfd events" },
 1748     { NULL,     "timerfd-ops N",    "stop after N timerfd bogo events" },
 1749     { NULL,     "timerfd-freq F",   "run timer(s) at F Hz, range 1 to 1000000000" },
 1750     { NULL,     "timerfd-rand",     "enable random timerfd frequency" },
 1751     { NULL,     "tlb-shootdown N",  "start N workers that force TLB shootdowns" },
 1752     { NULL,     "tlb-shootdown-ops N",  "stop after N TLB shootdown bogo ops" },
 1753     { NULL,     "tmpfs N",      "start N workers mmap'ing a file on tmpfs" },
 1754     { NULL,     "tmpfs-ops N",      "stop after N tmpfs bogo ops" },
 1755     { NULL,     "tree N",       "start N workers that exercise tree structures" },
 1756     { NULL,     "tree-ops N",       "stop after N bogo tree operations" },
 1757     { NULL,     "tree-method M",    "select tree method, all,avl,binary,rb,splay" },
 1758     { NULL,     "tree-size N",      "N is the number of items in the tree" },
 1759     { NULL,     "tsc N",        "start N workers reading the TSC (x86 only)" },
 1760     { NULL,     "tsc-ops N",        "stop after N TSC bogo operations" },
 1761     { NULL,     "tsearch N",        "start N workers that exercise a tree search" },
 1762     { NULL,     "tsearch-ops N",    "stop after N tree search bogo operations" },
 1763     { NULL,     "tsearch-size N",   "number of 32 bit integers to tsearch" },
 1764     { NULL,     "udp N",        "start N workers performing UDP send/receives " },
 1765     { NULL,     "udp-ops N",        "stop after N udp bogo operations" },
 1766     { NULL,     "udp-domain D",     "specify domain, default is ipv4" },
 1767     { NULL,     "udp-lite",     "use the UDP-Lite (RFC 3828) protocol" },
 1768     { NULL,     "udp-port P",       "use ports P to P + number of workers - 1" },
 1769     { NULL,     "udp-flood N",      "start N workers that performs a UDP flood attack" },
 1770     { NULL,     "udp-flood-ops N",  "stop after N udp flood bogo operations" },
 1771     { NULL,     "udp-flood-domain D",   "specify domain, default is ipv4" },
 1772     { NULL,     "unshare N",        "start N workers exercising resource unsharing" },
 1773     { NULL,     "unshare-ops N",    "stop after N bogo unshare operations" },
 1774     { "u N",    "urandom N",        "start N workers reading /dev/urandom" },
 1775     { NULL,     "urandom-ops N",    "stop after N urandom bogo read operations" },
 1776     { NULL,     "userfaultfd N",    "start N page faulting workers with userspace handling" },
 1777     { NULL,     "userfaultfd-ops N",    "stop after N page faults have been handled" },
 1778     { NULL,     "utime N",      "start N workers updating file timestamps" },
 1779     { NULL,     "utime-ops N",      "stop after N utime bogo operations" },
 1780     { NULL,     "utime-fsync",      "force utime meta data sync to the file system" },
 1781     { NULL,     "vdso",         "start N workers exercising functions in the VDSO" },
 1782     { NULL,     "vdso-ops N",       "stop after N vDSO function calls" },
 1783     { NULL,     "vdso-func F",      "use just vDSO functon F" },
 1784     { NULL,     "vecmath N",        "start N workers performing vector math ops" },
 1785     { NULL,     "vecmath-ops N",    "stop after N vector math bogo operations" },
 1786     { NULL,     "vfork N",      "start N workers spinning on vfork() and exit()" },
 1787     { NULL,     "vfork-ops N",      "stop after N vfork bogo operations" },
 1788     { NULL,     "vfork-max P",      "create P processes per iteration, default is 1" },
 1789     { NULL,     "vforkmany N",      "start N workers spawning many vfork children" },
 1790     { NULL,     "vforkmany-ops N",  "stop after spawning N vfork children" },
 1791     { "m N",    "vm N",         "start N workers spinning on anonymous mmap" },
 1792     { NULL,     "vm-bytes N",       "allocate N bytes per vm worker (default 256MB)" },
 1793     { NULL,     "vm-hang N",        "sleep N seconds before freeing memory" },
 1794     { NULL,     "vm-keep",      "redirty memory instead of reallocating" },
 1795     { NULL,     "vm-ops N",     "stop after N vm bogo operations" },
 1796 #if defined(MAP_LOCKED)
 1797     { NULL,     "vm-locked",        "lock the pages of the mapped region into memory" },
 1798 #endif
 1799     { NULL,     "vm-madvise M",     "specify mmap'd vm buffer madvise advice" },
 1800     { NULL,     "vm-method M",      "specify stress vm method M, default is all" },
 1801 #if defined(MAP_POPULATE)
 1802     { NULL,     "vm-populate",      "populate (prefault) page tables for a mapping" },
 1803 #endif
 1804     { NULL,     "vm-addr N",        "start N vm address exercising workers" },
 1805     { NULL,     "vm-addr-ops N",    "stop after N vm address bogo operations" },
 1806     { NULL,     "vm-rw N",      "start N vm read/write process_vm* copy workers" },
 1807     { NULL,     "vm-rw-bytes N",    "transfer N bytes of memory per bogo operation" },
 1808     { NULL,     "vm-rw-ops N",      "stop after N vm process_vm* copy bogo operations" },
 1809     { NULL,     "vm-segv N",        "start N workers that unmap their address space" },
 1810     { NULL,     "vm-segv-ops N",    "stop after N vm-segv unmap'd SEGV faults" },
 1811     { NULL,     "vm-splice N",      "start N workers reading/writing using vmsplice" },
 1812     { NULL,     "vm-splice-ops N",  "stop after N bogo splice operations" },
 1813     { NULL,     "vm-splice-bytes N",    "number of bytes to transfer per vmsplice call" },
 1814     { NULL,     "wait N",       "start N workers waiting on child being stop/resumed" },
 1815     { NULL,     "wait-ops N",       "stop after N bogo wait operations" },
 1816     { NULL,     "watchdog N",       "start N workers that exercise /dev/watchdog" },
 1817     { NULL,     "watchdog-ops N",   "stop after N bogo watchdog operations" },
 1818     { NULL,     "wcs N",        "start N workers on lib C wide char string functions" },
 1819     { NULL,     "wcs-method func",  "specify the wide character string function to stress" },
 1820     { NULL,     "wcs-ops N",        "stop after N bogo wide character string operations" },
 1821     { NULL,     "xattr N",      "start N workers stressing file extended attributes" },
 1822     { NULL,     "xattr-ops N",      "stop after N bogo xattr operations" },
 1823     { "y N",    "yield N",      "start N workers doing sched_yield() calls" },
 1824     { NULL,     "yield-ops N",      "stop after N bogo yield operations" },
 1825     { NULL,     "zero N",       "start N workers reading /dev/zero" },
 1826     { NULL,     "zero-ops N",       "stop after N /dev/zero bogo read operations" },
 1827     { NULL,     "zlib N",       "start N workers compressing data with zlib" },
 1828     { NULL,     "zlib-ops N",       "stop after N zlib bogo compression operations" },
 1829     { NULL,     "zlib-level L",     "specify zlib compressession level 0=fast, 9=best" },
 1830     { NULL,     "zlib-method M",    "specify zlib random data generation method M" },
 1831     { NULL,     "zombie N",     "start N workers that rapidly create and reap zombies" },
 1832     { NULL,     "zombie-ops N",     "stop after N bogo zombie fork operations" },
 1833     { NULL,     "zombie-max N",     "set upper limit of N zombies per worker" },
 1834     { NULL,     NULL,           NULL }
 1835 };
 1836 
 1837 /*
 1838  *  stressor_name_find()
 1839  *      Find index into stressors by name
 1840  */
 1841 static inline int32_t stressor_name_find(const char *name)
 1842 {
 1843     int32_t i;
 1844     const char *tmp = stress_munge_underscore(name);
 1845     const size_t len = strlen(tmp) + 1;
 1846     char munged_name[len];
 1847 
 1848     (void)shim_strlcpy(munged_name, tmp, len);
 1849 
 1850     for (i = 0; stressors[i].name; i++) {
 1851         const char *munged_stressor_name =
 1852             stress_munge_underscore(stressors[i].name);
 1853 
 1854         if (!strcmp(munged_stressor_name, munged_name))
 1855             break;
 1856     }
 1857 
 1858     return i;   /* End of array is a special "NULL" entry */
 1859 }
 1860 
 1861 /*
 1862  *  remove_proc()
 1863  *  remove proc from proc list
 1864  */
 1865 static void remove_proc(proc_info_t *pi)
 1866 {
 1867     if (procs_head == pi) {
 1868         procs_head = pi->next;
 1869         if (pi->next)
 1870             pi->next->prev = pi->prev;
 1871     } else {
 1872         if (pi->prev)
 1873             pi->prev->next = pi->next;
 1874     }
 1875 
 1876     if (procs_tail == pi) {
 1877         procs_tail = pi->prev;
 1878         if (pi->prev)
 1879             pi->prev->next = pi->next;
 1880     } else {
 1881         if (pi->next)
 1882             pi->next->prev = pi->prev;
 1883     }
 1884 }
 1885 
 1886 /*
 1887  *  get_class_id()
 1888  *  find the class id of a given class name
 1889  */
 1890 static uint32_t get_class_id(char *const str)
 1891 {
 1892     size_t i;
 1893 
 1894     for (i = 0; i < SIZEOF_ARRAY(classes); i++) {
 1895         if (!strcmp(classes[i].name, str))
 1896             return classes[i].class;
 1897     }
 1898     return 0;
 1899 }
 1900 
 1901 /*
 1902  *  get_class()
 1903  *  parse for allowed class types, return bit mask of types, 0 if error
 1904  */
 1905 static int get_class(char *const class_str, uint32_t *class)
 1906 {
 1907     char *str, *token;
 1908     int ret = 0;
 1909 
 1910     *class = 0;
 1911     for (str = class_str; (token = strtok(str, ",")) != NULL; str = NULL) {
 1912         uint32_t cl = get_class_id(token);
 1913         if (!cl) {
 1914             size_t i;
 1915             size_t len = strlen(token);
 1916 
 1917             if ((len > 1) && (token[len - 1] == '?')) {
 1918                 token[len - 1] = '\0';
 1919 
 1920                 cl = get_class_id(token);
 1921                 if (cl) {
 1922                     size_t j;
 1923 
 1924                     (void)printf("class '%s' stressors:",
 1925                         token);
 1926                     for (j = 0; stressors[j].name; j++) {
 1927                         if (stressors[j].info->class & cl)
 1928                             (void)printf(" %s", stress_munge_underscore(stressors[j].name));
 1929                     }
 1930                     (void)printf("\n");
 1931                     return 1;
 1932                 }
 1933             }
 1934             (void)fprintf(stderr, "Unknown class: '%s', "
 1935                 "available classes:", token);
 1936             for (i = 0; i < SIZEOF_ARRAY(classes); i++)
 1937                 (void)fprintf(stderr, " %s", classes[i].name);
 1938             (void)fprintf(stderr, "\n\n");
 1939             return -1;
 1940         }
 1941         *class |= cl;
 1942     }
 1943     return ret;
 1944 }
 1945 
 1946 /*
 1947  *  stress_exclude()
 1948  *      parse -x --exlude exclude list
 1949  */
 1950 static int stress_exclude(void)
 1951 {
 1952     char *str, *token, *opt_exclude;
 1953 
 1954     if (!get_setting("exclude", &opt_exclude))
 1955         return 0;
 1956 
 1957     for (str = opt_exclude; (token = strtok(str, ",")) != NULL; str = NULL) {
 1958         stress_id_t id;
 1959         proc_info_t *pi = procs_head;
 1960         uint32_t i = stressor_name_find(token);
 1961 
 1962         if (!stressors[i].name) {
 1963             (void)fprintf(stderr, "Unknown stressor: '%s', "
 1964                 "invalid exclude option\n", token);
 1965             return -1;
 1966         }
 1967         id = stressors[i].id;
 1968 
 1969         while (pi) {
 1970             proc_info_t *next = pi->next;
 1971 
 1972             if (pi->stressor->id == id)
 1973                 remove_proc(pi);
 1974             pi = next;
 1975         }
 1976     }
 1977     return 0;
 1978 }
 1979 
 1980 /*
 1981  *  stress_sigint_handler()
 1982  *  catch signals and set flag to break out of stress loops
 1983  */
 1984 static void MLOCKED_TEXT stress_sigint_handler(int signum)
 1985 {
 1986     (void)signum;
 1987     g_caught_sigint = true;
 1988     g_keep_stressing_flag = false;
 1989     wait_flag = false;
 1990 
 1991     (void)kill(-getpid(), SIGALRM);
 1992 }
 1993 
 1994 /*
 1995  *  stress_sigalrm_parent_handler()
 1996  *  handle signal in parent process, don't block on waits
 1997  */
 1998 static void MLOCKED_TEXT stress_sigalrm_parent_handler(int signum)
 1999 {
 2000     (void)signum;
 2001     wait_flag = false;
 2002 }
 2003 
 2004 #if defined(SIGUSR2)
 2005 /*
 2006  *  stress_stats_handler()
 2007  *  dump current system stats
 2008  */
 2009 static void MLOCKED_TEXT stress_stats_handler(int signum)
 2010 {
 2011     static char buffer[80];
 2012     char *ptr = buffer;
 2013     int ret;
 2014     double min1, min5, min15;
 2015     size_t shmall, freemem, totalmem, freeswap;
 2016 
 2017     (void)signum;
 2018 
 2019     *ptr = '\0';
 2020 
 2021     if (stress_get_load_avg(&min1, &min5, &min15) == 0) {
 2022         ret = snprintf(ptr, sizeof(buffer),
 2023             "Load Avg: %.2f %.2f %.2f, ",
 2024             min1, min5, min15);
 2025         if (ret > 0)
 2026             ptr += ret;
 2027     }
 2028     stress_get_memlimits(&shmall, &freemem, &totalmem, &freeswap);
 2029 
 2030     (void)snprintf(ptr, buffer - ptr,
 2031         "MemFree: %zu MB, MemTotal: %zu MB",
 2032         freemem / (size_t)MB, totalmem / (size_t)MB);
 2033     /* Really shouldn't do this in a signal handler */
 2034     (void)fprintf(stdout, "%s\n", buffer);
 2035     (void)fflush(stdout);
 2036 }
 2037 #endif
 2038 
 2039 /*
 2040  *  stress_set_handler()
 2041  *  set signal handler to catch SIGINT, SIGALRM, SIGHUP
 2042  */
 2043 static int stress_set_handler(const char *stress, const bool child)
 2044 {
 2045     if (stress_sighandler(stress, SIGINT, stress_sigint_handler, NULL) < 0)
 2046         return -1;
 2047     if (stress_sighandler(stress, SIGHUP, stress_sigint_handler, NULL) < 0)
 2048         return -1;
 2049 #if defined(SIGUSR2)
 2050     if (!child) {
 2051         if (stress_sighandler(stress, SIGUSR2,
 2052             stress_stats_handler, NULL) < 0) {
 2053             return -1;
 2054         }
 2055     }
 2056 #endif
 2057     if (stress_sighandler(stress, SIGALRM,
 2058         child ? stress_handle_stop_stressing :
 2059             stress_sigalrm_parent_handler, NULL) < 0)
 2060         return -1;
 2061     return 0;
 2062 }
 2063 
 2064 /*
 2065  *  version()
 2066  *  print program version info
 2067  */
 2068 static void version(void)
 2069 {
 2070     (void)printf("%s, version " VERSION " (%s, %s) \U0001F4BB\U0001F525\n",
 2071         g_app_name, stress_get_compiler(), stress_get_uname_info());
 2072 }
 2073 
 2074 /*
 2075  *  usage_help()
 2076  *  show generic help information
 2077  */
 2078 static void usage_help(const help_t help_info[])
 2079 {
 2080     size_t i;
 2081 
 2082     for (i = 0; help_info[i].description; i++) {
 2083         char opt_s[10] = "";
 2084 
 2085         if (help_info[i].opt_s)
 2086             (void)snprintf(opt_s, sizeof(opt_s), "-%s,",
 2087                     help_info[i].opt_s);
 2088         (void)printf("%-6s--%-19s%s\n", opt_s,
 2089             help_info[i].opt_l, help_info[i].description);
 2090     }
 2091 }
 2092 
 2093 /*
 2094  *  show_stressor_names()
 2095  *  show stressor names
 2096  */
 2097 static inline void show_stressor_names(void)
 2098 {
 2099     size_t i;
 2100 
 2101     for (i = 0; stressors[i].name; i++)
 2102         (void)printf("%s%s", i ? " " : "",
 2103             stress_munge_underscore(stressors[i].name));
 2104     (void)putchar('\n');
 2105 }
 2106 
 2107 /*
 2108  *  usage()
 2109  *  print some help
 2110  */
 2111 static void usage(void)
 2112 {
 2113     version();
 2114     (void)printf("\nUsage: %s [OPTION [ARG]]\n", g_app_name);
 2115     (void)printf("\nGeneral control options:\n");
 2116     usage_help(help_generic);
 2117     (void)printf("\nStressor specific options:\n");
 2118     usage_help(help_stressors);
 2119     (void)printf("\nExample: %s --cpu 8 --io 4 --vm 2 --vm-bytes 128M "
 2120         "--fork 4 --timeout 10s\n\n"
 2121         "Note: Sizes can be suffixed with B,K,M,G and times with "
 2122         "s,m,h,d,y\n", g_app_name);
 2123     free_settings();
 2124     exit(EXIT_SUCCESS);
 2125 }
 2126 
 2127 /*
 2128  *  opt_name()
 2129  *  find name associated with an option value
 2130  */
 2131 static const char *opt_name(const int opt_val)
 2132 {
 2133     size_t i;
 2134 
 2135     for (i = 0; long_options[i].name; i++)
 2136         if (long_options[i].val == opt_val)
 2137             return long_options[i].name;
 2138 
 2139     return "<unknown>";
 2140 }
 2141 
 2142 /*
 2143  *  stress_get_processors()
 2144  *  get number of processors, set count if <=0 as:
 2145  *      count = 0 -> number of CPUs in system
 2146  *      count < 0 -> number of CPUs online
 2147  */
 2148 static void stress_get_processors(int32_t *count)
 2149 {
 2150     if (*count == 0)
 2151         *count = stress_get_processors_configured();
 2152     else if (*count < 0)
 2153         *count = stress_get_processors_online();
 2154 }
 2155 
 2156 /*
 2157  *  proc_finished()
 2158  *  mark a process as complete
 2159  */
 2160 static inline void proc_finished(pid_t *pid)
 2161 {
 2162     *pid = 0;
 2163 }
 2164 
 2165 /*
 2166  *  kill_procs()
 2167  *  kill tasks using signal
 2168  */
 2169 static void kill_procs(const int sig)
 2170 {
 2171     static int count = 0;
 2172     int signum = sig;
 2173     proc_info_t *pi;
 2174 
 2175     /* multiple calls will always fallback to SIGKILL */
 2176     count++;
 2177     if (count > 5) {
 2178         pr_dbg("killing process group %d with SIGKILL\n", (int)g_pgrp);
 2179         signum = SIGKILL;
 2180     }
 2181 
 2182     (void)killpg(g_pgrp, sig);
 2183 
 2184     for (pi = procs_head; pi; pi = pi->next) {
 2185         int32_t i;
 2186 
 2187         for (i = 0; i < pi->started_procs; i++) {
 2188             if (pi->pids[i])
 2189                 (void)kill(pi->pids[i], signum);
 2190         }
 2191     }
 2192 }
 2193 
 2194 /*
 2195  *  str_exitstatus()
 2196  *  map stress-ng exit status returns into text
 2197  */
 2198 static char *str_exitstatus(const int status)
 2199 {
 2200     switch (status) {
 2201     case EXIT_SUCCESS:
 2202         return "success";
 2203     case EXIT_FAILURE:
 2204         return "stress-ng core failure";
 2205     case EXIT_NOT_SUCCESS:
 2206         return "stressor failed";
 2207     case EXIT_NO_RESOURCE:
 2208         return "no resource(s)";
 2209     case EXIT_NOT_IMPLEMENTED:
 2210         return "not implemented";
 2211     case EXIT_SIGNALED:
 2212         return "killed by signal";
 2213     default:
 2214         return "unknown";
 2215     }
 2216 }
 2217 
 2218 /*
 2219  *  wait_procs()
 2220  *  wait for procs
 2221  */
 2222 static void MLOCKED_TEXT wait_procs(
 2223     proc_info_t *procs_list,
 2224     bool *success,
 2225     bool *resource_success)
 2226 {
 2227     proc_info_t *pi;
 2228 
 2229     if (g_opt_flags & OPT_FLAGS_IGNITE_CPU)
 2230         ignite_cpu_start();
 2231 
 2232 #if defined(HAVE_SCHED_GETAFFINITY) && NEED_GLIBC(2,3,0)
 2233     /*
 2234      *  On systems that support changing CPU affinity
 2235      *  we keep on moving processes between processors
 2236      *  to impact on memory locality (e.g. NUMA) to
 2237      *  try to thrash the system when in aggressive mode
 2238      */
 2239     if (g_opt_flags & OPT_FLAGS_AGGRESSIVE) {
 2240         cpu_set_t proc_mask;
 2241         unsigned long int cpu = 0;
 2242         const uint32_t ticks_per_sec =
 2243             stress_get_ticks_per_second() * 5;
 2244         const useconds_t usec_sleep =
 2245             ticks_per_sec ? 1000000 / ticks_per_sec : 1000000 / 250;
 2246 
 2247         while (wait_flag) {
 2248             const int32_t cpus = stress_get_processors_configured();
 2249 
 2250             /*
 2251              *  If we can't get the mask, then don't do
 2252              *  any affinity twiddling
 2253              */
 2254             if (sched_getaffinity(0, sizeof(proc_mask), &proc_mask) < 0)
 2255                 goto do_wait;
 2256             if (!CPU_COUNT(&proc_mask)) /* Highly unlikely */
 2257                 goto do_wait;
 2258 
 2259             for (pi = procs_list; pi; pi = pi->next) {
 2260                 int32_t j;
 2261 
 2262                 for (j = 0; j < pi->started_procs; j++) {
 2263                     const pid_t pid = pi->pids[j];
 2264                     if (pid) {
 2265                         cpu_set_t mask;
 2266                         int32_t cpu_num;
 2267 
 2268                         do {
 2269                             cpu_num = mwc32() % cpus;
 2270                         } while (!(CPU_ISSET(cpu_num, &proc_mask)));
 2271 
 2272                         CPU_ZERO(&mask);
 2273                         CPU_SET(cpu_num, &mask);
 2274                         if (sched_setaffinity(pid, sizeof(mask), &mask) < 0)
 2275                             goto do_wait;
 2276                     }
 2277                 }
 2278             }
 2279             (void)shim_usleep(usec_sleep);
 2280             cpu++;
 2281         }
 2282     }
 2283 do_wait:
 2284 #endif
 2285     for (pi = procs_list; pi; pi = pi->next) {
 2286         int32_t j;
 2287 
 2288         for (j = 0; j < pi->started_procs; j++) {
 2289             pid_t pid;
 2290 redo:
 2291             pid = pi->pids[j];
 2292             if (pid) {
 2293                 int status, ret;
 2294                 bool do_abort = false;
 2295                 const char *stressor_name = stress_munge_underscore(pi->stressor->name);
 2296 
 2297                 ret = waitpid(pid, &status, 0);
 2298                 if (ret > 0) {
 2299                     if (WIFSIGNALED(status)) {
 2300 #if defined(WTERMSIG)
 2301 #if NEED_GLIBC(2,1,0)
 2302                         const char *signame = strsignal(WTERMSIG(status));
 2303 
 2304                         pr_dbg("process [%d] (stress-ng-%s) terminated on signal: %d (%s)\n",
 2305                             ret, stressor_name,
 2306                             WTERMSIG(status), signame);
 2307 #else
 2308                         pr_dbg("process [%d] (stress-ng-%s) terminated on signal: %d\n",
 2309                             ret, stressor_name,
 2310                             WTERMSIG(status));
 2311 #endif
 2312 #else
 2313                         pr_dbg("process [%d] (stress-ng-%s) terminated on signal\n",
 2314                             ret, stressor_name);
 2315 #endif
 2316                         /*
 2317                          *  If the stressor got killed by OOM or SIGKILL
 2318                          *  then somebody outside of our control nuked it
 2319                          *  so don't necessarily flag that up as a direct
 2320                          *  failure.
 2321                          */
 2322                         if (process_oomed(ret)) {
 2323                             pr_dbg("process [%d] (stress-ng-%s) was killed by the OOM killer\n",
 2324                                 ret, stressor_name);
 2325                         } else if (WTERMSIG(status) == SIGKILL) {
 2326                             pr_dbg("process [%d] (stress-ng-%s) was possibly killed by the OOM killer\n",
 2327                                 ret, stressor_name);
 2328                         } else {
 2329                             *success = false;
 2330                         }
 2331                     }
 2332                     switch (WEXITSTATUS(status)) {
 2333                     case EXIT_SUCCESS:
 2334                         break;
 2335                     case EXIT_NO_RESOURCE:
 2336                         pr_err("process [%d] (stress-ng-%s) aborted early, out of system resources\n",
 2337                             ret, stressor_name);
 2338                         *resource_success = false;
 2339                         do_abort = true;
 2340                         break;
 2341                     case EXIT_NOT_IMPLEMENTED:
 2342                         do_abort = true;
 2343                         break;
 2344                     case EXIT_BY_SYS_EXIT:
 2345                         pr_dbg("process [%d] (stress-ng-%s) aborted via exit() which was not expected\n",
 2346                             ret, stressor_name);
 2347                         do_abort = true;
 2348                         break;
 2349                     default:
 2350                         pr_err("process %d (stress-ng-%s) terminated with an error, exit status=%d (%s)\n",
 2351                             ret, stressor_name, WEXITSTATUS(status),
 2352                             str_exitstatus(WEXITSTATUS(status)));
 2353                         *success = false;
 2354                         do_abort = true;
 2355                         break;
 2356                     }
 2357                     if ((g_opt_flags & OPT_FLAGS_ABORT) && do_abort) {
 2358                         g_keep_stressing_flag = false;
 2359                         wait_flag = false;
 2360                         kill_procs(SIGALRM);
 2361                     }
 2362 
 2363                     proc_finished(&pi->pids[j]);
 2364                     pr_dbg("process [%d] terminated\n", ret);
 2365                 } else if (ret == -1) {
 2366                     /* Somebody interrupted the wait */
 2367                     if (errno == EINTR)
 2368                         goto redo;
 2369                     /* This child did not exist, mark it done anyhow */
 2370                     if (errno == ECHILD)
 2371                         proc_finished(&pi->pids[j]);
 2372                 }
 2373             }
 2374         }
 2375     }
 2376     if (g_opt_flags & OPT_FLAGS_IGNITE_CPU)
 2377         ignite_cpu_stop();
 2378 }
 2379 
 2380 /*
 2381  *  handle_terminate()
 2382  *  catch terminating signals
 2383  */
 2384 static void MLOCKED_TEXT handle_terminate(int signum)
 2385 {
 2386     terminate_signum = signum;
 2387     g_keep_stressing_flag = false;
 2388     kill_procs(SIGALRM);
 2389 
 2390     switch(signum) {
 2391     case SIGILL:
 2392     case SIGSEGV:
 2393     case SIGFPE:
 2394     case SIGBUS:
 2395         fprintf(stderr, "%s: info:  [%d] terminated with unexpected signal %s\n",
 2396             g_app_name, (int)getpid(), stress_strsignal(signum));
 2397         fflush(stderr);
 2398         _exit(EXIT_SIGNALED);
 2399         break;
 2400     default:
 2401         break;
 2402     }
 2403 }
 2404 
 2405 /*
 2406  *  get_proc()
 2407  *  return nth proc from list
 2408  */
 2409 static proc_info_t *get_nth_proc(const uint32_t n)
 2410 {
 2411     proc_info_t *pi = procs_head;
 2412     uint32_t i;
 2413 
 2414     for (i = 0; pi && (i < n); i++)
 2415         pi = pi->next;
 2416 
 2417     return pi;
 2418 }
 2419 
 2420 /*
 2421  *  get_num_procs()
 2422  *  return number of procs in proc list
 2423  */
 2424 static uint32_t get_num_procs(void)
 2425 {
 2426     uint32_t n = 0;
 2427     proc_info_t *pi;
 2428 
 2429     for (pi = procs_head; pi; pi = pi->next)
 2430         n++;
 2431 
 2432     return n;
 2433 }
 2434 
 2435 /*
 2436  *  free_procs()
 2437  *  free proc info in procs table
 2438  */
 2439 static void free_procs(void)
 2440 {
 2441     proc_info_t *pi = procs_head;
 2442 
 2443     while (pi) {
 2444         proc_info_t *next = pi->next;
 2445 
 2446         free(pi->pids);
 2447         free(pi->stats);
 2448         free(pi);
 2449 
 2450         pi = next;
 2451     }
 2452 
 2453     procs_head = NULL;
 2454     procs_tail = NULL;
 2455 }
 2456 
 2457 /*
 2458  *  get_total_num_procs()
 2459  *  deterimine number of runnable procs from list
 2460  */
 2461 static uint32_t get_total_num_procs(proc_info_t *procs_list)
 2462 {
 2463     uint32_t total_num_procs = 0;
 2464     proc_info_t *pi;
 2465 
 2466     for (pi = procs_list; pi; pi = pi->next)
 2467         total_num_procs += pi->num_procs;
 2468 
 2469     return total_num_procs;
 2470 }
 2471 
 2472 /*
 2473  *  stress_child_atexit(void)
 2474  *  handle unexpected exit() call in child stressor
 2475  */
 2476 static void stress_child_atexit(void)
 2477 {
 2478     _exit(EXIT_BY_SYS_EXIT);
 2479 }
 2480 
 2481 /*
 2482  *  stress_run ()
 2483  *  kick off and run stressors
 2484  */
 2485 static void MLOCKED_TEXT stress_run(
 2486     proc_info_t *procs_list,
 2487     double *duration,
 2488     bool *success,
 2489     bool *resource_success
 2490 )
 2491 {
 2492     double time_start, time_finish;
 2493     int32_t n_procs, j;
 2494     const int32_t total_procs = get_total_num_procs(procs_list);
 2495 
 2496     wait_flag = true;
 2497     time_start = time_now();
 2498     pr_dbg("starting stressors\n");
 2499     for (n_procs = 0; n_procs < total_procs; n_procs++) {
 2500         for (proc_current = procs_list; proc_current; proc_current = proc_current->next) {
 2501             if (g_opt_timeout && (time_now() - time_start > g_opt_timeout))
 2502                 goto abort;
 2503 
 2504             j = proc_current->started_procs;
 2505 
 2506             if (j < proc_current->num_procs) {
 2507                 int rc = EXIT_SUCCESS;
 2508                 pid_t pid;
 2509                 char name[64];
 2510                 int64_t backoff = DEFAULT_BACKOFF;
 2511                 int32_t ionice_class = UNDEFINED;
 2512                 int32_t ionice_level = UNDEFINED;
 2513 
 2514                 (void)get_setting("backoff", &backoff);
 2515                 (void)get_setting("ionice-class", &ionice_class);
 2516                 (void)get_setting("ionice-level", &ionice_level);
 2517 
 2518                 proc_stats_t *stats = proc_current->stats[j];
 2519 again:
 2520                 if (!g_keep_stressing_flag)
 2521                     break;
 2522                 pid = fork();
 2523                 switch (pid) {
 2524                 case -1:
 2525                     if (errno == EAGAIN) {
 2526                         (void)shim_usleep(100000);
 2527                         goto again;
 2528                     }
 2529                     pr_err("Cannot fork: errno=%d (%s)\n",
 2530                         errno, strerror(errno));
 2531                     kill_procs(SIGALRM);
 2532                     goto wait_for_procs;
 2533                 case 0:
 2534                     /* Child */
 2535                     (void)atexit(stress_child_atexit);
 2536                     (void)setpgid(0, g_pgrp);
 2537                     if (stress_set_handler(name, true) < 0) {
 2538                         rc = EXIT_FAILURE;
 2539                         goto child_exit;
 2540                     }
 2541                     stress_parent_died_alarm();
 2542                     stress_process_dumpable(false);
 2543                     if (g_opt_flags & OPT_FLAGS_TIMER_SLACK)
 2544                         stress_set_timer_slack();
 2545 
 2546                     if (g_opt_timeout)
 2547                         (void)alarm(g_opt_timeout);
 2548                     mwc_reseed();
 2549                     (void)snprintf(name, sizeof(name), "%s-%s", g_app_name,
 2550                         stress_munge_underscore(proc_current->stressor->name));
 2551                     set_oom_adjustment(name, false);
 2552                     set_max_limits();
 2553                     set_iopriority(ionice_class, ionice_level);
 2554                     stress_set_proc_name(name);
 2555                     (void)umask(0077);
 2556 
 2557                     pr_dbg("%s: started [%d] (instance %" PRIu32 ")\n",
 2558                         name, (int)getpid(), j);
 2559 
 2560                     stats->start = stats->finish = time_now();
 2561 #if defined(STRESS_PERF_STATS) && defined(HAVE_LINUX_PERF_EVENT_H)
 2562                     if (g_opt_flags & OPT_FLAGS_PERF_STATS)
 2563                         (void)perf_open(&stats->sp);
 2564 #endif
 2565                     (void)shim_usleep(backoff * n_procs);
 2566 #if defined(STRESS_PERF_STATS) && defined(HAVE_LINUX_PERF_EVENT_H)
 2567                     if (g_opt_flags & OPT_FLAGS_PERF_STATS)
 2568                         (void)perf_enable(&stats->sp);
 2569 #endif
 2570                     if (g_keep_stressing_flag && !(g_opt_flags & OPT_FLAGS_DRY_RUN)) {
 2571                         const args_t args = {
 2572                             .counter = &stats->counter,
 2573                             .name = name,
 2574                             .max_ops = proc_current->bogo_ops,
 2575                             .instance = j,
 2576                             .num_instances = proc_current->num_procs,
 2577                             .pid = getpid(),
 2578                             .ppid = getppid(),
 2579                             .page_size = stress_get_pagesize(),
 2580                         };
 2581 
 2582                         rc = proc_current->stressor->info->stressor(&args);
 2583                         pr_fail_check(&rc);
 2584                         stats->run_ok = (rc == EXIT_SUCCESS);
 2585                     }
 2586 #if defined(STRESS_PERF_STATS) && defined(HAVE_LINUX_PERF_EVENT_H)
 2587                     if (g_opt_flags & OPT_FLAGS_PERF_STATS) {
 2588                         (void)perf_disable(&stats->sp);
 2589                         (void)perf_close(&stats->sp);
 2590                     }
 2591 #endif
 2592 #if defined(STRESS_THERMAL_ZONES)
 2593                     if (g_opt_flags & OPT_FLAGS_THERMAL_ZONES)
 2594                         (void)tz_get_temperatures(&g_shared->tz_info, &stats->tz);
 2595 #endif
 2596 
 2597                     stats->finish = time_now();
 2598                     if (times(&stats->tms) == (clock_t)-1) {
 2599                         pr_dbg("times failed: errno=%d (%s)\n",
 2600                             errno, strerror(errno));
 2601                     }
 2602                     pr_dbg("%s: exited [%d] (instance %" PRIu32 ")\n",
 2603                         name, (int)getpid(), j);
 2604 
 2605 child_exit:
 2606                     free_procs();
 2607                     stress_cache_free();
 2608                     free_settings();
 2609                     if ((rc != 0) && (g_opt_flags & OPT_FLAGS_ABORT)) {
 2610                         g_keep_stressing_flag = false;
 2611                         wait_flag = false;
 2612                         (void)kill(getppid(), SIGALRM);
 2613                     }
 2614                     if (terminate_signum)
 2615                         rc = EXIT_SIGNALED;
 2616                     _exit(rc);
 2617                 default:
 2618                     if (pid > -1) {
 2619                         (void)setpgid(pid, g_pgrp);
 2620                         proc_current->pids[j] = pid;
 2621                         proc_current->started_procs++;
 2622                     }
 2623 
 2624                     /* Forced early abort during startup? */
 2625                     if (!g_keep_stressing_flag) {
 2626                         pr_dbg("abort signal during startup, cleaning up\n");
 2627                         kill_procs(SIGALRM);
 2628                         goto wait_for_procs;
 2629                     }
 2630                     break;
 2631                 }
 2632             }
 2633         }
 2634     }
 2635     (void)stress_set_handler("stress-ng", false);
 2636     if (g_opt_timeout)
 2637         (void)alarm(g_opt_timeout);
 2638 
 2639 abort:
 2640     pr_dbg("%d stressor%s spawned\n", n_procs,
 2641         n_procs == 1 ? "" : "s");
 2642 
 2643 wait_for_procs:
 2644     wait_procs(procs_list, success, resource_success);
 2645     time_finish = time_now();
 2646 
 2647     *duration += time_finish - time_start;
 2648 }
 2649 
 2650 /*
 2651  *  show_stressors()
 2652  *  show names of stressors that are going to be run
 2653  */
 2654 static int show_stressors(void)
 2655 {
 2656     char *newstr, *str = NULL;
 2657     ssize_t len = 0;
 2658     char buffer[64];
 2659     bool previous = false;
 2660     proc_info_t *pi;
 2661 
 2662     for (pi = procs_head; pi; pi = pi->next) {
 2663         const int32_t n = pi->num_procs;
 2664 
 2665         if (n) {
 2666             ssize_t buffer_len;
 2667 
 2668             buffer_len = snprintf(buffer, sizeof(buffer),
 2669                     "%s %" PRId32 " %s",
 2670                     previous ? "," : "", n,
 2671                     stress_munge_underscore(pi->stressor->name));
 2672             previous = true;
 2673             if (buffer_len >= 0) {
 2674                 newstr = realloc(str, len + buffer_len + 1);
 2675                 if (!newstr) {
 2676                     pr_err("Cannot allocate temporary buffer\n");
 2677                     free(str);
 2678                     return -1;
 2679                 }
 2680                 str = newstr;
 2681                 (void)shim_strlcpy(str + len, buffer, buffer_len + 1);
 2682             }
 2683             len += buffer_len;
 2684         }
 2685     }
 2686     pr_inf("dispatching hogs:%s\n", str ? str : "");
 2687     free(str);
 2688     (void)fflush(stdout);
 2689 
 2690     return 0;
 2691 }
 2692 
 2693 /*
 2694  *  metrics_dump()
 2695  *  output metrics
 2696  */
 2697 static void metrics_dump(
 2698     FILE *yaml,
 2699     const int32_t ticks_per_sec)
 2700 {
 2701     proc_info_t *pi;
 2702 
 2703     pr_inf("%-13s %9.9s %9.9s %9.9s %9.9s %12s %12s\n",
 2704         "stressor", "bogo ops", "real time", "usr time",
 2705         "sys time", "bogo ops/s", "bogo ops/s");
 2706     pr_inf("%-13s %9.9s %9.9s %9.9s %9.9s %12s %12s\n",
 2707         "", "", "(secs) ", "(secs) ", "(secs) ", "(real time)",
 2708         "(usr+sys time)");
 2709     pr_yaml(yaml, "metrics:\n");
 2710 
 2711     for (pi = procs_head; pi; pi = pi->next) {
 2712         uint64_t c_total = 0, u_total = 0, s_total = 0, us_total;
 2713         double   r_total = 0.0;
 2714         int32_t  j;
 2715         char *munged = stress_munge_underscore(pi->stressor->name);
 2716         double u_time, s_time, bogo_rate_r_time, bogo_rate;
 2717         bool run_ok = false;
 2718 
 2719         for (j = 0; j < pi->started_procs; j++) {
 2720             const proc_stats_t *const stats = pi->stats[j];
 2721 
 2722             run_ok  |= stats->run_ok;
 2723             c_total += stats->counter;
 2724             u_total += stats->tms.tms_utime +
 2725                    stats->tms.tms_cutime;
 2726             s_total += stats->tms.tms_stime +
 2727                    stats->tms.tms_cstime;
 2728             r_total += stats->finish - stats->start;
 2729         }
 2730         /* Total usr + sys time of all procs */
 2731         us_total = u_total + s_total;
 2732         /* Real time in terms of average wall clock time of all procs */
 2733         r_total = pi->started_procs ?
 2734             r_total / (double)pi->started_procs : 0.0;
 2735 
 2736         if ((g_opt_flags & OPT_FLAGS_METRICS_BRIEF) &&
 2737             (c_total == 0) && (!run_ok))
 2738             continue;
 2739 
 2740         u_time = (ticks_per_sec > 0) ? (double)u_total / (double)ticks_per_sec : 0.0;
 2741         s_time = (ticks_per_sec > 0) ? (double)s_total / (double)ticks_per_sec : 0.0;
 2742         bogo_rate_r_time = (r_total > 0.0) ? (double)c_total / r_total : 0.0;
 2743         bogo_rate = (us_total > 0) ? (double)c_total / ((double)us_total / (double)ticks_per_sec) : 0.0;
 2744 
 2745         pr_inf("%-13s %9" PRIu64 " %9.2f %9.2f %9.2f %12.2f %12.2f\n",
 2746             munged,     /* stress test name */
 2747             c_total,    /* op count */
 2748             r_total,    /* average real (wall) clock time */
 2749             u_time,     /* actual user time */
 2750             s_time,     /* actual system time */
 2751             bogo_rate_r_time, /* bogo ops on wall clock time */
 2752             bogo_rate); /* bogo ops per second */
 2753 
 2754         pr_yaml(yaml, "    - stressor: %s\n", munged);
 2755         pr_yaml(yaml, "      bogo-ops: %" PRIu64 "\n", c_total);
 2756         pr_yaml(yaml, "      bogo-ops-per-second-usr-sys-time: %f\n", bogo_rate);
 2757         pr_yaml(yaml, "      bogo-ops-per-second-real-time: %f\n", bogo_rate_r_time);
 2758         pr_yaml(yaml, "      wall-clock-time: %f\n", r_total);
 2759         pr_yaml(yaml, "      user-time: %f\n", u_time);
 2760         pr_yaml(yaml, "      system-time: %f\n", s_time);
 2761         pr_yaml(yaml, "\n");
 2762     }
 2763 }
 2764 
 2765 /*
 2766  *  times_dump()
 2767  *  output the run times
 2768  */
 2769 static void times_dump(
 2770     FILE *yaml,
 2771     const int32_t ticks_per_sec,
 2772     const double duration)
 2773 {
 2774     struct tms buf;
 2775     double total_cpu_time = stress_get_processors_configured() * duration;
 2776     double u_time, s_time, t_time, u_pc, s_pc, t_pc;
 2777     double min1, min5, min15;
 2778     int rc;
 2779 
 2780     if (times(&buf) == (clock_t)-1) {
 2781         pr_err("cannot get run time information: errno=%d (%s)\n",
 2782             errno, strerror(errno));
 2783         return;
 2784     }
 2785     rc = stress_get_load_avg(&min1, &min5, &min15);
 2786 
 2787     u_time = (float)buf.tms_cutime / (float)ticks_per_sec;
 2788     s_time = (float)buf.tms_cstime / (float)ticks_per_sec;
 2789     t_time = ((float)buf.tms_cutime + (float)buf.tms_cstime) / (float)ticks_per_sec;
 2790     u_pc = (total_cpu_time > 0.0) ? 100.0 * u_time / total_cpu_time : 0.0;
 2791     s_pc = (total_cpu_time > 0.0) ? 100.0 * s_time / total_cpu_time : 0.0;
 2792     t_pc = (total_cpu_time > 0.0) ? 100.0 * t_time / total_cpu_time : 0.0;
 2793 
 2794     pr_inf("for a %.2fs run time:\n", duration);
 2795     pr_inf("  %8.2fs available CPU time\n",
 2796         total_cpu_time);
 2797     pr_inf("  %8.2fs user time   (%6.2f%%)\n", u_time, u_pc);
 2798     pr_inf("  %8.2fs system time (%6.2f%%)\n", s_time, s_pc);
 2799     pr_inf("  %8.2fs total time  (%6.2f%%)\n", t_time, t_pc);
 2800 
 2801     if (!rc) {
 2802         pr_inf("load average: %.2f %.2f %.2f\n",
 2803             min1, min5, min15);
 2804     }
 2805 
 2806     pr_yaml(yaml, "times:\n");
 2807     pr_yaml(yaml, "      run-time: %f\n", duration);
 2808     pr_yaml(yaml, "      available-cpu-time: %f\n", total_cpu_time);
 2809     pr_yaml(yaml, "      user-time: %f\n", u_time);
 2810     pr_yaml(yaml, "      system-time: %f\n", s_time);
 2811     pr_yaml(yaml, "      total-time: %f\n", t_time);
 2812     pr_yaml(yaml, "      user-time-percent: %f\n", u_pc);
 2813     pr_yaml(yaml, "      system-time-percent: %f\n", s_pc);
 2814     pr_yaml(yaml, "      total-time-percent: %f\n", t_pc);
 2815     if (!rc) {
 2816         pr_yaml(yaml, "      load-average-1-minute: %f\n", min1);
 2817         pr_yaml(yaml, "      load-average-5-minute: %f\n", min5);
 2818         pr_yaml(yaml, "      load-average-15-minute: %f\n", min15);
 2819     }
 2820 }
 2821 
 2822 /*
 2823  *  log_args()
 2824  *  dump to syslog argv[]
 2825  */
 2826 static void log_args(int argc, char **argv)
 2827 {
 2828     size_t i, len, arglen[argc];
 2829     char *buf;
 2830 
 2831     for (len = 0, i = 0; i < (size_t)argc; i++) {
 2832         arglen[i] = strlen(argv[i]);
 2833         len += arglen[i] + 1;
 2834     }
 2835 
 2836     buf = calloc(len, sizeof(*buf));
 2837     if (!buf)
 2838         return;
 2839 
 2840     for (len = 0, i = 0; i < (size_t)argc; i++) {
 2841         if (i) {
 2842             (void)shim_strlcat(buf + len, " ", 1);
 2843             len++;
 2844         }
 2845         (void)shim_strlcat(buf + len, argv[i], arglen[i]);
 2846         len += arglen[i];
 2847     }
 2848 #if defined(HAVE_SYSLOG_H)
 2849     syslog(LOG_INFO, "invoked with '%s' by user %d", buf, getuid());
 2850 #endif
 2851     free(buf);
 2852 }
 2853 
 2854 /*
 2855  *  log_system_mem_info()
 2856  *  dump system memory info
 2857  */
 2858 void log_system_mem_info(void)
 2859 {
 2860 #if defined(HAVE_SYS_SYSINFO_H) && \
 2861     defined(HAVE_SYSINFO) && \
 2862     defined(HAVE_SYSLOG_H)
 2863     struct sysinfo info;
 2864 
 2865     if (sysinfo(&info) == 0) {
 2866         syslog(LOG_INFO, "memory (MB): total %.2f, "
 2867             "free %.2f, "
 2868             "shared %.2f, "
 2869             "buffer %.2f, "
 2870             "swap %.2f, "
 2871             "free swap %.2f\n",
 2872             (double)(info.totalram * info.mem_unit) / MB,
 2873             (double)(info.freeram * info.mem_unit) / MB,
 2874             (double)(info.sharedram * info.mem_unit) / MB,
 2875             (double)(info.bufferram * info.mem_unit) / MB,
 2876             (double)(info.totalswap * info.mem_unit) / MB,
 2877             (double)(info.freeswap * info.mem_unit) / MB);
 2878     }
 2879 #endif
 2880 }
 2881 
 2882 /*
 2883  *  log_system_info()
 2884  *  dump system info
 2885  */
 2886 static void log_system_info(void)
 2887 {
 2888 #if defined(HAVE_UNAME) &&      \
 2889     defined(HAVE_SYS_UTSNAME_H) &&  \
 2890     defined(HAVE_SYSLOG_H)
 2891     struct utsname buf;
 2892 
 2893     if (uname(&buf) == 0) {
 2894         syslog(LOG_INFO, "system: '%s' %s %s %s %s\n",
 2895             buf.nodename,
 2896             buf.sysname,
 2897             buf.release,
 2898             buf.version,
 2899             buf.machine);
 2900     }
 2901 #endif
 2902 }
 2903 
 2904 /*
 2905  *  stress_map_shared()
 2906  *  mmap shared region, with an extra page at the end
 2907  *  that is marked read-only to stop accidental smashing
 2908  *  from a run-away stack expansion
 2909  */
 2910 static inline void stress_map_shared(const size_t len)
 2911 {
 2912     const size_t page_size = stress_get_pagesize();
 2913     const size_t sz = (len + (page_size << 1)) & ~(page_size - 1);
 2914 #if defined(HAVE_MPROTECT)
 2915     void *last_page;
 2916 #endif
 2917 
 2918     g_shared = (shared_t *)mmap(NULL, sz, PROT_READ | PROT_WRITE,
 2919         MAP_SHARED | MAP_ANON, -1, 0);
 2920     if (g_shared == MAP_FAILED) {
 2921         pr_err("Cannot mmap to shared memory region: errno=%d (%s)\n",
 2922             errno, strerror(errno));
 2923         free_procs();
 2924         exit(EXIT_FAILURE);
 2925     }
 2926 
 2927     /* Paraniod */
 2928     (void)memset(g_shared, 0, sz);
 2929     g_shared->length = sz;
 2930 
 2931 #if defined(HAVE_MPROTECT)
 2932     last_page = ((uint8_t *)g_shared) + sz - page_size;
 2933 
 2934     /* Make last page trigger a segfault if it is accessed */
 2935     (void)mprotect(last_page, page_size, PROT_NONE);
 2936 #elif defined(HAVE_MREMAP) && defined(MAP_FIXED)
 2937     {
 2938         void *new_last_page;
 2939 
 2940         /* Try to remap last page with PROT_NONE */
 2941         (void)munmap(last_page, page_size);
 2942         new_last_page = mmap(last_page, page_size, PROT_NONE,
 2943             MAP_SHARED | MAP_ANON | MAP_FIXED, -1, 0);
 2944 
 2945         /* Failed, retry read-only */
 2946         if (new_last_page == MAP_FAILED)
 2947             new_last_page = mmap(last_page, page_size, PROT_READ,
 2948                 MAP_SHARED | MAP_ANON | MAP_FIXED, -1, 0);
 2949         /* Can't remap, bump length down a page */
 2950         if (new_last_page == MAP_FAILED)
 2951             g_shared->length -= sz;
 2952     }
 2953 #endif
 2954 }
 2955 
 2956 /*
 2957  *  stress_unmap_shared()
 2958  *  unmap shared region
 2959  */
 2960 void stress_unmap_shared(void)
 2961 {
 2962     (void)munmap((void *)g_shared, g_shared->length);
 2963 }
 2964 
 2965 /*
 2966  *  exclude_unsupported()
 2967  *  tag stressor proc count to be excluded
 2968  */
 2969 static inline void exclude_unsupported(void)
 2970 {
 2971     size_t i;
 2972 
 2973     for (i = 0; i < SIZEOF_ARRAY(stressors); i++) {
 2974         if (stressors[i].info && stressors[i].info->supported) {
 2975             proc_info_t *pi = procs_head;
 2976             stress_id_t id = stressors[i].id;
 2977 
 2978             while (pi) {
 2979                 proc_info_t *next = pi->next;
 2980 
 2981                 if ((pi->stressor->id == id) &&
 2982                     pi->num_procs &&
 2983                     (stressors[i].info->supported() < 0)) {
 2984                     remove_proc(pi);
 2985                     g_unsupported = true;
 2986                 }
 2987                 pi = next;
 2988             }
 2989         }
 2990     }
 2991 }
 2992 
 2993 /*
 2994  *  set_proc_limits()
 2995  *  set maximum number of processes for specific stressors
 2996  */
 2997 static void set_proc_limits(void)
 2998 {
 2999 #if defined(RLIMIT_NPROC)
 3000     proc_info_t *pi;
 3001     struct rlimit limit;
 3002 
 3003     if (getrlimit(RLIMIT_NPROC, &limit) < 0)
 3004         return;
 3005 
 3006     for (pi = procs_head; pi; pi = pi->next) {
 3007         size_t i;
 3008 
 3009         for (i = 0; i < SIZEOF_ARRAY(stressors); i++) {
 3010             if (stressors[i].info &&
 3011                 stressors[i].info->set_limit &&
 3012                 (stressors[i].id == pi->stressor->id) &&
 3013                 pi->num_procs) {
 3014                 const uint64_t max = (uint64_t)limit.rlim_cur / pi->num_procs;
 3015 
 3016                 stressors[i].info->set_limit(max);
 3017             }
 3018         }
 3019     }
 3020 #endif
 3021 }
 3022 
 3023 /*
 3024  *  find_proc_info()
 3025  *  find proc info that is associated with a specific
 3026  *  stressor.  If it does not exist, create a new one
 3027  *  and return that. Terminate if out of memory.
 3028  */
 3029 static proc_info_t *find_proc_info(const stress_t *stressor)
 3030 {
 3031     proc_info_t *pi;
 3032 
 3033 #if 0
 3034     /* Scan backwards in time to find last matching stressor */
 3035     for (pi = procs_tail; pi; pi = pi->prev) {
 3036         if (pi->stressor == stressor)
 3037             return pi;
 3038     }
 3039 #endif
 3040 
 3041     pi = calloc(1, sizeof(*pi));
 3042     if (!pi) {
 3043         (void)fprintf(stderr, "Cannot allocate stressor state info\n");
 3044         exit(EXIT_FAILURE);
 3045     }
 3046 
 3047     pi->stressor = stressor;
 3048 
 3049     /* Add to end of procs list */
 3050     if (procs_tail)
 3051         procs_tail->next = pi;
 3052     else
 3053         procs_head = pi;
 3054     pi->prev = procs_tail;
 3055     procs_tail = pi;
 3056 
 3057     return pi;
 3058 }
 3059 
 3060 /*
 3061  *  stressors_init()
 3062  *  initialize any stressors that will be used
 3063  */
 3064 static void stressors_init(void)
 3065 {
 3066     proc_info_t *pi;
 3067 
 3068     for (pi = procs_head; pi; pi = pi->next) {
 3069         size_t i;
 3070 
 3071         for (i = 0; i < SIZEOF_ARRAY(stressors); i++) {
 3072             if (stressors[i].info &&
 3073                 stressors[i].info->init &&
 3074                 stressors[i].id == pi->stressor->id)
 3075                 stressors[i].info->init();
 3076         }
 3077     }
 3078 }
 3079 
 3080 /*
 3081  *  stressors_deinit()
 3082  *  de-initialize any stressors that will be used
 3083  */
 3084 static void stressors_deinit(void)
 3085 {
 3086     proc_info_t *pi;
 3087 
 3088     for (pi = procs_head; pi; pi = pi->next) {
 3089         size_t i;
 3090 
 3091         for (i = 0; i < SIZEOF_ARRAY(stressors); i++) {
 3092             if (stressors[i].info &&
 3093                 stressors[i].info->deinit &&
 3094                 stressors[i].id == pi->stressor->id)
 3095                 stressors[i].info->deinit();
 3096         }
 3097     }
 3098 }
 3099 
 3100 
 3101 /*
 3102  *  stessor_set_defaults()
 3103  *  set up stressor default settings that can be overridden
 3104  *  by user later on
 3105  */
 3106 static inline void stressor_set_defaults(void)
 3107 {
 3108     size_t i;
 3109 
 3110     for (i = 0; i < SIZEOF_ARRAY(stressors); i++) {
 3111         if (stressors[i].info && stressors[i].info->set_default) {
 3112             stressors[i].info->set_default();
 3113         }
 3114     }
 3115 }
 3116 
 3117 /*
 3118  *  exclude_pathological()
 3119  *  Disable pathological stressors if user has not explicitly
 3120  *  request them to be used. Let's play safe.
 3121  */
 3122 static inline void exclude_pathological(void)
 3123 {
 3124     if (!(g_opt_flags & OPT_FLAGS_PATHOLOGICAL)) {
 3125         proc_info_t *pi = procs_head;
 3126 
 3127         while (pi) {
 3128             proc_info_t *next = pi->next;
 3129 
 3130             if (pi->stressor->info->class & CLASS_PATHOLOGICAL) {
 3131                 if (pi->num_procs > 0) {
 3132                     pr_inf("disabled '%s' as it "
 3133                         "may hang or reboot the machine "
 3134                         "(enable it with the "
 3135                         "--pathological option)\n",
 3136                         stress_munge_underscore(pi->stressor->name));
 3137                 }
 3138                 remove_proc(pi);
 3139             }
 3140             pi = next;
 3141         }
 3142     }
 3143 }
 3144 
 3145 /*
 3146  *  setup_stats_buffers()
 3147  *  setup the stats data from the shared memory
 3148  */
 3149 static inline void setup_stats_buffers(void)
 3150 {
 3151     proc_info_t *pi;
 3152     proc_stats_t *stats = g_shared->stats;
 3153 
 3154     for (pi = procs_head; pi; pi = pi->next) {
 3155         int32_t j;
 3156 
 3157         for (j = 0; j < pi->num_procs; j++, stats++)
 3158             pi->stats[j] = stats;
 3159     }
 3160 }
 3161 
 3162 /*
 3163  *  set_random_stressors()
 3164  *  select stressors at random
 3165  */
 3166 static inline void set_random_stressors(void)
 3167 {
 3168     int32_t opt_random = 0;
 3169 
 3170     (void)get_setting("random", &opt_random);
 3171 
 3172     if (g_opt_flags & OPT_FLAGS_RANDOM) {
 3173         int32_t n = opt_random;
 3174         int32_t n_procs = get_num_procs();
 3175 
 3176         if (g_opt_flags & OPT_FLAGS_SET) {
 3177             (void)fprintf(stderr, "Cannot specify random "
 3178                 "option with other stress processes "
 3179                 "selected\n");
 3180             exit(EXIT_FAILURE);
 3181         }
 3182 
 3183         if (!n_procs)
 3184             n_procs = 1;
 3185 
 3186         /* create n randomly chosen stressors */
 3187         while (n > 0) {
 3188             int32_t rnd = mwc32() % ((opt_random >> 5) + 2);
 3189             int32_t i = mwc32() % n_procs;
 3190             proc_info_t *pi = get_nth_proc(i);
 3191 
 3192             if (!pi)
 3193                 continue;
 3194 
 3195             if (rnd > n)
 3196                 rnd = n;
 3197             pi->num_procs += rnd;
 3198             n -= rnd;
 3199         }
 3200     }
 3201 }
 3202 
 3203 /*
 3204  *  enable_all_stressors()
 3205  *  enable all the stressors
 3206  */
 3207 static void enable_all_stressors(const uint32_t instances)
 3208 {
 3209     size_t i;
 3210 
 3211     /* Don't enable all if some stressors are set */
 3212     if (g_opt_flags & OPT_FLAGS_SET)
 3213         return;
 3214 
 3215     for (i = 0; i < STRESS_MAX; i++) {
 3216         proc_info_t *pi = find_proc_info(&stressors[i]);
 3217 
 3218         if (!pi) {
 3219             (void)fprintf(stderr, "Cannot allocate stressor state info\n");
 3220             exit(EXIT_FAILURE);
 3221         }
 3222         pi->num_procs = instances;
 3223     }
 3224 }
 3225 
 3226 /*
 3227  *  enable_classes()
 3228  *  enable stressors based on class
 3229  */
 3230 static void enable_classes(const uint32_t class)
 3231 {
 3232     size_t i;
 3233 
 3234     if (!class)
 3235         return;
 3236 
 3237     /* This indicates some stressors are set */
 3238     g_opt_flags |= OPT_FLAGS_SET;
 3239 
 3240     for (i = 0; stressors[i].id != STRESS_MAX; i++) {
 3241         if (stressors[i].info->class & class) {
 3242             proc_info_t *pi = find_proc_info(&stressors[i]);
 3243 
 3244             if (g_opt_flags & OPT_FLAGS_SEQUENTIAL)
 3245                 pi->num_procs = g_opt_sequential;
 3246             if (g_opt_flags & OPT_FLAGS_ALL)
 3247                 pi->num_procs = g_opt_parallel;
 3248         }
 3249     }
 3250 }
 3251 
 3252 
 3253 /*
 3254  *  parse_opts
 3255  *  parse argv[] and set stress-ng options accordingly
 3256  */
 3257 int parse_opts(int argc, char **argv, const bool jobmode)
 3258 {
 3259     optind = 0;
 3260 
 3261     for (;;) {
 3262         int64_t i64;
 3263         int32_t i32;
 3264         uint32_t u32;
 3265         int16_t i16;
 3266         int c, option_index, ret;
 3267         size_t i;
 3268 
 3269         opterr = (!jobmode)? opterr: 0;
 3270 next_opt:
 3271         if ((c = getopt_long(argc, argv, "?khMVvqnt:b:c:i:j:m:d:f:s:l:p:P:C:S:a:y:F:D:T:u:o:r:B:R:Y:x:",
 3272             long_options, &option_index)) == -1) {
 3273             break;
 3274         }
 3275 
 3276         for (i = 0; stressors[i].id != STRESS_MAX; i++) {
 3277             if (stressors[i].short_getopt == c) {
 3278                 const char *name = opt_name(c);
 3279                 proc_info_t *pi = find_proc_info(&stressors[i]);
 3280                 proc_current = pi;
 3281 
 3282                 g_opt_flags |= OPT_FLAGS_SET;
 3283                 pi->num_procs = get_int32(optarg);
 3284                 stress_get_processors(&pi->num_procs);
 3285                 check_value(name, pi->num_procs);
 3286 
 3287                 goto next_opt;
 3288             }
 3289             if (stressors[i].op == (stress_op_t)c) {
 3290                 uint64_t bogo_ops;
 3291 
 3292                 bogo_ops = get_uint64(optarg);
 3293                 check_range(opt_name(c), bogo_ops,
 3294                     MIN_OPS, MAX_OPS);
 3295                 /* We don't need to set this, but it may be useful */
 3296                 set_setting(opt_name(c), TYPE_ID_UINT64, &bogo_ops);
 3297                 if (proc_current)
 3298                     proc_current->bogo_ops = bogo_ops;
 3299                 goto next_opt;
 3300             }
 3301         }
 3302 
 3303         for (i = 0; i < SIZEOF_ARRAY(opt_flags); i++) {
 3304             if (c == opt_flags[i].opt) {
 3305                 g_opt_flags |= opt_flags[i].opt_flag;
 3306                 goto next_opt;
 3307             }
 3308         }
 3309         for (i = 0; i < SIZEOF_ARRAY(opt_set_funcs); i++) {
 3310             if (c == opt_set_funcs[i].opt) {
 3311                 ret = opt_set_funcs[i].opt_set_func(optarg);
 3312                 if (ret < 0)
 3313                     return EXIT_FAILURE;
 3314                 goto next_opt;
 3315             }
 3316         }
 3317 
 3318         switch (c) {
 3319         case OPT_all:
 3320             g_opt_flags |= OPT_FLAGS_ALL;
 3321             g_opt_parallel = get_int32(optarg);
 3322             stress_get_processors(&g_opt_parallel);
 3323             check_value("all", g_opt_parallel);
 3324             break;
 3325         case OPT_backoff:
 3326             i64 = (int64_t)get_uint64(optarg);
 3327             set_setting_global("backoff", TYPE_ID_INT64, &i64);
 3328             break;
 3329         case OPT_cache_level:
 3330             /*
 3331              * Note: Overly high values will be caught in the
 3332              * caching code.
 3333              */
 3334             i16 = atoi(optarg);
 3335             if ((i16 <= 0) || (i16 > 3))
 3336                 i16 = DEFAULT_CACHE_LEVEL;
 3337             set_setting("cache-level", TYPE_ID_INT16, &i16);
 3338             break;
 3339         case OPT_cache_ways:
 3340             u32 = get_uint32(optarg);
 3341             set_setting("cache-ways", TYPE_ID_UINT32, &u32);
 3342             break;
 3343         case OPT_class:
 3344             ret = get_class(optarg, &u32);
 3345             if (ret < 0)
 3346                 return EXIT_FAILURE;
 3347             else if (ret > 0)
 3348                 exit(EXIT_SUCCESS);
 3349             else {
 3350                 set_setting("class", TYPE_ID_UINT32, &u32);
 3351                 enable_classes(u32);
 3352             }
 3353             break;
 3354         case OPT_exclude:
 3355             set_setting_global("exclude", TYPE_ID_STR, (void *)optarg);
 3356             break;
 3357         case OPT_help:
 3358             usage();
 3359             break;
 3360         case OPT_ionice_class:
 3361             i32 = get_opt_ionice_class(optarg);
 3362             set_setting("ionice-class", TYPE_ID_INT32, &i32);
 3363             break;
 3364         case OPT_ionice_level:
 3365             i32 = get_int32(optarg);
 3366             set_setting("ionice-level", TYPE_ID_INT32, &i32);
 3367             break;
 3368         case OPT_job:
 3369             set_setting_global("job", TYPE_ID_STR, (void *)optarg);
 3370             break;
 3371         case OPT_log_file:
 3372             set_setting_global("log-file", TYPE_ID_STR, (void *)optarg);
 3373             break;
 3374         case OPT_no_madvise:
 3375             g_opt_flags &= ~OPT_FLAGS_MMAP_MADVISE;
 3376             break;
 3377         case OPT_query:
 3378             if (!jobmode) {
 3379                 (void)printf("Try '%s --help' for more information.\n", g_app_name);
 3380             }
 3381             return EXIT_FAILURE;
 3382             break;
 3383         case OPT_quiet:
 3384             g_opt_flags &= ~(PR_ALL);
 3385             break;
 3386         case OPT_random:
 3387             g_opt_flags |= OPT_FLAGS_RANDOM;
 3388             i32 = get_int32(optarg);
 3389             check_value("random", i32);
 3390             stress_get_processors(&i32);
 3391             set_setting("random", TYPE_ID_INT32, &i32);
 3392             break;
 3393         case OPT_sched:
 3394             i32 = get_opt_sched(optarg);
 3395             set_setting_global("sched", TYPE_ID_INT32, &i32);
 3396             break;
 3397         case OPT_sched_prio:
 3398             i32 = get_int32(optarg);
 3399             set_setting_global("sched-prio", TYPE_ID_INT32, &i32);
 3400             break;
 3401         case OPT_sequential:
 3402             g_opt_flags |= OPT_FLAGS_SEQUENTIAL;
 3403             g_opt_sequential = get_int32(optarg);
 3404             stress_get_processors(&g_opt_sequential);
 3405             check_range("sequential", g_opt_sequential,
 3406                 MIN_SEQUENTIAL, MAX_SEQUENTIAL);
 3407             break;
 3408         case OPT_stressors:
 3409             show_stressor_names();
 3410             exit(EXIT_SUCCESS);
 3411         case OPT_timeout:
 3412             g_opt_timeout = get_uint64_time(optarg);
 3413             break;
 3414         case OPT_version:
 3415             version();
 3416             exit(EXIT_SUCCESS);
 3417 #if defined(MAP_LOCKED)
 3418         case OPT_vm_mmap_locked:
 3419             stress_set_vm_flags(MAP_LOCKED);
 3420             break;
 3421 #endif
 3422 #if defined(MAP_POPULATE)
 3423         case OPT_vm_mmap_populate:
 3424             stress_set_vm_flags(MAP_POPULATE);
 3425             break;
 3426 #endif
 3427         case OPT_yaml:
 3428             set_setting_global("yaml", TYPE_ID_STR, (void *)optarg);
 3429             break;
 3430         default:
 3431             if (!jobmode)
 3432                 (void)printf("Unknown option (%d)\n",c);
 3433             return EXIT_FAILURE;
 3434         }
 3435     }
 3436     return EXIT_SUCCESS;
 3437 }
 3438 
 3439 /*
 3440  *  alloc_proc_resources()
 3441  *  allocate array of pids based on n pids required
 3442  */
 3443 static void alloc_proc_resources(pid_t **pids, proc_stats_t ***stats, size_t n)
 3444 {
 3445     *pids = calloc(n, sizeof(pid_t));
 3446     if (!*pids) {
 3447         pr_err("cannot allocate pid list\n");
 3448         free_procs();
 3449         exit(EXIT_FAILURE);
 3450     }
 3451 
 3452     *stats = calloc(n, sizeof(proc_stats_t *));
 3453     if (!*stats) {
 3454         pr_err("cannot allocate stats list\n");
 3455         free(*pids);
 3456         *pids = NULL;
 3457         free_procs();
 3458         exit(EXIT_FAILURE);
 3459     }
 3460 }
 3461 
 3462 /*
 3463  *  set_default_timeout()
 3464  *  set timeout to a default value if not already set
 3465  */
 3466 static void set_default_timeout(const uint64_t timeout)
 3467 {
 3468     if (g_opt_timeout == TIMEOUT_NOT_SET) {
 3469         g_opt_timeout = timeout;
 3470         pr_inf("defaulting to a %" PRIu64 " second%s run per stressor\n",
 3471             g_opt_timeout,
 3472             duration_to_str((double)g_opt_timeout));
 3473     }
 3474 }
 3475 
 3476 /*
 3477  *  stress_setup_sequential()
 3478  *  setup for sequential --seq mode stressors
 3479  */
 3480 static void stress_setup_sequential(const uint32_t class)
 3481 {
 3482     proc_info_t *pi;
 3483 
 3484     set_default_timeout(60);
 3485 
 3486     for (pi = procs_head; pi; pi = pi->next) {
 3487         if (pi->stressor->info->class & class)
 3488             pi->num_procs = g_opt_sequential;
 3489         alloc_proc_resources(&pi->pids, &pi->stats, pi->num_procs);
 3490     }
 3491 }
 3492 
 3493 /*
 3494  *  stress_setup_parallel()
 3495  *  setup for parallel mode stressors
 3496  */
 3497 static void stress_setup_parallel(const uint32_t class)
 3498 {
 3499     proc_info_t *pi;
 3500 
 3501     set_default_timeout(DEFAULT_TIMEOUT);
 3502 
 3503     for (pi = procs_head; pi; pi = pi->next) {
 3504         if (pi->stressor->info->class & class)
 3505             pi->num_procs = g_opt_parallel;
 3506         /*
 3507          * Share bogo ops between processes equally, rounding up
 3508          * if nonzero bogo_ops
 3509          */
 3510         pi->bogo_ops = pi->num_procs ?
 3511             (pi->bogo_ops + (pi->num_procs - 1)) / pi->num_procs : 0;
 3512         if (pi->num_procs)
 3513             alloc_proc_resources(&pi->pids, &pi->stats, pi->num_procs);
 3514     }
 3515 }
 3516 
 3517 /*
 3518  *  stress_run_sequential()
 3519  *  run stressors sequentially
 3520  */
 3521 static inline void stress_run_sequential(
 3522     double *duration,
 3523     bool *success,
 3524     bool *resource_success)
 3525 {
 3526     proc_info_t *pi;
 3527 
 3528     /*
 3529      *  Step through each stressor one by one
 3530      */
 3531     for (pi = procs_head; pi && g_keep_stressing_flag; pi = pi->next) {
 3532         proc_info_t *next = pi->next;
 3533 
 3534         pi->next = NULL;
 3535         stress_run(pi, duration, success, resource_success);
 3536         pi->next = next;
 3537 
 3538     }
 3539 }
 3540 
 3541 /*
 3542  *  stress_run_parallel()
 3543  *  run stressors in parallel
 3544  */
 3545 static inline void stress_run_parallel(
 3546     double *duration,
 3547     bool *success,
 3548     bool *resource_success)
 3549 {
 3550     /*
 3551      *  Run all stressors in parallel
 3552      */
 3553     stress_run(procs_head, duration, success, resource_success);
 3554 }
 3555 
 3556 /*
 3557  *  stress_mlock_executable()
 3558  *  try to mlock image into memory so it
 3559  *  won't get swapped out
 3560  */
 3561 static inline void stress_mlock_executable(void)
 3562 {
 3563 #if defined(MLOCKED_SECTION)
 3564     extern void *__start_mlocked_text;
 3565     extern void *__stop_mlocked_text;
 3566     extern void *__start_mlocked_data;
 3567     extern void *__stop_mlocked_data;
 3568 
 3569     stress_mlock_region(&__start_mlocked_text, &__stop_mlocked_text);
 3570     stress_mlock_region(&__start_mlocked_data, &__stop_mlocked_data);
 3571 #endif
 3572 }
 3573 
 3574 int main(int argc, char **argv)
 3575 {
 3576     double duration = 0.0;          /* stressor run time in secs */
 3577     size_t len;
 3578     bool success = true, resource_success = true;
 3579     FILE *yaml;             /* YAML output file */
 3580     char *yaml_filename;            /* YAML file name */
 3581     char *log_filename;         /* log filename */
 3582     char *job_filename = NULL;      /* job filename */
 3583     int32_t ticks_per_sec;          /* clock ticks per second (jiffies) */
 3584     int32_t sched = UNDEFINED;      /* scheduler type */
 3585     int32_t sched_prio = UNDEFINED;     /* scheduler priority */
 3586     int32_t ionice_class = UNDEFINED;   /* ionice class */
 3587     int32_t ionice_level = UNDEFINED;   /* ionice level */
 3588     int32_t i;
 3589     uint32_t class = 0;
 3590     const uint32_t cpus_online = stress_get_processors_online();
 3591     const uint32_t cpus_configured = stress_get_processors_configured();
 3592     int ret;
 3593 
 3594     if (setjmp(g_error_env) == 1)
 3595         exit(EXIT_FAILURE);
 3596 
 3597     yaml = NULL;
 3598 
 3599     /* --exec stressor uses this to exec itself and then exit early */
 3600     if ((argc == 2) && !strcmp(argv[1], "--exec-exit"))
 3601         exit(EXIT_SUCCESS);
 3602 
 3603     procs_head = NULL;
 3604     procs_tail = NULL;
 3605     mwc_reseed();
 3606 
 3607     (void)stress_get_pagesize();
 3608     stressor_set_defaults();
 3609     g_pgrp = getpid();
 3610 
 3611     if (stress_get_processors_configured() < 0) {
 3612         pr_err("sysconf failed, number of cpus configured "
 3613             "unknown: errno=%d: (%s)\n",
 3614             errno, strerror(errno));
 3615         exit(EXIT_FAILURE);
 3616     }
 3617     ticks_per_sec = stress_get_ticks_per_second();
 3618     if (ticks_per_sec < 0) {
 3619         pr_err("sysconf failed, clock ticks per second "
 3620             "unknown: errno=%d (%s)\n",
 3621             errno, strerror(errno));
 3622         exit(EXIT_FAILURE);
 3623     }
 3624 
 3625     ret = parse_opts(argc, argv, false);
 3626     if (ret != EXIT_SUCCESS)
 3627         exit(ret);
 3628 
 3629     /*
 3630      *  Sanity check minimize/maximize options
 3631      */
 3632     if ((g_opt_flags & OPT_FLAGS_MINMAX_MASK) == OPT_FLAGS_MINMAX_MASK) {
 3633         (void)fprintf(stderr, "maximize and minimize cannot "
 3634             "be used together\n");
 3635         exit(EXIT_FAILURE);
 3636     }
 3637 
 3638     /*
 3639      *  Sanity check seq/all settings
 3640      */
 3641     if ((g_opt_flags & (OPT_FLAGS_SEQUENTIAL | OPT_FLAGS_ALL)) ==
 3642         (OPT_FLAGS_SEQUENTIAL | OPT_FLAGS_ALL)) {
 3643         (void)fprintf(stderr, "cannot invoke --sequential and --all "
 3644             "options together\n");
 3645         exit(EXIT_FAILURE);
 3646     }
 3647     (void)get_setting("class", &class);
 3648     if (class &&
 3649         !(g_opt_flags & (OPT_FLAGS_SEQUENTIAL | OPT_FLAGS_ALL))) {
 3650         (void)fprintf(stderr, "class option is only used with "
 3651             "--sequential or --all options\n");
 3652         exit(EXIT_FAILURE);
 3653     }
 3654 
 3655     /*
 3656      *  Setup logging
 3657      */
 3658     if (get_setting("log-file", &log_filename))
 3659         pr_openlog(log_filename);
 3660     openlog("stress-ng", 0, LOG_USER);
 3661     log_args(argc, argv);
 3662     log_system_info();
 3663     log_system_mem_info();
 3664 
 3665     pr_dbg("%" PRId32 " processor%s online, %" PRId32
 3666         " processor%s configured\n",
 3667         cpus_online, cpus_online == 1 ? "" : "s",
 3668         cpus_configured, cpus_configured == 1 ? "" : "s");
 3669 
 3670     /*
 3671      *  These two options enable all the stressors
 3672      */
 3673     if (g_opt_flags & OPT_FLAGS_SEQUENTIAL)
 3674         enable_all_stressors(g_opt_sequential);
 3675     if (g_opt_flags & OPT_FLAGS_ALL)
 3676         enable_all_stressors(g_opt_parallel);
 3677 
 3678     /*
 3679      *  Discard stressors that we can't run
 3680      */
 3681     exclude_unsupported();
 3682     exclude_pathological();
 3683     /*
 3684      *  Throw away excluded stressors
 3685      */
 3686     if (stress_exclude() < 0)
 3687         exit(EXIT_FAILURE);
 3688 
 3689     /*
 3690      *  Setup random stressors if requested
 3691      */
 3692     set_random_stressors();
 3693 
 3694 #if defined(STRESS_PERF_STATS) && defined(HAVE_LINUX_PERF_EVENT_H)
 3695     if (g_opt_flags & OPT_FLAGS_PERF_STATS)
 3696         perf_init();
 3697 #endif
 3698 
 3699     /*
 3700      *  Setup running environment
 3701      */
 3702     stress_process_dumpable(false);
 3703     stress_cwd_readwriteable();
 3704     set_oom_adjustment("main", false);
 3705 
 3706     /*
 3707      *  Get various user defined settings
 3708      */
 3709     (void)get_setting("sched", &sched);
 3710     (void)get_setting("sched-prio", &sched_prio);
 3711     if (stress_set_sched(getpid(), sched, sched_prio, false) < 0)
 3712         exit(EXIT_FAILURE);
 3713     (void)get_setting("ionice-class", &ionice_class);
 3714     (void)get_setting("ionice-level", &ionice_level);
 3715     set_iopriority(ionice_class, ionice_level);
 3716 
 3717     stress_mlock_executable();
 3718 
 3719     /*
 3720      *  Enable signal handers
 3721      */
 3722     for (i = 0; terminate_signals[i] != -1; i++) {
 3723         if (stress_sighandler("stress-ng", terminate_signals[i], handle_terminate, NULL) < 0)
 3724             exit(EXIT_FAILURE);
 3725     }
 3726 
 3727     /*
 3728      *  Load in job file options
 3729      */
 3730     (void)get_setting("job", &job_filename);
 3731     if (parse_jobfile(argc, argv, job_filename) < 0)
 3732         exit(EXIT_FAILURE);
 3733 
 3734     /*
 3735      *  Setup stressor proc info
 3736      */
 3737     if (g_opt_flags & OPT_FLAGS_SEQUENTIAL) {
 3738         stress_setup_sequential(class);
 3739     } else {
 3740         stress_setup_parallel(class);
 3741     }
 3742 
 3743     set_proc_limits();
 3744 
 3745     if (!procs_head) {
 3746         pr_err("No stress workers invoked%s\n",
 3747             g_unsupported ? " (one or more were unsupported)" : "");
 3748         free_procs();
 3749         /*
 3750          *  If some stressors were given but marked as
 3751          *  unsupported then this is not an error.
 3752          */
 3753         exit(g_unsupported ? EXIT_SUCCESS : EXIT_FAILURE);
 3754     }
 3755 
 3756     /*
 3757      *  Show the stressors we're going to run
 3758      */
 3759     if (show_stressors() < 0) {
 3760         free_procs();
 3761         exit(EXIT_FAILURE);
 3762     }
 3763 
 3764     /*
 3765      *  Allocate shared memory segment for shared data
 3766      *  across all the child stressors
 3767      */
 3768     len = sizeof(shared_t) + (sizeof(proc_stats_t) * get_total_num_procs(procs_head));
 3769     stress_map_shared(len);
 3770 
 3771     /*
 3772      *  Setup spinlocks
 3773      */
 3774 #if defined(STRESS_PERF_STATS) && defined(HAVE_LINUX_PERF_EVENT_H)
 3775     shim_pthread_spin_init(&g_shared->perf.lock, 0);
 3776 #endif
 3777 #if defined(HAVE_LIB_PTHREAD)
 3778     shim_pthread_spin_init(&g_shared->warn_once.lock, 0);
 3779 #endif
 3780 
 3781     /*
 3782      *  Assign procs with shared stats memory
 3783      */
 3784     setup_stats_buffers();
 3785 
 3786     /*
 3787      *  Allocate shared cache memory
 3788      */
 3789     g_shared->mem_cache_level = DEFAULT_CACHE_LEVEL;
 3790     (void)get_setting("cache-level", &g_shared->mem_cache_level);
 3791     g_shared->mem_cache_ways = 0;
 3792     (void)get_setting("cache-ways", &g_shared->mem_cache_ways);
 3793     if (stress_cache_alloc("cache allocate") < 0) {
 3794         stress_unmap_shared();
 3795         free_procs();
 3796         exit(EXIT_FAILURE);
 3797     }
 3798 
 3799 #if defined(STRESS_THERMAL_ZONES)
 3800     /*
 3801      *  Setup thermal zone data
 3802      */
 3803     if (g_opt_flags & OPT_FLAGS_THERMAL_ZONES)
 3804         tz_init(&g_shared->tz_info);
 3805 #endif
 3806 
 3807     stressors_init();
 3808 
 3809     /* Start thrasher process if required */
 3810     if (g_opt_flags & OPT_FLAGS_THRASH)
 3811         thrash_start();
 3812 
 3813     if (g_opt_flags & OPT_FLAGS_SEQUENTIAL) {
 3814         stress_run_sequential(&duration,
 3815             &success, &resource_success);
 3816     } else {
 3817         stress_run_parallel(&duration,
 3818             &success, &resource_success);
 3819     }
 3820 
 3821     /* Stop thasher process */
 3822     if (g_opt_flags & OPT_FLAGS_THRASH)
 3823         thrash_stop();
 3824 
 3825     pr_inf("%s run completed in %.2fs%s\n",
 3826         success ? "successful" : "unsuccessful",
 3827         duration, duration_to_str(duration));
 3828 
 3829     /*
 3830      *  Save results to YAML file
 3831      */
 3832     if (get_setting("yaml", &yaml_filename)) {
 3833         yaml= fopen(yaml_filename, "w");
 3834         if (!yaml)
 3835             pr_err("Cannot output YAML data to %s\n", yaml_filename);
 3836 
 3837         pr_yaml(yaml, "---\n");
 3838         pr_yaml_runinfo(yaml);
 3839     }
 3840 
 3841     /*
 3842      *  Dump metrics
 3843      */
 3844     if (g_opt_flags & OPT_FLAGS_METRICS)
 3845         metrics_dump(yaml, ticks_per_sec);
 3846 
 3847 #if defined(STRESS_PERF_STATS) && defined(HAVE_LINUX_PERF_EVENT_H)
 3848     /*
 3849      *  Dump perf statistics
 3850      */
 3851     if (g_opt_flags & OPT_FLAGS_PERF_STATS)
 3852         perf_stat_dump(yaml, procs_head, duration);
 3853 #endif
 3854 
 3855 #if defined(STRESS_THERMAL_ZONES)
 3856     /*
 3857      *  Dump thermal zone measurements
 3858      */
 3859     if (g_opt_flags & OPT_FLAGS_THERMAL_ZONES) {
 3860         tz_dump(yaml, procs_head);
 3861         tz_free(&g_shared->tz_info);
 3862     }
 3863 #endif
 3864     /*
 3865      *  Dump run times
 3866      */
 3867     if (g_opt_flags & OPT_FLAGS_TIMES)
 3868         times_dump(yaml, ticks_per_sec, duration);
 3869 
 3870     /*
 3871      *  Tidy up
 3872      */
 3873     free_procs();
 3874     stressors_deinit();
 3875     stress_cache_free();
 3876     stress_unmap_shared();
 3877     free_settings();
 3878 
 3879     /*
 3880      *  Close logs
 3881      */
 3882     closelog();
 3883     pr_closelog();
 3884     if (yaml) {
 3885         pr_yaml(yaml, "...\n");
 3886         (void)fclose(yaml);
 3887     }
 3888 
 3889     /*
 3890      *  Done!
 3891      */
 3892     if (!success)
 3893         exit(EXIT_NOT_SUCCESS);
 3894     if (!resource_success)
 3895         exit(EXIT_NO_RESOURCE);
 3896     exit(EXIT_SUCCESS);
 3897 }