"Fossies" - the Fresh Open Source Software Archive

Member "stress-ng-0.13.05/stress-ng.h" (11 Oct 2021, 112146 Bytes) of package /linux/privat/stress-ng-0.13.05.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.13.04_vs_0.13.05.

    1 /*
    2  * Copyright (C) 2013-2021 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) &&   \
   43     !defined(__sun__)
   44 #define __sun__
   45 #endif
   46 
   47 /*
   48  *  Standard includes
   49  */
   50 #include <ctype.h>
   51 #include <dirent.h>
   52 #include <errno.h>
   53 #include <fcntl.h>
   54 #include <getopt.h>
   55 #include <inttypes.h>
   56 #include <limits.h>
   57 #include <math.h>
   58 #include <pwd.h>
   59 #include <sched.h>
   60 #include <search.h>
   61 #include <setjmp.h>
   62 #include <signal.h>
   63 #include <stdarg.h>
   64 #include <stdbool.h>
   65 #include <stddef.h>
   66 #include <stdint.h>
   67 #include <stdio.h>
   68 #include <stdlib.h>
   69 #include <string.h>
   70 #include <time.h>
   71 #include <unistd.h>
   72 
   73 #include "config.h"
   74 
   75 #ifndef SCHED_FLAG_RESET_ON_FORK
   76 #define SCHED_FLAG_RESET_ON_FORK    (0x01)
   77 #endif
   78 
   79 /*
   80  * SCHED_DEADLINE
   81  */
   82 #ifndef SCHED_FLAG_RECLAIM
   83 #define SCHED_FLAG_RECLAIM          (0x02)
   84 #endif
   85 
   86 #ifndef SCHED_FLAG_DL_OVERRUN
   87 #define SCHED_FLAG_DL_OVERRUN       (0x04)
   88 #endif
   89 
   90 /*
   91  *  Networking includes that are part of
   92  *  Single UNIX Specification V2
   93  */
   94 #include <arpa/inet.h>
   95 #include <netinet/in.h>
   96 #if defined(HAVE_NET_IF_H)
   97 #include <net/if.h>
   98 #endif
   99 #if defined(HAVE_NETINET_IP_H)
  100 #include <netinet/ip.h>
  101 #endif
  102 #if defined(HAVE_NETINET_IP_ICMP_H)
  103 #include <netinet/ip_icmp.h>
  104 #endif
  105 #if defined(HAVE_NETINET_TCP_H)
  106 #include <netinet/tcp.h>
  107 #endif
  108 #if defined(HAVE_NETINET_SCTP_H)
  109 #include <netinet/sctp.h>
  110 #endif
  111 
  112 #if defined(HAVE_AIO_H)
  113 #include <aio.h>
  114 #endif
  115 
  116 #if defined(HAVE_COMPLEX_H)
  117 #include <complex.h>
  118 #endif
  119 
  120 #if defined(HAVE_CPUID_H)
  121 #include <cpuid.h>
  122 #endif
  123 
  124 #if defined(HAVE_CRYPT_H)
  125 #include <crypt.h>
  126 #endif
  127 
  128 #if defined(HAVE_FEATURES_H)
  129 #include <features.h>
  130 #endif
  131 
  132 #if defined(HAVE_FENV_H)
  133 #include <fenv.h>
  134 #endif
  135 
  136 #if defined(HAVE_FLOAT_H)
  137 #include <float.h>
  138 #endif
  139 
  140 #if defined(HAVE_GRP_H)
  141 #include <grp.h>
  142 #endif
  143 
  144 #if defined(HAVE_JUDY_H)
  145 #include <Judy.h>
  146 #endif
  147 
  148 #if defined(HAVE_INTEL_IPSEC_MB_H)
  149 #include <intel-ipsec-mb.h>
  150 #endif
  151 
  152 #if defined(HAVE_KEYUTILS_H)
  153 #include <keyutils.h>
  154 #endif
  155 
  156 #if defined(HAVE_LIBAIO_H)
  157 #include <libaio.h>
  158 #endif
  159 
  160 #if defined(HAVE_LIBGEN_H)
  161 #include <libgen.h>
  162 #endif
  163 
  164 #if defined(HAVE_LIBKMOD_H)
  165 #include <libkmod.h>
  166 #endif
  167 
  168 #if defined(HAVE_LINK_H)
  169 #include <link.h>
  170 #endif
  171 
  172 #if defined(HAVE_LOCALE_H)
  173 #include <locale.h>
  174 #endif
  175 
  176 #if defined(HAVE_MALLOC_H)
  177 #include <malloc.h>
  178 #endif
  179 
  180 #if defined(HAVE_MNTENT_H)
  181 #include <mntent.h>
  182 #endif
  183 
  184 #if defined(HAVE_MQUEUE_H)
  185 #include <mqueue.h>
  186 #endif
  187 
  188 #if defined(HAVE_POLL_H)
  189 #include <poll.h>
  190 #endif
  191 
  192 #if defined(HAVE_LIB_PTHREAD)
  193 #include <pthread.h>
  194 #endif
  195 
  196 #if defined(HAVE_SEMAPHORE_H)
  197 #include <semaphore.h>
  198 #endif
  199 
  200 #if defined(HAVE_SOUND_ASOUND_H)
  201 #include <sound/asound.h>
  202 #endif
  203 
  204 #if defined(HAVE_SPAWN_H)
  205 #include <spawn.h>
  206 #endif
  207 
  208 #if defined(HAVE_STRINGS_H)
  209 #include <strings.h>
  210 #endif
  211 
  212 #if defined(HAVE_SYSLOG_H)
  213 #include <syslog.h>
  214 #endif
  215 
  216 #if defined(HAVE_TERMIO_H)
  217 #include <termio.h>
  218 #endif
  219 
  220 #if defined(HAVE_TERMIOS_H)
  221 #include <termios.h>
  222 #endif
  223 
  224 #if defined(HAVE_UCONTEXT_H)
  225 #include <ucontext.h>
  226 #endif
  227 
  228 #if defined(HAVE_USTAT_H)
  229 #if defined(__sun__)
  230 /* ustat and long file support on sun does not build */
  231 #undef HAVE_USTAT_H
  232 #else
  233 #include <ustat.h>
  234 #endif
  235 #endif
  236 
  237 #if defined(HAVE_UTIME_H)
  238 #include <utime.h>
  239 #endif
  240 
  241 #if defined(HAVE_WCHAR)
  242 #include <wchar.h>
  243 #endif
  244 
  245 #if defined(HAVE_SYS_TREE_H)
  246 #include <sys/tree.h>
  247 #endif
  248 
  249 #if defined(HAVE_BSD_STDLIB_H)
  250 #include <bsd/stdlib.h>
  251 #endif
  252 
  253 #if defined(HAVE_BSD_STRING_H)
  254 #include <bsd/string.h>
  255 #endif
  256 
  257 #if defined(HAVE_BSD_SYS_TREE_H)
  258 #include <bsd/sys/tree.h>
  259 #endif
  260 
  261 #if defined(HAVE_BSD_UNISTD_H)
  262 #include <bsd/unistd.h>
  263 #endif
  264 
  265 #if defined(HAVE_BSD_WCHAR)
  266 #include <bsd/wchar.h>
  267 #endif
  268 
  269 #if defined(HAVE_ASM_PRCTL_H)
  270 #include <asm/prctl.h>
  271 #endif
  272 
  273 #if defined(HAVE_ASM_MTRR_H)
  274 #include <asm/mtrr.h>
  275 #endif
  276 
  277 #if defined(HAVE_MODIFY_LDT)
  278 #include <asm/ldt.h>
  279 #endif
  280 
  281 /*
  282  *  Various sys include files
  283  */
  284 #include <sys/ioctl.h>
  285 #include <sys/file.h>
  286 #include <sys/mman.h>
  287 #include <sys/resource.h>
  288 #include <sys/socket.h>
  289 #include <sys/stat.h>
  290 #include <sys/time.h>
  291 #include <sys/times.h>
  292 #include <sys/types.h>
  293 #include <sys/wait.h>
  294 
  295 #if defined(HAVE_SYS_APPARMOR_H)
  296 #include <sys/apparmor.h>
  297 #endif
  298 
  299 #if defined(HAVE_SYS_AUXV_H)
  300 #include <sys/auxv.h>
  301 #endif
  302 
  303 #if defined(HAVE_SYS_CAPABILITY_H)
  304 #include <sys/capability.h>
  305 #endif
  306 
  307 #if defined(HAVE_SYS_EPOLL_H)
  308 #include <sys/epoll.h>
  309 #endif
  310 
  311 #if defined(HAVE_SYS_EVENTFD_H)
  312 #include <sys/eventfd.h>
  313 #endif
  314 
  315 #if defined(HAVE_SYS_FANOTIFY_H)
  316 #include <sys/fanotify.h>
  317 #endif
  318 
  319 #if defined(HAVE_SYS_FSUID_H)
  320 #include <sys/fsuid.h>
  321 #endif
  322 
  323 #if defined(HAVE_SYS_IO_H)
  324 #include <sys/io.h>
  325 #endif
  326 
  327 #if defined(HAVE_SYS_IPC_H)
  328 #include <sys/ipc.h>
  329 #endif
  330 
  331 #if defined(HAVE_SYS_INOTIFY_H)
  332 #include <sys/inotify.h>
  333 #endif
  334 
  335 #if defined(HAVE_SYS_MOUNT_H)
  336 #include <sys/mount.h>
  337 #endif
  338 
  339 #if defined(HAVE_SYS_MSG_H)
  340 #include <sys/msg.h>
  341 #endif
  342 
  343 #if defined(HAVE_SYS_PARAM_H)
  344 #include <sys/param.h>
  345 #endif
  346 
  347 #if defined(HAVE_SYS_PERSONALITY_H)
  348 #include <sys/personality.h>
  349 #endif
  350 
  351 #if defined(HAVE_SYS_PRCTL_H)
  352 #include <sys/prctl.h>
  353 #endif
  354 
  355 #if defined(HAVE_SYS_PLATFORM_PPC_H)
  356 #include <sys/platform/ppc.h>
  357 #endif
  358 
  359 #if defined(HAVE_PTRACE)
  360 #include <sys/ptrace.h>
  361 #endif
  362 
  363 #if defined(HAVE_SYS_QUEUE_H)
  364 #include <sys/queue.h>
  365 #endif
  366 
  367 #if defined(HAVE_SYS_QUOTA_H)
  368 #include <sys/quota.h>
  369 #endif
  370 
  371 #if defined(__APPLE__)
  372 #include <sys/random.h>
  373 #endif
  374 
  375 #if defined(HAVE_SYS_SELECT_H)
  376 #include <sys/select.h>
  377 #endif
  378 
  379 #if defined(HAVE_SEM_SYSV)
  380 #include <sys/sem.h>
  381 #endif
  382 
  383 #if defined(HAVE_SYS_SENDFILE_H)
  384 #include <sys/sendfile.h>
  385 #endif
  386 
  387 #if defined(HAVE_SYS_SHM_H)
  388 #include <sys/shm.h>
  389 #endif
  390 
  391 #if defined(HAVE_SYS_SIGNALFD_H)
  392 #include <sys/signalfd.h>
  393 #endif
  394 
  395 #if defined(HAVE_SYS_STATFS_H)
  396 #include <sys/statfs.h>
  397 #endif
  398 
  399 #if defined(HAVE_SYS_STATVFS_H)
  400 #include <sys/statvfs.h>
  401 #endif
  402 
  403 #if defined(__sun__)
  404 /* Disable for SunOs/Solaris because */
  405 #undef HAVE_SYS_SWAP_H
  406 #endif
  407 #if defined(HAVE_SYS_SWAP_H)
  408 #include <sys/swap.h>
  409 #endif
  410 
  411 #if defined(HAVE_SYSCALL_H)
  412 #include <sys/syscall.h>
  413 #endif
  414 
  415 #if defined(HAVE_SYS_SYSINFO_H)
  416 #include <sys/sysinfo.h>
  417 #if defined(__GNUC__) &&    \
  418     !defined(__GLIBC__)
  419 /* Suppress kernel sysinfo to avoid collision with musl */
  420 #define _LINUX_SYSINFO_H
  421 #endif
  422 #endif
  423 
  424 #if defined(HAVE_SYS_SYSMACROS_H)
  425 #include <sys/sysmacros.h>
  426 #endif
  427 
  428 #if defined(HAVE_SYS_TIMEX_H)
  429 #include <sys/timex.h>
  430 #endif
  431 
  432 #if defined(HAVE_SYS_TIMERFD_H)
  433 #include <sys/timerfd.h>
  434 #endif
  435 
  436 #if defined(HAVE_SYS_UCRED_H)
  437 #include <sys/ucred.h>
  438 #endif
  439 
  440 #if defined(HAVE_SYS_UIO_H)
  441 #include <sys/uio.h>
  442 #endif
  443 
  444 #if defined(HAVE_SYS_UN_H)
  445 #include <sys/un.h>
  446 #endif
  447 
  448 #if defined(HAVE_SYS_UTSNAME_H)
  449 #include <sys/utsname.h>
  450 #endif
  451 
  452 #if defined(HAVE_SYS_VFS_H)
  453 #include <sys/vfs.h>
  454 #endif
  455 
  456 
  457 /*
  458  *  SCSI related headers
  459  */
  460 #if defined(HAVE_SCSI_SCSI_H)
  461 #include <scsi/scsi.h>
  462 #endif
  463 
  464 #if defined(HAVE_SCSI_SCSI_IOCTL_H)
  465 #include <scsi/scsi_ioctl.h>
  466 #endif
  467 
  468 #if defined(HAVE_SCSI_SG_H)
  469 #include <scsi/sg.h>
  470 #endif
  471 
  472 /*
  473  *  Linux specific includes
  474  */
  475 #if defined(HAVE_LINUX_ANDROID_BINDER_H)
  476 #include <linux/android/binder.h>
  477 #endif
  478 
  479 #if defined(HAVE_LINUX_ANDROID_BINDERFS_H)
  480 #include <linux/android/binderfs.h>
  481 #endif
  482 
  483 #if defined(HAVE_LINUX_AUDIT_H)
  484 #include <linux/audit.h>
  485 #endif
  486 
  487 #if defined(HAVE_LINUX_CDROM_H)
  488 #include <linux/cdrom.h>
  489 #endif
  490 
  491 #if defined(HAVE_LINUX_CN_PROC_H)
  492 #include <linux/cn_proc.h>
  493 #endif
  494 
  495 #if defined(HAVE_LINUX_CONNECTOR_H)
  496 #include <linux/connector.h>
  497 #endif
  498 
  499 #if defined(HAVE_LINUX_DM_IOCTL_H)
  500 #include <linux/dm-ioctl.h>
  501 #endif
  502 
  503 #if defined(HAVE_LINUX_FD_H)
  504 #include <linux/fd.h>
  505 #endif
  506 
  507 #if defined(HAVE_LINUX_GENETLINK_H)
  508 #include <linux/genetlink.h>
  509 #endif
  510 
  511 #if defined(HAVE_LINUX_HDREG_H)
  512 #include <linux/hdreg.h>
  513 #endif
  514 
  515 #if defined(HAVE_LINUX_IF_ALG_H)
  516 #include <linux/if_alg.h>
  517 #endif
  518 
  519 #if defined(HAVE_LINUX_IF_PACKET_H)
  520 #include <linux/if_packet.h>
  521 #endif
  522 
  523 #if defined(HAVE_LINUX_IF_TUN_H)
  524 #include <linux/if_tun.h>
  525 #endif
  526 
  527 #if defined(HAVE_LINUX_IO_URING_H)
  528 #include <linux/io_uring.h>
  529 #endif
  530 
  531 #if defined(HAVE_LINUX_FIEMAP_H)
  532 #include <linux/fiemap.h>
  533 #endif
  534 
  535 #if defined(HAVE_LINUX_FILTER_H)
  536 #include <linux/filter.h>
  537 #endif
  538 
  539 #if defined(HAVE_LINUX_FS_H)
  540 #include <linux/fs.h>
  541 #endif
  542 
  543 #if defined(HAVE_LINUX_FSVERITY_H)
  544 #include <linux/fsverity.h>
  545 #endif
  546 
  547 #if defined(HAVE_LINUX_FUTEX_H)
  548 #include <linux/futex.h>
  549 #endif
  550 
  551 #if defined(HAVE_LINUX_HPET_H)
  552 #include <linux/hpet.h>
  553 #endif
  554 
  555 #if defined(HAVE_LINUX_KD_H)
  556 #include <linux/kd.h>
  557 #endif
  558 
  559 #if defined(HAVE_LINUX_LANDLOCK_H)
  560 #include <linux/landlock.h>
  561 #endif
  562 
  563 #if defined(HAVE_LINUX_LOOP_H)
  564 #include <linux/loop.h>
  565 #endif
  566 
  567 #if defined(HAVE_LINUX_MEDIA_H)
  568 #include <linux/media.h>
  569 #endif
  570 
  571 #if defined(HAVE_LINUX_MEMBARRIER_H)
  572 #include <linux/membarrier.h>
  573 #endif
  574 
  575 #if defined(HAVE_LINUX_MEMPOLICY_H)
  576 #include <linux/mempolicy.h>
  577 #endif
  578 
  579 #if defined(HAVE_LINUX_NETLINK_H)
  580 #include <linux/netlink.h>
  581 #endif
  582 
  583 #if defined(HAVE_LINUX_OPENAT2_H)
  584 #include <linux/openat2.h>
  585 #endif
  586 
  587 #if defined(HAVE_LINUX_PCI_H)
  588 #include <linux/pci.h>
  589 #endif
  590 
  591 #if defined(HAVE_LINUX_PERF_EVENT_H)
  592 #include <linux/perf_event.h>
  593 #endif
  594 
  595 #if defined(HAVE_LINUX_PTP_CLOCK_H)
  596 #include <linux/ptp_clock.h>
  597 #endif
  598 
  599 #if defined(HAVE_LINUX_POSIX_TYPES_H)
  600 #include <linux/posix_types.h>
  601 #endif
  602 
  603 #if defined(HAVE_LINUX_PPDEV_H)
  604 #include <linux/ppdev.h>
  605 #endif
  606 
  607 #if defined(HAVE_LINUX_RANDOM_H)
  608 #include <linux/random.h>
  609 #endif
  610 
  611 #if defined(HAVE_LINUX_RSEQ_H)
  612 #include <linux/rseq.h>
  613 #endif
  614 
  615 #if defined(HAVE_LINUX_RTC_H)
  616 #include <linux/rtc.h>
  617 #endif
  618 
  619 #if defined(HAVE_LINUX_RTNETLINK_H)
  620 #include <linux/rtnetlink.h>
  621 #endif
  622 
  623 #if defined(HAVE_LINUX_SECCOMP_H)
  624 #include <linux/seccomp.h>
  625 #endif
  626 
  627 #if defined(HAVE_LINUX_SERIAL_H)
  628 #include <linux/serial.h>
  629 #endif
  630 
  631 #if defined(HAVE_LINUX_SOCK_DIAG_H)
  632 #include <linux/sock_diag.h>
  633 #endif
  634 
  635 #if defined(HAVE_LINUX_SOCKET_H)
  636 #include <linux/socket.h>
  637 #endif
  638 
  639 #if defined(HAVE_LINUX_SOCKIOS_H)
  640 #include <linux/sockios.h>
  641 #endif
  642 
  643 #if defined(HAVE_LINUX_SYSCTL_H)
  644 #include <linux/sysctl.h>
  645 #endif
  646 
  647 #if defined(HAVE_LINUX_TASKSTATS_H)
  648 #include <linux/taskstats.h>
  649 #endif
  650 
  651 #if defined(HAVE_LINUX_UDP_H)
  652 #include <linux/udp.h>
  653 #endif
  654 
  655 #if defined(HAVE_LINUX_UNIX_DIAG_H)
  656 #include <linux/unix_diag.h>
  657 #endif
  658 
  659 #if defined(HAVE_LINUX_USERFAULTFD_H)
  660 #include <linux/userfaultfd.h>
  661 #endif
  662 
  663 #if defined(HAVE_LINUX_VERSION_H)
  664 #include <linux/version.h>
  665 #endif
  666 
  667 #if defined(HAVE_LINUX_VIDEODEV2_H)
  668 #include <linux/videodev2.h>
  669 #endif
  670 
  671 #if defined(HAVE_LINUX_VT_H)
  672 #include <linux/vt.h>
  673 #endif
  674 
  675 #if defined(HAVE_LINUX_WATCHDOG_H)
  676 #include <linux/watchdog.h>
  677 #endif
  678 
  679 /*
  680  *  We want sys/xattr.h in preference
  681  *  to the older attr/xattr.h if both
  682  *  are available
  683  */
  684 #if defined(HAVE_SYS_XATTR_H)
  685 #include <sys/xattr.h>
  686 #undef HAVE_ATTR_XATTR_H
  687 #elif defined(HAVE_ATTR_XATTR_H)
  688 #include <attr/xattr.h>
  689 #endif
  690 /*  Sanity check */
  691 #if defined(HAVE_SYS_XATTR_H) &&    \
  692     defined(HAVE_ATTR_XATTR_H)
  693 #error cannot have both HAVE_SYS_XATTR_H and HAVE_ATTR_XATTR_H
  694 #endif
  695 
  696 #if defined(HAVE_LIB_DL)
  697 #include <dlfcn.h>
  698 #include <gnu/lib-names.h>
  699 #endif
  700 
  701 /*
  702  *  Various system calls not included in libc (yet)
  703  */
  704 #if defined(__linux__)
  705 
  706 #if defined(__NR_add_key)
  707 #define HAVE_ADD_KEY
  708 #endif
  709 
  710 #if defined(__NR_getcpu)
  711 #define HAVE_GETCPU
  712 #endif
  713 
  714 #if defined(__NR_getdents)
  715 #define HAVE_GETDENTS
  716 #endif
  717 
  718 #if defined(__NR_getdents64)
  719 #define HAVE_GETDENTS64
  720 #endif
  721 
  722 #if defined(__NR_get_thread_area)
  723 #define HAVE_GET_THREAD_AREA
  724 #endif
  725 
  726 #if defined(__NR_gettid)
  727 #define HAVE_GETTID
  728 #endif
  729 
  730 #if defined(__NR_get_robust_list)
  731 #define HAVE_GET_ROBUST_LIST
  732 #endif
  733 
  734 #if defined(__NR_ioprio_get)
  735 #define HAVE_IOPRIO_GET
  736 #endif
  737 
  738 #if defined(__NR_ioprio_set)
  739 #define HAVE_IOPRIO_SET
  740 #endif
  741 
  742 #if defined(__NR_kcmp)
  743 #define HAVE_KCMP
  744 #endif
  745 
  746 #if defined(__NR_keyctl)
  747 #define HAVE_KEYCTL
  748 #endif
  749 
  750 #if defined(__NR_membarrier)
  751 #define HAVE_MEMBARRIER
  752 #endif
  753 
  754 #if defined(__NR_mmap2)
  755 #define HAVE_MMAP2
  756 #endif
  757 
  758 #if defined(__NR_pkey_get)
  759 #define HAVE_PKEY_GET
  760 #endif
  761 
  762 #if defined(__NR_pkey_set)
  763 #define HAVE_PKEY_SET
  764 #endif
  765 
  766 #if defined(__NR_request_key)
  767 #define HAVE_REQUEST_KEY
  768 #endif
  769 
  770 #if defined(__NR_sched_getattr)
  771 #define HAVE_SCHED_GETATTR
  772 #endif
  773 
  774 #if defined(__NR_sched_setattr)
  775 #define HAVE_SCHED_SETATTR
  776 #endif
  777 
  778 #if defined(__NR_set_robust_list)
  779 #define HAVE_SET_ROBUST_LIST
  780 #endif
  781 
  782 #if defined(__NR_set_thread_area)
  783 #define HAVE_SET_THREAD_AREA
  784 #endif
  785 
  786 #if defined(__NR_syslog)
  787 #define HAVE_SYSLOG
  788 #endif
  789 
  790 #if defined(__NR_userfaultfd)
  791 #define HAVE_USERFAULTFD
  792 #endif
  793 
  794 #endif
  795 
  796 #include "stress-version.h"
  797 
  798 /*
  799  *  BeagleBoneBlack with 4.1.15 kernel does not
  800  *  define the following, these should be defined
  801  *  in linux/posix_types.h - define them if they
  802  *  don't exist.
  803  */
  804 #if !defined(HAVE_KERNEL_LONG_T)
  805 typedef long int __kernel_long_t;
  806 #endif
  807 #if !defined(HAVE_KERNEL_ULONG_T)
  808 typedef unsigned long int __kernel_ulong_t;
  809 #endif
  810 
  811 #define STRESS_BIT_U(shift) (1U << shift)
  812 #define STRESS_BIT_UL(shift)    (1UL << shift)
  813 #define STRESS_BIT_ULL(shift)   (1ULL << shift)
  814 
  815 /*
  816  *  cacheflush(2) cache options
  817  */
  818 #ifdef ICACHE
  819 #define SHIM_ICACHE (ICACHE)
  820 #else
  821 #define SHIM_ICACHE (1 << 0)
  822 #endif
  823 
  824 #ifdef DCACHE
  825 #define SHIM_DCACHE (DCACHE)
  826 #else
  827 #define SHIM_DCACHE (1 << 1)
  828 #endif
  829 
  830 #if !defined(EXIT_SUCCESS)
  831 #define EXIT_SUCESSS            (0)
  832 #endif
  833 #if !defined(EXIT_FAILURE)
  834 #define EXIT_FAILURE            (1)
  835 #endif
  836 #define EXIT_NOT_SUCCESS        (2)
  837 #define EXIT_NO_RESOURCE        (3)
  838 #define EXIT_NOT_IMPLEMENTED        (4)
  839 #define EXIT_SIGNALED           (5)
  840 #define EXIT_BY_SYS_EXIT        (6)
  841 #define EXIT_METRICS_UNTRUSTWORTHY  (7)
  842 
  843 /*
  844  *  Stressor run states
  845  */
  846 #define STRESS_STATE_START      (0)
  847 #define STRESS_STATE_INIT       (1)
  848 #define STRESS_STATE_RUN        (2)
  849 #define STRESS_STATE_DEINIT     (3)
  850 #define STRESS_STATE_STOP       (4)
  851 #define STRESS_STATE_EXIT       (5)
  852 #define STRESS_STATE_WAIT       (6)
  853 
  854 /*
  855  *  Timing units
  856  */
  857 #define STRESS_NANOSECOND       (1000000000L)
  858 #define STRESS_MICROSECOND      (1000000L)
  859 #define STRESS_MILLISECOND      (1000L)
  860 
  861 /*
  862  * STRESS_ASSERT(test)
  863  *   throw compile time error if test not true
  864  */
  865 #define STRESS_CONCAT(a, b) a ## b
  866 #define STRESS_CONCAT_EXPAND(a, b) STRESS_CONCAT(a, b)
  867 #define STRESS_ASSERT(expr) \
  868     enum { STRESS_CONCAT_EXPAND(STRESS_ASSERT_AT_LINE_, __LINE__) = \
  869         1 / !!(expr) };
  870 
  871 #define STRESS_MINIMUM(a,b) (((a) < (b)) ? (a) : (b))
  872 #define STRESS_MAXIMUM(a,b) (((a) > (b)) ? (a) : (b))
  873 
  874 /* NetBSD does not define MAP_ANONYMOUS */
  875 #if defined(MAP_ANON) &&    \
  876     !defined(MAP_ANONYMOUS)
  877 #define MAP_ANONYMOUS MAP_ANON
  878 #endif
  879 
  880 /* GNU HURD and other systems that don't define PATH_MAX */
  881 #ifndef PATH_MAX
  882 #define PATH_MAX        (4096)
  883 #endif
  884 
  885 /*
  886  * making local static fixes globbering warnings
  887  */
  888 #define NOCLOBBER   static
  889 
  890 #if (_BSD_SOURCE || _SVID_SOURCE || !defined(__gnu_hurd__))
  891 #define STRESS_PAGE_IN
  892 #endif
  893 
  894 #define STRESS_TRY_OPEN_OK    (0)       /* File can be opened */
  895 #define STRESS_TRY_OPEN_FORK_FAIL (1)       /* Try failed, e.g. can't fork */
  896 #define STRESS_TRY_OPEN_WAIT_FAIL (2)       /* Wait on child open failed */
  897 #define STRESS_TRY_OPEN_EXIT_FAIL (3)       /* Can't get _exit() status */
  898 #define STRESS_TRY_OPEN_FAIL      (4)       /* Can't open file */
  899 #define STRESS_TRY_AGAIN      (5)       /* Device busy, try again */
  900 
  901 #define STRESS_FD_MAX       (65536)     /* Max fds if we can't figure it out */
  902 #define STRESS_PROCS_MAX    (8192)      /* Max number of processes per stressor */
  903 
  904 #define DCCP_BUF        (1024)      /* DCCP I/O buffer size */
  905 #define SOCKET_BUF      (8192)      /* Socket I/O buffer size */
  906 #define UDP_BUF         (1024)      /* UDP I/O buffer size */
  907 #define SOCKET_PAIR_BUF     (64)        /* Socket pair I/O buffer size */
  908 
  909 #define ABORT_FAILURES      (5)     /* Number of failures before we abort */
  910 
  911 /* debug output bitmasks */
  912 #define PR_ERROR         STRESS_BIT_ULL(0)  /* Print errors */
  913 #define PR_INFO          STRESS_BIT_ULL(1)  /* Print info */
  914 #define PR_DEBUG         STRESS_BIT_ULL(2)  /* Print debug */
  915 #define PR_FAIL          STRESS_BIT_ULL(3)  /* Print test failure message */
  916 #define PR_ALL           (PR_ERROR | PR_INFO | PR_DEBUG | PR_FAIL)
  917 
  918 /* Option bit masks */
  919 #define OPT_FLAGS_DRY_RUN    STRESS_BIT_ULL(4)  /* Don't actually run */
  920 #define OPT_FLAGS_METRICS    STRESS_BIT_ULL(5)  /* Dump metrics at end */
  921 #define OPT_FLAGS_RANDOM     STRESS_BIT_ULL(6)  /* Randomize */
  922 #define OPT_FLAGS_SET        STRESS_BIT_ULL(7)  /* Set if user specifies stress procs */
  923 #define OPT_FLAGS_KEEP_NAME  STRESS_BIT_ULL(8)  /* Keep stress names to stress-ng */
  924 #define OPT_FLAGS_METRICS_BRIEF  STRESS_BIT_ULL(9)  /* dump brief metrics */
  925 #define OPT_FLAGS_VERIFY     STRESS_BIT_ULL(10) /* verify mode */
  926 #define OPT_FLAGS_MMAP_MADVISE   STRESS_BIT_ULL(11) /* enable random madvise settings */
  927 #define OPT_FLAGS_MMAP_MINCORE   STRESS_BIT_ULL(12) /* mincore force pages into mem */
  928 #define OPT_FLAGS_TIMES      STRESS_BIT_ULL(13) /* user/system time summary */
  929 #define OPT_FLAGS_HDD_SYNC   STRESS_BIT_ULL(14) /* HDD O_SYNC */
  930 #define OPT_FLAGS_HDD_DSYNC  STRESS_BIT_ULL(15) /* HDD O_DYNC */
  931 #define OPT_FLAGS_HDD_DIRECT     STRESS_BIT_ULL(16) /* HDD O_DIRECT */
  932 #define OPT_FLAGS_HDD_NOATIME    STRESS_BIT_ULL(17) /* HDD O_NOATIME */
  933 #define OPT_FLAGS_MINIMIZE   STRESS_BIT_ULL(18) /* Minimize */
  934 #define OPT_FLAGS_MAXIMIZE   STRESS_BIT_ULL(19) /* Maximize */
  935 #define OPT_FLAGS_SYSLOG     STRESS_BIT_ULL(20) /* log test progress to syslog */
  936 #define OPT_FLAGS_AGGRESSIVE     STRESS_BIT_ULL(21) /* aggressive mode enabled */
  937 #define OPT_FLAGS_ALL        STRESS_BIT_ULL(22) /* --all mode */
  938 #define OPT_FLAGS_SEQUENTIAL     STRESS_BIT_ULL(23) /* --sequential mode */
  939 #define OPT_FLAGS_PERF_STATS     STRESS_BIT_ULL(24) /* --perf stats mode */
  940 #define OPT_FLAGS_LOG_BRIEF  STRESS_BIT_ULL(25) /* --log-brief */
  941 #define OPT_FLAGS_THERMAL_ZONES  STRESS_BIT_ULL(26) /* --tz thermal zones */
  942 #define OPT_FLAGS_SOCKET_NODELAY STRESS_BIT_ULL(27) /* --sock-nodelay */
  943 #define OPT_FLAGS_IGNITE_CPU     STRESS_BIT_ULL(28) /* --cpu-ignite */
  944 #define OPT_FLAGS_PATHOLOGICAL   STRESS_BIT_ULL(29) /* --pathological */
  945 #define OPT_FLAGS_NO_RAND_SEED   STRESS_BIT_ULL(30) /* --no-rand-seed */
  946 #define OPT_FLAGS_THRASH     STRESS_BIT_ULL(31) /* --thrash */
  947 #define OPT_FLAGS_OOMABLE    STRESS_BIT_ULL(32) /* --oomable */
  948 #define OPT_FLAGS_ABORT      STRESS_BIT_ULL(33) /* --abort */
  949 #define OPT_FLAGS_CPU_ONLINE_ALL STRESS_BIT_ULL(34) /* --cpu-online-all */
  950 #define OPT_FLAGS_TIMESTAMP  STRESS_BIT_ULL(35) /* --timestamp */
  951 #define OPT_FLAGS_DEADLINE_GRUB  STRESS_BIT_ULL(36) /* --sched-reclaim */
  952 #define OPT_FLAGS_FTRACE     STRESS_BIT_ULL(37) /* --ftrace */
  953 #define OPT_FLAGS_SEED       STRESS_BIT_ULL(38) /* --seed */
  954 #define OPT_FLAGS_SKIP_SILENT    STRESS_BIT_ULL(39) /* --skip-silent */
  955 #define OPT_FLAGS_SMART      STRESS_BIT_ULL(40) /* --smart */
  956 #define OPT_FLAGS_NO_OOM_ADJUST  STRESS_BIT_ULL(41) /* --no-oom-adjust */
  957 
  958 #define OPT_FLAGS_MINMAX_MASK       \
  959     (OPT_FLAGS_MINIMIZE | OPT_FLAGS_MAXIMIZE)
  960 
  961 /* Aggressive mode flags */
  962 #define OPT_FLAGS_AGGRESSIVE_MASK   \
  963     (OPT_FLAGS_MMAP_MADVISE |   \
  964      OPT_FLAGS_MMAP_MINCORE |   \
  965      OPT_FLAGS_HDD_SYNC |       \
  966      OPT_FLAGS_HDD_DSYNC |      \
  967      OPT_FLAGS_HDD_DIRECT |     \
  968      OPT_FLAGS_AGGRESSIVE |     \
  969      OPT_FLAGS_IGNITE_CPU)
  970 
  971 /* Stressor classes */
  972 #define CLASS_CPU       STRESS_BIT_UL(0)    /* CPU only */
  973 #define CLASS_MEMORY        STRESS_BIT_UL(1)    /* Memory thrashers */
  974 #define CLASS_CPU_CACHE     STRESS_BIT_UL(2)    /* CPU cache */
  975 #define CLASS_IO        STRESS_BIT_UL(3)    /* I/O read/writes etc */
  976 #define CLASS_NETWORK       STRESS_BIT_UL(4)    /* Network, sockets, etc */
  977 #define CLASS_SCHEDULER     STRESS_BIT_UL(5)    /* Scheduling */
  978 #define CLASS_VM        STRESS_BIT_UL(6)    /* VM stress, big memory, swapping */
  979 #define CLASS_INTERRUPT     STRESS_BIT_UL(7)    /* interrupt floods */
  980 #define CLASS_OS        STRESS_BIT_UL(8)    /* generic OS tests */
  981 #define CLASS_PIPE_IO       STRESS_BIT_UL(9)    /* pipe I/O */
  982 #define CLASS_FILESYSTEM    STRESS_BIT_UL(10)   /* file system */
  983 #define CLASS_DEV       STRESS_BIT_UL(11)   /* device (null, zero, etc) */
  984 #define CLASS_SECURITY      STRESS_BIT_UL(12)   /* security APIs */
  985 #define CLASS_PATHOLOGICAL  STRESS_BIT_UL(13)   /* can hang a machine */
  986 
  987 
  988 /* Help information for options */
  989 typedef struct {
  990     const char *opt_s;      /* short option */
  991     const char *opt_l;      /* long option */
  992     const char *description;    /* description */
  993 } stress_help_t;
  994 
  995 /* native setting types */
  996 typedef enum {
  997     TYPE_ID_UNDEFINED,
  998     TYPE_ID_UINT8,
  999     TYPE_ID_INT8,
 1000     TYPE_ID_UINT16,
 1001     TYPE_ID_INT16,
 1002     TYPE_ID_UINT32,
 1003     TYPE_ID_INT32,
 1004     TYPE_ID_UINT64,
 1005     TYPE_ID_INT64,
 1006     TYPE_ID_SIZE_T,
 1007     TYPE_ID_SSIZE_T,
 1008     TYPE_ID_UINT,
 1009     TYPE_ID_INT,
 1010     TYPE_ID_ULONG,
 1011     TYPE_ID_LONG,
 1012     TYPE_ID_OFF_T,
 1013     TYPE_ID_STR,
 1014     TYPE_ID_BOOL,
 1015     TYPE_ID_UINTPTR_T
 1016 } stress_type_id_t;
 1017 
 1018 typedef struct stress_stressor_info *stress_pstressor_info_t;
 1019 
 1020 /*
 1021  *  Per ELISA request, we have a duplicated counter
 1022  *  and run_ok flag in a different shared memory region
 1023  *  so we can sanity check these just in case the stats
 1024  *  have got corrupted.
 1025  */
 1026 typedef struct {
 1027     struct {
 1028         uint64_t counter;   /* Copy of stats counter */
 1029         bool     run_ok;    /* Copy of run_ok */
 1030     } data;
 1031     uint32_t    hash;       /* Hash of data */
 1032 } stress_checksum_t;
 1033 
 1034 /* settings for storing opt arg parsed data */
 1035 typedef struct stress_setting {
 1036     struct stress_setting *next;    /* next setting in list */
 1037     stress_pstressor_info_t proc;
 1038     char *name;         /* name of setting */
 1039     stress_type_id_t type_id;   /* setting type */
 1040     bool        global;     /* true if global */
 1041     union {             /* setting value */
 1042         uint8_t     uint8;
 1043         int8_t      int8;
 1044         uint16_t    uint16;
 1045         int16_t     int16;
 1046         uint32_t    uint32;
 1047         int32_t     int32;
 1048         uint64_t    uint64;
 1049         int64_t     int64;
 1050         size_t      size;
 1051         ssize_t     ssize;
 1052         unsigned int    uint;
 1053         signed int  sint;
 1054         unsigned long   ulong;
 1055         signed long slong;
 1056         off_t       off;
 1057         char        *str;
 1058         bool        boolean;
 1059         uintptr_t   uintptr;/* for func pointers */
 1060     } u;
 1061 } stress_setting_t;
 1062 
 1063 typedef union {
 1064     volatile uint8_t    uint8_val;
 1065     volatile uint16_t   uint16_val;
 1066     volatile uint32_t   uint32_val;
 1067     volatile uint64_t   uint64_val;
 1068 #if defined(HAVE_INT128_T)
 1069     volatile __uint128_t    uint128_val;
 1070 #endif
 1071     volatile float      float_val;
 1072     volatile double     double_val;
 1073     volatile long double    long_double_val;
 1074     volatile void       *void_ptr_val;
 1075 } stress_put_val_t;
 1076 
 1077 /* Network domains flags */
 1078 #define DOMAIN_INET     (0x00000001)    /* AF_INET */
 1079 #define DOMAIN_INET6        (0x00000002)    /* AF_INET6 */
 1080 #define DOMAIN_UNIX     (0x00000004)    /* AF_UNIX */
 1081 
 1082 #define DOMAIN_INET_ALL     (DOMAIN_INET | DOMAIN_INET6)
 1083 #define DOMAIN_ALL      (DOMAIN_INET | DOMAIN_INET6 | DOMAIN_UNIX)
 1084 
 1085 /* Large prime to stride around large VM regions */
 1086 #define PRIME_64        (0x8f0000000017116dULL)
 1087 
 1088 typedef uint32_t stress_class_t;
 1089 
 1090 typedef struct {
 1091     void *page_none;        /* mmap'd PROT_NONE page */
 1092     void *page_ro;          /* mmap'd PROT_RO page */
 1093     void *page_wo;          /* mmap'd PROT_WO page */
 1094 } stress_mapped_t;
 1095 
 1096 #define STRESS_MISC_STATS_MAX   (10)
 1097 
 1098 typedef struct {
 1099     char description[32];
 1100     double value;
 1101 } stress_misc_stats_t;
 1102 
 1103 /* stressor args */
 1104 typedef struct {
 1105     uint64_t *counter;      /* stressor counter */
 1106     bool *counter_ready;        /* counter can be read */
 1107     const char *name;       /* stressor name */
 1108     uint64_t max_ops;       /* max number of bogo ops */
 1109     const uint32_t instance;    /* stressor instance # */
 1110     const uint32_t num_instances;   /* number of instances */
 1111     pid_t pid;          /* stressor pid */
 1112     pid_t ppid;         /* stressor ppid */
 1113     size_t page_size;       /* page size */
 1114     stress_mapped_t *mapped;    /* mmap'd pages, addr of g_shared mapped */
 1115     stress_misc_stats_t *misc_stats;/* misc per stressor stats */
 1116 } stress_args_t;
 1117 
 1118 typedef struct {
 1119     const int opt;          /* optarg option*/
 1120     int (*opt_set_func)(const char *opt); /* function to set it */
 1121 } stress_opt_set_func_t;
 1122 
 1123 /* stressor information */
 1124 typedef struct {
 1125     int (*stressor)(const stress_args_t *args); /* stressor function */
 1126     int (*supported)(const char *name); /* return 0 = supported, -1, not */
 1127     void (*init)(void);     /* stressor init, NULL = ignore */
 1128     void (*deinit)(void);       /* stressor de-init, NULL = ignore */
 1129     void (*set_default)(void);  /* default set-up */
 1130     void (*set_limit)(uint64_t max);/* set limits */
 1131     const stress_class_t class; /* stressor class */
 1132     const stress_opt_set_func_t *opt_set_funcs; /* option functions */
 1133     const stress_help_t *help;  /* stressor help options */
 1134 } stressor_info_t;
 1135 
 1136 /* pthread wrapped stress_args_t */
 1137 typedef struct {
 1138     const stress_args_t *args;  /* Stress test args */
 1139     void *data;         /* Per thread private data */
 1140     int pthread_ret;        /* Per thread return value */
 1141 } stress_pthread_args_t;
 1142 
 1143 /* string hash linked list type */
 1144 typedef struct stress_hash {
 1145     struct stress_hash *next;   /* next hash item */
 1146 } stress_hash_t;
 1147 
 1148 /* string hash table */
 1149 typedef struct {
 1150     stress_hash_t   **table;    /* hash table */
 1151     size_t      n;      /* number of hash items in table */
 1152 } stress_hash_table_t;
 1153 
 1154 /* vmstat information */
 1155 typedef struct {            /* vmstat column */
 1156     uint64_t    procs_running;  /* r */
 1157     uint64_t    procs_blocked;  /* b */
 1158     uint64_t    swap_total; /* swpd info, total */
 1159     uint64_t    swap_free;  /* swpd info, free */
 1160     uint64_t    swap_used;  /* swpd used = total - free */
 1161     uint64_t    memory_free;    /* free */
 1162     uint64_t    memory_buff;    /* buff */
 1163     uint64_t    memory_cache;   /* cache */
 1164     uint64_t    swap_in;    /* si */
 1165     uint64_t    swap_out;   /* so */
 1166     uint64_t    block_in;   /* bi */
 1167     uint64_t    block_out;  /* bo */
 1168     uint64_t    interrupt;  /* in */
 1169     uint64_t    context_switch; /* cs */
 1170     uint64_t    user_time;  /* us */
 1171     uint64_t    system_time;    /* sy */
 1172     uint64_t    idle_time;  /* id */
 1173     uint64_t    wait_time;  /* wa */
 1174     uint64_t    stolen_time;    /* st */
 1175 } stress_vmstat_t;
 1176 
 1177 /* iostat information, from /sys/block/$dev/stat */
 1178 typedef struct {
 1179     uint64_t    read_io;    /* number of read I/Os processed */
 1180     uint64_t    read_merges;    /* number of read I/Os merged with in-queue I/O */
 1181     uint64_t    read_sectors;   /* number of sectors read */
 1182     uint64_t    read_ticks; /* total wait time for read requests */
 1183     uint64_t    write_io;   /* number of write I/Os processed */
 1184     uint64_t    write_merges;   /* number of write I/Os merged with in-queue I/O */
 1185     uint64_t    write_sectors;  /* number of sectors written */
 1186     uint64_t    write_ticks;    /* total wait time for write requests */
 1187     uint64_t    in_flight;  /* number of I/Os currently in flight */
 1188     uint64_t    io_ticks;   /* total time this block device has been active */
 1189     uint64_t    time_in_queue;  /* total wait time for all requests */
 1190     uint64_t    discard_io; /* number of discard I/Os processed */
 1191     uint64_t    discard_merges; /* number of discard I/Os merged with in-queue I/O */
 1192     uint64_t    discard_sectors;/* number of sectors discarded */
 1193     uint64_t    discard_ticks;  /* total wait time for discard requests */
 1194 } stress_iostat_t;
 1195 
 1196 /* gcc 4.7 and later support vector ops */
 1197 #if defined(__GNUC__) &&    \
 1198     NEED_GNUC(4, 7, 0)
 1199 #define STRESS_VECTOR   1
 1200 #endif
 1201 
 1202 /* gcc 7.0 and later support __attribute__((fallthrough)); */
 1203 #if defined(HAVE_ATTRIBUTE_FALLTHROUGH)
 1204 #define CASE_FALLTHROUGH __attribute__((fallthrough)) /* Fallthrough */
 1205 #else
 1206 #define CASE_FALLTHROUGH /* Fallthrough */
 1207 #endif
 1208 
 1209 /* no return hint */
 1210 #if (defined(__GNUC__) && NEED_GNUC(2, 5, 0)) ||    \
 1211     (defined(__clang__) && NEED_CLANG(3, 0, 0))
 1212 #define NORETURN    __attribute__ ((noreturn))
 1213 #else
 1214 #define NORETURN
 1215 #endif
 1216 
 1217 /* weak attribute */
 1218 #if (defined(__GNUC__) && NEED_GNUC(4, 0, 0)) ||    \
 1219     (defined(__clang__) && NEED_CLANG(3, 4, 0))
 1220 #define WEAK        __attribute__ ((weak))
 1221 #define HAVE_WEAK_ATTRIBUTE
 1222 #else
 1223 #define WEAK
 1224 #endif
 1225 
 1226 /* force inlining hint */
 1227 #if (defined(__GNUC__) && NEED_GNUC(3, 4, 0)                    \
 1228      && ((!defined(__s390__) && !defined(__s390x__)) || NEED_GNUC(6, 0, 1))) || \
 1229     (defined(__clang__) && NEED_CLANG(3, 0, 0))
 1230 #define ALWAYS_INLINE   __attribute__ ((always_inline))
 1231 #else
 1232 #define ALWAYS_INLINE
 1233 #endif
 1234 
 1235 /* force no inlining hint */
 1236 #if (defined(__GNUC__) && NEED_GNUC(3, 4, 0)) ||    \
 1237     (defined(__clang__) && NEED_CLANG(3, 0, 0))
 1238 #define NOINLINE    __attribute__ ((noinline))
 1239 #else
 1240 #define NOINLINE
 1241 #endif
 1242 
 1243 /* -O3 attribute support */
 1244 #if defined(__GNUC__) &&    \
 1245     !defined(__clang__) &&  \
 1246     NEED_GNUC(4, 6, 0)
 1247 #define OPTIMIZE3   __attribute__((optimize("-O3")))
 1248 #else
 1249 #define OPTIMIZE3
 1250 #endif
 1251 
 1252 /* -O1 attribute support */
 1253 #if defined(__GNUC__) &&    \
 1254     !defined(__clang__) &&  \
 1255     NEED_GNUC(4, 6, 0)
 1256 #define OPTIMIZE1   __attribute__((optimize("-O1")))
 1257 #else
 1258 #define OPTIMIZE1
 1259 #endif
 1260 
 1261 /* -O0 attribute support */
 1262 #if defined(__GNUC__) &&    \
 1263     !defined(__clang__) &&  \
 1264     NEED_GNUC(4, 6, 0)
 1265 #define OPTIMIZE0   __attribute__((optimize("-O0")))
 1266 #else
 1267 #define OPTIMIZE0
 1268 #endif
 1269 
 1270 /* warn unused attribute */
 1271 #if (defined(__GNUC__) && NEED_GNUC(4, 2, 0)) ||    \
 1272     (defined(__clang__) && NEED_CLANG(3, 0, 0))
 1273 #define WARN_UNUSED __attribute__((warn_unused_result))
 1274 #else
 1275 #define WARN_UNUSED
 1276 #endif
 1277 
 1278 #if ((defined(__GNUC__) && NEED_GNUC(3, 3, 0)) ||   \
 1279      (defined(__clang__) && NEED_CLANG(3, 0, 0))) &&    \
 1280     !defined(__PCC__)
 1281 #define ALIGNED(a)  __attribute__((aligned(a)))
 1282 #else
 1283 #define ALIGNED(a)
 1284 #endif
 1285 
 1286 /* Force alignment to nearest 128 bytes */
 1287 #if ((defined(__GNUC__) && NEED_GNUC(3, 3, 0)) ||   \
 1288      (defined(__clang__) && NEED_CLANG(3, 0, 0))) &&    \
 1289     defined(HAVE_ALIGNED_128)
 1290 #define ALIGN128    ALIGNED(128)
 1291 #else
 1292 #define ALIGN128
 1293 #endif
 1294 
 1295 /* Force alignment to nearest 64 bytes */
 1296 #if ((defined(__GNUC__) && NEED_GNUC(3, 3, 0)) ||   \
 1297      (defined(__clang__) && NEED_CLANG(3, 0, 0))) &&    \
 1298     defined(HAVE_ALIGNED_64)
 1299 #define ALIGN64     ALIGNED(64)
 1300 #else
 1301 #define ALIGN64
 1302 #endif
 1303 
 1304 #if (defined(__GNUC__) && NEED_GNUC(4, 6, 0)) ||    \
 1305     (defined(__clang__) && NEED_CLANG(3, 0, 0))
 1306 #define SECTION(s)  __attribute__((__section__(# s)))
 1307 #else
 1308 #define SECTION(s)
 1309 #endif
 1310 
 1311 /* Choose cacheline alignment */
 1312 #if defined(ALIGN128)
 1313 #define ALIGN_CACHELINE ALIGN128
 1314 #else
 1315 #define ALIGN_CACHELINE ALIGN64
 1316 #endif
 1317 
 1318 /* GCC hot attribute */
 1319 #if (defined(__GNUC__) && NEED_GNUC(4, 6, 0)) ||    \
 1320     (defined(__clang__) && NEED_CLANG(3, 3, 0))
 1321 #define HOT     __attribute__ ((hot))
 1322 #else
 1323 #define HOT
 1324 #endif
 1325 
 1326 /* GCC mlocked data and data section attribute */
 1327 #if ((defined(__GNUC__) && NEED_GNUC(4, 6, 0) ||    \
 1328      (defined(__clang__) && NEED_CLANG(3, 0, 0)))) &&   \
 1329     !defined(__sun__) &&                \
 1330     !defined(__APPLE__) &&              \
 1331     !defined(BUILD_STATIC)
 1332 #define MLOCKED_TEXT    __attribute__((__section__("mlocked_text")))
 1333 #define MLOCKED_SECTION 1
 1334 #else
 1335 #define MLOCKED_TEXT
 1336 #endif
 1337 
 1338 /* print format attribute */
 1339 #if ((defined(__GNUC__) && NEED_GNUC(3, 2, 0)) ||   \
 1340      (defined(__clang__) && NEED_CLANG(3, 0, 0)))
 1341 #define FORMAT(func, a, b) __attribute__((format(func, a, b)))
 1342 #else
 1343 #define FORMAT(func, a, b)
 1344 #endif
 1345 
 1346 /* restrict keyword */
 1347 #if defined(HAVE___RESTRICT)
 1348 #define RESTRICT __restrict
 1349 #else
 1350 #define RESTRICT
 1351 #endif
 1352 
 1353 /* optimisation on branching */
 1354 #if defined(HAVE_BUILTIN_EXPECT)
 1355 #define LIKELY(x)   __builtin_expect((x),1)
 1356 #define UNLIKELY(x) __builtin_expect((x),0)
 1357 #else
 1358 #define LIKELY(x)   (x)
 1359 #define UNLIKELY(x) (x)
 1360 #endif
 1361 
 1362 #if !defined(HAVE_BUILTIN_PREFETCH) || defined(__PCC__)
 1363 /* a fake prefetch var-args no-op */
 1364 static inline void shim_builtin_prefetch(const void *addr, ...)
 1365 {
 1366     va_list ap;
 1367 
 1368     va_start(ap, addr);
 1369     va_end(ap);
 1370 }
 1371 #else
 1372 #define shim_builtin_prefetch       __builtin_prefetch
 1373 #endif
 1374 
 1375 #if defined(HAVE_BUILTIN_MEMMOVE)
 1376 #define shim_builtin_memmove        __builtin_memmove
 1377 #else
 1378 #define shim_builtin_memmove        memmove
 1379 #endif
 1380 
 1381 /* do nothing */
 1382 #if defined(HAVE_ASM_NOP)
 1383 #define FORCE_DO_NOTHING() __asm__ __volatile__("nop;")
 1384 #elif defined(HAVE_ASM_NOTHING)
 1385 #define FORCE_DO_NOTHING() __asm__ __volatile__("")
 1386 #else
 1387 #define FORCE_DO_NOTHING() while (0)
 1388 #endif
 1389 
 1390 #if defined(__clang__) &&   \
 1391     NEED_CLANG(4, 0, 0)
 1392 #define STRESS_PRAGMA_PUSH  _Pragma("GCC diagnostic push")
 1393 #define STRESS_PRAGMA_POP   _Pragma("GCC diagnostic pop")
 1394 #define STRESS_PRAGMA_WARN_OFF  _Pragma("GCC diagnostic ignored \"-Weverything\"")
 1395 #elif defined(__GNUC__) &&  \
 1396       NEED_GNUC(4, 4, 0)
 1397 #define STRESS_PRAGMA_PUSH  _Pragma("GCC diagnostic push")
 1398 #define STRESS_PRAGMA_POP   _Pragma("GCC diagnostic pop")
 1399 #define STRESS_PRAGMA_WARN_OFF  _Pragma("GCC diagnostic ignored \"-Wall\"") \
 1400                 _Pragma("GCC diagnostic ignored \"-Wextra\"") \
 1401                 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") \
 1402                 _Pragma("GCC diagnostic ignored \"-Wcast-qual\"") \
 1403                 _Pragma("GCC diagnostic ignored \"-Wnonnull\"")
 1404 #else
 1405 #define STRESS_PRAGMA_PUSH
 1406 #define STRESS_PRAGMA_POP
 1407 #define STRESS_PRAGMA_WARN_OFF
 1408 #endif
 1409 
 1410 /* Logging helpers */
 1411 extern int pr_msg(FILE *fp, const uint64_t flag,
 1412     const char *const fmt, va_list va) FORMAT(printf, 3, 0);
 1413 extern int pr_yaml(FILE *fp, const char *const fmt, ...) FORMAT(printf, 2, 3);
 1414 extern void pr_yaml_runinfo(FILE *fp);
 1415 extern void pr_runinfo(void);
 1416 extern void pr_openlog(const char *filename);
 1417 extern void pr_closelog(void);
 1418 extern void pr_fail_check(int *rc);
 1419 
 1420 extern void pr_dbg(const char *fmt, ...)  FORMAT(printf, 1, 2);
 1421 extern void pr_dbg_skip(const char *fmt, ...)  FORMAT(printf, 1, 2);
 1422 extern void pr_inf(const char *fmt, ...)  FORMAT(printf, 1, 2);
 1423 extern void pr_inf_skip(const char *fmt, ...)  FORMAT(printf, 1, 2);
 1424 extern void pr_err(const char *fmt, ...)  FORMAT(printf, 1, 2);
 1425 extern void pr_err_skip(const char *fmt, ...)  FORMAT(printf, 1, 2);
 1426 extern void pr_fail(const char *fmt, ...) FORMAT(printf, 1, 2);
 1427 extern void pr_tidy(const char *fmt, ...) FORMAT(printf, 1, 2);
 1428 
 1429 extern void pr_lock(bool *locked);
 1430 extern void pr_unlock(bool *locked);
 1431 extern void pr_inf_lock(bool *locked, const char *fmt, ...)  FORMAT(printf, 2, 3);
 1432 extern void pr_dbg_lock(bool *locked, const char *fmt, ...)  FORMAT(printf, 2, 3);
 1433 
 1434 /* volatile debug print macro */
 1435 #ifdef DEBUG
 1436 #define pr_dbg_v(fmt, ...) \
 1437     do { if (DEBUG) pr_dbg(fmt, __VA_ARGS__); } while (0)
 1438 #else
 1439 #define pr_dbg_v(fmt, ...)
 1440 #endif
 1441 
 1442 #if defined(HAVE_SYSLOG_H)
 1443 #define shim_syslog(priority, format, ...)  \
 1444         syslog(priority, format, __VA_ARGS__)
 1445 #define shim_openlog(ident, option, facility) \
 1446         openlog(ident, option, facility)
 1447 #define shim_closelog()     closelog()
 1448 #else
 1449 #define shim_syslog(priority, format, ...)
 1450 #define shim_openlog(ident, option, facility)
 1451 #define shim_closelog()
 1452 #endif
 1453 
 1454 /* Memory size constants */
 1455 #define KB          (1ULL << 10)
 1456 #define MB          (1ULL << 20)
 1457 #define GB          (1ULL << 30)
 1458 #define TB          (1ULL << 40)
 1459 #define PB          (1ULL << 50)
 1460 #define EB          (1ULL << 60)
 1461 
 1462 #define PAGE_4K_SHIFT       (12)
 1463 #define PAGE_4K         (1 << PAGE_4K_SHIFT)
 1464 
 1465 #define STACK_ALIGNMENT     (64)    /* thread stacks align to 64 bytes */
 1466 
 1467 #define MIN_OPS         (1ULL)
 1468 #define MAX_OPS         (100000000ULL)
 1469 #define MAX_32          (0xffffffffUL)
 1470 #define MAX_48          (0xffffffffffffULL)
 1471 #define MAX_64          (0xffffffffffffffffULL)
 1472 
 1473 /* Maximum memory limits, 256TB for 64 bit is good enough for 2017 */
 1474 #if UINTPTR_MAX == MAX_32
 1475 #define MAX_MEM_LIMIT       (MAX_32)
 1476 #else
 1477 #define MAX_MEM_LIMIT       (MAX_48)
 1478 #endif
 1479 
 1480 #define MAX_FILE_LIMIT      ((1ULL << ((sizeof(off_t) * 8) - 1)) - 1)
 1481 /*
 1482  * --maximize files must not be so big that we fill up
 1483  * a disk, so make them either the MAX_FILE_FILE_LIMIT for
 1484  * systems with small off_t or 4GB for large off_t systems
 1485  */
 1486 #define MAXIMIZED_FILE_SIZE ((sizeof(off_t) < 8) ? MAX_FILE_LIMIT : MAX_32)
 1487 
 1488 /* Stressor defaults */
 1489 #define MIN_AIO_REQUESTS    (1)
 1490 #define MAX_AIO_REQUESTS    (4096)
 1491 #define DEFAULT_AIO_REQUESTS    (16)
 1492 
 1493 #define MIN_AIO_LINUX_REQUESTS  (1)
 1494 #define MAX_AIO_LINUX_REQUESTS  (4096)
 1495 #define DEFAULT_AIO_LINUX_REQUESTS  (64)
 1496 
 1497 #define MIN_BIGHEAP_GROWTH  (4 * KB)
 1498 #define MAX_BIGHEAP_GROWTH  (64 * MB)
 1499 #define DEFAULT_BIGHEAP_GROWTH  (64 * KB)
 1500 
 1501 #define MIN_BSEARCH_SIZE    (1 * KB)
 1502 #define MAX_BSEARCH_SIZE    (4 * MB)
 1503 #define DEFAULT_BSEARCH_SIZE    (64 * KB)
 1504 
 1505 #define MIN_CHDIR_DIRS      (64)
 1506 #define MAX_CHDIR_DIRS      (65536)
 1507 #define DEFAULT_CHDIR_DIRS  (8192)
 1508 
 1509 #define MIN_CLONES      (1)
 1510 #define MAX_CLONES      (1000000)
 1511 #define DEFAULT_CLONES      (8192)
 1512 
 1513 #define MIN_COPY_FILE_BYTES (128 * MB)
 1514 #define MAX_COPY_FILE_BYTES (MAX_FILE_LIMIT)
 1515 #define DEFAULT_COPY_FILE_BYTES (256 * MB)
 1516 #define DEFAULT_COPY_FILE_SIZE  (2 * MB)
 1517 
 1518 #define MIN_DCCP_PORT       (1024)
 1519 #define MAX_DCCP_PORT       (65535)
 1520 #define DEFAULT_DCCP_PORT   (10000)
 1521 
 1522 #define MIN_DENTRIES        (1)
 1523 #define MAX_DENTRIES        (1000000)
 1524 #define DEFAULT_DENTRIES    (2048)
 1525 
 1526 #define MIN_DIR_DIRS        (64)
 1527 #define MAX_DIR_DIRS        (65536)
 1528 #define DEFAULT_DIR_DIRS    (8192)
 1529 
 1530 #define MIN_EPOLL_PORT      (1024)
 1531 #define MAX_EPOLL_PORT      (65535)
 1532 #define DEFAULT_EPOLL_PORT  (6000)
 1533 
 1534 #define MIN_HDD_BYTES       (1 * MB)
 1535 #define MAX_HDD_BYTES       (MAX_FILE_LIMIT)
 1536 #define DEFAULT_HDD_BYTES   (1 * GB)
 1537 
 1538 #define MIN_HDD_WRITE_SIZE  (1)
 1539 #define MAX_HDD_WRITE_SIZE  (4 * MB)
 1540 #define DEFAULT_HDD_WRITE_SIZE  (64 * 1024)
 1541 
 1542 #define MIN_FALLOCATE_BYTES (1 * MB)
 1543 #define MAX_FALLOCATE_BYTES (MAX_FILE_LIMIT)
 1544 #define DEFAULT_FALLOCATE_BYTES (1 * GB)
 1545 
 1546 #define MIN_FIEMAP_SIZE     (1 * MB)
 1547 #define MAX_FIEMAP_SIZE     (MAX_FILE_LIMIT)
 1548 #define DEFAULT_FIEMAP_SIZE (16 * MB)
 1549 
 1550 #define MIN_FIFO_READERS    (1)
 1551 #define MAX_FIFO_READERS    (64)
 1552 #define DEFAULT_FIFO_READERS    (4)
 1553 
 1554 #define MIN_ITIMER_FREQ     (1)
 1555 #define MAX_ITIMER_FREQ     (100000000)
 1556 #define DEFAULT_ITIMER_FREQ (1000000)
 1557 
 1558 #define MIN_MQ_SIZE     (1)
 1559 #define MAX_MQ_SIZE     (32)
 1560 #define DEFAULT_MQ_SIZE     (10)
 1561 
 1562 #define MIN_SEMAPHORE_PROCS (2)
 1563 #define MAX_SEMAPHORE_PROCS (64)
 1564 #define DEFAULT_SEMAPHORE_PROCS (2)
 1565 
 1566 #define MIN_EXECS       (1)
 1567 #define MAX_EXECS       (16000)
 1568 #define DEFAULT_EXECS       (1)
 1569 
 1570 #define MIN_FORKS       (1)
 1571 #define MAX_FORKS       (16000)
 1572 #define DEFAULT_FORKS       (1)
 1573 
 1574 #define MIN_HEAPSORT_SIZE   (1 * KB)
 1575 #define MAX_HEAPSORT_SIZE   (4 * MB)
 1576 #define DEFAULT_HEAPSORT_SIZE   (256 * KB)
 1577 
 1578 #define MIN_IOMIX_BYTES     (1 * MB)
 1579 #define MAX_IOMIX_BYTES     (MAX_FILE_LIMIT)
 1580 #define DEFAULT_IOMIX_BYTES (1 * GB)
 1581 
 1582 #define MIN_JUDY_SIZE       (1 * KB)
 1583 #define MAX_JUDY_SIZE       (4 * MB)
 1584 #define DEFAULT_JUDY_SIZE   (256 * KB)
 1585 
 1586 #define MIN_VFORKS      (1)
 1587 #define MAX_VFORKS      (16000)
 1588 #define DEFAULT_VFORKS      (1)
 1589 
 1590 #define MIN_HSEARCH_SIZE    (1 * KB)
 1591 #define MAX_HSEARCH_SIZE    (4 * MB)
 1592 #define DEFAULT_HSEARCH_SIZE    (8 * KB)
 1593 
 1594 #define MIN_LEASE_BREAKERS  (1)
 1595 #define MAX_LEASE_BREAKERS  (64)
 1596 #define DEFAULT_LEASE_BREAKERS  (1)
 1597 
 1598 #define MIN_LIST_SIZE       (64)
 1599 #define MAX_LIST_SIZE       (1000000)
 1600 #define DEFAULT_LIST_SIZE   (5000)
 1601 
 1602 #define MIN_LSEARCH_SIZE    (1 * KB)
 1603 #define MAX_LSEARCH_SIZE    (1 * MB)
 1604 #define DEFAULT_LSEARCH_SIZE    (8 * KB)
 1605 
 1606 #define MIN_MALLOC_BYTES    (1 * KB)
 1607 #define MAX_MALLOC_BYTES    (MAX_MEM_LIMIT)
 1608 #define DEFAULT_MALLOC_BYTES    (64 * KB)
 1609 
 1610 #define MIN_MALLOC_MAX      (32)
 1611 #define MAX_MALLOC_MAX      (256 * 1024)
 1612 #define DEFAULT_MALLOC_MAX  (64 * KB)
 1613 
 1614 #define MIN_MALLOC_THRESHOLD    (1)
 1615 #define MAX_MALLOC_THRESHOLD    (256 * MB)
 1616 #define DEFAULT_MALLOC_THRESHOLD (128 * KB)
 1617 
 1618 #define MIN_MATRIX_SIZE     (16)
 1619 #define MAX_MATRIX_SIZE     (8192)
 1620 #define DEFAULT_MATRIX_SIZE (256)
 1621 
 1622 #define MIN_MATRIX3D_SIZE   (16)
 1623 #define MAX_MATRIX3D_SIZE   (1024)
 1624 #define DEFAULT_MATRIX3D_SIZE   (64)
 1625 
 1626 #define MIN_MEMFD_BYTES     (2 * MB)
 1627 #define MAX_MEMFD_BYTES     (MAX_MEM_LIMIT)
 1628 #define DEFAULT_MEMFD_BYTES (256 * MB)
 1629 
 1630 #define MIN_MEMFD_FDS       (8)
 1631 #define MAX_MEMFD_FDS       (4096)
 1632 #define DEFAULT_MEMFD_FDS   (256)
 1633 
 1634 #define MIN_MERGESORT_SIZE  (1 * KB)
 1635 #define MAX_MERGESORT_SIZE  (4 * MB)
 1636 #define DEFAULT_MERGESORT_SIZE  (256 * KB)
 1637 
 1638 #define MIN_MMAP_BYTES      (4 * KB)
 1639 #define MAX_MMAP_BYTES      (MAX_MEM_LIMIT)
 1640 #define DEFAULT_MMAP_BYTES  (256 * MB)
 1641 
 1642 #define MIN_MEMRATE_BYTES   (4 * KB)
 1643 #define MAX_MEMRATE_BYTES   (MAX_MEM_LIMIT)
 1644 #define DEFAULT_MEMRATE_BYTES   (256 * MB)
 1645 
 1646 #define DEFAULT_MREMAP_BYTES    (256 * MB)
 1647 #define MIN_MREMAP_BYTES    (4 * KB)
 1648 #define MAX_MREMAP_BYTES    (MAX_MEM_LIMIT)
 1649 #define DEFAULT_MREMAP_BYTES    (256 * MB)
 1650 
 1651 #define MIN_MSYNC_BYTES     (1 * MB)    /* MUST NOT BE page size or less! */
 1652 #define MAX_MSYNC_BYTES     (MAX_FILE_LIMIT)
 1653 #define DEFAULT_MSYNC_BYTES (256 * MB)
 1654 
 1655 #define MIN_PTHREAD     (1)
 1656 #define MAX_PTHREAD     (30000)
 1657 #define DEFAULT_PTHREAD     (1024)
 1658 
 1659 #define MIN_PTYS        (8)
 1660 #define MAX_PTYS        (65536)
 1661 #define DEFAULT_PTYS        (65536)
 1662 
 1663 #define MIN_QSORT_SIZE      (1 * KB)
 1664 #define MAX_QSORT_SIZE      (4 * MB)
 1665 #define DEFAULT_QSORT_SIZE  (256 * KB)
 1666 
 1667 #define MIN_RADIXSORT_SIZE  (1 * KB)
 1668 #define MAX_RADIXSORT_SIZE  (4 * MB)
 1669 #define DEFAULT_RADIXSORT_SIZE  (256 * KB)
 1670 
 1671 #define MIN_READAHEAD_BYTES (1 * MB)
 1672 #define MAX_READAHEAD_BYTES (MAX_FILE_LIMIT)
 1673 #define DEFAULT_READAHEAD_BYTES (64 * MB)
 1674 
 1675 #define MIN_REVIO_BYTES     (1 * MB)
 1676 #define MAX_REVIO_BYTES     (MAX_FILE_LIMIT)
 1677 #define DEFAULT_REVIO_BYTES (1 * GB)
 1678 
 1679 #define MIN_SCTP_PORT       (1024)
 1680 #define MAX_SCTP_PORT       (65535)
 1681 #define DEFAULT_SCTP_PORT   (9000)
 1682 
 1683 #define MIN_SENDFILE_SIZE   (1 * KB)
 1684 #define MAX_SENDFILE_SIZE   (1 * GB)
 1685 #define DEFAULT_SENDFILE_SIZE   (4 * MB)
 1686 
 1687 #define MIN_SEEK_SIZE       (1 * MB)
 1688 #define MAX_SEEK_SIZE       (MAX_FILE_LIMIT)
 1689 #define DEFAULT_SEEK_SIZE   (16 * MB)
 1690 
 1691 #define MIN_SEQUENTIAL      (0)
 1692 #define MAX_SEQUENTIAL      (1000000)
 1693 #define DEFAULT_SEQUENTIAL  (0) /* Disabled */
 1694 #define DEFAULT_PARALLEL    (0) /* Disabled */
 1695 
 1696 #define MIN_SHELLSORT_SIZE  (1 * KB)
 1697 #define MAX_SHELLSORT_SIZE  (4 * MB)
 1698 #define DEFAULT_SHELLSORT_SIZE  (256 * KB)
 1699 
 1700 #define MIN_SHM_SYSV_BYTES  (1 * MB)
 1701 #define MAX_SHM_SYSV_BYTES  (256 * MB)
 1702 #define DEFAULT_SHM_SYSV_BYTES  (8 * MB)
 1703 
 1704 #define MIN_SHM_SYSV_SEGMENTS   (1)
 1705 #define MAX_SHM_SYSV_SEGMENTS   (128)
 1706 #define DEFAULT_SHM_SYSV_SEGMENTS (8)
 1707 
 1708 #define MIN_SHM_POSIX_BYTES (1 * MB)
 1709 #define MAX_SHM_POSIX_BYTES (1 * GB)
 1710 #define DEFAULT_SHM_POSIX_BYTES (8 * MB)
 1711 
 1712 #define MIN_SHM_POSIX_OBJECTS   (1)
 1713 #define MAX_SHM_POSIX_OBJECTS   (128)
 1714 #define DEFAULT_SHM_POSIX_OBJECTS (32)
 1715 
 1716 #define MAX_SIGSUSPEND_PIDS (4)
 1717 
 1718 #define MIN_SKIPLIST_SIZE   (1 * KB)
 1719 #define MAX_SKIPLIST_SIZE   (4 * MB)
 1720 #define DEFAULT_SKIPLIST_SIZE   (64 * KB)
 1721 
 1722 #define MIN_SLEEP       (1)
 1723 #define MAX_SLEEP       (30000)
 1724 #define DEFAULT_SLEEP       (1024)
 1725 
 1726 #define MIN_SOCKET_PORT     (1024)
 1727 #define MAX_SOCKET_PORT     (65535)
 1728 #define DEFAULT_SOCKET_PORT (5000)
 1729 
 1730 #define DEFAULT_SOCKET_MANY_PORT (11000)
 1731 #define DEFAULT_SOCKABUSE_PORT  (12000)
 1732 
 1733 #define MIN_RAWUDP_PORT     (1024)
 1734 #define MAX_RAWUDP_PORT     (65535)
 1735 #define DEFAULT_RAWUDP_PORT (13000)
 1736 
 1737 #define MIN_RAWPKT_PORT     (1024)
 1738 #define MAX_RAWPKT_PORT     (65535)
 1739 #define DEFAULT_RAWPKT_PORT (14000)
 1740 
 1741 #define MIN_SOCKET_FD_PORT  (1024)
 1742 #define MAX_SOCKET_FD_PORT  (65535)
 1743 #define DEFAULT_SOCKET_FD_PORT  (8000)
 1744 
 1745 #define MIN_SPLICE_BYTES    (1 * KB)
 1746 #define MAX_SPLICE_BYTES    (64 * MB)
 1747 #define DEFAULT_SPLICE_BYTES    (64 * KB)
 1748 
 1749 #define MIN_STREAM_L3_SIZE  (4 * KB)
 1750 #define MAX_STREAM_L3_SIZE  (MAX_MEM_LIMIT)
 1751 #define DEFAULT_STREAM_L3_SIZE  (4 * MB)
 1752 
 1753 #define MIN_SYNC_FILE_BYTES (1 * MB)
 1754 #define MAX_SYNC_FILE_BYTES (MAX_FILE_LIMIT)
 1755 #define DEFAULT_SYNC_FILE_BYTES (1 * GB)
 1756 
 1757 #define MIN_TIMER_FREQ      (1)
 1758 #define MAX_TIMER_FREQ      (100000000)
 1759 #define DEFAULT_TIMER_FREQ  (1000000)
 1760 
 1761 #define MIN_TIMERFD_FREQ    (1)
 1762 #define MAX_TIMERFD_FREQ    (100000000)
 1763 #define DEFAULT_TIMERFD_FREQ    (1000000)
 1764 
 1765 #define MIN_TREE_SIZE       (1000)
 1766 #define MAX_TREE_SIZE       (25000000)
 1767 #define DEFAULT_TREE_SIZE   (250000)
 1768 
 1769 #define MIN_TSEARCH_SIZE    (1 * KB)
 1770 #define MAX_TSEARCH_SIZE    (4 * MB)
 1771 #define DEFAULT_TSEARCH_SIZE    (64 * KB)
 1772 
 1773 #define MIN_UDP_PORT        (1024)
 1774 #define MAX_UDP_PORT        (65535)
 1775 #define DEFAULT_UDP_PORT    (7000)
 1776 
 1777 #define MIN_USERFAULTFD_BYTES   (4 * KB)
 1778 #define MAX_USERFAULTFD_BYTES   (MAX_MEM_LIMIT)
 1779 #define DEFAULT_USERFAULTFD_BYTES (16 * MB)
 1780 
 1781 #define MIN_VM_BYTES        (4 * KB)
 1782 #define MAX_VM_BYTES        (MAX_MEM_LIMIT)
 1783 #define DEFAULT_VM_BYTES    (256 * MB)
 1784 
 1785 #define MIN_VM_HANG     (0)
 1786 #define MAX_VM_HANG     (3600)
 1787 #define DEFAULT_VM_HANG     (~0ULL)
 1788 
 1789 #define MIN_VM_RW_BYTES     (4 * KB)
 1790 #define MAX_VM_RW_BYTES     (MAX_MEM_LIMIT)
 1791 #define DEFAULT_VM_RW_BYTES (16 * MB)
 1792 
 1793 #define MIN_VM_SPLICE_BYTES (4 * KB)
 1794 #define MAX_VM_SPLICE_BYTES (64 * MB)
 1795 #define DEFAULT_VM_SPLICE_BYTES (64 * KB)
 1796 
 1797 #define MIN_ZOMBIES     (1)
 1798 #define MAX_ZOMBIES     (1000000)
 1799 #define DEFAULT_ZOMBIES     (8192)
 1800 
 1801 #define TIMEOUT_NOT_SET     (~0ULL)
 1802 #define DEFAULT_TIMEOUT     (60 * 60 * 24)
 1803 #define DEFAULT_BACKOFF     (0)
 1804 #define DEFAULT_LINKS       (8192)
 1805 #define DEFAULT_DIRS        (8192)
 1806 
 1807 #define STR_SHARED_SIZE     (65536 * 32)
 1808 #define MEM_CACHE_SIZE      (65536 * 32)
 1809 #define DEFAULT_CACHE_LEVEL     3
 1810 #define UNDEFINED       (-1)
 1811 
 1812 #define PAGE_MAPPED     (0x01)
 1813 #define PAGE_MAPPED_FAIL    (0x02)
 1814 
 1815 #if defined(__GNUC__) || defined(__clang__)
 1816 #define TYPEOF_CAST(a)  (typeof(a))
 1817 #else
 1818 #define TYPEOF_CAST(a)
 1819 #endif
 1820 
 1821 /* Generic bit setting on an array macros */
 1822 #define STRESS_NBITS(a)     (sizeof(a[0]) * 8)
 1823 #define STRESS_GETBIT(a, i) (a[i / STRESS_NBITS(a)] & \
 1824                  (TYPEOF_CAST(a[0])1 << (i & (STRESS_NBITS(a)-1))))
 1825 #define STRESS_CLRBIT(a, i) (a[i / STRESS_NBITS(a)] &= \
 1826                  ~(TYPEOF_CAST(a[0])1 << (i & (STRESS_NBITS(a)-1))))
 1827 #define STRESS_SETBIT(a, i) (a[i / STRESS_NBITS(a)] |= \
 1828                  (TYPEOF_CAST(a[0])1 << (i & (STRESS_NBITS(a)-1))))
 1829 
 1830 /* MWC random number initial seed */
 1831 #define STRESS_MWC_SEED_Z   (362436069UL)
 1832 #define STRESS_MWC_SEED_W   (521288629UL)
 1833 #define STRESS_MWC_SEED()   stress_mwc_seed(STRESS_MWC_SEED_W, STRESS_MWC_SEED_Z)
 1834 
 1835 #define SIZEOF_ARRAY(a)     (sizeof(a) / sizeof(a[0]))
 1836 
 1837 /* Arch specific, x86 */
 1838 #if defined(__x86_64__) || defined(__x86_64) || \
 1839     defined(__i386__)   || defined(__i386)
 1840 #define STRESS_ARCH_X86     (1)
 1841 #endif
 1842 
 1843 /* Arch specific, ARM */
 1844 #if defined(__ARM_ARCH_6__)   || defined(__ARM_ARCH_6J__)  || \
 1845     defined(__ARM_ARCH_6K__)  || defined(__ARM_ARCH_6Z__)  || \
 1846     defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) || \
 1847     defined(__ARM_ARCH_6M__)  || defined(__ARM_ARCH_7__)   || \
 1848     defined(__ARM_ARCH_7A__)  || defined(__ARM_ARCH_7R__)  || \
 1849     defined(__ARM_ARCH_7M__)  || defined(__ARM_ARCH_7EM__) || \
 1850     defined(__ARM_ARCH_8A__)  || defined(__aarch64__)
 1851 #define STRESS_ARCH_ARM     (1)
 1852 #endif
 1853 
 1854 /* Arch specific RISC-V */
 1855 #if defined(__riscv) || \
 1856     defined(__riscv__)
 1857 #define STRESS_ARCH_RISC_V  (1)
 1858 #endif
 1859 
 1860 /* Arch specific, IBM S390 */
 1861 #if defined(__s390__)
 1862 #define STRESS_ARCH_S390    (1)
 1863 #endif
 1864 
 1865 /* Arch specific PPC64 */
 1866 #if defined(__PPC64__)
 1867 #define STRESS_ARCH_PPC64   (1)
 1868 #endif
 1869 
 1870 /* Arch specific M68K */
 1871 #if defined(__m68k__) ||    \
 1872     defined(__mc68000__) || \
 1873     defined(__mc68010__) || \
 1874     defined(__mc68020__)
 1875 #define STRESS_ARCH_M68K    (1)
 1876 #endif
 1877 
 1878 /* Arch specific SPARC */
 1879 #if defined(__sparc) ||     \
 1880     defined(__sparc__) ||   \
 1881     defined(__sparc_v9__)
 1882 #define STRESS_ARCH_SPARC
 1883 #endif
 1884 
 1885 /* GCC5.0+ target_clones attribute */
 1886 #if defined(HAVE_TARGET_CLONES) &&  \
 1887     defined(STRESS_ARCH_X86)
 1888 #if defined(__MMX_WITH_SSE__)
 1889 #define TARGET_CLONE_MMX    "mmx",
 1890 #else
 1891 #define TARGET_CLONE_MMX
 1892 #endif
 1893 
 1894 #if defined(__AVX__)
 1895 #define TARGET_CLONE_AVX    "avx",
 1896 #else
 1897 #define TARGET_CLONE_AVX
 1898 #endif
 1899 
 1900 #if defined(__AVX2__)
 1901 #define TARGET_CLONE_AVX2   "avx2",
 1902 #else
 1903 #define TARGET_CLONE_AVX2
 1904 #endif
 1905 
 1906 #if defined(__SSE__)
 1907 #define TARGET_CLONE_SSE    "sse",
 1908 #else
 1909 #define TARGET_CLONE_SSE
 1910 #endif
 1911 
 1912 #if defined(__SSE2__)
 1913 #define TARGET_CLONE_SSE2   "sse2",
 1914 #else
 1915 #define TARGET_CLONE_SSE2
 1916 #endif
 1917 
 1918 #if defined(__SSE3__)
 1919 #define TARGET_CLONE_SSE3   "sse3",
 1920 #else
 1921 #define TARGET_CLONE_SSE3
 1922 #endif
 1923 
 1924 #if defined(__SSSE3__)
 1925 #define TARGET_CLONE_SSSE3  "ssse3",
 1926 #else
 1927 #define TARGET_CLONE_SSSE3
 1928 #endif
 1929 
 1930 #if defined(__SSE4_1__)
 1931 #define TARGET_CLONE_SSE4_1 "sse4.1",
 1932 #else
 1933 #define TARGET_CLONE_SSE4_1
 1934 #endif
 1935 
 1936 #if defined(__SSE4_2__)
 1937 #define TARGET_CLONE_SSE4_2 "sse4.2",
 1938 #else
 1939 #define TARGET_CLONE_SSE4_2
 1940 #endif
 1941 
 1942 #if defined(__AVX512F__)
 1943 #define TARGET_CLONE_SKYLAKE_AVX512 "arch=skylake-avx512",
 1944 #else
 1945 #define TARGET_CLONE_SKYLAKE_AVX512
 1946 #endif
 1947 
 1948 #define TARGET_CLONES_ALL           \
 1949     TARGET_CLONE_AVX TARGET_CLONE_AVX2  \
 1950     TARGET_CLONE_MMX TARGET_CLONE_SSE   \
 1951     TARGET_CLONE_SSE2 TARGET_CLONE_SSE3 \
 1952     TARGET_CLONE_SSSE3 TARGET_CLONE_SSE4_1  \
 1953     TARGET_CLONE_SSE4_2         \
 1954     TARGET_CLONE_SKYLAKE_AVX512     \
 1955     "default"
 1956 
 1957 #define TARGET_CLONES   __attribute__((target_clones(TARGET_CLONES_ALL)))
 1958 #elif defined(HAVE_TARGET_CLONES) &&    \
 1959       defined(STRESS_ARCH_PPC64)
 1960 #define TARGET_CLONES   __attribute__((target_clones("cpu=power9,default")))
 1961 #else
 1962 #define TARGET_CLONES
 1963 #endif
 1964 
 1965 /*
 1966  *  See ioprio_set(2) and linux/ioprio.h, glibc has no definitions
 1967  *  for these at present. Also refer to Documentation/block/ioprio.txt
 1968  *  in the Linux kernel source.
 1969  */
 1970 #if !defined(IOPRIO_CLASS_RT)
 1971 #define IOPRIO_CLASS_RT         (1)
 1972 #endif
 1973 #if !defined(IOPRIO_CLASS_BE)
 1974 #define IOPRIO_CLASS_BE         (2)
 1975 #endif
 1976 #if !defined(IOPRIO_CLASS_IDLE)
 1977 #define IOPRIO_CLASS_IDLE       (3)
 1978 #endif
 1979 
 1980 #if !defined(IOPRIO_WHO_PROCESS)
 1981 #define IOPRIO_WHO_PROCESS      (1)
 1982 #endif
 1983 #if !defined(IOPRIO_WHO_PGRP)
 1984 #define IOPRIO_WHO_PGRP         (2)
 1985 #endif
 1986 #if !defined(IOPRIO_WHO_USER)
 1987 #define IOPRIO_WHO_USER         (3)
 1988 #endif
 1989 
 1990 #if !defined(IOPRIO_PRIO_VALUE)
 1991 #define IOPRIO_PRIO_VALUE(class, data)  (((class) << 13) | data)
 1992 #endif
 1993 
 1994 /* prctl(2) timer slack support */
 1995 #if defined(HAVE_SYS_PRCTL_H) && \
 1996     defined(HAVE_PRCTL) && \
 1997     defined(PR_SET_TIMERSLACK) && \
 1998     defined(PR_GET_TIMERSLACK)
 1999 #define HAVE_PRCTL_TIMER_SLACK
 2000 #endif
 2001 
 2002 static inline void ALWAYS_INLINE shim_mb(void)
 2003 {
 2004     asm volatile ("" ::: "memory");
 2005 }
 2006 
 2007 /* increment the stessor bogo ops counter */
 2008 static inline void ALWAYS_INLINE inc_counter(const stress_args_t *args)
 2009 {
 2010     *args->counter_ready = false;
 2011     shim_mb();
 2012     (*(args->counter))++;
 2013     shim_mb();
 2014     *args->counter_ready = true;
 2015     shim_mb();
 2016 }
 2017 
 2018 static inline uint64_t ALWAYS_INLINE get_counter(const stress_args_t *args)
 2019 {
 2020     return *args->counter;
 2021 }
 2022 
 2023 static inline void ALWAYS_INLINE set_counter(const stress_args_t *args, const uint64_t val)
 2024 {
 2025     *args->counter_ready = false;
 2026     shim_mb();
 2027     *args->counter = val;
 2028     shim_mb();
 2029     *args->counter_ready = true;
 2030     shim_mb();
 2031 }
 2032 
 2033 static inline void ALWAYS_INLINE add_counter(const stress_args_t *args, const uint64_t inc)
 2034 {
 2035     *args->counter_ready = false;
 2036     shim_mb();
 2037     *args->counter += inc;
 2038     shim_mb();
 2039     *args->counter_ready = true;
 2040     shim_mb();
 2041 }
 2042 
 2043 /* pthread porting shims, spinlock or fallback to mutex */
 2044 #if defined(HAVE_LIB_PTHREAD)
 2045 #if defined(HAVE_LIB_PTHREAD_SPINLOCK) &&   \
 2046     !defined(__DragonFly__) &&          \
 2047     !defined(__OpenBSD__)
 2048 typedef pthread_spinlock_t  shim_pthread_spinlock_t;
 2049 
 2050 #define SHIM_PTHREAD_PROCESS_SHARED     PTHREAD_PROCESS_SHARED
 2051 #define SHIM_PTHREAD_PROCESS_PRIVATE        PTHREAD_PROCESS_PRIVATE
 2052 
 2053 #define shim_pthread_spin_lock(lock)        pthread_spin_lock(lock)
 2054 #define shim_pthread_spin_unlock(lock)      pthread_spin_unlock(lock)
 2055 #define shim_pthread_spin_init(lock, shared)    pthread_spin_init(lock, shared)
 2056 #define shim_pthread_spin_destroy(lock)     pthread_spin_destroy(lock)
 2057 #else
 2058 typedef pthread_mutex_t     shim_pthread_spinlock_t;
 2059 
 2060 #define SHIM_PTHREAD_PROCESS_SHARED     NULL
 2061 #define SHIM_PTHREAD_PROCESS_PRIVATE        NULL
 2062 
 2063 #define shim_pthread_spin_lock(lock)        pthread_mutex_lock(lock)
 2064 #define shim_pthread_spin_unlock(lock)      pthread_mutex_unlock(lock)
 2065 #define shim_pthread_spin_init(lock, shared)    pthread_mutex_init(lock, shared)
 2066 #define shim_pthread_spin_destroy(lock)     pthread_mutex_destroy(lock)
 2067 #endif
 2068 #endif
 2069 
 2070 /* Capabilities shim */
 2071 
 2072 #define SHIM_CAP_IS_ROOT        (-1)
 2073 
 2074 /* POSIX-draft defined capabilities */
 2075 #if defined(CAP_CHOWN)
 2076 #define SHIM_CAP_CHOWN          CAP_CHOWN
 2077 #else
 2078 #define SHIM_CAP_CHOWN          SHIM_CAP_IS_ROOT
 2079 #endif
 2080 
 2081 #if defined(CAP_DAC_OVERRIDE)
 2082 #define SHIM_CAP_DAC_OVERRIDE       CAP_DAC_OVERRIDE
 2083 #else
 2084 #define SHIM_CAP_DAC_OVERRIDE       SHIM_CAP_IS_ROOT
 2085 #endif
 2086 
 2087 #if defined(CAP_DAC_READ_SEARCH)
 2088 #define SHIM_CAP_DAC_READ_SEARCH    CAP_DAC_READ_SEARCH
 2089 #else
 2090 #define SHIM_CAP_DAC_READ_SEARCH    SHIM_CAP_IS_ROOT
 2091 #endif
 2092 
 2093 #if defined(CAP_FOWNER)
 2094 #define SHIM_CAP_FOWNER         CAP_FOWNER
 2095 #else
 2096 #define SHIM_CAP_FOWNER         SHIM_CAP_IS_ROOT
 2097 #endif
 2098 
 2099 #if defined(CAP_FSETID)
 2100 #define SHIM_CAP_FSETID         CAP_FSETID
 2101 #else
 2102 #define SHIM_CAP_FSETID         SHIM_CAP_IS_ROOT
 2103 #endif
 2104 
 2105 #if defined(CAP_KILL)
 2106 #define SHIM_CAP_KILL           CAP_KILL
 2107 #else
 2108 #define SHIM_CAP_KILL           SHIM_CAP_IS_ROOT
 2109 #endif
 2110 
 2111 #if defined(CAP_SETGID)
 2112 #define SHIM_CAP_SETGID         CAP_SETGID
 2113 #else
 2114 #define SHIM_CAP_SETGID         SHIM_CAP_IS_ROOT
 2115 #endif
 2116 
 2117 #if defined(CAP_SETUID)
 2118 #define SHIM_CAP_SETUID         CAP_SETUID
 2119 #else
 2120 #define SHIM_CAP_SETUID         SHIM_CAP_IS_ROOT
 2121 #endif
 2122 
 2123 /* Linux specific capabilities */
 2124 #if defined(CAP_SETPCAP)
 2125 #define SHIM_CAP_SETPCAP        CAP_SETPCAP
 2126 #else
 2127 #define SHIM_CAP_SETPCAP        SHIM_CAP_IS_ROOT
 2128 #endif
 2129 
 2130 #if defined(CAP_LINUX_IMMUTABLE)
 2131 #define SHIM_CAP_LINUX_IMMUTABLE    CAP_LINUX_IMMUTABLE
 2132 #else
 2133 #define SHIM_CAP_LINUX_IMMUTABLE    SHIM_CAP_IS_ROOT
 2134 #endif
 2135 
 2136 #if defined(CAP_NET_BIND_SERVICE)
 2137 #define SHIM_CAP_NET_BIND_SERVICE   CAP_NET_BIND_SERVICE
 2138 #else
 2139 #define SHIM_CAP_NET_BIND_SERVICE   SHIM_CAP_IS_ROOT
 2140 #endif
 2141 
 2142 #if defined(CAP_NET_BROADCAST)
 2143 #define SHIM_CAP_NET_BROADCAST      CAP_NET_BROADCAST
 2144 #else
 2145 #define SHIM_CAP_NET_BROADCAST      SHIM_CAP_IS_ROOT
 2146 #endif
 2147 
 2148 #if defined(CAP_NET_ADMIN)
 2149 #define SHIM_CAP_NET_ADMIN      CAP_NET_ADMIN
 2150 #else
 2151 #define SHIM_CAP_NET_ADMIN      SHIM_CAP_IS_ROOT
 2152 #endif
 2153 
 2154 #if defined(CAP_NET_RAW)
 2155 #define SHIM_CAP_NET_RAW        CAP_NET_RAW
 2156 #else
 2157 #define SHIM_CAP_NET_RAW        SHIM_CAP_IS_ROOT
 2158 #endif
 2159 
 2160 #if defined(CAP_IPC_LOCK)
 2161 #define SHIM_CAP_IPC_LOCK       CAP_IPC_LOCK
 2162 #else
 2163 #define SHIM_CAP_IPC_LOCK       SHIM_CAP_IS_ROOT
 2164 #endif
 2165 
 2166 #if defined(CAP_IPC_OWNER)
 2167 #define SHIM_CAP_IPC_OWNER      CAP_IPC_OWNER
 2168 #else
 2169 #define SHIM_CAP_IPC_OWNER      SHIM_CAP_IS_ROOT
 2170 #endif
 2171 
 2172 #if defined(CAP_SYS_MODULE)
 2173 #define SHIM_CAP_SYS_MODULE     CAP_SYS_MODULE
 2174 #else
 2175 #define SHIM_CAP_SYS_MODULE     SHIM_CAP_IS_ROOT
 2176 #endif
 2177 
 2178 #if defined(CAP_SYS_RAWIO)
 2179 #define SHIM_CAP_SYS_RAWIO      CAP_SYS_RAWIO
 2180 #else
 2181 #define SHIM_CAP_SYS_RAWIO      SHIM_CAP_IS_ROOT
 2182 #endif
 2183 
 2184 #if defined(CAP_SYS_CHROOT)
 2185 #define SHIM_CAP_SYS_CHROOT     CAP_SYS_CHROOT
 2186 #else
 2187 #define SHIM_CAP_SYS_CHROOT     SHIM_CAP_IS_ROOT
 2188 #endif
 2189 
 2190 #if defined(CAP_SYS_PTRACE)
 2191 #define SHIM_CAP_SYS_PTRACE     CAP_SYS_PTRACE
 2192 #else
 2193 #define SHIM_CAP_SYS_PTRACE     SHIM_CAP_IS_ROOT
 2194 #endif
 2195 
 2196 #if defined(CAP_SYS_PACCT)
 2197 #define SHIM_CAP_SYS_PACCT      CAP_SYS_PACCT
 2198 #else
 2199 #define SHIM_CAP_SYS_PACCT      SHIM_CAP_IS_ROOT
 2200 #endif
 2201 
 2202 #if defined(CAP_SYS_ADMIN)
 2203 #define SHIM_CAP_SYS_ADMIN      CAP_SYS_ADMIN
 2204 #else
 2205 #define SHIM_CAP_SYS_ADMIN      SHIM_CAP_IS_ROOT
 2206 #endif
 2207 
 2208 #if defined(CAP_SYS_BOOT)
 2209 #define SHIM_CAP_SYS_BOOT       CAP_SYS_BOOT
 2210 #else
 2211 #define SHIM_CAP_SYS_BOOT       SHIM_CAP_IS_ROOT
 2212 #endif
 2213 
 2214 #if defined(CAP_SYS_NICE)
 2215 #define SHIM_CAP_SYS_NICE       CAP_SYS_NICE
 2216 #else
 2217 #define SHIM_CAP_SYS_NICE       SHIM_CAP_IS_ROOT
 2218 #endif
 2219 
 2220 #if defined(CAP_SYS_RESOURCE)
 2221 #define SHIM_CAP_SYS_RESOURCE       CAP_SYS_RESOURCE
 2222 #else
 2223 #define SHIM_CAP_SYS_RESOURCE       SHIM_CAP_IS_ROOT
 2224 #endif
 2225 
 2226 #if defined(CAP_SYS_TIME)
 2227 #define SHIM_CAP_SYS_TIME       CAP_SYS_TIME
 2228 #else
 2229 #define SHIM_CAP_SYS_TIME       SHIM_CAP_IS_ROOT
 2230 #endif
 2231 
 2232 #if defined(CAP_SYS_TTY_CONFIG)
 2233 #define SHIM_CAP_SYS_TTY_CONFIG     CAP_SYS_TTY_CONFIG
 2234 #else
 2235 #define SHIM_CAP_SYS_TTY_CONFIG     SHIM_CAP_IS_ROOT
 2236 #endif
 2237 
 2238 #if defined(CAP_MKNOD)
 2239 #define SHIM_CAP_MKNOD          CAP_MKNOD
 2240 #else
 2241 #define SHIM_CAP_MKNOD          SHIM_CAP_IS_ROOT
 2242 #endif
 2243 
 2244 #if defined(CAP_LEASE)
 2245 #define SHIM_CAP_LEASE          CAP_LEASE
 2246 #else
 2247 #define SHIM_CAP_LEASE          SHIM_CAP_IS_ROOT
 2248 #endif
 2249 
 2250 #if defined(CAP_AUDIT_WRITE)
 2251 #define SHIM_CAP_AUDIT_WRITE        CAP_AUDIT_WRITE
 2252 #else
 2253 #define SHIM_CAP_AUDIT_WRITE        SHIM_CAP_IS_ROOT
 2254 #endif
 2255 
 2256 #if defined(CAP_AUDIT_CONTROL)
 2257 #define SHIM_CAP_AUDIT_CONTROL      CAP_AUDIT_CONTROL
 2258 #else
 2259 #define SHIM_CAP_AUDIT_CONTROL      SHIM_CAP_IS_ROOT
 2260 #endif
 2261 
 2262 #if defined(CAP_SETFCAP)
 2263 #define SHIM_CAP_SETFCAP        CAP_SETFCAP
 2264 #else
 2265 #define SHIM_CAP_SETFCAP        SHIM_CAP_IS_ROOT
 2266 #endif
 2267 
 2268 #if defined(CAP_MAC_OVERRIDE)
 2269 #define SHIM_CAP_MAC_OVERRIDE       CAP_MAC_OVERRIDE
 2270 #else
 2271 #define SHIM_CAP_MAC_OVERRIDE       SHIM_CAP_IS_ROOT
 2272 #endif
 2273 
 2274 #if defined(CAP_MAC_ADMIN)
 2275 #define SHIM_CAP_MAC_ADMIN      CAP_MAC_ADMIN
 2276 #else
 2277 #define SHIM_CAP_MAC_ADMIN      SHIM_CAP_IS_ROOT
 2278 #endif
 2279 
 2280 #if defined(CAP_SYSLOG)
 2281 #define SHIM_CAP_SYSLOG         CAP_SYSLOG
 2282 #else
 2283 #define SHIM_CAP_SYSLOG         SHIM_CAP_IS_ROOT
 2284 #endif
 2285 
 2286 #if defined(CAP_WAKE_ALARM)
 2287 #define SHIM_CAP_WAKE_ALARM     CAP_WAKE_ALARM
 2288 #else
 2289 #define SHIM_CAP_WAKE_ALARM     SHIM_CAP_IS_ROOT
 2290 #endif
 2291 
 2292 #if defined(CAP_BLOCK_SUSPEND)
 2293 #define SHIM_CAP_BLOCK_SUSPEND      CAP_BLOCK_SUSPEND
 2294 #else
 2295 #define SHIM_CAP_BLOCK_SUSPEND      SHIM_CAP_IS_ROOT
 2296 #endif
 2297 
 2298 #if defined(CAP_AUDIT_READ)
 2299 #define SHIM_CAP_AUDIT_READ     CAP_AUDIT_READ
 2300 #else
 2301 #define SHIM_CAP_AUDIT_READ     SHIM_CAP_IS_ROOT
 2302 #endif
 2303 
 2304 #if defined(CAP_PERFMON)
 2305 #define SHIM_CAP_PERFMON        CAP_PERFMON
 2306 #else
 2307 #define SHIM_CAP_PERFMON        SHIM_CAP_IS_ROOT
 2308 #endif
 2309 
 2310 #if defined(CAP_BPF)
 2311 #define SHIM_CAP_BPF            CAP_BPF
 2312 #else
 2313 #define SHIM_CAP_BPF            SHIM_CAP_IS_ROOT
 2314 #endif
 2315 
 2316 
 2317 /* stress process prototype */
 2318 typedef int (*stress_func_t)(const stress_args_t *args);
 2319 
 2320 /* Fast random number generator state */
 2321 typedef struct {
 2322     uint32_t w;
 2323     uint32_t z;
 2324 } stress_mwc_t;
 2325 
 2326 /* perf related constants */
 2327 #if defined(HAVE_LIB_PTHREAD) &&    \
 2328     defined(HAVE_LINUX_PERF_EVENT_H) && \
 2329     defined(__NR_perf_event_open)
 2330 #define STRESS_PERF_STATS   (1)
 2331 #define STRESS_PERF_INVALID (~0ULL)
 2332 #define STRESS_PERF_MAX     (128)
 2333 
 2334 /* per perf counter info */
 2335 typedef struct {
 2336     uint64_t counter;       /* perf counter */
 2337     int  fd;            /* perf per counter fd */
 2338 } stress_perf_stat_t;
 2339 
 2340 /* per stressor perf info */
 2341 typedef struct {
 2342     stress_perf_stat_t  perf_stat[STRESS_PERF_MAX]; /* perf counters */
 2343     int         perf_opened;    /* count of opened counters */
 2344 } stress_perf_t;
 2345 #endif
 2346 
 2347 /* linux thermal zones */
 2348 #define STRESS_THERMAL_ZONES     (1)
 2349 #define STRESS_THERMAL_ZONES_MAX (31)   /* best if prime */
 2350 
 2351 #if defined(STRESS_THERMAL_ZONES)
 2352 /* per stressor thermal zone info */
 2353 typedef struct stress_tz_info {
 2354     char    *path;          /* thermal zone path */
 2355     char    *type;          /* thermal zone type */
 2356     uint32_t type_instance;     /* thermal zone instance # */
 2357     size_t  index;          /* thermal zone # index */
 2358     struct stress_tz_info *next;    /* next thermal zone in list */
 2359 } stress_tz_info_t;
 2360 
 2361 typedef struct {
 2362     uint64_t temperature;       /* temperature in Celsius * 1000 */
 2363 } stress_tz_stat_t;
 2364 
 2365 typedef struct {
 2366     stress_tz_stat_t tz_stat[STRESS_THERMAL_ZONES_MAX];
 2367 } stress_tz_t;
 2368 #endif
 2369 
 2370 /* Per stressor statistics and accounting info */
 2371 typedef struct {
 2372     uint64_t counter;       /* number of bogo ops */
 2373     bool counter_ready;     /* counter can be read */
 2374     struct tms tms;         /* run time stats of process */
 2375     double start;           /* wall clock start time */
 2376     double finish;          /* wall clock stop time */
 2377 #if defined(STRESS_PERF_STATS)
 2378     stress_perf_t sp;       /* perf counters */
 2379 #endif
 2380 #if defined(STRESS_THERMAL_ZONES)
 2381     stress_tz_t tz;         /* thermal zones */
 2382 #endif
 2383     bool run_ok;            /* true if stressor exited OK */
 2384     stress_checksum_t *checksum;    /* pointer to checksum data */
 2385     stress_misc_stats_t misc_stats[STRESS_MISC_STATS_MAX];
 2386 } stress_stats_t;
 2387 
 2388 #define STRESS_WARN_HASH_MAX        (128)
 2389 
 2390 /* The stress-ng global shared memory segment */
 2391 typedef struct {
 2392     size_t length;                  /* Size of segment */
 2393     uint8_t *mem_cache;             /* Shared memory cache */
 2394     uint64_t mem_cache_size;            /* Bytes */
 2395     uint16_t mem_cache_level;           /* 1=L1, 2=L2, 3=L3 */
 2396     uint16_t padding1;              /* alignment padding */
 2397     uint32_t mem_cache_ways;            /* cache ways size */
 2398     uint64_t zero;                  /* zero'd data */
 2399     stress_mapped_t mapped;             /* mmap'd pages to help testing */
 2400     struct {
 2401         uint32_t hash[STRESS_WARN_HASH_MAX];    /* hash patterns */
 2402 #if defined(HAVE_LIB_PTHREAD)
 2403         shim_pthread_spinlock_t lock;       /* protection lock */
 2404 #endif
 2405     } warn_once;
 2406     uint32_t warn_once_flags;           /* Warn once flags */
 2407     struct {
 2408         uint64_t val64;
 2409         uint32_t val32;
 2410         uint16_t val16;
 2411         uint8_t  val8;
 2412         uint8_t  padding2;          /* more padding */
 2413     } atomic;                   /* Shared atomic temp vars */
 2414     struct {
 2415         uint32_t futex[STRESS_PROCS_MAX];   /* Shared futexes */
 2416         uint64_t timeout[STRESS_PROCS_MAX]; /* Shared futex timeouts */
 2417     } futex;
 2418     struct {
 2419         key_t key_id;               /* System V semaphore key id */
 2420         int sem_id;             /* System V semaphore id */
 2421         bool init;              /* System V semaphore initialized */
 2422     } sem_sysv;
 2423 #if defined(STRESS_PERF_STATS)
 2424     struct {
 2425         bool no_perf;               /* true = Perf not available */
 2426         shim_pthread_spinlock_t lock;       /* spinlock on no_perf updates */
 2427     } perf;
 2428 #endif
 2429     bool *af_alg_hash_skip;             /* Shared array of hash skip flags */
 2430     bool *af_alg_cipher_skip;           /* Shared array of cipher skip flags */
 2431 #if defined(STRESS_THERMAL_ZONES)
 2432     stress_tz_info_t *tz_info;          /* List of valid thermal zones */
 2433 #endif
 2434 #if defined(HAVE_ATOMIC)
 2435     uint32_t softlockup_count;          /* Atomic counter of softlock children */
 2436 #endif
 2437     uint8_t  str_shared[STR_SHARED_SIZE];       /* str copying buffer */
 2438     stress_checksum_t *checksums;           /* per stressor counter checksum */
 2439     size_t  checksums_length;           /* size of checksums mapping */
 2440     stress_stats_t stats[0];            /* Shared statistics */
 2441 } stress_shared_t;
 2442 
 2443 /* Stress test classes */
 2444 typedef struct {
 2445     stress_class_t class;       /* Class type bit mask */
 2446     const char *name;       /* Name of class */
 2447 } stress_class_info_t;
 2448 
 2449 #define STRESSORS(MACRO)    \
 2450     MACRO(access)       \
 2451     MACRO(af_alg)       \
 2452     MACRO(affinity)     \
 2453     MACRO(aio)      \
 2454     MACRO(aiol)         \
 2455     MACRO(apparmor)     \
 2456     MACRO(alarm)        \
 2457     MACRO(atomic)       \
 2458     MACRO(bad_altstack)     \
 2459     MACRO(bad_ioctl)    \
 2460     MACRO(bigheap)      \
 2461     MACRO(bind_mount)   \
 2462     MACRO(binderfs)     \
 2463     MACRO(branch)       \
 2464     MACRO(brk)      \
 2465     MACRO(bsearch)      \
 2466     MACRO(cache)        \
 2467     MACRO(cap)      \
 2468     MACRO(chattr)       \
 2469     MACRO(chdir)        \
 2470     MACRO(chmod)        \
 2471     MACRO(chown)        \
 2472     MACRO(chroot)       \
 2473     MACRO(clock)        \
 2474     MACRO(clone)        \
 2475     MACRO(close)        \
 2476     MACRO(context)      \
 2477     MACRO(copy_file)    \
 2478     MACRO(cpu)      \
 2479     MACRO(cpu_online)   \
 2480     MACRO(crypt)        \
 2481     MACRO(cyclic)       \
 2482     MACRO(daemon)       \
 2483     MACRO(dccp)     \
 2484     MACRO(dentry)       \
 2485     MACRO(dev)      \
 2486     MACRO(dev_shm)      \
 2487     MACRO(dir)      \
 2488     MACRO(dirdeep)      \
 2489     MACRO(dirmany)      \
 2490     MACRO(dnotify)      \
 2491     MACRO(dup)      \
 2492     MACRO(dynlib)       \
 2493     MACRO(efivar)       \
 2494     MACRO(enosys)       \
 2495     MACRO(env)      \
 2496     MACRO(epoll)        \
 2497     MACRO(eventfd)      \
 2498     MACRO(exec)     \
 2499     MACRO(exit_group)   \
 2500     MACRO(fallocate)    \
 2501     MACRO(fanotify)     \
 2502     MACRO(fault)        \
 2503     MACRO(fcntl)        \
 2504     MACRO(fiemap)       \
 2505     MACRO(fifo)     \
 2506     MACRO(file_ioctl)   \
 2507     MACRO(filename)     \
 2508     MACRO(flock)        \
 2509     MACRO(fork)     \
 2510     MACRO(fp_error)     \
 2511     MACRO(fpunch)       \
 2512     MACRO(fstat)        \
 2513     MACRO(full)     \
 2514     MACRO(funccall)     \
 2515     MACRO(funcret)      \
 2516     MACRO(futex)        \
 2517     MACRO(get)      \
 2518     MACRO(getdent)      \
 2519     MACRO(getrandom)    \
 2520     MACRO(handle)       \
 2521     MACRO(hdd)      \
 2522     MACRO(heapsort)     \
 2523     MACRO(hrtimers)     \
 2524     MACRO(hsearch)      \
 2525     MACRO(icache)       \
 2526     MACRO(icmp_flood)   \
 2527     MACRO(idle_page)    \
 2528     MACRO(inode_flags)  \
 2529     MACRO(inotify)      \
 2530     MACRO(io)       \
 2531     MACRO(iomix)        \
 2532     MACRO(ioport)       \
 2533     MACRO(ioprio)       \
 2534     MACRO(io_uring)     \
 2535     MACRO(ipsec_mb)     \
 2536     MACRO(itimer)       \
 2537     MACRO(judy)     \
 2538     MACRO(kcmp)     \
 2539     MACRO(key)      \
 2540     MACRO(kill)     \
 2541     MACRO(klog)     \
 2542     MACRO(l1cache)      \
 2543     MACRO(landlock)     \
 2544     MACRO(lease)        \
 2545     MACRO(link)     \
 2546     MACRO(list)     \
 2547     MACRO(loadavg)      \
 2548     MACRO(locka)        \
 2549     MACRO(lockbus)      \
 2550     MACRO(lockf)        \
 2551     MACRO(lockofd)      \
 2552     MACRO(longjmp)      \
 2553     MACRO(loop)     \
 2554     MACRO(lsearch)      \
 2555     MACRO(madvise)      \
 2556     MACRO(malloc)       \
 2557     MACRO(matrix)       \
 2558     MACRO(matrix_3d)    \
 2559     MACRO(mcontend)     \
 2560     MACRO(membarrier)   \
 2561     MACRO(memcpy)       \
 2562     MACRO(memfd)        \
 2563     MACRO(memhotplug)   \
 2564     MACRO(memrate)      \
 2565     MACRO(memthrash)    \
 2566     MACRO(mergesort)    \
 2567     MACRO(mincore)      \
 2568     MACRO(misaligned)   \
 2569     MACRO(mknod)        \
 2570     MACRO(mlock)        \
 2571     MACRO(mlockmany)    \
 2572     MACRO(mmap)     \
 2573     MACRO(mmapaddr)     \
 2574     MACRO(mmapfixed)    \
 2575     MACRO(mmapfork)     \
 2576     MACRO(mmaphuge)     \
 2577     MACRO(mmapmany)     \
 2578     MACRO(mq)       \
 2579     MACRO(mremap)       \
 2580     MACRO(msg)      \
 2581     MACRO(msync)        \
 2582     MACRO(munmap)       \
 2583     MACRO(nanosleep)    \
 2584     MACRO(netdev)       \
 2585     MACRO(netlink_proc) \
 2586     MACRO(netlink_task) \
 2587     MACRO(nice)     \
 2588     MACRO(nop)      \
 2589     MACRO(null)     \
 2590     MACRO(numa)     \
 2591     MACRO(oom_pipe)     \
 2592     MACRO(opcode)       \
 2593     MACRO(open)     \
 2594     MACRO(pci)      \
 2595     MACRO(personality)  \
 2596     MACRO(physpage)     \
 2597     MACRO(pidfd)        \
 2598     MACRO(ping_sock)    \
 2599     MACRO(pipe)     \
 2600     MACRO(pipeherd)     \
 2601     MACRO(pkey)     \
 2602     MACRO(poll)     \
 2603     MACRO(prctl)        \
 2604     MACRO(prefetch)     \
 2605     MACRO(procfs)       \
 2606     MACRO(pthread)      \
 2607     MACRO(ptrace)       \
 2608     MACRO(pty)      \
 2609     MACRO(qsort)        \
 2610     MACRO(quota)        \
 2611     MACRO(radixsort)    \
 2612     MACRO(ramfs)        \
 2613     MACRO(rawdev)       \
 2614     MACRO(rawpkt)       \
 2615     MACRO(rawsock)      \
 2616     MACRO(rawudp)       \
 2617     MACRO(rdrand)       \
 2618     MACRO(readahead)    \
 2619     MACRO(reboot)       \
 2620     MACRO(remap)        \
 2621     MACRO(rename)       \
 2622     MACRO(resources)    \
 2623     MACRO(revio)        \
 2624     MACRO(rlimit)       \
 2625     MACRO(rmap)     \
 2626     MACRO(rseq)     \
 2627     MACRO(rtc)      \
 2628     MACRO(schedpolicy)  \
 2629     MACRO(sctp)     \
 2630     MACRO(seal)     \
 2631     MACRO(seccomp)      \
 2632     MACRO(secretmem)    \
 2633     MACRO(seek)     \
 2634     MACRO(sem)      \
 2635     MACRO(sem_sysv)     \
 2636     MACRO(sendfile)     \
 2637     MACRO(session)      \
 2638     MACRO(set)      \
 2639     MACRO(shellsort)    \
 2640     MACRO(shm)      \
 2641     MACRO(shm_sysv)     \
 2642     MACRO(sigabrt)      \
 2643     MACRO(sigchld)      \
 2644     MACRO(sigfd)        \
 2645     MACRO(sigfpe)       \
 2646     MACRO(sigio)        \
 2647     MACRO(signal)       \
 2648     MACRO(signest)      \
 2649     MACRO(sigpending)   \
 2650     MACRO(sigpipe)      \
 2651     MACRO(sigq)     \
 2652     MACRO(sigrt)        \
 2653     MACRO(sigsegv)      \
 2654     MACRO(sigsuspend)   \
 2655     MACRO(sigtrap)      \
 2656     MACRO(skiplist)     \
 2657     MACRO(sleep)        \
 2658     MACRO(smi)      \
 2659     MACRO(sock)     \
 2660     MACRO(sockabuse)    \
 2661     MACRO(sockdiag)     \
 2662     MACRO(sockfd)       \
 2663     MACRO(sockpair)     \
 2664     MACRO(sockmany)     \
 2665     MACRO(softlockup)   \
 2666     MACRO(spawn)        \
 2667     MACRO(splice)       \
 2668     MACRO(stack)        \
 2669     MACRO(stackmmap)    \
 2670     MACRO(str)      \
 2671     MACRO(stream)       \
 2672     MACRO(swap)     \
 2673     MACRO(switch)       \
 2674     MACRO(symlink)      \
 2675     MACRO(sync_file)    \
 2676     MACRO(sysbadaddr)   \
 2677     MACRO(sysinfo)      \
 2678     MACRO(sysinval)     \
 2679     MACRO(sysfs)        \
 2680     MACRO(tee)      \
 2681     MACRO(timer)        \
 2682     MACRO(timerfd)      \
 2683     MACRO(tlb_shootdown)    \
 2684     MACRO(tmpfs)        \
 2685     MACRO(tree)     \
 2686     MACRO(tsc)      \
 2687     MACRO(tsearch)      \
 2688     MACRO(tun)      \
 2689     MACRO(udp)      \
 2690     MACRO(udp_flood)    \
 2691     MACRO(unshare)      \
 2692     MACRO(uprobe)       \
 2693     MACRO(urandom)      \
 2694     MACRO(userfaultfd)  \
 2695     MACRO(utime)        \
 2696     MACRO(vdso)     \
 2697     MACRO(vecmath)      \
 2698     MACRO(verity)       \
 2699     MACRO(vfork)        \
 2700     MACRO(vforkmany)    \
 2701     MACRO(vm)       \
 2702     MACRO(vm_addr)      \
 2703     MACRO(vm_rw)        \
 2704     MACRO(vm_segv)      \
 2705     MACRO(vm_splice)    \
 2706     MACRO(wait)     \
 2707     MACRO(watchdog)     \
 2708     MACRO(wcs)      \
 2709     MACRO(x86syscall)   \
 2710     MACRO(xattr)        \
 2711     MACRO(yield)        \
 2712     MACRO(zero)     \
 2713     MACRO(zlib)     \
 2714     MACRO(zombie)
 2715 
 2716 /*
 2717  *  Declaration of stress_*_info object
 2718  */
 2719 #define STRESSOR_ENUM(name) \
 2720     STRESS_ ## name,
 2721 
 2722 /*
 2723  *  Declaration of stress_*_info object
 2724  */
 2725 #define STRESSOR_DECL(name)     \
 2726     extern stressor_info_t stress_ ## name ## _info;
 2727 
 2728 STRESSORS(STRESSOR_DECL)
 2729 
 2730 /* Stress tests */
 2731 typedef enum {
 2732     STRESS_START = -1,
 2733     STRESSORS(STRESSOR_ENUM)
 2734     /* STRESS_MAX must be last one */
 2735     STRESS_MAX
 2736 } stress_id_t;
 2737 
 2738 /* Command line long options */
 2739 typedef enum {
 2740     OPT_undefined = 0,
 2741     /* Short options */
 2742     OPT_query = '?',
 2743     OPT_all = 'a',
 2744     OPT_backoff = 'b',
 2745     OPT_bigheap = 'B',
 2746     OPT_cpu = 'c',
 2747     OPT_cache = 'C',
 2748     OPT_hdd = 'd',
 2749     OPT_dentry = 'D',
 2750     OPT_fork = 'f',
 2751     OPT_fallocate = 'F',
 2752     OPT_io = 'i',
 2753     OPT_job = 'j',
 2754     OPT_help = 'h',
 2755     OPT_keep_name = 'k',
 2756     OPT_cpu_load = 'l',
 2757     OPT_vm = 'm',
 2758     OPT_metrics = 'M',
 2759     OPT_dry_run = 'n',
 2760     OPT_rename = 'R',
 2761     OPT_open = 'o',
 2762     OPT_pipe = 'p',
 2763     OPT_poll = 'P',
 2764     OPT_quiet = 'q',
 2765     OPT_random = 'r',
 2766     OPT_switch = 's',
 2767     OPT_sock = 'S',
 2768     OPT_timeout = 't',
 2769     OPT_timer = 'T',
 2770     OPT_urandom = 'u',
 2771     OPT_verbose = 'v',
 2772     OPT_version = 'V',
 2773     OPT_yield = 'y',
 2774     OPT_yaml = 'Y',
 2775     OPT_exclude = 'x',
 2776 
 2777     /* Long options only */
 2778 
 2779     OPT_long_ops_start = 0x7f,
 2780 
 2781     OPT_abort,
 2782 
 2783     OPT_access,
 2784     OPT_access_ops,
 2785 
 2786     OPT_affinity,
 2787     OPT_affinity_delay,
 2788     OPT_affinity_ops,
 2789     OPT_affinity_pin,
 2790     OPT_affinity_rand,
 2791     OPT_affinity_sleep,
 2792 
 2793     OPT_af_alg,
 2794     OPT_af_alg_ops,
 2795     OPT_af_alg_dump,
 2796 
 2797     OPT_aggressive,
 2798 
 2799     OPT_aio,
 2800     OPT_aio_ops,
 2801     OPT_aio_requests,
 2802 
 2803     OPT_aiol,
 2804     OPT_aiol_ops,
 2805     OPT_aiol_requests,
 2806 
 2807     OPT_alarm,
 2808     OPT_alarm_ops,
 2809 
 2810     OPT_apparmor,
 2811     OPT_apparmor_ops,
 2812 
 2813     OPT_atomic,
 2814     OPT_atomic_ops,
 2815 
 2816     OPT_bad_altstack,
 2817     OPT_bad_altstack_ops,
 2818 
 2819     OPT_bad_ioctl,
 2820     OPT_bad_ioctl_ops,
 2821 
 2822     OPT_branch,
 2823     OPT_branch_ops,
 2824 
 2825     OPT_brk,
 2826     OPT_brk_ops,
 2827     OPT_brk_mlock,
 2828     OPT_brk_notouch,
 2829 
 2830     OPT_bsearch,
 2831     OPT_bsearch_ops,
 2832     OPT_bsearch_size,
 2833 
 2834     OPT_bigheap_ops,
 2835     OPT_bigheap_growth,
 2836 
 2837     OPT_bind_mount,
 2838     OPT_bind_mount_ops,
 2839 
 2840     OPT_binderfs,
 2841     OPT_binderfs_ops,
 2842 
 2843     OPT_class,
 2844     OPT_cache_ops,
 2845     OPT_cache_prefetch,
 2846     OPT_cache_flush,
 2847     OPT_cache_fence,
 2848     OPT_cache_sfence,
 2849     OPT_cache_level,
 2850     OPT_cache_ways,
 2851     OPT_cache_no_affinity,
 2852 
 2853     OPT_cap,
 2854     OPT_cap_ops,
 2855 
 2856     OPT_chattr,
 2857     OPT_chattr_ops,
 2858 
 2859     OPT_chdir,
 2860     OPT_chdir_dirs,
 2861     OPT_chdir_ops,
 2862 
 2863     OPT_chmod,
 2864     OPT_chmod_ops,
 2865 
 2866     OPT_chown,
 2867     OPT_chown_ops,
 2868 
 2869     OPT_chroot,
 2870     OPT_chroot_ops,
 2871 
 2872     OPT_clock,
 2873     OPT_clock_ops,
 2874 
 2875     OPT_clone,
 2876     OPT_clone_ops,
 2877     OPT_clone_max,
 2878 
 2879     OPT_close,
 2880     OPT_close_ops,
 2881 
 2882     OPT_context,
 2883     OPT_context_ops,
 2884 
 2885     OPT_copy_file,
 2886     OPT_copy_file_ops,
 2887     OPT_copy_file_bytes,
 2888 
 2889     OPT_cpu_ops,
 2890     OPT_cpu_method,
 2891     OPT_cpu_load_slice,
 2892 
 2893     OPT_cpu_online,
 2894     OPT_cpu_online_ops,
 2895     OPT_cpu_online_all,
 2896 
 2897     OPT_crypt,
 2898     OPT_crypt_ops,
 2899 
 2900     OPT_cyclic,
 2901     OPT_cyclic_ops,
 2902     OPT_cyclic_method,
 2903     OPT_cyclic_policy,
 2904     OPT_cyclic_prio,
 2905     OPT_cyclic_sleep,
 2906     OPT_cyclic_dist,
 2907 
 2908     OPT_daemon,
 2909     OPT_daemon_ops,
 2910 
 2911     OPT_dccp,
 2912     OPT_dccp_domain,
 2913     OPT_dccp_ops,
 2914     OPT_dccp_opts,
 2915     OPT_dccp_port,
 2916 
 2917     OPT_dentry_ops,
 2918     OPT_dentries,
 2919     OPT_dentry_order,
 2920 
 2921     OPT_dev,
 2922     OPT_dev_ops,
 2923     OPT_dev_file,
 2924 
 2925     OPT_dev_shm,
 2926     OPT_dev_shm_ops,
 2927 
 2928     OPT_dir,
 2929     OPT_dir_ops,
 2930     OPT_dir_dirs,
 2931 
 2932     OPT_dirdeep,
 2933     OPT_dirdeep_ops,
 2934     OPT_dirdeep_dirs,
 2935     OPT_dirdeep_inodes,
 2936 
 2937     OPT_dirmany,
 2938     OPT_dirmany_ops,
 2939 
 2940     OPT_dnotify,
 2941     OPT_dnotify_ops,
 2942 
 2943     OPT_dup,
 2944     OPT_dup_ops,
 2945 
 2946     OPT_dynlib,
 2947     OPT_dynlib_ops,
 2948 
 2949     OPT_efivar,
 2950     OPT_efivar_ops,
 2951 
 2952     OPT_enosys,
 2953     OPT_enosys_ops,
 2954 
 2955     OPT_env,
 2956     OPT_env_ops,
 2957 
 2958     OPT_epoll,
 2959     OPT_epoll_ops,
 2960     OPT_epoll_port,
 2961     OPT_epoll_domain,
 2962 
 2963     OPT_eventfd,
 2964     OPT_eventfd_ops,
 2965     OPT_eventfd_nonblock,
 2966 
 2967     OPT_exec,
 2968     OPT_exec_ops,
 2969     OPT_exec_max,
 2970 
 2971     OPT_exit_group,
 2972     OPT_exit_group_ops,
 2973 
 2974     OPT_fallocate_ops,
 2975     OPT_fallocate_bytes,
 2976 
 2977     OPT_fanotify,
 2978     OPT_fanotify_ops,
 2979 
 2980     OPT_fault,
 2981     OPT_fault_ops,
 2982 
 2983     OPT_fcntl,
 2984     OPT_fcntl_ops,
 2985 
 2986     OPT_fiemap,
 2987     OPT_fiemap_ops,
 2988     OPT_fiemap_bytes,
 2989 
 2990     OPT_fifo,
 2991     OPT_fifo_ops,
 2992     OPT_fifo_readers,
 2993 
 2994     OPT_file_ioctl,
 2995     OPT_file_ioctl_ops,
 2996 
 2997     OPT_filename,
 2998     OPT_filename_ops,
 2999     OPT_filename_opts,
 3000 
 3001     OPT_flock,
 3002     OPT_flock_ops,
 3003 
 3004     OPT_fork_ops,
 3005     OPT_fork_max,
 3006     OPT_fork_vm,
 3007 
 3008     OPT_fp_error,
 3009     OPT_fp_error_ops,
 3010 
 3011     OPT_fpunch,
 3012     OPT_fpunch_ops,
 3013 
 3014     OPT_fstat,
 3015     OPT_fstat_ops,
 3016     OPT_fstat_dir,
 3017 
 3018     OPT_ftrace,
 3019 
 3020     OPT_full,
 3021     OPT_full_ops,
 3022 
 3023     OPT_funccall,
 3024     OPT_funccall_ops,
 3025     OPT_funccall_method,
 3026 
 3027     OPT_funcret,
 3028     OPT_funcret_ops,
 3029     OPT_funcret_method,
 3030 
 3031     OPT_futex,
 3032     OPT_futex_ops,
 3033 
 3034     OPT_get,
 3035     OPT_get_ops,
 3036 
 3037     OPT_getrandom,
 3038     OPT_getrandom_ops,
 3039 
 3040     OPT_getdent,
 3041     OPT_getdent_ops,
 3042 
 3043     OPT_handle,
 3044     OPT_handle_ops,
 3045 
 3046     OPT_hdd_bytes,
 3047     OPT_hdd_write_size,
 3048     OPT_hdd_ops,
 3049     OPT_hdd_opts,
 3050 
 3051     OPT_heapsort,
 3052     OPT_heapsort_ops,
 3053     OPT_heapsort_integers,
 3054 
 3055     OPT_hrtimers,
 3056     OPT_hrtimers_ops,
 3057 
 3058     OPT_hsearch,
 3059     OPT_hsearch_ops,
 3060     OPT_hsearch_size,
 3061 
 3062     OPT_icache,
 3063     OPT_icache_ops,
 3064 
 3065     OPT_icmp_flood,
 3066     OPT_icmp_flood_ops,
 3067 
 3068     OPT_idle_page,
 3069     OPT_idle_page_ops,
 3070 
 3071     OPT_ignite_cpu,
 3072 
 3073     OPT_inode_flags,
 3074     OPT_inode_flags_ops,
 3075 
 3076     OPT_inotify,
 3077     OPT_inotify_ops,
 3078 
 3079     OPT_iomix,
 3080     OPT_iomix_bytes,
 3081     OPT_iomix_ops,
 3082 
 3083     OPT_ioport,
 3084     OPT_ioport_ops,
 3085     OPT_ioport_opts,
 3086 
 3087     OPT_ionice_class,
 3088     OPT_ionice_level,
 3089 
 3090     OPT_ioprio,
 3091     OPT_ioprio_ops,
 3092 
 3093     OPT_iostat,
 3094 
 3095     OPT_io_ops,
 3096 
 3097     OPT_io_uring,
 3098     OPT_io_uring_ops,
 3099 
 3100     OPT_ipsec_mb,
 3101     OPT_ipsec_mb_ops,
 3102     OPT_ipsec_mb_feature,
 3103 
 3104     OPT_itimer,
 3105     OPT_itimer_ops,
 3106     OPT_itimer_freq,
 3107     OPT_itimer_rand,
 3108 
 3109     OPT_judy,
 3110     OPT_judy_ops,
 3111     OPT_judy_size,
 3112 
 3113     OPT_kcmp,
 3114     OPT_kcmp_ops,
 3115 
 3116     OPT_key,
 3117     OPT_key_ops,
 3118 
 3119     OPT_kill,
 3120     OPT_kill_ops,
 3121 
 3122     OPT_klog,
 3123     OPT_klog_ops,
 3124 
 3125     OPT_l1cache,
 3126     OPT_l1cache_ops,
 3127     OPT_l1cache_line_size,
 3128     OPT_l1cache_size,
 3129     OPT_l1cache_sets,
 3130     OPT_l1cache_ways,
 3131 
 3132     OPT_landlock,
 3133     OPT_landlock_ops,
 3134 
 3135     OPT_lease,
 3136     OPT_lease_ops,
 3137     OPT_lease_breakers,
 3138 
 3139     OPT_link,
 3140     OPT_link_ops,
 3141 
 3142     OPT_list,
 3143     OPT_list_ops,
 3144     OPT_list_method,
 3145     OPT_list_size,
 3146 
 3147     OPT_loadavg,
 3148     OPT_loadavg_ops,
 3149 
 3150     OPT_lockbus,
 3151     OPT_lockbus_ops,
 3152 
 3153     OPT_locka,
 3154     OPT_locka_ops,
 3155 
 3156     OPT_lockf,
 3157     OPT_lockf_ops,
 3158     OPT_lockf_nonblock,
 3159 
 3160     OPT_lockofd,
 3161     OPT_lockofd_ops,
 3162 
 3163     OPT_log_brief,
 3164     OPT_log_file,
 3165 
 3166     OPT_longjmp,
 3167     OPT_longjmp_ops,
 3168 
 3169     OPT_loop,
 3170     OPT_loop_ops,
 3171 
 3172     OPT_lsearch,
 3173     OPT_lsearch_ops,
 3174     OPT_lsearch_size,
 3175 
 3176     OPT_madvise,
 3177     OPT_madvise_ops,
 3178 
 3179     OPT_malloc,
 3180     OPT_malloc_ops,
 3181     OPT_malloc_bytes,
 3182     OPT_malloc_max,
 3183     OPT_malloc_pthreads,
 3184     OPT_malloc_threshold,
 3185     OPT_malloc_touch,
 3186 
 3187     OPT_matrix,
 3188     OPT_matrix_ops,
 3189     OPT_matrix_size,
 3190     OPT_matrix_method,
 3191     OPT_matrix_yx,
 3192 
 3193     OPT_matrix_3d,
 3194     OPT_matrix_3d_ops,
 3195     OPT_matrix_3d_size,
 3196     OPT_matrix_3d_method,
 3197     OPT_matrix_3d_zyx,
 3198 
 3199     OPT_maximize,
 3200     OPT_max_fd,
 3201 
 3202     OPT_mcontend,
 3203     OPT_mcontend_ops,
 3204 
 3205     OPT_membarrier,
 3206     OPT_membarrier_ops,
 3207 
 3208     OPT_memcpy,
 3209     OPT_memcpy_ops,
 3210     OPT_memcpy_method,
 3211 
 3212     OPT_memfd,
 3213     OPT_memfd_ops,
 3214     OPT_memfd_bytes,
 3215     OPT_memfd_fds,
 3216 
 3217     OPT_memhotplug,
 3218     OPT_memhotplug_ops,
 3219 
 3220     OPT_memrate,
 3221     OPT_memrate_ops,
 3222     OPT_memrate_rd_mbs,
 3223     OPT_memrate_wr_mbs,
 3224     OPT_memrate_bytes,
 3225 
 3226     OPT_memthrash,
 3227     OPT_memthrash_ops,
 3228     OPT_memthrash_method,
 3229 
 3230     OPT_mergesort,
 3231     OPT_mergesort_ops,
 3232     OPT_mergesort_integers,
 3233 
 3234     OPT_metrics_brief,
 3235 
 3236     OPT_mincore,
 3237     OPT_mincore_ops,
 3238     OPT_mincore_rand,
 3239 
 3240     OPT_misaligned,
 3241     OPT_misaligned_ops,
 3242     OPT_misaligned_method,
 3243 
 3244     OPT_mknod,
 3245     OPT_mknod_ops,
 3246 
 3247     OPT_minimize,
 3248 
 3249     OPT_mlock,
 3250     OPT_mlock_ops,
 3251 
 3252     OPT_mlockmany,
 3253     OPT_mlockmany_ops,
 3254     OPT_mlockmany_procs,
 3255 
 3256     OPT_mmap,
 3257     OPT_mmap_ops,
 3258     OPT_mmap_bytes,
 3259     OPT_mmap_file,
 3260     OPT_mmap_async,
 3261     OPT_mmap_mprotect,
 3262     OPT_mmap_osync,
 3263     OPT_mmap_odirect,
 3264     OPT_mmap_mmap2,
 3265 
 3266     OPT_mmapaddr,
 3267     OPT_mmapaddr_ops,
 3268 
 3269     OPT_mmapfixed,
 3270     OPT_mmapfixed_ops,
 3271 
 3272     OPT_mmapfork,
 3273     OPT_mmapfork_ops,
 3274 
 3275     OPT_mmaphuge,
 3276     OPT_mmaphuge_ops,
 3277     OPT_mmaphuge_mmaps,
 3278 
 3279     OPT_mmapmany,
 3280     OPT_mmapmany_ops,
 3281 
 3282     OPT_mq,
 3283     OPT_mq_ops,
 3284     OPT_mq_size,
 3285 
 3286     OPT_mremap,
 3287     OPT_mremap_ops,
 3288     OPT_mremap_bytes,
 3289     OPT_mremap_mlock,
 3290 
 3291     OPT_msg,
 3292     OPT_msg_ops,
 3293     OPT_msg_types,
 3294 
 3295     OPT_msync,
 3296     OPT_msync_bytes,
 3297     OPT_msync_ops,
 3298 
 3299     OPT_munmap,
 3300     OPT_munmap_ops,
 3301 
 3302     OPT_nanosleep,
 3303     OPT_nanosleep_ops,
 3304 
 3305     OPT_netdev,
 3306     OPT_netdev_ops,
 3307 
 3308     OPT_netlink_proc,
 3309     OPT_netlink_proc_ops,
 3310 
 3311     OPT_netlink_task,
 3312     OPT_netlink_task_ops,
 3313 
 3314     OPT_nice,
 3315     OPT_nice_ops,
 3316 
 3317     OPT_no_madvise,
 3318     OPT_no_oom_adjust,
 3319     OPT_no_rand_seed,
 3320 
 3321     OPT_nop,
 3322     OPT_nop_ops,
 3323     OPT_nop_instr,
 3324 
 3325     OPT_null,
 3326     OPT_null_ops,
 3327 
 3328     OPT_numa,
 3329     OPT_numa_ops,
 3330 
 3331     OPT_oomable,
 3332 
 3333     OPT_oom_pipe,
 3334     OPT_oom_pipe_ops,
 3335 
 3336     OPT_opcode,
 3337     OPT_opcode_ops,
 3338     OPT_opcode_method,
 3339 
 3340     OPT_open_ops,
 3341     OPT_open_fd,
 3342 
 3343     OPT_page_in,
 3344     OPT_pathological,
 3345 
 3346     OPT_pci,
 3347     OPT_pci_ops,
 3348 
 3349     OPT_perf_stats,
 3350 
 3351     OPT_personality,
 3352     OPT_personality_ops,
 3353 
 3354     OPT_physpage,
 3355     OPT_physpage_ops,
 3356 
 3357     OPT_pidfd,
 3358     OPT_pidfd_ops,
 3359 
 3360     OPT_ping_sock,
 3361     OPT_ping_sock_ops,
 3362 
 3363     OPT_pipe_ops,
 3364     OPT_pipe_size,
 3365     OPT_pipe_data_size,
 3366 
 3367     OPT_pipeherd,
 3368     OPT_pipeherd_ops,
 3369     OPT_pipeherd_yield,
 3370 
 3371     OPT_pkey,
 3372     OPT_pkey_ops,
 3373 
 3374     OPT_poll_ops,
 3375     OPT_poll_fds,
 3376 
 3377     OPT_prefetch,
 3378     OPT_prefetch_ops,
 3379     OPT_prefetch_l3_size,
 3380 
 3381     OPT_prctl,
 3382     OPT_prctl_ops,
 3383 
 3384     OPT_procfs,
 3385     OPT_procfs_ops,
 3386 
 3387     OPT_pthread,
 3388     OPT_pthread_ops,
 3389     OPT_pthread_max,
 3390 
 3391     OPT_ptrace,
 3392     OPT_ptrace_ops,
 3393 
 3394     OPT_pty,
 3395     OPT_pty_ops,
 3396     OPT_pty_max,
 3397 
 3398     OPT_qsort,
 3399     OPT_qsort_ops,
 3400     OPT_qsort_integers,
 3401 
 3402     OPT_quota,
 3403     OPT_quota_ops,
 3404 
 3405     OPT_radixsort,
 3406     OPT_radixsort_ops,
 3407     OPT_radixsort_size,
 3408 
 3409     OPT_ramfs,
 3410     OPT_ramfs_ops,
 3411     OPT_ramfs_size,
 3412 
 3413     OPT_rawdev,
 3414     OPT_rawdev_method,
 3415     OPT_rawdev_ops,
 3416 
 3417     OPT_rawpkt,
 3418     OPT_rawpkt_ops,
 3419     OPT_rawpkt_port,
 3420 
 3421     OPT_rawsock,
 3422     OPT_rawsock_ops,
 3423 
 3424     OPT_rawudp,
 3425     OPT_rawudp_ops,
 3426     OPT_rawudp_port,
 3427 
 3428     OPT_rdrand,
 3429     OPT_rdrand_ops,
 3430 
 3431     OPT_readahead,
 3432     OPT_readahead_ops,
 3433     OPT_readahead_bytes,
 3434 
 3435     OPT_reboot,
 3436     OPT_reboot_ops,
 3437 
 3438     OPT_remap,
 3439     OPT_remap_ops,
 3440 
 3441     OPT_rename_ops,
 3442 
 3443     OPT_resources,
 3444     OPT_resources_ops,
 3445 
 3446     OPT_revio,
 3447     OPT_revio_ops,
 3448     OPT_revio_opts,
 3449     OPT_revio_bytes,
 3450 
 3451     OPT_rlimit,
 3452     OPT_rlimit_ops,
 3453 
 3454     OPT_rmap,
 3455     OPT_rmap_ops,
 3456 
 3457     OPT_rseq,
 3458     OPT_rseq_ops,
 3459 
 3460     OPT_rtc,
 3461     OPT_rtc_ops,
 3462 
 3463     OPT_sched,
 3464     OPT_sched_prio,
 3465 
 3466     OPT_schedpolicy,
 3467     OPT_schedpolicy_ops,
 3468 
 3469     OPT_sched_period,
 3470     OPT_sched_runtime,
 3471     OPT_sched_deadline,
 3472     OPT_sched_reclaim,
 3473 
 3474     OPT_sctp,
 3475     OPT_sctp_ops,
 3476     OPT_sctp_domain,
 3477     OPT_sctp_port,
 3478 
 3479     OPT_seal,
 3480     OPT_seal_ops,
 3481 
 3482     OPT_seccomp,
 3483     OPT_seccomp_ops,
 3484 
 3485     OPT_secretmem,
 3486     OPT_secretmem_ops,
 3487 
 3488     OPT_seed,
 3489 
 3490     OPT_seek,
 3491     OPT_seek_ops,
 3492     OPT_seek_punch,
 3493     OPT_seek_size,
 3494 
 3495     OPT_sendfile,
 3496     OPT_sendfile_ops,
 3497     OPT_sendfile_size,
 3498 
 3499     OPT_sem,
 3500     OPT_sem_ops,
 3501     OPT_sem_procs,
 3502 
 3503     OPT_sem_sysv,
 3504     OPT_sem_sysv_ops,
 3505     OPT_sem_sysv_procs,
 3506 
 3507     OPT_session,
 3508     OPT_session_ops,
 3509 
 3510     OPT_set,
 3511     OPT_set_ops,
 3512 
 3513     OPT_shellsort,
 3514     OPT_shellsort_ops,
 3515     OPT_shellsort_integers,
 3516 
 3517     OPT_shm,
 3518     OPT_shm_ops,
 3519     OPT_shm_bytes,
 3520     OPT_shm_objects,
 3521 
 3522     OPT_shm_sysv,
 3523     OPT_shm_sysv_ops,
 3524     OPT_shm_sysv_bytes,
 3525     OPT_shm_sysv_segments,
 3526 
 3527     OPT_sequential,
 3528 
 3529     OPT_sigabrt,
 3530     OPT_sigabrt_ops,
 3531 
 3532     OPT_sigchld,
 3533     OPT_sigchld_ops,
 3534 
 3535     OPT_sigfd,
 3536     OPT_sigfd_ops,
 3537 
 3538     OPT_sigfpe,
 3539     OPT_sigfpe_ops,
 3540 
 3541     OPT_sigio,
 3542     OPT_sigio_ops,
 3543 
 3544     OPT_signal,
 3545     OPT_signal_ops,
 3546 
 3547     OPT_signest,
 3548     OPT_signest_ops,
 3549 
 3550     OPT_sigpending,
 3551     OPT_sigpending_ops,
 3552 
 3553     OPT_sigpipe,
 3554     OPT_sigpipe_ops,
 3555 
 3556     OPT_sigq,
 3557     OPT_sigq_ops,
 3558 
 3559     OPT_sigrt,
 3560     OPT_sigrt_ops,
 3561 
 3562     OPT_sigsegv,
 3563     OPT_sigsegv_ops,
 3564 
 3565     OPT_sigsuspend,
 3566     OPT_sigsuspend_ops,
 3567 
 3568     OPT_sigtrap,
 3569     OPT_sigtrap_ops,
 3570 
 3571     OPT_skiplist,
 3572     OPT_skiplist_ops,
 3573     OPT_skiplist_size,
 3574 
 3575     OPT_skip_silent,
 3576 
 3577     OPT_sleep,
 3578     OPT_sleep_ops,
 3579     OPT_sleep_max,
 3580 
 3581     OPT_smart,
 3582 
 3583     OPT_smi,
 3584     OPT_smi_ops,
 3585 
 3586     OPT_sock_ops,
 3587     OPT_sock_domain,
 3588     OPT_sock_nodelay,
 3589     OPT_sock_opts,
 3590     OPT_sock_port,
 3591     OPT_sock_protocol,
 3592     OPT_sock_type,
 3593     OPT_sock_zerocopy,
 3594 
 3595     OPT_sockabuse,
 3596     OPT_sockabuse_ops,
 3597 
 3598     OPT_sockdiag,
 3599     OPT_sockdiag_ops,
 3600 
 3601     OPT_sockfd,
 3602     OPT_sockfd_ops,
 3603     OPT_sockfd_port,
 3604 
 3605     OPT_sockmany,
 3606     OPT_sockmany_ops,
 3607 
 3608     OPT_sockpair,
 3609     OPT_sockpair_ops,
 3610 
 3611     OPT_softlockup,
 3612     OPT_softlockup_ops,
 3613 
 3614     OPT_swap,
 3615     OPT_swap_ops,
 3616 
 3617     OPT_switch_ops,
 3618     OPT_switch_freq,
 3619 
 3620     OPT_spawn,
 3621     OPT_spawn_ops,
 3622 
 3623     OPT_splice,
 3624     OPT_splice_ops,
 3625     OPT_splice_bytes,
 3626 
 3627     OPT_stack,
 3628     OPT_stack_ops,
 3629     OPT_stack_fill,
 3630     OPT_stack_mlock,
 3631 
 3632     OPT_stackmmap,
 3633     OPT_stackmmap_ops,
 3634 
 3635     OPT_str,
 3636     OPT_str_ops,
 3637     OPT_str_method,
 3638 
 3639     OPT_stream,
 3640     OPT_stream_ops,
 3641     OPT_stream_index,
 3642     OPT_stream_l3_size,
 3643     OPT_stream_madvise,
 3644 
 3645     OPT_stressors,
 3646 
 3647     OPT_symlink,
 3648     OPT_symlink_ops,
 3649 
 3650     OPT_sync_file,
 3651     OPT_sync_file_ops,
 3652     OPT_sync_file_bytes,
 3653 
 3654     OPT_sysbadaddr,
 3655     OPT_sysbadaddr_ops,
 3656 
 3657     OPT_sysinfo,
 3658     OPT_sysinfo_ops,
 3659 
 3660     OPT_sysinval,
 3661     OPT_sysinval_ops,
 3662 
 3663     OPT_sysfs,
 3664     OPT_sysfs_ops,
 3665 
 3666     OPT_syslog,
 3667 
 3668     OPT_tee,
 3669     OPT_tee_ops,
 3670 
 3671     OPT_taskset,
 3672 
 3673     OPT_temp_path,
 3674 
 3675     OPT_thermalstat,
 3676     OPT_thermal_zones,
 3677 
 3678     OPT_thrash,
 3679 
 3680     OPT_timer_slack,
 3681 
 3682     OPT_timer_ops,
 3683     OPT_timer_freq,
 3684     OPT_timer_rand,
 3685 
 3686     OPT_timerfd,
 3687     OPT_timerfd_ops,
 3688     OPT_timerfd_fds,
 3689     OPT_timerfd_freq,
 3690     OPT_timerfd_rand,
 3691 
 3692     OPT_times,
 3693 
 3694     OPT_timestamp,
 3695 
 3696     OPT_tlb_shootdown,
 3697     OPT_tlb_shootdown_ops,
 3698 
 3699     OPT_tmpfs,
 3700     OPT_tmpfs_ops,
 3701     OPT_tmpfs_mmap_async,
 3702     OPT_tmpfs_mmap_file,
 3703 
 3704     OPT_tree,
 3705     OPT_tree_ops,
 3706     OPT_tree_method,
 3707     OPT_tree_size,
 3708 
 3709     OPT_tsc,
 3710     OPT_tsc_ops,
 3711 
 3712     OPT_tsearch,
 3713     OPT_tsearch_ops,
 3714     OPT_tsearch_size,
 3715 
 3716     OPT_tun,
 3717     OPT_tun_ops,
 3718     OPT_tun_tap,
 3719 
 3720     OPT_udp,
 3721     OPT_udp_ops,
 3722     OPT_udp_port,
 3723     OPT_udp_domain,
 3724     OPT_udp_lite,
 3725 
 3726     OPT_udp_flood,
 3727     OPT_udp_flood_ops,
 3728     OPT_udp_flood_domain,
 3729 
 3730     OPT_unshare,
 3731     OPT_unshare_ops,
 3732 
 3733     OPT_uprobe,
 3734     OPT_uprobe_ops,
 3735 
 3736     OPT_urandom_ops,
 3737 
 3738     OPT_userfaultfd,
 3739     OPT_userfaultfd_ops,
 3740     OPT_userfaultfd_bytes,
 3741 
 3742     OPT_utime,
 3743     OPT_utime_ops,
 3744     OPT_utime_fsync,
 3745 
 3746     OPT_vdso,
 3747     OPT_vdso_ops,
 3748     OPT_vdso_func,
 3749 
 3750     OPT_vecmath,
 3751     OPT_vecmath_ops,
 3752 
 3753     OPT_verify,
 3754 
 3755     OPT_verity,
 3756     OPT_verity_ops,
 3757 
 3758     OPT_vfork,
 3759     OPT_vfork_ops,
 3760     OPT_vfork_max,
 3761     OPT_vfork_vm,
 3762 
 3763     OPT_vforkmany,
 3764     OPT_vforkmany_ops,
 3765     OPT_vforkmany_vm,
 3766 
 3767     OPT_vm_bytes,
 3768     OPT_vm_hang,
 3769     OPT_vm_keep,
 3770     OPT_vm_mmap_populate,
 3771     OPT_vm_mmap_locked,
 3772     OPT_vm_ops,
 3773     OPT_vm_madvise,
 3774     OPT_vm_method,
 3775 
 3776     OPT_vm_addr,
 3777     OPT_vm_addr_method,
 3778     OPT_vm_addr_ops,
 3779 
 3780     OPT_vm_rw,
 3781     OPT_vm_rw_ops,
 3782     OPT_vm_rw_bytes,
 3783 
 3784     OPT_vm_segv,
 3785     OPT_vm_segv_ops,
 3786 
 3787     OPT_vm_splice,
 3788     OPT_vm_splice_ops,
 3789     OPT_vm_splice_bytes,
 3790 
 3791     OPT_vmstat,
 3792 
 3793     OPT_wait,
 3794     OPT_wait_ops,
 3795 
 3796     OPT_watchdog,
 3797     OPT_watchdog_ops,
 3798 
 3799     OPT_wcs,
 3800     OPT_wcs_ops,
 3801     OPT_wcs_method,
 3802 
 3803     OPT_x86syscall,
 3804     OPT_x86syscall_ops,
 3805     OPT_x86syscall_func,
 3806 
 3807     OPT_xattr,
 3808     OPT_xattr_ops,
 3809 
 3810     OPT_yield_ops,
 3811 
 3812     OPT_zero,
 3813     OPT_zero_ops,
 3814 
 3815     OPT_zlib,
 3816     OPT_zlib_ops,
 3817     OPT_zlib_level,
 3818     OPT_zlib_mem_level,
 3819     OPT_zlib_method,
 3820     OPT_zlib_window_bits,
 3821     OPT_zlib_stream_bytes,
 3822     OPT_zlib_strategy,
 3823 
 3824     OPT_zombie,
 3825     OPT_zombie_ops,
 3826     OPT_zombie_max,
 3827 } stress_op_t;
 3828 
 3829 /* stress test metadata */
 3830 typedef struct {
 3831     const stressor_info_t *info;    /* stress test info */
 3832     const stress_id_t id;       /* stress test ID */
 3833     const short int short_getopt;   /* getopt short option */
 3834     const stress_op_t op;       /* ops option */
 3835     const char *name;       /* name of stress test */
 3836 } stress_t;
 3837 
 3838 /* Per stressor information */
 3839 typedef struct stress_stressor_info {
 3840     struct stress_stressor_info *next;  /* next proc info struct in list */
 3841     struct stress_stressor_info *prev;  /* prev proc info struct in list */
 3842     const stress_t *stressor;   /* stressor */
 3843     pid_t   *pids;          /* stressor process id */
 3844     stress_stats_t **stats;     /* stressor stats info */
 3845     int32_t started_instances;  /* count of started instances */
 3846     int32_t num_instances;      /* number of instances per stressor */
 3847     uint64_t bogo_ops;      /* number of bogo ops */
 3848 } stress_stressor_t;
 3849 
 3850 /* Pointer to current running stressor proc info */
 3851 extern stress_stressor_t *g_stressor_current;
 3852 
 3853 /* Scale lookup mapping, suffix -> scale by */
 3854 typedef struct {
 3855     const char  ch;     /* Scaling suffix */
 3856     const uint64_t  scale;      /* Amount to scale by */
 3857 } stress_scale_t;
 3858 
 3859 /* Cache types */
 3860 typedef enum stress_cache_type {
 3861     CACHE_TYPE_UNKNOWN = 0,     /* Unknown type */
 3862     CACHE_TYPE_DATA,        /* D$ */
 3863     CACHE_TYPE_INSTRUCTION,     /* I$ */
 3864     CACHE_TYPE_UNIFIED,     /* D$ + I$ */
 3865 } stress_cache_type_t;
 3866 
 3867 /* CPU cache information */
 3868 typedef struct stress_cpu_cache {
 3869     uint64_t           size;        /* cache size in bytes */
 3870     uint32_t           line_size;   /* cache line size in bytes */
 3871     uint32_t           ways;    /* cache ways */
 3872     stress_cache_type_t type;   /* cache type */
 3873     uint16_t           level;   /* cache level, L1, L2 etc */
 3874 } stress_cpu_cache_t;
 3875 
 3876 typedef struct stress_cpu {
 3877     stress_cpu_cache_t *caches; /* CPU cache data */
 3878     uint32_t       num;     /* CPU # number */
 3879     uint32_t       cache_count; /* CPU cache #  */
 3880     bool           online;      /* CPU online when true */
 3881 } stress_cpu_t;
 3882 
 3883 typedef struct stress_cpus {
 3884     stress_cpu_t *cpus;     /* CPU data */
 3885     uint32_t   count;       /* CPU count */
 3886 } stress_cpus_t;
 3887 
 3888 /* Various global option settings and flags */
 3889 extern const char *g_app_name;      /* Name of application */
 3890 extern stress_shared_t *g_shared;   /* shared memory */
 3891 extern uint64_t g_opt_timeout;      /* timeout in seconds */
 3892 extern uint64_t g_opt_flags;        /* option flags */
 3893 extern int32_t g_opt_sequential;    /* Number of sequential stressors */
 3894 extern int32_t g_opt_parallel;      /* Number of parallel stressors */
 3895 extern volatile bool g_keep_stressing_flag; /* false to exit stressor */
 3896 extern volatile bool g_caught_sigint;   /* true if stopped by SIGINT */
 3897 extern pid_t g_pgrp;            /* proceess group leader */
 3898 extern jmp_buf g_error_env;     /* parsing error env */
 3899 extern stress_put_val_t g_put_val;  /* sync data to somewhere */
 3900 
 3901 static inline bool ALWAYS_INLINE OPTIMIZE3 keep_stressing_flag(void)
 3902 {
 3903     return g_keep_stressing_flag;
 3904 }
 3905 
 3906 static inline void OPTIMIZE3 keep_stressing_set_flag(const bool setting)
 3907 {
 3908     g_keep_stressing_flag = setting;
 3909 }
 3910 
 3911 /*
 3912  *  keep_stressing()
 3913  *      returns true if we can keep on running a stressor
 3914  */
 3915 static inline bool OPTIMIZE3 keep_stressing(const stress_args_t *args)
 3916 {
 3917     return (LIKELY(g_keep_stressing_flag) &&
 3918         LIKELY(!args->max_ops || (get_counter(args) < args->max_ops)));
 3919 }
 3920 
 3921 /*
 3922  *  stressor option value handling
 3923  */
 3924 extern int stress_set_setting(const char *name, const stress_type_id_t type_id,
 3925     const void *value);
 3926 extern int stress_set_setting_global(const char *name, const stress_type_id_t type_id,
 3927     const void *value);
 3928 extern bool stress_get_setting(const char *name, void *value);
 3929 extern void stress_settings_free(void);
 3930 
 3931 /*
 3932  *  externs to force gcc to stash computed values and hence
 3933  *  to stop the optimiser optimising code away to zero. The
 3934  *  *_put funcs are essentially no-op functions.
 3935  */
 3936 extern uint64_t stress_uint64_zero(void);
 3937 
 3938 /*
 3939  *  uint8_put()
 3940  *  stash a uint8_t value
 3941  */
 3942 static inline void ALWAYS_INLINE stress_uint8_put(const uint8_t a)
 3943 {
 3944     g_put_val.uint8_val = a;
 3945 }
 3946 
 3947 /*
 3948  *  uint16_put()
 3949  *  stash a uint16_t value
 3950  */
 3951 static inline void ALWAYS_INLINE stress_uint16_put(const uint16_t a)
 3952 {
 3953     g_put_val.uint16_val = a;
 3954 }
 3955 
 3956 /*
 3957  *  stress_uint32_put()
 3958  *  stash a uint32_t value
 3959  */
 3960 static inline void ALWAYS_INLINE stress_uint32_put(const uint32_t a)
 3961 {
 3962     g_put_val.uint32_val = a;
 3963 }
 3964 
 3965 /*
 3966  *  stress_uint64_put()
 3967  *  stash a uint64_t value
 3968  */
 3969 static inline void ALWAYS_INLINE stress_uint64_put(const uint64_t a)
 3970 {
 3971     g_put_val.uint64_val = a;
 3972 }
 3973 
 3974 #if defined(HAVE_INT128_T)
 3975 /*
 3976  *  stress_uint128_put()
 3977  *  stash a uint128_t value
 3978  */
 3979 static inline void ALWAYS_INLINE stress_uint128_put(const __uint128_t a)
 3980 {
 3981     g_put_val.uint128_val = a;
 3982 }
 3983 #endif
 3984 
 3985 /*
 3986  *  stress_float_put()
 3987  *  stash a float value
 3988  */
 3989 static inline void ALWAYS_INLINE stress_float_put(const float a)
 3990 {
 3991     g_put_val.float_val = a;
 3992 }
 3993 
 3994 /*
 3995  *  stress_double_put()
 3996  *  stash a double value
 3997  */
 3998 static inline void ALWAYS_INLINE stress_double_put(const double a)
 3999 {
 4000     g_put_val.double_val = a;
 4001 }
 4002 
 4003 /*
 4004  *  stress_long_double_put()
 4005  *  stash a double value
 4006  */
 4007 static inline void ALWAYS_INLINE stress_long_double_put(const long double a)
 4008 {
 4009     g_put_val.long_double_val = a;
 4010 }
 4011 
 4012 /*
 4013  *  stress_void_ptr_put()
 4014  *  stash a void * pointer value
 4015  */
 4016 static inline void ALWAYS_INLINE stress_void_ptr_put(volatile void * const a)
 4017 {
 4018     g_put_val.void_ptr_val = a;
 4019 }
 4020 
 4021 /* Filenames and directories */
 4022 extern int stress_temp_filename(char *path, const size_t len,
 4023     const char *name, const pid_t pid, const uint32_t instance,
 4024     const uint64_t magic);
 4025 extern int stress_temp_filename_args(const stress_args_t *args, char *path,
 4026     const size_t len, const uint64_t magic);
 4027 extern int stress_temp_dir(char *path, const size_t len,
 4028     const char *name, const pid_t pid, const uint32_t instance);
 4029 extern int stress_temp_dir_args(const stress_args_t *args, char *path,
 4030     const size_t len);
 4031 extern WARN_UNUSED int stress_temp_dir_mk(const char *name, const pid_t pid,
 4032     const uint32_t instance);
 4033 extern WARN_UNUSED int stress_temp_dir_mk_args(const stress_args_t *args);
 4034 extern int stress_temp_dir_rm(const char *name, const pid_t pid,
 4035     const uint32_t instance);
 4036 extern int stress_temp_dir_rm_args(const stress_args_t *args);
 4037 extern void stress_cwd_readwriteable(void);
 4038 
 4039 extern const char *stress_signal_name(const int signum);
 4040 extern const char *stress_strsignal(const int signum);
 4041 
 4042 #if defined(STRESS_ARCH_X86)
 4043 /*
 4044  *  shim_clflush()
 4045  *  flush a cache line
 4046  */
 4047 static inline void ALWAYS_INLINE shim_clflush(volatile void *ptr)
 4048 {
 4049     asm volatile("clflush %0" : "+m" (*(volatile char *)ptr));
 4050 }
 4051 #else
 4052 #define shim_clflush(ptr)   do { } while (0) /* No-op */
 4053 #endif
 4054 
 4055 /*
 4056  *  shim_mfence()
 4057  *  serializing memory fence
 4058  */
 4059 static inline void ALWAYS_INLINE shim_mfence(void)
 4060 {
 4061 #if NEED_GNUC(4, 2, 0) &&   \
 4062     !defined(__PCC__)
 4063     __sync_synchronize();
 4064 #else
 4065 #if defined(STRESS_ARCH_X86)
 4066     asm volatile("mfence" : : : "memory");
 4067 #else
 4068     /* Other arches not yet implemented for older GCC flavours */
 4069 #endif
 4070 #endif
 4071 }
 4072 
 4073 /* Fast random numbers */
 4074 extern uint32_t stress_mwc32(void);
 4075 extern uint64_t stress_mwc64(void);
 4076 extern uint16_t stress_mwc16(void);
 4077 extern uint8_t stress_mwc8(void);
 4078 extern uint8_t stress_mwc1(void);
 4079 extern void stress_mwc_seed(const uint32_t w, const uint32_t z);
 4080 extern void stress_mwc_reseed(void);
 4081 
 4082 /* Time handling */
 4083 extern WARN_UNUSED double stress_timeval_to_double(const struct timeval *tv);
 4084 extern WARN_UNUSED double stress_time_now(void);
 4085 extern const char *stress_duration_to_str(const double duration);
 4086 
 4087 /* Perf statistics */
 4088 #if defined(STRESS_PERF_STATS)
 4089 extern int stress_perf_open(stress_perf_t *sp);
 4090 extern int stress_perf_enable(stress_perf_t *sp);
 4091 extern int stress_perf_disable(stress_perf_t *sp);
 4092 extern int stress_perf_close(stress_perf_t *sp);
 4093 extern bool stress_perf_stat_succeeded(const stress_perf_t *sp);
 4094 extern void stress_perf_stat_dump(FILE *yaml, stress_stressor_t *procs_head,
 4095     const double duration);
 4096 extern void stress_perf_init(void);
 4097 #endif
 4098 
 4099 /* CPU helpers */
 4100 extern WARN_UNUSED bool stress_cpu_is_x86(void);
 4101 
 4102 typedef int stress_oomable_child_func_t(const stress_args_t *args, void *context);
 4103 
 4104 #define STRESS_OOMABLE_NORMAL   (0x00000000)        /* Normal oomability */
 4105 #define STRESS_OOMABLE_DROP_CAP (0x00000001)        /* Drop capabilities */
 4106 #define STRESS_OOMABLE_QUIET    (0x00000002)        /* Don't report activity */
 4107 
 4108 /* Misc helpers */
 4109 extern size_t stress_mk_filename(char *fullname, const size_t fullname_len,
 4110     const char *pathname, const char *filename);
 4111 extern void stress_set_oom_adjustment(const char *name, const bool killable);
 4112 extern WARN_UNUSED bool stress_process_oomed(const pid_t pid);
 4113 extern WARN_UNUSED int stress_oomable_child(const stress_args_t *args,
 4114     void *context, stress_oomable_child_func_t func, const int flag);
 4115 extern WARN_UNUSED int stress_set_sched(const pid_t pid, const int sched,
 4116     const int sched_priority, const bool quiet);
 4117 extern WARN_UNUSED int stress_set_deadline_sched(const pid_t, const uint64_t period,
 4118     const uint64_t runtime, const uint64_t deadline, const bool quiet);
 4119 extern int sched_settings_apply(const bool quiet);
 4120 extern const char *stress_get_sched_name(const int sched);
 4121 extern void stress_set_iopriority(const int32_t class, const int32_t level);
 4122 extern void stress_set_proc_name_init(int argc, char *argv[], char *envp[]);
 4123 extern void stress_set_proc_name(const char *name);
 4124 extern void stress_set_proc_state(const char *name, const int state);
 4125 extern WARN_UNUSED int stress_get_unused_uid(uid_t *uid);
 4126 extern void NORETURN MLOCKED_TEXT stress_sig_handler_exit(int signum);
 4127 
 4128 /* Memory locking */
 4129 extern int stress_mlock_region(const void *addr_start, const void *addr_end);
 4130 
 4131 /* Argument parsing and range checking */
 4132 extern WARN_UNUSED uint64_t stress_get_uint64(const char *const str);
 4133 extern WARN_UNUSED uint64_t stress_get_uint64_scale(const char *const str,
 4134     const stress_scale_t scales[], const char *const msg);
 4135 extern WARN_UNUSED uint64_t stress_get_uint64_percent(const char *const str,
 4136     const uint32_t instances, const uint64_t max, const char *const errmsg);
 4137 extern WARN_UNUSED uint64_t stress_get_uint64_byte(const char *const str);
 4138 extern WARN_UNUSED uint64_t stress_get_uint64_byte_memory(
 4139     const char *const str, const uint32_t instances);
 4140 extern WARN_UNUSED uint64_t stress_get_uint64_byte_filesystem(
 4141     const char *const str, const uint32_t instances);
 4142 extern WARN_UNUSED uint64_t stress_get_uint64_time(const char *const str);
 4143 extern void stress_check_value(const char *const msg, const int val);
 4144 extern void stress_check_range(const char *const opt, const uint64_t val,
 4145     const uint64_t lo, const uint64_t hi);
 4146 extern void stress_check_range_bytes(const char *const opt,
 4147     const uint64_t val, const uint64_t lo, const uint64_t hi);
 4148 extern WARN_UNUSED int stress_set_cpu_affinity(const char *arg);
 4149 extern WARN_UNUSED uint32_t stress_get_uint32(const char *const str);
 4150 extern WARN_UNUSED int32_t  stress_get_int32(const char *const str);
 4151 extern WARN_UNUSED int32_t  stress_get_opt_sched(const char *const str);
 4152 extern WARN_UNUSED int32_t  stress_get_opt_ionice_class(const char *const str);
 4153 
 4154 /* Misc helper funcs */
 4155 extern WARN_UNUSED size_t stress_sig_stack_size(void);
 4156 extern WARN_UNUSED size_t stress_min_sig_stack_size(void);
 4157 extern WARN_UNUSED size_t stress_min_pthread_stack_size(void);
 4158 
 4159 #define STRESS_SIGSTKSZ     (stress_sig_stack_size())
 4160 #define STRESS_MINSIGSTKSZ  (stress_min_sig_stack_size())
 4161 
 4162 extern void stress_shared_unmap(void);
 4163 extern void stress_log_system_mem_info(void);
 4164 extern WARN_UNUSED char *stress_munge_underscore(const char *str);
 4165 extern size_t stress_get_pagesize(void);
 4166 extern WARN_UNUSED int32_t stress_get_processors_online(void);
 4167 extern WARN_UNUSED int32_t stress_get_processors_configured(void);
 4168 extern WARN_UNUSED int32_t stress_get_ticks_per_second(void);
 4169 extern WARN_UNUSED ssize_t stress_get_stack_direction(void);
 4170 extern WARN_UNUSED void *stress_get_stack_top(void *start, size_t size);
 4171 extern void stress_get_memlimits(size_t *shmall, size_t *freemem,
 4172     size_t *totalmem, size_t *freeswap);
 4173 extern WARN_UNUSED int stress_get_load_avg(double *min1, double *min5,
 4174     double *min15);
 4175 extern void stress_set_max_limits(void);
 4176 extern void stress_parent_died_alarm(void);
 4177 extern int stress_process_dumpable(const bool dumpable);
 4178 extern int stress_set_timer_slack_ns(const char *opt);
 4179 extern void stress_set_timer_slack(void);
 4180 extern WARN_UNUSED int stress_set_temp_path(const char *path);
 4181 extern WARN_UNUSED const char *stress_get_temp_path(void);
 4182 extern void stress_temp_path_free(void);
 4183 extern void stress_strnrnd(char *str, const size_t len);
 4184 extern void stress_get_cache_size(uint64_t *l2, uint64_t *l3);
 4185 extern WARN_UNUSED unsigned int stress_get_cpu(void);
 4186 extern WARN_UNUSED const char *stress_get_compiler(void);
 4187 extern WARN_UNUSED const char *stress_get_uname_info(void);
 4188 extern WARN_UNUSED int stress_cache_alloc(const char *name);
 4189 extern void stress_cache_free(void);
 4190 extern void stress_ignite_cpu_start(void);
 4191 extern void stress_ignite_cpu_stop(void);
 4192 extern ssize_t system_write(const char *path, const char *buf, const size_t buf_len);
 4193 extern WARN_UNUSED int stress_set_nonblock(const int fd);
 4194 extern WARN_UNUSED ssize_t system_read(const char *path, char *buf,
 4195     const size_t buf_len);
 4196 extern WARN_UNUSED bool stress_is_prime64(const uint64_t n);
 4197 extern WARN_UNUSED uint64_t stress_get_prime64(const uint64_t n);
 4198 extern WARN_UNUSED size_t stress_get_file_limit(void);
 4199 extern WARN_UNUSED size_t stress_get_max_file_limit(void);
 4200 extern WARN_UNUSED int stress_get_bad_fd(void);
 4201 extern void stress_vmstat_start(void);
 4202 extern void stress_vmstat_stop(void);
 4203 extern WARN_UNUSED int stress_sigaltstack(void *stack, const size_t size);
 4204 extern WARN_UNUSED int stress_sighandler(const char *name, const int signum,
 4205     void (*handler)(int), struct sigaction *orig_action);
 4206 extern int stress_sighandler_default(const int signum);
 4207 extern void stress_handle_stop_stressing(int dummy);
 4208 extern WARN_UNUSED int stress_sig_stop_stressing(const char *name,
 4209     const int sig);
 4210 extern int stress_sigrestore(const char *name, const int signum,
 4211     struct sigaction *orig_action);
 4212 extern WARN_UNUSED int stress_not_implemented(const stress_args_t *args);
 4213 extern WARN_UNUSED size_t stress_probe_max_pipe_size(void);
 4214 extern WARN_UNUSED void *stress_align_address(const void *addr,
 4215     const size_t alignment);
 4216 extern void stress_mmap_set(uint8_t *buf, const size_t sz,
 4217     const size_t page_size);
 4218 extern WARN_UNUSED int stress_mmap_check(uint8_t *buf, const size_t sz,
 4219     const size_t page_size);
 4220 extern WARN_UNUSED uint64_t stress_get_phys_mem_size(void);
 4221 extern WARN_UNUSED uint64_t stress_get_filesystem_size(void);
 4222 extern WARN_UNUSED ssize_t stress_read_buffer(int, void*, ssize_t, bool);
 4223 extern WARN_UNUSED ssize_t stress_write_buffer(int, void*, ssize_t, bool);
 4224 extern WARN_UNUSED uint64_t stress_get_filesystem_available_inodes(void);
 4225 extern WARN_UNUSED int stress_kernel_release(const int major,
 4226     const int minor, const int patchlevel);
 4227 extern WARN_UNUSED int stress_get_kernel_release(void);
 4228 extern char *stress_uint64_to_str(char *str, size_t len, const uint64_t val);
 4229 extern WARN_UNUSED int stress_drop_capabilities(const char *name);
 4230 extern WARN_UNUSED bool stress_is_dot_filename(const char *name);
 4231 extern WARN_UNUSED char *stress_const_optdup(const char *opt);
 4232 extern size_t stress_text_addr(char **start, char **end);
 4233 extern WARN_UNUSED bool stress_check_capability(const int capability);
 4234 extern WARN_UNUSED bool stress_sigalrm_pending(void);
 4235 extern WARN_UNUSED bool stress_is_dev_tty(const int fd);
 4236 extern WARN_UNUSED stress_hash_table_t *stress_hash_create(const size_t n);
 4237 extern stress_hash_t *stress_hash_add(stress_hash_table_t *hash_table,
 4238     const char *str);
 4239 extern WARN_UNUSED stress_hash_t *stress_hash_get(
 4240     stress_hash_table_t *hash_table, const char *str);
 4241 extern void stress_hash_delete(stress_hash_table_t *hash_table);
 4242 extern WARN_UNUSED int stress_try_open(const stress_args_t *args,
 4243     const char *path, const int flags, const unsigned long timeout_ns);
 4244 extern WARN_UNUSED int stress_open_timeout(const char *name,
 4245         const char *path, const int flags, const unsigned long timeout_ns);
 4246 extern WARN_UNUSED uint32_t stress_hash_jenkin(const uint8_t *data,
 4247     const size_t len);
 4248 extern WARN_UNUSED uint32_t stress_hash_pjw(const char *str);
 4249 extern WARN_UNUSED uint32_t stress_hash_djb2a(const char *str);
 4250 extern WARN_UNUSED uint32_t stress_hash_fnv1a(const char *str);
 4251 extern WARN_UNUSED uint32_t stress_hash_sdbm(const char *str);
 4252 extern WARN_UNUSED uint32_t stress_hash_nhash(const char *str);
 4253 extern WARN_UNUSED uint32_t stress_hash_murmur3_32(const uint8_t* key, size_t len, uint32_t seed);
 4254 extern void stress_dirent_list_free(struct dirent **dlist, const int n);
 4255 extern WARN_UNUSED int stress_dirent_list_prune(struct dirent **dlist, const int n);
 4256 extern WARN_UNUSED uint16_t stress_ipv4_checksum(uint16_t *ptr, const size_t n);
 4257 extern int stress_read_fdinfo(const pid_t pid, const int fd);
 4258 extern WARN_UNUSED pid_t stress_get_unused_pid_racy(const bool fork_test);
 4259 extern WARN_UNUSED size_t stress_hostname_length(void);
 4260 extern WARN_UNUSED int32_t stress_set_vmstat(const char *const str);
 4261 extern WARN_UNUSED int32_t stress_set_thermalstat(const char *const str);
 4262 extern WARN_UNUSED int32_t stress_set_iostat(const char *const str);
 4263 extern void stress_misc_stats_set(stress_misc_stats_t *misc_stats,
 4264     const int idx, const char *description, const double value);
 4265 extern WARN_UNUSED int stress_tty_width(void);
 4266 extern WARN_UNUSED size_t stress_get_extents(const int fd);
 4267 extern WARN_UNUSED bool stress_redo_fork(const int err);
 4268 
 4269 extern void stress_smart_start(void);
 4270 extern void stress_smart_stop(void);
 4271 
 4272 extern int stress_ftrace_start(void);
 4273 extern void stress_ftrace_stop(void);
 4274 extern void stress_ftrace_free(void);
 4275 extern void stress_ftrace_add_pid(const pid_t pid);
 4276 
 4277 extern int stress_module_load(const char *name, const char *alias,
 4278     const char *options, bool *already_loaded);
 4279 extern int stress_module_unload(const char *name, const char *alias,
 4280     const bool already_loaded);
 4281 
 4282 /*
 4283  *  Indicate a stress test failed because of limited resources
 4284  *  rather than a failure of the tests during execution.
 4285  *  err is the errno of the failure.
 4286  */
 4287 static inline WARN_UNUSED ALWAYS_INLINE int exit_status(const int err)
 4288 {
 4289     switch (err) {
 4290     case ENOMEM:
 4291     case ENOSPC:
 4292         return EXIT_NO_RESOURCE;
 4293     case ENOSYS:
 4294         return EXIT_NOT_IMPLEMENTED;
 4295     }
 4296     return EXIT_FAILURE;    /* cppcheck-suppress ConfigurationNotChecked */
 4297 }
 4298 
 4299 /*
 4300  *  Stack aligning for clone() system calls
 4301  *  align to nearest 16 bytes for aarch64 et al,
 4302  *  assumes we have enough slop to do this
 4303  */
 4304 static inline WARN_UNUSED ALWAYS_INLINE void *stress_align_stack(void *stack_top)
 4305 {
 4306     return (void *)((uintptr_t)stack_top & ~(uintptr_t)0xf);
 4307 }
 4308 
 4309 /*
 4310  *  stress_warn_once hashes the current filename and line where
 4311  *  the macro is used and returns true if it's never been called
 4312  *  there before across all threads and child processes
 4313  */
 4314 extern WARN_UNUSED bool stress_warn_once_hash(const char *filename, const int line);
 4315 #define stress_warn_once()  stress_warn_once_hash(__FILE__, __LINE__)
 4316 
 4317 /* Jobfile parsing */
 4318 extern WARN_UNUSED int stress_parse_jobfile(int argc, char **argv,
 4319     const char *jobfile);
 4320 extern WARN_UNUSED int stress_parse_opts(int argc, char **argv,
 4321     const bool jobmode);
 4322 
 4323 /* Memory tweaking */
 4324 extern int stress_madvise_random(void *addr, const size_t length);
 4325 extern void stress_madvise_pid_all_pages(const pid_t pid, const int advise);
 4326 extern int stress_mincore_touch_pages(void *buf, const size_t buf_len);
 4327 extern int stress_mincore_touch_pages_interruptible(void *buf,
 4328     const size_t buf_len);
 4329 
 4330 /* Mounts */
 4331 extern void stress_mount_free(char *mnts[], const int n);
 4332 extern WARN_UNUSED int stress_mount_get(char *mnts[], const int max);
 4333 
 4334 /* Thermal Zones */
 4335 #if defined(STRESS_THERMAL_ZONES)
 4336 extern int stress_tz_init(stress_tz_info_t **tz_info_list);
 4337 extern void stress_tz_free(stress_tz_info_t **tz_info_list);
 4338 extern int stress_tz_get_temperatures(stress_tz_info_t **tz_info_list,
 4339     stress_tz_t *tz);
 4340 extern void stress_tz_dump(FILE *yaml, stress_stressor_t *procs_head);
 4341 #endif
 4342 
 4343 /* Network helpers */
 4344 
 4345 #define NET_ADDR_ANY        (0)
 4346 #define NET_ADDR_LOOPBACK   (1)
 4347 
 4348 extern void stress_set_net_port(const char *optname, const char *opt,
 4349     const int min_port, const int max_port, int *port);
 4350 extern WARN_UNUSED int stress_set_net_domain(const int domain_mask,
 4351     const char *name, const char *domain_name, int *domain);
 4352 extern void stress_set_sockaddr(const char *name, const uint32_t instance,
 4353     const pid_t ppid, const int domain, const int port,
 4354     struct sockaddr **sockaddr, socklen_t *len, const int net_addr);
 4355 extern void stress_set_sockaddr_port(const int domain, const int port,
 4356     struct sockaddr *sockaddr);
 4357 
 4358 /* CPU caches */
 4359 extern stress_cpus_t *stress_get_all_cpu_cache_details(void);
 4360 extern uint16_t stress_get_max_cache_level(const stress_cpus_t *cpus);
 4361 extern stress_cpu_cache_t *stress_get_cpu_cache(const stress_cpus_t *cpus,
 4362     const uint16_t cache_level);
 4363 extern void stress_free_cpu_caches(stress_cpus_t *cpus);
 4364 
 4365 /* CPU thrashing start/stop helpers */
 4366 extern int  stress_thrash_start(void);
 4367 extern void stress_thrash_stop(void);
 4368 
 4369 /* Used to set options for specific stressors */
 4370 extern void stress_adjust_pthread_max(const uint64_t max);
 4371 extern void stress_adjust_sleep_max(const uint64_t max);
 4372 
 4373 /* Enable/disable stack smashing error message */
 4374 extern void stress_set_stack_smash_check_flag(const bool flag);
 4375 
 4376 /* loff_t and off64_t porting shims */
 4377 #if defined(HAVE_LOFF_T)
 4378 typedef loff_t      shim_loff_t;
 4379 #elif defined(HAVE_OFF_T)
 4380 typedef off_t       shim_loff_t;
 4381 #else
 4382 typedef long        shim_loff_t;
 4383 #endif
 4384 
 4385 #if defined(HAVE_OFF64_T)
 4386 typedef off64_t     shim_off64_t;
 4387 #else
 4388 typedef uint64_t    shim_off64_t;
 4389 #endif
 4390 
 4391 /* clone3 clone args */
 4392 struct shim_clone_args {
 4393     uint64_t flags;         /* Flags bit mask */
 4394     uint64_t pidfd;         /* (pid_t *) PID fd */
 4395     uint64_t child_tid;     /* (pid_t *) child TID */
 4396     uint64_t parent_tid;        /* (pid_t *) parent TID */
 4397     uint64_t exit_signal;       /* exit signal */
 4398     uint64_t stack;         /* lowest address of stack */
 4399     uint64_t stack_size;        /* size of stack */
 4400     uint64_t tls;           /* tls address */
 4401 };
 4402 
 4403 struct shim_getcpu_cache {
 4404         unsigned long blob[128 / sizeof(long)];
 4405 };
 4406 
 4407 /*
 4408  *  shim'd abstracted system or library calls
 4409  *  that have a layer of OS abstraction
 4410  */
 4411 struct shim_linux_dirent {
 4412     unsigned long   d_ino;      /* Inode number */
 4413     unsigned long   d_off;      /* Offset to next linux_dirent */
 4414     unsigned short  d_reclen;   /* Length of this linux_dirent */
 4415     char        d_name[];   /* Filename (null-terminated) */
 4416 };
 4417 
 4418 /* dirent64 porting shim */
 4419 struct shim_linux_dirent64 {
 4420 #if defined(HAVE_INO64_T)
 4421     ino64_t     d_ino;      /* 64-bit inode number */
 4422 #else
 4423     int64_t     d_ino;      /* 64-bit inode number */
 4424 #endif
 4425     shim_off64_t    d_off;      /* 64-bit offset to next structure */
 4426     unsigned short  d_reclen;   /* Size of this dirent */
 4427     unsigned char   d_type;     /* File type */
 4428     char        d_name[];   /* Filename (null-terminated) */
 4429 };
 4430 
 4431 /* sched_getattr attributes */
 4432 struct shim_sched_attr {
 4433     uint32_t size;          /* size of struct */
 4434     uint32_t sched_policy;      /* policy, SCHED_* */
 4435     uint64_t sched_flags;       /* scheduling flags */
 4436     int32_t  sched_nice;        /* nice value SCHED_OTHER, SCHED_BATCH */
 4437     uint32_t sched_priority;    /* priority SCHED_FIFO, SCHED_RR */
 4438     uint64_t sched_runtime;     /* runtime SCHED_DEADLINE, ns */
 4439     uint64_t sched_deadline;    /* deadline time, ns */
 4440     uint64_t sched_period;      /* period, ns */
 4441     uint32_t sched_util_min;    /* utilization hint, min */
 4442     uint32_t sched_util_max;    /* utilization hint, max */
 4443 };
 4444 
 4445 #if defined(HAVE_TERMIOS_H)
 4446 
 4447 #define HAVE_SHIM_TERMIOS2
 4448 /* shim_speed_t */
 4449 typedef unsigned int shim_speed_t;
 4450 
 4451 /* shim termios2 */
 4452 struct shim_termios2 {
 4453     tcflag_t c_iflag;       /* input mode flags */
 4454     tcflag_t c_oflag;       /* output mode flags */
 4455     tcflag_t c_cflag;       /* control mode flags */
 4456     tcflag_t c_lflag;       /* local mode flags */
 4457     cc_t c_line;            /* line discipline */
 4458     cc_t c_cc[NCCS];        /* control characters */
 4459     shim_speed_t c_ispeed;      /* input speed */
 4460     shim_speed_t c_ospeed;      /* output speed */
 4461 };
 4462 #endif
 4463 
 4464 /* shim'd STATX flags */
 4465 #define SHIM_STATX_TYPE         (0x00000001U)
 4466 #define SHIM_STATX_MODE         (0x00000002U)
 4467 #define SHIM_STATX_NLINK        (0x00000004U)
 4468 #define SHIM_STATX_UID          (0x00000008U)
 4469 #define SHIM_STATX_GID          (0x00000010U)
 4470 #define SHIM_STATX_ATIME        (0x00000020U)
 4471 #define SHIM_STATX_MTIME        (0x00000040U)
 4472 #define SHIM_STATX_CTIME        (0x00000080U)
 4473 #define SHIM_STATX_INO          (0x00000100U)
 4474 #define SHIM_STATX_SIZE         (0x00000200U)
 4475 #define SHIM_STATX_BLOCKS       (0x00000400U)
 4476 #define SHIM_STATX_BASIC_STATS      (0x000007ffU)
 4477 #define SHIM_STATX_BTIME        (0x00000800U)
 4478 #define SHIM_STATX_ALL          (0x00000fffU)
 4479 
 4480 struct shim_statx_timestamp {
 4481     int64_t tv_sec;
 4482     int32_t tv_nsec;
 4483     int32_t __reserved;
 4484 };
 4485 
 4486 /* shim'd statx */
 4487 struct shim_statx {
 4488     uint32_t stx_mask;
 4489     uint32_t stx_blksize;
 4490     uint64_t stx_attributes;
 4491     uint32_t stx_nlink;
 4492     uint32_t stx_uid;
 4493     uint32_t stx_gid;
 4494     uint16_t stx_mode;
 4495     uint16_t __spare0[1];
 4496     uint64_t stx_ino;
 4497     uint64_t stx_size;
 4498     uint64_t stx_blocks;
 4499     uint64_t __spare1[1];
 4500     struct shim_statx_timestamp stx_atime;
 4501     struct shim_statx_timestamp stx_btime;
 4502     struct shim_statx_timestamp stx_ctime;
 4503     struct shim_statx_timestamp stx_mtime;
 4504     uint32_t stx_rdev_major;
 4505     uint32_t stx_rdev_minor;
 4506     uint32_t stx_dev_major;
 4507     uint32_t stx_dev_minor;
 4508     uint64_t __spare2[14];
 4509 };
 4510 
 4511 /* old ustat struct */
 4512 struct shim_ustat {
 4513 #if defined(HAVE_DADDR_T)
 4514     daddr_t f_tfree;
 4515 #else
 4516     long    f_tfree;
 4517 #endif
 4518     ino_t   f_tinode;
 4519     char    f_fname[6];
 4520     char    f_fpack[6];
 4521 };
 4522 
 4523 /* waitid/pidfd shims */
 4524 #if !defined(P_PIDFD)
 4525 #define P_PIDFD     (3)
 4526 #endif
 4527 
 4528 #if defined(HAVE_SYS_TIMEX_H)
 4529 #define shim_timex  timex
 4530 #else
 4531 struct shim_timex {
 4532     char data[128];
 4533 };
 4534 #endif
 4535 
 4536 /* linux/pid.h */
 4537 enum shim_pid_type {
 4538     SHIM_PIDTYPE_PID,
 4539     SHIM_PIDTYPE_TGID,
 4540     SHIM_PIDTYPE_PGID,
 4541     SHIM_PIDTYPE_SID,
 4542     SHIM_PIDTYPE_MAX,
 4543 };
 4544 
 4545 /*
 4546  *  shim_unconstify_ptr()
 4547  *      some older system calls require non-const void *
 4548  *      or caddr_t args, so we need to unconstify them
 4549  */
 4550 #if defined(__sun__)
 4551 static inline void *shim_unconstify_ptr(const void *ptr)
 4552 {
 4553     void *unconst_ptr = (void *)ptr;
 4554 
 4555     return unconst_ptr;
 4556 }
 4557 #else
 4558 #define shim_unconstify_ptr(ptr)        (ptr)
 4559 #endif
 4560 
 4561 extern int shim_arch_prctl(int code, unsigned long addr);
 4562 extern int shim_brk(void *addr);
 4563 extern int shim_cacheflush(char *addr, int nbytes, int cache);
 4564 extern void shim_flush_icache(void *begin, void *end);
 4565 extern int shim_clock_adjtime(clockid_t clk_id, struct shim_timex *tx);
 4566 extern int shim_clock_getres(clockid_t clk_id, struct timespec *res);
 4567 extern int shim_clock_gettime(clockid_t clk_id, struct timespec *tp);
 4568 extern int shim_clock_settime(clockid_t clk_id, struct timespec *tp);
 4569 extern int sys_clone3(struct shim_clone_args *cl_args, size_t size);
 4570 extern int shim_close_range(unsigned int fd, unsigned int max_fd, unsigned int flags);
 4571 extern ssize_t shim_copy_file_range(int fd_in, shim_loff_t *off_in,
 4572     int fd_out, shim_loff_t *off_out, size_t len, unsigned int flags);
 4573 extern int shim_dup3(int oldfd, int newfd, int flags);
 4574 extern int shim_execveat(int dir_fd, const char *pathname, char *const argv[],
 4575     char *const envp[], int flags);
 4576 extern void shim_exit_group(int status);
 4577 extern int shim_fallocate(int fd, int mode, off_t offset, off_t len);
 4578 extern int shim_fdatasync(int fd);
 4579 extern ssize_t shim_fgetxattr(int fd, const char *name, void *value, size_t size);
 4580 extern ssize_t shim_flistxattr(int fd, char *list, size_t size);
 4581 extern int shim_fsconfig(int fd, unsigned int cmd, const char *key,
 4582     const void *value, int aux);
 4583 extern int shim_fsetxattr(int fd, const char *name, const void *value,
 4584     size_t size, int flags);
 4585 extern int shim_fsmount(int fd, unsigned int flags, unsigned int ms_flags);
 4586 extern int shim_fsopen(const char *fsname, unsigned int flags);
 4587 extern int shim_fsync(int fd);
 4588 extern int shim_futex_wait(const void *futex, const int val,
 4589     const struct timespec *timeout);
 4590 extern int shim_futex_wake(const void *futex, const int n);
 4591 extern long shim_getcpu(unsigned *cpu, unsigned *node, void *tcache);
 4592 extern int shim_getdents(unsigned int fd, struct shim_linux_dirent *dirp,
 4593     unsigned int count);
 4594 extern int shim_getdents64(unsigned int fd, struct shim_linux_dirent64 *dirp,
 4595     unsigned int count);
 4596 extern char *shim_getlogin(void);
 4597 extern int shim_get_mempolicy(int *mode, unsigned long *nodemask,
 4598     unsigned long maxnode, void *addr, unsigned long flags);
 4599 extern int shim_getrandom(void *buff, size_t buflen, unsigned int flags);
 4600 extern int shim_getrusage(int who, struct rusage *usage);
 4601 extern int shim_gettid(void);
 4602 extern ssize_t shim_getxattr(const char *path, const char *name,
 4603     void *value, size_t size);
 4604 extern int shim_ioprio_set(int which, int who, int ioprio);
 4605 extern int shim_ioprio_get(int which, int who);
 4606 extern long shim_kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1,
 4607     unsigned long idx2);
 4608 extern int shim_klogctl(int type, char *bufp, int len);
 4609 extern ssize_t shim_lgetxattr(const char *path, const char *name, void *value,
 4610     size_t size);
 4611 extern ssize_t shim_llistxattr(const char *path, char *list, size_t size);
 4612 extern int shim_lsetxattr(const char *path, const char *name,
 4613     const void *value, size_t size, int flags);
 4614 extern ssize_t shim_listxattr(const char *path, char *list, size_t size);
 4615 extern int shim_lookup_dcookie(uint64_t cookie, char *buffer, size_t len);
 4616 extern int shim_lremovexattr(const char *path, const char *name);
 4617 extern int shim_madvise(void *addr, size_t length, int advice);
 4618 extern long shim_mbind(void *addr, unsigned long len,
 4619     int mode, const unsigned long *nodemask,
 4620     unsigned long maxnode, unsigned flags);
 4621 extern int shim_membarrier(int cmd, int flags, int cpu_id);
 4622 extern int shim_memfd_create(const char *name, unsigned int flags);
 4623 extern int shim_memfd_secret(unsigned long flags);
 4624 extern long shim_migrate_pages(int pid, unsigned long maxnode,
 4625     const unsigned long *old_nodes, const unsigned long *new_nodes);
 4626 extern int shim_mincore(void *addr, size_t length, unsigned char *vec);
 4627 extern int shim_mlock(const void *addr, size_t len);
 4628 extern int shim_mlock2(const void *addr, size_t len, int flags);
 4629 extern int shim_mlockall(int flags);
 4630 extern int shim_move_mount(int from_dfd, const char *from_pathname,
 4631     int to_dfd, const char *to_pathname, unsigned int flags);
 4632 extern long shim_move_pages(int pid, unsigned long count,
 4633     void **pages, const int *nodes, int *status, int flags);
 4634 extern int shim_msync(void *addr, size_t length, int flags);
 4635 extern int shim_munlock(const void *addr, size_t len);
 4636 extern int shim_munlockall(void);
 4637 extern int shim_modify_ldt(int func, void *ptr, unsigned long bytecount);
 4638 extern int shim_nanosleep_uint64(uint64_t usec);
 4639 extern int shim_nice(int inc);
 4640 extern time_t shim_time(time_t *tloc);
 4641 extern int shim_gettimeofday(struct timeval *tv, struct timezone *tz);
 4642 extern int shim_pidfd_getfd(int pidfd, int targetfd, unsigned int flags);
 4643 extern int shim_pidfd_open(pid_t pid, unsigned int flags);
 4644 extern int shim_pidfd_send_signal(int pidfd, int sig, siginfo_t *info,
 4645     unsigned int flags);
 4646 extern int shim_pkey_alloc(unsigned long flags, unsigned long access_rights);
 4647 extern int shim_pkey_free(int pkey);
 4648 extern int shim_pkey_mprotect(void *addr, size_t len, int prot, int pkey);
 4649 extern int shim_pkey_get(int pkey);
 4650 extern int shim_pkey_set(int pkey, unsigned int rights);
 4651 extern ssize_t shim_process_madvise(int pidfd, const struct iovec *iovec,
 4652     unsigned long vlen, int advice, unsigned int flags);
 4653 extern int shim_process_mrelease(int pidfd, unsigned int flags);
 4654 extern int shim_quotactl_fd(unsigned int fd, unsigned int cmd, int id, void *addr);
 4655 extern ssize_t shim_readlink(const char *pathname, char *buf, size_t bufsiz);
 4656 extern int shim_reboot(int magic, int magic2, int cmd, void *arg);
 4657 extern int shim_removexattr(const char *path, const char *name);
 4658 extern void *shim_sbrk(intptr_t increment);
 4659 extern int shim_sched_getattr(pid_t pid, struct shim_sched_attr *attr,
 4660     unsigned int size, unsigned int flags);
 4661 extern int shim_sched_setattr(pid_t pid, struct shim_sched_attr *attr,
 4662     unsigned int flags);
 4663 extern long shim_sgetmask(void);
 4664 extern long shim_ssetmask(long newmask);
 4665 extern int shim_stime(const time_t *t);
 4666 extern int shim_sched_yield(void);
 4667 extern int shim_set_mempolicy(int mode, unsigned long *nodemask,
 4668     unsigned long maxnode);
 4669 extern int shim_seccomp(unsigned int operation, unsigned int flags, void *args);
 4670 extern ssize_t shim_statx(int dfd, const char *filename, unsigned int flags,
 4671     unsigned int mask, struct shim_statx *buffer);
 4672 extern int shim_setxattr(const char *path, const char *name, const void *value,
 4673     size_t size, int flags);
 4674 extern size_t shim_strlcat(char *dst, const char *src, size_t len);
 4675 extern size_t shim_strlcpy(char *dst, const char *src, size_t len);
 4676 extern int shim_sync_file_range(int fd, shim_off64_t offset,
 4677     shim_off64_t nbytes, unsigned int flags);
 4678 extern int shim_sysfs(int option, ...);
 4679 extern int shim_tgkill(int tgid, int tid, int sig);
 4680 extern int shim_tkill(int tid, int sig);
 4681 extern int shim_fremovexattr(int fd, const char *name);
 4682 extern int shim_unshare(int flags);
 4683 extern int shim_userfaultfd(int flags);
 4684 extern int shim_usleep(uint64_t usec);
 4685 extern int shim_usleep_interruptible(uint64_t usec);
 4686 extern int shim_ustat(dev_t dev, struct shim_ustat *ubuf);
 4687 extern int shim_vhangup(void);
 4688 extern pid_t shim_waitpid(pid_t pid, int *wstatus, int options);
 4689 extern pid_t shim_wait(int *wstatus);
 4690 extern pid_t shim_wait3(int *wstatus, int options, struct rusage *rusage);
 4691 extern pid_t shim_wait4(pid_t pid, int *wstatus, int options, struct rusage *rusage);
 4692 
 4693 #endif