"Fossies" - the Fresh Open Source Software Archive

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


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

    1 /*
    2  * Copyright (C) 2013-2019 Canonical, Ltd.
    3  *
    4  * This program is free software; you can redistribute it and/or
    5  * modify it under the terms of the GNU General Public License
    6  * as published by the Free Software Foundation; either version 2
    7  * of the License, or (at your option) any later version.
    8  *
    9  * This program is distributed in the hope that it will be useful,
   10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12  * GNU General Public License for more details.
   13  *
   14  * You should have received a copy of the GNU General Public License
   15  * along with this program; if not, write to the Free Software
   16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
   17  *
   18  * This code is a complete clean re-write of the stress tool by
   19  * Colin Ian King <colin.king@canonical.com> and attempts to be
   20  * backwardly compatible with the stress tool by Amos Waterland
   21  * <apw@rossby.metr.ou.edu> but has more stress tests and more
   22  * functionality.
   23  *
   24  */
   25 #include "stress-ng.h"
   26 
   27 #if defined(HAVE_MINCORE) && NEED_GLIBC(2,2,0)
   28 
   29 #define VEC_MAX_SIZE    (64)
   30 
   31 /*
   32  *  stress_mincore()
   33  *  stress mincore system call
   34  */
   35 static int stress_mincore(const args_t *args)
   36 {
   37     uint8_t *addr = 0, *prev_addr = 0;
   38     const size_t page_size = args->page_size;
   39     const ptrdiff_t mask = ~(page_size - 1);
   40 
   41     do {
   42         int i;
   43 
   44         for (i = 0; (i < 100) && g_keep_stressing_flag; i++) {
   45             int ret, redo = 0;
   46             unsigned char vec[1];
   47 
   48 redo:           errno = 0;
   49             ret = shim_mincore((void *)addr, page_size, vec);
   50             if (ret < 0) {
   51                 switch (errno) {
   52                 case ENOMEM:
   53                     /* Page not mapped */
   54                     break;
   55                 case EAGAIN:
   56                     if (++redo < 100)
   57                         goto redo;
   58                     /* fall through */
   59                 case ENOSYS:
   60                     pr_inf("%s: mincore no not implemented, skipping stressor\n",
   61                         args->name);
   62                     return EXIT_NOT_IMPLEMENTED;
   63                 default:
   64                     pr_fail("%s: mincore on address %p error: %d %s\n",
   65                         args->name, addr, errno,
   66                         strerror(errno));
   67                     return EXIT_FAILURE;
   68                 }
   69             }
   70             if (g_opt_flags & OPT_FLAGS_MINCORE_RAND) {
   71                 addr = (uint8_t *)(ptrdiff_t)
   72                     (((ptrdiff_t)addr >> 1) & mask);
   73                 if (addr == prev_addr)
   74                     addr = (uint8_t *)((ptrdiff_t)(mwc64() & mask));
   75                 prev_addr = addr;
   76             }
   77             else
   78                 addr += page_size;
   79         }
   80         inc_counter(args);
   81     } while (keep_stressing());
   82 
   83     return EXIT_SUCCESS;
   84 }
   85 
   86 stressor_info_t stress_mincore_info = {
   87     .stressor = stress_mincore,
   88     .class = CLASS_OS | CLASS_MEMORY
   89 };
   90 #else
   91 stressor_info_t stress_mincore_info = {
   92     .stressor = stress_not_implemented,
   93     .class = CLASS_OS | CLASS_MEMORY
   94 };
   95 #endif