"Fossies" - the Fresh Open Source Software Archive

Member "stress-ng-0.09.59.1/stress-kill.c" (8 Jun 2019, 2923 Bytes) of package /linux/privat/stress-ng-0.09.59.1.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-kill.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 0.09.57_vs_0.09.58.

    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 static const help_t help[] = {
   28     { NULL, "kill N",   "start N workers killing with SIGUSR1" },
   29     { NULL, "kill-ops N",   "stop after N kill bogo operations" },
   30     { NULL, NULL,       NULL }
   31 };
   32 
   33 /*
   34  *  stress on sched_kill()
   35  *  stress system by rapid kills
   36  */
   37 static int stress_kill(const args_t *args)
   38 {
   39     uint64_t udelay = 5000;
   40 
   41     if (stress_sighandler(args->name, SIGUSR1, SIG_IGN, NULL) < 0)
   42         return EXIT_FAILURE;
   43 
   44     do {
   45         int ret;
   46 
   47         /*
   48          *  With many kill stressors we get into a state
   49          *  where they all hammer on kill system calls and
   50          *  this stops the parent from getting scheduling
   51          *  time to spawn off the rest of the kill stressors
   52          *  causing some lag in getting all the stressors
   53          *  running. Ease this pressure off to being with
   54          *  with some small sleeps that shrink to zero over
   55          *  time. The alternative was to re-nice all the
   56          *  processes, but even then one gets the child
   57          *  stressors all contending and causing a bottle
   58          *  neck.  Any simpler and/or better solutions would
   59          *  be appreciated!
   60          */
   61         if (udelay >= 1000) {
   62             (void)shim_usleep(udelay);
   63             udelay -= 500;
   64         }
   65 
   66         ret = kill(args->pid, SIGUSR1);
   67         if ((ret < 0) && (g_opt_flags & OPT_FLAGS_VERIFY))
   68             pr_fail_err("kill");
   69 
   70         /* Zero signal can be used to see if process exists */
   71         ret = kill(args->pid, 0);
   72         if ((ret < 0) && (g_opt_flags & OPT_FLAGS_VERIFY))
   73             pr_fail_err("kill");
   74 
   75         /*
   76          * Zero signal can be used to see if process exists,
   77          * -1 pid means signal sent to every process caller has
   78          * permission to send to
   79          */
   80         ret = kill(-1, 0);
   81         if ((ret < 0) && (g_opt_flags & OPT_FLAGS_VERIFY))
   82             pr_fail_err("kill");
   83 
   84         inc_counter(args);
   85     } while (keep_stressing());
   86 
   87     return EXIT_SUCCESS;
   88 }
   89 
   90 stressor_info_t stress_kill_info = {
   91     .stressor = stress_kill,
   92     .class = CLASS_INTERRUPT | CLASS_SCHEDULER | CLASS_OS,
   93     .help = help
   94 };