Changeset 762fbc1 for libcfa/src


Ignore:
Timestamp:
Aug 15, 2020, 12:20:44 PM (5 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
36de20d
Parents:
7f51b9d (diff), 5715d43 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc into master

Location:
libcfa/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/coroutine.cfa

    r7f51b9d r762fbc1  
    215215                return cor;
    216216        }
     217
     218        struct $coroutine * __cfactx_cor_active(void) {
     219                return active_coroutine();
     220        }
    217221}
    218222
  • libcfa/src/concurrency/invoke.c

    r7f51b9d r762fbc1  
    2929// Called from the kernel when starting a coroutine or task so must switch back to user mode.
    3030
     31extern struct $coroutine * __cfactx_cor_active(void);
    3132extern struct $coroutine * __cfactx_cor_finish(void);
    3233extern void __cfactx_cor_leave ( struct $coroutine * );
     
    3536extern void disable_interrupts() OPTIONAL_THREAD;
    3637extern void enable_interrupts( __cfaabi_dbg_ctx_param );
     38
     39struct exception_context_t * this_exception_context() {
     40        return &__get_stack( __cfactx_cor_active() )->exception_context;
     41}
    3742
    3843void __cfactx_invoke_coroutine(
  • libcfa/src/concurrency/invoke.h

    r7f51b9d r762fbc1  
    9898        }
    9999
     100        struct exception_context_t * this_exception_context();
     101
    100102        // struct which calls the monitor is accepting
    101103        struct __waitfor_mask_t {
  • libcfa/src/concurrency/io.cfa

    r7f51b9d r762fbc1  
    359359
    360360                        // We got the lock
     361                        // Collect the submissions
    361362                        unsigned to_submit = __collect_submitions( ring );
     363
     364                        // Actually submit
    362365                        int ret = __io_uring_enter( ring, to_submit, false );
    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) );
     366
     367                        unlock(ring.submit_q.lock);
     368                        if( ret < 0 ) return;
    369369
    370370                        // Release the consumed SQEs
     
    372372
    373373                        // update statistics
    374                         __STATS__( true,
     374                        __STATS__( false,
    375375                                io.submit_q.submit_avg.rdy += to_submit;
    376376                                io.submit_q.submit_avg.csm += ret;
    377377                                io.submit_q.submit_avg.cnt += 1;
    378378                        )
    379 
    380                         unlock(ring.submit_q.lock);
    381379                }
    382380                else {
  • libcfa/src/concurrency/io/setup.cfa

    r7f51b9d r762fbc1  
    298298                if( params_in.poll_complete ) params.flags |= IORING_SETUP_IOPOLL;
    299299
    300                 uint32_t nentries = params_in.num_entries;
     300                uint32_t 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                }
    301307
    302308                int fd = syscall(__NR_io_uring_setup, nentries, &params );
  • libcfa/src/concurrency/iocall.cfa

    r7f51b9d r762fbc1  
    101101        #endif
    102102
    103 
    104103        #define __submit_prelude \
    105104                if( 0 != (submit_flags & LINK_FLAGS) ) { errno = ENOTSUP; return -1; } \
     
    110109                struct io_uring_sqe * sqe; \
    111110                uint32_t idx; \
     111                uint8_t sflags = REGULAR_FLAGS & submit_flags; \
    112112                [sqe, idx] = __submit_alloc( ring, (uint64_t)(uintptr_t)&data ); \
    113                 sqe->flags = REGULAR_FLAGS & submit_flags;
     113                sqe->flags = sflags;
    114114
    115115        #define __submit_wait \
     
    186186                        __submit_prelude
    187187
    188                         (*sqe){ IORING_OP_READV, fd, iov, iovcnt, offset };
     188                        sqe->opcode = IORING_OP_READV;
     189                        sqe->ioprio = 0;
     190                        sqe->fd = fd;
     191                        sqe->off = offset;
     192                        sqe->addr = (uint64_t)(uintptr_t)iov;
     193                        sqe->len = iovcnt;
     194                        sqe->rw_flags = 0;
     195                        sqe->__pad2[0] = sqe->__pad2[1] = sqe->__pad2[2] = 0;
    189196
    190197                        __submit_wait
  • libcfa/src/exception.c

    r7f51b9d r762fbc1  
    5959
    6060
    61 // Temperary global exception context. Does not work with concurency.
    62 static struct exception_context_t shared_stack = {NULL, NULL};
    63 
    6461// Get the current exception context.
    6562// There can be a single global until multithreading occurs, then each stack
    66 // needs its own. It will have to be updated to handle that.
    67 struct exception_context_t * this_exception_context() {
     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};
    6866        return &shared_stack;
    6967}
  • libcfa/src/parseargs.cfa

    r7f51b9d r762fbc1  
    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);
    2122}
    2223
     
    2829extern char ** cfa_args_envp;
    2930
    30 void 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 }
     31static void usage(char * cmd, cfa_option options[], size_t opt_count, const char * usage, FILE * out)  __attribute__ ((noreturn));
    4132
    4233void parse_args( cfa_option options[], size_t opt_count, const char * usage, char ** & left ) {
     
    4435}
    4536
     37//-----------------------------------------------------------------------------
     38// getopt_long wrapping
    4639void parse_args(
    4740        int argc,
     
    5346) {
    5447        struct option optarr[opt_count + 2];
    55         int width = 0;
    56         int max_width = 1_000_000;
    5748        {
    5849                int idx = 0;
     
    6960                                }
    7061                                idx++;
    71 
    72                                 int w = strlen(options[i].long_name);
    73                                 if(w > width) width = w;
    7462                        }
    7563                }
     
    10694                                out = stdout;
    10795                        case '?':
    108                                 goto USAGE;
     96                                usage(argv[0], options, opt_count, usage, out);
    10997                        default:
    11098                                for(i; opt_count) {
     
    115103
    116104                                                fprintf(out, "Argument '%s' for option %c could not be parsed\n\n", arg, (char)opt);
    117                                                 goto USAGE;
     105                                                usage(argv[0], options, opt_count, usage, out);
    118106                                        }
    119107                                }
     
    122110
    123111        }
    124 
    125         USAGE:;
     112}
     113
     114//-----------------------------------------------------------------------------
     115// Print usage
     116static 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
     128void 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
     132void 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
     136static void usage(char * cmd, cfa_option options[], size_t opt_count, const char * help, FILE * out) __attribute__((noreturn)) {
     137        int width = 0;
     138        {
     139                int idx = 0;
     140                for(i; opt_count) {
     141                        if(options[i].long_name) {
     142                                int w = strlen(options[i].long_name);
     143                                if(w > width) width = w;
     144                        }
     145                }
     146        }
     147
     148        int max_width = 1_000_000;
    126149        int outfd = fileno(out);
    127150        if(isatty(outfd)) {
     
    132155        }
    133156
    134         fprintf(out, "Usage:\n  %s %s\n", argv[0], usage);
     157        fprintf(out, "Usage:\n  %s %s\n", cmd, help);
    135158
    136159        for(i; opt_count) {
     
    141164}
    142165
     166//-----------------------------------------------------------------------------
     167// Typed argument parsing
    143168bool parse_yesno(const char * arg, bool & value ) {
    144169        if(strcmp(arg, "yes") == 0) {
     
    167192bool parse(const char * arg, const char * & value ) {
    168193        value = arg;
     194        return true;
     195}
     196
     197bool parse(const char * arg, int & value) {
     198        char * end;
     199        int r = strtoll(arg, &end, 10);
     200        if(*end != '\0') return false;
     201
     202        value = r;
    169203        return true;
    170204}
     
    200234}
    201235
    202 bool parse(const char * arg, int & value) {
    203         char * end;
    204         int r = strtoll(arg, &end, 10);
    205         if(*end != '\0') return false;
    206 
    207         value = r;
    208         return true;
    209 }
     236bool parse(const char * arg, double & value) {
     237        char * end;
     238        double r = strtod(arg, &end);
     239        if(*end != '\0') return false;
     240
     241        value = r;
     242        return true;
     243}
  • libcfa/src/parseargs.hfa

    r7f51b9d r762fbc1  
    3434void parse_args( int argc, char * argv[], cfa_option options[], size_t opt_count, const char * usage, char ** & left );
    3535
     36void print_args_usage(cfa_option options[], size_t opt_count, const char * usage, bool error)  __attribute__ ((noreturn));
     37void print_args_usage(int argc, char * argv[], cfa_option options[], size_t opt_count, const char * usage, bool error)  __attribute__ ((noreturn));
     38
    3639bool parse_yesno   (const char *, bool & );
    3740bool parse_settrue (const char *, bool & );
     
    3942
    4043bool parse(const char *, const char * & );
     44bool parse(const char *, int & );
    4145bool parse(const char *, unsigned & );
    4246bool parse(const char *, unsigned long & );
    4347bool parse(const char *, unsigned long long & );
    44 bool parse(const char *, int & );
     48bool parse(const char *, double & );
Note: See TracChangeset for help on using the changeset viewer.