Changes in / [13d33a75:ef9988b]


Ignore:
Files:
13 deleted
35 edited

Legend:

Unmodified
Added
Removed
  • benchmark/benchcltr.hfa

    r13d33a75 ref9988b  
    11#pragma once
     2
    23#include <assert.h>
    3 #include <stdint.h>
    4 
    5 #ifdef __cforall
    6         #include <kernel.hfa>
    7         #include <thread.hfa>
    8         #include <stats.hfa>
    9 #else
    10 #include <time.h>                                                                               // timespec
    11 #include <sys/time.h>                                                                   // timeval
    12 
    13 enum { TIMEGRAN = 1000000000LL };                                       // nanosecond granularity, except for timeval
    14 #endif
     4#include <kernel.hfa>
     5#include <thread.hfa>
     6#include <stats.hfa>
    157
    168#define BENCH_OPT_SHORT "d:p:t:SPV"
     
    2214        {"procstat",     no_argument      , 0, 'P'}, \
    2315        {"viewhalts",    no_argument      , 0, 'V'},
     16
     17#define BENCH_DECL \
     18        double duration = 5; \
     19        int nprocs = 1; \
     20        int nthreads = 1;
    2421
    2522#define BENCH_OPT_CASE \
     
    5552                break;
    5653
    57 double duration = 5;
    58 int nprocs = 1;
    59 int nthreads = 1;
    6054bool silent = false;
    61 bool continuous = false;
    6255bool procstats = false;
    6356bool viewhalts = false;
    64 
    65 #define BENCH_OPT_CFA \
    66         {'d', "duration",  "Duration of the experiments in seconds", duration }, \
    67         {'t', "nthreads",  "Number of threads to use", nthreads }, \
    68         {'p', "nprocs",    "Number of processors to use", nprocs }, \
    69         {'S', "nostats",   "Don't print statistics", silent, parse_settrue }, \
    70         {'C', "constats",  "Regularly print statistics", continuous, parse_settrue }, \
    71         {'P', "procstat",  "Print statistics for each processors", procstats, parse_settrue }, \
    72         {'V', "viewhalts", "Visualize halts, prints timestamp and Processor id for each halt.", viewhalts, parse_settrue },
    73 
    74 #ifdef __cforall
    75 #include <parseargs.hfa>
    76 
    7757struct cluster * the_benchmark_cluster = 0p;
    7858struct BenchCluster {
     
    8060};
    8161
    82 void ?{}( BenchCluster & this, int num_io, const io_context_params & io_params, int stats ) {
    83         (this.self){ "Benchmark Cluster", num_io, io_params };
     62void ?{}( BenchCluster & this, int flags, int stats ) {
     63        (this.self){ "Benchmark Cluster", flags };
    8464
    8565        assert( the_benchmark_cluster == 0p );
     
    125105        }
    126106}
    127 #else
    128 uint64_t getTimeNsec() {
    129         timespec curr;
    130         clock_gettime( CLOCK_REALTIME, &curr );
    131         return (int64_t)curr.tv_sec * TIMEGRAN + curr.tv_nsec;
    132 }
    133 
    134 uint64_t to_miliseconds( uint64_t durtn ) { return durtn / (TIMEGRAN / 1000LL); }
    135 double to_fseconds(uint64_t durtn ) { return durtn / (double)TIMEGRAN; }
    136 uint64_t from_fseconds(double sec) { return sec * TIMEGRAN; }
    137 
    138 
    139 void wait_duration(double duration, uint64_t & start, uint64_t & end, bool is_tty) {
    140         for(;;) {
    141                 usleep(100000);
    142                 end = getTimeNsec();
    143                 uint64_t delta = end - start;
    144                 /*if(is_tty)*/ {
    145                         printf(" %.1f\r", to_fseconds(delta));
    146                         fflush(stdout);
    147                 }
    148                 if( delta >= from_fseconds(duration) ) {
    149                         break;
    150                 }
    151         }
    152 }
    153 #endif
    154 
    155107
    156108void bench_usage( char * argv [] ) {
  • benchmark/io/readv.cfa

    r13d33a75 ref9988b  
    4040int do_read(int fd, struct iovec * iov) {
    4141        // extern ssize_t cfa_preadv2(int, const struct iovec *, int, off_t, int, int = 0, Duration = -1`s, io_cancellation * = 0p, io_context * = 0p);
    42         int sflags = 0
    43         #if defined(CFA_HAVE_IOSQE_ASYNC)
    44                 | CFA_IO_ASYNC
    45         #else
    46         #warning no CFA_IO_ASYNC support
    47         #endif
    48         ;
     42        int sflags = 0;
    4943        if(fixed_file) {
    5044                sflags |= CFA_IO_FIXED_FD1;
     
    6963
    7064int main(int argc, char * argv[]) {
     65        BENCH_DECL
     66        unsigned num_io = 1;
     67        io_context_params params;
    7168        int file_flags = 0;
    72         unsigned num_io = 1;
    7369        unsigned sublen = 16;
    74         unsigned nentries = 0;
    7570
    76         bool subthrd = false;
    77         bool subeagr = false;
    78         bool odirect = false;
    79         bool kpollsb = false;
    80         bool kpollcp = false;
     71        arg_loop:
     72        for(;;) {
     73                static struct option options[] = {
     74                        BENCH_OPT_LONG
     75                        {"bufsize",       required_argument, 0, 'b'},
     76                        {"submitthread",  no_argument      , 0, 's'},
     77                        {"eagersubmit",   no_argument      , 0, 'e'},
     78                        {"kpollsubmit",   no_argument      , 0, 'k'},
     79                        {"kpollcomplete", no_argument      , 0, 'i'},
     80                        {"fixed-files",   no_argument      , 0, 'f'},
     81                        {"open-direct",   no_argument      , 0, 'o'},
     82                        {"submitlength",  required_argument, 0, 'l'},
     83                        {0, 0, 0, 0}
     84                };
    8185
    82         cfa_option opt[] = {
    83                 BENCH_OPT_CFA
    84                 {'b', "bufsize",       "Number of bytes to read per request", buflen},
    85                 {'s', "submitthread",  "If set, cluster uses polling thread to submit I/O", subthrd, parse_settrue},
    86                 {'e', "eagersubmit",   "If set, cluster submits I/O eagerly but still aggregates submits", subeagr, parse_settrue},
    87                 {'f', "fixed-files",   "Pre-register files with the io_contexts", fixed_file, parse_settrue},
    88                 {'o', "open-direct",   "Open files with O_DIRECT flag, bypassing the file cache", odirect, parse_settrue},
    89                 {'k', "kpollsubmit",   "If set, cluster uses an in kernel thread to poll submission, implies -f, requires elevated permissions", kpollsb, parse_settrue},
    90                 {'i', "kpollcomplete", "If set, cluster polls fds for completions instead of relying on interrupts to get notifications, implies -o", kpollcp, parse_settrue},
    91                 {'l', "submitlength",  "Size of the buffer that stores ready submissions", sublen},
    92                 {'r', "numentries",    "Number of entries each of the io_context have", nentries},
    93                 {'n', "numcontexts",   "Number of io_contexts to the cluster", num_io},
    94         };
    95         int opt_cnt = sizeof(opt) / sizeof(cfa_option);
     86                int idx = 0;
     87                int opt = getopt_long(argc, argv, BENCH_OPT_SHORT "b:sekil:", options, &idx);
    9688
    97         char **left;
    98         parse_args( opt, opt_cnt, "[OPTIONS]...\ncforall yield benchmark", left );
    99 
    100         if(kpollcp || odirect) {
    101                 if( (buflen % 512) != 0 ) {
    102                         fprintf(stderr, "Buffer length must be a multiple of 512 when using O_DIRECT, was %lu\n\n", buflen);
    103                         print_args_usage(opt, opt_cnt, "[OPTIONS]...\ncforall yield benchmark", true);
     89                const char * arg = optarg ? optarg : "";
     90                char * end;
     91                switch(opt) {
     92                        // Exit Case
     93                        case -1:
     94                                break arg_loop;
     95                        BENCH_OPT_CASE
     96                        case 'b':
     97                                buflen = strtoul(arg, &end, 10);
     98                                if(*end != '\0' && buflen < 10) {
     99                                        fprintf(stderr, "Buffer size must be at least 10, was %s\n", arg);
     100                                        goto usage;
     101                                }
     102                                break;
     103                        case 's':
     104                                params.poller_submits = true;
     105                                break;
     106                        case 'e':
     107                                params.eager_submits = true;
     108                                break;
     109                        case 'k':
     110                                params.poll_submit = true;
     111                        case 'f':
     112                                fixed_file = true;
     113                                break;
     114                        case 'i':
     115                                params.poll_complete = true;
     116                        case 'o':
     117                                file_flags |= O_DIRECT;
     118                                break;
     119                        case 'l':
     120                                sublen = strtoul(arg, &end, 10);
     121                                if(*end != '\0' && sublen < 16) {
     122                                        fprintf(stderr, "Submit length must be at least 16, was %s\n", arg);
     123                                        goto usage;
     124                                }
     125                                // flags |= (sublen << CFA_CLUSTER_IO_BUFFLEN_OFFSET);
     126                                break;
     127                        default: /* ? */
     128                                fprintf(stderr, "%d\n", opt);
     129                        usage:
     130                                bench_usage( argv );
     131                                fprintf( stderr, "  -b, --buflen=SIZE        Number of bytes to read per request\n" );
     132                                fprintf( stderr, "  -u, --userthread         If set, cluster uses user-thread to poll I/O\n" );
     133                                fprintf( stderr, "  -s, --submitthread       If set, cluster uses polling thread to submit I/O\n" );
     134                                fprintf( stderr, "  -e, --eagersubmit        If set, cluster submits I/O eagerly but still aggregates submits\n" );
     135                                fprintf( stderr, "  -k, --kpollsubmit        If set, cluster uses IORING_SETUP_SQPOLL\n" );
     136                                fprintf( stderr, "  -i, --kpollcomplete      If set, cluster uses IORING_SETUP_IOPOLL\n" );
     137                                fprintf( stderr, "  -l, --submitlength=LEN   Max number of submitions that can be submitted together\n" );
     138                                exit(EXIT_FAILURE);
    104139                }
    105140        }
    106 
    107         io_context_params params;
    108 
    109         if( subthrd ) params.poller_submits = true;
    110         if( subeagr ) params.eager_submits  = true;
    111         if( kpollsb ) params.poll_submit    = true;
    112         if( kpollcp ) params.poll_complete  = true;
    113 
    114         if(params.poll_submit  ) fixed_file = true;
    115         if(params.poll_complete) odirect    = true;
    116 
    117         params.num_ready = sublen;
    118         params.num_entries = nentries;
    119 
    120         if(odirect) file_flags |= O_DIRECT;
    121141
    122142        int lfd = open(__FILE__, file_flags);
  • benchmark/readyQ/yield.cfa

    r13d33a75 ref9988b  
    4343
    4444int main(int argc, char * argv[]) {
    45         unsigned num_io = 1;
    46         io_context_params params;
     45        BENCH_DECL
    4746
    48         cfa_option opt[] = {
    49                 BENCH_OPT_CFA
    50         };
    51         int opt_cnt = sizeof(opt) / sizeof(cfa_option);
     47        for(;;) {
     48                static struct option options[] = {
     49                        BENCH_OPT_LONG
     50                        {0, 0, 0, 0}
     51                };
    5252
    53         char **left;
    54         parse_args( argc, argv, opt, opt_cnt, "[OPTIONS]...\ncforall yield benchmark", left );
     53                int idx = 0;
     54                int opt = getopt_long(argc, argv, BENCH_OPT_SHORT, options, &idx);
     55
     56                const char * arg = optarg ? optarg : "";
     57                char * end;
     58                switch(opt) {
     59                        case -1:
     60                                goto run;
     61                        BENCH_OPT_CASE
     62                        default: /* ? */
     63                                fprintf( stderr, "Unkown option '%c'\n", opt);
     64                        usage:
     65                                bench_usage( argv );
     66                                exit(1);
     67                }
     68        }
     69        run:
    5570
    5671        {
     
    5873
    5974                Time start, end;
    60                 BenchCluster cl = { num_io, params, CFA_STATS_READY_Q };
     75                BenchCluster cl = { 0, CFA_STATS_READY_Q };
    6176                {
    6277                        BenchProc procs[nprocs];
  • driver/cc1.cc

    r13d33a75 ref9988b  
    1010// Created On       : Fri Aug 26 14:23:51 2005
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug 16 21:03:02 2020
    13 // Update Count     : 413
     12// Last Modified On : Sat May 30 18:09:05 2020
     13// Update Count     : 404
    1414//
    1515
     
    2424#include <unistd.h>                                                                             // execvp, fork, unlink
    2525#include <sys/wait.h>                                                                   // wait
    26 #include <fcntl.h>                                                                              // creat
     26#include <fcntl.h>
    2727
    2828
     
    5959
    6060
    61 static string __CFA_FLAGPREFIX__( "__CFA_FLAG" );               // "__CFA_FLAG__=" suffix
     61static string __CFA_FLAGPREFIX__( "__CFA_FLAG" );               // "N__=" suffix
    6262
    6363static void checkEnv1( const char * args[], int & nargs ) { // stage 1
     
    111111} // checkEnv2
    112112
    113 #define CFA_SUFFIX ".ifa"
    114 
    115 static char tmpname[] = P_tmpdir "/CFAXXXXXX" CFA_SUFFIX;
     113
     114static char tmpname[] = P_tmpdir "/CFAXXXXXX.ifa";
    116115static int tmpfilefd = -1;
    117116static bool startrm = false;
     
    171170                        if ( arg == "-quiet" ) {
    172171                        } else if ( arg == "-imultilib" || arg == "-imultiarch" ) {
    173                                 i += 1;                                                                 // and argument
     172                                i += 1;                                                                 // and the argument
    174173                        } else if ( prefix( arg, "-A" ) ) {
    175174                        } else if ( prefix( arg, "-D__GNU" ) ) {
     
    178177                                //********
    179178                        } else if ( arg == "-D" && prefix( argv[i + 1], "__GNU" ) ) {
    180                                 i += 1;                                                                 // and argument
     179                                i += 1;                                                                 // and the argument
    181180
    182181                                // strip flags controlling cpp step
     
    185184                                cpp_flag = true;
    186185                        } else if ( arg == "-D" && string( argv[i + 1] ) == "__CPP__" ) {
    187                                 i += 1;                                                                 // and argument
     186                                i += 1;                                                                 // and the argument
    188187                                cpp_flag = true;
    189188
     
    195194                                cpp_out = argv[i];
    196195                        } else {
    197                                 args[nargs++] = argv[i];                                // pass flag along
     196                                args[nargs++] = argv[i];                                // pass the flag along
    198197                                // CPP flags with an argument
    199198                                if ( arg == "-D" || arg == "-U" || arg == "-I" || arg == "-MF" || arg == "-MT" || arg == "-MQ" ||
     
    201200                                         arg == "-iwithprefix" || arg == "-iwithprefixbefore" || arg == "-isystem" || arg == "-isysroot" ) {
    202201                                        i += 1;
    203                                         args[nargs++] = argv[i];                        // pass argument along
     202                                        args[nargs++] = argv[i];                        // pass the argument along
    204203                                        #ifdef __DEBUG_H__
    205204                                        cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl;
    206205                                        #endif // __DEBUG_H__
    207206                                } else if ( arg == "-MD" || arg == "-MMD" ) {
    208                                         // gcc frontend generates the dependency file-name after the -MD/-MMD flag, but it is necessary to
    209                                         // prefix that file name with -MF.
    210207                                        args[nargs++] = "-MF";                          // insert before file
    211208                                        i += 1;
    212                                         args[nargs++] = argv[i];                        // pass argument along
     209                                        args[nargs++] = argv[i];                        // pass the argument along
    213210                                        #ifdef __DEBUG_H__
    214211                                        cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl;
     
    282279        // Run the C preprocessor and save the output in the given file.
    283280
    284         if ( fork() == 0 ) {                                                            // child process ?
     281        if ( fork() == 0 ) {                                                             // child process ?
    285282                // -o xxx.ii cannot be used to write the output file from cpp because no output file is created if cpp detects
    286283                // an error (e.g., cannot find include file). Whereas, output is always generated, even when there is an error,
     
    322319
    323320        if ( WIFSIGNALED(code) ) {                                                      // child failed ?
    324                 rmtmpfile();                                                                    // remove tmpname
    325321                cerr << "CC1 Translator error: stage 1, child failed " << WTERMSIG(code) << endl;
    326322                exit( EXIT_FAILURE );
    327323        } // if
    328324
    329         exit( WEXITSTATUS( code ) );                                            // bad cpp result stops top-level gcc
     325        exit( WEXITSTATUS(code) );                                                      // bad cpp result stops top-level gcc
    330326} // Stage1
    331327
     
    375371                        } else if ( arg == "-fno-diagnostics-color" ) {
    376372                                color_arg = Color_Auto;
    377                         } // if
     373                        }
    378374
    379375                        if ( arg == "-quiet" || arg == "-version" || arg == "-fpreprocessed" ||
    380                                  // Currently CFA does not suppose precompiled .h files.
    381                                  prefix( arg, "--output-pch" ) ) {
     376                                // Currently CFA does not suppose precompiled .h files.
     377                                prefix( arg, "--output-pch" ) ) {
    382378
    383379                                // strip inappropriate flags with an argument
     
    392388
    393389                        } else {
    394                                 args[nargs++] = argv[i];                                // pass flag along
     390                                args[nargs++] = argv[i];                                // pass the flag along
    395391                                if ( arg == "-o" ) {
    396392                                        i += 1;
    397393                                        cpp_out = argv[i];
    398                                         args[nargs++] = argv[i];                        // pass argument along
     394                                        args[nargs++] = argv[i];                        // pass the argument along
    399395                                        #ifdef __DEBUG_H__
    400396                                        cerr << "arg:\"" << argv[i] << "\"" << endl;
     
    443439                        } // if
    444440
    445                         cfa_cpp_out = cfa_cpp_out.substr( 0, dot ) + CFA_SUFFIX;
     441                        cfa_cpp_out = cfa_cpp_out.substr( 0, dot ) + ".ifa";
    446442                        if ( creat( cfa_cpp_out.c_str(), 0666 ) == -1 ) {
    447443                                perror( "CC1 Translator error: stage 2, creat" );
     
    464460        // output.  Otherwise, run the cfa-cpp preprocessor on the temporary file and save the result into the output file.
    465461
    466         if ( fork() == 0 ) {                                                            // child runs CFA preprocessor
     462        if ( fork() == 0 ) {                                                            // child runs CFA
    467463                cargs[0] = ( *new string( bprefix + "cfa-cpp" ) ).c_str();
    468464                cargs[ncargs++] = cpp_in;
     
    522518        #endif // __DEBUG_H__
    523519
    524         if ( fork() == 0 ) {                                                            // child runs gcc
     520        if ( fork() == 0 ) {                                                            // child runs CFA
    525521                args[0] = compiler_path.c_str();
    526522                args[nargs++] = "-S";                                                   // only compile and put assembler output in specified file
  • driver/cfa.cc

    r13d33a75 ref9988b  
    1010// Created On       : Tue Aug 20 13:44:49 2002
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug 16 23:05:59 2020
    13 // Update Count     : 447
     12// Last Modified On : Sat May 30 18:28:23 2020
     13// Update Count     : 433
    1414//
    1515
    1616#include <iostream>
    17 #include <cstdio>                                                                               // perror
    18 #include <cstdlib>                                                                              // putenv, exit
    19 #include <climits>                                                                              // PATH_MAX
    20 #include <string>                                                                               // STL version
    21 #include <algorithm>                                                                    // find
    22 
    23 #include <unistd.h>                                                                             // execvp
     17#include <cstdio>      // perror
     18#include <cstdlib>     // putenv, exit
     19#include <climits>     // PATH_MAX
     20#include <unistd.h>    // execvp
     21#include <string>      // STL version
     22#include <string.h>    // strcmp
     23#include <algorithm>   // find
     24
    2425#include <sys/types.h>
    2526#include <sys/stat.h>
     
    3334using std::to_string;
    3435
    35 //#define __DEBUG_H__
    36 
    37 #define xstr(s) str(s)
    38 #define str(s) #s
    39 
    40 static string __CFA_FLAGPREFIX__( "__CFA_FLAG" );               // "__CFA_FLAG__=" suffix
    41 
    42 static void Putenv( char * argv[], string arg ) {
     36// #define __DEBUG_H__
     37
     38// "N__=" suffix
     39static string __CFA_FLAGPREFIX__( "__CFA_FLAG" );
     40
     41void Putenv( char * argv[], string arg ) {
    4342        // environment variables must have unique names
    4443        static int flags = 0;
     
    5049} // Putenv
    5150
    52 static bool prefix( const string & arg, const string & pre ) { // check if string has prefix
     51// check if string has prefix
     52bool prefix( const string & arg, const string & pre ) {
    5353        return arg.substr( 0, pre.size() ) == pre;
    5454} // prefix
    5555
    56 static inline bool ends_with(const string & str, const string & sfix) {
     56inline bool ends_with(const string & str, const string & sfix) {
    5757        if (sfix.size() > str.size()) return false;
    5858        return std::equal(str.rbegin(), str.rbegin() + sfix.size(), sfix.rbegin(), sfix.rend());
     
    6060
    6161// check if string has suffix
    62 static bool suffix( const string & arg ) {
     62bool suffix( const string & arg ) {
    6363        enum { NumSuffixes = 3 };
    6464        static const string suffixes[NumSuffixes] = { "cfa", "hfa", "ifa" };
     
    7070} // suffix
    7171
     72
    7273static inline bool dirExists( const string & path ) {   // check if directory exists
    7374    struct stat info;
     
    7879static inline string dir(const string & path) {
    7980        return path.substr(0, path.find_last_of('/'));
    80 } // dir
     81}
    8182
    8283// Different path modes
     
    117118}
    118119
     120
     121#define xstr(s) str(s)
     122#define str(s) #s
    119123
    120124int main( int argc, char * argv[] ) {
     
    154158        PathMode path = FromProc();
    155159
    156         const char * args[argc + 100];                                          // cfa command line values, plus some space for additional flags
     160        const char *args[argc + 100];                                           // cfa command line values, plus some space for additional flags
    157161        int sargs = 1;                                                                          // starting location for arguments in args list
    158162        int nargs = sargs;                                                                      // number of arguments in args list; 0 => command name
    159163
    160         const char * libs[argc + 20];                                           // non-user libraries must come separately, plus some added libraries and flags
     164        const char *libs[argc + 20];                                            // non-user libraries must come separately, plus some added libraries and flags
    161165        int nlibs = 0;
    162166
     
    176180
    177181                        if ( arg == "-Xlinker" || arg == "-o" ) {
    178                                 args[nargs++] = argv[i];                                // pass flag along
     182                                args[nargs++] = argv[i];                                // pass argument along
    179183                                i += 1;
    180184                                if ( i == argc ) continue;                              // next argument available ?
    181185                                args[nargs++] = argv[i];                                // pass argument along
    182186                                if ( arg == "-o" ) o_file = i;                  // remember file
    183 
    184                                 // CFA specific arguments
    185 
    186                         } else if ( strncmp(arg.c_str(), "-XCFA", 5) == 0 ) { // CFA pass through
    187                                 if ( arg.size() == 5 ) {
     187                        } else if ( strncmp(arg.c_str(), "-XCFA", 5) == 0 ) {                           // CFA pass through
     188                                if(arg.size() == 5) {
    188189                                        i += 1;
    189                                         if ( i == argc ) continue;                      // next argument available ?
     190                                        if ( i == argc ) continue;                              // next argument available ?
    190191                                        Putenv( argv, argv[i] );
    191                                 } else if ( arg[5] == ',' ) {                   // CFA specific arguments
     192
     193                                        // CFA specific arguments
     194                                }
     195                                else if(arg[5] == ',') {
    192196                                        Putenv( argv, argv[i] + 6 );
    193                                 } else {                                                                // CFA specific arguments
     197
     198                                        // CFA specific arguments
     199                                }
     200                                else {
    194201                                        args[nargs++] = argv[i];
    195                                 } // if
     202                                }
     203
    196204                        } else if ( arg == "-CFA" ) {
    197205                                CFA_flag = true;                                                // strip the -CFA flag
     
    202210                        } else if ( arg == "-nodebug" ) {
    203211                                debug = false;                                                  // strip the nodebug flag
     212                        } else if ( arg == "-nolib" ) {
     213                                nolib = true;                                                   // strip the nodebug flag
    204214                        } else if ( arg == "-quiet" ) {
    205215                                quiet = true;                                                   // strip the quiet flag
    206216                        } else if ( arg == "-noquiet" ) {
    207217                                quiet = false;                                                  // strip the noquiet flag
    208                         } else if ( arg == "-no-include-stdhdr" ) {
    209                                 noincstd_flag = true;                                   // strip the no-include-stdhdr flag
    210                         } else if ( arg == "-nolib" ) {
    211                                 nolib = true;                                                   // strip the nolib flag
    212218                        } else if ( arg == "-help" ) {
    213219                                help = true;                                                    // strip the help flag
    214220                        } else if ( arg == "-nohelp" ) {
    215221                                help = false;                                                   // strip the nohelp flag
     222                        } else if ( arg == "-no-include-stdhdr" ) {
     223                                noincstd_flag = true;                                   // strip the no-include-stdhdr flag
    216224                        } else if ( arg == "-cfalib") {
    217225                                compiling_libs = true;
     
    227235                        } else if ( arg == "-v" ) {
    228236                                verbose = true;                                                 // verbosity required
    229                                 args[nargs++] = argv[i];                                // pass flag along
     237                                args[nargs++] = argv[i];                                // pass argument along
    230238                        } else if ( arg == "-g" ) {
    231239                                debugging = true;                                               // symbolic debugging required
    232                                 args[nargs++] = argv[i];                                // pass flag along
     240                                args[nargs++] = argv[i];                                // pass argument along
    233241                        } else if ( arg == "-save-temps" ) {
    234                                 args[nargs++] = argv[i];                                // pass flag along
     242                                args[nargs++] = argv[i];                                // pass argument along
    235243                                Putenv( argv, arg );                                    // save cfa-cpp output
    236244                        } else if ( prefix( arg, "-x" ) ) {                     // file suffix ?
    237245                                string lang;
    238                                 args[nargs++] = argv[i];                                // pass flag along
     246                                args[nargs++] = argv[i];                                // pass argument along
    239247                                if ( arg.length() == 2 ) {                              // separate argument ?
    240248                                        i += 1;
     
    253261                        } else if ( prefix( arg, "-std=" ) || prefix( arg, "--std=" ) ) {
    254262                                std_flag = true;                                                // -std=XX provided
    255                                 args[nargs++] = argv[i];                                // pass flag along
     263                                args[nargs++] = argv[i];                                // pass argument along
    256264                        } else if ( arg == "-w" ) {
    257                                 args[nargs++] = argv[i];                                // pass flag along
     265                                args[nargs++] = argv[i];                                // pass argument along
    258266                                Putenv( argv, arg );
    259267                        } else if ( prefix( arg, "-W" ) ) {                     // check before next tests
    260268                                if ( arg == "-Werror" || arg == "-Wall" ) {
    261                                         args[nargs++] = argv[i];                        // pass flag along
     269                                        args[nargs++] = argv[i];                        // pass argument along
    262270                                        Putenv( argv, argv[i] );
    263271                                } else {
     
    273281                                bprefix = arg.substr(2);                                // strip the -B flag
    274282                        } else if ( arg == "-c" || arg == "-S" || arg == "-E" || arg == "-M" || arg == "-MM" ) {
    275                                 args[nargs++] = argv[i];                                // pass flag along
     283                                args[nargs++] = argv[i];                                // pass argument along
    276284                                if ( arg == "-E" || arg == "-M" || arg == "-MM" ) {
    277285                                        cpp_flag = true;                                        // cpp only
    278286                                } // if
    279287                                link = false;                           // no linkage required
    280                         } else if ( arg == "-D" || arg == "-U" || arg == "-I" || arg == "-MF" || arg == "-MT" || arg == "-MQ" ||
    281                                                 arg == "-include" || arg == "-imacros" || arg == "-idirafter" || arg == "-iprefix" ||
    282                                                 arg == "-iwithprefix" || arg == "-iwithprefixbefore" || arg == "-isystem" || arg == "-isysroot" ) {
    283                                 args[nargs++] = argv[i];                                // pass flag along
    284                                 i += 1;
    285                                 args[nargs++] = argv[i];                                // pass argument along
    286288                        } else if ( arg[1] == 'l' ) {
    287289                                // if the user specifies a library, load it after user code
     
    335337        string libbase;
    336338        switch(path) {
    337           case Installed:
     339        case Installed:
    338340                args[nargs++] = "-I" CFA_INCDIR;
    339341                // do not use during build
     
    345347                libbase = CFA_LIBDIR;
    346348                break;
    347           case BuildTree:
    348           case Distributed:
     349        case BuildTree:
     350        case Distributed:
    349351                args[nargs++] = "-I" TOP_SRCDIR "libcfa/src";
    350352                // do not use during build
     
    380382        string libdir = libbase + arch + "-" + config;
    381383
    382         if ( path != Distributed ) {
     384        if (path != Distributed) {
    383385                if ( ! nolib && ! dirExists( libdir ) ) {
    384386                        cerr << argv[0] << " internal error, configuration " << config << " not installed." << endl;
     
    400402        string preludedir;
    401403        switch(path) {
    402           case Installed   : preludedir = libdir; break;
    403           case BuildTree   : preludedir = libdir + "/prelude"; break;
    404           case Distributed : preludedir = dir(argv[0]); break;
    405         } // switch
     404        case Installed   : preludedir = libdir; break;
     405        case BuildTree   : preludedir = libdir + "/prelude"; break;
     406        case Distributed : preludedir = dir(argv[0]); break;
     407        }
    406408
    407409        Putenv( argv, "--prelude-dir=" + preludedir );
     
    475477        if ( bprefix.length() == 0 ) {
    476478                switch(path) {
    477                   case Installed   : bprefix = installlibdir; break;
    478                   case BuildTree   : bprefix = srcdriverdir ; break;
    479                   case Distributed : bprefix = dir(argv[0]) ; break;
    480                 } // switch
    481         } // if
    482         if ( bprefix[bprefix.length() - 1] != '/' ) bprefix += '/';
    483         Putenv( argv, string("-B=") + bprefix );
     479                case Installed   : bprefix = installlibdir; break;
     480                case BuildTree   : bprefix = srcdriverdir ; break;
     481                case Distributed : bprefix = dir(argv[0]) ; break;
     482                }
     483                if ( bprefix[bprefix.length() - 1] != '/' ) bprefix += '/';
     484                Putenv( argv, string("-B=") + bprefix );
     485        } // if
    484486
    485487        args[nargs++] = "-Xlinker";                                                     // used by backtrace
     
    503505                args[nargs++] = "-Wno-cast-function-type";
    504506                #endif // HAVE_CAST_FUNCTION_TYPE
    505                 if ( ! std_flag && ! x_flag ) {
    506                         args[nargs++] = "-std=gnu11";                           // default c11, if none specified
     507                if ( ! std_flag ) {                                                             // default c11, if none specified
     508                        args[nargs++] = "-std=gnu11";
    507509                } // if
    508510                args[nargs++] = "-fgnu89-inline";
     
    554556        // execute the command and return the result
    555557
    556         execvp( args[0], (char * const *)args );                        // should not return
     558        execvp( args[0], (char *const *)args );                         // should not return
    557559        perror( "CFA Translator error: execvp" );
    558560        exit( EXIT_FAILURE );
  • libcfa/src/bits/locks.hfa

    r13d33a75 ref9988b  
    219219                }
    220220        }
    221 
    222         // Semaphore which only supports a single thread and one post
    223         // Semaphore which only supports a single thread
    224         struct oneshot {
    225                 struct $thread * volatile ptr;
    226         };
    227 
    228         static inline {
    229                 void  ?{}(oneshot & this) {
    230                         this.ptr = 0p;
    231                 }
    232 
    233                 void ^?{}(oneshot & this) {}
    234 
    235                 bool wait(oneshot & this) {
    236                         for() {
    237                                 struct $thread * expected = this.ptr;
    238                                 if(expected == 1p) return false;
    239                                 /* paranoid */ verify( expected == 0p );
    240                                 if(__atomic_compare_exchange_n(&this.ptr, &expected, active_thread(), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    241                                         park( __cfaabi_dbg_ctx );
    242                                         /* paranoid */ verify( this.ptr == 1p );
    243                                         return true;
    244                                 }
    245                         }
    246                 }
    247 
    248                 bool post(oneshot & this) {
    249                         struct $thread * got = __atomic_exchange_n( &this.ptr, 1p, __ATOMIC_SEQ_CST);
    250                         if( got == 0p ) return false;
    251                         unpark( got __cfaabi_dbg_ctx2 );
    252                         return true;
    253                 }
    254         }
    255221#endif
  • libcfa/src/common.hfa

    r13d33a75 ref9988b  
    1010// Created On       : Wed Jul 11 17:54:36 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Aug 15 08:51:29 2020
    13 // Update Count     : 14
     12// Last Modified On : Thu Jul 12 08:02:18 2018
     13// Update Count     : 5
    1414//
    1515
     
    6767
    6868static inline {
    69         char min( char t1, char t2 ) { return t1 < t2 ? t1 : t2; } // optimization
    70         intptr_t min( intptr_t t1, intptr_t t2 ) { return t1 < t2 ? t1 : t2; } // optimization
    71         uintptr_t min( uintptr_t t1, uintptr_t t2 ) { return t1 < t2 ? t1 : t2; } // optimization
    7269        forall( otype T | { int ?<?( T, T ); } )
    7370        T min( T t1, T t2 ) { return t1 < t2 ? t1 : t2; }
    7471
    75         char max( char t1, char t2 ) { return t1 > t2 ? t1 : t2; } // optimization
    76         intptr_t max( intptr_t t1, intptr_t t2 ) { return t1 > t2 ? t1 : t2; } // optimization
    77         uintptr_t max( uintptr_t t1, uintptr_t t2 ) { return t1 > t2 ? t1 : t2; } // optimization
    7872        forall( otype T | { int ?>?( T, T ); } )
    7973        T max( T t1, T t2 ) { return t1 > t2 ? t1 : t2; }
  • libcfa/src/concurrency/coroutine.cfa

    r13d33a75 ref9988b  
    215215                return cor;
    216216        }
    217 
    218         struct $coroutine * __cfactx_cor_active(void) {
    219                 return active_coroutine();
    220         }
    221217}
    222218
  • libcfa/src/concurrency/invoke.c

    r13d33a75 ref9988b  
    2929// Called from the kernel when starting a coroutine or task so must switch back to user mode.
    3030
    31 extern struct $coroutine * __cfactx_cor_active(void);
    3231extern struct $coroutine * __cfactx_cor_finish(void);
    3332extern void __cfactx_cor_leave ( struct $coroutine * );
     
    3635extern void disable_interrupts() OPTIONAL_THREAD;
    3736extern void enable_interrupts( __cfaabi_dbg_ctx_param );
    38 
    39 struct exception_context_t * this_exception_context() {
    40         return &__get_stack( __cfactx_cor_active() )->exception_context;
    41 }
    4237
    4338void __cfactx_invoke_coroutine(
  • libcfa/src/concurrency/invoke.h

    r13d33a75 ref9988b  
    2626#ifndef _INVOKE_H_
    2727#define _INVOKE_H_
    28 
    29         struct __cfaehm_try_resume_node;
    30         struct __cfaehm_base_exception_t;
    31         struct exception_context_t {
    32                 struct __cfaehm_try_resume_node * top_resume;
    33                 struct __cfaehm_base_exception_t * current_exception;
    34         };
    3528
    3629        struct __stack_context_t {
     
    5851                // base of stack
    5952                void * base;
    60 
    61                 // Information for exception handling.
    62                 struct exception_context_t exception_context;
    6353        };
    6454
     
    9484        };
    9585
    96         static inline struct __stack_t * __get_stack( struct $coroutine * cor ) {
    97                 return (struct __stack_t*)(((uintptr_t)cor->stack.storage) & ((uintptr_t)-2));
    98         }
    99 
    100         struct exception_context_t * this_exception_context();
     86        static inline struct __stack_t * __get_stack( struct $coroutine * cor ) { return (struct __stack_t*)(((uintptr_t)cor->stack.storage) & ((uintptr_t)-2)); }
    10187
    10288        // struct which calls the monitor is accepting
  • libcfa/src/concurrency/io.cfa

    r13d33a75 ref9988b  
    4141        #include "kernel/fwd.hfa"
    4242        #include "io/types.hfa"
    43 
    44         // returns true of acquired as leader or second leader
    45         static inline bool try_lock( __leaderlock_t & this ) {
    46                 const uintptr_t thrd = 1z | (uintptr_t)active_thread();
    47                 bool block;
    48                 disable_interrupts();
    49                 for() {
    50                         struct $thread * expected = this.value;
    51                         if( 1p != expected && 0p != expected ) {
    52                                 /* paranoid */ verify( thrd != (uintptr_t)expected ); // We better not already be the next leader
    53                                 enable_interrupts( __cfaabi_dbg_ctx );
    54                                 return false;
    55                         }
    56                         struct $thread * desired;
    57                         if( 0p == expected ) {
    58                                 // If the lock isn't locked acquire it, no need to block
    59                                 desired = 1p;
    60                                 block = false;
    61                         }
    62                         else {
    63                                 // If the lock is already locked try becomming the next leader
    64                                 desired = (struct $thread *)thrd;
    65                                 block = true;
    66                         }
    67                         if( __atomic_compare_exchange_n(&this.value, &expected, desired, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ) break;
    68                 }
    69                 if( block ) {
    70                         enable_interrupts( __cfaabi_dbg_ctx );
    71                         park( __cfaabi_dbg_ctx );
    72                         disable_interrupts();
    73                 }
    74                 return true;
    75         }
    76 
    77         static inline bool next( __leaderlock_t & this ) {
    78                 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    79                 struct $thread * nextt;
    80                 for() {
    81                         struct $thread * expected = this.value;
    82                         /* paranoid */ verify( (1 & (uintptr_t)expected) == 1 ); // The lock better be locked
    83 
    84                         struct $thread * desired;
    85                         if( 1p == expected ) {
    86                                 // No next leader, just unlock
    87                                 desired = 0p;
    88                                 nextt   = 0p;
    89                         }
    90                         else {
    91                                 // There is a next leader, remove but keep locked
    92                                 desired = 1p;
    93                                 nextt   = (struct $thread *)(~1z & (uintptr_t)expected);
    94                         }
    95                         if( __atomic_compare_exchange_n(&this.value, &expected, desired, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ) break;
    96                 }
    97 
    98                 if(nextt) {
    99                         unpark( nextt __cfaabi_dbg_ctx2 );
    100                         enable_interrupts( __cfaabi_dbg_ctx );
    101                         return true;
    102                 }
    103                 enable_interrupts( __cfaabi_dbg_ctx );
    104                 return false;
    105         }
    10643
    10744//=============================================================================================
     
    15693//=============================================================================================
    15794        static unsigned __collect_submitions( struct __io_data & ring );
    158         static __u32 __release_consumed_submission( struct __io_data & ring );
     95        static uint32_t __release_consumed_submission( struct __io_data & ring );
    15996
    16097        static inline void process(struct io_uring_cqe & cqe ) {
     
    163100
    164101                data->result = cqe.res;
    165                 post( data->sem );
     102                unpark( data->thrd __cfaabi_dbg_ctx2 );
    166103        }
    167104
     
    199136                unsigned head = *ring.completion_q.head;
    200137                unsigned tail = *ring.completion_q.tail;
    201                 const __u32 mask = *ring.completion_q.mask;
     138                const uint32_t mask = *ring.completion_q.mask;
    202139
    203140                // Nothing was new return 0
     
    206143                }
    207144
    208                 __u32 count = tail - head;
     145                uint32_t count = tail - head;
    209146                /* paranoid */ verify( count != 0 );
    210147                for(i; count) {
     
    245182                                __STATS__( true,
    246183                                        io.complete_q.completed_avg.val += count;
    247                                         io.complete_q.completed_avg.cnt += 1;
     184                                        io.complete_q.completed_avg.fast_cnt += 1;
    248185                                )
    249186                        enable_interrupts( __cfaabi_dbg_ctx );
     
    255192                        // We didn't get anything baton pass to the slow poller
    256193                        else {
    257                                 __STATS__( false,
    258                                         io.complete_q.blocks += 1;
    259                                 )
    260194                                __cfadbg_print_safe(io_core, "Kernel I/O : Parking io poller %p\n", &this.self);
    261195                                reset = 0;
     
    290224//
    291225
    292         [* struct io_uring_sqe, __u32] __submit_alloc( struct __io_data & ring, __u64 data ) {
     226        [* struct io_uring_sqe, uint32_t] __submit_alloc( struct __io_data & ring, uint64_t data ) {
    293227                /* paranoid */ verify( data != 0 );
    294228
     
    296230                __attribute((unused)) int len   = 0;
    297231                __attribute((unused)) int block = 0;
    298                 __u32 cnt = *ring.submit_q.num;
    299                 __u32 mask = *ring.submit_q.mask;
     232                uint32_t cnt = *ring.submit_q.num;
     233                uint32_t mask = *ring.submit_q.mask;
    300234
    301235                disable_interrupts();
    302                         __u32 off = __tls_rand();
     236                        uint32_t off = __tls_rand();
    303237                enable_interrupts( __cfaabi_dbg_ctx );
    304238
     
    307241                        // Look through the list starting at some offset
    308242                        for(i; cnt) {
    309                                 __u64 expected = 0;
    310                                 __u32 idx = (i + off) & mask;
     243                                uint64_t expected = 0;
     244                                uint32_t idx = (i + off) & mask;
    311245                                struct io_uring_sqe * sqe = &ring.submit_q.sqes[idx];
    312                                 volatile __u64 * udata = &sqe->user_data;
     246                                volatile uint64_t * udata = (volatile uint64_t *)&sqe->user_data;
    313247
    314248                                if( *udata == expected &&
     
    336270        }
    337271
    338         static inline __u32 __submit_to_ready_array( struct __io_data & ring, __u32 idx, const __u32 mask ) {
     272        static inline uint32_t __submit_to_ready_array( struct __io_data & ring, uint32_t idx, const uint32_t mask ) {
    339273                /* paranoid */ verify( idx <= mask   );
    340274                /* paranoid */ verify( idx != -1ul32 );
     
    343277                __attribute((unused)) int len   = 0;
    344278                __attribute((unused)) int block = 0;
    345                 __u32 ready_mask = ring.submit_q.ready_cnt - 1;
     279                uint32_t ready_mask = ring.submit_q.ready_cnt - 1;
    346280
    347281                disable_interrupts();
    348                         __u32 off = __tls_rand();
     282                        uint32_t off = __tls_rand();
    349283                enable_interrupts( __cfaabi_dbg_ctx );
    350284
    351                 __u32 picked;
     285                uint32_t picked;
    352286                LOOKING: for() {
    353287                        for(i; ring.submit_q.ready_cnt) {
    354288                                picked = (i + off) & ready_mask;
    355                                 __u32 expected = -1ul32;
     289                                uint32_t expected = -1ul32;
    356290                                if( __atomic_compare_exchange_n( &ring.submit_q.ready[picked], &expected, idx, true, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED ) ) {
    357291                                        break LOOKING;
     
    363297
    364298                        block++;
    365 
    366                         __u32 released = __release_consumed_submission( ring );
    367                         if( released == 0 ) {
     299                        if( try_lock(ring.submit_q.lock __cfaabi_dbg_ctx2) ) {
     300                                __release_consumed_submission( ring );
     301                                unlock( ring.submit_q.lock );
     302                        }
     303                        else {
    368304                                yield();
    369305                        }
     
    380316        }
    381317
    382         void __submit( struct io_context * ctx, __u32 idx ) __attribute__((nonnull (1))) {
     318        void __submit( struct io_context * ctx, uint32_t idx ) __attribute__((nonnull (1))) {
    383319                __io_data & ring = *ctx->thrd.ring;
    384320                // Get now the data we definetely need
    385                 volatile __u32 * const tail = ring.submit_q.tail;
    386                 const __u32 mask  = *ring.submit_q.mask;
     321                volatile uint32_t * const tail = ring.submit_q.tail;
     322                const uint32_t mask  = *ring.submit_q.mask;
    387323
    388324                // There are 2 submission schemes, check which one we are using
     
    396332                }
    397333                else if( ring.eager_submits ) {
    398                         __u32 picked = __submit_to_ready_array( ring, idx, mask );
    399 
    400                         #if defined(LEADER_LOCK)
    401                                 if( !try_lock(ring.submit_q.submit_lock) ) {
     334                        uint32_t picked = __submit_to_ready_array( ring, idx, mask );
     335
     336                        for() {
     337                                yield();
     338
     339                                // If some one else collected our index, we are done
     340                                #warning ABA problem
     341                                if( ring.submit_q.ready[picked] != idx ) {
    402342                                        __STATS__( false,
    403343                                                io.submit_q.helped += 1;
     
    405345                                        return;
    406346                                }
    407                                 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    408                                 __STATS__( true,
    409                                         io.submit_q.leader += 1;
     347
     348                                if( try_lock(ring.submit_q.lock __cfaabi_dbg_ctx2) ) {
     349                                        __STATS__( false,
     350                                                io.submit_q.leader += 1;
     351                                        )
     352                                        break;
     353                                }
     354
     355                                __STATS__( false,
     356                                        io.submit_q.busy += 1;
    410357                                )
    411                         #else
    412                                 for() {
    413                                         yield();
    414 
    415                                         if( try_lock(ring.submit_q.submit_lock __cfaabi_dbg_ctx2) ) {
    416                                                 __STATS__( false,
    417                                                         io.submit_q.leader += 1;
    418                                                 )
    419                                                 break;
    420                                         }
    421 
    422                                         // If some one else collected our index, we are done
    423                                         #warning ABA problem
    424                                         if( ring.submit_q.ready[picked] != idx ) {
    425                                                 __STATS__( false,
    426                                                         io.submit_q.helped += 1;
    427                                                 )
    428                                                 return;
    429                                         }
    430 
    431                                         __STATS__( false,
    432                                                 io.submit_q.busy += 1;
    433                                         )
    434                                 }
    435                         #endif
     358                        }
    436359
    437360                        // We got the lock
    438                         // Collect the submissions
    439361                        unsigned to_submit = __collect_submitions( ring );
    440 
    441                         // Actually submit
    442362                        int ret = __io_uring_enter( ring, to_submit, false );
    443 
    444                         #if defined(LEADER_LOCK)
    445                                 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    446                                 next(ring.submit_q.submit_lock);
    447                         #else
    448                                 unlock(ring.submit_q.submit_lock);
    449                         #endif
    450                         if( ret < 0 ) return;
     363                        if( ret < 0 ) {
     364                                unlock(ring.submit_q.lock);
     365                                return;
     366                        }
     367
     368                        /* paranoid */ verify( ret > 0 || to_submit == 0 || (ring.ring_flags & IORING_SETUP_SQPOLL) );
    451369
    452370                        // Release the consumed SQEs
     
    454372
    455373                        // update statistics
    456                         __STATS__( false,
     374                        __STATS__( true,
    457375                                io.submit_q.submit_avg.rdy += to_submit;
    458376                                io.submit_q.submit_avg.csm += ret;
    459377                                io.submit_q.submit_avg.cnt += 1;
    460378                        )
     379
     380                        unlock(ring.submit_q.lock);
    461381                }
    462382                else {
    463383                        // get mutual exclusion
    464                         #if defined(LEADER_LOCK)
    465                                 while(!try_lock(ring.submit_q.submit_lock));
    466                         #else
    467                                 lock(ring.submit_q.submit_lock __cfaabi_dbg_ctx2);
    468                         #endif
     384                        lock(ring.submit_q.lock __cfaabi_dbg_ctx2);
    469385
    470386                        /* paranoid */ verifyf( ring.submit_q.sqes[ idx ].user_data != 0,
     
    504420                        __release_consumed_submission( ring );
    505421
    506                         #if defined(LEADER_LOCK)
    507                                 next(ring.submit_q.submit_lock);
    508                         #else
    509                                 unlock(ring.submit_q.submit_lock);
    510                         #endif
     422                        unlock(ring.submit_q.lock);
    511423
    512424                        __cfadbg_print_safe( io, "Kernel I/O : Performed io_submit for %p, returned %d\n", active_thread(), ret );
     
    514426        }
    515427
    516         // #define PARTIAL_SUBMIT 32
    517428        static unsigned __collect_submitions( struct __io_data & ring ) {
    518429                /* paranoid */ verify( ring.submit_q.ready != 0p );
     
    520431
    521432                unsigned to_submit = 0;
    522                 __u32 tail = *ring.submit_q.tail;
    523                 const __u32 mask = *ring.submit_q.mask;
    524                 #if defined(PARTIAL_SUBMIT)
    525                         #if defined(LEADER_LOCK)
    526                                 #error PARTIAL_SUBMIT and LEADER_LOCK cannot co-exist
    527                         #endif
    528                         const __u32 cnt = ring.submit_q.ready_cnt > PARTIAL_SUBMIT ? PARTIAL_SUBMIT : ring.submit_q.ready_cnt;
    529                         const __u32 offset = ring.submit_q.prev_ready;
    530                         ring.submit_q.prev_ready += cnt;
    531                 #else
    532                         const __u32 cnt = ring.submit_q.ready_cnt;
    533                         const __u32 offset = 0;
    534                 #endif
     433                uint32_t tail = *ring.submit_q.tail;
     434                const uint32_t mask = *ring.submit_q.mask;
    535435
    536436                // Go through the list of ready submissions
    537                 for( c; cnt ) {
    538                         __u32 i = (offset + c) % ring.submit_q.ready_cnt;
    539 
     437                for( i; ring.submit_q.ready_cnt ) {
    540438                        // replace any submission with the sentinel, to consume it.
    541                         __u32 idx = __atomic_exchange_n( &ring.submit_q.ready[i], -1ul32, __ATOMIC_RELAXED);
     439                        uint32_t idx = __atomic_exchange_n( &ring.submit_q.ready[i], -1ul32, __ATOMIC_RELAXED);
    542440
    543441                        // If it was already the sentinel, then we are done
     
    555453        }
    556454
    557         static __u32 __release_consumed_submission( struct __io_data & ring ) {
    558                 const __u32 smask = *ring.submit_q.mask;
     455        static uint32_t __release_consumed_submission( struct __io_data & ring ) {
     456                const uint32_t smask = *ring.submit_q.mask;
    559457
    560458                if( !try_lock(ring.submit_q.release_lock __cfaabi_dbg_ctx2) ) return 0;
    561                 __u32 chead = *ring.submit_q.head;
    562                 __u32 phead = ring.submit_q.prev_head;
     459                uint32_t chead = *ring.submit_q.head;
     460                uint32_t phead = ring.submit_q.prev_head;
    563461                ring.submit_q.prev_head = chead;
    564462                unlock(ring.submit_q.release_lock);
    565463
    566                 __u32 count = chead - phead;
     464                uint32_t count = chead - phead;
    567465                for( i; count ) {
    568                         __u32 idx = ring.submit_q.array[ (phead + i) & smask ];
     466                        uint32_t idx = ring.submit_q.array[ (phead + i) & smask ];
    569467                        ring.submit_q.sqes[ idx ].user_data = 0;
    570468                }
  • libcfa/src/concurrency/io/setup.cfa

    r13d33a75 ref9988b  
    298298                if( params_in.poll_complete ) params.flags |= IORING_SETUP_IOPOLL;
    299299
    300                 __u32 nentries = params_in.num_entries != 0 ? params_in.num_entries : 256;
    301                 if( !is_pow2(nentries) ) {
    302                         abort("ERROR: I/O setup 'num_entries' must be a power of 2\n");
    303                 }
    304                 if( params_in.poller_submits && params_in.eager_submits ) {
    305                         abort("ERROR: I/O setup 'poller_submits' and 'eager_submits' cannot be used together\n");
    306                 }
     300                uint32_t nentries = params_in.num_entries;
    307301
    308302                int fd = syscall(__NR_io_uring_setup, nentries, &params );
     
    362356                // Get the pointers from the kernel to fill the structure
    363357                // submit queue
    364                 sq.head    = (volatile __u32 *)(((intptr_t)sq.ring_ptr) + params.sq_off.head);
    365                 sq.tail    = (volatile __u32 *)(((intptr_t)sq.ring_ptr) + params.sq_off.tail);
    366                 sq.mask    = (   const __u32 *)(((intptr_t)sq.ring_ptr) + params.sq_off.ring_mask);
    367                 sq.num     = (   const __u32 *)(((intptr_t)sq.ring_ptr) + params.sq_off.ring_entries);
    368                 sq.flags   = (         __u32 *)(((intptr_t)sq.ring_ptr) + params.sq_off.flags);
    369                 sq.dropped = (         __u32 *)(((intptr_t)sq.ring_ptr) + params.sq_off.dropped);
    370                 sq.array   = (         __u32 *)(((intptr_t)sq.ring_ptr) + params.sq_off.array);
     358                sq.head    = (volatile uint32_t *)(((intptr_t)sq.ring_ptr) + params.sq_off.head);
     359                sq.tail    = (volatile uint32_t *)(((intptr_t)sq.ring_ptr) + params.sq_off.tail);
     360                sq.mask    = (   const uint32_t *)(((intptr_t)sq.ring_ptr) + params.sq_off.ring_mask);
     361                sq.num     = (   const uint32_t *)(((intptr_t)sq.ring_ptr) + params.sq_off.ring_entries);
     362                sq.flags   = (         uint32_t *)(((intptr_t)sq.ring_ptr) + params.sq_off.flags);
     363                sq.dropped = (         uint32_t *)(((intptr_t)sq.ring_ptr) + params.sq_off.dropped);
     364                sq.array   = (         uint32_t *)(((intptr_t)sq.ring_ptr) + params.sq_off.array);
    371365                sq.prev_head = *sq.head;
    372366
    373367                {
    374                         const __u32 num = *sq.num;
     368                        const uint32_t num = *sq.num;
    375369                        for( i; num ) {
    376370                                sq.sqes[i].user_data = 0ul64;
     
    378372                }
    379373
    380                 (sq.submit_lock){};
     374                (sq.lock){};
    381375                (sq.release_lock){};
    382376
     
    388382                                sq.ready[i] = -1ul32;
    389383                        }
    390                         sq.prev_ready = 0;
    391384                }
    392385                else {
    393386                        sq.ready_cnt = 0;
    394387                        sq.ready = 0p;
    395                         sq.prev_ready = 0;
    396388                }
    397389
    398390                // completion queue
    399                 cq.head      = (volatile __u32 *)(((intptr_t)cq.ring_ptr) + params.cq_off.head);
    400                 cq.tail      = (volatile __u32 *)(((intptr_t)cq.ring_ptr) + params.cq_off.tail);
    401                 cq.mask      = (   const __u32 *)(((intptr_t)cq.ring_ptr) + params.cq_off.ring_mask);
    402                 cq.num       = (   const __u32 *)(((intptr_t)cq.ring_ptr) + params.cq_off.ring_entries);
    403                 cq.overflow  = (         __u32 *)(((intptr_t)cq.ring_ptr) + params.cq_off.overflow);
    404                 cq.cqes = (struct io_uring_cqe *)(((intptr_t)cq.ring_ptr) + params.cq_off.cqes);
     391                cq.head     = (volatile uint32_t *)(((intptr_t)cq.ring_ptr) + params.cq_off.head);
     392                cq.tail     = (volatile uint32_t *)(((intptr_t)cq.ring_ptr) + params.cq_off.tail);
     393                cq.mask     = (   const uint32_t *)(((intptr_t)cq.ring_ptr) + params.cq_off.ring_mask);
     394                cq.num      = (   const uint32_t *)(((intptr_t)cq.ring_ptr) + params.cq_off.ring_entries);
     395                cq.overflow = (         uint32_t *)(((intptr_t)cq.ring_ptr) + params.cq_off.overflow);
     396                cq.cqes   = (struct io_uring_cqe *)(((intptr_t)cq.ring_ptr) + params.cq_off.cqes);
    405397
    406398                // some paranoid checks
     
    450442        void __ioctx_register($io_ctx_thread & ctx, struct epoll_event & ev) {
    451443                ev.events = EPOLLIN | EPOLLONESHOT;
    452                 ev.data.u64 = (__u64)&ctx;
     444                ev.data.u64 = (uint64_t)&ctx;
    453445                int ret = epoll_ctl(iopoll.epollfd, EPOLL_CTL_ADD, ctx.ring->fd, &ev);
    454446                if (ret < 0) {
  • libcfa/src/concurrency/io/types.hfa

    r13d33a75 ref9988b  
    1717
    1818#if defined(CFA_HAVE_LINUX_IO_URING_H)
    19         extern "C" {
    20                 #include <linux/types.h>
    21         }
    22 
    2319      #include "bits/locks.hfa"
    24 
    25         #define LEADER_LOCK
    26         struct __leaderlock_t {
    27                 struct $thread * volatile value;        // ($thread) next_leader | (bool:1) is_locked
    28         };
    29 
    30         static inline void ?{}( __leaderlock_t & this ) { this.value = 0p; }
    3120
    3221        //-----------------------------------------------------------------------
     
    3423      struct __submition_data {
    3524                // Head and tail of the ring (associated with array)
    36                 volatile __u32 * head;
    37                 volatile __u32 * tail;
    38                 volatile __u32 prev_head;
     25                volatile uint32_t * head;
     26                volatile uint32_t * tail;
     27                volatile uint32_t prev_head;
    3928
    4029                // The actual kernel ring which uses head/tail
    4130                // indexes into the sqes arrays
    42                 __u32 * array;
     31                uint32_t * array;
    4332
    4433                // number of entries and mask to go with it
    45                 const __u32 * num;
    46                 const __u32 * mask;
     34                const uint32_t * num;
     35                const uint32_t * mask;
    4736
    4837                // Submission flags (Not sure what for)
    49                 __u32 * flags;
     38                uint32_t * flags;
    5039
    5140                // number of sqes not submitted (whatever that means)
    52                 __u32 * dropped;
     41                uint32_t * dropped;
    5342
    5443                // Like head/tail but not seen by the kernel
    55                 volatile __u32 * ready;
    56                 __u32 ready_cnt;
    57                 __u32 prev_ready;
     44                volatile uint32_t * ready;
     45                uint32_t ready_cnt;
    5846
    59                 #if defined(LEADER_LOCK)
    60                         __leaderlock_t submit_lock;
    61                 #else
    62                         __spinlock_t submit_lock;
    63                 #endif
    64                 __spinlock_t  release_lock;
     47                __spinlock_t lock;
     48                __spinlock_t release_lock;
    6549
    6650                // A buffer of sqes (not the actual ring)
     
    7458        struct __completion_data {
    7559                // Head and tail of the ring
    76                 volatile __u32 * head;
    77                 volatile __u32 * tail;
     60                volatile uint32_t * head;
     61                volatile uint32_t * tail;
    7862
    7963                // number of entries and mask to go with it
    80                 const __u32 * mask;
    81                 const __u32 * num;
     64                const uint32_t * mask;
     65                const uint32_t * num;
    8266
    8367                // number of cqes not submitted (whatever that means)
    84                 __u32 * overflow;
     68                uint32_t * overflow;
    8569
    8670                // the kernel ring
     
    9579                struct __submition_data submit_q;
    9680                struct __completion_data completion_q;
    97                 __u32 ring_flags;
     81                uint32_t ring_flags;
    9882                int fd;
    9983                bool eager_submits:1;
     
    10589        // IO user data
    10690        struct __io_user_data_t {
    107                 __s32 result;
    108                 oneshot sem;
     91                int32_t result;
     92                $thread * thrd;
    10993        };
    11094
  • libcfa/src/concurrency/iocall.cfa

    r13d33a75 ref9988b  
    3232        #include "io/types.hfa"
    3333
    34         extern [* struct io_uring_sqe, __u32] __submit_alloc( struct __io_data & ring, __u64 data );
    35         extern void __submit( struct io_context * ctx, __u32 idx ) __attribute__((nonnull (1)));
    36 
    37         static inline void ?{}(struct io_uring_sqe & this, __u8 opcode, int fd) {
     34        extern [* struct io_uring_sqe, uint32_t] __submit_alloc( struct __io_data & ring, uint64_t data );
     35        extern void __submit( struct io_context * ctx, uint32_t idx ) __attribute__((nonnull (1)));
     36
     37        static inline void ?{}(struct io_uring_sqe & this, uint8_t opcode, int fd) {
    3838                this.opcode = opcode;
    3939                #if !defined(IOSQE_ASYNC)
     
    5151        }
    5252
    53         static inline void ?{}(struct io_uring_sqe & this, __u8 opcode, int fd, void * addr, __u32 len, __u64 off ) {
     53        static inline void ?{}(struct io_uring_sqe & this, uint8_t opcode, int fd, void * addr, uint32_t len, uint64_t off ) {
    5454                (this){ opcode, fd };
    5555                this.off = off;
    56                 this.addr = (__u64)(uintptr_t)addr;
     56                this.addr = (uint64_t)(uintptr_t)addr;
    5757                this.len = len;
    5858        }
     
    101101        #endif
    102102
     103
    103104        #define __submit_prelude \
    104105                if( 0 != (submit_flags & LINK_FLAGS) ) { errno = ENOTSUP; return -1; } \
    105106                (void)timeout; (void)cancellation; \
    106107                if( !context ) context = __get_io_context(); \
    107                 __io_user_data_t data = { 0 }; \
     108                __io_user_data_t data = { 0, active_thread() }; \
    108109                struct __io_data & ring = *context->thrd.ring; \
    109110                struct io_uring_sqe * sqe; \
    110                 __u32 idx; \
    111                 __u8 sflags = REGULAR_FLAGS & submit_flags; \
    112                 [sqe, idx] = __submit_alloc( ring, (__u64)(uintptr_t)&data ); \
    113                 sqe->flags = sflags;
     111                uint32_t idx; \
     112                [sqe, idx] = __submit_alloc( ring, (uint64_t)(uintptr_t)&data ); \
     113                sqe->flags = REGULAR_FLAGS & submit_flags;
    114114
    115115        #define __submit_wait \
    116116                /*__cfaabi_bits_print_safe( STDERR_FILENO, "Preparing user data %p for %p\n", &data, data.thrd );*/ \
    117                 verify( sqe->user_data == (__u64)(uintptr_t)&data ); \
     117                verify( sqe->user_data == (uint64_t)(uintptr_t)&data ); \
    118118                __submit( context, idx ); \
    119                 wait( data.sem ); \
     119                park( __cfaabi_dbg_ctx ); \
    120120                if( data.result < 0 ) { \
    121121                        errno = -data.result; \
     
    149149
    150150        extern int fsync(int fd);
    151 
    152         typedef __off64_t off_t;
    153         typedef __off64_t off64_t;
    154         extern int sync_file_range(int fd, off64_t offset, off64_t nbytes, unsigned int flags);
     151        extern int sync_file_range(int fd, int64_t offset, int64_t nbytes, unsigned int flags);
    155152
    156153        struct msghdr;
     
    163160        extern int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
    164161
    165         extern int fallocate(int fd, int mode, off_t offset, off_t len);
    166         extern int posix_fadvise(int fd, off_t offset, off_t len, int advice);
     162        extern int fallocate(int fd, int mode, uint64_t offset, uint64_t len);
     163        extern int posix_fadvise(int fd, uint64_t offset, uint64_t len, int advice);
    167164        extern int madvise(void *addr, size_t length, int advice);
    168165
     
    189186                        __submit_prelude
    190187
    191                         sqe->opcode = IORING_OP_READV;
    192                         sqe->ioprio = 0;
    193                         sqe->fd = fd;
    194                         sqe->off = offset;
    195                         sqe->addr = (__u64)iov;
    196                         sqe->len = iovcnt;
    197                         sqe->rw_flags = 0;
    198                         sqe->__pad2[0] = sqe->__pad2[1] = sqe->__pad2[2] = 0;
     188                        (*sqe){ IORING_OP_READV, fd, iov, iovcnt, offset };
    199189
    200190                        __submit_wait
     
    210200                        __submit_prelude
    211201
    212                         sqe->opcode = IORING_OP_WRITEV;
    213                         sqe->ioprio = 0;
    214                         sqe->fd = fd;
    215                         sqe->off = offset;
    216                         sqe->addr = (__u64)iov;
    217                         sqe->len = iovcnt;
    218                         sqe->rw_flags = 0;
    219                         sqe->__pad2[0] = sqe->__pad2[1] = sqe->__pad2[2] = 0;
     202                        (*sqe){ IORING_OP_WRITEV, fd, iov, iovcnt, offset };
    220203
    221204                        __submit_wait
     
    230213                __submit_prelude
    231214
    232                 sqe->opcode = IORING_OP_FSYNC;
    233                 sqe->ioprio = 0;
    234                 sqe->fd = fd;
    235                 sqe->off = 0;
    236                 sqe->addr = 0;
    237                 sqe->len = 0;
    238                 sqe->rw_flags = 0;
    239                 sqe->__pad2[0] = sqe->__pad2[1] = sqe->__pad2[2] = 0;
    240 
    241                 __submit_wait
    242         #endif
    243 }
    244 
    245 int cfa_sync_file_range(int fd, off64_t offset, off64_t nbytes, unsigned int flags, int submit_flags, Duration timeout, io_cancellation * cancellation, io_context * context) {
     215                (*sqe){ IORING_OP_FSYNC, fd };
     216
     217                __submit_wait
     218        #endif
     219}
     220
     221int cfa_sync_file_range(int fd, int64_t offset, int64_t nbytes, unsigned int flags, int submit_flags, Duration timeout, io_cancellation * cancellation, io_context * context) {
    246222        #if !defined(CFA_HAVE_LINUX_IO_URING_H) || !defined(CFA_HAVE_IORING_OP_SYNC_FILE_RANGE)
    247223                return sync_file_range(fd, offset, nbytes, flags);
     
    292268
    293269                (*sqe){ IORING_OP_SEND, sockfd };
    294                 sqe->addr = (__u64)buf;
     270                sqe->addr = (uint64_t)buf;
    295271                sqe->len = len;
    296272                sqe->msg_flags = flags;
     
    307283
    308284                (*sqe){ IORING_OP_RECV, sockfd };
    309                 sqe->addr = (__u64)buf;
     285                sqe->addr = (uint64_t)buf;
    310286                sqe->len = len;
    311287                sqe->msg_flags = flags;
     
    322298
    323299                (*sqe){ IORING_OP_ACCEPT, sockfd };
    324                 sqe->addr  = (__u64)addr;
    325                 sqe->addr2 = (__u64)addrlen;
     300                sqe->addr = (uint64_t)(uintptr_t)addr;
     301                sqe->addr2 = (uint64_t)(uintptr_t)addrlen;
    326302                sqe->accept_flags = flags;
    327303
     
    337313
    338314                (*sqe){ IORING_OP_CONNECT, sockfd };
    339                 sqe->addr = (__u64)addr;
    340                 sqe->off  = (__u64)addrlen;
    341 
    342                 __submit_wait
    343         #endif
    344 }
    345 
    346 int cfa_fallocate(int fd, int mode, off_t offset, off_t len, int submit_flags, Duration timeout, io_cancellation * cancellation, io_context * context) {
     315                sqe->addr = (uint64_t)(uintptr_t)addr;
     316                sqe->off  = (uint64_t)(uintptr_t)addrlen;
     317
     318                __submit_wait
     319        #endif
     320}
     321
     322int cfa_fallocate(int fd, int mode, uint64_t offset, uint64_t len, int submit_flags, Duration timeout, io_cancellation * cancellation, io_context * context) {
    347323        #if !defined(CFA_HAVE_LINUX_IO_URING_H) || !defined(CFA_HAVE_IORING_OP_FALLOCATE)
    348324                return fallocate( fd, mode, offset, len );
     
    361337}
    362338
    363 int cfa_fadvise(int fd, off_t offset, off_t len, int advice, int submit_flags, Duration timeout, io_cancellation * cancellation, io_context * context) {
     339int cfa_fadvise(int fd, uint64_t offset, uint64_t len, int advice, int submit_flags, Duration timeout, io_cancellation * cancellation, io_context * context) {
    364340        #if !defined(CFA_HAVE_LINUX_IO_URING_H) || !defined(CFA_HAVE_IORING_OP_FADVISE)
    365341                return posix_fadvise( fd, offset, len, advice );
     
    368344
    369345                (*sqe){ IORING_OP_FADVISE, fd };
    370                 sqe->off = (__u64)offset;
     346                sqe->off = (uint64_t)offset;
    371347                sqe->len = len;
    372348                sqe->fadvise_advice = advice;
     
    383359
    384360                (*sqe){ IORING_OP_MADVISE, 0 };
    385                 sqe->addr = (__u64)addr;
     361                sqe->addr = (uint64_t)addr;
    386362                sqe->len = length;
    387363                sqe->fadvise_advice = advice;
     
    398374
    399375                (*sqe){ IORING_OP_OPENAT, dirfd };
    400                 sqe->addr = (__u64)pathname;
     376                sqe->addr = (uint64_t)pathname;
    401377                sqe->open_flags = flags;
    402378                sqe->len = mode;
     
    431407                __submit_prelude
    432408
    433                 (*sqe){ IORING_OP_STATX, dirfd, pathname, mask, (__u64)statxbuf };
     409                (*sqe){ IORING_OP_STATX, dirfd, pathname, mask, (uint64_t)statxbuf };
    434410                sqe->statx_flags = flags;
    435411
     
    473449                }
    474450                else {
    475                         sqe->off = (__u64)-1;
     451                        sqe->off = (uint64_t)-1;
    476452                }
    477453                sqe->len = len;
     
    481457                }
    482458                else {
    483                         sqe->splice_off_in = (__u64)-1;
     459                        sqe->splice_off_in = (uint64_t)-1;
    484460                }
    485461                sqe->splice_flags  = flags | (SPLICE_FLAGS & submit_flags);
  • libcfa/src/concurrency/kernel.cfa

    r13d33a75 ref9988b  
    103103        // Do it here
    104104        kernelTLS.rand_seed ^= rdtscl();
    105         kernelTLS.ready_rng.fwd_seed = 25214903917_l64u * (rdtscl() ^ (uintptr_t)&runner);
    106         __tls_rand_advance_bck();
    107105
    108106        processor * this = runner.proc;
     
    534532                unsigned total   = this.total;
    535533                processor * proc = &this.list`first;
    536                 // Compiler fence is unnecessary, but gcc-8 and older incorrectly reorder code without it
    537                 asm volatile("": : :"memory");
     534                // Thread fence is unnecessary, but gcc-8 and older incorrectly reorder code without it
     535                __atomic_thread_fence(__ATOMIC_SEQ_CST);
    538536                if(l != __atomic_load_n(&this.lock, __ATOMIC_SEQ_CST)) { Pause(); continue; }
    539537                return [idle, total, proc];
  • libcfa/src/concurrency/kernel/fwd.hfa

    r13d33a75 ref9988b  
    5050                                uint64_t rand_seed;
    5151                        #endif
    52                         struct {
    53                                 uint64_t fwd_seed;
    54                                 uint64_t bck_seed;
    55                         } ready_rng;
    5652                } kernelTLS __attribute__ ((tls_model ( "initial-exec" )));
    57 
    58 
    5953
    6054                static inline uint64_t __tls_rand() {
     
    6458                                return __xorshift64( kernelTLS.rand_seed );
    6559                        #endif
    66                 }
    67 
    68                 #define M  (1_l64u << 48_l64u)
    69                 #define A  (25214903917_l64u)
    70                 #define AI (18446708753438544741_l64u)
    71                 #define C  (11_l64u)
    72                 #define D  (16_l64u)
    73 
    74                 static inline unsigned __tls_rand_fwd() {
    75 
    76                         kernelTLS.ready_rng.fwd_seed = (A * kernelTLS.ready_rng.fwd_seed + C) & (M - 1);
    77                         return kernelTLS.ready_rng.fwd_seed >> D;
    78                 }
    79 
    80                 static inline unsigned __tls_rand_bck() {
    81                         unsigned int r = kernelTLS.ready_rng.bck_seed >> D;
    82                         kernelTLS.ready_rng.bck_seed = AI * (kernelTLS.ready_rng.bck_seed - C) & (M - 1);
    83                         return r;
    84                 }
    85 
    86                 #undef M
    87                 #undef A
    88                 #undef AI
    89                 #undef C
    90                 #undef D
    91 
    92                 static inline void __tls_rand_advance_bck(void) {
    93                         kernelTLS.ready_rng.bck_seed = kernelTLS.ready_rng.fwd_seed;
    9460                }
    9561        }
  • libcfa/src/concurrency/kernel/startup.cfa

    r13d33a75 ref9988b  
    7878static void ?{}(processorCtx_t & this, processor * proc, current_stack_info_t * info);
    7979
    80 #if defined(__CFA_WITH_VERIFY__)
    81         static bool verify_fwd_bck_rng(void);
    82 #endif
    83 
    8480//-----------------------------------------------------------------------------
    8581// Forward Declarations for other modules
     
    162158        __cfa_dbg_global_clusters.list{ __get };
    163159        __cfa_dbg_global_clusters.lock{};
    164 
    165         /* paranoid */ verify( verify_fwd_bck_rng() );
    166160
    167161        // Initialize the global scheduler lock
     
    522516        ( this.terminated ){ 0 };
    523517        ( this.runner ){};
    524 
    525         disable_interrupts();
    526                 init( this, name, _cltr );
    527         enable_interrupts( __cfaabi_dbg_ctx );
     518        init( this, name, _cltr );
    528519
    529520        __cfadbg_print_safe(runtime_core, "Kernel : Starting core %p\n", &this);
     
    549540        free( this.stack );
    550541
    551         disable_interrupts();
    552                 deinit( this );
    553         enable_interrupts( __cfaabi_dbg_ctx );
     542        deinit( this );
    554543}
    555544
     
    683672        return stack;
    684673}
    685 
    686 #if defined(__CFA_WITH_VERIFY__)
    687 static bool verify_fwd_bck_rng(void) {
    688         kernelTLS.ready_rng.fwd_seed = 25214903917_l64u * (rdtscl() ^ (uintptr_t)&verify_fwd_bck_rng);
    689 
    690         unsigned values[10];
    691         for(i; 10) {
    692                 values[i] = __tls_rand_fwd();
    693         }
    694 
    695         __tls_rand_advance_bck();
    696 
    697         for ( i; 9 -~= 0 ) {
    698                 if(values[i] != __tls_rand_bck()) {
    699                         return false;
    700                 }
    701         }
    702 
    703         return true;
    704 }
    705 #endif
  • libcfa/src/concurrency/ready_queue.cfa

    r13d33a75 ref9988b  
    150150//  queues or removing them.
    151151uint_fast32_t ready_mutate_lock( void ) with(*__scheduler_lock) {
    152         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    153 
    154152        // Step 1 : lock global lock
    155153        // It is needed to avoid processors that register mid Critical-Section
     
    166164        }
    167165
    168         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    169166        return s;
    170167}
    171168
    172169void ready_mutate_unlock( uint_fast32_t last_s ) with(*__scheduler_lock) {
    173         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    174 
    175170        // Step 1 : release local locks
    176171        // This must be done while the global lock is held to avoid
     
    187182        /*paranoid*/ assert(true == lock);
    188183        __atomic_store_n(&lock, (bool)false, __ATOMIC_RELEASE);
    189 
    190         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    191184}
    192185
  • libcfa/src/concurrency/stats.cfa

    r13d33a75 ref9988b  
    3838                        stats->io.submit_q.busy   = 0;
    3939                        stats->io.complete_q.completed_avg.val = 0;
    40                         stats->io.complete_q.completed_avg.cnt = 0;
    41                         stats->io.complete_q.blocks = 0;
     40                        stats->io.complete_q.completed_avg.slow_cnt = 0;
     41                        stats->io.complete_q.completed_avg.fast_cnt = 0;
    4242                #endif
    4343        }
     
    6060
    6161                #if defined(CFA_HAVE_LINUX_IO_URING_H)
    62                         __atomic_fetch_add( &cltr->io.submit_q.submit_avg.rdy     , proc->io.submit_q.submit_avg.rdy     , __ATOMIC_SEQ_CST );
    63                         __atomic_fetch_add( &cltr->io.submit_q.submit_avg.csm     , proc->io.submit_q.submit_avg.csm     , __ATOMIC_SEQ_CST );
    64                         __atomic_fetch_add( &cltr->io.submit_q.submit_avg.avl     , proc->io.submit_q.submit_avg.avl     , __ATOMIC_SEQ_CST );
    65                         __atomic_fetch_add( &cltr->io.submit_q.submit_avg.cnt     , proc->io.submit_q.submit_avg.cnt     , __ATOMIC_SEQ_CST );
    66                         __atomic_fetch_add( &cltr->io.submit_q.look_avg.val       , proc->io.submit_q.look_avg.val       , __ATOMIC_SEQ_CST );
    67                         __atomic_fetch_add( &cltr->io.submit_q.look_avg.cnt       , proc->io.submit_q.look_avg.cnt       , __ATOMIC_SEQ_CST );
    68                         __atomic_fetch_add( &cltr->io.submit_q.look_avg.block     , proc->io.submit_q.look_avg.block     , __ATOMIC_SEQ_CST );
    69                         __atomic_fetch_add( &cltr->io.submit_q.alloc_avg.val      , proc->io.submit_q.alloc_avg.val      , __ATOMIC_SEQ_CST );
    70                         __atomic_fetch_add( &cltr->io.submit_q.alloc_avg.cnt      , proc->io.submit_q.alloc_avg.cnt      , __ATOMIC_SEQ_CST );
    71                         __atomic_fetch_add( &cltr->io.submit_q.alloc_avg.block    , proc->io.submit_q.alloc_avg.block    , __ATOMIC_SEQ_CST );
    72                         __atomic_fetch_add( &cltr->io.submit_q.helped             , proc->io.submit_q.helped             , __ATOMIC_SEQ_CST );
    73                         __atomic_fetch_add( &cltr->io.submit_q.leader             , proc->io.submit_q.leader             , __ATOMIC_SEQ_CST );
    74                         __atomic_fetch_add( &cltr->io.submit_q.busy               , proc->io.submit_q.busy               , __ATOMIC_SEQ_CST );
    75                         __atomic_fetch_add( &cltr->io.complete_q.completed_avg.val, proc->io.complete_q.completed_avg.val, __ATOMIC_SEQ_CST );
    76                         __atomic_fetch_add( &cltr->io.complete_q.completed_avg.cnt, proc->io.complete_q.completed_avg.cnt, __ATOMIC_SEQ_CST );
    77                         __atomic_fetch_add( &cltr->io.complete_q.blocks           , proc->io.complete_q.blocks           , __ATOMIC_SEQ_CST );
     62                        __atomic_fetch_add( &cltr->io.submit_q.submit_avg.rdy          , proc->io.submit_q.submit_avg.rdy          , __ATOMIC_SEQ_CST );
     63                        __atomic_fetch_add( &cltr->io.submit_q.submit_avg.csm          , proc->io.submit_q.submit_avg.csm          , __ATOMIC_SEQ_CST );
     64                        __atomic_fetch_add( &cltr->io.submit_q.submit_avg.avl          , proc->io.submit_q.submit_avg.avl          , __ATOMIC_SEQ_CST );
     65                        __atomic_fetch_add( &cltr->io.submit_q.submit_avg.cnt          , proc->io.submit_q.submit_avg.cnt          , __ATOMIC_SEQ_CST );
     66                        __atomic_fetch_add( &cltr->io.submit_q.look_avg.val            , proc->io.submit_q.look_avg.val            , __ATOMIC_SEQ_CST );
     67                        __atomic_fetch_add( &cltr->io.submit_q.look_avg.cnt            , proc->io.submit_q.look_avg.cnt            , __ATOMIC_SEQ_CST );
     68                        __atomic_fetch_add( &cltr->io.submit_q.look_avg.block          , proc->io.submit_q.look_avg.block          , __ATOMIC_SEQ_CST );
     69                        __atomic_fetch_add( &cltr->io.submit_q.alloc_avg.val           , proc->io.submit_q.alloc_avg.val           , __ATOMIC_SEQ_CST );
     70                        __atomic_fetch_add( &cltr->io.submit_q.alloc_avg.cnt           , proc->io.submit_q.alloc_avg.cnt           , __ATOMIC_SEQ_CST );
     71                        __atomic_fetch_add( &cltr->io.submit_q.alloc_avg.block         , proc->io.submit_q.alloc_avg.block         , __ATOMIC_SEQ_CST );
     72                        __atomic_fetch_add( &cltr->io.submit_q.helped                  , proc->io.submit_q.helped                  , __ATOMIC_SEQ_CST );
     73                        __atomic_fetch_add( &cltr->io.submit_q.leader                  , proc->io.submit_q.leader                  , __ATOMIC_SEQ_CST );
     74                        __atomic_fetch_add( &cltr->io.submit_q.busy                    , proc->io.submit_q.busy                    , __ATOMIC_SEQ_CST );
     75                        __atomic_fetch_add( &cltr->io.complete_q.completed_avg.val     , proc->io.complete_q.completed_avg.val     , __ATOMIC_SEQ_CST );
     76                        __atomic_fetch_add( &cltr->io.complete_q.completed_avg.slow_cnt, proc->io.complete_q.completed_avg.slow_cnt, __ATOMIC_SEQ_CST );
     77                        __atomic_fetch_add( &cltr->io.complete_q.completed_avg.fast_cnt, proc->io.complete_q.completed_avg.fast_cnt, __ATOMIC_SEQ_CST );
    7878                #endif
    7979        }
     
    154154                                        "- avg alloc search len   : %'18.2lf\n"
    155155                                        "- avg alloc search block : %'18.2lf\n"
    156                                         "- total wait calls       : %'15" PRIu64 "\n"
     156                                        "- total wait calls       : %'15" PRIu64 "   (%'" PRIu64 " slow, %'" PRIu64 " fast)\n"
    157157                                        "- avg completion/wait    : %'18.2lf\n"
    158                                         "- total completion blocks: %'15" PRIu64 "\n"
    159158                                        "\n"
    160159                                        , cluster ? "Cluster" : "Processor",  name, id
     
    166165                                        , io.submit_q.alloc_avg.cnt
    167166                                        , aavgv, aavgb
    168                                         , io.complete_q.completed_avg.cnt
    169                                         , ((double)io.complete_q.completed_avg.val) / io.complete_q.completed_avg.cnt
    170                                         , io.complete_q.blocks
     167                                        , io.complete_q.completed_avg.slow_cnt + io.complete_q.completed_avg.fast_cnt
     168                                        , io.complete_q.completed_avg.slow_cnt,  io.complete_q.completed_avg.fast_cnt
     169                                        , ((double)io.complete_q.completed_avg.val) / (io.complete_q.completed_avg.slow_cnt + io.complete_q.completed_avg.fast_cnt)
    171170                                );
    172171                        }
  • libcfa/src/concurrency/stats.hfa

    r13d33a75 ref9988b  
    9090                                struct {
    9191                                        volatile uint64_t val;
    92                                         volatile uint64_t cnt;
     92                                        volatile uint64_t slow_cnt;
     93                                        volatile uint64_t fast_cnt;
    9394                                } completed_avg;
    94                                 volatile uint64_t blocks;
    9595                        } complete_q;
    9696                };
  • libcfa/src/exception.c

    r13d33a75 ref9988b  
    1010// Created On       : Mon Jun 26 15:13:00 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Aug 12 13:55:00 2020
    13 // Update Count     : 21
     12// Last Modified On : Thr May 21 12:18:00 2020
     13// Update Count     : 20
    1414//
    1515
     
    2828#include <unwind.h>
    2929#include <bits/debug.hfa>
    30 #include "concurrency/invoke.h"
    3130#include "stdhdr/assert.h"
    3231
     
    5958
    6059
     60// Temperary global exception context. Does not work with concurency.
     61struct exception_context_t {
     62        struct __cfaehm_try_resume_node * top_resume;
     63
     64        exception_t * current_exception;
     65        int current_handler_index;
     66} static shared_stack = {NULL, NULL, 0};
     67
    6168// Get the current exception context.
    6269// There can be a single global until multithreading occurs, then each stack
    63 // needs its own. We get this from libcfathreads (no weak attribute).
    64 __attribute__((weak)) struct exception_context_t * this_exception_context() {
    65         static struct exception_context_t shared_stack = {NULL, NULL};
     70// needs its own. It will have to be updated to handle that.
     71struct exception_context_t * this_exception_context() {
    6672        return &shared_stack;
    6773}
     
    116122
    117123// MEMORY MANAGEMENT =========================================================
    118 
    119 struct __cfaehm_node {
    120         struct _Unwind_Exception unwind_exception;
    121         struct __cfaehm_node * next;
    122         int handler_index;
    123 };
    124 
    125 #define NODE_TO_EXCEPT(node) ((exception_t *)(1 + (node)))
    126 #define EXCEPT_TO_NODE(except) ((struct __cfaehm_node *)(except) - 1)
    127 #define UNWIND_TO_NODE(unwind) ((struct __cfaehm_node *)(unwind))
    128 #define NULL_MAP(map, ptr) ((ptr) ? (map(ptr)) : NULL)
    129124
    130125// How to clean up an exception in various situations.
     
    142137}
    143138
     139// We need a piece of storage to raise the exception, for now its a single
     140// piece.
     141static struct _Unwind_Exception this_exception_storage;
     142
     143struct __cfaehm_node {
     144        struct __cfaehm_node * next;
     145};
     146
     147#define NODE_TO_EXCEPT(node) ((exception_t *)(1 + (node)))
     148#define EXCEPT_TO_NODE(except) ((struct __cfaehm_node *)(except) - 1)
     149
    144150// Creates a copy of the indicated exception and sets current_exception to it.
    145151static void __cfaehm_allocate_exception( exception_t * except ) {
     
    155161        }
    156162
    157         // Initialize the node:
    158         exception_t * except_store = NODE_TO_EXCEPT(store);
    159         store->unwind_exception.exception_class = __cfaehm_exception_class;
    160         store->unwind_exception.exception_cleanup = __cfaehm_exception_cleanup;
    161         store->handler_index = 0;
    162         except->virtual_table->copy( except_store, except );
    163 
    164163        // Add the node to the list:
    165         store->next = NULL_MAP(EXCEPT_TO_NODE, context->current_exception);
    166         context->current_exception = except_store;
     164        store->next = EXCEPT_TO_NODE(context->current_exception);
     165        context->current_exception = NODE_TO_EXCEPT(store);
     166
     167        // Copy the exception to storage.
     168        except->virtual_table->copy( context->current_exception, except );
     169
     170        // Set up the exception storage.
     171        this_exception_storage.exception_class = __cfaehm_exception_class;
     172        this_exception_storage.exception_cleanup = __cfaehm_exception_cleanup;
    167173}
    168174
     
    179185        if ( context->current_exception == except ) {
    180186                node = to_free->next;
    181                 context->current_exception = NULL_MAP(NODE_TO_EXCEPT, node);
     187                context->current_exception = (node) ? NODE_TO_EXCEPT(node) : 0;
    182188        } else {
    183189                node = EXCEPT_TO_NODE(context->current_exception);
     
    207213        // Verify actions follow the rules we expect.
    208214        verify((actions & _UA_CLEANUP_PHASE) && (actions & _UA_FORCE_UNWIND));
    209         verify(!(actions & (_UA_SEARCH_PHASE | _UA_HANDLER_FRAME)));
     215        verify(!(actions & (_UA_SEARCH_PHASE | _UA_HANDER_FRAME)));
    210216
    211217        if ( actions & _UA_END_OF_STACK ) {
     
    216222}
    217223
    218 static struct _Unwind_Exception cancel_exception_storage;
    219 
    220224// Cancel the current stack, prefroming approprate clean-up and messaging.
    221225void __cfaehm_cancel_stack( exception_t * exception ) {
    222226        // TODO: Detect current stack and pick a particular stop-function.
    223227        _Unwind_Reason_Code ret;
    224         ret = _Unwind_ForcedUnwind( &cancel_exception_storage, _Stop_Fn, (void*)0x22 );
     228        ret = _Unwind_ForcedUnwind( &this_exception_storage, _Stop_Fn, (void*)0x22 );
    225229        printf("UNWIND ERROR %d after force unwind\n", ret);
    226230        abort();
     
    243247static void __cfaehm_begin_unwind(void(*defaultHandler)(exception_t *)) {
    244248        struct exception_context_t * context = this_exception_context();
     249        struct _Unwind_Exception * storage = &this_exception_storage;
    245250        if ( NULL == context->current_exception ) {
    246251                printf("UNWIND ERROR missing exception in begin unwind\n");
    247252                abort();
    248253        }
    249         struct _Unwind_Exception * storage =
    250                 &EXCEPT_TO_NODE(context->current_exception)->unwind_exception;
    251254
    252255        // Call stdlibc to raise the exception
     
    416419                                _Unwind_Reason_Code ret = (0 == index)
    417420                                        ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
    418                                 UNWIND_TO_NODE(unwind_exception)->handler_index = index;
     421                                context->current_handler_index = index;
    419422
    420423                                // Based on the return value, check if we matched the exception
     
    422425                                        __cfadbg_print_safe(exception, " handler found\n");
    423426                                } else {
    424                                         // TODO: Continue the search if there is more in the table.
    425427                                        __cfadbg_print_safe(exception, " no handler\n");
    426428                                }
     
    514516        // Exception handler
    515517        // Note: Saving the exception context on the stack breaks termination exceptions.
    516         catch_block( EXCEPT_TO_NODE( this_exception_context()->current_exception )->handler_index,
     518        catch_block( this_exception_context()->current_handler_index,
    517519                     this_exception_context()->current_exception );
    518520}
  • libcfa/src/heap.cfa

    r13d33a75 ref9988b  
    1010// Created On       : Tue Dec 19 21:58:35 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Aug 12 16:43:38 2020
    13 // Update Count     : 902
     12// Last Modified On : Sun Aug  9 12:23:20 2020
     13// Update Count     : 894
    1414//
    1515
     
    650650                for ( HeapManager.Storage * p = freeLists[i].freeList; p != 0p; p = p->header.kind.real.next ) {
    651651                #else
    652                 // for ( HeapManager.Storage * p = top( freeLists[i].freeList ); p != 0p; p = (p)`next->top ) {
    653                 for ( HeapManager.Storage * p = top( freeLists[i].freeList ); p != 0p; /* p = getNext( p )->top */) {
    654                         typeof(p) temp = (( p )`next)->top;                     // FIX ME: direct assignent fails, initialization works
    655                         p = temp;
     652                for ( HeapManager.Storage * p = top( freeLists[i].freeList ); p != 0p; p = (p)`next->top ) {
    656653                #endif // BUCKETLOCK
    657654                        total += size;
     
    11651162                choose( option ) {
    11661163                  case M_TOP_PAD:
    1167                         heapExpand = ceiling2( value, pageSize ); return 1;
     1164                        heapExpand = ceiling( value, pageSize ); return 1;
    11681165                  case M_MMAP_THRESHOLD:
    11691166                        if ( setMmapStart( value ) ) return 1;
  • libcfa/src/iostream.cfa

    r13d33a75 ref9988b  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Aug 11 22:16:33 2020
    13 // Update Count     : 1128
     12// Last Modified On : Mon Aug 10 09:32:14 2020
     13// Update Count     : 1126
    1414//
    1515
     
    3737
    3838forall( dtype ostype | ostream( ostype ) ) {
     39        ostype & ?|?( ostype & os, zero_t ) {
     40                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
     41                fmt( os, "%d", 0n );
     42                return os;
     43        } // ?|?
     44        void ?|?( ostype & os, zero_t z ) {
     45                (ostype &)(os | z); ends( os );
     46        } // ?|?
     47
     48        ostype & ?|?( ostype & os, one_t ) {
     49                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
     50                fmt( os, "%d", 1n );
     51                return os;
     52        } // ?|?
     53        void ?|?( ostype & os, one_t o ) {
     54                (ostype &)(os | o); ends( os );
     55        } // ?|?
     56
    3957        ostype & ?|?( ostype & os, bool b ) {
    4058                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
  • libcfa/src/iostream.hfa

    r13d33a75 ref9988b  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Aug 11 22:16:14 2020
    13 // Update Count     : 350
     12// Last Modified On : Thu Jul 16 07:43:32 2020
     13// Update Count     : 348
    1414//
    1515
     
    6767
    6868forall( dtype ostype | ostream( ostype ) ) {
     69        ostype & ?|?( ostype &, zero_t );
     70        void ?|?( ostype &, zero_t );
     71        ostype & ?|?( ostype &, one_t );
     72        void ?|?( ostype &, one_t );
     73
    6974        ostype & ?|?( ostype &, bool );
    7075        void ?|?( ostype &, bool );
  • libcfa/src/parseargs.cfa

    r13d33a75 ref9988b  
    1919        extern          long long int strtoll (const char* str, char** endptr, int base);
    2020        extern unsigned long long int strtoull(const char* str, char** endptr, int base);
    21         extern                 double strtod  (const char* str, char** endptr);
    2221}
    2322
     
    2928extern char ** cfa_args_envp;
    3029
    31 static void usage(char * cmd, cfa_option options[], size_t opt_count, const char * usage, FILE * out)  __attribute__ ((noreturn));
     30void printopt(FILE * out, int width, int max, char sn, const char * ln, const char * help) {
     31        int hwidth = max - (11 + width);
     32        if(hwidth <= 0) hwidth = max;
     33
     34        fprintf(out, "  -%c, --%-*s   %.*s\n", sn, width, ln, hwidth, help);
     35        for() {
     36                help += min(strlen(help), hwidth);
     37                if('\0' == *help) break;
     38                fprintf(out, "%*s%.*s\n", width + 11, "", hwidth, help);
     39        }
     40}
    3241
    3342void parse_args( cfa_option options[], size_t opt_count, const char * usage, char ** & left ) {
     
    3544}
    3645
    37 //-----------------------------------------------------------------------------
    38 // getopt_long wrapping
    3946void parse_args(
    4047        int argc,
     
    4653) {
    4754        struct option optarr[opt_count + 2];
     55        int width = 0;
     56        int max_width = 1_000_000;
    4857        {
    4958                int idx = 0;
     
    6069                                }
    6170                                idx++;
     71
     72                                int w = strlen(options[i].long_name);
     73                                if(w > width) width = w;
    6274                        }
    6375                }
     
    94106                                out = stdout;
    95107                        case '?':
    96                                 usage(argv[0], options, opt_count, usage, out);
     108                                goto USAGE;
    97109                        default:
    98110                                for(i; opt_count) {
     
    103115
    104116                                                fprintf(out, "Argument '%s' for option %c could not be parsed\n\n", arg, (char)opt);
    105                                                 usage(argv[0], options, opt_count, usage, out);
     117                                                goto USAGE;
    106118                                        }
    107119                                }
     
    110122
    111123        }
    112 }
    113 
    114 //-----------------------------------------------------------------------------
    115 // Print usage
    116 static void printopt(FILE * out, int width, int max, char sn, const char * ln, const char * help) {
    117         int hwidth = max - (11 + width);
    118         if(hwidth <= 0) hwidth = max;
    119 
    120         fprintf(out, "  -%c, --%-*s   %.*s\n", sn, width, ln, hwidth, help);
    121         for() {
    122                 help += min(strlen(help), hwidth);
    123                 if('\0' == *help) break;
    124                 fprintf(out, "%*s%.*s\n", width + 11, "", hwidth, help);
    125         }
    126 }
    127 
    128 void print_args_usage(cfa_option options[], size_t opt_count, const char * usage, bool error)  __attribute__ ((noreturn)) {
    129         usage(cfa_args_argv[0], options, opt_count, usage, error ? stderr : stdout);
    130 }
    131 
    132 void print_args_usage(int , char * argv[], cfa_option options[], size_t opt_count, const char * usage, bool error)  __attribute__ ((noreturn)) {
    133         usage(argv[0], options, opt_count, usage, error ? stderr : stdout);
    134 }
    135 
    136 static void usage(char * cmd, cfa_option options[], size_t opt_count, const char * help, FILE * out) __attribute__((noreturn)) {
    137         int width = 0;
    138         {
    139                 for(i; opt_count) {
    140                         if(options[i].long_name) {
    141                                 int w = strlen(options[i].long_name);
    142                                 if(w > width) width = w;
    143                         }
    144                 }
    145         }
    146 
    147         int max_width = 1_000_000;
     124
     125        USAGE:;
    148126        int outfd = fileno(out);
    149127        if(isatty(outfd)) {
     
    154132        }
    155133
    156         fprintf(out, "Usage:\n  %s %s\n", cmd, help);
     134        fprintf(out, "Usage:\n  %s %s\n", argv[0], usage);
    157135
    158136        for(i; opt_count) {
     
    163141}
    164142
    165 //-----------------------------------------------------------------------------
    166 // Typed argument parsing
    167143bool parse_yesno(const char * arg, bool & value ) {
    168144        if(strcmp(arg, "yes") == 0) {
     
    191167bool parse(const char * arg, const char * & value ) {
    192168        value = arg;
    193         return true;
    194 }
    195 
    196 bool parse(const char * arg, int & value) {
    197         char * end;
    198         int r = strtoll(arg, &end, 10);
    199         if(*end != '\0') return false;
    200 
    201         value = r;
    202169        return true;
    203170}
     
    233200}
    234201
    235 bool parse(const char * arg, double & value) {
     202bool parse(const char * arg, int & value) {
    236203        char * end;
    237         double r = strtod(arg, &end);
     204        int r = strtoll(arg, &end, 10);
    238205        if(*end != '\0') return false;
    239206
  • libcfa/src/parseargs.hfa

    r13d33a75 ref9988b  
    3434void parse_args( int argc, char * argv[], cfa_option options[], size_t opt_count, const char * usage, char ** & left );
    3535
    36 void print_args_usage(cfa_option options[], size_t opt_count, const char * usage, bool error)  __attribute__ ((noreturn));
    37 void print_args_usage(int argc, char * argv[], cfa_option options[], size_t opt_count, const char * usage, bool error)  __attribute__ ((noreturn));
    38 
    3936bool parse_yesno   (const char *, bool & );
    4037bool parse_settrue (const char *, bool & );
     
    4239
    4340bool parse(const char *, const char * & );
    44 bool parse(const char *, int & );
    4541bool parse(const char *, unsigned & );
    4642bool parse(const char *, unsigned long & );
    4743bool parse(const char *, unsigned long long & );
    48 bool parse(const char *, double & );
     44bool parse(const char *, int & );
  • libcfa/src/stdlib.hfa

    r13d33a75 ref9988b  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Aug 14 23:38:50 2020
    13 // Update Count     : 504
     12// Last Modified On : Thu Jul 30 16:14:58 2020
     13// Update Count     : 490
    1414//
    1515
     
    3939//---------------------------------------
    4040
    41 #include "common.hfa"
    42 
    43 //---------------------------------------
    44 
    4541// Macro because of returns
    4642#define $VAR_ALLOC( allocation, alignment ) \
     
    140136        T * alloc_set( char fill ) {
    141137                return (T *)memset( (T *)alloc(), (int)fill, sizeof(T) ); // initialize with fill value
    142         } // alloc_set
    143 
    144         T * alloc_set( const T & fill ) {
     138        } // alloc
     139
     140        T * alloc_set( T fill ) {
    145141                return (T *)memcpy( (T *)alloc(), &fill, sizeof(T) ); // initialize with fill value
    146         } // alloc_set
     142        } // alloc
    147143
    148144        T * alloc_set( size_t dim, char fill ) {
    149145                return (T *)memset( (T *)alloc( dim ), (int)fill, dim * sizeof(T) ); // initialize with fill value
    150         } // alloc_set
    151 
    152         T * alloc_set( size_t dim, const T & fill ) {
     146        } // alloc
     147
     148        T * alloc_set( size_t dim, T fill ) {
    153149                T * r = (T *)alloc( dim );
    154150                for ( i; dim ) { memcpy( &r[i], &fill, sizeof(T) ); } // initialize with fill value
    155151                return r;
    156         } // alloc_set
    157 
    158         T * alloc_set( size_t dimNew, const T fill[], size_t dimOld ) {
    159                 return (T *)memcpy( (T *)alloc( dimNew ), fill, min( dimNew, dimOld ) * sizeof(T) ); // initialize with fill value
    160         } // alloc_set
     152        } // alloc
     153
     154        T * alloc_set( size_t dim, const T fill[] ) {
     155                return (T *)memcpy( (T *)alloc( dim ), fill, dim * sizeof(T) ); // initialize with fill value
     156        } // alloc
    161157
    162158        T * alloc_set( T ptr[], size_t dim, char fill ) {       // realloc array with fill
     
    170166        } // alloc_set
    171167
    172         T * alloc_set( T ptr[], size_t dim, const T & fill ) {  // realloc array with fill
     168        T * alloc_set( T ptr[], size_t dim, T & fill ) {        // realloc array with fill
    173169                size_t odim = malloc_size( ptr ) / sizeof(T);   // current dimension
    174170                size_t nsize = dim * sizeof(T);                                 // new allocation
     
    181177                } // if
    182178                return nptr;
    183         } // alloc_set
     179        } // alloc_align_set
    184180} // distribution
    185181
     
    208204        T * alloc_align_set( size_t align, char fill ) {
    209205                return (T *)memset( (T *)alloc_align( align ), (int)fill, sizeof(T) ); // initialize with fill value
    210         } // alloc_align_set
    211 
    212         T * alloc_align_set( size_t align, const T & fill ) {
     206        } // alloc_align
     207
     208        T * alloc_align_set( size_t align, T fill ) {
    213209                return (T *)memcpy( (T *)alloc_align( align ), &fill, sizeof(T) ); // initialize with fill value
    214         } // alloc_align_set
     210        } // alloc_align
    215211
    216212        T * alloc_align_set( size_t align, size_t dim, char fill ) {
    217213                return (T *)memset( (T *)alloc_align( align, dim ), (int)fill, dim * sizeof(T) ); // initialize with fill value
    218         } // alloc_align_set
    219 
    220         T * alloc_align_set( size_t align, size_t dim, const T & fill ) {
     214        } // alloc_align
     215
     216        T * alloc_align_set( size_t align, size_t dim, T fill ) {
    221217                T * r = (T *)alloc_align( align, dim );
    222218                for ( i; dim ) { memcpy( &r[i], &fill, sizeof(T) ); } // initialize with fill value
    223219                return r;
    224         } // alloc_align_set
    225 
    226         T * alloc_align_set( size_t align, size_t dimNew, const T fill[], size_t dimOld ) {
    227                 return (T *)memcpy( (T *)alloc_align( align, dimNew ), fill, min( dimNew, dimOld ) * sizeof(T) );
    228         } // alloc_align_set
     220        } // alloc_align
     221
     222        T * alloc_align_set( size_t align, size_t dim, const T fill[] ) {
     223                return (T *)memcpy( (T *)alloc_align( align, dim ), fill, dim * sizeof(T) );
     224        } // alloc_align
    229225
    230226        T * alloc_align_set( T ptr[], size_t align, size_t dim, char fill ) {
     
    238234        } // alloc_align_set
    239235
    240         T * alloc_align_set( T ptr[], size_t align, size_t dim, const T & fill ) {
     236        T * alloc_align_set( T ptr[], size_t align, size_t dim, T & fill ) {
    241237                size_t odim = malloc_size( ptr ) / sizeof(T);   // current dimension
    242238                size_t nsize = dim * sizeof(T);                                 // new allocation
     
    378374//---------------------------------------
    379375
     376#include "common.hfa"
     377
     378//---------------------------------------
     379
    380380extern bool threading_enabled(void) OPTIONAL_THREAD;
    381381
  • src/AST/Pass.hpp

    r13d33a75 ref9988b  
    9191        static void run( std::list< ptr<Decl> > & decls, Args &&... args ) {
    9292                Pass<core_t> visitor( std::forward<Args>( args )... );
    93                 accept_all( decls, visitor );
    94         }
    95 
    96         template< typename... Args >
    97         static void run( std::list< ptr<Decl> > & decls ) {
    98                 Pass<core_t> visitor;
    9993                accept_all( decls, visitor );
    10094        }
  • tests/.expect/minmax.txt

    r13d33a75 ref9988b  
    11char                    z a     min a
    2 signed int              4 -3    min -3
     2signed int              4 3     min 3
    33unsigned int            4 3     min 3
    4 signed long int         4 -3    min -3
     4signed long int         4 3     min 3
    55unsigned long int       4 3     min 3
    6 signed long long int    4 -3    min -3
     6signed long long int    4 3     min 3
    77unsigned long long int  4 3     min 3
    88float                   4. 3.1  min 3.1
     
    1111
    1212char                    z a     max z
    13 signed int              4 -3    max 4
     13signed int              4 3     max 4
    1414unsigned int            4 3     max 4
    15 signed long int         4 -3    max 4
     15signed long int         4 3     max 4
    1616unsigned long int       4 3     max 4
    17 signed long long int    4 -3    max 4
     17signed long long int    4 3     max 4
    1818unsigned long long int  4 3     max 4
    1919float                   4. 3.1  max 4.
  • tests/Makefile.am

    r13d33a75 ref9988b  
    163163        $(CFACOMPILETEST) -DERR2 -c -fsyntax-only -o $(abspath ${@})
    164164
    165 # Exception Tests
    166 # Test with libcfathread; it changes how storage works.
    167 
    168 exceptions/%-threads : exceptions/%.cfa $(CFACCBIN)
    169         $(CFACOMPILETEST) -include exceptions/with-threads.hfa -c -o $(abspath ${@}).o
    170         $(CFACCLOCAL) $($(shell echo "${@}_FLAGSLD" | sed 's/-\|\//_/g')) $(abspath ${@}).o -o $(abspath ${@})
    171 
    172165#------------------------------------------------------------------------------
    173166# Other targets
  • tests/alloc.cfa

    r13d33a75 ref9988b  
    1010// Created On       : Wed Feb  3 07:56:22 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Aug 14 16:59:59 2020
    13 // Update Count     : 430
     12// Last Modified On : Mon Apr  6 21:08:23 2020
     13// Update Count     : 428
    1414//
    1515
     
    9090        // do not free
    9191
    92         ip1 = alloc_set( 2 * dim, ip, 2 * dim );                                // CFA array alloc, fill
     92        ip1 = alloc_set( 2 * dim, ip );                                         // CFA array alloc, fill
    9393        printf( "CFA array alloc, fill from array\n" );
    9494        for ( i; 2 * dim ) { printf( "%#x %#x, ", ip[i], ip1[i] ); }
     
    288288        // do not free
    289289
    290         stp1 = alloc_align_set( Alignment, dim, stp, dim );     // CFA array memalign, fill
     290        stp1 = alloc_align_set( Alignment, dim, stp );          // CFA array memalign, fill
    291291        assert( (uintptr_t)stp % Alignment == 0 );
    292292        printf( "CFA array alloc_align, fill array\n" );
  • tests/exceptions/terminate.cfa

    r13d33a75 ref9988b  
    142142        }
    143143}
     144
  • tests/heap.cfa

    r13d33a75 ref9988b  
    1010// Created On       : Tue Nov  6 17:54:56 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug  9 08:05:16 2020
    13 // Update Count     : 57
     12// Last Modified On : Tue Aug  4 06:36:17 2020
     13// Update Count     : 56
    1414//
    1515
     
    232232                size_t s = i + default_mmap_start();                    // cross over point
    233233                char * area = (char *)calloc( 1, s );
     234//              if ( area == 0p ) abort( "calloc/realloc/free out of memory" );
    234235                if ( area[0] != '\0' || area[s - 1] != '\0' ||
    235236                         area[malloc_size( area ) - 1] != '\0' ||
    236                          ! malloc_zero_fill( area ) ) abort( "calloc/realloc/free corrupt storage3" );
     237                         ! malloc_zero_fill( area ) ) //abort( "calloc/realloc/free corrupt storage3" );
     238                        printf( "C %zd %d %d %d %d\n", s, area[0] != '\0', area[s - 1] != '\0', area[malloc_size( area ) - 1] != '\0', ! malloc_zero_fill( area ) );
    237239
    238240                // Do not start this loop index at 0 because realloc of 0 bytes frees the storage.
    239241                for ( r; i ~ 256 * 1024 ~ 26 ) {                                // start at initial memory request
    240242                        area = (char *)realloc( area, r );                      // attempt to reuse storage
     243//                      if ( area == 0p ) abort( "calloc/realloc/free out of memory" );
    241244                        if ( area[0] != '\0' || area[r - 1] != '\0' ||
    242245                                 area[malloc_size( area ) - 1] != '\0' ||
     
    252255                // initial N byte allocation
    253256                char * area = (char *)memalign( a, amount );    // aligned N-byte allocation
     257//              if ( area == 0p ) abort( "memalign/realloc/free out of memory" ); // no storage ?
    254258                //sout | alignments[a] | area;
    255259                if ( (size_t)area % a != 0 || malloc_alignment( area ) != a ) { // check for initial alignment
  • tests/linking/withthreads.cfa

    r13d33a75 ref9988b  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // withthreads.cfa --
     7// nothreads.cfa --
    88//
    99// Author           : Thierry Delisle
  • tests/minmax.cfa

    r13d33a75 ref9988b  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Aug 15 08:28:01 2020
    13 // Update Count     : 54
     12// Last Modified On : Tue Dec  4 21:45:31 2018
     13// Update Count     : 52
    1414//
    1515
     
    2323
    2424        sout | "char\t\t\t"                                     | 'z' | ' ' | 'a' | "\tmin " | min( 'z', 'a' );
    25         sout | "signed int\t\t"                         | 4 | -3 | "\tmin" | min( 4, -3 );
     25        sout | "signed int\t\t"                         | 4 | 3 | "\tmin" | min( 4, 3 );
    2626        sout | "unsigned int\t\t"                       | 4u | 3u | "\tmin" | min( 4u, 3u );
    27         sout | "signed long int\t\t"            | 4l | -3l | "\tmin" | min( 4l, -3l );
     27        sout | "signed long int\t\t"            | 4l | 3l | "\tmin" | min( 4l, 3l );
    2828        sout | "unsigned long int\t"            | 4ul | 3ul | "\tmin" | min( 4ul, 3ul );
    29         sout | "signed long long int\t"         | 4ll | -3ll | "\tmin" | min( 4ll, -3ll );
     29        sout | "signed long long int\t"         | 4ll | 3ll | "\tmin" | min( 4ll, 3ll );
    3030        sout | "unsigned long long int\t"       | 4ull | 3ull | "\tmin" | min( 4ull, 3ull );
    3131        sout | "float\t\t\t"                            | 4.0f | 3.1f | "\tmin" | min( 4.0f, 3.1f );
     
    3636
    3737        sout | "char\t\t\t"                                     | 'z' | ' ' | 'a' | "\tmax " | max( 'z', 'a' );
    38         sout | "signed int\t\t"                         | 4 | -3 | "\tmax" | max( 4, -3 );
     38        sout | "signed int\t\t"                         | 4 | 3 | "\tmax" | max( 4, 3 );
    3939        sout | "unsigned int\t\t"                       | 4u | 3u | "\tmax" | max( 4u, 3u );
    40         sout | "signed long int\t\t"            | 4l | -3l | "\tmax" | max( 4l, -3l );
     40        sout | "signed long int\t\t"            | 4l | 3l | "\tmax" | max( 4l, 3l );
    4141        sout | "unsigned long int\t"            | 4ul | 3ul | "\tmax" | max( 4ul, 3ul );
    42         sout | "signed long long int\t"         | 4ll | -3ll | "\tmax" | max( 4ll, -3ll );
     42        sout | "signed long long int\t"         | 4ll | 3ll | "\tmax" | max( 4ll, 3ll );
    4343        sout | "unsigned long long int\t"       | 4ull | 3ull | "\tmax" | max( 4ull, 3ull );
    4444        sout | "float\t\t\t"                            | 4.0f | 3.1f | "\tmax" | max( 4.0f, 3.1f );
Note: See TracChangeset for help on using the changeset viewer.