"Fossies" - the Fresh Open Source Software Archive

Member "stress-ng-0.09.56/stress-ng.h" (15 Mar 2019, 92214 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.h" 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 #ifndef __STRESS_NG_H__
   26 #define __STRESS_NG_H__
   27 
   28 #define _GNU_SOURCE
   29 #define _ATFILE_SOURCE
   30 #ifndef _LARGEFILE_SOURCE
   31 #define _LARGEFILE_SOURCE
   32 #endif
   33 #ifndef _LARGEFILE64_SOURCE
   34 #define _LARGEFILE64_SOURCE
   35 #endif
   36 
   37 #if !defined(_FILE_OFFSET_BITS)
   38 #define _FILE_OFFSET_BITS   (64)
   39 #endif
   40 
   41 /* Some Solaris tool chains only define __sun */
   42 #if defined(__sun) && !defined(__sun__)
   43 #define __sun__
   44 #endif
   45 
   46 /*
   47  *  Standard includes
   48  */
   49 #include <ctype.h>
   50 #include <dirent.h>
   51 #include <errno.h>
   52 #include <fcntl.h>
   53 #include <getopt.h>
   54 #include <inttypes.h>
   55 #include <limits.h>
   56 #include <math.h>
   57 #include <pwd.h>
   58 #include <sched.h>
   59 #include <search.h>
   60 #include <setjmp.h>
   61 #include <signal.h>
   62 #include <stdarg.h>
   63 #include <stdbool.h>
   64 #include <stddef.h>
   65 #include <stdint.h>
   66 #include <stdio.h>
   67 #include <stdlib.h>
   68 #include <string.h>
   69 #include <time.h>
   70 #include <unistd.h>
   71 
   72 /*
   73  *  Networking includes that are part of
   74  *  Single UNIX Specification V2
   75  */
   76 #include <arpa/inet.h>
   77 #include <netinet/in.h>
   78 #if defined(HAVE_NET_IF_H)
   79 #include <net/if.h>
   80 #endif
   81 #if defined(HAVE_NETINET_IP_H)
   82 #include <netinet/ip.h>
   83 #endif
   84 #if defined(HAVE_NETINET_IP_ICMP_H)
   85 #include <netinet/ip_icmp.h>
   86 #endif
   87 #if defined(HAVE_NETINET_TCP_H)
   88 #include <netinet/tcp.h>
   89 #endif
   90 #if defined(HAVE_NETINET_SCTP_H)
   91 #include <netinet/sctp.h>
   92 #endif
   93 
   94 #if defined(HAVE_AIO_H)
   95 #include <aio.h>
   96 #endif
   97 
   98 #if defined(HAVE_COMPLEX_H)
   99 #include <complex.h>
  100 #endif
  101 
  102 #if defined(HAVE_CPUID_H)
  103 #include <cpuid.h>
  104 #endif
  105 
  106 #if defined(HAVE_CRYPT_H)
  107 #include <crypt.h>
  108 #endif
  109 
  110 #if defined(HAVE_FEATURES_H)
  111 #include <features.h>
  112 #endif
  113 
  114 #if defined(HAVE_FENV_H)
  115 #include <fenv.h>
  116 #endif
  117 
  118 #if defined(HAVE_FLOAT_H)
  119 #include <float.h>
  120 #endif
  121 
  122 #if defined(HAVE_GRP_H)
  123 #include <grp.h>
  124 #endif
  125 
  126 #if defined(HAVE_INTEL_IPSEC_MB_H)
  127 #include <intel-ipsec-mb.h>
  128 #endif
  129 
  130 #if defined(HAVE_KEYUTILS_H)
  131 #include <keyutils.h>
  132 #endif
  133 
  134 #if defined(HAVE_LIBAIO_H)
  135 #include <libaio.h>
  136 #endif
  137 
  138 #if defined(HAVE_LIBGEN_H)
  139 #include <libgen.h>
  140 #endif
  141 
  142 #if defined(HAVE_LINK_H)
  143 #include <link.h>
  144 #endif
  145 
  146 #if defined(HAVE_LOCALE_H)
  147 #include <locale.h>
  148 #endif
  149 
  150 #if defined(HAVE_MALLOC_H)
  151 #include <malloc.h>
  152 #endif
  153 
  154 #if defined(HAVE_MNTENT_H)
  155 #include <mntent.h>
  156 #endif
  157 
  158 #if defined(HAVE_MQUEUE_H)
  159 #include <mqueue.h>
  160 #endif
  161 
  162 #if defined(HAVE_POLL_H)
  163 #include <poll.h>
  164 #endif
  165 
  166 #if defined(HAVE_LIB_PTHREAD)
  167 #include <pthread.h>
  168 #endif
  169 
  170 #if defined(HAVE_SEMAPHORE_H)
  171 #include <semaphore.h>
  172 #endif
  173 
  174 #if defined(HAVE_SPAWN_H)
  175 #include <spawn.h>
  176 #endif
  177 
  178 #if defined(HAVE_STRINGS_H)
  179 #include <strings.h>
  180 #endif
  181 
  182 #if defined(HAVE_SYSLOG_H)
  183 #include <syslog.h>
  184 #endif
  185 
  186 #if defined(HAVE_TERMIO_H)
  187 #include <termio.h>
  188 #endif
  189 
  190 #if defined(HAVE_TERMIOS_H)
  191 #include <termios.h>
  192 #endif
  193 
  194 #if defined(HAVE_UCONTEXT_H)
  195 #include <ucontext.h>
  196 #endif
  197 
  198 #if defined(HAVE_USTAT)
  199 #include <ustat.h>
  200 #endif
  201 
  202 #if defined(HAVE_UTIME_H)
  203 #include <utime.h>
  204 #endif
  205 
  206 #if defined(HAVE_WCHAR)
  207 #include <wchar.h>
  208 #endif
  209 
  210 #if defined(HAVE_SYS_TREE_H)
  211 #include <sys/tree.h>
  212 #endif
  213 
  214 #if defined(HAVE_BSD_STDLIB_H)
  215 #include <bsd/stdlib.h>
  216 #endif
  217 
  218 #if defined(HAVE_BSD_STRING_H)
  219 #include <bsd/string.h>
  220 #endif
  221 
  222 #if defined(HAVE_BSD_SYS_TREE_H)
  223 #include <bsd/sys/tree.h>
  224 #endif
  225 
  226 #if defined(HAVE_BSD_WCHAR)
  227 #include <bsd/wchar.h>
  228 #endif
  229 
  230 #if defined(HAVE_MODIFY_LDT)
  231 #include <asm/ldt.h>
  232 #endif
  233 
  234 /*
  235  *  Various sys include files
  236  */
  237 #include <sys/ioctl.h>
  238 #include <sys/file.h>
  239 #include <sys/mman.h>
  240 #include <sys/resource.h>
  241 #include <sys/socket.h>
  242 #include <sys/stat.h>
  243 #include <sys/time.h>
  244 #include <sys/times.h>
  245 #include <sys/types.h>
  246 #include <sys/wait.h>
  247 
  248 #if defined(HAVE_SYS_APPARMOR_H)
  249 #include <sys/apparmor.h>
  250 #endif
  251 
  252 #if defined(HAVE_SYS_AUXV_H)
  253 #include <sys/auxv.h>
  254 #endif
  255 
  256 #if defined(HAVE_SYS_CAPABILITY_H)
  257 #include <sys/capability.h>
  258 #endif
  259 
  260 #if defined(HAVE_SYS_EPOLL_H)
  261 #include <sys/epoll.h>
  262 #endif
  263 
  264 #if defined(HAVE_SYS_EVENTFD_H)
  265 #include <sys/eventfd.h>
  266 #endif
  267 
  268 #if defined(HAVE_SYS_FANOTIFY_H)
  269 #include <sys/fanotify.h>
  270 #endif
  271 
  272 #if defined(HAVE_SYS_IO_H)
  273 #include <sys/io.h>
  274 #endif
  275 
  276 #if defined(HAVE_SYS_IPC_H)
  277 #include <sys/ipc.h>
  278 #endif
  279 
  280 #if defined(HAVE_SYS_INOTIFY_H)
  281 #include <sys/inotify.h>
  282 #endif
  283 
  284 #if defined(HAVE_SYS_MEMFD_H)
  285 #include <sys/memfd.h>
  286 #endif
  287 
  288 #if defined(HAVE_SYS_MOUNT_H)
  289 #include <sys/mount.h>
  290 #endif
  291 
  292 #if defined(HAVE_SYS_PARAM_H)
  293 #include <sys/param.h>
  294 #endif
  295 
  296 #if defined(HAVE_SYS_MSG_H)
  297 #include <sys/msg.h>
  298 #endif
  299 
  300 #if defined(HAVE_SYS_PERSONALITY_H)
  301 #include <sys/personality.h>
  302 #endif
  303 
  304 #if defined(HAVE_SYS_PRCTL_H)
  305 #include <sys/prctl.h>
  306 #endif
  307 
  308 #if defined(HAVE_PTRACE)
  309 #include <sys/ptrace.h>
  310 #endif
  311 
  312 #if defined(HAVE_SYS_QUOTA_H)
  313 #include <sys/quota.h>
  314 #endif
  315 
  316 #if defined(__APPLE__)
  317 #include <sys/random.h>
  318 #endif
  319 
  320 #if defined(HAVE_SYS_SELECT_H)
  321 #include <sys/select.h>
  322 #endif
  323 
  324 #if defined(HAVE_SEM_SYSV)
  325 #include <sys/sem.h>
  326 #endif
  327 
  328 #if defined(HAVE_SYS_SENDFILE_H)
  329 #include <sys/sendfile.h>
  330 #endif
  331 
  332 #if defined(HAVE_SYS_SHM_H)
  333 #include <sys/shm.h>
  334 #endif
  335 
  336 #if defined(HAVE_SYS_SIGNALFD_H)
  337 #include <sys/signalfd.h>
  338 #endif
  339 
  340 #if defined(HAVE_SYS_STATFS_H)
  341 #include <sys/statfs.h>
  342 #endif
  343 
  344 #if defined(HAVE_SYS_STATVFS_H)
  345 #include <sys/statvfs.h>
  346 #endif
  347 
  348 #if defined(__sun__)
  349 /* Disable for SunOs/Solaris because */
  350 #undef HAVE_SYS_SWAP_H
  351 #endif
  352 #if defined(HAVE_SYS_SWAP_H)
  353 #include <sys/swap.h>
  354 #endif
  355 
  356 #if defined(HAVE_SYSCALL_H)
  357 #include <sys/syscall.h>
  358 #endif
  359 
  360 #if defined(HAVE_SYS_SYSINFO_H)
  361 #include <sys/sysinfo.h>
  362 #endif
  363 
  364 #if defined(HAVE_SYS_SYSMACROS_H)
  365 #include <sys/sysmacros.h>
  366 #endif
  367 
  368 #if defined(HAVE_SYS_TIMEX_H)
  369 #include <sys/timex.h>
  370 #endif
  371 
  372 #if defined(HAVE_SYS_TIMERFD_H)
  373 #include <sys/timerfd.h>
  374 #endif
  375 
  376 #if defined(HAVE_SYS_UCRED_H)
  377 #include <sys/ucred.h>
  378 #endif
  379 
  380 #if defined(HAVE_SYS_UIO_H)
  381 #include <sys/uio.h>
  382 #endif
  383 
  384 #if defined(HAVE_SYS_UN_H)
  385 #include <sys/un.h>
  386 #endif
  387 
  388 #if defined(HAVE_SYS_UTSNAME_H)
  389 #include <sys/utsname.h>
  390 #endif
  391 
  392 #if defined(HAVE_SYS_VFS_H)
  393 #include <sys/vfs.h>
  394 #endif
  395 
  396 
  397 /*
  398  *  SCSI related headers
  399  */
  400 #if defined(HAVE_SCSI_SCSI_H)
  401 #include <scsi/scsi.h>
  402 #endif
  403 
  404 #if defined(HAVE_SCSI_SG_H)
  405 #include <scsi/sg.h>
  406 #endif
  407 
  408 /*
  409  *  Linux specific includes
  410  */
  411 #if defined(HAVE_LINUX_AUDIT_H)
  412 #include <linux/audit.h>
  413 #endif
  414 
  415 #if defined(HAVE_LINUX_CN_PROC_H)
  416 #include <linux/cn_proc.h>
  417 #endif
  418 
  419 #if defined(HAVE_LINUX_CONNECTOR_H)
  420 #include <linux/connector.h>
  421 #endif
  422 
  423 #if defined(HAVE_LINUX_DM_IOCTL_H)
  424 #include <linux/dm-ioctl.h>
  425 #endif
  426 
  427 #if defined(HAVE_LINUX_HDREG_H)
  428 #include <linux/hdreg.h>
  429 #endif
  430 
  431 #if defined(HAVE_LINUX_IF_ALG_H)
  432 #include <linux/if_alg.h>
  433 #endif
  434 
  435 #if defined(HAVE_LINUX_FIEMAP_H)
  436 #include <linux/fiemap.h>
  437 #endif
  438 
  439 #if defined(HAVE_LINUX_FILTER_H)
  440 #include <linux/filter.h>
  441 #endif
  442 
  443 #if defined(HAVE_LINUX_FS_H)
  444 #include <linux/fs.h>
  445 #endif
  446 
  447 #if defined(HAVE_LINUX_FUTEX_H)
  448 #include <linux/futex.h>
  449 #endif
  450 
  451 #if defined(HAVE_LINUX_LOOP_H)
  452 #include <linux/loop.h>
  453 #endif
  454 
  455 #if defined(HAVE_LINUX_MEDIA_H)
  456 #include <linux/media.h>
  457 #endif
  458 
  459 #if defined(HAVE_LINUX_MEMBARRIER_H)
  460 #include <linux/membarrier.h>
  461 #endif
  462 
  463 #if defined(HAVE_LINUX_NETLINK_H)
  464 #include <linux/netlink.h>
  465 #endif
  466 
  467 #if defined(HAVE_LINUX_PERF_EVENT_H)
  468 #include <linux/perf_event.h>
  469 #endif
  470 
  471 #if defined(HAVE_LINUX_POSIX_TYPES_H)
  472 #include <linux/posix_types.h>
  473 #endif
  474 
  475 #if defined(HAVE_LINUX_RANDOM_H)
  476 #include <linux/random.h>
  477 #endif
  478 
  479 #if defined(HAVE_LINUX_RTC_H)
  480 #include <linux/rtc.h>
  481 #endif
  482 
  483 #if defined(HAVE_LINUX_RTNETLINK_H)
  484 #include <linux/rtnetlink.h>
  485 #endif
  486 
  487 #if defined(HAVE_LINUX_SECCOMP_H)
  488 #include <linux/seccomp.h>
  489 #endif
  490 
  491 #if defined(HAVE_LINUX_SOCK_DIAG_H)
  492 #include <linux/sock_diag.h>
  493 #endif
  494 
  495 #if defined(HAVE_LINUX_SOCKET_H)
  496 #include <linux/socket.h>
  497 #endif
  498 
  499 #if defined(HAVE_LINUX_UNIX_DIAG_H)
  500 #include <linux/unix_diag.h>
  501 #endif
  502 
  503 #if defined(HAVE_LINUX_USERFAULTFD_H)
  504 #include <linux/userfaultfd.h>
  505 #endif
  506 
  507 #if defined(HAVE_LINUX_VERSION_H)
  508 #include <linux/version.h>
  509 #endif
  510 
  511 #if defined(HAVE_LINUX_VIDEODEV2_H)
  512 #include <linux/videodev2.h>
  513 #endif
  514 
  515 #if defined(HAVE_LINUX_VT_H)
  516 #include <linux/vt.h>
  517 #endif
  518 
  519 #if defined(HAVE_LINUX_WATCHDOG_H)
  520 #include <linux/watchdog.h>
  521 #endif
  522 
  523 /*
  524  *  We want sys/xattr.h in preference
  525  *  to the older attr/xattr.h if both
  526  *  are available
  527  */
  528 #if defined(HAVE_SYS_XATTR_H)
  529 #include <sys/xattr.h>
  530 #undef HAVE_ATTR_XATTR_H
  531 #elif defined(HAVE_ATTR_XATTR_H)
  532 #include <attr/xattr.h>
  533 #endif
  534 /*  Sanity check */
  535 #if defined(HAVE_SYS_XATTR_H) && defined(HAVE_ATTR_XATTR_H)
  536 #error cannot have both HAVE_SYS_XATTR_H and HAVE_ATTR_XATTR_H
  537 #endif
  538 
  539 #if defined(HAVE_LIB_DL)
  540 #include <dlfcn.h>
  541 #include <gnu/lib-names.h>
  542 #endif
  543 
  544 /*
  545  *  Various system calls not included in libc (yet)
  546  */
  547 #if defined(__linux__)
  548 
  549 #if defined(__NR_add_key)
  550 #define HAVE_ADD_KEY
  551 #endif
  552 
  553 #if defined(__NR_getcpu)
  554 #define HAVE_GETCPU
  555 #endif
  556 
  557 #if defined(__NR_getdents)
  558 #define HAVE_GETDENTS
  559 #endif
  560 
  561 #if defined(__NR_getdents64)
  562 #define HAVE_GETDENTS64
  563 #endif
  564 
  565 #if defined(__NR_gettid)
  566 #define HAVE_GETTID
  567 #endif
  568 
  569 #if defined(__NR_get_robust_list)
  570 #define HAVE_GET_ROBUST_LIST
  571 #endif
  572 
  573 #if defined(__NR_ioprio_get)
  574 #define HAVE_IOPRIO_GET
  575 #endif
  576 
  577 #if defined(__NR_ioprio_set)
  578 #define HAVE_IOPRIO_SET
  579 #endif
  580 
  581 #if defined(__NR_kcmp)
  582 #define HAVE_KCMP
  583 #endif
  584 
  585 #if defined(__NR_keyctl)
  586 #define HAVE_KEYCTL
  587 #endif
  588 
  589 #if defined(__NR_membarrier)
  590 #define HAVE_MEMBARRIER
  591 #endif
  592 
  593 #if defined(__NR_pkey_get)
  594 #define HAVE_PKEY_GET
  595 #endif
  596 
  597 #if defined(__NR_pkey_set)
  598 #define HAVE_PKEY_SET
  599 #endif
  600 
  601 #if defined(__NR_request_key)
  602 #define HAVE_REQUEST_KEY
  603 #endif
  604 
  605 #if defined(__NR_sched_getattr)
  606 #define HAVE_SCHED_GETATTR
  607 #endif
  608 
  609 #if defined(__NR_sched_setattr)
  610 #define HAVE_SCHED_SETATTR
  611 #endif
  612 
  613 #if defined(__NR_set_robust_list)
  614 #define HAVE_SET_ROBUST_LIST
  615 #endif
  616 
  617 #if defined(__NR_syslog)
  618 #define HAVE_SYSLOG
  619 #endif
  620 
  621 #if defined(__NR_tgkill)
  622 #define HAVE_TGKILL
  623 #endif
  624 
  625 #if defined(__NR_userfaultfd)
  626 #define HAVE_USERFAULTFD
  627 #endif
  628 
  629 #endif
  630 
  631 #include "stress-version.h"
  632 
  633 /*
  634  *  BeagleBoneBlack with 4.1.15 kernel does not
  635  *  define the following, these should be defined
  636  *  in linux/posix_types.h - define them if they
  637  *  don't exist.
  638  */
  639 #if !defined(HAVE_KERNEL_LONG_T)
  640 typedef long int __kernel_long_t;
  641 #endif
  642 #if !defined(HAVE_KERNEL_ULONG_T)
  643 typedef unsigned long int __kernel_ulong_t;
  644 #endif
  645 
  646 /*
  647  *  cacheflush(2) cache options
  648  */
  649 #ifndef ICACHE
  650 #define ICACHE  (1 << 0)
  651 #endif
  652 #ifndef DCACHE
  653 #define DCACHE  (1 << 1)
  654 #endif
  655 
  656 #define EXIT_NOT_SUCCESS    (2)
  657 #define EXIT_NO_RESOURCE    (3)
  658 #define EXIT_NOT_IMPLEMENTED    (4)
  659 #define EXIT_SIGNALED       (5)
  660 #define EXIT_BY_SYS_EXIT    (6)
  661 
  662 /*
  663  * STRESS_ASSERT(test)
  664  *   throw compile time error if test not true
  665  */
  666 #define STRESS_CONCAT(a, b) a ## b
  667 #define STRESS_CONCAT_EXPAND(a, b) STRESS_CONCAT(a, b)
  668 #define STRESS_ASSERT(expr) \
  669     enum { STRESS_CONCAT_EXPAND(STRESS_ASSERT_AT_LINE_, __LINE__) = \
  670         1 / !!(expr) };
  671 
  672 #define STRESS_MINIMUM(a,b) (((a) < (b)) ? (a) : (b))
  673 #define STRESS_MAXIMUM(a,b) (((a) > (b)) ? (a) : (b))
  674 
  675 /* NetBSD does not define MAP_ANONYMOUS */
  676 #if defined(MAP_ANON) && !defined(MAP_ANONYMOUS)
  677 #define MAP_ANONYMOUS MAP_ANON
  678 #endif
  679 
  680 /* GNU HURD and other systems that don't define PATH_MAX */
  681 #ifndef PATH_MAX
  682 #define PATH_MAX        (4096)
  683 #endif
  684 
  685 /*
  686  * making local static fixes globbering warnings on older gcc versions
  687  */
  688 #if defined(__GNUC__) || defined(__clang__)
  689 #define NOCLOBBER   static
  690 #else
  691 #define NOCLOBBER
  692 #endif
  693 
  694 #if (_BSD_SOURCE || _SVID_SOURCE || !defined(__gnu_hurd__))
  695 #define STRESS_PAGE_IN
  696 #endif
  697 
  698 #define STRESS_FD_MAX       (65536)     /* Max fds if we can't figure it out */
  699 #define STRESS_PROCS_MAX    (8192)      /* Max number of processes per stressor */
  700 
  701 #define DCCP_BUF        (1024)      /* DCCP I/O buffer size */
  702 #define SOCKET_BUF      (8192)      /* Socket I/O buffer size */
  703 #define UDP_BUF         (1024)      /* UDP I/O buffer size */
  704 #define SOCKET_PAIR_BUF     (64)        /* Socket pair I/O buffer size */
  705 
  706 #define ABORT_FAILURES      (5)     /* Number of failures before we abort */
  707 
  708 /* debug output bitmasks */
  709 #define PR_ERROR         0x00000000000001ULL    /* Print errors */
  710 #define PR_INFO          0x00000000000002ULL    /* Print info */
  711 #define PR_DEBUG         0x00000000000004ULL    /* Print debug */
  712 #define PR_FAIL          0x00000000000008ULL    /* Print test failure message */
  713 #define PR_ALL           (PR_ERROR | PR_INFO | PR_DEBUG | PR_FAIL)
  714 
  715 /* Option bit masks */
  716 #define OPT_FLAGS_AFFINITY_RAND  0x00000000000010ULL    /* Change affinity randomly */
  717 #define OPT_FLAGS_DRY_RUN    0x00000000000020ULL    /* Don't actually run */
  718 #define OPT_FLAGS_METRICS    0x00000000000040ULL    /* Dump metrics at end */
  719 #define OPT_FLAGS_VM_KEEP    0x00000000000080ULL    /* Don't keep re-allocating */
  720 #define OPT_FLAGS_RANDOM     0x00000000000100ULL    /* Randomize */
  721 #define OPT_FLAGS_SET        0x00000000000200ULL    /* Set if user specifies stress procs */
  722 #define OPT_FLAGS_KEEP_NAME  0x00000000000400ULL    /* Keep stress names to stress-ng */
  723 #define OPT_FLAGS_UTIME_FSYNC    0x00000000000800ULL    /* fsync after utime modification */
  724 #define OPT_FLAGS_METRICS_BRIEF  0x00000000001000ULL    /* dump brief metrics */
  725 #define OPT_FLAGS_VERIFY     0x00000000002000ULL    /* verify mode */
  726 #define OPT_FLAGS_MMAP_MADVISE   0x00000000004000ULL    /* enable random madvise settings */
  727 #define OPT_FLAGS_MMAP_MINCORE   0x00000000008000ULL    /* mincore force pages into mem */
  728 #define OPT_FLAGS_TIMES      0x00000000010000ULL    /* user/system time summary */
  729 #define OPT_FLAGS_CACHE_PREFETCH 0x00000000020000ULL    /* cache prefetch */
  730 #define OPT_FLAGS_CACHE_FLUSH    0x00000000040000ULL    /* cache flush */
  731 #define OPT_FLAGS_CACHE_FENCE    0x00000000080000ULL    /* cache fence */
  732 #define OPT_FLAGS_MMAP_FILE  0x00000000100000ULL    /* mmap onto a file */
  733 #define OPT_FLAGS_MMAP_ASYNC     0x00000000200000ULL    /* mmap file asynchronous I/O */
  734 #define OPT_FLAGS_MMAP_MPROTECT  0x00000000400000ULL    /* mmap mprotect enabled */
  735 #define OPT_FLAGS_LOCKF_NONBLK   0x00000000800000ULL    /* Non-blocking lockf */
  736 #define OPT_FLAGS_MINCORE_RAND   0x00000001000000ULL    /* mincore randomize */
  737 #define OPT_FLAGS_BRK_NOTOUCH    0x00000002000000ULL    /* brk, don't touch page */
  738 #define OPT_FLAGS_HDD_SYNC   0x00000004000000ULL    /* HDD O_SYNC */
  739 #define OPT_FLAGS_HDD_DSYNC  0x00000008000000ULL    /* HDD O_DYNC */
  740 #define OPT_FLAGS_HDD_DIRECT     0x00000010000000ULL    /* HDD O_DIRECT */
  741 #define OPT_FLAGS_HDD_NOATIME    0x00000020000000ULL    /* HDD O_NOATIME */
  742 #define OPT_FLAGS_STACK_FILL     0x00000040000000ULL    /* Fill stack */
  743 #define OPT_FLAGS_MINIMIZE   0x00000080000000ULL    /* Minimize */
  744 #define OPT_FLAGS_MAXIMIZE   0x00000100000000ULL    /* Maximize */
  745 #define OPT_FLAGS_SYSLOG     0x00000200000000ULL    /* log test progress to syslog */
  746 #define OPT_FLAGS_AGGRESSIVE     0x00000400000000ULL    /* aggressive mode enabled */
  747 #define OPT_FLAGS_TIMER_RAND     0x00000800000000ULL    /* Enable random timer freq */
  748 #define OPT_FLAGS_TIMERFD_RAND   0x00001000000000ULL    /* Enable random timerfd freq */
  749 #define OPT_FLAGS_ALL        0x00002000000000ULL    /* --all mode */
  750 #define OPT_FLAGS_SEQUENTIAL     0x00004000000000ULL    /* --sequential mode */
  751 #define OPT_FLAGS_PERF_STATS     0x00008000000000ULL    /* --perf stats mode */
  752 #define OPT_FLAGS_LOG_BRIEF  0x00010000000000ULL    /* --log-brief */
  753 #define OPT_FLAGS_THERMAL_ZONES  0x00020000000000ULL    /* --tz thermal zones */
  754 #define OPT_FLAGS_TIMER_SLACK    0x00040000000000ULL    /* --timer-slack */
  755 #define OPT_FLAGS_SOCKET_NODELAY 0x00080000000000ULL    /* --sock-nodelay */
  756 #define OPT_FLAGS_UDP_LITE   0x00100000000000ULL    /* --udp-lite */
  757 #define OPT_FLAGS_SEEK_PUNCH     0x00200000000000ULL    /* --seek-punch */
  758 #define OPT_FLAGS_CACHE_NOAFF    0x00400000000000ULL    /* disable CPU affinity */
  759 #define OPT_FLAGS_IGNITE_CPU     0x00800000000000ULL    /* --cpu-ignite */
  760 #define OPT_FLAGS_PATHOLOGICAL   0x01000000000000ULL    /* --pathological */
  761 #define OPT_FLAGS_NO_RAND_SEED   0x02000000000000ULL    /* --no-rand-seed */
  762 #define OPT_FLAGS_THRASH     0x04000000000000ULL    /* --thrash */
  763 #define OPT_FLAGS_OOMABLE    0x08000000000000ULL    /* --oomable */
  764 #define OPT_FLAGS_ABORT      0x10000000000000ULL    /* --abort */
  765 #define OPT_FLAGS_CPU_ONLINE_ALL 0x20000000000000ULL    /* --cpu-online-all */
  766 #define OPT_FLAGS_TIMESTAMP  0x40000000000000ULL    /* --timestamp */
  767 
  768 #define OPT_FLAGS_CACHE_MASK        \
  769     (OPT_FLAGS_CACHE_FLUSH |    \
  770      OPT_FLAGS_CACHE_FENCE |    \
  771      OPT_FLAGS_CACHE_PREFETCH)
  772 
  773 #define OPT_FLAGS_MINMAX_MASK       \
  774     (OPT_FLAGS_MINIMIZE | OPT_FLAGS_MAXIMIZE)
  775 
  776 /* Aggressive mode flags */
  777 #define OPT_FLAGS_AGGRESSIVE_MASK   \
  778     (OPT_FLAGS_AFFINITY_RAND |  \
  779      OPT_FLAGS_UTIME_FSYNC |    \
  780      OPT_FLAGS_MMAP_MADVISE |   \
  781      OPT_FLAGS_MMAP_MINCORE |   \
  782      OPT_FLAGS_CACHE_FLUSH |    \
  783      OPT_FLAGS_CACHE_FENCE |    \
  784      OPT_FLAGS_MMAP_FILE |      \
  785      OPT_FLAGS_MMAP_ASYNC |     \
  786      OPT_FLAGS_MMAP_MPROTECT |  \
  787      OPT_FLAGS_LOCKF_NONBLK |   \
  788      OPT_FLAGS_MINCORE_RAND |   \
  789      OPT_FLAGS_HDD_SYNC |       \
  790      OPT_FLAGS_HDD_DSYNC |      \
  791      OPT_FLAGS_HDD_DIRECT |     \
  792      OPT_FLAGS_STACK_FILL |     \
  793      OPT_FLAGS_CACHE_PREFETCH | \
  794      OPT_FLAGS_AGGRESSIVE |     \
  795      OPT_FLAGS_IGNITE_CPU)
  796 
  797 #define WARN_ONCE_NO_CACHE  0x00000001  /* No /sys/../cpu0/cache */
  798 #define WARN_ONCE_CACHE_DEFAULT 0x00000002  /* default cache size */
  799 #define WARN_ONCE_CACHE_NONE    0x00000004  /* no cache info */
  800 #define WARN_ONCE_CACHE_WAY 0x00000008  /* cache way too high */
  801 #define WARN_ONCE_CACHE_SIZE    0x00000010  /* cache size info */
  802 #define WARN_ONCE_CACHE_REDUCED 0x00000020  /* reduced cache */
  803 
  804 /* Stressor classes */
  805 #define CLASS_CPU       0x00000001  /* CPU only */
  806 #define CLASS_MEMORY        0x00000002  /* Memory thrashers */
  807 #define CLASS_CPU_CACHE     0x00000004  /* CPU cache */
  808 #define CLASS_IO        0x00000008  /* I/O read/writes etc */
  809 #define CLASS_NETWORK       0x00000010  /* Network, sockets, etc */
  810 #define CLASS_SCHEDULER     0x00000020  /* Scheduling */
  811 #define CLASS_VM        0x00000040  /* VM stress, big memory, swapping */
  812 #define CLASS_INTERRUPT     0x00000080  /* interrupt floods */
  813 #define CLASS_OS        0x00000100  /* generic OS tests */
  814 #define CLASS_PIPE_IO       0x00000200  /* pipe I/O */
  815 #define CLASS_FILESYSTEM    0x00000400  /* file system */
  816 #define CLASS_DEV       0x00000800  /* device (null, zero, etc) */
  817 #define CLASS_SECURITY      0x00001000  /* security APIs */
  818 #define CLASS_PATHOLOGICAL  0x00002000  /* can hang a machine */
  819 
  820 typedef struct proc_info *pproc_info_t;
  821 
  822 /* native setting types */
  823 typedef enum {
  824     TYPE_ID_UNDEFINED,
  825     TYPE_ID_UINT8,
  826     TYPE_ID_INT8,
  827     TYPE_ID_UINT16,
  828     TYPE_ID_INT16,
  829     TYPE_ID_UINT32,
  830     TYPE_ID_INT32,
  831     TYPE_ID_UINT64,
  832     TYPE_ID_INT64,
  833     TYPE_ID_SIZE_T,
  834     TYPE_ID_SSIZE_T,
  835     TYPE_ID_UINT,
  836     TYPE_ID_INT,
  837     TYPE_ID_ULONG,
  838     TYPE_ID_LONG,
  839     TYPE_ID_OFF_T,
  840     TYPE_ID_STR,
  841     TYPE_ID_BOOL,
  842     TYPE_ID_UINTPTR_T
  843 } type_id_t;
  844 
  845 /* settings for storing opt arg parsed data */
  846 typedef struct setting {
  847     struct setting *next;       /* next setting in list */
  848     pproc_info_t    proc;
  849     char *name;         /* name of setting */
  850     type_id_t   type_id;    /* setting type */
  851     bool        global;     /* true if global */
  852     union {             /* setting value */
  853         uint8_t     uint8;
  854         int8_t      int8;
  855         uint16_t    uint16;
  856         int16_t     int16;
  857         uint32_t    uint32;
  858         int32_t     int32;
  859         uint64_t    uint64;
  860         int64_t     int64;
  861         size_t      size;
  862         ssize_t     ssize;
  863         unsigned int    uint;
  864         signed int  sint;
  865         unsigned long   ulong;
  866         signed long slong;
  867         off_t       off;
  868         const char *    str;
  869         bool        boolean;
  870         uintptr_t   uintptr;/* for func pointers */
  871     } u;
  872 } setting_t;
  873 
  874 typedef union {
  875     volatile uint8_t    uint8_val;
  876     volatile uint16_t   uint16_val;
  877     volatile uint32_t   uint32_val;
  878     volatile uint64_t   uint64_val;
  879 #if defined(HAVE_INT128_T)
  880     volatile __uint128_t    uint128_val;
  881 #endif
  882     volatile float      float_val;
  883     volatile double     double_val;
  884     volatile long double    long_double_val;
  885 } put_val_t;
  886 
  887 /* Network domains flags */
  888 #define DOMAIN_INET     0x00000001  /* AF_INET */
  889 #define DOMAIN_INET6        0x00000002  /* AF_INET6 */
  890 #define DOMAIN_UNIX     0x00000004  /* AF_UNIX */
  891 
  892 #define DOMAIN_INET_ALL     (DOMAIN_INET | DOMAIN_INET6)
  893 #define DOMAIN_ALL      (DOMAIN_INET | DOMAIN_INET6 | DOMAIN_UNIX)
  894 
  895 /* Large prime to stride around large VM regions */
  896 #define PRIME_64        (0x8f0000000017116dULL)
  897 
  898 typedef uint32_t class_t;
  899 
  900 /* stressor args */
  901 typedef struct {
  902     uint64_t *const counter;    /* stressor counter */
  903     const char *name;       /* stressor name */
  904     const uint64_t max_ops;     /* max number of bogo ops */
  905     const uint32_t instance;    /* stressor instance # */
  906     const uint32_t num_instances;   /* number of instances */
  907     pid_t pid;          /* stressor pid */
  908     pid_t ppid;         /* stressor ppid */
  909     size_t page_size;       /* page size */
  910 } args_t;
  911 
  912 typedef struct {
  913     int (*stressor)(const args_t *args);
  914     int (*supported)(void);
  915     void (*init)(void);
  916     void (*deinit)(void);
  917     void (*set_default)(void);
  918     void (*set_limit)(uint64_t max);
  919     class_t class;
  920 } stressor_info_t;
  921 
  922 /* pthread wrapped args_t */
  923 typedef struct {
  924     const args_t *args;
  925     void *data;
  926 } pthread_args_t;
  927 
  928 /* gcc 4.7 and later support vector ops */
  929 #if defined(__GNUC__) && NEED_GNUC(4,7,0)
  930 #define STRESS_VECTOR   1
  931 #endif
  932 
  933 /* gcc 7.0 and later support __attribute__((fallthrough)); */
  934 #if defined(__GNUC__) && NEED_GNUC(7,0,0)
  935 #define CASE_FALLTHROUGH __attribute__((fallthrough)) /* Fallthrough */
  936 #else
  937 #define CASE_FALLTHROUGH /* Fallthrough */
  938 #endif
  939 
  940 /* no return hint */
  941 #if defined(__GNUC__) && NEED_GNUC(2,5,0)
  942 #define NORETURN    __attribute__ ((noreturn))
  943 #else
  944 #define NORETURN
  945 #endif
  946 
  947 /* force inlining hint */
  948 #if defined(__GNUC__) && NEED_GNUC(3,4,0)   /* or possibly earlier */ \
  949  && ((!defined(__s390__) && !defined(__s390x__)) || NEED_GNUC(6,0,1))
  950 #define ALWAYS_INLINE   __attribute__ ((always_inline))
  951 #else
  952 #define ALWAYS_INLINE
  953 #endif
  954 
  955 /* force no inlining hint */
  956 #if defined(__GNUC__) && NEED_GNUC(3,4,0)   /* or possibly earier */
  957 #define NOINLINE    __attribute__ ((noinline))
  958 #else
  959 #define NOINLINE
  960 #endif
  961 
  962 /* -O3 attribute support */
  963 #if defined(__GNUC__) && !defined(__clang__) && NEED_GNUC(4,6,0)
  964 #define OPTIMIZE3   __attribute__((optimize("-O3")))
  965 #else
  966 #define OPTIMIZE3
  967 #endif
  968 
  969 /* -O1 attribute support */
  970 #if defined(__GNUC__) && !defined(__clang__) && NEED_GNUC(4,6,0)
  971 #define OPTIMIZE1   __attribute__((optimize("-O1")))
  972 #else
  973 #define OPTIMIZE1
  974 #endif
  975 
  976 /* -O0 attribute support */
  977 #if defined(__GNUC__) && !defined(__clang__) && NEED_GNUC(4,6,0)
  978 #define OPTIMIZE0   __attribute__((optimize("-O0")))
  979 #else
  980 #define OPTIMIZE0
  981 #endif
  982 
  983 /* warn unused attribute */
  984 #if defined(__GNUC__) && NEED_GNUC(4,2,0)
  985 #define WARN_UNUSED __attribute__((warn_unused_result))
  986 #else
  987 #define WARN_UNUSED
  988 #endif
  989 
  990 #if defined(__GNUC__) && NEED_GNUC(3,3,0)
  991 #define ALIGNED(a)  __attribute__((aligned(a)))
  992 #else
  993 #define ALIGNED(a)
  994 #endif
  995 
  996 /* Force aligment to nearest 128 bytes */
  997 #if defined(__GNUC__) && NEED_GNUC(3,3,0) && defined(HAVE_ALIGNED_128)
  998 #define ALIGN128    ALIGNED(128)
  999 #else
 1000 #define ALIGN128
 1001 #endif
 1002 
 1003 /* Force aligment to nearest 64 bytes */
 1004 #if defined(__GNUC__) && NEED_GNUC(3,3,0) && defined(HAVE_ALIGNED_64)
 1005 #define ALIGN64     ALIGNED(64)
 1006 #else
 1007 #define ALIGN64
 1008 #endif
 1009 
 1010 #if defined(__GNUC__) && NEED_GNUC(4,6,0)
 1011 #define SECTION(s)  __attribute__((__section__(# s)))
 1012 #else
 1013 #define SECTION(s)
 1014 #endif
 1015 
 1016 /* Choose cacheline alignment */
 1017 #if defined(ALIGN128)
 1018 #define ALIGN_CACHELINE ALIGN128
 1019 #else
 1020 #define ALIGN_CACHELINE ALIGN64
 1021 #endif
 1022 
 1023 /* GCC hot attribute */
 1024 #if defined(__GNUC__) && NEED_GNUC(4,6,0)
 1025 #define HOT     __attribute__ ((hot))
 1026 #else
 1027 #define HOT
 1028 #endif
 1029 
 1030 /* GCC mlocked data and data section attribute */
 1031 #if defined(__GNUC__) && NEED_GNUC(4,6,0) && !defined(__sun__)
 1032 #define MLOCKED_DATA    __attribute__((__section__("mlocked_data")))
 1033 #define MLOCKED_TEXT    __attribute__((__section__("mlocked_text")))
 1034 #define MLOCKED_SECTION 1
 1035 #else
 1036 #define MLOCKED_DATA
 1037 #define MLOCKED_TEXT
 1038 #endif
 1039 
 1040 /* print format attribute */
 1041 #if defined(__GNUC__) && NEED_GNUC(3,2,0)
 1042 #define FORMAT(func, a, b) __attribute__((format(func, a, b)))
 1043 #else
 1044 #define FORMAT(func, a, b)
 1045 #endif
 1046 
 1047 /* restrict keyword */
 1048 #if defined(__GNUC__) || defined(__clang__)
 1049 #define RESTRICT __restrict
 1050 #else
 1051 #define RESTRICT
 1052 #endif
 1053 
 1054 /* optimisation on branching */
 1055 #if defined(__GNUC__)
 1056 #define LIKELY(x)   __builtin_expect((x),1)
 1057 #define UNLIKELY(x) __builtin_expect((x),0)
 1058 #else
 1059 #define LIKELY(x)   (x)
 1060 #define UNLIKELY(x) (x)
 1061 #endif
 1062 
 1063 #if !defined(HAVE_BUILTIN_PREFETCH)
 1064 static inline void __builtin_prefetch(const void *addr, ...)
 1065 {
 1066     va_list ap;
 1067 
 1068     va_start(ap, addr);
 1069     va_end(ap);
 1070 }
 1071 #endif
 1072 
 1073 /* waste some cycles */
 1074 #if defined(__GNUC__) || defined(__clang__)
 1075 #  if defined(HAVE_ASM_NOP)
 1076 #    define FORCE_DO_NOTHING() __asm__ __volatile__("nop;")
 1077 #  else
 1078 #    define FORCE_DO_NOTHING() __asm__ __volatile__("")
 1079 #  endif
 1080 #else
 1081 #  define FORCE_DO_NOTHING() while (0)
 1082 #endif
 1083 
 1084 #if defined(__clang__) && NEED_CLANG(4, 0, 0)
 1085 #define PRAGMA_PUSH _Pragma("GCC diagnostic push")
 1086 #define PRAGMA_POP  _Pragma("GCC diagnostic pop")
 1087 #define PRAGMA_WARN_OFF _Pragma("GCC diagnostic ignored \"-Weverything\"")
 1088 #elif defined(__GNUC__) && NEED_GNUC(4, 4, 0)
 1089 #define PRAGMA_PUSH _Pragma("GCC diagnostic push")
 1090 #define PRAGMA_POP  _Pragma("GCC diagnostic pop")
 1091 #define PRAGMA_WARN_OFF _Pragma("GCC diagnostic ignored \"-Wall\"") \
 1092             _Pragma("GCC diagnostic ignored \"-Wextra\"") \
 1093             _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") \
 1094             _Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
 1095 #else
 1096 #define PRAGMA_PUSH
 1097 #define PRAGMA_POP
 1098 #define PRAGMA_WARN_OFF
 1099 #endif
 1100 
 1101 /* Logging helpers */
 1102 extern int pr_msg(FILE *fp, const uint64_t flag,
 1103     const char *const fmt, va_list va) FORMAT(printf, 3, 0);
 1104 extern void pr_msg_fail(const uint64_t flag, const char *name, const char *what, const int err);
 1105 extern int pr_yaml(FILE *fp, const char *const fmt, ...) FORMAT(printf, 2, 3);
 1106 extern void pr_yaml_runinfo(FILE *fp);
 1107 extern void pr_openlog(const char *filename);
 1108 extern void pr_closelog(void);
 1109 extern void pr_fail_check(int *rc);
 1110 
 1111 extern void pr_dbg(const char *fmt, ...)  FORMAT(printf, 1, 2);
 1112 extern void pr_inf(const char *fmt, ...)  FORMAT(printf, 1, 2);
 1113 extern void pr_err(const char *fmt, ...)  FORMAT(printf, 1, 2);
 1114 extern void pr_fail(const char *fmt, ...) FORMAT(printf, 1, 2);
 1115 extern void pr_tidy(const char *fmt, ...) FORMAT(printf, 1, 2);
 1116 
 1117 extern void pr_lock(bool *locked);
 1118 extern void pr_unlock(bool *locked);
 1119 extern void pr_inf_lock(bool *locked, const char *fmt, ...)  FORMAT(printf, 2, 3);
 1120 extern void pr_dbg_lock(bool *locked, const char *fmt, ...)  FORMAT(printf, 2, 3);
 1121 
 1122 extern void pr_fail_err__(const args_t *args, const char *msg);
 1123 extern void pr_fail_errno__(const args_t *args, const char *msg, int err);
 1124 extern void pr_fail_dbg__(const args_t *args, const char *msg);
 1125 
 1126 #define pr_fail_err(msg)        pr_fail_err__(args, msg)
 1127 #define pr_fail_errno(msg, err)     pr_fail_errno__(args, msg, err)
 1128 #define pr_fail_dbg(msg)        pr_fail_dbg__(args, msg)
 1129 
 1130 /* Memory size constants */
 1131 #define KB          (1ULL << 10)
 1132 #define MB          (1ULL << 20)
 1133 #define GB          (1ULL << 30)
 1134 #define TB          (1ULL << 40)
 1135 #define PB          (1ULL << 50)
 1136 #define EB          (1ULL << 60)
 1137 
 1138 #define PAGE_4K_SHIFT       (12)
 1139 #define PAGE_4K         (1 << PAGE_4K_SHIFT)
 1140 
 1141 #define STACK_ALIGNMENT     (64)    /* thread stacks align to 64 bytes */
 1142 
 1143 #define MIN_OPS         (1ULL)
 1144 #define MAX_OPS         (100000000ULL)
 1145 #define MAX_32          (0xffffffffUL)
 1146 #define MAX_48          (0xffffffffffffULL)
 1147 #define MAX_64          (0xffffffffffffffffULL)
 1148 
 1149 /* Maximum memory limits, 256TB for 64 bit is good enough for 2017 */
 1150 #if UINTPTR_MAX == MAX_32
 1151 #define MAX_MEM_LIMIT       MAX_32
 1152 #else
 1153 #define MAX_MEM_LIMIT       MAX_48
 1154 #endif
 1155 
 1156 /* Stressor defaults */
 1157 #define MIN_AIO_REQUESTS    (1)
 1158 #define MAX_AIO_REQUESTS    (4096)
 1159 #define DEFAULT_AIO_REQUESTS    (16)
 1160 
 1161 #define MIN_AIO_LINUX_REQUESTS  (1)
 1162 #define MAX_AIO_LINUX_REQUESTS  (4096)
 1163 #define DEFAULT_AIO_LINUX_REQUESTS  (64)
 1164 
 1165 #define MIN_BIGHEAP_GROWTH  (4 * KB)
 1166 #define MAX_BIGHEAP_GROWTH  (64 * MB)
 1167 #define DEFAULT_BIGHEAP_GROWTH  (64 * KB)
 1168 
 1169 #define MIN_BSEARCH_SIZE    (1 * KB)
 1170 #define MAX_BSEARCH_SIZE    (4 * MB)
 1171 #define DEFAULT_BSEARCH_SIZE    (64 * KB)
 1172 
 1173 #define MIN_CHDIR_DIRS      (64)
 1174 #define MAX_CHDIR_DIRS      (65536)
 1175 #define DEFAULT_CHDIR_DIRS  (8192)
 1176 
 1177 #define MIN_CLONES      (1)
 1178 #define MAX_CLONES      (1000000)
 1179 #define DEFAULT_CLONES      (8192)
 1180 
 1181 #define MIN_COPY_FILE_BYTES (128 * MB)
 1182 #define MAX_COPY_FILE_BYTES (256ULL * GB)
 1183 #define DEFAULT_COPY_FILE_BYTES (256 * MB)
 1184 #define DEFAULT_COPY_FILE_SIZE  (2 * MB)
 1185 
 1186 #define MIN_DCCP_PORT       (1024)
 1187 #define MAX_DCCP_PORT       (65535)
 1188 #define DEFAULT_DCCP_PORT   (10000)
 1189 
 1190 #define MIN_DENTRIES        (1)
 1191 #define MAX_DENTRIES        (1000000)
 1192 #define DEFAULT_DENTRIES    (2048)
 1193 
 1194 #define MIN_DIR_DIRS        (64)
 1195 #define MAX_DIR_DIRS        (65536)
 1196 #define DEFAULT_DIR_DIRS    (8192)
 1197 
 1198 #define MIN_EPOLL_PORT      (1024)
 1199 #define MAX_EPOLL_PORT      (65535)
 1200 #define DEFAULT_EPOLL_PORT  (6000)
 1201 
 1202 #define MIN_HDD_BYTES       (1 * MB)
 1203 #define MAX_HDD_BYTES       (256ULL * GB)
 1204 #define DEFAULT_HDD_BYTES   (1 * GB)
 1205 
 1206 #define MIN_HDD_WRITE_SIZE  (1)
 1207 #define MAX_HDD_WRITE_SIZE  (4 * MB)
 1208 #define DEFAULT_HDD_WRITE_SIZE  (64 * 1024)
 1209 
 1210 #define MIN_FALLOCATE_BYTES (1 * MB)
 1211 #if UINTPTR_MAX == MAX_32
 1212 #define MAX_FALLOCATE_BYTES (MAX_32)
 1213 #else
 1214 #define MAX_FALLOCATE_BYTES (4 * GB)
 1215 #endif
 1216 #define DEFAULT_FALLOCATE_BYTES (1 * GB)
 1217 
 1218 #define MIN_FIEMAP_SIZE     (1 * MB)
 1219 #if UINTPTR_MAX == MAX_32
 1220 #define MAX_FIEMAP_SIZE     (0xffffe00)
 1221 #else
 1222 #define MAX_FIEMAP_SIZE     (256ULL * GB)
 1223 #endif
 1224 #define DEFAULT_FIEMAP_SIZE (16 * MB)
 1225 
 1226 #define MIN_FIFO_READERS    (1)
 1227 #define MAX_FIFO_READERS    (64)
 1228 #define DEFAULT_FIFO_READERS    (4)
 1229 
 1230 #define MIN_ITIMER_FREQ     (1)
 1231 #define MAX_ITIMER_FREQ     (100000000)
 1232 #define DEFAULT_ITIMER_FREQ (1000000)
 1233 
 1234 #define MIN_MQ_SIZE     (1)
 1235 #define MAX_MQ_SIZE     (32)
 1236 #define DEFAULT_MQ_SIZE     (10)
 1237 
 1238 #define MIN_SEMAPHORE_PROCS (2)
 1239 #define MAX_SEMAPHORE_PROCS (64)
 1240 #define DEFAULT_SEMAPHORE_PROCS (2)
 1241 
 1242 #define MIN_EXECS       (1)
 1243 #define MAX_EXECS       (16000)
 1244 #define DEFAULT_EXECS       (1)
 1245 
 1246 #define MIN_FORKS       (1)
 1247 #define MAX_FORKS       (16000)
 1248 #define DEFAULT_FORKS       (1)
 1249 
 1250 #define MIN_HEAPSORT_SIZE   (1 * KB)
 1251 #define MAX_HEAPSORT_SIZE   (4 * MB)
 1252 #define DEFAULT_HEAPSORT_SIZE   (256 * KB)
 1253 
 1254 #define MIN_IOMIX_BYTES     (1 * MB)
 1255 #define MAX_IOMIX_BYTES     (256ULL * GB)
 1256 #define DEFAULT_IOMIX_BYTES (1 * GB)
 1257 
 1258 #define MIN_VFORKS      (1)
 1259 #define MAX_VFORKS      (16000)
 1260 #define DEFAULT_VFORKS      (1)
 1261 
 1262 #define MIN_HSEARCH_SIZE    (1 * KB)
 1263 #define MAX_HSEARCH_SIZE    (4 * MB)
 1264 #define DEFAULT_HSEARCH_SIZE    (8 * KB)
 1265 
 1266 #define MIN_LEASE_BREAKERS  (1)
 1267 #define MAX_LEASE_BREAKERS  (64)
 1268 #define DEFAULT_LEASE_BREAKERS  (1)
 1269 
 1270 #define MIN_LSEARCH_SIZE    (1 * KB)
 1271 #define MAX_LSEARCH_SIZE    (1 * MB)
 1272 #define DEFAULT_LSEARCH_SIZE    (8 * KB)
 1273 
 1274 #define MIN_MALLOC_BYTES    (1 * KB)
 1275 #if UINTPTR_MAX == MAX_32
 1276 #define MAX_MALLOC_BYTES    (MAX_32)
 1277 #else
 1278 #define MAX_MALLOC_BYTES    (4 * GB)
 1279 #endif
 1280 #define DEFAULT_MALLOC_BYTES    (64 * KB)
 1281 
 1282 #define MIN_MALLOC_MAX      (32)
 1283 #define MAX_MALLOC_MAX      (256 * 1024)
 1284 #define DEFAULT_MALLOC_MAX  (64 * KB)
 1285 
 1286 #define MIN_MALLOC_THRESHOLD    (1)
 1287 #define MAX_MALLOC_THRESHOLD    (256 * MB)
 1288 #define DEFAULT_MALLOC_THRESHOLD (128 * KB)
 1289 
 1290 #define MIN_MATRIX_SIZE     (16)
 1291 #define MAX_MATRIX_SIZE     (8192)
 1292 #define DEFAULT_MATRIX_SIZE (256)
 1293 
 1294 #define MIN_MATRIX3D_SIZE   (16)
 1295 #define MAX_MATRIX3D_SIZE   (1024)
 1296 #define DEFAULT_MATRIX3D_SIZE   (64)
 1297 
 1298 #define MIN_MEMFD_BYTES     (2 * MB)
 1299 #if UINTPTR_MAX == MAX_32
 1300 #define MAX_MEMFD_BYTES     (MAX_32)
 1301 #else
 1302 #define MAX_MEMFD_BYTES     (4 * GB)
 1303 #endif
 1304 #define DEFAULT_MEMFD_BYTES (256 * MB)
 1305 
 1306 #define MIN_MEMFD_FDS       (8)
 1307 #define MAX_MEMFD_FDS       (4096)
 1308 #define DEFAULT_MEMFD_FDS   (256)
 1309 
 1310 #define MIN_MERGESORT_SIZE  (1 * KB)
 1311 #define MAX_MERGESORT_SIZE  (4 * MB)
 1312 #define DEFAULT_MERGESORT_SIZE  (256 * KB)
 1313 
 1314 #define MIN_MMAP_BYTES      (4 * KB)
 1315 #if UINTPTR_MAX == MAX_32
 1316 #define MAX_MMAP_BYTES      (MAX_32)
 1317 #else
 1318 #define MAX_MMAP_BYTES      (4 * GB)
 1319 #endif
 1320 #define DEFAULT_MMAP_BYTES  (256 * MB)
 1321 
 1322 #define MIN_MEMRATE_BYTES   (4 * KB)
 1323 #if UINTPTR_MAX == MAX_32
 1324 #define MAX_MEMRATE_BYTES   (MAX_32)
 1325 #else
 1326 #define MAX_MEMRATE_BYTES   (4 * GB)
 1327 #endif
 1328 #define DEFAULT_MEMRATE_BYTES   (256 * MB)
 1329 
 1330 #define DEFAULT_MREMAP_BYTES    (256 * MB)
 1331 #define MIN_MREMAP_BYTES    (4 * KB)
 1332 #if UINTPTR_MAX == MAX_32
 1333 #define MAX_MREMAP_BYTES    (MAX_32)
 1334 #else
 1335 #define MAX_MREMAP_BYTES    (4 * GB)
 1336 #endif
 1337 #define DEFAULT_MREMAP_BYTES    (256 * MB)
 1338 
 1339 #define MIN_MSYNC_BYTES     (1 * MB)    /* MUST NOT BE page size or less! */
 1340 #if UINTPTR_MAX == MAX_32
 1341 #define MAX_MSYNC_BYTES     (MAX_32)
 1342 #else
 1343 #define MAX_MSYNC_BYTES     (4 * GB)
 1344 #endif
 1345 #define DEFAULT_MSYNC_BYTES (256 * MB)
 1346 
 1347 #define MIN_PTHREAD     (1)
 1348 #define MAX_PTHREAD     (30000)
 1349 #define DEFAULT_PTHREAD     (1024)
 1350 
 1351 #define MIN_PTYS        (8)
 1352 #define MAX_PTYS        (65536)
 1353 #define DEFAULT_PTYS        (65536)
 1354 
 1355 #define MIN_QSORT_SIZE      (1 * KB)
 1356 #define MAX_QSORT_SIZE      (4 * MB)
 1357 #define DEFAULT_QSORT_SIZE  (256 * KB)
 1358 
 1359 #define MIN_RADIXSORT_SIZE  (1 * KB)
 1360 #define MAX_RADIXSORT_SIZE  (4 * MB)
 1361 #define DEFAULT_RADIXSORT_SIZE  (256 * KB)
 1362 
 1363 #define MIN_READAHEAD_BYTES (1 * MB)
 1364 #define MAX_READAHEAD_BYTES (256ULL * GB)
 1365 #define DEFAULT_READAHEAD_BYTES (1 * GB)
 1366 
 1367 #define MIN_REVIO_BYTES     (1 * MB)
 1368 #define MAX_REVIO_BYTES     (256ULL * GB)
 1369 #define DEFAULT_REVIO_BYTES (1 * GB)
 1370 
 1371 #define MIN_SCTP_PORT       (1024)
 1372 #define MAX_SCTP_PORT       (65535)
 1373 #define DEFAULT_SCTP_PORT   (9000)
 1374 
 1375 #define MIN_SENDFILE_SIZE   (1 * KB)
 1376 #define MAX_SENDFILE_SIZE   (1 * GB)
 1377 #define DEFAULT_SENDFILE_SIZE   (4 * MB)
 1378 
 1379 #define MIN_SEEK_SIZE       (1 * MB)
 1380 #if UINTPTR_MAX == MAX_32
 1381 #define MAX_SEEK_SIZE       (0xffffe00)
 1382 #else
 1383 #define MAX_SEEK_SIZE       (256ULL * GB)
 1384 #endif
 1385 #define DEFAULT_SEEK_SIZE   (16 * MB)
 1386 
 1387 #define MIN_SEQUENTIAL      (0)
 1388 #define MAX_SEQUENTIAL      (1000000)
 1389 #define DEFAULT_SEQUENTIAL  (0) /* Disabled */
 1390 #define DEFAULT_PARALLEL    (0) /* Disabled */
 1391 
 1392 #define MIN_SHM_SYSV_BYTES  (1 * MB)
 1393 #define MAX_SHM_SYSV_BYTES  (256 * MB)
 1394 #define DEFAULT_SHM_SYSV_BYTES  (8 * MB)
 1395 
 1396 #define MIN_SHM_SYSV_SEGMENTS   (1)
 1397 #define MAX_SHM_SYSV_SEGMENTS   (128)
 1398 #define DEFAULT_SHM_SYSV_SEGMENTS (8)
 1399 
 1400 #define MIN_SHM_POSIX_BYTES (1 * MB)
 1401 #define MAX_SHM_POSIX_BYTES (1 * GB)
 1402 #define DEFAULT_SHM_POSIX_BYTES (8 * MB)
 1403 
 1404 #define MIN_SHM_POSIX_OBJECTS   (1)
 1405 #define MAX_SHM_POSIX_OBJECTS   (128)
 1406 #define DEFAULT_SHM_POSIX_OBJECTS (32)
 1407 
 1408 #define MAX_SIGSUSPEND_PIDS (4)
 1409 
 1410 #define MIN_SLEEP       (1)
 1411 #define MAX_SLEEP       (30000)
 1412 #define DEFAULT_SLEEP       (1024)
 1413 
 1414 #define MIN_SOCKET_PORT     (1024)
 1415 #define MAX_SOCKET_PORT     (65535)
 1416 #define DEFAULT_SOCKET_PORT (5000)
 1417 
 1418 #define MIN_SOCKET_FD_PORT  (1024)
 1419 #define MAX_SOCKET_FD_PORT  (65535)
 1420 #define DEFAULT_SOCKET_FD_PORT  (8000)
 1421 
 1422 #define MIN_SPLICE_BYTES    (1*KB)
 1423 #define MAX_SPLICE_BYTES    (64*MB)
 1424 #define DEFAULT_SPLICE_BYTES    (64*KB)
 1425 
 1426 #define MIN_STREAM_L3_SIZE  (4 * KB)
 1427 #if UINTPTR_MAX == MAX_32
 1428 #define MAX_STREAM_L3_SIZE  (MAX_32)
 1429 #else
 1430 #define MAX_STREAM_L3_SIZE  (4 * GB)
 1431 #endif
 1432 #define DEFAULT_STREAM_L3_SIZE  (4 * MB)
 1433 
 1434 #define MIN_SYNC_FILE_BYTES (1 * MB)
 1435 #if UINTPTR_MAX == MAX_32
 1436 #define MAX_SYNC_FILE_BYTES (MAX_32)
 1437 #else
 1438 #define MAX_SYNC_FILE_BYTES (4 * GB)
 1439 #endif
 1440 #define DEFAULT_SYNC_FILE_BYTES (1 * GB)
 1441 
 1442 #define MIN_TIMER_FREQ      (1)
 1443 #define MAX_TIMER_FREQ      (100000000)
 1444 #define DEFAULT_TIMER_FREQ  (1000000)
 1445 
 1446 #define MIN_TIMERFD_FREQ    (1)
 1447 #define MAX_TIMERFD_FREQ    (100000000)
 1448 #define DEFAULT_TIMERFD_FREQ    (1000000)
 1449 
 1450 #define MIN_TREE_SIZE       (1000)
 1451 #define MAX_TREE_SIZE       (25000000)
 1452 #define DEFAULT_TREE_SIZE   (250000)
 1453 
 1454 #define MIN_TSEARCH_SIZE    (1 * KB)
 1455 #define MAX_TSEARCH_SIZE    (4 * MB)
 1456 #define DEFAULT_TSEARCH_SIZE    (64 * KB)
 1457 
 1458 #define MIN_UDP_PORT        (1024)
 1459 #define MAX_UDP_PORT        (65535)
 1460 #define DEFAULT_UDP_PORT    (7000)
 1461 
 1462 #define MIN_USERFAULTFD_BYTES   (4 * KB)
 1463 #if UINTPTR_MAX == MAX_32
 1464 #define MAX_USERFAULTFD_BYTES   (MAX_32)
 1465 #else
 1466 #define MAX_USERFAULTFD_BYTES   (4 * GB)
 1467 #endif
 1468 #define DEFAULT_USERFAULTFD_BYTES (16 * MB)
 1469 
 1470 #define MIN_VM_BYTES        (4 * KB)
 1471 #if UINTPTR_MAX == MAX_32
 1472 #define MAX_VM_BYTES        (MAX_32)
 1473 #else
 1474 #define MAX_VM_BYTES        (4 * GB)
 1475 #endif
 1476 #define DEFAULT_VM_BYTES    (256 * MB)
 1477 
 1478 #define MIN_VM_HANG     (0)
 1479 #define MAX_VM_HANG     (3600)
 1480 #define DEFAULT_VM_HANG     (~0ULL)
 1481 
 1482 #define MIN_VM_RW_BYTES     (4 * KB)
 1483 #if UINTPTR_MAX == MAX_32
 1484 #define MAX_VM_RW_BYTES     (MAX_32)
 1485 #else
 1486 #define MAX_VM_RW_BYTES     (4 * GB)
 1487 #endif
 1488 #define DEFAULT_VM_RW_BYTES (16 * MB)
 1489 
 1490 #define MIN_VM_SPLICE_BYTES (4*KB)
 1491 #define MAX_VM_SPLICE_BYTES (64*MB)
 1492 #define DEFAULT_VM_SPLICE_BYTES (64*KB)
 1493 
 1494 #define MIN_ZOMBIES     (1)
 1495 #define MAX_ZOMBIES     (1000000)
 1496 #define DEFAULT_ZOMBIES     (8192)
 1497 
 1498 #define TIMEOUT_NOT_SET     (~0ULL)
 1499 #define DEFAULT_TIMEOUT     (60 * 60 * 24)
 1500 #define DEFAULT_BACKOFF     (0)
 1501 #define DEFAULT_LINKS       (8192)
 1502 #define DEFAULT_DIRS        (8192)
 1503 
 1504 #define STR_SHARED_SIZE     (65536 * 32)
 1505 #define MEM_CACHE_SIZE      (65536 * 32)
 1506 #define DEFAULT_CACHE_LEVEL     3
 1507 #define UNDEFINED       (-1)
 1508 
 1509 #define PAGE_MAPPED     (0x01)
 1510 #define PAGE_MAPPED_FAIL    (0x02)
 1511 
 1512 #define FFT_SIZE        (4096)
 1513 
 1514 #define STRESS_CPU_DITHER_X (1024)
 1515 #define STRESS_CPU_DITHER_Y (768)
 1516 
 1517 #if defined(__GNUC__) || defined(__clang__)
 1518 #define TYPEOF_CAST(a)  (typeof(a))
 1519 #else
 1520 #define TYPEOF_CAST(a)
 1521 #endif
 1522 
 1523 /* Generic bit setting on an array macros */
 1524 #define STRESS_NBITS(a)     (sizeof(a[0]) * 8)
 1525 #define STRESS_GETBIT(a, i) (a[i / STRESS_NBITS(a)] & \
 1526                  (TYPEOF_CAST(a[0])1 << (i & (STRESS_NBITS(a)-1))))
 1527 #define STRESS_CLRBIT(a, i) (a[i / STRESS_NBITS(a)] &= \
 1528                  ~(TYPEOF_CAST(a[0])1 << (i & (STRESS_NBITS(a)-1))))
 1529 #define STRESS_SETBIT(a, i) (a[i / STRESS_NBITS(a)] |= \
 1530                  (TYPEOF_CAST(a[0])1 << (i & (STRESS_NBITS(a)-1))))
 1531 
 1532 #define SIEVE_SIZE      (10000000)
 1533 
 1534 /* MWC random number initial seed */
 1535 #define MWC_SEED_Z      (362436069UL)
 1536 #define MWC_SEED_W      (521288629UL)
 1537 #define MWC_SEED()      mwc_seed(MWC_SEED_W, MWC_SEED_Z)
 1538 
 1539 #define SIZEOF_ARRAY(a)     (sizeof(a) / sizeof(a[0]))
 1540 
 1541 /* Arch specific, x86 */
 1542 #if defined(__x86_64__) || defined(__x86_64) || \
 1543     defined(__i386__)   || defined(__i386)
 1544 #define STRESS_X86  1
 1545 #endif
 1546 
 1547 /* Arch specific, ARM */
 1548 #if defined(__ARM_ARCH_6__)   || defined(__ARM_ARCH_6J__)  || \
 1549     defined(__ARM_ARCH_6K__)  || defined(__ARM_ARCH_6Z__)  || \
 1550     defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) || \
 1551     defined(__ARM_ARCH_6M__)  || defined(__ARM_ARCH_7__)   || \
 1552     defined(__ARM_ARCH_7A__)  || defined(__ARM_ARCH_7R__)  || \
 1553     defined(__ARM_ARCH_7M__)  || defined(__ARM_ARCH_7EM__) || \
 1554     defined(__ARM_ARCH_8A__)  || defined(__aarch64__)
 1555 #define STRESS_ARM      1
 1556 #endif
 1557 
 1558 /* Arch specific, IBM S390 */
 1559 #if defined(__s390__)
 1560 #define STRESS_S390
 1561 #endif
 1562 
 1563 /* Arch specific PPC64 */
 1564 #if defined(__PPC64__)
 1565 #define STRESS_PPC64
 1566 #endif
 1567 
 1568 /* GCC5.0+ target_clones attribute */
 1569 #if defined(HAVE_TARGET_CLONES)
 1570 #define TARGET_CLONES   __attribute__((target_clones("mmx","sse","sse2","ssse3", "sse4.1", "sse4a", "avx", "avx2", "avx512f", "default")))
 1571 #else
 1572 #define TARGET_CLONES
 1573 #endif
 1574 
 1575 /*
 1576  *  See ioprio_set(2) and linux/ioprio.h, glibc has no definitions
 1577  *  for these at present. Also refer to Documentation/block/ioprio.txt
 1578  *  in the Linux kernel source.
 1579  */
 1580 #if !defined(IOPRIO_CLASS_RT)
 1581 #define IOPRIO_CLASS_RT         (1)
 1582 #endif
 1583 #if !defined(IOPRIO_CLASS_BE)
 1584 #define IOPRIO_CLASS_BE         (2)
 1585 #endif
 1586 #if !defined(IOPRIO_CLASS_IDLE)
 1587 #define IOPRIO_CLASS_IDLE       (3)
 1588 #endif
 1589 
 1590 #if !defined(IOPRIO_WHO_PROCESS)
 1591 #define IOPRIO_WHO_PROCESS      (1)
 1592 #endif
 1593 #if !defined(IOPRIO_WHO_PGRP)
 1594 #define IOPRIO_WHO_PGRP         (2)
 1595 #endif
 1596 #if !defined(IOPRIO_WHO_USER)
 1597 #define IOPRIO_WHO_USER         (3)
 1598 #endif
 1599 
 1600 #if !defined(IOPRIO_PRIO_VALUE)
 1601 #define IOPRIO_PRIO_VALUE(class, data)  (((class) << 13) | data)
 1602 #endif
 1603 
 1604 /* prctl(2) timer slack support */
 1605 #if defined(HAVE_SYS_PRCTL_H) && \
 1606     defined(HAVE_PRCTL) && \
 1607     defined(PR_SET_TIMERSLACK) && \
 1608     defined(PR_GET_TIMERSLACK)
 1609 #define HAVE_PRCTL_TIMER_SLACK
 1610 #endif
 1611 
 1612 /*
 1613  *  checks to see if we should keep in running the stressors
 1614  */
 1615 extern bool __keep_stressing(const args_t *args);
 1616 
 1617 #define keep_stressing()    __keep_stressing(args)
 1618 
 1619 /* increment the stessor bogo ops counter */
 1620 static inline void ALWAYS_INLINE inc_counter(const args_t *args)
 1621 {
 1622     (*(args->counter))++;
 1623 }
 1624 
 1625 static inline uint64_t ALWAYS_INLINE get_counter(const args_t *args)
 1626 {
 1627     return *args->counter;
 1628 }
 1629 
 1630 static inline void ALWAYS_INLINE set_counter(const args_t *args, const uint64_t val)
 1631 {
 1632     *args->counter = val;
 1633 }
 1634 
 1635 static inline void ALWAYS_INLINE add_counter(const args_t *args, const uint64_t inc)
 1636 {
 1637     *args->counter += inc;
 1638 }
 1639 
 1640 /* pthread porting shims, spinlock or fallback to mutex */
 1641 #if defined(HAVE_LIB_PTHREAD)
 1642 #if defined(HAVE_LIB_PTHREAD_SPINLOCK) && !defined(__DragonFly__) && !defined(__OpenBSD__)
 1643 typedef pthread_spinlock_t  shim_pthread_spinlock_t;
 1644 
 1645 #define SHIM_PTHREAD_PROCESS_SHARED     PTHREAD_PROCESS_SHARED
 1646 #define SHIM_PTHREAD_PROCESS_PRIVATE        PTHREAD_PROCESS_PRIVATE
 1647 
 1648 #define shim_pthread_spin_lock(lock)        pthread_spin_lock(lock)
 1649 #define shim_pthread_spin_unlock(lock)      pthread_spin_unlock(lock)
 1650 #define shim_pthread_spin_init(lock, shared)    pthread_spin_init(lock, shared)
 1651 #define shim_pthread_spin_destroy(lock)     pthread_spin_destroy(lock)
 1652 #else
 1653 typedef pthread_mutex_t     shim_pthread_spinlock_t;
 1654 
 1655 #define SHIM_PTHREAD_PROCESS_SHARED     NULL
 1656 #define SHIM_PTHREAD_PROCESS_PRIVATE        NULL
 1657 
 1658 #define shim_pthread_spin_lock(lock)        pthread_mutex_lock(lock)
 1659 #define shim_pthread_spin_unlock(lock)      pthread_mutex_unlock(lock)
 1660 #define shim_pthread_spin_init(lock, shared)    pthread_mutex_init(lock, shared)
 1661 #define shim_pthread_spin_destroy(lock)     pthread_mutex_destroy(lock)
 1662 #endif
 1663 #endif
 1664 
 1665 /* stress process prototype */
 1666 typedef int (*stress_func_t)(const args_t *args);
 1667 
 1668 /* Fast random number generator state */
 1669 typedef struct {
 1670     uint32_t w;
 1671     uint32_t z;
 1672 } mwc_t;
 1673 
 1674 /* perf related constants */
 1675 #if defined(HAVE_LIB_PTHREAD) &&    \
 1676     defined(HAVE_LINUX_PERF_EVENT_H) && \
 1677     defined(__NR_perf_event_open)
 1678 #define STRESS_PERF_STATS   (1)
 1679 #define STRESS_PERF_INVALID (~0ULL)
 1680 #define STRESS_PERF_MAX     (128)
 1681 
 1682 /* per perf counter info */
 1683 typedef struct {
 1684     uint64_t counter;       /* perf counter */
 1685     int  fd;            /* perf per counter fd */
 1686 } perf_stat_t;
 1687 
 1688 /* per stressor perf info */
 1689 typedef struct {
 1690     perf_stat_t perf_stat[STRESS_PERF_MAX]; /* perf counters */
 1691     int     perf_opened;    /* count of opened counters */
 1692 } stress_perf_t;
 1693 #endif
 1694 
 1695 /* linux thermal zones */
 1696 #define STRESS_THERMAL_ZONES     (1)
 1697 #define STRESS_THERMAL_ZONES_MAX (31)   /* best if prime */
 1698 
 1699 #if defined(STRESS_THERMAL_ZONES)
 1700 /* per stressor thermal zone info */
 1701 typedef struct tz_info {
 1702     char    *path;          /* thermal zone path */
 1703     char    *type;          /* thermal zone type */
 1704     size_t  index;          /* thermal zone # index */
 1705     struct tz_info *next;       /* next thermal zone in list */
 1706 } tz_info_t;
 1707 
 1708 typedef struct {
 1709     uint64_t temperature;       /* temperature in Celsius * 1000 */
 1710 } tz_stat_t;
 1711 
 1712 typedef struct {
 1713     tz_stat_t tz_stat[STRESS_THERMAL_ZONES_MAX];
 1714 } stress_tz_t;
 1715 #endif
 1716 
 1717 /* Per process statistics and accounting info */
 1718 typedef struct {
 1719     uint64_t counter;       /* number of bogo ops */
 1720     struct tms tms;         /* run time stats of process */
 1721     double start;           /* wall clock start time */
 1722     double finish;          /* wall clock stop time */
 1723 #if defined(STRESS_PERF_STATS)
 1724     stress_perf_t sp;       /* perf counters */
 1725 #endif
 1726 #if defined(STRESS_THERMAL_ZONES)
 1727     stress_tz_t tz;         /* thermal zones */
 1728 #endif
 1729     bool run_ok;            /* true if stressor exited OK */
 1730 } proc_stats_t;
 1731 
 1732 /* The stress-ng global shared memory segment */
 1733 typedef struct {
 1734     size_t length;                  /* Size of segment */
 1735     uint8_t *mem_cache;             /* Shared memory cache */
 1736     uint64_t mem_cache_size;            /* Bytes */
 1737     uint16_t mem_cache_level;           /* 1=L1, 2=L2, 3=L3 */
 1738     uint16_t padding1;              /* alignment padding */
 1739     uint32_t mem_cache_ways;            /* cache ways size */
 1740     uint64_t zero;                  /* zero'd data */
 1741     struct {
 1742         uint32_t    flags;          /* flag bits */
 1743 #if defined(HAVE_LIB_PTHREAD)
 1744         shim_pthread_spinlock_t lock;       /* protection lock */
 1745 #endif
 1746     } warn_once;
 1747     uint32_t warn_once_flags;           /* Warn once flags */
 1748     struct {
 1749         uint64_t val64;
 1750         uint32_t val32;
 1751         uint16_t val16;
 1752         uint8_t  val8;
 1753         uint8_t  padding2;          /* more padding */
 1754     } atomic;                   /* Shared atomic temp vars */
 1755     struct {
 1756         uint32_t futex[STRESS_PROCS_MAX];   /* Shared futexes */
 1757         uint64_t timeout[STRESS_PROCS_MAX]; /* Shared futex timeouts */
 1758     } futex;
 1759     struct {
 1760         key_t key_id;               /* System V semaphore key id */
 1761         int sem_id;             /* System V semaphore id */
 1762         bool init;              /* System V semaphore initialized */
 1763     } sem_sysv;
 1764 #if defined(STRESS_PERF_STATS)
 1765     struct {
 1766         bool no_perf;               /* true = Perf not available */
 1767         shim_pthread_spinlock_t lock;       /* spinlock on no_perf updates */
 1768     } perf;
 1769 #endif
 1770 #if defined(STRESS_THERMAL_ZONES)
 1771     tz_info_t *tz_info;             /* List of valid thermal zones */
 1772 #endif
 1773 #if defined(HAVE_ATOMIC)
 1774     uint32_t softlockup_count;          /* Atomic counter of softlock children */
 1775 #endif
 1776     uint8_t  str_shared[STR_SHARED_SIZE];       /* str copying buffer */
 1777     proc_stats_t stats[0];              /* Shared statistics */
 1778 } shared_t;
 1779 
 1780 /* Stress test classes */
 1781 typedef struct {
 1782     class_t class;          /* Class type bit mask */
 1783     const char *name;       /* Name of class */
 1784 } class_info_t;
 1785 
 1786 /* Stress tests */
 1787 typedef enum {
 1788     STRESS_START = -1,
 1789     STRESS_access,
 1790     STRESS_affinity,
 1791     STRESS_af_alg,
 1792     STRESS_aio,
 1793     STRESS_aiol,
 1794     STRESS_apparmor,
 1795     STRESS_atomic,
 1796     STRESS_bad_altstack,
 1797     STRESS_branch,
 1798     STRESS_brk,
 1799     STRESS_bsearch,
 1800     STRESS_bigheap,
 1801     STRESS_bind_mount,
 1802     STRESS_cache,
 1803     STRESS_cap,
 1804     STRESS_chdir,
 1805     STRESS_chmod,
 1806     STRESS_chown,
 1807     STRESS_chroot,
 1808     STRESS_clock,
 1809     STRESS_clone,
 1810     STRESS_close,
 1811     STRESS_context,
 1812     STRESS_copy_file,
 1813     STRESS_cpu,
 1814     STRESS_cpu_online,
 1815     STRESS_crypt,
 1816     STRESS_cyclic,
 1817     STRESS_daemon,
 1818     STRESS_dccp,
 1819     STRESS_dentry,
 1820     STRESS_dev,
 1821     STRESS_dev_shm,
 1822     STRESS_dir,
 1823     STRESS_dirdeep,
 1824     STRESS_dnotify,
 1825     STRESS_dup,
 1826     STRESS_dynlib,
 1827     STRESS_efivar,
 1828     STRESS_enosys,
 1829     STRESS_epoll,
 1830     STRESS_eventfd,
 1831     STRESS_exec,
 1832     STRESS_fallocate,
 1833     STRESS_fanotify,
 1834     STRESS_fault,
 1835     STRESS_fcntl,
 1836     STRESS_fiemap,
 1837     STRESS_fifo,
 1838     STRESS_file_ioctl,
 1839     STRESS_filename,
 1840     STRESS_flock,
 1841     STRESS_fork,
 1842     STRESS_fp_error,
 1843     STRESS_fstat,
 1844     STRESS_full,
 1845     STRESS_funccall,
 1846     STRESS_futex,
 1847     STRESS_get,
 1848     STRESS_getrandom,
 1849     STRESS_getdent,
 1850     STRESS_handle,
 1851     STRESS_hdd,
 1852     STRESS_heapsort,
 1853     STRESS_hrtimers,
 1854     STRESS_hsearch,
 1855     STRESS_icache,
 1856     STRESS_icmp_flood,
 1857     STRESS_idle_page,
 1858     STRESS_ipsec_mb,
 1859     STRESS_inode_flags,
 1860     STRESS_inotify,
 1861     STRESS_iomix,
 1862     STRESS_ioport,
 1863     STRESS_ioprio,
 1864     STRESS_io,
 1865     STRESS_itimer,
 1866     STRESS_kcmp,
 1867     STRESS_key,
 1868     STRESS_kill,
 1869     STRESS_klog,
 1870     STRESS_lease,
 1871     STRESS_link,
 1872     STRESS_lockbus,
 1873     STRESS_locka,
 1874     STRESS_lockf,
 1875     STRESS_lockofd,
 1876     STRESS_longjmp,
 1877     STRESS_loop,
 1878     STRESS_lsearch,
 1879     STRESS_madvise,
 1880     STRESS_malloc,
 1881     STRESS_matrix,
 1882     STRESS_matrix_3d,
 1883     STRESS_mcontend,
 1884     STRESS_membarrier,
 1885     STRESS_memcpy,
 1886     STRESS_memfd,
 1887     STRESS_memrate,
 1888     STRESS_memthrash,
 1889     STRESS_mergesort,
 1890     STRESS_mincore,
 1891     STRESS_mknod,
 1892     STRESS_mlock,
 1893     STRESS_mlockmany,
 1894     STRESS_mmap,
 1895     STRESS_mmapaddr,
 1896     STRESS_mmapfixed,
 1897     STRESS_mmapfork,
 1898     STRESS_mmapmany,
 1899     STRESS_mq,
 1900     STRESS_mremap,
 1901     STRESS_msg,
 1902     STRESS_msync,
 1903     STRESS_netdev,
 1904     STRESS_netlink_proc,
 1905     STRESS_nice,
 1906     STRESS_nop,
 1907     STRESS_null,
 1908     STRESS_numa,
 1909     STRESS_oom_pipe,
 1910     STRESS_opcode,
 1911     STRESS_open,
 1912     STRESS_personality,
 1913     STRESS_physpage,
 1914     STRESS_pipe,
 1915     STRESS_pkey,
 1916     STRESS_poll,
 1917     STRESS_prctl,
 1918     STRESS_procfs,
 1919     STRESS_pthread,
 1920     STRESS_ptrace,
 1921     STRESS_pty,
 1922     STRESS_qsort,
 1923     STRESS_quota,
 1924     STRESS_radixsort,
 1925     STRESS_rawdev,
 1926     STRESS_rdrand,
 1927     STRESS_readahead,
 1928     STRESS_remap,
 1929     STRESS_rename,
 1930     STRESS_resources,
 1931     STRESS_revio,
 1932     STRESS_rlimit,
 1933     STRESS_rmap,
 1934     STRESS_rtc,
 1935     STRESS_schedpolicy,
 1936     STRESS_sctp,
 1937     STRESS_seal,
 1938     STRESS_seccomp,
 1939     STRESS_seek,
 1940     STRESS_sem,
 1941     STRESS_sem_sysv,
 1942     STRESS_sendfile,
 1943     STRESS_set,
 1944     STRESS_shm,
 1945     STRESS_shm_sysv,
 1946     STRESS_sigfd,
 1947     STRESS_sigfpe,
 1948     STRESS_sigio,
 1949     STRESS_sigpending,
 1950     STRESS_sigpipe,
 1951     STRESS_sigq,
 1952     STRESS_sigrt,
 1953     STRESS_sigsegv,
 1954     STRESS_sigsuspend,
 1955     STRESS_sleep,
 1956     STRESS_sock,
 1957     STRESS_sockdiag,
 1958     STRESS_sockfd,
 1959     STRESS_sockpair,
 1960     STRESS_softlockup,
 1961     STRESS_spawn,
 1962     STRESS_splice,
 1963     STRESS_stack,
 1964     STRESS_stackmmap,
 1965     STRESS_str,
 1966     STRESS_stream,
 1967     STRESS_swap,
 1968     STRESS_switch,
 1969     STRESS_symlink,
 1970     STRESS_sync_file,
 1971     STRESS_sysbadaddr,
 1972     STRESS_sysinfo,
 1973     STRESS_sysfs,
 1974     STRESS_tee,
 1975     STRESS_timer,
 1976     STRESS_timerfd,
 1977     STRESS_tlb_shootdown,
 1978     STRESS_tmpfs,
 1979     STRESS_tree,
 1980     STRESS_tsc,
 1981     STRESS_tsearch,
 1982     STRESS_udp,
 1983     STRESS_udp_flood,
 1984     STRESS_unshare,
 1985     STRESS_urandom,
 1986     STRESS_userfaultfd,
 1987     STRESS_utime,
 1988     STRESS_vdso,
 1989     STRESS_vecmath,
 1990     STRESS_vfork,
 1991     STRESS_vforkmany,
 1992     STRESS_vm,
 1993     STRESS_vm_addr,
 1994     STRESS_vm_rw,
 1995     STRESS_vm_segv,
 1996     STRESS_vm_splice,
 1997     STRESS_wait,
 1998     STRESS_watchdog,
 1999     STRESS_wcs,
 2000     STRESS_xattr,
 2001     STRESS_yield,
 2002     STRESS_zero,
 2003     STRESS_zlib,
 2004     STRESS_zombie,
 2005     /* STRESS_MAX must be last one */
 2006     STRESS_MAX
 2007 } stress_id_t;
 2008 
 2009 /* Command line long options */
 2010 typedef enum {
 2011     /* Short options */
 2012     OPT_query = '?',
 2013     OPT_all = 'a',
 2014     OPT_backoff = 'b',
 2015     OPT_bigheap = 'B',
 2016     OPT_cpu = 'c',
 2017     OPT_cache = 'C',
 2018     OPT_hdd = 'd',
 2019     OPT_dentry = 'D',
 2020     OPT_fork = 'f',
 2021     OPT_fallocate = 'F',
 2022     OPT_io = 'i',
 2023     OPT_job = 'j',
 2024     OPT_help = 'h',
 2025     OPT_keep_name = 'k',
 2026     OPT_cpu_load = 'l',
 2027     OPT_vm = 'm',
 2028     OPT_metrics = 'M',
 2029     OPT_dry_run = 'n',
 2030     OPT_rename = 'R',
 2031     OPT_open = 'o',
 2032     OPT_pipe = 'p',
 2033     OPT_poll = 'P',
 2034     OPT_quiet = 'q',
 2035     OPT_random = 'r',
 2036     OPT_switch = 's',
 2037     OPT_sock = 'S',
 2038     OPT_timeout = 't',
 2039     OPT_timer = 'T',
 2040     OPT_urandom = 'u',
 2041     OPT_verbose = 'v',
 2042     OPT_version = 'V',
 2043     OPT_yield = 'y',
 2044     OPT_yaml = 'Y',
 2045     OPT_exclude = 'x',
 2046 
 2047     /* Long options only */
 2048 
 2049     OPT_long_ops_start = 0x7f,
 2050 
 2051     OPT_abort,
 2052 
 2053     OPT_access,
 2054     OPT_access_ops,
 2055 
 2056     OPT_affinity,
 2057     OPT_affinity_ops,
 2058     OPT_affinity_rand,
 2059 
 2060     OPT_af_alg,
 2061     OPT_af_alg_ops,
 2062 
 2063     OPT_aggressive,
 2064 
 2065     OPT_aio,
 2066     OPT_aio_ops,
 2067     OPT_aio_requests,
 2068 
 2069     OPT_aiol,
 2070     OPT_aiol_ops,
 2071     OPT_aiol_requests,
 2072 
 2073     OPT_apparmor,
 2074     OPT_apparmor_ops,
 2075 
 2076     OPT_atomic,
 2077     OPT_atomic_ops,
 2078 
 2079     OPT_bad_altstack,
 2080     OPT_bad_altstack_ops,
 2081 
 2082     OPT_branch,
 2083     OPT_branch_ops,
 2084 
 2085     OPT_brk,
 2086     OPT_brk_ops,
 2087     OPT_brk_notouch,
 2088 
 2089     OPT_bsearch,
 2090     OPT_bsearch_ops,
 2091     OPT_bsearch_size,
 2092 
 2093     OPT_bigheap_ops,
 2094     OPT_bigheap_growth,
 2095 
 2096     OPT_bind_mount,
 2097     OPT_bind_mount_ops,
 2098 
 2099     OPT_class,
 2100     OPT_cache_ops,
 2101     OPT_cache_prefetch,
 2102     OPT_cache_flush,
 2103     OPT_cache_fence,
 2104     OPT_cache_level,
 2105     OPT_cache_ways,
 2106     OPT_cache_no_affinity,
 2107 
 2108     OPT_cap,
 2109     OPT_cap_ops,
 2110 
 2111     OPT_chdir,
 2112     OPT_chdir_dirs,
 2113     OPT_chdir_ops,
 2114 
 2115     OPT_chmod,
 2116     OPT_chmod_ops,
 2117 
 2118     OPT_chown,
 2119     OPT_chown_ops,
 2120 
 2121     OPT_chroot,
 2122     OPT_chroot_ops,
 2123 
 2124     OPT_clock,
 2125     OPT_clock_ops,
 2126 
 2127     OPT_clone,
 2128     OPT_clone_ops,
 2129     OPT_clone_max,
 2130 
 2131     OPT_close,
 2132     OPT_close_ops,
 2133 
 2134     OPT_context,
 2135     OPT_context_ops,
 2136 
 2137     OPT_copy_file,
 2138     OPT_copy_file_ops,
 2139     OPT_copy_file_bytes,
 2140 
 2141     OPT_cpu_ops,
 2142     OPT_cpu_method,
 2143     OPT_cpu_load_slice,
 2144 
 2145     OPT_cpu_online,
 2146     OPT_cpu_online_ops,
 2147     OPT_cpu_online_all,
 2148 
 2149     OPT_crypt,
 2150     OPT_crypt_ops,
 2151 
 2152     OPT_cyclic,
 2153     OPT_cyclic_ops,
 2154     OPT_cyclic_method,
 2155     OPT_cyclic_policy,
 2156     OPT_cyclic_prio,
 2157     OPT_cyclic_sleep,
 2158     OPT_cyclic_dist,
 2159 
 2160     OPT_daemon,
 2161     OPT_daemon_ops,
 2162 
 2163     OPT_dccp,
 2164     OPT_dccp_domain,
 2165     OPT_dccp_ops,
 2166     OPT_dccp_opts,
 2167     OPT_dccp_port,
 2168 
 2169     OPT_dentry_ops,
 2170     OPT_dentries,
 2171     OPT_dentry_order,
 2172 
 2173     OPT_dev,
 2174     OPT_dev_ops,
 2175 
 2176     OPT_dev_shm,
 2177     OPT_dev_shm_ops,
 2178 
 2179     OPT_dir,
 2180     OPT_dir_ops,
 2181     OPT_dir_dirs,
 2182 
 2183     OPT_dirdeep,
 2184     OPT_dirdeep_ops,
 2185     OPT_dirdeep_dirs,
 2186     OPT_dirdeep_inodes,
 2187 
 2188     OPT_dnotify,
 2189     OPT_dnotify_ops,
 2190 
 2191     OPT_dup,
 2192     OPT_dup_ops,
 2193 
 2194     OPT_dynlib,
 2195     OPT_dynlib_ops,
 2196 
 2197     OPT_efivar,
 2198     OPT_efivar_ops,
 2199 
 2200     OPT_enosys,
 2201     OPT_enosys_ops,
 2202 
 2203     OPT_epoll,
 2204     OPT_epoll_ops,
 2205     OPT_epoll_port,
 2206     OPT_epoll_domain,
 2207 
 2208     OPT_eventfd,
 2209     OPT_eventfd_ops,
 2210 
 2211     OPT_exec,
 2212     OPT_exec_ops,
 2213     OPT_exec_max,
 2214 
 2215     OPT_fallocate_ops,
 2216     OPT_fallocate_bytes,
 2217 
 2218     OPT_fanotify,
 2219     OPT_fanotify_ops,
 2220 
 2221     OPT_fault,
 2222     OPT_fault_ops,
 2223 
 2224     OPT_fcntl,
 2225     OPT_fcntl_ops,
 2226 
 2227     OPT_fiemap,
 2228     OPT_fiemap_ops,
 2229     OPT_fiemap_bytes,
 2230 
 2231     OPT_fifo,
 2232     OPT_fifo_ops,
 2233     OPT_fifo_readers,
 2234 
 2235     OPT_file_ioctl,
 2236     OPT_file_ioctl_ops,
 2237 
 2238     OPT_filename,
 2239     OPT_filename_ops,
 2240     OPT_filename_opts,
 2241 
 2242     OPT_flock,
 2243     OPT_flock_ops,
 2244 
 2245     OPT_fork_ops,
 2246     OPT_fork_max,
 2247 
 2248     OPT_fp_error,
 2249     OPT_fp_error_ops,
 2250 
 2251     OPT_fstat,
 2252     OPT_fstat_ops,
 2253     OPT_fstat_dir,
 2254 
 2255     OPT_full,
 2256     OPT_full_ops,
 2257 
 2258     OPT_funccall,
 2259     OPT_funccall_ops,
 2260     OPT_funccall_method,
 2261 
 2262     OPT_futex,
 2263     OPT_futex_ops,
 2264 
 2265     OPT_get,
 2266     OPT_get_ops,
 2267 
 2268     OPT_getrandom,
 2269     OPT_getrandom_ops,
 2270 
 2271     OPT_getdent,
 2272     OPT_getdent_ops,
 2273 
 2274     OPT_handle,
 2275     OPT_handle_ops,
 2276 
 2277     OPT_hdd_bytes,
 2278     OPT_hdd_write_size,
 2279     OPT_hdd_ops,
 2280     OPT_hdd_opts,
 2281 
 2282     OPT_heapsort,
 2283     OPT_heapsort_ops,
 2284     OPT_heapsort_integers,
 2285 
 2286     OPT_hrtimers,
 2287     OPT_hrtimers_ops,
 2288 
 2289     OPT_hsearch,
 2290     OPT_hsearch_ops,
 2291     OPT_hsearch_size,
 2292 
 2293     OPT_icache,
 2294     OPT_icache_ops,
 2295 
 2296     OPT_icmp_flood,
 2297     OPT_icmp_flood_ops,
 2298 
 2299     OPT_idle_page,
 2300     OPT_idle_page_ops,
 2301 
 2302     OPT_ignite_cpu,
 2303 
 2304     OPT_inode_flags,
 2305     OPT_inode_flags_ops,
 2306 
 2307     OPT_inotify,
 2308     OPT_inotify_ops,
 2309 
 2310     OPT_iomix,
 2311     OPT_iomix_bytes,
 2312     OPT_iomix_ops,
 2313 
 2314     OPT_ioport,
 2315     OPT_ioport_ops,
 2316     OPT_ioport_opts,
 2317 
 2318     OPT_ionice_class,
 2319     OPT_ionice_level,
 2320 
 2321     OPT_ioprio,
 2322     OPT_ioprio_ops,
 2323 
 2324     OPT_io_ops,
 2325 
 2326     OPT_ipsec_mb,
 2327     OPT_ipsec_mb_ops,
 2328 
 2329     OPT_itimer,
 2330     OPT_itimer_ops,
 2331     OPT_itimer_freq,
 2332 
 2333     OPT_kcmp,
 2334     OPT_kcmp_ops,
 2335 
 2336     OPT_key,
 2337     OPT_key_ops,
 2338 
 2339     OPT_kill,
 2340     OPT_kill_ops,
 2341 
 2342     OPT_klog,
 2343     OPT_klog_ops,
 2344 
 2345     OPT_lease,
 2346     OPT_lease_ops,
 2347     OPT_lease_breakers,
 2348 
 2349     OPT_link,
 2350     OPT_link_ops,
 2351 
 2352     OPT_lockbus,
 2353     OPT_lockbus_ops,
 2354 
 2355     OPT_locka,
 2356     OPT_locka_ops,
 2357 
 2358     OPT_lockf,
 2359     OPT_lockf_ops,
 2360     OPT_lockf_nonblock,
 2361 
 2362     OPT_lockofd,
 2363     OPT_lockofd_ops,
 2364 
 2365     OPT_log_brief,
 2366     OPT_log_file,
 2367 
 2368     OPT_longjmp,
 2369     OPT_longjmp_ops,
 2370 
 2371     OPT_loop,
 2372     OPT_loop_ops,
 2373 
 2374     OPT_lsearch,
 2375     OPT_lsearch_ops,
 2376     OPT_lsearch_size,
 2377 
 2378     OPT_madvise,
 2379     OPT_madvise_ops,
 2380 
 2381     OPT_malloc,
 2382     OPT_malloc_ops,
 2383     OPT_malloc_bytes,
 2384     OPT_malloc_max,
 2385     OPT_malloc_threshold,
 2386 
 2387     OPT_matrix,
 2388     OPT_matrix_ops,
 2389     OPT_matrix_size,
 2390     OPT_matrix_method,
 2391     OPT_matrix_yx,
 2392 
 2393     OPT_matrix_3d,
 2394     OPT_matrix_3d_ops,
 2395     OPT_matrix_3d_size,
 2396     OPT_matrix_3d_method,
 2397     OPT_matrix_3d_zyx,
 2398 
 2399     OPT_maximize,
 2400 
 2401     OPT_mcontend,
 2402     OPT_mcontend_ops,
 2403 
 2404     OPT_membarrier,
 2405     OPT_membarrier_ops,
 2406 
 2407     OPT_memcpy,
 2408     OPT_memcpy_ops,
 2409     OPT_memcpy_method,
 2410 
 2411     OPT_memfd,
 2412     OPT_memfd_ops,
 2413     OPT_memfd_bytes,
 2414     OPT_memfd_fds,
 2415 
 2416     OPT_memrate,
 2417     OPT_memrate_ops,
 2418     OPT_memrate_rd_mbs,
 2419     OPT_memrate_wr_mbs,
 2420     OPT_memrate_bytes,
 2421 
 2422     OPT_memthrash,
 2423     OPT_memthrash_ops,
 2424     OPT_memthrash_method,
 2425 
 2426     OPT_mergesort,
 2427     OPT_mergesort_ops,
 2428     OPT_mergesort_integers,
 2429 
 2430     OPT_metrics_brief,
 2431 
 2432     OPT_mincore,
 2433     OPT_mincore_ops,
 2434     OPT_mincore_rand,
 2435 
 2436     OPT_mknod,
 2437     OPT_mknod_ops,
 2438 
 2439     OPT_minimize,
 2440 
 2441     OPT_mlock,
 2442     OPT_mlock_ops,
 2443 
 2444     OPT_mlockmany,
 2445     OPT_mlockmany_ops,
 2446 
 2447     OPT_mmap,
 2448     OPT_mmap_ops,
 2449     OPT_mmap_bytes,
 2450     OPT_mmap_file,
 2451     OPT_mmap_async,
 2452     OPT_mmap_mprotect,
 2453 
 2454     OPT_mmapaddr,
 2455     OPT_mmapaddr_ops,
 2456 
 2457     OPT_mmapfixed,
 2458     OPT_mmapfixed_ops,
 2459 
 2460     OPT_mmapfork,
 2461     OPT_mmapfork_ops,
 2462 
 2463     OPT_mmapmany,
 2464     OPT_mmapmany_ops,
 2465 
 2466     OPT_mq,
 2467     OPT_mq_ops,
 2468     OPT_mq_size,
 2469 
 2470     OPT_mremap,
 2471     OPT_mremap_ops,
 2472     OPT_mremap_bytes,
 2473 
 2474     OPT_msg,
 2475     OPT_msg_ops,
 2476 
 2477     OPT_msync,
 2478     OPT_msync_bytes,
 2479     OPT_msync_ops,
 2480 
 2481     OPT_netdev,
 2482     OPT_netdev_ops,
 2483 
 2484     OPT_netlink_proc,
 2485     OPT_netlink_proc_ops,
 2486 
 2487     OPT_nice,
 2488     OPT_nice_ops,
 2489 
 2490     OPT_no_madvise,
 2491     OPT_no_rand_seed,
 2492 
 2493     OPT_nop,
 2494     OPT_nop_ops,
 2495 
 2496     OPT_null,
 2497     OPT_null_ops,
 2498 
 2499     OPT_numa,
 2500     OPT_numa_ops,
 2501 
 2502     OPT_oomable,
 2503 
 2504     OPT_physpage,
 2505     OPT_physpage_ops,
 2506 
 2507     OPT_oom_pipe,
 2508     OPT_oom_pipe_ops,
 2509 
 2510     OPT_opcode,
 2511     OPT_opcode_ops,
 2512     OPT_opcode_method,
 2513 
 2514     OPT_open_ops,
 2515 
 2516     OPT_page_in,
 2517     OPT_pathological,
 2518 
 2519     OPT_perf_stats,
 2520 
 2521     OPT_personality,
 2522     OPT_personality_ops,
 2523 
 2524     OPT_pipe_ops,
 2525     OPT_pipe_size,
 2526     OPT_pipe_data_size,
 2527 
 2528     OPT_pkey,
 2529     OPT_pkey_ops,
 2530 
 2531     OPT_poll_ops,
 2532 
 2533     OPT_prctl,
 2534     OPT_prctl_ops,
 2535 
 2536     OPT_procfs,
 2537     OPT_procfs_ops,
 2538 
 2539     OPT_pthread,
 2540     OPT_pthread_ops,
 2541     OPT_pthread_max,
 2542 
 2543     OPT_ptrace,
 2544     OPT_ptrace_ops,
 2545 
 2546     OPT_pty,
 2547     OPT_pty_ops,
 2548     OPT_pty_max,
 2549 
 2550     OPT_qsort,
 2551     OPT_qsort_ops,
 2552     OPT_qsort_integers,
 2553 
 2554     OPT_quota,
 2555     OPT_quota_ops,
 2556 
 2557     OPT_radixsort,
 2558     OPT_radixsort_ops,
 2559     OPT_radixsort_size,
 2560 
 2561     OPT_rawdev,
 2562     OPT_rawdev_method,
 2563     OPT_rawdev_ops,
 2564 
 2565     OPT_rdrand,
 2566     OPT_rdrand_ops,
 2567 
 2568     OPT_readahead,
 2569     OPT_readahead_ops,
 2570     OPT_readahead_bytes,
 2571 
 2572     OPT_remap,
 2573     OPT_remap_ops,
 2574 
 2575     OPT_rename_ops,
 2576 
 2577     OPT_resources,
 2578     OPT_resources_ops,
 2579 
 2580     OPT_revio,
 2581     OPT_revio_ops,
 2582     OPT_revio_opts,
 2583     OPT_revio_bytes,
 2584 
 2585     OPT_rlimit,
 2586     OPT_rlimit_ops,
 2587 
 2588     OPT_rmap,
 2589     OPT_rmap_ops,
 2590 
 2591     OPT_rtc,
 2592     OPT_rtc_ops,
 2593 
 2594     OPT_sched,
 2595     OPT_sched_prio,
 2596 
 2597     OPT_schedpolicy,
 2598     OPT_schedpolicy_ops,
 2599 
 2600     OPT_sctp,
 2601     OPT_sctp_ops,
 2602     OPT_sctp_domain,
 2603     OPT_sctp_port,
 2604 
 2605     OPT_seal,
 2606     OPT_seal_ops,
 2607 
 2608     OPT_seccomp,
 2609     OPT_seccomp_ops,
 2610 
 2611     OPT_seek,
 2612     OPT_seek_ops,
 2613     OPT_seek_punch,
 2614     OPT_seek_size,
 2615 
 2616     OPT_sendfile,
 2617     OPT_sendfile_ops,
 2618     OPT_sendfile_size,
 2619 
 2620     OPT_sem,
 2621     OPT_sem_ops,
 2622     OPT_sem_procs,
 2623 
 2624     OPT_sem_sysv,
 2625     OPT_sem_sysv_ops,
 2626     OPT_sem_sysv_procs,
 2627 
 2628     OPT_set,
 2629     OPT_set_ops,
 2630 
 2631     OPT_shm,
 2632     OPT_shm_ops,
 2633     OPT_shm_bytes,
 2634     OPT_shm_objects,
 2635 
 2636     OPT_shm_sysv,
 2637     OPT_shm_sysv_ops,
 2638     OPT_shm_sysv_bytes,
 2639     OPT_shm_sysv_segments,
 2640 
 2641     OPT_sequential,
 2642 
 2643     OPT_sigfd,
 2644     OPT_sigfd_ops,
 2645 
 2646     OPT_sigfpe,
 2647     OPT_sigfpe_ops,
 2648 
 2649     OPT_sigio,
 2650     OPT_sigio_ops,
 2651 
 2652     OPT_sigpending,
 2653     OPT_sigpending_ops,
 2654 
 2655     OPT_sigpipe,
 2656     OPT_sigpipe_ops,
 2657 
 2658     OPT_sigq,
 2659     OPT_sigq_ops,
 2660 
 2661     OPT_sigrt,
 2662     OPT_sigrt_ops,
 2663 
 2664     OPT_sigsegv,
 2665     OPT_sigsegv_ops,
 2666 
 2667     OPT_sigsuspend,
 2668     OPT_sigsuspend_ops,
 2669 
 2670     OPT_sleep,
 2671     OPT_sleep_ops,
 2672     OPT_sleep_max,
 2673 
 2674     OPT_sock_ops,
 2675     OPT_sock_domain,
 2676     OPT_sock_nodelay,
 2677     OPT_sock_opts,
 2678     OPT_sock_port,
 2679     OPT_sock_type,
 2680 
 2681     OPT_sockdiag,
 2682     OPT_sockdiag_ops,
 2683 
 2684     OPT_sockfd,
 2685     OPT_sockfd_ops,
 2686     OPT_sockfd_port,
 2687 
 2688     OPT_sockpair,
 2689     OPT_sockpair_ops,
 2690 
 2691     OPT_softlockup,
 2692     OPT_softlockup_ops,
 2693 
 2694     OPT_swap,
 2695     OPT_swap_ops,
 2696 
 2697     OPT_switch_ops,
 2698     OPT_switch_freq,
 2699 
 2700     OPT_spawn,
 2701     OPT_spawn_ops,
 2702 
 2703     OPT_splice,
 2704     OPT_splice_ops,
 2705     OPT_splice_bytes,
 2706 
 2707     OPT_stack,
 2708     OPT_stack_ops,
 2709     OPT_stack_fill,
 2710 
 2711     OPT_stackmmap,
 2712     OPT_stackmmap_ops,
 2713 
 2714     OPT_str,
 2715     OPT_str_ops,
 2716     OPT_str_method,
 2717 
 2718     OPT_stream,
 2719     OPT_stream_ops,
 2720     OPT_stream_index,
 2721     OPT_stream_l3_size,
 2722     OPT_stream_madvise,
 2723 
 2724     OPT_stressors,
 2725 
 2726     OPT_symlink,
 2727     OPT_symlink_ops,
 2728 
 2729     OPT_sync_file,
 2730     OPT_sync_file_ops,
 2731     OPT_sync_file_bytes,
 2732 
 2733     OPT_sysbadaddr,
 2734     OPT_sysbadaddr_ops,
 2735 
 2736     OPT_sysinfo,
 2737     OPT_sysinfo_ops,
 2738 
 2739     OPT_sysfs,
 2740     OPT_sysfs_ops,
 2741 
 2742     OPT_syslog,
 2743 
 2744     OPT_tee,
 2745     OPT_tee_ops,
 2746 
 2747     OPT_taskset,
 2748 
 2749     OPT_temp_path,
 2750 
 2751     OPT_thermal_zones,
 2752 
 2753     OPT_thrash,
 2754 
 2755     OPT_timer_slack,
 2756 
 2757     OPT_timer_ops,
 2758     OPT_timer_freq,
 2759     OPT_timer_rand,
 2760 
 2761     OPT_timerfd,
 2762     OPT_timerfd_ops,
 2763     OPT_timerfd_freq,
 2764     OPT_timerfd_rand,
 2765 
 2766     OPT_times,
 2767 
 2768     OPT_timestamp,
 2769 
 2770     OPT_tlb_shootdown,
 2771     OPT_tlb_shootdown_ops,
 2772 
 2773     OPT_tmpfs,
 2774     OPT_tmpfs_ops,
 2775 
 2776     OPT_tree,
 2777     OPT_tree_ops,
 2778     OPT_tree_method,
 2779     OPT_tree_size,
 2780 
 2781     OPT_tsc,
 2782     OPT_tsc_ops,
 2783 
 2784     OPT_tsearch,
 2785     OPT_tsearch_ops,
 2786     OPT_tsearch_size,
 2787 
 2788     OPT_udp,
 2789     OPT_udp_ops,
 2790     OPT_udp_port,
 2791     OPT_udp_domain,
 2792     OPT_udp_lite,
 2793 
 2794     OPT_udp_flood,
 2795     OPT_udp_flood_ops,
 2796     OPT_udp_flood_domain,
 2797 
 2798     OPT_unshare,
 2799     OPT_unshare_ops,
 2800 
 2801     OPT_urandom_ops,
 2802 
 2803     OPT_userfaultfd,
 2804     OPT_userfaultfd_ops,
 2805     OPT_userfaultfd_bytes,
 2806 
 2807     OPT_utime,
 2808     OPT_utime_ops,
 2809     OPT_utime_fsync,
 2810 
 2811     OPT_vdso,
 2812     OPT_vdso_ops,
 2813     OPT_vdso_func,
 2814 
 2815     OPT_vecmath,
 2816     OPT_vecmath_ops,
 2817 
 2818     OPT_verify,
 2819 
 2820     OPT_vfork,
 2821     OPT_vfork_ops,
 2822     OPT_vfork_max,
 2823 
 2824     OPT_vforkmany,
 2825     OPT_vforkmany_ops,
 2826 
 2827     OPT_vm_bytes,
 2828     OPT_vm_hang,
 2829     OPT_vm_keep,
 2830     OPT_vm_mmap_populate,
 2831     OPT_vm_mmap_locked,
 2832     OPT_vm_ops,
 2833     OPT_vm_madvise,
 2834     OPT_vm_method,
 2835 
 2836     OPT_vm_addr,
 2837     OPT_vm_addr_method,
 2838     OPT_vm_addr_ops,
 2839 
 2840     OPT_vm_rw,
 2841     OPT_vm_rw_ops,
 2842     OPT_vm_rw_bytes,
 2843 
 2844     OPT_vm_segv,
 2845     OPT_vm_segv_ops,
 2846 
 2847     OPT_vm_splice,
 2848     OPT_vm_splice_ops,
 2849     OPT_vm_splice_bytes,
 2850 
 2851     OPT_wait,
 2852     OPT_wait_ops,
 2853 
 2854     OPT_watchdog,
 2855     OPT_watchdog_ops,
 2856 
 2857     OPT_wcs,
 2858     OPT_wcs_ops,
 2859     OPT_wcs_method,
 2860 
 2861     OPT_xattr,
 2862     OPT_xattr_ops,
 2863 
 2864     OPT_yield_ops,
 2865 
 2866     OPT_zero,
 2867     OPT_zero_ops,
 2868 
 2869     OPT_zlib,
 2870     OPT_zlib_ops,
 2871     OPT_zlib_level,
 2872     OPT_zlib_method,
 2873 
 2874     OPT_zombie,
 2875     OPT_zombie_ops,
 2876     OPT_zombie_max,
 2877 } stress_op_t;
 2878 
 2879 /* stress test metadata */
 2880 typedef struct {
 2881     const stressor_info_t *info;    /* stress test info */
 2882     const stress_id_t id;       /* stress test ID */
 2883     const short int short_getopt;   /* getopt short option */
 2884     const stress_op_t op;       /* ops option */
 2885     const char *name;       /* name of stress test */
 2886 } stress_t;
 2887 
 2888 /* Per process information */
 2889 typedef struct proc_info {
 2890     struct proc_info *next;     /* next proc info struct in list */
 2891     struct proc_info *prev;     /* prev proc info struct in list */
 2892     const stress_t *stressor;   /* stressor */
 2893     pid_t   *pids;          /* process id */
 2894     proc_stats_t **stats;       /* process proc stats info */
 2895     int32_t started_procs;      /* count of started processes */
 2896     int32_t num_procs;      /* number of process per stressor */
 2897     uint64_t bogo_ops;      /* number of bogo ops */
 2898 } proc_info_t;
 2899 
 2900 /* Pointer to current running stressor proc info */
 2901 extern proc_info_t *proc_current;
 2902 
 2903 /* Scale lookup mapping, suffix -> scale by */
 2904 typedef struct {
 2905     const char  ch;     /* Scaling suffix */
 2906     const uint64_t  scale;      /* Amount to scale by */
 2907 } scale_t;
 2908 
 2909 /* Cache types */
 2910 typedef enum cache_type {
 2911     CACHE_TYPE_UNKNOWN = 0,     /* Unknown type */
 2912     CACHE_TYPE_DATA,        /* D$ */
 2913     CACHE_TYPE_INSTRUCTION,     /* I$ */
 2914     CACHE_TYPE_UNIFIED,     /* D$ + I$ */
 2915 } cache_type_t;
 2916 
 2917 /* CPU cache information */
 2918 typedef struct cpu_cache {
 2919     uint64_t           size;        /* cache size in bytes */
 2920     uint32_t           line_size;   /* cache line size in bytes */
 2921     uint32_t           ways;    /* cache ways */
 2922     cache_type_t       type;    /* cache type */
 2923     uint16_t           level;   /* cache level, L1, L2 etc */
 2924 } cpu_cache_t;
 2925 
 2926 typedef struct cpu {
 2927     cpu_cache_t   *caches;      /* CPU cache data */
 2928     uint32_t       num;     /* CPU # number */
 2929     uint32_t       cache_count; /* CPU cache #  */
 2930     bool           online;      /* CPU online when true */
 2931 } cpu_t;
 2932 
 2933 typedef struct cpus {
 2934     cpu_t     *cpus;        /* CPU data */
 2935     uint32_t   count;       /* CPU count */
 2936 } cpus_t;
 2937 
 2938 /* Various global option settings and flags */
 2939 extern const char *g_app_name;      /* Name of application */
 2940 extern shared_t *g_shared;      /* shared memory */
 2941 extern uint64_t g_opt_timeout;      /* timeout in seconds */
 2942 extern uint64_t g_opt_flags;        /* option flags */
 2943 extern int32_t g_opt_sequential;    /* Number of sequential stressors */
 2944 extern int32_t g_opt_parallel;      /* Number of parallel stressors */
 2945 extern volatile bool g_keep_stressing_flag; /* false to exit stressor */
 2946 extern volatile bool g_caught_sigint;   /* true if stopped by SIGINT */
 2947 extern pid_t g_pgrp;            /* proceess group leader */
 2948 extern jmp_buf g_error_env;     /* parsing error env */
 2949 extern put_val_t g_put_val;     /* sync data to somewhere */
 2950 
 2951 /*
 2952  *  stressor option value handling
 2953  */
 2954 extern int set_setting(const char *name, const type_id_t type_id, const void *value);
 2955 extern int set_setting_global(const char *name, const type_id_t type_id, const void *value);
 2956 extern bool get_setting(const char *name, void *value);
 2957 extern void free_settings(void);
 2958 
 2959 /*
 2960  *  externs to force gcc to stash computed values and hence
 2961  *  to stop the optimiser optimising code away to zero. The
 2962  *  *_put funcs are essentially no-op functions.
 2963  */
 2964 extern uint64_t stress_uint64_zero(void);
 2965 
 2966 /*
 2967  *  uint8_put()
 2968  *  stash a uint8_t value
 2969  */
 2970 static inline void ALWAYS_INLINE uint8_put(const uint8_t a)
 2971 {
 2972     g_put_val.uint8_val = a;
 2973 }
 2974 
 2975 /*
 2976  *  uint16_put()
 2977  *  stash a uint16_t value
 2978  */
 2979 static inline void ALWAYS_INLINE uint16_put(const uint16_t a)
 2980 {
 2981     g_put_val.uint16_val = a;
 2982 }
 2983 
 2984 /*
 2985  *  uint32_put()
 2986  *  stash a uint32_t value
 2987  */
 2988 static inline void ALWAYS_INLINE uint32_put(const uint32_t a)
 2989 {
 2990     g_put_val.uint32_val = a;
 2991 }
 2992 
 2993 /*
 2994  *  uint64_put()
 2995  *  stash a uint64_t value
 2996  */
 2997 static inline void ALWAYS_INLINE uint64_put(const uint64_t a)
 2998 {
 2999     g_put_val.uint64_val = a;
 3000 }
 3001 
 3002 #if defined(HAVE_INT128_T)
 3003 /*
 3004  *  uint128_put()
 3005  *  stash a uint128_t value
 3006  */
 3007 static inline void ALWAYS_INLINE uint128_put(const __uint128_t a)
 3008 {
 3009     g_put_val.uint128_val = a;
 3010 }
 3011 #endif
 3012 
 3013 /*
 3014  *  float_put()
 3015  *  stash a float value
 3016  */
 3017 static inline void ALWAYS_INLINE float_put(const float a)
 3018 {
 3019     g_put_val.float_val = a;
 3020 }
 3021 
 3022 /*
 3023  *  double_put()
 3024  *  stash a double value
 3025  */
 3026 static inline void ALWAYS_INLINE double_put(const double a)
 3027 {
 3028     g_put_val.double_val = a;
 3029 }
 3030 
 3031 /*
 3032  *  long_double_put()
 3033  *  stash a double value
 3034  */
 3035 static inline void ALWAYS_INLINE long_double_put(const double a)
 3036 {
 3037     g_put_val.long_double_val = a;
 3038 }
 3039 
 3040 
 3041 /* Filenames and directories */
 3042 extern int stress_temp_filename(char *path, const size_t len,
 3043     const char *name, const pid_t pid, const uint32_t instance,
 3044     const uint64_t magic);
 3045 extern int stress_temp_filename_args(const args_t *args, char *path,
 3046     const size_t len, const uint64_t magic);
 3047 extern int stress_temp_dir(char *path, const size_t len,
 3048     const char *name, const pid_t pid, const uint32_t instance);
 3049 extern int stress_temp_dir_args(const args_t *args, char *path, const size_t len);
 3050 extern WARN_UNUSED int stress_temp_dir_mk(const char *name, const pid_t pid,
 3051     const uint32_t instance);
 3052 extern WARN_UNUSED int stress_temp_dir_mk_args(const args_t *args);
 3053 extern int stress_temp_dir_rm(const char *name, const pid_t pid,
 3054     const uint32_t instance);
 3055 extern int stress_temp_dir_rm_args(const args_t *args);
 3056 extern void stress_cwd_readwriteable(void);
 3057 
 3058 extern const char *stress_strsignal(const int signum);
 3059 
 3060 #if defined(STRESS_X86)
 3061 /*
 3062  *  clflush()
 3063  *  flush a cache line
 3064  */
 3065 static inline void ALWAYS_INLINE clflush(volatile void *ptr)
 3066 {
 3067         asm volatile("clflush %0" : "+m" (*(volatile char *)ptr));
 3068 }
 3069 #else
 3070 #define clflush(ptr)    do { } while (0) /* No-op */
 3071 #endif
 3072 
 3073 /*
 3074  *  mfence()
 3075  *  serializing memory fence
 3076  */
 3077 static inline void ALWAYS_INLINE mfence(void)
 3078 {
 3079 #if NEED_GNUC(4, 2, 0) && !defined(__PCC__)
 3080     __sync_synchronize();
 3081 #else
 3082 #if defined(STRESS_X86)
 3083     asm volatile("mfence" : : : "memory");
 3084 #else
 3085     /* Other arches not yet implemented for older GCC flavours */
 3086 #endif
 3087 #endif
 3088 }
 3089 
 3090 /* Fast random numbers */
 3091 extern uint32_t mwc32(void);
 3092 extern uint64_t mwc64(void);
 3093 extern uint16_t mwc16(void);
 3094 extern uint8_t mwc8(void);
 3095 extern uint8_t mwc1(void);
 3096 extern void mwc_seed(const uint32_t w, const uint32_t z);
 3097 extern void mwc_reseed(void);
 3098 
 3099 /* Time handling */
 3100 
 3101 /*
 3102  *  timeval_to_double()
 3103  *      convert timeval to seconds as a double
 3104  */
 3105 static inline WARN_UNUSED double timeval_to_double(const struct timeval *tv)
 3106 {
 3107         return (double)tv->tv_sec + ((double)tv->tv_usec / 1000000.0);
 3108 }
 3109 
 3110 extern double time_now(void);
 3111 extern const char *duration_to_str(const double duration);
 3112 
 3113 /* Perf statistics */
 3114 #if defined(STRESS_PERF_STATS)
 3115 extern int perf_open(stress_perf_t *sp);
 3116 extern int perf_enable(stress_perf_t *sp);
 3117 extern int perf_disable(stress_perf_t *sp);
 3118 extern int perf_close(stress_perf_t *sp);
 3119 extern bool perf_stat_succeeded(const stress_perf_t *sp);
 3120 extern void perf_stat_dump(FILE *yaml, proc_info_t *procs_head, const double duration);
 3121 extern void perf_init(void);
 3122 #endif
 3123 
 3124 /* CPU helpers */
 3125 extern WARN_UNUSED bool cpu_is_x86(void);
 3126 
 3127 /* Misc settings helpers */
 3128 extern void set_oom_adjustment(const char *name, const bool killable);
 3129 extern WARN_UNUSED bool process_oomed(const pid_t pid);
 3130 extern WARN_UNUSED int stress_set_sched(const pid_t pid, const int32_t sched,
 3131     const int sched_priority, const bool quiet);
 3132 extern const char *stress_get_sched_name(const int sched);
 3133 extern void set_iopriority(const int32_t class, const int32_t level);
 3134 extern void stress_set_proc_name(const char *name);
 3135 
 3136 /* Memory locking */
 3137 extern int stress_mlock_region(const void *addr_start, const void *addr_end);
 3138 
 3139 /* Argument parsing and range checking */
 3140 extern WARN_UNUSED uint64_t get_uint64(const char *const str);
 3141 extern WARN_UNUSED uint64_t get_uint64_scale(const char *const str,
 3142     const scale_t scales[], const char *const msg);
 3143 extern WARN_UNUSED uint64_t get_uint64_percent(const char *const str,
 3144     const uint32_t instances, const uint64_t max, const char *const errmsg);
 3145 extern WARN_UNUSED uint64_t get_uint64_byte(const char *const str);
 3146 extern WARN_UNUSED uint64_t get_uint64_byte_memory(const char *const str,
 3147     const uint32_t instances);
 3148 extern WARN_UNUSED uint64_t get_uint64_byte_filesystem(const char *const str,
 3149     const uint32_t instances);
 3150 extern WARN_UNUSED uint64_t get_uint64_time(const char *const str);
 3151 extern void check_value(const char *const msg, const int val);
 3152 extern void check_range(const char *const opt, const uint64_t val,
 3153     const uint64_t lo, const uint64_t hi);
 3154 extern void check_range_bytes(const char *const opt, const uint64_t val,
 3155     const uint64_t lo, const uint64_t hi);
 3156 extern WARN_UNUSED int stress_set_cpu_affinity(const char *arg);
 3157 extern WARN_UNUSED uint32_t get_uint32(const char *const str);
 3158 extern WARN_UNUSED int32_t  get_int32(const char *const str);
 3159 extern WARN_UNUSED int32_t  get_opt_sched(const char *const str);
 3160 extern WARN_UNUSED int32_t  get_opt_ionice_class(const char *const str);
 3161 
 3162 /* Misc helper funcs */
 3163 extern void stress_unmap_shared(void);
 3164 extern void log_system_mem_info(void);
 3165 extern WARN_UNUSED char *stress_munge_underscore(const char *str);
 3166 extern size_t stress_get_pagesize(void);
 3167 extern WARN_UNUSED int32_t stress_get_processors_online(void);
 3168 extern WARN_UNUSED int32_t stress_get_processors_configured(void);
 3169 extern WARN_UNUSED int32_t stress_get_ticks_per_second(void);
 3170 extern WARN_UNUSED ssize_t stress_get_stack_direction(void);
 3171 extern void stress_get_memlimits(size_t *shmall, size_t *freemem, size_t *totalmem, size_t *freeswap);
 3172 extern WARN_UNUSED int stress_get_load_avg(double *min1, double *min5, double *min15);
 3173 extern void set_max_limits(void);
 3174 extern void stress_parent_died_alarm(void);
 3175 extern int stress_process_dumpable(const bool dumpable);
 3176 extern int stress_set_timer_slack_ns(const char *opt);
 3177 extern void stress_set_timer_slack(void);
 3178 extern WARN_UNUSED int stress_set_temp_path(const char *path);
 3179 extern void stress_strnrnd(char *str, const size_t len);
 3180 extern void stress_get_cache_size(uint64_t *l2, uint64_t *l3);
 3181 extern WARN_UNUSED unsigned int stress_get_cpu(void);
 3182 extern WARN_UNUSED const char *stress_get_compiler(void);
 3183 extern WARN_UNUSED const char *stress_get_uname_info(void);
 3184 extern WARN_UNUSED int stress_cache_alloc(const char *name);
 3185 extern void stress_cache_free(void);
 3186 extern void ignite_cpu_start(void);
 3187 extern void ignite_cpu_stop(void);
 3188 extern int system_write(const char *path, const char *buf, const size_t buf_len);
 3189 extern WARN_UNUSED int stress_set_nonblock(const int fd);
 3190 extern WARN_UNUSED int system_read(const char *path, char *buf, const size_t buf_len);
 3191 extern WARN_UNUSED uint64_t stress_get_prime64(const uint64_t n);
 3192 extern WARN_UNUSED size_t stress_get_file_limit(void);
 3193 extern WARN_UNUSED int stress_sigaltstack(const void *stack, const size_t size);
 3194 extern WARN_UNUSED int stress_sighandler(const char *name, const int signum, void (*handler)(int), struct sigaction *orig_action);
 3195 extern void stress_handle_stop_stressing(int dummy);
 3196 extern WARN_UNUSED int stress_sig_stop_stressing(const char *name, const int sig);
 3197 extern int stress_sigrestore(const char *name, const int signum, struct sigaction *orig_action);
 3198 extern WARN_UNUSED int stress_not_implemented(const args_t *args);
 3199 extern WARN_UNUSED size_t stress_probe_max_pipe_size(void);
 3200 extern WARN_UNUSED void *stress_align_address(const void *addr, const size_t alignment);
 3201 extern void mmap_set(uint8_t *buf, const size_t sz, const size_t page_size);
 3202 extern WARN_UNUSED int mmap_check(uint8_t *buf, const size_t sz, const size_t page_size);
 3203 extern WARN_UNUSED uint64_t stress_get_phys_mem_size(void);
 3204 extern WARN_UNUSED uint64_t stress_get_filesystem_size(void);
 3205 extern WARN_UNUSED uint64_t stress_get_filesystem_available_inodes(void);
 3206 extern char *stress_uint64_to_str(char *str, size_t len, const uint64_t val);
 3207 extern WARN_UNUSED int stress_drop_capabilities(const char *name);
 3208 extern WARN_UNUSED bool stress_is_dot_filename(const char *name);
 3209 extern WARN_UNUSED char *stress_const_optdup(const char *opt);
 3210 extern size_t stress_text_addr(char **start, char **end);
 3211 
 3212 /*
 3213  *  Indicate a stress test failed because of limited resources
 3214  *  rather than a failure of the tests during execution.
 3215  *  err is the errno of the failure.
 3216  */
 3217 static inline WARN_UNUSED ALWAYS_INLINE int exit_status(const int err)
 3218 {
 3219     switch (err) {
 3220     case ENOMEM:
 3221     case ENOSPC:
 3222         return EXIT_NO_RESOURCE;
 3223     case ENOSYS:
 3224         return EXIT_NOT_IMPLEMENTED;
 3225     }
 3226     return EXIT_FAILURE;
 3227 }
 3228 
 3229 /*
 3230  *  Stack aligning for clone() system calls
 3231  *  align to nearest 16 bytes for aarch64 et al,
 3232  *  assumes we have enough slop to do this
 3233  */
 3234 static inline WARN_UNUSED ALWAYS_INLINE void *align_stack(void *stack_top)
 3235 {
 3236     return (void *)((uintptr_t)stack_top & ~(uintptr_t)0xf);
 3237 }
 3238 
 3239 /*
 3240  *  Check if flag is set, and set flag
 3241  */
 3242 static inline WARN_UNUSED uint32_t warn_once(const uint32_t flag)
 3243 {
 3244     uint32_t tmp;
 3245 #if defined(HAVE_LIB_PTHREAD)
 3246     int ret;
 3247 
 3248     ret = shim_pthread_spin_lock(&g_shared->warn_once.lock);
 3249 #endif
 3250     tmp = !(g_shared->warn_once.flags & flag);
 3251     g_shared->warn_once.flags |= flag;
 3252 #if defined(HAVE_LIB_PTHREAD)
 3253     if (!ret)
 3254         shim_pthread_spin_unlock(&g_shared->warn_once.lock);
 3255 #endif
 3256     return tmp;
 3257 }
 3258 
 3259 /* Jobfile parsing */
 3260 extern WARN_UNUSED int parse_jobfile(int argc, char **argv, const char *jobfile);
 3261 extern WARN_UNUSED int parse_opts(int argc, char **argv, const bool jobmode);
 3262 
 3263 /* Memory tweaking */
 3264 extern int madvise_random(void *addr, const size_t length);
 3265 extern int mincore_touch_pages(void *buf, const size_t buf_len);
 3266 
 3267 /* Mounts */
 3268 extern void mount_free(char *mnts[], const int n);
 3269 extern WARN_UNUSED int mount_get(char *mnts[], const int max);
 3270 
 3271 /* Thermal Zones */
 3272 #if defined(STRESS_THERMAL_ZONES)
 3273 extern int tz_init(tz_info_t **tz_info_list);
 3274 extern void tz_free(tz_info_t **tz_info_list);
 3275 extern int tz_get_temperatures(tz_info_t **tz_info_list, stress_tz_t *tz);
 3276 extern void tz_dump(FILE *yaml, proc_info_t *procs_head);
 3277 #endif
 3278 
 3279 /* Network helpers */
 3280 
 3281 #define NET_ADDR_ANY        (0)
 3282 #define NET_ADDR_LOOPBACK   (1)
 3283 
 3284 extern void stress_set_net_port(const char *optname, const char *opt,
 3285     const int min_port, const int max_port, int *port);
 3286 extern WARN_UNUSED int stress_set_net_domain(const int domain_mask, const char *name, const char *domain_name, int *domain);
 3287 extern void stress_set_sockaddr(const char *name, const uint32_t instance,
 3288     const pid_t ppid, const int domain, const int port,
 3289     struct sockaddr **sockaddr, socklen_t *len, const int net_addr);
 3290 extern void stress_set_sockaddr_port(const int domain, const int port, struct sockaddr *sockaddr);
 3291 
 3292 /* CPU caches */
 3293 extern cpus_t *get_all_cpu_cache_details(void);
 3294 extern uint16_t get_max_cache_level(const cpus_t *cpus);
 3295 extern cpu_cache_t *get_cpu_cache(const cpus_t *cpus, const uint16_t cache_level);
 3296 extern void free_cpu_caches(cpus_t *cpus);
 3297 
 3298 /* CPU thrashing start/stop helpers */
 3299 extern int  thrash_start(void);
 3300 extern void thrash_stop(void);
 3301 
 3302 /* Used to set options for specific stressors */
 3303 extern void stress_adjust_pthread_max(const uint64_t max);
 3304 extern void stress_adjust_sleep_max(const uint64_t max);
 3305 extern int  stress_set_aio_requests(const char *opt);
 3306 extern int  stress_set_aio_linux_requests(const char *opt);
 3307 extern int  stress_set_bigheap_growth(const char *arg);
 3308 extern int  stress_set_bsearch_size(const char *opt);
 3309 extern int  stress_set_chdir_dirs(const char *opt);
 3310 extern int  stress_set_clone_max(const char *opt);
 3311 extern int  stress_set_copy_file_bytes(const char *opt);
 3312 extern int  stress_set_cpu_load(const char *opt);
 3313 extern int  stress_set_cpu_load_slice(const char *opt);
 3314 extern int  stress_set_cpu_method(const char *name);
 3315 extern int  stress_set_cyclic_dist(const char *opt);
 3316 extern int  stress_set_cyclic_method(const char *opt);
 3317 extern int  stress_set_cyclic_policy(const char *opt);
 3318 extern int  stress_set_cyclic_prio(const char *opt);
 3319 extern int  stress_set_cyclic_sleep(const char *opt);
 3320 extern int  stress_set_dccp_domain(const char *name);
 3321 extern int  stress_set_dccp_opts(const char *opt);
 3322 extern int  stress_set_dccp_port(const char *opt);
 3323 extern int  stress_set_dentries(const char *opt);
 3324 extern int  stress_set_dentry_order(const char *opt);
 3325 extern int  stress_set_dir_dirs(const char *opt);
 3326 extern int  stress_set_dirdeep_dirs(const char *opt);
 3327 extern int  stress_set_dirdeep_inodes(const char *opt);
 3328 extern int  stress_set_epoll_port(const char *opt);
 3329 extern int  stress_set_epoll_domain(const char *opt);
 3330 extern int  stress_set_exec_max(const char *opt);
 3331 extern int  stress_set_fallocate_bytes(const char *opt);
 3332 extern int  stress_set_fifo_readers(const char *opt);
 3333 extern int  stress_set_funccall_method(const char *name);
 3334 extern int  stress_set_filename_opts(const char *opt);
 3335 extern int  stress_set_fiemap_bytes(const char *opt);
 3336 extern int  stress_set_fork_max(const char *opt);
 3337 extern int  stress_set_fstat_dir(const char *opt);
 3338 extern int  stress_set_hdd_bytes(const char *opt);
 3339 extern int  stress_set_hdd_opts(const char *opts);
 3340 extern int  stress_set_hdd_write_size(const char *opt);
 3341 extern int  stress_set_heapsort_size(const char *opt);
 3342 extern int  stress_set_hsearch_size(const char *opt);
 3343 extern int  stress_set_iomix_bytes(const char *opt);
 3344 extern int  stress_set_ioport_opts(const char *opts);
 3345 extern int  stress_set_itimer_freq(const char *opt);
 3346 extern int  stress_set_lease_breakers(const char *opt);
 3347 extern int  stress_set_lsearch_size(const char *opt);
 3348 extern int  stress_set_malloc_bytes(const char *opt);
 3349 extern int  stress_set_malloc_max(const char *opt);
 3350 extern int  stress_set_malloc_threshold(const char *opt);
 3351 extern int  stress_set_matrix_method(const char *name);
 3352 extern int  stress_set_matrix_yx(const char *opt);
 3353 extern int  stress_set_matrix_size(const char *opt);
 3354 extern int  stress_set_matrix_3d_method(const char *name);
 3355 extern int  stress_set_matrix_3d_size(const char *opt);
 3356 extern int  stress_set_matrix_3d_zyx(const char *opt);
 3357 extern int  stress_set_memcpy_method(const char *name);
 3358 extern int  stress_set_memfd_bytes(const char *opt);
 3359 extern int  stress_set_memfd_fds(const char *opt);
 3360 extern int  stress_set_memrate_bytes(const char *opt);
 3361 extern int  stress_set_memrate_rd_mbs(const char *opt);
 3362 extern int  stress_set_memrate_wr_mbs(const char *opt);
 3363 extern int  stress_set_memthrash_method(const char *name);
 3364 extern int  stress_set_mergesort_size(const char *opt);
 3365 extern int  stress_set_mmap_bytes(const char *opt);
 3366 extern int  stress_set_mq_size(const char *opt);
 3367 extern int  stress_set_mremap_bytes(const char *opt);
 3368 extern int  stress_set_msync_bytes(const char *opt);
 3369 extern int  stress_set_opcode_method(const char *name);
 3370 extern int  stress_set_pipe_data_size(const char *opt);
 3371 extern int  stress_set_pipe_size(const char *opt);
 3372 extern int  stress_set_pthread_max(const char *opt);
 3373 extern int  stress_set_pty_max(const char *opt);
 3374 extern int  stress_set_qsort_size(const char *opt);
 3375 extern int  stress_set_radixsort_size(const char *opt);
 3376 extern int  stress_set_rawdev_method(const char *name);
 3377 extern int  stress_set_readahead_bytes(const char *opt);
 3378 extern int  stress_set_revio_bytes(const char *opt);
 3379 extern int  stress_set_revio_opts(const char *opts);
 3380 extern int  stress_set_sctp_domain(const char *opt);
 3381 extern int  stress_set_sctp_port(const char *opt);
 3382 extern int  stress_set_seek_size(const char *opt);
 3383 extern int  stress_set_semaphore_posix_procs(const char *opt);
 3384 extern int  stress_set_semaphore_sysv_procs(const char *opt);
 3385 extern int  stress_set_sendfile_size(const char *opt);
 3386 extern int  stress_set_shm_posix_bytes(const char *opt);
 3387 extern int  stress_set_shm_posix_objects(const char *opt);
 3388 extern int  stress_set_shm_sysv_bytes(const char *opt);
 3389 extern int  stress_set_shm_sysv_segments(const char *opt);
 3390 extern int  stress_set_sleep_max(const char *opt);
 3391 extern int  stress_set_socket_domain(const char *name);
 3392 extern int  stress_set_socket_opts(const char *opt);
 3393 extern int  stress_set_socket_type(const char *opt);
 3394 extern int  stress_set_socket_port(const char *opt);
 3395 extern int  stress_set_socket_fd_port(const char *opt);
 3396 extern int  stress_set_splice_bytes(const char *opt);
 3397 extern int  stress_set_str_method(const char *name);
 3398 extern int  stress_set_stream_L3_size(const char *opt);
 3399 extern int  stress_set_stream_index(const char *opt);
 3400 extern int  stress_set_stream_madvise(const char *opt);
 3401 extern int  stress_set_switch_freq(const char *opt);
 3402 extern int  stress_set_sync_file_bytes(const char *opt);
 3403 extern int  stress_set_timer_freq(const char *opt);
 3404 extern int  stress_set_timerfd_freq(const char *opt);
 3405 extern int  stress_set_tree_method(const char *name);
 3406 extern int  stress_set_tree_size(const char *opt);
 3407 extern int  stress_set_tsearch_size(const char *opt);
 3408 extern int  stress_set_udp_domain(const char *name);
 3409 extern int  stress_set_udp_port(const char *opt);
 3410 extern int  stress_set_udp_flood_domain(const char *name);
 3411 extern int  stress_set_userfaultfd_bytes(const char *opt);
 3412 extern int  stress_set_vdso_func(const char *name);
 3413 extern int  stress_set_vfork_max(const char *opt);
 3414 extern int  stress_set_vm_bytes(const char *opt);
 3415 extern int  stress_set_vm_flags(const int flag);
 3416 extern int  stress_set_vm_hang(const char *opt);
 3417 extern int  stress_set_vm_madvise(const char *name);
 3418 extern int  stress_set_vm_method(const char *name);
 3419 extern int  stress_set_vm_rw_bytes(const char *opt);
 3420 extern int  stress_set_vm_splice_bytes(const char *opt);
 3421 extern int  stress_set_vm_addr_method(const char *name);
 3422 extern int  stress_set_wcs_method(const char *name);
 3423 extern int  stress_set_zlib_level(const char *name);
 3424 extern int  stress_set_zlib_method(const char *name);
 3425 extern int  stress_set_zombie_max(const char *opt);
 3426 
 3427 /* loff_t and off64_t porting shims */
 3428 #if defined(HAVE_LOFF_T)
 3429 typedef loff_t      shim_loff_t;
 3430 #else
 3431 typedef uint64_t    shim_loff_t;    /* Assume 64 bit */
 3432 #endif
 3433 
 3434 #if defined(HAVE_OFF64_T)
 3435 typedef off64_t     shim_off64_t;
 3436 #else
 3437 typedef uint64_t    shim_off64_t;
 3438 #endif
 3439 
 3440 /*
 3441  *  shim'd abstracted system or library calls
 3442  *  that have a layer of OS abstraction
 3443  */
 3444 struct shim_linux_dirent {
 3445     unsigned long   d_ino;      /* Inode number */
 3446     unsigned long   d_off;      /* Offset to next linux_dirent */
 3447     unsigned short  d_reclen;   /* Length of this linux_dirent */
 3448     char        d_name[];   /* Filename (null-terminated) */
 3449 };
 3450 
 3451 /* dirent64 porting shim */
 3452 struct shim_linux_dirent64 {
 3453 #if defined(HAVE_INO64_T)
 3454     ino64_t     d_ino;      /* 64-bit inode number */
 3455 #else
 3456     int64_t     d_ino;      /* 64-bit inode number */
 3457 #endif
 3458     shim_off64_t    d_off;      /* 64-bit offset to next structure */
 3459     unsigned short  d_reclen;   /* Size of this dirent */
 3460     unsigned char   d_type;     /* File type */
 3461     char        d_name[];   /* Filename (null-terminated) */
 3462 };
 3463 
 3464 /* sched_getattr attributes */
 3465 struct shim_sched_attr {
 3466     uint32_t size;          /* size of struct */
 3467     uint32_t sched_policy;      /* policy, SCHED_* */
 3468     uint64_t sched_flags;       /* scheduling flags */
 3469     int32_t  sched_nice;        /* nice value SCHED_OTHER, SCHED_BATCH */
 3470     uint32_t sched_priority;    /* priority SCHED_FIFO, SCHED_RR */
 3471     uint64_t sched_runtime;     /* runtime SCHED_DEADLINE, ns */
 3472     uint64_t sched_deadline;    /* deadline time, ns */
 3473     uint64_t sched_period;      /* period, ns */
 3474 };
 3475 
 3476 /* shim'd STATX flags */
 3477 #define SHIM_STATX_TYPE              0x00000001U
 3478 #define SHIM_STATX_MODE              0x00000002U
 3479 #define SHIM_STATX_NLINK             0x00000004U
 3480 #define SHIM_STATX_UID               0x00000008U
 3481 #define SHIM_STATX_GID               0x00000010U
 3482 #define SHIM_STATX_ATIME             0x00000020U
 3483 #define SHIM_STATX_MTIME             0x00000040U
 3484 #define SHIM_STATX_CTIME             0x00000080U
 3485 #define SHIM_STATX_INO               0x00000100U
 3486 #define SHIM_STATX_SIZE              0x00000200U
 3487 #define SHIM_STATX_BLOCKS            0x00000400U
 3488 #define SHIM_STATX_BASIC_STATS       0x000007ffU
 3489 #define SHIM_STATX_BTIME             0x00000800U
 3490 #define SHIM_STATX_ALL               0x00000fffU
 3491 
 3492 struct shim_statx_timestamp {
 3493         int64_t     tv_sec;
 3494         int32_t     tv_nsec;
 3495         int32_t     __reserved;
 3496 };
 3497 
 3498 /* shim'd statx */
 3499 struct shim_statx {
 3500         uint32_t   stx_mask;
 3501         uint32_t   stx_blksize;
 3502         uint64_t   stx_attributes;
 3503         uint32_t   stx_nlink;
 3504         uint32_t   stx_uid;
 3505         uint32_t   stx_gid;
 3506         uint16_t   stx_mode;
 3507         uint16_t   __spare0[1];
 3508         uint64_t   stx_ino;
 3509         uint64_t   stx_size;
 3510         uint64_t   stx_blocks;
 3511         uint64_t   __spare1[1];
 3512         struct shim_statx_timestamp  stx_atime;
 3513         struct shim_statx_timestamp  stx_btime;
 3514         struct shim_statx_timestamp  stx_ctime;
 3515         struct shim_statx_timestamp  stx_mtime;
 3516         uint32_t   stx_rdev_major;
 3517         uint32_t   stx_rdev_minor;
 3518         uint32_t   stx_dev_major;
 3519         uint32_t   stx_dev_minor;
 3520         uint64_t   __spare2[14];
 3521 };
 3522 
 3523 extern int shim_brk(void *addr);
 3524 extern int shim_cacheflush(char *addr, int nbytes, int cache) ;
 3525 extern void shim_clear_cache(char* begin, char *end);
 3526 extern ssize_t shim_copy_file_range(int fd_in, shim_loff_t *off_in,
 3527         int fd_out, shim_loff_t *off_out, size_t len, unsigned int flags);
 3528 extern int shim_dup3(int oldfd, int newfd, int flags);
 3529 extern int shim_execveat(int dirfd, const char *pathname, char *const argv[],
 3530     char *const envp[], int flags);
 3531 extern int shim_fallocate(int fd, int mode, off_t offset, off_t len);
 3532 extern int shim_fdatasync(int fd);
 3533 extern long shim_getcpu(unsigned *cpu, unsigned *node, void *tcache);
 3534 extern int shim_getdents(unsigned int fd, struct shim_linux_dirent *dirp,
 3535     unsigned int count);
 3536 extern int shim_getdents64(unsigned int fd, struct shim_linux_dirent64 *dirp,
 3537     unsigned int count);
 3538 extern char *shim_getlogin(void);
 3539 extern int shim_get_mempolicy(int *mode, unsigned long *nodemask,
 3540     unsigned long maxnode, unsigned long addr, unsigned long flags);
 3541 extern int shim_getrandom(void *buff, size_t buflen, unsigned int flags);
 3542 extern int shim_gettid(void);
 3543 extern ssize_t shim_getxattr(const char *path, const char *name,
 3544     void *value, size_t size);
 3545 extern int shim_futex_wait(const void *futex, const int val,
 3546     const struct timespec *timeout);
 3547 extern int shim_futex_wake(const void *futex, const int n);
 3548 extern int shim_fsync(int fd);
 3549 extern int shim_ioprio_set(int which, int who, int ioprio);
 3550 extern int shim_ioprio_get(int which, int who);
 3551 extern long shim_kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1,
 3552     unsigned long idx2);
 3553 extern int shim_madvise(void *addr, size_t length, int advice);
 3554 extern long shim_mbind(void *addr, unsigned long len,
 3555     int mode, const unsigned long *nodemask,
 3556     unsigned long maxnode, unsigned flags);
 3557 extern int shim_membarrier(int cmd, int flags);
 3558 extern int shim_memfd_create(const char *name, unsigned int flags);
 3559 extern long shim_migrate_pages(int pid, unsigned long maxnode,
 3560     const unsigned long *old_nodes, const unsigned long *new_nodes);
 3561 extern int shim_mincore(void *addr, size_t length, unsigned char *vec);
 3562 extern int shim_mlock(const void *addr, size_t len);
 3563 extern int shim_mlock2(const void *addr, size_t len, int flags);
 3564 extern int shim_mlockall(int flags);
 3565 extern long shim_move_pages(int pid, unsigned long count,
 3566     void **pages, const int *nodes, int *status, int flags);
 3567 extern int shim_msync(void *addr, size_t length, int flags);
 3568 extern int shim_munlock(const void *addr, size_t len);
 3569 extern int shim_munlockall(void);
 3570 extern int shim_pkey_alloc(unsigned long flags, unsigned long access_rights);
 3571 extern int shim_pkey_free(int pkey);
 3572 extern int shim_pkey_mprotect(void *addr, size_t len, int prot, int pkey);
 3573 extern int shim_pkey_get(int pkey);
 3574 extern int shim_pkey_set(int pkey, unsigned int rights);
 3575 extern void *shim_sbrk(intptr_t increment);
 3576 extern int shim_sched_getattr(pid_t pid, struct shim_sched_attr *attr,
 3577     unsigned int size, unsigned int flags);
 3578 extern int shim_sched_setattr(pid_t pid, struct shim_sched_attr *attr,
 3579     unsigned int flags);
 3580 extern int shim_sched_yield(void);
 3581 extern int shim_set_mempolicy(int mode, unsigned long *nodemask,
 3582     unsigned long maxnode);
 3583 extern int shim_seccomp(unsigned int operation, unsigned int flags, void *args);
 3584 extern ssize_t shim_statx(int dfd, const char *filename, unsigned int flags,
 3585     unsigned int mask, struct shim_statx *buffer);
 3586 extern size_t shim_strlcat(char *dst, const char *src, size_t len);
 3587 extern size_t shim_strlcpy(char *dst, const char *src, size_t len);
 3588 extern int shim_sync_file_range(int fd, shim_off64_t offset,
 3589     shim_off64_t nbytes, unsigned int flags);
 3590 extern int shim_sysfs(int option, ...);
 3591 extern int shim_syslog(int type, char *bufp, int len);
 3592 extern int shim_unshare(int flags);
 3593 extern int shim_userfaultfd(int flags);
 3594 extern int shim_usleep(uint64_t usec);
 3595 extern int shim_usleep_interruptible(uint64_t usec);
 3596 extern int shim_nanosleep_uint64(uint64_t usec);
 3597 
 3598 #define STRESS(stressor) extern stressor_info_t stressor ## _info;
 3599 
 3600 /* Stressors */
 3601 STRESS(stress_affinity);
 3602 STRESS(stress_access);
 3603 STRESS(stress_af_alg);
 3604 STRESS(stress_aio);
 3605 STRESS(stress_aiol);
 3606 STRESS(stress_apparmor);
 3607 STRESS(stress_atomic);
 3608 STRESS(stress_bad_altstack);
 3609 STRESS(stress_bigheap);
 3610 STRESS(stress_bind_mount);
 3611 STRESS(stress_branch);
 3612 STRESS(stress_brk);
 3613 STRESS(stress_bsearch);
 3614 STRESS(stress_cache);
 3615 STRESS(stress_cap);
 3616 STRESS(stress_chdir);
 3617 STRESS(stress_chmod);
 3618 STRESS(stress_chown);
 3619 STRESS(stress_chroot);
 3620 STRESS(stress_clock);
 3621 STRESS(stress_clone);
 3622 STRESS(stress_close);
 3623 STRESS(stress_context);
 3624 STRESS(stress_copy_file);
 3625 STRESS(stress_cpu);
 3626 STRESS(stress_cpu_online);
 3627 STRESS(stress_crypt);
 3628 STRESS(stress_cyclic);
 3629 STRESS(stress_daemon);
 3630 STRESS(stress_dccp);
 3631 STRESS(stress_dentry);
 3632 STRESS(stress_dev);
 3633 STRESS(stress_dev_shm);
 3634 STRESS(stress_dir);
 3635 STRESS(stress_dirdeep);
 3636 STRESS(stress_dnotify);
 3637 STRESS(stress_dup);
 3638 STRESS(stress_dynlib);
 3639 STRESS(stress_efivar);
 3640 STRESS(stress_enosys);
 3641 STRESS(stress_epoll);
 3642 STRESS(stress_eventfd);
 3643 STRESS(stress_exec);
 3644 STRESS(stress_fallocate);
 3645 STRESS(stress_fault);
 3646 STRESS(stress_fcntl);
 3647 STRESS(stress_fiemap);
 3648 STRESS(stress_fifo);
 3649 STRESS(stress_file_ioctl);
 3650 STRESS(stress_filename);
 3651 STRESS(stress_flock);
 3652 STRESS(stress_fanotify);
 3653 STRESS(stress_fork);
 3654 STRESS(stress_fp_error);
 3655 STRESS(stress_fstat);
 3656 STRESS(stress_funccall);
 3657 STRESS(stress_full);
 3658 STRESS(stress_futex);
 3659 STRESS(stress_get);
 3660 STRESS(stress_getrandom);
 3661 STRESS(stress_getdent);
 3662 STRESS(stress_handle);
 3663 STRESS(stress_hdd);
 3664 STRESS(stress_heapsort);
 3665 STRESS(stress_hrtimers);
 3666 STRESS(stress_hsearch);
 3667 STRESS(stress_icache);
 3668 STRESS(stress_icmp_flood);
 3669 STRESS(stress_idle_page);
 3670 STRESS(stress_inode_flags);
 3671 STRESS(stress_inotify);
 3672 STRESS(stress_io);
 3673 STRESS(stress_iomix);
 3674 STRESS(stress_ioport);
 3675 STRESS(stress_ioprio);
 3676 STRESS(stress_ipsec_mb);
 3677 STRESS(stress_itimer);
 3678 STRESS(stress_kcmp);
 3679 STRESS(stress_key);
 3680 STRESS(stress_kill);
 3681 STRESS(stress_klog);
 3682 STRESS(stress_lease);
 3683 STRESS(stress_link);
 3684 STRESS(stress_lockbus);
 3685 STRESS(stress_locka);
 3686 STRESS(stress_lockf);
 3687 STRESS(stress_lockofd);
 3688 STRESS(stress_longjmp);
 3689 STRESS(stress_loop);
 3690 STRESS(stress_lsearch);
 3691 STRESS(stress_madvise);
 3692 STRESS(stress_malloc);
 3693 STRESS(stress_matrix);
 3694 STRESS(stress_matrix_3d);
 3695 STRESS(stress_mcontend);
 3696 STRESS(stress_membarrier);
 3697 STRESS(stress_memcpy);
 3698 STRESS(stress_memfd);
 3699 STRESS(stress_memrate);
 3700 STRESS(stress_memthrash);
 3701 STRESS(stress_mergesort);
 3702 STRESS(stress_mincore);
 3703 STRESS(stress_mknod);
 3704 STRESS(stress_mlock);
 3705 STRESS(stress_mlockmany);
 3706 STRESS(stress_mmap);
 3707 STRESS(stress_mmapaddr);
 3708 STRESS(stress_mmapfixed);
 3709 STRESS(stress_mmapfork);
 3710 STRESS(stress_mmapmany);
 3711 STRESS(stress_mq);
 3712 STRESS(stress_mremap);
 3713 STRESS(stress_msg);
 3714 STRESS(stress_msync);
 3715 STRESS(stress_netdev);
 3716 STRESS(stress_netlink_proc);
 3717 STRESS(stress_nice);
 3718 STRESS(stress_nop);
 3719 STRESS(stress_null);
 3720 STRESS(stress_numa);
 3721 STRESS(stress_oom_pipe);
 3722 STRESS(stress_opcode);
 3723 STRESS(stress_open);
 3724 STRESS(stress_personality);
 3725 STRESS(stress_physpage);
 3726 STRESS(stress_pipe);
 3727 STRESS(stress_pkey);
 3728 STRESS(stress_poll);
 3729 STRESS(stress_prctl);
 3730 STRESS(stress_procfs);
 3731 STRESS(stress_pthread);
 3732 STRESS(stress_ptrace);
 3733 STRESS(stress_pty);
 3734 STRESS(stress_qsort);
 3735 STRESS(stress_quota);
 3736 STRESS(stress_radixsort);
 3737 STRESS(stress_rawdev);
 3738 STRESS(stress_rdrand);
 3739 STRESS(stress_readahead);
 3740 STRESS(stress_remap);
 3741 STRESS(stress_rename);
 3742 STRESS(stress_resources);
 3743 STRESS(stress_revio);
 3744 STRESS(stress_rlimit);
 3745 STRESS(stress_rmap);
 3746 STRESS(stress_rtc);
 3747 STRESS(stress_schedpolicy);
 3748 STRESS(stress_sctp);
 3749 STRESS(stress_seal);
 3750 STRESS(stress_seccomp);
 3751 STRESS(stress_seek);
 3752 STRESS(stress_sem);
 3753 STRESS(stress_sem_sysv);
 3754 STRESS(stress_sendfile);
 3755 STRESS(stress_set);
 3756 STRESS(stress_shm);
 3757 STRESS(stress_shm_sysv);
 3758 STRESS(stress_sigfd);
 3759 STRESS(stress_sigfpe);
 3760 STRESS(stress_sigio);
 3761 STRESS(stress_sigpending);
 3762 STRESS(stress_sigpipe);
 3763 STRESS(stress_sigq);
 3764 STRESS(stress_sigrt);
 3765 STRESS(stress_sigsegv);
 3766 STRESS(stress_sigsuspend);
 3767 STRESS(stress_sleep);
 3768 STRESS(stress_sock);
 3769 STRESS(stress_sockdiag);
 3770 STRESS(stress_sockfd);
 3771 STRESS(stress_sockpair);
 3772 STRESS(stress_softlockup);
 3773 STRESS(stress_spawn);
 3774 STRESS(stress_splice);
 3775 STRESS(stress_stack);
 3776 STRESS(stress_stackmmap);
 3777 STRESS(stress_str);
 3778 STRESS(stress_stream);
 3779 STRESS(stress_swap);
 3780 STRESS(stress_switch);
 3781 STRESS(stress_symlink);
 3782 STRESS(stress_sync_file);
 3783 STRESS(stress_sysbadaddr);
 3784 STRESS(stress_sysinfo);
 3785 STRESS(stress_sysfs);
 3786 STRESS(stress_tee);
 3787 STRESS(stress_timer);
 3788 STRESS(stress_timerfd);
 3789 STRESS(stress_tlb_shootdown);
 3790 STRESS(stress_tmpfs);
 3791 STRESS(stress_tree);
 3792 STRESS(stress_tsc);
 3793 STRESS(stress_tsearch);
 3794 STRESS(stress_udp);
 3795 STRESS(stress_udp_flood);
 3796 STRESS(stress_unshare);
 3797 STRESS(stress_urandom);
 3798 STRESS(stress_userfaultfd);
 3799 STRESS(stress_utime);
 3800 STRESS(stress_vdso);
 3801 STRESS(stress_vecmath);
 3802 STRESS(stress_vfork);
 3803 STRESS(stress_vforkmany);
 3804 STRESS(stress_vm);
 3805 STRESS(stress_vm_addr);
 3806 STRESS(stress_vm_rw);
 3807 STRESS(stress_vm_segv);
 3808 STRESS(stress_vm_splice);
 3809 STRESS(stress_wait);
 3810 STRESS(stress_watchdog);
 3811 STRESS(stress_wcs);
 3812 STRESS(stress_xattr);
 3813 STRESS(stress_yield);
 3814 STRESS(stress_zero);
 3815 STRESS(stress_zlib);
 3816 STRESS(stress_zombie);
 3817 
 3818 #endif