"Fossies" - the Fresh Open Source Software Archive

Member "stress-ng-0.09.56/stress-branch.c" (15 Mar 2019, 10589 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-branch.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 0.09.55_vs_0.09.56.

    1 /*
    2  * Copyright (C) 2013-2019 Canonical, Ltd.
    3  *
    4  * This program is free software; you can redistribute it and/or
    5  * modify it under the terms of the GNU General Public License
    6  * as published by the Free Software Foundation; either version 2
    7  * of the License, or (at your option) any later version.
    8  *
    9  * This program is distributed in the hope that it will be useful,
   10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12  * GNU General Public License for more details.
   13  *
   14  * You should have received a copy of the GNU General Public License
   15  * along with this program; if not, write to the Free Software
   16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
   17  *
   18  * This code is a complete clean re-write of the stress tool by
   19  * Colin Ian King <colin.king@canonical.com> and attempts to be
   20  * backwardly compatible with the stress tool by Amos Waterland
   21  * <apw@rossby.metr.ou.edu> but has more stress tests and more
   22  * functionality.
   23  *
   24  */
   25 #include "stress-ng.h"
   26 
   27 #if defined(HAVE_LABEL_AS_VALUE)
   28 /*
   29  *  jmp_mwc8()
   30  *  special non-overly optimized mwc8 that gets inlined
   31  *  to remove a jmp and hence boost branch miss rates.
   32  *  Do not optimize this any further as this will lower
   33  *  the branch miss rate.
   34  */
   35 static inline uint8_t jmp_mwc8(void)
   36 {
   37     static uint32_t w = MWC_SEED_W;
   38     static uint32_t z = MWC_SEED_Z;
   39 
   40         z = 36969 * (z & 65535) + (z >> 16);
   41         w = 18000 * (w & 65535) + (w >> 16);
   42         return (w >> 3) & 0xff;
   43 }
   44 
   45 /*
   46  *  The following jumps to a random label. If do_more is false
   47  *  then we jump to label ret and abort. This has been carefully
   48  *  hand crafted to make each JMP() macro expand to code with
   49  *  just one jmp statement
   50  */
   51 #define JMP(a)  label ## a:                 \
   52 {                           \
   53     register bool do_more;              \
   54     register uint16_t _index = jmp_mwc8();      \
   55                             \
   56     inc_counter(args);              \
   57     do_more = LIKELY((int)g_keep_stressing_flag) &  \
   58         (((int)!args->max_ops) |        \
   59          (get_counter(args) < args->max_ops));  \
   60     _index |= (do_more << 8);           \
   61     goto *labels[_index];               \
   62 }
   63 
   64 /*
   65  *  stress_branch()
   66  *  stress instruction branch prediction
   67  */
   68 static int stress_branch(const args_t *args)
   69 {
   70     static const void ALIGN64 *labels[] = {
   71         &&ret, &&ret, &&ret, &&ret,
   72         &&ret, &&ret, &&ret, &&ret,
   73         &&ret, &&ret, &&ret, &&ret,
   74         &&ret, &&ret, &&ret, &&ret,
   75         &&ret, &&ret, &&ret, &&ret,
   76         &&ret, &&ret, &&ret, &&ret,
   77         &&ret, &&ret, &&ret, &&ret,
   78         &&ret, &&ret, &&ret, &&ret,
   79         &&ret, &&ret, &&ret, &&ret,
   80         &&ret, &&ret, &&ret, &&ret,
   81         &&ret, &&ret, &&ret, &&ret,
   82         &&ret, &&ret, &&ret, &&ret,
   83         &&ret, &&ret, &&ret, &&ret,
   84         &&ret, &&ret, &&ret, &&ret,
   85         &&ret, &&ret, &&ret, &&ret,
   86         &&ret, &&ret, &&ret, &&ret,
   87 
   88         &&ret, &&ret, &&ret, &&ret,
   89         &&ret, &&ret, &&ret, &&ret,
   90         &&ret, &&ret, &&ret, &&ret,
   91         &&ret, &&ret, &&ret, &&ret,
   92         &&ret, &&ret, &&ret, &&ret,
   93         &&ret, &&ret, &&ret, &&ret,
   94         &&ret, &&ret, &&ret, &&ret,
   95         &&ret, &&ret, &&ret, &&ret,
   96         &&ret, &&ret, &&ret, &&ret,
   97         &&ret, &&ret, &&ret, &&ret,
   98         &&ret, &&ret, &&ret, &&ret,
   99         &&ret, &&ret, &&ret, &&ret,
  100         &&ret, &&ret, &&ret, &&ret,
  101         &&ret, &&ret, &&ret, &&ret,
  102         &&ret, &&ret, &&ret, &&ret,
  103         &&ret, &&ret, &&ret, &&ret,
  104 
  105         &&ret, &&ret, &&ret, &&ret,
  106         &&ret, &&ret, &&ret, &&ret,
  107         &&ret, &&ret, &&ret, &&ret,
  108         &&ret, &&ret, &&ret, &&ret,
  109         &&ret, &&ret, &&ret, &&ret,
  110         &&ret, &&ret, &&ret, &&ret,
  111         &&ret, &&ret, &&ret, &&ret,
  112         &&ret, &&ret, &&ret, &&ret,
  113         &&ret, &&ret, &&ret, &&ret,
  114         &&ret, &&ret, &&ret, &&ret,
  115         &&ret, &&ret, &&ret, &&ret,
  116         &&ret, &&ret, &&ret, &&ret,
  117         &&ret, &&ret, &&ret, &&ret,
  118         &&ret, &&ret, &&ret, &&ret,
  119         &&ret, &&ret, &&ret, &&ret,
  120         &&ret, &&ret, &&ret, &&ret,
  121 
  122         &&ret, &&ret, &&ret, &&ret,
  123         &&ret, &&ret, &&ret, &&ret,
  124         &&ret, &&ret, &&ret, &&ret,
  125         &&ret, &&ret, &&ret, &&ret,
  126         &&ret, &&ret, &&ret, &&ret,
  127         &&ret, &&ret, &&ret, &&ret,
  128         &&ret, &&ret, &&ret, &&ret,
  129         &&ret, &&ret, &&ret, &&ret,
  130         &&ret, &&ret, &&ret, &&ret,
  131         &&ret, &&ret, &&ret, &&ret,
  132         &&ret, &&ret, &&ret, &&ret,
  133         &&ret, &&ret, &&ret, &&ret,
  134         &&ret, &&ret, &&ret, &&ret,
  135         &&ret, &&ret, &&ret, &&ret,
  136         &&ret, &&ret, &&ret, &&ret,
  137         &&ret, &&ret, &&ret, &&ret,
  138 
  139         &&label0x00, &&label0x01, &&label0x02, &&label0x03,
  140         &&label0x04, &&label0x05, &&label0x06, &&label0x07,
  141         &&label0x08, &&label0x09, &&label0x0a, &&label0x0b,
  142         &&label0x0c, &&label0x0d, &&label0x0e, &&label0x0f,
  143         &&label0x10, &&label0x11, &&label0x12, &&label0x13,
  144         &&label0x14, &&label0x15, &&label0x16, &&label0x17,
  145         &&label0x18, &&label0x19, &&label0x1a, &&label0x1b,
  146         &&label0x1c, &&label0x1d, &&label0x1e, &&label0x1f,
  147         &&label0x20, &&label0x21, &&label0x22, &&label0x23,
  148         &&label0x24, &&label0x25, &&label0x26, &&label0x27,
  149         &&label0x28, &&label0x29, &&label0x2a, &&label0x2b,
  150         &&label0x2c, &&label0x2d, &&label0x2e, &&label0x2f,
  151         &&label0x30, &&label0x31, &&label0x32, &&label0x33,
  152         &&label0x34, &&label0x35, &&label0x36, &&label0x37,
  153         &&label0x38, &&label0x39, &&label0x3a, &&label0x3b,
  154         &&label0x3c, &&label0x3d, &&label0x3e, &&label0x3f,
  155 
  156         &&label0x40, &&label0x41, &&label0x42, &&label0x43,
  157         &&label0x44, &&label0x45, &&label0x46, &&label0x47,
  158         &&label0x48, &&label0x49, &&label0x4a, &&label0x4b,
  159         &&label0x4c, &&label0x4d, &&label0x4e, &&label0x4f,
  160         &&label0x50, &&label0x51, &&label0x52, &&label0x53,
  161         &&label0x54, &&label0x55, &&label0x56, &&label0x57,
  162         &&label0x58, &&label0x59, &&label0x5a, &&label0x5b,
  163         &&label0x5c, &&label0x5d, &&label0x5e, &&label0x5f,
  164         &&label0x60, &&label0x61, &&label0x62, &&label0x63,
  165         &&label0x64, &&label0x65, &&label0x66, &&label0x67,
  166         &&label0x68, &&label0x69, &&label0x6a, &&label0x6b,
  167         &&label0x6c, &&label0x6d, &&label0x6e, &&label0x6f,
  168         &&label0x70, &&label0x71, &&label0x72, &&label0x73,
  169         &&label0x74, &&label0x75, &&label0x76, &&label0x77,
  170         &&label0x78, &&label0x79, &&label0x7a, &&label0x7b,
  171         &&label0x7c, &&label0x7d, &&label0x7e, &&label0x7f,
  172 
  173         &&label0x80, &&label0x81, &&label0x82, &&label0x83,
  174         &&label0x84, &&label0x85, &&label0x86, &&label0x87,
  175         &&label0x88, &&label0x89, &&label0x8a, &&label0x8b,
  176         &&label0x8c, &&label0x8d, &&label0x8e, &&label0x8f,
  177         &&label0x90, &&label0x91, &&label0x92, &&label0x93,
  178         &&label0x94, &&label0x95, &&label0x96, &&label0x97,
  179         &&label0x98, &&label0x99, &&label0x9a, &&label0x9b,
  180         &&label0x9c, &&label0x9d, &&label0x9e, &&label0x9f,
  181         &&label0xa0, &&label0xa1, &&label0xa2, &&label0xa3,
  182         &&label0xa4, &&label0xa5, &&label0xa6, &&label0xa7,
  183         &&label0xa8, &&label0xa9, &&label0xaa, &&label0xab,
  184         &&label0xac, &&label0xad, &&label0xae, &&label0xaf,
  185         &&label0xb0, &&label0xb1, &&label0xb2, &&label0xb3,
  186         &&label0xb4, &&label0xb5, &&label0xb6, &&label0xb7,
  187         &&label0xb8, &&label0xb9, &&label0xba, &&label0xbb,
  188         &&label0xbc, &&label0xbd, &&label0xbe, &&label0xbf,
  189 
  190         &&label0xc0, &&label0xc1, &&label0xc2, &&label0xc3,
  191         &&label0xc4, &&label0xc5, &&label0xc6, &&label0xc7,
  192         &&label0xc8, &&label0xc9, &&label0xca, &&label0xcb,
  193         &&label0xcc, &&label0xcd, &&label0xce, &&label0xcf,
  194         &&label0xd0, &&label0xd1, &&label0xd2, &&label0xd3,
  195         &&label0xd4, &&label0xd5, &&label0xd6, &&label0xd7,
  196         &&label0xd8, &&label0xd9, &&label0xda, &&label0xdb,
  197         &&label0xdc, &&label0xdd, &&label0xde, &&label0xdf,
  198         &&label0xe0, &&label0xe1, &&label0xe2, &&label0xe3,
  199         &&label0xe4, &&label0xe5, &&label0xe6, &&label0xe7,
  200         &&label0xe8, &&label0xe9, &&label0xea, &&label0xeb,
  201         &&label0xec, &&label0xed, &&label0xee, &&label0xef,
  202         &&label0xf0, &&label0xf1, &&label0xf2, &&label0xf3,
  203         &&label0xf4, &&label0xf5, &&label0xf6, &&label0xf7,
  204         &&label0xf8, &&label0xf9, &&label0xfa, &&label0xfb,
  205         &&label0xfc, &&label0xfd, &&label0xfe, &&label0xff,
  206     };
  207 
  208     for (;;) {
  209         JMP(0x00) JMP(0x01) JMP(0x02) JMP(0x03)
  210         JMP(0x04) JMP(0x05) JMP(0x06) JMP(0x07)
  211         JMP(0x08) JMP(0x09) JMP(0x0a) JMP(0x0b)
  212         JMP(0x0c) JMP(0x0d) JMP(0x0e) JMP(0x0f)
  213         JMP(0x10) JMP(0x11) JMP(0x12) JMP(0x13)
  214         JMP(0x14) JMP(0x15) JMP(0x16) JMP(0x17)
  215         JMP(0x18) JMP(0x19) JMP(0x1a) JMP(0x1b)
  216         JMP(0x1c) JMP(0x1d) JMP(0x1e) JMP(0x1f)
  217         JMP(0x20) JMP(0x21) JMP(0x22) JMP(0x23)
  218         JMP(0x24) JMP(0x25) JMP(0x26) JMP(0x27)
  219         JMP(0x28) JMP(0x29) JMP(0x2a) JMP(0x2b)
  220         JMP(0x2c) JMP(0x2d) JMP(0x2e) JMP(0x2f)
  221         JMP(0x30) JMP(0x31) JMP(0x32) JMP(0x33)
  222         JMP(0x34) JMP(0x35) JMP(0x36) JMP(0x37)
  223         JMP(0x38) JMP(0x39) JMP(0x3a) JMP(0x3b)
  224         JMP(0x3c) JMP(0x3d) JMP(0x3e) JMP(0x3f)
  225 
  226         JMP(0x40) JMP(0x41) JMP(0x42) JMP(0x43)
  227         JMP(0x44) JMP(0x45) JMP(0x46) JMP(0x47)
  228         JMP(0x48) JMP(0x49) JMP(0x4a) JMP(0x4b)
  229         JMP(0x4c) JMP(0x4d) JMP(0x4e) JMP(0x4f)
  230         JMP(0x50) JMP(0x51) JMP(0x52) JMP(0x53)
  231         JMP(0x54) JMP(0x55) JMP(0x56) JMP(0x57)
  232         JMP(0x58) JMP(0x59) JMP(0x5a) JMP(0x5b)
  233         JMP(0x5c) JMP(0x5d) JMP(0x5e) JMP(0x5f)
  234         JMP(0x60) JMP(0x61) JMP(0x62) JMP(0x63)
  235         JMP(0x64) JMP(0x65) JMP(0x66) JMP(0x67)
  236         JMP(0x68) JMP(0x69) JMP(0x6a) JMP(0x6b)
  237         JMP(0x6c) JMP(0x6d) JMP(0x6e) JMP(0x6f)
  238         JMP(0x70) JMP(0x71) JMP(0x72) JMP(0x73)
  239         JMP(0x74) JMP(0x75) JMP(0x76) JMP(0x77)
  240         JMP(0x78) JMP(0x79) JMP(0x7a) JMP(0x7b)
  241         JMP(0x7c) JMP(0x7d) JMP(0x7e) JMP(0x7f)
  242 
  243         JMP(0x80) JMP(0x81) JMP(0x82) JMP(0x83)
  244         JMP(0x84) JMP(0x85) JMP(0x86) JMP(0x87)
  245         JMP(0x88) JMP(0x89) JMP(0x8a) JMP(0x8b)
  246         JMP(0x8c) JMP(0x8d) JMP(0x8e) JMP(0x8f)
  247         JMP(0x90) JMP(0x91) JMP(0x92) JMP(0x93)
  248         JMP(0x94) JMP(0x95) JMP(0x96) JMP(0x97)
  249         JMP(0x98) JMP(0x99) JMP(0x9a) JMP(0x9b)
  250         JMP(0x9c) JMP(0x9d) JMP(0x9e) JMP(0x9f)
  251         JMP(0xa0) JMP(0xa1) JMP(0xa2) JMP(0xa3)
  252         JMP(0xa4) JMP(0xa5) JMP(0xa6) JMP(0xa7)
  253         JMP(0xa8) JMP(0xa9) JMP(0xaa) JMP(0xab)
  254         JMP(0xac) JMP(0xad) JMP(0xae) JMP(0xaf)
  255         JMP(0xb0) JMP(0xb1) JMP(0xb2) JMP(0xb3)
  256         JMP(0xb4) JMP(0xb5) JMP(0xb6) JMP(0xb7)
  257         JMP(0xb8) JMP(0xb9) JMP(0xba) JMP(0xbb)
  258         JMP(0xbc) JMP(0xbd) JMP(0xbe) JMP(0xbf)
  259 
  260         JMP(0xc0) JMP(0xc1) JMP(0xc2) JMP(0xc3)
  261         JMP(0xc4) JMP(0xc5) JMP(0xc6) JMP(0xc7)
  262         JMP(0xc8) JMP(0xc9) JMP(0xca) JMP(0xcb)
  263         JMP(0xcc) JMP(0xcd) JMP(0xce) JMP(0xcf)
  264         JMP(0xd0) JMP(0xd1) JMP(0xd2) JMP(0xd3)
  265         JMP(0xd4) JMP(0xd5) JMP(0xd6) JMP(0xd7)
  266         JMP(0xd8) JMP(0xd9) JMP(0xda) JMP(0xdb)
  267         JMP(0xdc) JMP(0xdd) JMP(0xde) JMP(0xdf)
  268         JMP(0xe0) JMP(0xe1) JMP(0xe2) JMP(0xe3)
  269         JMP(0xe4) JMP(0xe5) JMP(0xe6) JMP(0xe7)
  270         JMP(0xe8) JMP(0xe9) JMP(0xea) JMP(0xeb)
  271         JMP(0xec) JMP(0xed) JMP(0xee) JMP(0xef)
  272         JMP(0xf0) JMP(0xf1) JMP(0xf2) JMP(0xf3)
  273         JMP(0xf4) JMP(0xf5) JMP(0xf6) JMP(0xf7)
  274         JMP(0xf8) JMP(0xf9) JMP(0xfa) JMP(0xfb)
  275         JMP(0xfc) JMP(0xfd) JMP(0xfe) JMP(0xff)
  276     }
  277 ret:
  278     return EXIT_SUCCESS;
  279 }
  280 
  281 stressor_info_t stress_branch_info = {
  282     .stressor = stress_branch,
  283     .class = CLASS_CPU
  284 };
  285 #else
  286 stressor_info_t stress_branch_info = {
  287     .stressor = stress_not_implemented,
  288     .class = CLASS_CPU
  289 };
  290 #endif