Changes in / [12c1eef:5235d49]


Ignore:
Files:
6 added
12 deleted
40 edited

Legend:

Unmodified
Added
Removed
  • benchmark/readyQ/churn.cfa

    r12c1eef r5235d49  
    2121        wait( sem );
    2222        for() {
    23                 uint32_t r = prng();
     23                uint64_t r = thread_rand();
    2424                bench_sem * next = __atomic_exchange_n(&spots[r % spot_cnt], &sem, __ATOMIC_SEQ_CST);
    2525                if(next) post( *next );
  • benchmark/readyQ/locality.cfa

    r12c1eef r5235d49  
    128128__attribute__((noinline)) void work(MyData & data, size_t cnt_, uint64_t & state) {
    129129        for (cnt_) {
    130                 access(data, xorshift_13_7_17(state));
     130                access(data, __xorshift64(state));
    131131        }
    132132}
    133133
    134134void main(MyThread & this) {
    135         uint64_t state = prng();
     135        uint64_t state = thread_rand();
    136136
    137137        // Wait for start
     
    144144
    145145                // Wait on a random spot
    146                 uint64_t idx = xorshift_13_7_17(state) % this.spots.len;
     146                uint64_t idx = __xorshift64(state) % this.spots.len;
    147147                bool closed = put(*this.spots.ptr[idx], this, this.data, this.share);
    148148
  • benchmark/readyQ/transfer.cfa

    r12c1eef r5235d49  
    11#include "rq_bench.hfa"
    22#include <fstream.hfa>
    3 #include <locale.h>
    43
    54Duration default_preemption() {
     
    98#define PRINT(...)
    109
    11 __uint128_t lead_seed;
     10__lehmer64_state_t lead_seed;
    1211volatile unsigned leader;
    1312volatile size_t lead_idx;
     
    6968        waitgroup();
    7069
    71         unsigned nleader = lehmer64( lead_seed ) % nthreads;
     70        unsigned nleader = __lehmer64( lead_seed ) % nthreads;
    7271        __atomic_store_n( &leader, nleader, __ATOMIC_SEQ_CST );
    7372
     
    106105// ==================================================
    107106int main(int argc, char * argv[]) {
    108         uint64_t lead_seed = getpid();
    109         for(10) lehmer64( lead_seed );
     107        __lehmer64_state_t lead_seed = getpid();
     108        for(10) __lehmer64( lead_seed );
    110109        unsigned nprocs = 2;
    111110
     
    127126
    128127        lead_idx = 0;
    129         leader = lehmer64( lead_seed ) % nthreads;
     128        leader = __lehmer64( lead_seed ) % nthreads;
    130129
    131130        size_t rechecks = 0;
     
    168167        }
    169168
    170         setlocale( LC_NUMERIC, getenv( "LANG" ) );
    171169        sout | "Duration (ms)           : " | ws(3, 3, unit(eng((end - start)`dms)));
    172170        sout | "Number of processors    : " | nprocs;
  • libcfa/prelude/Makefile.am

    r12c1eef r5235d49  
    1111## Created On       : Sun May 31 08:54:01 2015
    1212## Last Modified By : Peter A. Buhr
    13 ## Last Modified On : Thu Jan 13 17:06:27 2022
    14 ## Update Count     : 215
     13## Last Modified On : Mon Feb  3 21:27:18 2020
     14## Update Count     : 208
    1515###############################################################################
    1616
     
    3737# create extra forward types/declarations to reduce inclusion of library files
    3838extras.cf : ${srcdir}/extras.regx ${srcdir}/extras.c
    39         @echo '# 2 "${@}"  // needed for error messages from this file' > ${@}
    40         ${AM_V_GEN}gcc ${AM_CFLAGS} -E ${srcdir}/extras.c | grep -f ${srcdir}/extras.regx >> ${@}
    41         ${AM_V_GEN}gcc ${AM_CFLAGS} -E ${srcdir}/extras.c | grep -zo -f ${srcdir}/extras.regx2 | tr '\0' '\n' >> ${@}
     39        ${AM_V_GEN}gcc ${AM_CFLAGS} -E ${srcdir}/extras.c | grep -f ${srcdir}/extras.regx > extras.cf
     40        ${AM_V_GEN}gcc ${AM_CFLAGS} -E ${srcdir}/extras.c | grep -zo -f ${srcdir}/extras.regx2 | tr '\0' '\n' >> extras.cf
    4241
    4342# create forward declarations for gcc builtins
    4443gcc-builtins.cf : gcc-builtins.c ${srcdir}/prototypes.sed
    45         @echo '# 2 "${@}"  // needed for error messages from this file' > ${@}
    46         ${AM_V_GEN}gcc -I${srcdir} -E -P $< | sed -r -f ${srcdir}/prototypes.sed >> ${@}
     44        ${AM_V_GEN}gcc -I${srcdir} -E -P $< | sed -r -f ${srcdir}/prototypes.sed > $@
    4745
    4846gcc-builtins.c : ${srcdir}/builtins.def ${srcdir}/prototypes.awk ${srcdir}/sync-builtins.cf ${srcdir}/prototypes.c
    49         ${AM_V_GEN}gcc -I${srcdir} -E ${srcdir}/prototypes.c | awk -f ${srcdir}/prototypes.awk > ${@}
     47        ${AM_V_GEN}gcc -I${srcdir} -E ${srcdir}/prototypes.c | awk -f ${srcdir}/prototypes.awk > $@
    5048
    5149prelude.cfa : prelude-gen.cc
    5250        ${AM_V_GEN}${CXX} ${AM_CXXFLAGS} ${CXXFLAGS} ${AM_CFLAGS} ${<} -o prelude-gen -Wall -Wextra -O2 -g -std=c++14
    53         @./prelude-gen > ${@}
     51        @./prelude-gen > $@
    5452        @rm ./prelude-gen
    5553
     
    6058# create forward declarations for cfa builtins
    6159builtins.cf : builtins.c @LOCAL_CFACC@
    62         ${AM_V_GEN}gcc ${AM_CFLAGS} -E ${<} -o ${@} -MD -MP -MF $(DEPDIR)/builtins.Po -D__cforall
     60        ${AM_V_GEN}gcc ${AM_CFLAGS} -E -P ${<} -o ${@} -MD -MP -MF $(DEPDIR)/builtins.Po -D__cforall
    6361        ${AM_V_at}sed -i 's/builtins.o/builtins.cf/g' $(DEPDIR)/builtins.Po
    6462
     
    6664
    6765bootloader.c : ${srcdir}/bootloader.cf prelude.cfa extras.cf gcc-builtins.cf builtins.cf @CFACPP@
    68         ${AM_V_GEN}@CFACPP@ --prelude-dir=${builddir} -tpm ${srcdir}/bootloader.cf ${@}  # use src/cfa-cpp as not in lib until after install
     66        ${AM_V_GEN}@CFACPP@ --prelude-dir=${builddir} -tpm ${srcdir}/bootloader.cf $@  # use src/cfa-cpp as not in lib until after install
    6967
    7068maintainer-clean-local :
  • libcfa/src/bits/locks.hfa

    r12c1eef r5235d49  
    3131                // previous thread to acquire the lock
    3232                void* prev_thrd;
    33                 // keep track of number of times we had to spin, just in case the number is unexpectedly huge
    34                 size_t spin_count;
    3533        #endif
    3634};
     
    5048        static inline void ?{}( __spinlock_t & this ) {
    5149                this.lock = 0;
    52                 #ifdef __CFA_DEBUG__
    53                         this.spin_count = 0;
    54                 #endif
    5550        }
    5651
     
    7772                for ( unsigned int i = 1;; i += 1 ) {
    7873                        if ( (this.lock == 0) && (__atomic_test_and_set( &this.lock, __ATOMIC_ACQUIRE ) == 0) ) break;
    79                         #ifdef __CFA_DEBUG__
    80                                 this.spin_count++;
    81                         #endif
    8274                        #ifndef NOEXPBACK
    8375                                // exponential spin
  • libcfa/src/bits/random.hfa

    r12c1eef r5235d49  
    1 //
    2 // Cforall Version 1.0.0 Copyright (C) 2022 University of Waterloo
    3 //
    4 // The contents of this file are covered under the licence agreement in the
    5 // file "LICENCE" distributed with Cforall.
    6 //
    7 // random.hfa --
    8 //
    9 // Author           : Peter A. Buhr
    10 // Created On       : Fri Jan 14 07:18:11 2022
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jan 14 07:18:58 2022
    13 // Update Count     : 1
    14 //
    15 
    161#pragma once
    172
    183#include <stdint.h>
    194
    20 // Pipelined to allow out-of-order overlap with reduced dependencies. Critically, the current random state is returned
    21 // (copied), and then compute and store the next random value.
    22 
     5//--------------------------------------------------
    236#if defined(__SIZEOF_INT128__)
    24 //--------------------------------------------------
    25         static inline uint64_t lehmer64( __uint128_t & state ) {
    26                 __uint128_t ret = state;
     7        typedef __uint128_t __lehmer64_state_t;
     8        static inline uint64_t __lehmer64( __lehmer64_state_t & state ) {
    279                state *= 0xda942042e4dd58b5;
    28                 return ret >> 64;
     10                return state >> 64;
    2911        }
    3012
    3113//--------------------------------------------------
    32         static inline uint64_t wyhash64( uint64_t & state ) {
     14        typedef uint64_t __wyhash64_state_t;
     15        static inline uint64_t __wyhash64( __wyhash64_state_t & state ) {
    3316                state += 0x60bee2bee120fc15;
    3417                __uint128_t tmp;
     
    4225
    4326//--------------------------------------------------
    44 static inline uint64_t xorshift_13_7_17( uint64_t & state ) {
    45         uint64_t ret = state;
    46         state ^= state << 13;
    47         state ^= state >> 7;
    48         state ^= state << 17;
    49         return ret;
     27typedef uint64_t __xorshift64_state_t;
     28static inline uint64_t __xorshift64( __xorshift64_state_t & state ) {
     29        uint64_t x = state;
     30        x ^= x << 13;
     31        x ^= x >> 7;
     32        x ^= x << 17;
     33        return state = x;
    5034}
    51 
    52 //--------------------------------------------------
    53 static inline uint32_t xorshift_6_21_7( uint32_t & state ) {
    54         uint32_t ret = state;
    55         state ^= state << 6;
    56         state ^= state >> 21;
    57         state ^= state << 7;
    58         return ret;
    59 } // xorshift_6_21_7
    6035
    6136//--------------------------------------------------
     
    6338  uint32_t a, b, c, d;
    6439  uint32_t counter;
    65 } xorwow__state_t;
     40} __xorwow__state_t;
    6641
    67 // The state array must be initialized to not be all zero in the first four words.
    68 static inline uint32_t xorwow( xorwow__state_t & state ) {
    69         // Algorithm "xorwow" from p. 5 of Marsaglia, "Xorshift RNGs".
    70         uint32_t ret = state.a + state.counter;
     42/* The state array must be initialized to not be all zero in the first four words */
     43static inline uint32_t __xorwow( __xorwow__state_t & state ) {
     44        /* Algorithm "xorwow" from p. 5 of Marsaglia, "Xorshift RNGs" */
    7145        uint32_t t = state.d;
    7246
     
    8256
    8357        state.counter += 362437;
    84         return ret;
     58        return t + state.counter;
    8559}
    86 
    87 //--------------------------------------------------
    88 static inline uint32_t LCG( uint32_t & state ) {                // linear congruential generator
    89         uint32_t ret = state;
    90         state = 36969 * (state & 65535) + (state >> 16);        // 36969 is NOT prime! No not change it!
    91         return ret;
    92 } // LCG
    93 
    94 //--------------------------------------------------
    95 #define M  (1_l64u << 48_l64u)
    96 #define A  (25214903917_l64u)
    97 #define AI (18446708753438544741_l64u)
    98 #define C  (11_l64u)
    99 #define D  (16_l64u)
    100 
    101 // Bi-directional LCG random-number generator
    102 static inline uint32_t LCGBI_fwd( uint64_t & state ) {
    103         state = (A * state + C) & (M - 1);
    104         return state >> D;
    105 }
    106 
    107 static inline uint32_t LCGBI_bck( uint64_t & state ) {
    108         unsigned int r = state >> D;
    109         state = AI * (state - C) & (M - 1);
    110         return r;
    111 }
    112 
    113 #undef M
    114 #undef A
    115 #undef AI
    116 #undef C
    117 #undef D
  • libcfa/src/common.hfa

    r12c1eef r5235d49  
    1 //
     1// 
    22// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
    33//
    44// The contents of this file are covered under the licence agreement in the
    55// file "LICENCE" distributed with Cforall.
    6 //
    7 // common.hfa --
    8 //
     6// 
     7// common --
     8// 
    99// Author           : Peter A. Buhr
    1010// Created On       : Wed Jul 11 17:54:36 2018
     
    1212// Last Modified On : Wed May  5 14:02:04 2021
    1313// Update Count     : 18
    14 //
     14// 
    1515
    1616#pragma once
  • libcfa/src/concurrency/clib/cfathread.cfa

    r12c1eef r5235d49  
    2222#include "thread.hfa"
    2323#include "time.hfa"
    24 #include "stdlib.hfa"
    2524
    2625#include "cfathread.h"
     
    196195                                eevent.data.u64 = (uint64_t)active_thread();
    197196
    198                                 int id = prng() % poller_cnt;
     197                                int id = thread_rand() % poller_cnt;
    199198                                if(0 != epoll_ctl(poller_fds[id], EPOLL_CTL_ADD, fd, &eevent))
    200199                                {
  • libcfa/src/concurrency/coroutine.hfa

    r12c1eef r5235d49  
    1010// Created On       : Mon Nov 28 12:27:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jan  6 16:33:16 2022
    13 // Update Count     : 12
     12// Last Modified On : Tue Feb  4 12:29:26 2020
     13// Update Count     : 11
    1414//
    1515
     
    155155
    156156        if( unlikely(dst->context.SP == 0p) ) {
    157                 __stack_prepare(&dst->stack, DEFAULT_STACK_SIZE);
     157                __stack_prepare(&dst->stack, 65000);
    158158                __cfactx_start(main, dst, cor, __cfactx_invoke_coroutine);
    159159        }
  • libcfa/src/concurrency/invoke.h

    r12c1eef r5235d49  
    1010// Created On       : Tue Jan 17 12:27:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Jan  9 19:06:45 2022
    13 // Update Count     : 48
     12// Last Modified On : Thu Dec  5 16:26:03 2019
     13// Update Count     : 44
    1414//
    1515
     
    2727#ifndef _INVOKE_H_
    2828#define _INVOKE_H_
    29 
    30         enum { DEFAULT_STACK_SIZE = 65000 };
    3129
    3230        struct __cfaehm_try_resume_node;
     
    211209                struct processor * last_proc;
    212210
    213                 uint32_t random_state;                                                  // fast random numbers
    214 
    215211                #if defined( __CFA_WITH_VERIFY__ )
    216212                        void * canary;
  • libcfa/src/concurrency/io.cfa

    r12c1eef r5235d49  
    144144                __ioarbiter_flush( ctx );
    145145
    146                 if(ctx.sq.to_submit != 0 || min_comp > 0) {
    147 
    148                         __STATS__( true, io.calls.flush++; )
    149                         int ret = syscall( __NR_io_uring_enter, ctx.fd, ctx.sq.to_submit, min_comp, min_comp > 0 ? IORING_ENTER_GETEVENTS : 0, (sigset_t *)0p, _NSIG / 8);
    150                         if( ret < 0 ) {
    151                                 switch((int)errno) {
    152                                 case EAGAIN:
    153                                 case EINTR:
    154                                 case EBUSY:
    155                                         // Update statistics
    156                                         __STATS__( false, io.calls.errors.busy ++; )
    157                                         return false;
    158                                 default:
    159                                         abort( "KERNEL ERROR: IO_URING SYSCALL - (%d) %s\n", (int)errno, strerror(errno) );
    160                                 }
     146                __STATS__( true, io.calls.flush++; )
     147                int ret = syscall( __NR_io_uring_enter, ctx.fd, ctx.sq.to_submit, min_comp, min_comp > 0 ? IORING_ENTER_GETEVENTS : 0, (sigset_t *)0p, _NSIG / 8);
     148                if( ret < 0 ) {
     149                        switch((int)errno) {
     150                        case EAGAIN:
     151                        case EINTR:
     152                        case EBUSY:
     153                                // Update statistics
     154                                __STATS__( false, io.calls.errors.busy ++; )
     155                                return false;
     156                        default:
     157                                abort( "KERNEL ERROR: IO_URING SYSCALL - (%d) %s\n", (int)errno, strerror(errno) );
    161158                        }
    162 
    163                         __cfadbg_print_safe(io, "Kernel I/O : %u submitted to io_uring %d\n", ret, ctx.fd);
    164                         __STATS__( true, io.calls.submitted += ret; )
    165                         /* paranoid */ verify( ctx.sq.to_submit <= *ctx.sq.num );
    166                         /* paranoid */ verify( ctx.sq.to_submit >= ret );
    167 
    168                         ctx.sq.to_submit -= ret;
    169 
    170                         /* paranoid */ verify( ctx.sq.to_submit <= *ctx.sq.num );
    171 
    172                         // Release the consumed SQEs
    173                         __release_sqes( ctx );
    174 
    175                         /* paranoid */ verify( ! __preemption_enabled() );
    176 
    177                         ctx.proc->io.pending = false;
    178                 }
    179 
     159                }
     160
     161                __cfadbg_print_safe(io, "Kernel I/O : %u submitted to io_uring %d\n", ret, ctx.fd);
     162                __STATS__( true, io.calls.submitted += ret; )
     163                /* paranoid */ verify( ctx.sq.to_submit <= *ctx.sq.num );
     164                /* paranoid */ verify( ctx.sq.to_submit >= ret );
     165
     166                ctx.sq.to_submit -= ret;
     167
     168                /* paranoid */ verify( ctx.sq.to_submit <= *ctx.sq.num );
     169
     170                // Release the consumed SQEs
     171                __release_sqes( ctx );
     172
     173                /* paranoid */ verify( ! __preemption_enabled() );
     174
     175                ctx.proc->io.pending = false;
    180176                ready_schedule_lock();
    181177                bool ret = __cfa_io_drain( proc );
     
    552548                        /* paranoid */ verify( proc == __cfaabi_tls.this_processor );
    553549                        /* paranoid */ verify( ! __preemption_enabled() );
    554 
    555                         return true;
    556550                }
    557551        #endif
  • libcfa/src/concurrency/kernel.cfa

    r12c1eef r5235d49  
    142142extern void __disable_interrupts_hard();
    143143extern void __enable_interrupts_hard();
     144
     145static inline void __disable_interrupts_checked() {
     146        /* paranoid */ verify( __preemption_enabled() );
     147        disable_interrupts();
     148        /* paranoid */ verify( ! __preemption_enabled() );
     149}
     150
     151static inline void __enable_interrupts_checked( bool poll = true ) {
     152        /* paranoid */ verify( ! __preemption_enabled() );
     153        enable_interrupts( poll );
     154        /* paranoid */ verify( __preemption_enabled() );
     155}
    144156
    145157
     
    554566        /* paranoid */ verify( 0x0D15EA5E0D15EA5Ep == thrd->canary );
    555567
     568        const bool local = thrd->state != Start;
    556569        if (thrd->preempted == __NO_PREEMPTION) thrd->state = Ready;
    557570
     
    736749
    737750        // Check if there is a sleeping processor
    738         // int fd = __atomic_load_n(&this->procs.fd, __ATOMIC_SEQ_CST);
    739         int fd = 0;
    740         if( __atomic_load_n(&this->procs.fd, __ATOMIC_SEQ_CST) != 0 ) {
    741                 fd = __atomic_exchange_n(&this->procs.fd, 0, __ATOMIC_RELAXED);
    742         }
     751        int fd = __atomic_load_n(&this->procs.fd, __ATOMIC_SEQ_CST);
    743752
    744753        // If no one is sleeping, we are done
     
    767776// Unconditionnaly wake a thread
    768777void __wake_proc(processor * this) {
    769         /* paranoid */ verify( ! __preemption_enabled() );
    770 
    771778        __cfadbg_print_safe(runtime_core, "Kernel : waking Processor %p\n", this);
    772779
    773         eventfd_t val;
    774         val = 1;
    775         eventfd_write( this->idle_fd, val );
    776 
    777         /* paranoid */ verify( ! __preemption_enabled() );
     780        __disable_interrupts_checked();
     781                /* paranoid */ verify( ! __preemption_enabled() );
     782                eventfd_t val;
     783                val = 1;
     784                eventfd_write( this->idle_fd, val );
     785        __enable_interrupts_checked();
    778786}
    779787
  • libcfa/src/concurrency/kernel.hfa

    r12c1eef r5235d49  
    6767                unsigned target;
    6868                unsigned last;
    69                 signed   cpu;
     69                unsigned cnt;
     70                unsigned long long int cutoff;
    7071        } rdq;
    7172
     
    151152        volatile unsigned long long tv;
    152153        volatile unsigned long long ma;
    153 };
    154 
    155 struct __attribute__((aligned(16))) __cache_id_t {
    156         volatile unsigned id;
    157154};
    158155
     
    167164static inline void ^?{}(__timestamp_t & this) {}
    168165
    169 struct __attribute__((aligned(128))) __ready_queue_caches_t;
    170 void  ?{}(__ready_queue_caches_t & this);
    171 void ^?{}(__ready_queue_caches_t & this);
    172 
    173166//TODO adjust cache size to ARCHITECTURE
    174 // Structure holding the ready queue
     167// Structure holding the relaxed ready queue
    175168struct __ready_queue_t {
    176169        // Data tracking the actual lanes
     
    184177                // Array of times
    185178                __timestamp_t * volatile tscs;
    186 
    187                 __cache_id_t * volatile caches;
    188179
    189180                // Array of stats
  • libcfa/src/concurrency/kernel/fwd.hfa

    r12c1eef r5235d49  
    7777
    7878                static inline uint64_t __tls_rand() {
    79                         return
    8079                        #if defined(__SIZEOF_INT128__)
    81                                 lehmer64( kernelTLS().rand_seed );
     80                                return __lehmer64( kernelTLS().rand_seed );
    8281                        #else
    83                                 xorshift_13_7_17( kernelTLS().rand_seed );
     82                                return __xorshift64( kernelTLS().rand_seed );
    8483                        #endif
    8584                }
    8685
     86                #define M  (1_l64u << 48_l64u)
     87                #define A  (25214903917_l64u)
     88                #define AI (18446708753438544741_l64u)
     89                #define C  (11_l64u)
     90                #define D  (16_l64u)
     91
    8792                static inline unsigned __tls_rand_fwd() {
    88                         return LCGBI_fwd( kernelTLS().ready_rng.fwd_seed );
     93
     94                        kernelTLS().ready_rng.fwd_seed = (A * kernelTLS().ready_rng.fwd_seed + C) & (M - 1);
     95                        return kernelTLS().ready_rng.fwd_seed >> D;
    8996                }
    9097
    9198                static inline unsigned __tls_rand_bck() {
    92                         return LCGBI_bck( kernelTLS().ready_rng.bck_seed );
    93                 }
     99                        unsigned int r = kernelTLS().ready_rng.bck_seed >> D;
     100                        kernelTLS().ready_rng.bck_seed = AI * (kernelTLS().ready_rng.bck_seed - C) & (M - 1);
     101                        return r;
     102                }
     103
     104                #undef M
     105                #undef A
     106                #undef AI
     107                #undef C
     108                #undef D
    94109
    95110                static inline void __tls_rand_advance_bck(void) {
     
    97112                }
    98113        }
     114
     115
    99116
    100117        extern void disable_interrupts();
     
    125142                        }
    126143                }
     144
     145                extern uint64_t thread_rand();
    127146
    128147                // Semaphore which only supports a single thread
  • libcfa/src/concurrency/kernel/startup.cfa

    r12c1eef r5235d49  
    3434#include "kernel_private.hfa"
    3535#include "startup.hfa"          // STARTUP_PRIORITY_XXX
    36 #include "limits.hfa"
    3736#include "math.hfa"
    3837
     
    102101extern void __wake_proc(processor *);
    103102extern int cfa_main_returned;                                                   // from interpose.cfa
    104 extern uint32_t __global_random_seed;
    105103
    106104//-----------------------------------------------------------------------------
     
    178176
    179177
     178
    180179//=============================================================================================
    181180// Kernel Setup logic
     
    280279        // When its coroutine terminates, it return control to the mainThread
    281280        // which is currently here
    282         /* paranoid */ verify( !__atomic_load_n(&mainProcessor->do_terminate, __ATOMIC_ACQUIRE) );
    283281        __atomic_store_n(&mainProcessor->do_terminate, true, __ATOMIC_RELEASE);
    284         __wake_proc( mainProcessor );
    285282        __kernel_last_resume( __cfaabi_tls.this_processor );
    286283        mainThread->self_cor.state = Halted;
     
    406403
    407404        __cfaabi_tls.this_thread->curr_cor = dst;
    408         __stack_prepare( &dst->stack, DEFAULT_STACK_SIZE );
     405        __stack_prepare( &dst->stack, 65000 );
    409406        __cfactx_start(main, dst, this->runner, __cfactx_invoke_coroutine);
    410407
     
    490487        preferred = ready_queue_new_preferred();
    491488        last_proc = 0p;
    492         random_state = __global_random_seed;
    493489        #if defined( __CFA_WITH_VERIFY__ )
    494490                canary = 0x0D15EA5E0D15EA5Ep;
     
    515511        this.rdq.its = 0;
    516512        this.rdq.itr = 0;
    517         this.rdq.id  = MAX;
    518         this.rdq.target = MAX;
    519         this.rdq.last = MAX;
    520         this.rdq.cpu = 0;
    521         // this.rdq.cutoff = 0ull;
     513        this.rdq.id  = -1u;
     514        this.rdq.target = -1u;
     515        this.rdq.last = -1u;
     516        this.rdq.cutoff = 0ull;
    522517        do_terminate = false;
    523518        preemption_alarm = 0p;
     
    569564extern size_t __page_size;
    570565void ^?{}(processor & this) with( this ){
    571         /* paranoid */ verify( !__atomic_load_n(&do_terminate, __ATOMIC_ACQUIRE) );
    572         __cfadbg_print_safe(runtime_core, "Kernel : core %p signaling termination\n", &this);
    573 
    574         __atomic_store_n(&do_terminate, true, __ATOMIC_RELAXED);
    575         __disable_interrupts_checked();
     566        if( ! __atomic_load_n(&do_terminate, __ATOMIC_ACQUIRE) ) {
     567                __cfadbg_print_safe(runtime_core, "Kernel : core %p signaling termination\n", &this);
     568
     569                __atomic_store_n(&do_terminate, true, __ATOMIC_RELAXED);
    576570                __wake_proc( &this );
    577         __enable_interrupts_checked();
    578 
    579         wait( terminated );
    580         /* paranoid */ verify( active_processor() != &this);
     571
     572                wait( terminated );
     573                /* paranoid */ verify( active_processor() != &this);
     574        }
    581575
    582576        __destroy_pthread( kernel_thread, this.stack, 0p );
     
    688682        [this->unique_id, last_size] = ready_mutate_register();
    689683
    690                 this->rdq.cpu = __kernel_getcpu();
    691 
    692684                this->cltr->procs.total += 1u;
    693685                insert_last(this->cltr->procs.actives, *this);
     
    729721        check( pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute
    730722
    731         size_t stacksize = DEFAULT_STACK_SIZE;
     723        size_t stacksize;
     724        // default stack size, normally defined by shell limit
     725        check( pthread_attr_getstacksize( &attr, &stacksize ), "pthread_attr_getstacksize" );
     726        assert( stacksize >= PTHREAD_STACK_MIN );
    732727
    733728        void * stack;
     
    754749        #endif
    755750
     751
    756752        check( pthread_attr_setstack( &attr, stack, stacksize ), "pthread_attr_setstack" );
     753
    757754        check( pthread_create( pthread, &attr, start, arg ), "pthread_create" );
    758755        return stack;
  • libcfa/src/concurrency/kernel_private.hfa

    r12c1eef r5235d49  
    6060extern bool __preemption_enabled();
    6161
    62 static inline void __disable_interrupts_checked() {
    63         /* paranoid */ verify( __preemption_enabled() );
    64         disable_interrupts();
    65         /* paranoid */ verify( ! __preemption_enabled() );
    66 }
    67 
    68 static inline void __enable_interrupts_checked( bool poll = true ) {
    69         /* paranoid */ verify( ! __preemption_enabled() );
    70         enable_interrupts( poll );
    71         /* paranoid */ verify( __preemption_enabled() );
    72 }
    73 
    7462//release/wake-up the following resources
    7563void __thread_finish( thread$ * thrd );
  • libcfa/src/concurrency/locks.hfa

    r12c1eef r5235d49  
    3131
    3232//-----------------------------------------------------------------------------
     33// Semaphores
     34
     35// '0-nary' semaphore
     36// Similar to a counting semaphore except the value of one is never reached
     37// as a consequence, a V() that would bring the value to 1 *spins* until
     38// a P consumes it
     39struct Semaphore0nary {
     40        __spinlock_t lock; // needed to protect
     41        mpsc_queue(thread$) queue;
     42};
     43
     44static inline bool P(Semaphore0nary & this, thread$ * thrd) {
     45        /* paranoid */ verify(!thrd`next);
     46        /* paranoid */ verify(!(&(*thrd)`next));
     47
     48        push(this.queue, thrd);
     49        return true;
     50}
     51
     52static inline bool P(Semaphore0nary & this) {
     53    thread$ * thrd = active_thread();
     54    P(this, thrd);
     55    park();
     56    return true;
     57}
     58
     59static inline thread$ * V(Semaphore0nary & this, bool doUnpark = true) {
     60        thread$ * next;
     61        lock(this.lock __cfaabi_dbg_ctx2);
     62                for (;;) {
     63                        next = pop(this.queue);
     64                        if (next) break;
     65                        Pause();
     66                }
     67        unlock(this.lock);
     68
     69        if (doUnpark) unpark(next);
     70        return next;
     71}
     72
     73// Wrapper used on top of any sempahore to avoid potential locking
     74struct BinaryBenaphore {
     75        volatile ssize_t counter;
     76};
     77
     78static inline {
     79        void ?{}(BinaryBenaphore & this) { this.counter = 0; }
     80        void ?{}(BinaryBenaphore & this, zero_t) { this.counter = 0; }
     81        void ?{}(BinaryBenaphore & this, one_t ) { this.counter = 1; }
     82
     83        // returns true if no blocking needed
     84        bool P(BinaryBenaphore & this) {
     85                return __atomic_fetch_sub(&this.counter, 1, __ATOMIC_SEQ_CST) > 0;
     86        }
     87
     88        bool tryP(BinaryBenaphore & this) {
     89                ssize_t c = this.counter;
     90                /* paranoid */ verify( c > MIN );
     91                return (c >= 1) && __atomic_compare_exchange_n(&this.counter, &c, c-1, false, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);
     92        }
     93
     94        // returns true if notify needed
     95        bool V(BinaryBenaphore & this) {
     96                ssize_t c = 0;
     97                for () {
     98                        /* paranoid */ verify( this.counter < MAX );
     99                        if (__atomic_compare_exchange_n(&this.counter, &c, c+1, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
     100                                if (c == 0) return true;
     101                                /* paranoid */ verify(c < 0);
     102                                return false;
     103                        } else {
     104                                if (c == 1) return true;
     105                                /* paranoid */ verify(c < 1);
     106                                Pause();
     107                        }
     108                }
     109        }
     110}
     111
     112// Binary Semaphore based on the BinaryBenaphore on top of the 0-nary Semaphore
     113struct ThreadBenaphore {
     114        BinaryBenaphore ben;
     115        Semaphore0nary  sem;
     116};
     117
     118static inline void ?{}(ThreadBenaphore & this) {}
     119static inline void ?{}(ThreadBenaphore & this, zero_t) { (this.ben){ 0 }; }
     120static inline void ?{}(ThreadBenaphore & this, one_t ) { (this.ben){ 1 }; }
     121
     122static inline bool P(ThreadBenaphore & this)              { return P(this.ben) ? false : P(this.sem); }
     123static inline bool tryP(ThreadBenaphore & this)           { return tryP(this.ben); }
     124static inline bool P(ThreadBenaphore & this, bool wait)   { return wait ? P(this) : tryP(this); }
     125
     126static inline thread$ * V(ThreadBenaphore & this, bool doUnpark = true) {
     127        if (V(this.ben)) return 0p;
     128        return V(this.sem, doUnpark);
     129}
     130
     131//-----------------------------------------------------------------------------
    33132// Semaphore
    34133struct semaphore {
     
    72171static inline void   on_wakeup( owner_lock & this, size_t v ) { on_wakeup ( (blocking_lock &)this, v ); }
    73172static inline void   on_notify( owner_lock & this, struct thread$ * t ) { on_notify( (blocking_lock &)this, t ); }
     173
     174struct fast_lock {
     175        thread$ * volatile owner;
     176        ThreadBenaphore sem;
     177};
     178
     179static inline void ?{}(fast_lock & this) { this.owner = 0p; }
     180
     181static inline bool $try_lock(fast_lock & this, thread$ * thrd) {
     182    thread$ * exp = 0p;
     183    return __atomic_compare_exchange_n(&this.owner, &exp, thrd, false, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);
     184}
     185
     186static inline void lock( fast_lock & this ) __attribute__((artificial));
     187static inline void lock( fast_lock & this ) {
     188        thread$ * thrd = active_thread();
     189        /* paranoid */verify(thrd != this.owner);
     190
     191        for (;;) {
     192                if ($try_lock(this, thrd)) return;
     193                P(this.sem);
     194        }
     195}
     196
     197static inline bool try_lock( fast_lock & this ) __attribute__((artificial));
     198static inline bool try_lock ( fast_lock & this ) {
     199        thread$ * thrd = active_thread();
     200        /* paranoid */ verify(thrd != this.owner);
     201        return $try_lock(this, thrd);
     202}
     203
     204static inline thread$ * unlock( fast_lock & this ) __attribute__((artificial));
     205static inline thread$ * unlock( fast_lock & this ) {
     206        /* paranoid */ verify(active_thread() == this.owner);
     207
     208        // open 'owner' before unlocking anyone
     209        // so new and unlocked threads don't park incorrectly.
     210        // This may require additional fencing on ARM.
     211        this.owner = 0p;
     212
     213        return V(this.sem);
     214}
     215
     216static inline size_t on_wait( fast_lock & this ) { unlock(this); return 0; }
     217static inline void on_wakeup( fast_lock & this, size_t ) { lock(this); }
     218static inline void on_notify( fast_lock &, struct thread$ * t ) { unpark(t); }
    74219
    75220struct mcs_node {
  • libcfa/src/concurrency/ready_queue.cfa

    r12c1eef r5235d49  
    2020
    2121
    22 // #define USE_RELAXED_FIFO
     22#define USE_RELAXED_FIFO
    2323// #define USE_WORK_STEALING
    2424// #define USE_CPU_WORK_STEALING
    25 #define USE_AWARE_STEALING
    2625
    2726#include "bits/defs.hfa"
     
    3029
    3130#include "stdlib.hfa"
    32 #include "limits.hfa"
    3331#include "math.hfa"
    3432
     
    5654#endif
    5755
    58 #if   defined(USE_AWARE_STEALING)
    59         #define READYQ_SHARD_FACTOR 2
    60         #define SEQUENTIAL_SHARD 2
    61 #elif defined(USE_CPU_WORK_STEALING)
     56#if   defined(USE_CPU_WORK_STEALING)
    6257        #define READYQ_SHARD_FACTOR 2
    6358#elif defined(USE_RELAXED_FIFO)
     
    143138        __kernel_rseq_register();
    144139
     140        __cfadbg_print_safe(ready_queue, "Kernel : Registering proc %p for RW-Lock\n", proc);
    145141        bool * handle = (bool *)&kernelTLS().sched_lock;
    146142
     
    178174        }
    179175
     176        __cfadbg_print_safe(ready_queue, "Kernel : Registering proc %p done, id %lu\n", proc, n);
     177
    180178        // Return new spot.
    181179        /* paranoid */ verify(n < ready);
     
    192190
    193191        __atomic_store_n(cell, 0p, __ATOMIC_RELEASE);
     192
     193        __cfadbg_print_safe(ready_queue, "Kernel : Unregister proc %p\n", proc);
    194194
    195195        __kernel_rseq_unregister();
     
    244244
    245245//=======================================================================
    246 // caches handling
    247 
    248 struct __attribute__((aligned(128))) __ready_queue_caches_t {
    249         // Count States:
    250         // - 0  : No one is looking after this cache
    251         // - 1  : No one is looking after this cache, BUT it's not empty
    252         // - 2+ : At least one processor is looking after this cache
    253         volatile unsigned count;
    254 };
    255 
    256 void  ?{}(__ready_queue_caches_t & this) { this.count = 0; }
    257 void ^?{}(__ready_queue_caches_t & this) {}
    258 
    259 static inline void depart(__ready_queue_caches_t & cache) {
    260         /* paranoid */ verify( cache.count > 1);
    261         __atomic_fetch_add(&cache.count, -1, __ATOMIC_SEQ_CST);
    262         /* paranoid */ verify( cache.count != 0);
    263         /* paranoid */ verify( cache.count < 65536 ); // This verify assumes no cluster will have more than 65000 kernel threads mapped to a single cache, which could be correct but is super weird.
    264 }
    265 
    266 static inline void arrive(__ready_queue_caches_t & cache) {
    267         // for() {
    268         //      unsigned expected = cache.count;
    269         //      unsigned desired  = 0 == expected ? 2 : expected + 1;
    270         // }
    271 }
    272 
    273 //=======================================================================
    274246// Cforall Ready Queue used for scheduling
    275247//=======================================================================
    276 unsigned long long moving_average(unsigned long long currtsc, unsigned long long instsc, unsigned long long old_avg) {
    277         /* paranoid */ verifyf( currtsc < 45000000000000000, "Suspiciously large current time: %'llu (%llx)\n", currtsc, currtsc );
    278         /* paranoid */ verifyf( instsc  < 45000000000000000, "Suspiciously large insert time: %'llu (%llx)\n", instsc, instsc );
    279         /* paranoid */ verifyf( old_avg < 15000000000000, "Suspiciously large previous average: %'llu (%llx)\n", old_avg, old_avg );
    280 
    281         const unsigned long long new_val = currtsc > instsc ? currtsc - instsc : 0;
    282         const unsigned long long total_weight = 16;
    283         const unsigned long long new_weight   = 4;
    284         const unsigned long long old_weight = total_weight - new_weight;
    285         const unsigned long long ret = ((new_weight * new_val) + (old_weight * old_avg)) / total_weight;
    286         return ret;
     248unsigned long long moving_average(unsigned long long nval, unsigned long long oval) {
     249        const unsigned long long tw = 16;
     250        const unsigned long long nw = 4;
     251        const unsigned long long ow = tw - nw;
     252        return ((nw * nval) + (ow * oval)) / tw;
    287253}
    288254
     
    305271                }
    306272        #else
    307                 lanes.data   = 0p;
    308                 lanes.tscs   = 0p;
    309                 lanes.caches = 0p;
    310                 lanes.help   = 0p;
    311                 lanes.count  = 0;
     273                lanes.data  = 0p;
     274                lanes.tscs  = 0p;
     275                lanes.help  = 0p;
     276                lanes.count = 0;
    312277        #endif
    313278}
     
    320285        free(lanes.data);
    321286        free(lanes.tscs);
    322         free(lanes.caches);
    323287        free(lanes.help);
    324288}
    325289
    326290//-----------------------------------------------------------------------
    327 #if defined(USE_AWARE_STEALING)
    328         __attribute__((hot)) void push(struct cluster * cltr, struct thread$ * thrd, unpark_hint hint) with (cltr->ready_queue) {
    329                 processor * const proc = kernelTLS().this_processor;
    330                 const bool external = (!proc) || (cltr != proc->cltr);
    331                 const bool remote   = hint == UNPARK_REMOTE;
    332 
    333                 unsigned i;
    334                 if( external || remote ) {
    335                         // Figure out where thread was last time and make sure it's valid
    336                         /* paranoid */ verify(thrd->preferred >= 0);
    337                         if(thrd->preferred * READYQ_SHARD_FACTOR < lanes.count) {
    338                                 /* paranoid */ verify(thrd->preferred * READYQ_SHARD_FACTOR < lanes.count);
    339                                 unsigned start = thrd->preferred * READYQ_SHARD_FACTOR;
    340                                 do {
    341                                         unsigned r = __tls_rand();
    342                                         i = start + (r % READYQ_SHARD_FACTOR);
    343                                         /* paranoid */ verify( i < lanes.count );
    344                                         // If we can't lock it retry
    345                                 } while( !__atomic_try_acquire( &lanes.data[i].lock ) );
    346                         } else {
    347                                 do {
    348                                         i = __tls_rand() % lanes.count;
    349                                 } while( !__atomic_try_acquire( &lanes.data[i].lock ) );
    350                         }
    351                 } else {
    352                         do {
    353                                 unsigned r = proc->rdq.its++;
    354                                 i = proc->rdq.id + (r % READYQ_SHARD_FACTOR);
    355                                 /* paranoid */ verify( i < lanes.count );
    356                                 // If we can't lock it retry
    357                         } while( !__atomic_try_acquire( &lanes.data[i].lock ) );
    358                 }
    359 
    360                 // Actually push it
    361                 push(lanes.data[i], thrd);
    362 
    363                 // Unlock and return
    364                 __atomic_unlock( &lanes.data[i].lock );
    365 
    366                 #if !defined(__CFA_NO_STATISTICS__)
    367                         if(unlikely(external || remote)) __atomic_fetch_add(&cltr->stats->ready.push.extrn.success, 1, __ATOMIC_RELAXED);
    368                         else __tls_stats()->ready.push.local.success++;
    369                 #endif
    370         }
    371 
    372         static inline unsigned long long calc_cutoff(const unsigned long long ctsc, const processor * proc, __ready_queue_t & rdq) {
    373                 unsigned start = proc->rdq.id;
    374                 unsigned long long max = 0;
    375                 for(i; READYQ_SHARD_FACTOR) {
    376                         unsigned long long ptsc = ts(rdq.lanes.data[start + i]);
    377                         if(ptsc != -1ull) {
    378                                 /* paranoid */ verify( start + i < rdq.lanes.count );
    379                                 unsigned long long tsc = moving_average(ctsc, ptsc, rdq.lanes.tscs[start + i].ma);
    380                                 if(tsc > max) max = tsc;
    381                         }
    382                 }
    383                 return (max + 2 * max) / 2;
    384         }
    385 
    386         __attribute__((hot)) struct thread$ * pop_fast(struct cluster * cltr) with (cltr->ready_queue) {
    387                 /* paranoid */ verify( lanes.count > 0 );
    388                 /* paranoid */ verify( kernelTLS().this_processor );
    389                 /* paranoid */ verify( kernelTLS().this_processor->rdq.id < lanes.count );
    390 
    391                 processor * const proc = kernelTLS().this_processor;
    392                 unsigned this = proc->rdq.id;
    393                 /* paranoid */ verify( this < lanes.count );
    394                 __cfadbg_print_safe(ready_queue, "Kernel : pop from %u\n", this);
    395 
    396                 // Figure out the current cpu and make sure it is valid
    397                 const int cpu = __kernel_getcpu();
    398                 /* paranoid */ verify(cpu >= 0);
    399                 /* paranoid */ verify(cpu < cpu_info.hthrd_count);
    400                 unsigned this_cache = cpu_info.llc_map[cpu].cache;
    401 
    402                 // Super important: don't write the same value over and over again
    403                 // We want to maximise our chances that his particular values stays in cache
    404                 if(lanes.caches[this / READYQ_SHARD_FACTOR].id != this_cache)
    405                         __atomic_store_n(&lanes.caches[this / READYQ_SHARD_FACTOR].id, this_cache, __ATOMIC_RELAXED);
    406 
    407                 const unsigned long long ctsc = rdtscl();
    408 
    409                 if(proc->rdq.target == MAX) {
    410                         uint64_t chaos = __tls_rand();
    411                         unsigned ext = chaos & 0xff;
    412                         unsigned other  = (chaos >> 8) % (lanes.count);
    413 
    414                         if(ext < 3 || __atomic_load_n(&lanes.caches[other / READYQ_SHARD_FACTOR].id, __ATOMIC_RELAXED) == this_cache) {
    415                                 proc->rdq.target = other;
    416                         }
    417                 }
    418                 else {
    419                         const unsigned target = proc->rdq.target;
    420                         __cfadbg_print_safe(ready_queue, "Kernel : %u considering helping %u, tcsc %llu\n", this, target, lanes.tscs[target].tv);
    421                         /* paranoid */ verify( lanes.tscs[target].tv != MAX );
    422                         if(target < lanes.count) {
    423                                 const unsigned long long cutoff = calc_cutoff(ctsc, proc, cltr->ready_queue);
    424                                 const unsigned long long age = moving_average(ctsc, lanes.tscs[target].tv, lanes.tscs[target].ma);
    425                                 __cfadbg_print_safe(ready_queue, "Kernel : Help attempt on %u from %u, age %'llu vs cutoff %'llu, %s\n", target, this, age, cutoff, age > cutoff ? "yes" : "no");
    426                                 if(age > cutoff) {
    427                                         thread$ * t = try_pop(cltr, target __STATS(, __tls_stats()->ready.pop.help));
    428                                         if(t) return t;
    429                                 }
    430                         }
    431                         proc->rdq.target = MAX;
    432                 }
    433 
    434                 for(READYQ_SHARD_FACTOR) {
    435                         unsigned i = this + (proc->rdq.itr++ % READYQ_SHARD_FACTOR);
    436                         if(thread$ * t = try_pop(cltr, i __STATS(, __tls_stats()->ready.pop.local))) return t;
    437                 }
    438 
    439                 // All lanes where empty return 0p
    440                 return 0p;
    441 
    442         }
    443         __attribute__((hot)) struct thread$ * pop_slow(struct cluster * cltr) with (cltr->ready_queue) {
    444                 unsigned i = __tls_rand() % lanes.count;
    445                 return try_pop(cltr, i __STATS(, __tls_stats()->ready.pop.steal));
    446         }
    447         __attribute__((hot)) struct thread$ * pop_search(struct cluster * cltr) {
    448                 return search(cltr);
    449         }
    450 #endif
    451291#if defined(USE_CPU_WORK_STEALING)
    452292        __attribute__((hot)) void push(struct cluster * cltr, struct thread$ * thrd, unpark_hint hint) with (cltr->ready_queue) {
     
    510350                /* paranoid */ verify( kernelTLS().this_processor );
    511351
    512                 processor * const proc = kernelTLS().this_processor;
    513352                const int cpu = __kernel_getcpu();
    514353                /* paranoid */ verify(cpu >= 0);
     
    521360                /* paranoid */ verifyf((map.start + map.count) * READYQ_SHARD_FACTOR <= lanes.count, "have %zu lanes but map can go up to %u", lanes.count, (map.start + map.count) * READYQ_SHARD_FACTOR);
    522361
     362                processor * const proc = kernelTLS().this_processor;
    523363                const int start = map.self * READYQ_SHARD_FACTOR;
    524364                const unsigned long long ctsc = rdtscl();
    525365
    526366                // Did we already have a help target
    527                 if(proc->rdq.target == MAX) {
     367                if(proc->rdq.target == -1u) {
    528368                        unsigned long long max = 0;
    529369                        for(i; READYQ_SHARD_FACTOR) {
    530                                 unsigned long long tsc = moving_average(ctsc, ts(lanes.data[start + i]), lanes.tscs[start + i].ma);
     370                                unsigned long long tsc = moving_average(ctsc - ts(lanes.data[start + i]), lanes.tscs[start + i].ma);
    531371                                if(tsc > max) max = tsc;
    532372                        }
    533                         // proc->rdq.cutoff = (max + 2 * max) / 2;
     373                        proc->rdq.cutoff = (max + 2 * max) / 2;
    534374                        /* paranoid */ verify(lanes.count < 65536); // The following code assumes max 65536 cores.
    535375                        /* paranoid */ verify(map.count < 65536); // The following code assumes max 65536 cores.
     
    544384                        }
    545385
    546                         /* paranoid */ verify(proc->rdq.target != MAX);
     386                        /* paranoid */ verify(proc->rdq.target != -1u);
    547387                }
    548388                else {
    549389                        unsigned long long max = 0;
    550390                        for(i; READYQ_SHARD_FACTOR) {
    551                                 unsigned long long tsc = moving_average(ctsc, ts(lanes.data[start + i]), lanes.tscs[start + i].ma);
     391                                unsigned long long tsc = moving_average(ctsc - ts(lanes.data[start + i]), lanes.tscs[start + i].ma);
    552392                                if(tsc > max) max = tsc;
    553393                        }
     
    555395                        {
    556396                                unsigned target = proc->rdq.target;
    557                                 proc->rdq.target = MAX;
     397                                proc->rdq.target = -1u;
    558398                                lanes.help[target / READYQ_SHARD_FACTOR].tri++;
    559                                 if(moving_average(ctsc, lanes.tscs[target].tv, lanes.tscs[target].ma) > cutoff) {
     399                                if(moving_average(ctsc - lanes.tscs[target].tv, lanes.tscs[target].ma) > cutoff) {
    560400                                        thread$ * t = try_pop(cltr, target __STATS(, __tls_stats()->ready.pop.help));
    561401                                        proc->rdq.last = target;
    562402                                        if(t) return t;
     403                                        else proc->rdq.target = -1u;
    563404                                }
    564                                 proc->rdq.target = MAX;
     405                                else proc->rdq.target = -1u;
    565406                        }
    566407
    567408                        unsigned last = proc->rdq.last;
    568                         if(last != MAX && moving_average(ctsc, lanes.tscs[last].tv, lanes.tscs[last].ma) > cutoff) {
     409                        if(last != -1u && lanes.tscs[last].tv < cutoff && ts(lanes.data[last]) < cutoff) {
    569410                                thread$ * t = try_pop(cltr, last __STATS(, __tls_stats()->ready.pop.help));
    570411                                if(t) return t;
    571412                        }
    572413                        else {
    573                                 proc->rdq.last = MAX;
     414                                proc->rdq.last = -1u;
    574415                        }
    575416                }
     
    587428                processor * const proc = kernelTLS().this_processor;
    588429                unsigned last = proc->rdq.last;
    589                 if(last != MAX) {
     430                if(last != -1u) {
    590431                        struct thread$ * t = try_pop(cltr, last __STATS(, __tls_stats()->ready.pop.steal));
    591432                        if(t) return t;
    592                         proc->rdq.last = MAX;
     433                        proc->rdq.last = -1u;
    593434                }
    594435
     
    719560                #else
    720561                        unsigned preferred = thrd->preferred;
    721                         const bool external = (hint != UNPARK_LOCAL) || (!kernelTLS().this_processor) || preferred == MAX || thrd->curr_cluster != cltr;
     562                        const bool external = (hint != UNPARK_LOCAL) || (!kernelTLS().this_processor) || preferred == -1u || thrd->curr_cluster != cltr;
    722563                        /* paranoid */ verifyf(external || preferred < lanes.count, "Invalid preferred queue %u for %u lanes", preferred, lanes.count );
    723564
     
    771612                processor * proc = kernelTLS().this_processor;
    772613
    773                 if(proc->rdq.target == MAX) {
     614                if(proc->rdq.target == -1u) {
    774615                        unsigned long long min = ts(lanes.data[proc->rdq.id]);
    775616                        for(int i = 0; i < READYQ_SHARD_FACTOR; i++) {
     
    782623                else {
    783624                        unsigned target = proc->rdq.target;
    784                         proc->rdq.target = MAX;
     625                        proc->rdq.target = -1u;
    785626                        const unsigned long long bias = 0; //2_500_000_000;
    786627                        const unsigned long long cutoff = proc->rdq.cutoff > bias ? proc->rdq.cutoff - bias : proc->rdq.cutoff;
     
    817658// try to pop from a lane given by index w
    818659static inline struct thread$ * try_pop(struct cluster * cltr, unsigned w __STATS(, __stats_readyQ_pop_t & stats)) with (cltr->ready_queue) {
    819         /* paranoid */ verify( w < lanes.count );
    820660        __STATS( stats.attempt++; )
    821661
     
    841681        // Actually pop the list
    842682        struct thread$ * thrd;
    843         #if defined(USE_AWARE_STEALING) || defined(USE_WORK_STEALING) || defined(USE_CPU_WORK_STEALING)
    844                 unsigned long long tsc_before = ts(lane);
    845         #endif
     683        unsigned long long tsc_before = ts(lane);
    846684        unsigned long long tsv;
    847685        [thrd, tsv] = pop(lane);
     
    857695        __STATS( stats.success++; )
    858696
    859         #if defined(USE_AWARE_STEALING) || defined(USE_WORK_STEALING) || defined(USE_CPU_WORK_STEALING)
    860                 if (tsv != MAX) {
    861                         unsigned long long now = rdtscl();
    862                         unsigned long long pma = __atomic_load_n(&lanes.tscs[w].ma, __ATOMIC_RELAXED);
    863                         __atomic_store_n(&lanes.tscs[w].tv, tsv, __ATOMIC_RELAXED);
    864                         __atomic_store_n(&lanes.tscs[w].ma, moving_average(now, tsc_before, pma), __ATOMIC_RELAXED);
    865                 }
     697        #if defined(USE_WORK_STEALING) || defined(USE_CPU_WORK_STEALING)
     698                unsigned long long now = rdtscl();
     699                lanes.tscs[w].tv = tsv;
     700                lanes.tscs[w].ma = moving_average(now > tsc_before ? now - tsc_before : 0, lanes.tscs[w].ma);
    866701        #endif
    867702
    868         #if defined(USE_AWARE_STEALING) || defined(USE_CPU_WORK_STEALING)
     703        #if defined(USE_CPU_WORK_STEALING)
    869704                thrd->preferred = w / READYQ_SHARD_FACTOR;
    870705        #else
     
    965800                /* paranoid */ verifyf( it, "Unexpected null iterator, at index %u of %u\n", i, count);
    966801                it->rdq.id = value;
    967                 it->rdq.target = MAX;
     802                it->rdq.target = -1u;
    968803                value += READYQ_SHARD_FACTOR;
    969804                it = &(*it)`next;
     
    978813
    979814static void fix_times( struct cluster * cltr ) with( cltr->ready_queue ) {
    980         #if defined(USE_AWARE_STEALING) || defined(USE_WORK_STEALING)
     815        #if defined(USE_WORK_STEALING)
    981816                lanes.tscs = alloc(lanes.count, lanes.tscs`realloc);
    982817                for(i; lanes.count) {
    983                         lanes.tscs[i].tv = rdtscl();
    984                         lanes.tscs[i].ma = 0;
     818                        unsigned long long tsc1 = ts(lanes.data[i]);
     819                        unsigned long long tsc2 = rdtscl();
     820                        lanes.tscs[i].tv = min(tsc1, tsc2);
    985821                }
    986822        #endif
     
    1028864                        // Update original
    1029865                        lanes.count = ncount;
    1030 
    1031                         lanes.caches = alloc( target, lanes.caches`realloc );
    1032866                }
    1033867
     
    1106940                                fix(lanes.data[idx]);
    1107941                        }
    1108 
    1109                         lanes.caches = alloc( target, lanes.caches`realloc );
    1110942                }
    1111943
    1112944                fix_times(cltr);
    1113 
    1114945
    1115946                reassign_cltr_id(cltr);
  • libcfa/src/concurrency/thread.cfa

    r12c1eef r5235d49  
    1010// Created On       : Tue Jan 17 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jan 13 20:11:55 2022
    13 // Update Count     : 42
     12// Last Modified On : Wed Dec  4 09:17:49 2019
     13// Update Count     : 9
    1414//
    1515
     
    2525#include "invoke.h"
    2626
    27 extern uint32_t __global_random_seed;
     27uint64_t thread_rand();
    2828
    2929//-----------------------------------------------------------------------------
    3030// Thread ctors and dtors
    31 void ?{}( thread$ & this, const char * const name, cluster & cl, void * storage, size_t storageSize ) with( this ) {
     31void ?{}(thread$ & this, const char * const name, cluster & cl, void * storage, size_t storageSize ) with( this ) {
    3232        context{ 0p, 0p };
    3333        self_cor{ name, storage, storageSize };
     
    4545        preferred = ready_queue_new_preferred();
    4646        last_proc = 0p;
    47         random_state = __global_random_seed;
    4847        #if defined( __CFA_WITH_VERIFY__ )
    4948                canary = 0x0D15EA5E0D15EA5Ep;
     
    172171}
    173172
    174 //-----------------------------------------------------------------------------
    175 #define GENERATOR LCG
    176 
    177 void set_seed( uint32_t seed ) {
    178         active_thread()->random_state = __global_random_seed = seed;
    179         GENERATOR( active_thread()->random_state );
    180 } // set_seed
    181 uint32_t prng( void ) { return GENERATOR( active_thread()->random_state ); } // [0,UINT_MAX]
     173uint64_t thread_rand() {
     174        disable_interrupts();
     175        uint64_t ret = __tls_rand();
     176        enable_interrupts();
     177        return ret;
     178}
    182179
    183180// Local Variables: //
  • libcfa/src/concurrency/thread.hfa

    r12c1eef r5235d49  
    1010// Created On       : Tue Jan 17 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jan  6 16:40:16 2022
    13 // Update Count     : 7
     12// Last Modified On : Wed Dec  4 09:18:14 2019
     13// Update Count     : 6
    1414//
    1515
     
    6565void ^?{}(thread$ & this);
    6666
    67 static inline void ?{}(thread$ & this)                                                                  { this{ "Anonymous Thread", *mainCluster, 0p, DEFAULT_STACK_SIZE }; }
     67static inline void ?{}(thread$ & this)                                                                  { this{ "Anonymous Thread", *mainCluster, 0p, 65000 }; }
    6868static inline void ?{}(thread$ & this, size_t stackSize )                                               { this{ "Anonymous Thread", *mainCluster, 0p, stackSize }; }
    6969static inline void ?{}(thread$ & this, void * storage, size_t storageSize )                             { this{ "Anonymous Thread", *mainCluster, storage, storageSize }; }
    70 static inline void ?{}(thread$ & this, struct cluster & cl )                                            { this{ "Anonymous Thread", cl, 0p, DEFAULT_STACK_SIZE }; }
     70static inline void ?{}(thread$ & this, struct cluster & cl )                                            { this{ "Anonymous Thread", cl, 0p, 65000 }; }
    7171static inline void ?{}(thread$ & this, struct cluster & cl, size_t stackSize )                          { this{ "Anonymous Thread", cl, 0p, stackSize }; }
    7272static inline void ?{}(thread$ & this, struct cluster & cl, void * storage, size_t storageSize )        { this{ "Anonymous Thread", cl, storage, storageSize }; }
    73 static inline void ?{}(thread$ & this, const char * const name)                                         { this{ name, *mainCluster, 0p, DEFAULT_STACK_SIZE }; }
    74 static inline void ?{}(thread$ & this, const char * const name, struct cluster & cl )                   { this{ name, cl, 0p, DEFAULT_STACK_SIZE }; }
     73static inline void ?{}(thread$ & this, const char * const name)                                         { this{ name, *mainCluster, 0p, 65000 }; }
     74static inline void ?{}(thread$ & this, const char * const name, struct cluster & cl )                   { this{ name, cl, 0p, 65000 }; }
    7575static inline void ?{}(thread$ & this, const char * const name, struct cluster & cl, size_t stackSize ) { this{ name, cl, 0p, stackSize }; }
    7676
  • libcfa/src/device/cpu.cfa

    r12c1eef r5235d49  
    427427                        unsigned c = pairings[i].cpu;
    428428                        unsigned llc_id = pairings[i].id;
     429                        unsigned width = maps[llc_id].raw->width;
    429430                        unsigned start = maps[llc_id].start;
    430                         entries[c].count = maps[llc_id].raw->width;
     431                        unsigned self  = start + (maps[llc_id].count++);
     432                        entries[c].count = width;
    431433                        entries[c].start = start;
    432                         entries[c].self  = start + (maps[llc_id].count++);
    433                         entries[c].cache = llc_id;
     434                        entries[c].self  = self;
    434435                }
    435436
  • libcfa/src/device/cpu.hfa

    r12c1eef r5235d49  
    1616#include <stddef.h>
    1717
    18 // Map from cpu entry to a structure detailling cpus with common topologies
    19 // Note that the cpu-groups are contiguous so the indexing is different from
    20 // the cpu indexing
    2118struct cpu_map_entry_t {
    22         // Where this particular cpu is in the group
    2319        unsigned self;
    24 
    25         // Starting index of the cpus with the same topology
    2620        unsigned start;
    27 
    28         // Number of cpus with the same topology
    2921        unsigned count;
    30 
    31         // Index of the cache this entry describes
    32         unsigned cache;
    3322};
    3423
  • libcfa/src/fstream.cfa

    r12c1eef r5235d49  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jan 10 08:45:05 2022
    13 // Update Count     : 513
     12// Last Modified On : Sun Oct 10 11:23:05 2021
     13// Update Count     : 512
    1414//
    1515
     
    5252inline void setPrt$( ofstream & os, bool state ) { os.prt$ = state; }
    5353
    54 inline void lock( ofstream & os ) with( os ) { lock( os.lock$ ); }
     54inline void lock( ofstream & os ) with( os ) {  lock( os.lock$ ); }
    5555inline void unlock( ofstream & os ) { unlock( os.lock$ ); }
    5656
  • libcfa/src/heap.cfa

    r12c1eef r5235d49  
    1010// Created On       : Tue Dec 19 21:58:35 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Jan  2 23:29:41 2022
    13 // Update Count     : 1058
     12// Last Modified On : Mon Aug  9 19:03:02 2021
     13// Update Count     : 1040
    1414//
    1515
     
    263263#ifdef __STATISTICS__
    264264// Heap statistics counters.
    265 static unsigned int malloc_calls, malloc_0_calls;
    266 static unsigned long long int malloc_storage_request, malloc_storage_alloc;
    267 static unsigned int aalloc_calls, aalloc_0_calls;
    268 static unsigned long long int aalloc_storage_request, aalloc_storage_alloc;
    269 static unsigned int calloc_calls, calloc_0_calls;
    270 static unsigned long long int calloc_storage_request, calloc_storage_alloc;
    271 static unsigned int memalign_calls, memalign_0_calls;
    272 static unsigned long long int memalign_storage_request, memalign_storage_alloc;
    273 static unsigned int amemalign_calls, amemalign_0_calls;
    274 static unsigned long long int amemalign_storage_request, amemalign_storage_alloc;
    275 static unsigned int cmemalign_calls, cmemalign_0_calls;
    276 static unsigned long long int cmemalign_storage_request, cmemalign_storage_alloc;
    277 static unsigned int resize_calls, resize_0_calls;
    278 static unsigned long long int resize_storage_request, resize_storage_alloc;
    279 static unsigned int realloc_calls, realloc_0_calls;
    280 static unsigned long long int realloc_storage_request, realloc_storage_alloc;
    281 static unsigned int free_calls, free_null_calls;
    282 static unsigned long long int free_storage_request, free_storage_alloc;
     265static unsigned int malloc_zero_calls, malloc_calls;
     266static unsigned long long int malloc_storage;
     267static unsigned int aalloc_zero_calls, aalloc_calls;
     268static unsigned long long int aalloc_storage;
     269static unsigned int calloc_zero_calls, calloc_calls;
     270static unsigned long long int calloc_storage;
     271static unsigned int memalign_zero_calls, memalign_calls;
     272static unsigned long long int memalign_storage;
     273static unsigned int amemalign_zero_calls, amemalign_calls;
     274static unsigned long long int amemalign_storage;
     275static unsigned int cmemalign_zero_calls, cmemalign_calls;
     276static unsigned long long int cmemalign_storage;
     277static unsigned int resize_zero_calls, resize_calls;
     278static unsigned long long int resize_storage;
     279static unsigned int realloc_zero_calls, realloc_calls;
     280static unsigned long long int realloc_storage;
     281static unsigned int free_zero_calls, free_calls;
     282static unsigned long long int free_storage;
    283283static unsigned int mmap_calls;
    284 static unsigned long long int mmap_storage_request, mmap_storage_alloc;
     284static unsigned long long int mmap_storage;
    285285static unsigned int munmap_calls;
    286 static unsigned long long int munmap_storage_request, munmap_storage_alloc;
     286static unsigned long long int munmap_storage;
    287287static unsigned int sbrk_calls;
    288288static unsigned long long int sbrk_storage;
     
    294294        char helpText[1024];
    295295        __cfaabi_bits_print_buffer( STDERR_FILENO, helpText, sizeof(helpText),
    296                                                                 "\nHeap statistics: (storage request / allocation + header)\n"
    297                                                                 "  malloc    >0 calls %'u; 0 calls %'u; storage %'llu / %'llu bytes\n"
    298                                                                 "  aalloc    >0 calls %'u; 0 calls %'u; storage %'llu / %'llu bytes\n"
    299                                                                 "  calloc    >0 calls %'u; 0 calls %'u; storage %'llu / %'llu bytes\n"
    300                                                                 "  memalign  >0 calls %'u; 0 calls %'u; storage %'llu / %'llu bytes\n"
    301                                                                 "  amemalign >0 calls %'u; 0 calls %'u; storage %'llu / %'llu bytes\n"
    302                                                                 "  cmemalign >0 calls %'u; 0 calls %'u; storage %'llu / %'llu bytes\n"
    303                                                                 "  resize    >0 calls %'u; 0 calls %'u; storage %'llu / %'llu bytes\n"
    304                                                                 "  realloc   >0 calls %'u; 0 calls %'u; storage %'llu / %'llu bytes\n"
    305                                                                 "  free      !null calls %'u; null calls %'u; storage %'llu / %'llu bytes\n"
    306                                                                 "  sbrk      calls %'u; storage %'llu bytes\n"
    307                                                                 "  mmap      calls %'u; storage %'llu / %'llu bytes\n"
    308                                                                 "  munmap    calls %'u; storage %'llu / %'llu bytes\n",
    309                                                                 malloc_calls, malloc_0_calls, malloc_storage_request, malloc_storage_alloc,
    310                                                                 aalloc_calls, aalloc_0_calls, aalloc_storage_request, aalloc_storage_alloc,
    311                                                                 calloc_calls, calloc_0_calls, calloc_storage_request, calloc_storage_alloc,
    312                                                                 memalign_calls, memalign_0_calls, memalign_storage_request, memalign_storage_alloc,
    313                                                                 amemalign_calls, amemalign_0_calls, amemalign_storage_request, amemalign_storage_alloc,
    314                                                                 cmemalign_calls, cmemalign_0_calls, cmemalign_storage_request, cmemalign_storage_alloc,
    315                                                                 resize_calls, resize_0_calls, resize_storage_request, resize_storage_alloc,
    316                                                                 realloc_calls, realloc_0_calls, realloc_storage_request, realloc_storage_alloc,
    317                                                                 free_calls, free_null_calls, free_storage_request, free_storage_alloc,
    318                                                                 sbrk_calls, sbrk_storage,
    319                                                                 mmap_calls, mmap_storage_request, mmap_storage_alloc,
    320                                                                 munmap_calls, munmap_storage_request, munmap_storage_alloc
     296                                                                "\nHeap statistics:\n"
     297                                                                "  malloc    0-calls %'u; >0-calls %'u; storage %'llu bytes\n"
     298                                                                "  aalloc    0-calls %'u; >0-calls %'u; storage %'llu bytes\n"
     299                                                                "  calloc    0-calls %'u; >0-calls %'u; storage %'llu bytes\n"
     300                                                                "  memalign  0-calls %'u; >0-calls %'u; storage %'llu bytes\n"
     301                                                                "  amemalign 0-calls %'u; >0-calls %'u; storage %'llu bytes\n"
     302                                                                "  cmemalign 0-calls %'u; >0-calls %'u; storage %'llu bytes\n"
     303                                                                "  resize    0-calls %'u; >0-calls %'u; storage %'llu bytes\n"
     304                                                                "  realloc   0-calls %'u; >0-calls %'u; storage %'llu bytes\n"
     305                                                                "  free      0-calls %'u; >0-calls %'u; storage %'llu bytes\n"
     306                                                                "  mmap      calls %'u; storage %'llu bytes\n"
     307                                                                "  munmap    calls %'u; storage %'llu bytes\n"
     308                                                                "  sbrk      calls %'u; storage %'llu bytes\n",
     309                                                                malloc_zero_calls, malloc_calls, malloc_storage,
     310                                                                aalloc_zero_calls, aalloc_calls, aalloc_storage,
     311                                                                calloc_zero_calls, calloc_calls, calloc_storage,
     312                                                                memalign_zero_calls, memalign_calls, memalign_storage,
     313                                                                amemalign_zero_calls, amemalign_calls, amemalign_storage,
     314                                                                cmemalign_zero_calls, cmemalign_calls, cmemalign_storage,
     315                                                                resize_zero_calls, resize_calls, resize_storage,
     316                                                                realloc_zero_calls, realloc_calls, realloc_storage,
     317                                                                free_zero_calls, free_calls, free_storage,
     318                                                                mmap_calls, mmap_storage,
     319                                                                munmap_calls, munmap_storage,
     320                                                                sbrk_calls, sbrk_storage
    321321                );
    322322} // printStats
     
    329329                                                "<sizes>\n"
    330330                                                "</sizes>\n"
    331                                                 "<total type=\"malloc\" >0 count=\"%'u;\" 0 count=\"%'u;\" size=\"%'llu / %'llu\"/> bytes\n"
    332                                                 "<total type=\"aalloc\" >0 count=\"%'u;\" 0 count=\"%'u;\" size=\"%'llu / %'llu\"/> bytes\n"
    333                                                 "<total type=\"calloc\" >0 count=\"%'u;\" 0 count=\"%'u;\" size=\"%'llu / %'llu\"/> bytes\n"
    334                                                 "<total type=\"memalign\" >0 count=\"%'u;\" 0 count=\"%'u;\" size=\"%'llu / %'llu\"/> bytes\n"
    335                                                 "<total type=\"amemalign\" >0 count=\"%'u;\" 0 count=\"%'u;\" size=\"%'llu / %'llu\"/> bytes\n"
    336                                                 "<total type=\"cmemalign\" >0 count=\"%'u;\" 0 count=\"%'u;\" size=\"%'llu / %'llu\"/> bytes\n"
    337                                                 "<total type=\"resize\" >0 count=\"%'u;\" 0 count=\"%'u;\" size=\"%'llu / %'llu\"/> bytes\n"
    338                                                 "<total type=\"realloc\" >0 count=\"%'u;\" 0 count=\"%'u;\" size=\"%'llu / %'llu\"/> bytes\n"
    339                                                 "<total type=\"free\" !null=\"%'u;\" 0 null=\"%'u;\" size=\"%'llu / %'llu\"/> bytes\n"
     331                                                "<total type=\"malloc\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"
     332                                                "<total type=\"aalloc\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"
     333                                                "<total type=\"calloc\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"
     334                                                "<total type=\"memalign\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"
     335                                                "<total type=\"amemalign\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"
     336                                                "<total type=\"cmemalign\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"
     337                                                "<total type=\"resize\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"
     338                                                "<total type=\"realloc\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"
     339                                                "<total type=\"free\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"
     340                                                "<total type=\"mmap\" count=\"%'u;\" size=\"%'llu\"/> bytes\n"
     341                                                "<total type=\"munmap\" count=\"%'u;\" size=\"%'llu\"/> bytes\n"
    340342                                                "<total type=\"sbrk\" count=\"%'u;\" size=\"%'llu\"/> bytes\n"
    341                                                 "<total type=\"mmap\" count=\"%'u;\" size=\"%'llu / %'llu\" / > bytes\n"
    342                                                 "<total type=\"munmap\" count=\"%'u;\" size=\"%'llu / %'llu\"/> bytes\n"
    343343                                                "</malloc>",
    344                                                 malloc_calls, malloc_0_calls, malloc_storage_request, malloc_storage_alloc,
    345                                                 aalloc_calls, aalloc_0_calls, aalloc_storage_request, aalloc_storage_alloc,
    346                                                 calloc_calls, calloc_0_calls, calloc_storage_request, calloc_storage_alloc,
    347                                                 memalign_calls, memalign_0_calls, memalign_storage_request, memalign_storage_alloc,
    348                                                 amemalign_calls, amemalign_0_calls, amemalign_storage_request, amemalign_storage_alloc,
    349                                                 cmemalign_calls, cmemalign_0_calls, cmemalign_storage_request, cmemalign_storage_alloc,
    350                                                 resize_calls, resize_0_calls, resize_storage_request, resize_storage_alloc,
    351                                                 realloc_calls, realloc_0_calls, realloc_storage_request, realloc_storage_alloc,
    352                                                 free_calls, free_null_calls, free_storage_request, free_storage_alloc,
    353                                                 sbrk_calls, sbrk_storage,
    354                                                 mmap_calls, mmap_storage_request, mmap_storage_alloc,
    355                                                 munmap_calls, munmap_storage_request, munmap_storage_alloc
     344                                                malloc_zero_calls, malloc_calls, malloc_storage,
     345                                                aalloc_zero_calls, aalloc_calls, aalloc_storage,
     346                                                calloc_zero_calls, calloc_calls, calloc_storage,
     347                                                memalign_zero_calls, memalign_calls, memalign_storage,
     348                                                amemalign_zero_calls, amemalign_calls, amemalign_storage,
     349                                                cmemalign_zero_calls, cmemalign_calls, cmemalign_storage,
     350                                                resize_zero_calls, resize_calls, resize_storage,
     351                                                realloc_zero_calls, realloc_calls, realloc_storage,
     352                                                free_zero_calls, free_calls, free_storage,
     353                                                mmap_calls, mmap_storage,
     354                                                munmap_calls, munmap_storage,
     355                                                sbrk_calls, sbrk_storage
    356356                );
    357357        __cfaabi_bits_write( fileno( stream ), helpText, len ); // ensures all bytes written or exit
     
    577577                #ifdef __STATISTICS__
    578578                __atomic_add_fetch( &mmap_calls, 1, __ATOMIC_SEQ_CST );
    579                 __atomic_add_fetch( &mmap_storage_request, size, __ATOMIC_SEQ_CST );
    580                 __atomic_add_fetch( &mmap_storage_alloc, tsize, __ATOMIC_SEQ_CST );
     579                __atomic_add_fetch( &mmap_storage, tsize, __ATOMIC_SEQ_CST );
    581580                #endif // __STATISTICS__
    582581
     
    627626                #ifdef __STATISTICS__
    628627                __atomic_add_fetch( &munmap_calls, 1, __ATOMIC_SEQ_CST );
    629                 __atomic_add_fetch( &munmap_storage_request, header->kind.real.size, __ATOMIC_SEQ_CST );
    630                 __atomic_add_fetch( &munmap_storage_alloc, size, __ATOMIC_SEQ_CST );
     628                __atomic_add_fetch( &munmap_storage, size, __ATOMIC_SEQ_CST );
    631629                #endif // __STATISTICS__
    632630                if ( munmap( header, size ) == -1 ) {
     
    644642                #ifdef __STATISTICS__
    645643                __atomic_add_fetch( &free_calls, 1, __ATOMIC_SEQ_CST );
    646                 __atomic_add_fetch( &free_storage_request, header->kind.real.size, __ATOMIC_SEQ_CST );
    647                 __atomic_add_fetch( &free_storage_alloc, size, __ATOMIC_SEQ_CST );
     644                __atomic_add_fetch( &free_storage, size, __ATOMIC_SEQ_CST );
    648645                #endif // __STATISTICS__
    649646
     
    822819                if ( likely( size > 0 ) ) {
    823820                        __atomic_add_fetch( &malloc_calls, 1, __ATOMIC_SEQ_CST );
    824                         __atomic_add_fetch( &malloc_storage_request, size, __ATOMIC_SEQ_CST );
     821                        __atomic_add_fetch( &malloc_storage, size, __ATOMIC_SEQ_CST );
    825822                } else {
    826                         __atomic_add_fetch( &malloc_0_calls, 1, __ATOMIC_SEQ_CST );
     823                        __atomic_add_fetch( &malloc_zero_calls, 1, __ATOMIC_SEQ_CST );
    827824                } // if
    828825                #endif // __STATISTICS__
     
    838835                if ( likely( size > 0 ) ) {
    839836                        __atomic_add_fetch( &aalloc_calls, 1, __ATOMIC_SEQ_CST );
    840                         __atomic_add_fetch( &aalloc_storage_request, size, __ATOMIC_SEQ_CST );
     837                        __atomic_add_fetch( &aalloc_storage, size, __ATOMIC_SEQ_CST );
    841838                } else {
    842                         __atomic_add_fetch( &aalloc_0_calls, 1, __ATOMIC_SEQ_CST );
     839                        __atomic_add_fetch( &aalloc_zero_calls, 1, __ATOMIC_SEQ_CST );
    843840                } // if
    844841                #endif // __STATISTICS__
     
    853850          if ( unlikely( size ) == 0 ) {                        // 0 BYTE ALLOCATION RETURNS NULL POINTER
    854851                        #ifdef __STATISTICS__
    855                         __atomic_add_fetch( &calloc_0_calls, 1, __ATOMIC_SEQ_CST );
     852                        __atomic_add_fetch( &calloc_zero_calls, 1, __ATOMIC_SEQ_CST );
    856853                        #endif // __STATISTICS__
    857854                        return 0p;
     
    859856                #ifdef __STATISTICS__
    860857                __atomic_add_fetch( &calloc_calls, 1, __ATOMIC_SEQ_CST );
    861                 __atomic_add_fetch( &calloc_storage_request, dim * elemSize, __ATOMIC_SEQ_CST );
     858                __atomic_add_fetch( &calloc_storage, dim * elemSize, __ATOMIC_SEQ_CST );
    862859                #endif // __STATISTICS__
    863860
     
    894891          if ( unlikely( size == 0 ) ) {                                        // special cases
    895892                        #ifdef __STATISTICS__
    896                         __atomic_add_fetch( &resize_0_calls, 1, __ATOMIC_SEQ_CST );
     893                        __atomic_add_fetch( &resize_zero_calls, 1, __ATOMIC_SEQ_CST );
    897894                        #endif // __STATISTICS__
    898895                        free( oaddr );
     
    905902          if ( unlikely( oaddr == 0p ) ) {
    906903                        #ifdef __STATISTICS__
    907                         __atomic_add_fetch( &resize_storage_request, size, __ATOMIC_SEQ_CST );
     904                        __atomic_add_fetch( &resize_storage, size, __ATOMIC_SEQ_CST );
    908905                        #endif // __STATISTICS__
    909906                        return mallocNoStats( size );
     
    924921
    925922                #ifdef __STATISTICS__
    926                 __atomic_add_fetch( &resize_storage_request, size, __ATOMIC_SEQ_CST );
     923                __atomic_add_fetch( &resize_storage, size, __ATOMIC_SEQ_CST );
    927924                #endif // __STATISTICS__
    928925
     
    939936          if ( unlikely( size == 0 ) ) {                                        // special cases
    940937                        #ifdef __STATISTICS__
    941                         __atomic_add_fetch( &realloc_0_calls, 1, __ATOMIC_SEQ_CST );
     938                        __atomic_add_fetch( &realloc_zero_calls, 1, __ATOMIC_SEQ_CST );
    942939                        #endif // __STATISTICS__
    943940                        free( oaddr );
     
    950947          if ( unlikely( oaddr == 0p ) ) {
    951948                        #ifdef __STATISTICS__
    952                         __atomic_add_fetch( &realloc_storage_request, size, __ATOMIC_SEQ_CST );
     949                        __atomic_add_fetch( &realloc_storage, size, __ATOMIC_SEQ_CST );
    953950                        #endif // __STATISTICS__
    954951                        return mallocNoStats( size );
     
    972969
    973970                #ifdef __STATISTICS__
    974                 __atomic_add_fetch( &realloc_storage_request, size, __ATOMIC_SEQ_CST );
     971                __atomic_add_fetch( &realloc_storage, size, __ATOMIC_SEQ_CST );
    975972                #endif // __STATISTICS__
    976973
     
    10031000                if ( likely( size > 0 ) ) {
    10041001                        __atomic_add_fetch( &memalign_calls, 1, __ATOMIC_SEQ_CST );
    1005                         __atomic_add_fetch( &memalign_storage_request, size, __ATOMIC_SEQ_CST );
     1002                        __atomic_add_fetch( &memalign_storage, size, __ATOMIC_SEQ_CST );
    10061003                } else {
    1007                         __atomic_add_fetch( &memalign_0_calls, 1, __ATOMIC_SEQ_CST );
     1004                        __atomic_add_fetch( &memalign_zero_calls, 1, __ATOMIC_SEQ_CST );
    10081005                } // if
    10091006                #endif // __STATISTICS__
     
    10191016                if ( likely( size > 0 ) ) {
    10201017                        __atomic_add_fetch( &cmemalign_calls, 1, __ATOMIC_SEQ_CST );
    1021                         __atomic_add_fetch( &cmemalign_storage_request, size, __ATOMIC_SEQ_CST );
     1018                        __atomic_add_fetch( &cmemalign_storage, size, __ATOMIC_SEQ_CST );
    10221019                } else {
    1023                         __atomic_add_fetch( &cmemalign_0_calls, 1, __ATOMIC_SEQ_CST );
     1020                        __atomic_add_fetch( &cmemalign_zero_calls, 1, __ATOMIC_SEQ_CST );
    10241021                } // if
    10251022                #endif // __STATISTICS__
     
    10341031          if ( unlikely( size ) == 0 ) {                                        // 0 BYTE ALLOCATION RETURNS NULL POINTER
    10351032                        #ifdef __STATISTICS__
    1036                         __atomic_add_fetch( &cmemalign_0_calls, 1, __ATOMIC_SEQ_CST );
     1033                        __atomic_add_fetch( &cmemalign_zero_calls, 1, __ATOMIC_SEQ_CST );
    10371034                        #endif // __STATISTICS__
    10381035                        return 0p;
     
    10401037                #ifdef __STATISTICS__
    10411038                __atomic_add_fetch( &cmemalign_calls, 1, __ATOMIC_SEQ_CST );
    1042                 __atomic_add_fetch( &cmemalign_storage_request, dim * elemSize, __ATOMIC_SEQ_CST );
     1039                __atomic_add_fetch( &cmemalign_storage, dim * elemSize, __ATOMIC_SEQ_CST );
    10431040                #endif // __STATISTICS__
    10441041
     
    11041101          if ( unlikely( addr == 0p ) ) {                                       // special case
    11051102                        #ifdef __STATISTICS__
    1106                         __atomic_add_fetch( &free_null_calls, 1, __ATOMIC_SEQ_CST );
     1103                        __atomic_add_fetch( &free_zero_calls, 1, __ATOMIC_SEQ_CST );
    11071104                        #endif // __STATISTICS__
    11081105
     
    12831280  if ( unlikely( size == 0 ) ) {                                                // special cases
    12841281                #ifdef __STATISTICS__
    1285                 __atomic_add_fetch( &resize_0_calls, 1, __ATOMIC_SEQ_CST );
     1282                __atomic_add_fetch( &resize_zero_calls, 1, __ATOMIC_SEQ_CST );
    12861283                #endif // __STATISTICS__
    12871284                free( oaddr );
     
    12971294                #ifdef __STATISTICS__
    12981295                __atomic_add_fetch( &resize_calls, 1, __ATOMIC_SEQ_CST );
    1299                 __atomic_add_fetch( &resize_storage_request, size, __ATOMIC_SEQ_CST );
     1296                __atomic_add_fetch( &resize_storage, size, __ATOMIC_SEQ_CST );
    13001297                #endif // __STATISTICS__
    13011298                return memalignNoStats( nalign, size );
     
    13321329
    13331330        #ifdef __STATISTICS__
    1334         __atomic_add_fetch( &resize_storage_request, size, __ATOMIC_SEQ_CST );
     1331        __atomic_add_fetch( &resize_storage, size, __ATOMIC_SEQ_CST );
    13351332        #endif // __STATISTICS__
    13361333
     
    13451342  if ( unlikely( size == 0 ) ) {                                                // special cases
    13461343                #ifdef __STATISTICS__
    1347                 __atomic_add_fetch( &realloc_0_calls, 1, __ATOMIC_SEQ_CST );
     1344                __atomic_add_fetch( &realloc_zero_calls, 1, __ATOMIC_SEQ_CST );
    13481345                #endif // __STATISTICS__
    13491346                free( oaddr );
     
    13591356                #ifdef __STATISTICS__
    13601357                __atomic_add_fetch( &realloc_calls, 1, __ATOMIC_SEQ_CST );
    1361                 __atomic_add_fetch( &realloc_storage_request, size, __ATOMIC_SEQ_CST );
     1358                __atomic_add_fetch( &realloc_storage, size, __ATOMIC_SEQ_CST );
    13621359                #endif // __STATISTICS__
    13631360                return memalignNoStats( nalign, size );
     
    13831380        #ifdef __STATISTICS__
    13841381        __atomic_add_fetch( &realloc_calls, 1, __ATOMIC_SEQ_CST );
    1385         __atomic_add_fetch( &realloc_storage_request, size, __ATOMIC_SEQ_CST );
     1382        __atomic_add_fetch( &realloc_storage, size, __ATOMIC_SEQ_CST );
    13861383        #endif // __STATISTICS__
    13871384
  • libcfa/src/iostream.cfa

    r12c1eef r5235d49  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jan 19 08:15:53 2022
    13 // Update Count     : 1352
     12// Last Modified On : Sun Oct 10 09:28:17 2021
     13// Update Count     : 1345
    1414//
    1515
     
    5757        ostype & ?|?( ostype & os, signed char sc ) {
    5858                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    59                 fmt( os, "%'hhd", sc );
     59                fmt( os, "%hhd", sc );
    6060                return os;
    6161        } // ?|?
     
    6666        ostype & ?|?( ostype & os, unsigned char usc ) {
    6767                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    68                 fmt( os, "%'hhu", usc );
     68                fmt( os, "%hhu", usc );
    6969                return os;
    7070        } // ?|?
     
    7575        ostype & ?|?( ostype & os, short int si ) {
    7676                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    77                 fmt( os, "%'hd", si );
     77                fmt( os, "%hd", si );
    7878                return os;
    7979        } // ?|?
     
    8484        ostype & ?|?( ostype & os, unsigned short int usi ) {
    8585                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    86                 fmt( os, "%'hu", usi );
     86                fmt( os, "%hu", usi );
    8787                return os;
    8888        } // ?|?
     
    9393        ostype & ?|?( ostype & os, int i ) {
    9494                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    95                 fmt( os, "%'d", i );
     95                fmt( os, "%d", i );
    9696                return os;
    9797        } // ?|?
     
    102102        ostype & ?|?( ostype & os, unsigned int ui ) {
    103103                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    104                 fmt( os, "%'u", ui );
     104                fmt( os, "%u", ui );
    105105                return os;
    106106        } // ?|?
     
    111111        ostype & ?|?( ostype & os, long int li ) {
    112112                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    113                 fmt( os, "%'ld", li );
     113                fmt( os, "%ld", li );
    114114                return os;
    115115        } // ?|?
     
    120120        ostype & ?|?( ostype & os, unsigned long int uli ) {
    121121                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    122                 fmt( os, "%'lu", uli );
     122                fmt( os, "%lu", uli );
    123123                return os;
    124124        } // ?|?
     
    129129        ostype & ?|?( ostype & os, long long int lli ) {
    130130                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    131                 fmt( os, "%'lld", lli );
     131                fmt( os, "%lld", lli );
    132132                return os;
    133133        } // ?|?
     
    138138        ostype & ?|?( ostype & os, unsigned long long int ulli ) {
    139139                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    140                 fmt( os, "%'llu", ulli );
     140                fmt( os, "%llu", ulli );
    141141                return os;
    142142        } // ?|?
     
    205205        ostype & ?|?( ostype & os, float f ) {
    206206                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    207                 PrintWithDP( os, "%'g", f );
     207                PrintWithDP( os, "%g", f );
    208208                return os;
    209209        } // ?|?
     
    214214        ostype & ?|?( ostype & os, double d ) {
    215215                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    216                 PrintWithDP( os, "%'.*lg", d, DBL_DIG );
     216                PrintWithDP( os, "%.*lg", d, DBL_DIG );
    217217                return os;
    218218        } // ?|?
     
    223223        ostype & ?|?( ostype & os, long double ld ) {
    224224                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    225                 PrintWithDP( os, "%'.*Lg", ld, LDBL_DIG );
     225                PrintWithDP( os, "%.*Lg", ld, LDBL_DIG );
    226226                return os;
    227227        } // ?|?
     
    233233                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    234234//              os | crealf( fc ) | nonl;
    235                 PrintWithDP( os, "%'g", crealf( fc ) );
    236                 PrintWithDP( os, "%'+g", cimagf( fc ) );
     235                PrintWithDP( os, "%g", crealf( fc ) );
     236                PrintWithDP( os, "%+g", cimagf( fc ) );
    237237                fmt( os, "i" );
    238238                return os;
     
    245245                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    246246//              os | creal( dc ) | nonl;
    247                 PrintWithDP( os, "%'.*lg", creal( dc ), DBL_DIG );
    248                 PrintWithDP( os, "%'+.*lg", cimag( dc ), DBL_DIG );
     247                PrintWithDP( os, "%.*lg", creal( dc ), DBL_DIG );
     248                PrintWithDP( os, "%+.*lg", cimag( dc ), DBL_DIG );
    249249                fmt( os, "i" );
    250250                return os;
     
    257257                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    258258//              os | creall( ldc ) || nonl;
    259                 PrintWithDP( os, "%'.*Lg", creall( ldc ), LDBL_DIG );
    260                 PrintWithDP( os, "%'+.*Lg", cimagl( ldc ), LDBL_DIG );
     259                PrintWithDP( os, "%.*Lg", creall( ldc ), LDBL_DIG );
     260                PrintWithDP( os, "%+.*Lg", cimagl( ldc ), LDBL_DIG );
    261261                fmt( os, "i" );
    262262                return os;
     
    282282                }; // mask
    283283
    284           if ( s == 0p ) { fmt( os, "%s", "0p" ); return os; } // null pointer
    285284          if ( s[0] == '\0' ) { sepOff( os ); return os; } // null string => no separator
    286285
     
    497496                if ( ! f.flags.pc ) memcpy( &fmtstr, IFMTNP, sizeof(IFMTNP) ); \
    498497                else memcpy( &fmtstr, IFMTP, sizeof(IFMTP) ); \
    499                 int star = 5;                                                                   /* position before first '*' */ \
     498                int star = 4;                                                                   /* position before first '*' */ \
    500499\
    501500                /* Insert flags into spaces before '*', from right to left. */ \
     
    504503                if ( f.flags.sign ) { fmtstr[star] = '+'; star -= 1; } \
    505504                if ( f.flags.pad0 && ! f.flags.pc ) { fmtstr[star] = '0'; star -= 1; } \
    506                 fmtstr[star] = '\''; star -= 1;                                 /* locale */ \
    507505                fmtstr[star] = '%'; \
    508506\
     
    523521} // distribution
    524522
    525 IntegralFMTImpl( signed char,            "      *hh ", "      *.*hh " )
    526 IntegralFMTImpl( unsigned char,          "      *hh ", "      *.*hh " )
    527 IntegralFMTImpl( signed short int,       "      *h ",  "      *.*h " )
    528 IntegralFMTImpl( unsigned short int,     "      *h ",  "      *.*h " )
    529 IntegralFMTImpl( signed int,             "      * ",   "      *.* " )
    530 IntegralFMTImpl( unsigned int,           "      * ",   "      *.* " )
    531 IntegralFMTImpl( signed long int,        "      *l ",  "      *.*l " )
    532 IntegralFMTImpl( unsigned long int,      "      *l ",  "      *.*l " )
    533 IntegralFMTImpl( signed long long int,   "      *ll ", "      *.*ll " )
    534 IntegralFMTImpl( unsigned long long int, "      *ll ", "      *.*ll " )
     523IntegralFMTImpl( signed char, "     *hh ", "     *.*hh " )
     524IntegralFMTImpl( unsigned char, "     *hh ", "     *.*hh " )
     525IntegralFMTImpl( signed short int, "     *h ", "     *.*h " )
     526IntegralFMTImpl( unsigned short int, "     *h ", "     *.*h " )
     527IntegralFMTImpl( signed int, "     * ", "     *.* " )
     528IntegralFMTImpl( unsigned int, "     * ", "     *.* " )
     529IntegralFMTImpl( signed long int, "     *l ", "     *.*l " )
     530IntegralFMTImpl( unsigned long int, "     *l ", "     *.*l " )
     531IntegralFMTImpl( signed long long int, "     *ll ", "     *.*ll " )
     532IntegralFMTImpl( unsigned long long int, "     *ll ", "     *.*ll " )
    535533
    536534
     
    694692                if ( ! f.flags.pc ) memcpy( &fmtstr, DFMTNP, sizeof(DFMTNP) ); \
    695693                else memcpy( &fmtstr, DFMTP, sizeof(DFMTP) ); \
    696                 int star = 5;                                                                   /* position before first '*' */ \
     694                int star = 4;                                                                   /* position before first '*' */ \
    697695\
    698696                /* Insert flags into spaces before '*', from right to left. */ \
     
    700698                if ( f.flags.sign ) { fmtstr[star] = '+'; star -= 1; } \
    701699                if ( f.flags.pad0 ) { fmtstr[star] = '0'; star -= 1; } \
    702                 fmtstr[star] = '\''; star -= 1;                                 /* locale */ \
    703700                fmtstr[star] = '%'; \
    704701\
     
    718715} // distribution
    719716
    720 FloatingPointFMTImpl( double,      "      * ",  "      *.* " )
    721 FloatingPointFMTImpl( long double, "      *L ", "      *.*L " )
     717FloatingPointFMTImpl( double, "     * ", "     *.* " )
     718FloatingPointFMTImpl( long double, "     *L ", "     *.*L " )
    722719
    723720// *********************************** character ***********************************
  • libcfa/src/parseconfig.cfa

    r12c1eef r5235d49  
    1 
    2 
    3 #pragma GCC diagnostic push
    4 //#pragma GCC diagnostic ignored "-Wunused-parameter"
    5 //#pragma GCC diagnostic ignored "-Wunused-function"
    6 //#pragma GCC diagnostic ignored "-Wuninitialized"
    7 //#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
    8 
    91#include <fstream.hfa>
    102#include <parseargs.hfa>
     
    2719// TODO: use string interface when it's ready (and implement exception msg protocol)
    2820[ void ] msg( * Missing_Config_Entries ex ) {
    29         serr | "The config file is missing " | ex->num_missing | "entr" | sepOff | (ex->num_missing == 1 ? "y." : "ies.");
     21        serr | nlOff;
     22        serr | "The config file is missing " | ex->num_missing;
     23        serr | nlOn;
     24        if ( ex->num_missing == 1 ) {
     25                serr | " entry.";
     26        } else {
     27                serr | " entries.";
     28        }
    3029} // msg
    3130
     
    224223        return value < zero_val;
    225224}
    226 #pragma GCC diagnostic pop
    227225
    228226
  • libcfa/src/startup.cfa

    r12c1eef r5235d49  
    1010// Created On       : Tue Jul 24 16:21:57 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jan 17 16:41:54 2022
    13 // Update Count     : 55
     12// Last Modified On : Sat Jan  9 23:18:23 2021
     13// Update Count     : 34
    1414//
    1515
     
    1717#include <locale.h>                                                                             // setlocale
    1818#include <stdlib.h>                                                                             // getenv
    19 #include "bits/defs.hfa"                                                                // rdtscl
    2019#include "startup.hfa"
    21 
    22 extern uint32_t __global_random_seed;                                   // sequential/concurrent
    23 extern uint32_t __global_random_state;                                  // sequential
    2420
    2521extern "C" {
     
    2723        void __cfaabi_appready_startup( void ) {
    2824                tzset();                                                                                // initialize time global variables
     25                setlocale( LC_NUMERIC, getenv("LANG") );
    2926                #ifdef __CFA_DEBUG__
    3027                extern void heapAppStart();
     
    5148        void __cfaabi_core_startup( void ) __attribute__(( constructor( STARTUP_PRIORITY_CORE ) ));
    5249        void __cfaabi_core_startup( void ) {
    53                 __global_random_state = __global_random_seed = rdtscl();
    5450                __cfaabi_interpose_startup();
    5551                __cfaabi_device_startup();
  • libcfa/src/stdlib.cfa

    r12c1eef r5235d49  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jan 13 21:38:30 2022
    13 // Update Count     : 593
     12// Last Modified On : Wed Dec 29 15:32:44 2021
     13// Update Count     : 512
    1414//
    1515
    1616#include "stdlib.hfa"
    17 #include "bits/random.hfa"
    18 #include "concurrency/invoke.h"                                                 // random_state
    1917
    2018//---------------------------------------
     
    223221//---------------------------------------
    224222
     223static uint32_t seed = 0;                                                               // current seed
     224static thread_local uint32_t state;                                             // random state
     225
     226void set_seed( uint32_t seed_ ) { state = seed = seed_; }
     227uint32_t get_seed() { return seed; }
     228
    225229#define GENERATOR LCG
    226230
    227 uint32_t __global_random_seed;                                                  // sequential/concurrent
    228 uint32_t __global_random_state;                                         // sequential only
    229 
    230 void set_seed( PRNG & prng, uint32_t seed_ ) with( prng ) { state = seed = seed_; GENERATOR( state ); } // set seed
     231inline uint32_t MarsagliaXor( uint32_t & state ) {
     232        if ( unlikely( seed == 0 ) ) set_seed( rdtscl() );
     233        else if ( unlikely( state == 0 ) ) state = seed;
     234        state ^= state << 6;
     235        state ^= state >> 21;
     236        state ^= state << 7;
     237        return state;
     238} // MarsagliaXor
     239
     240inline uint32_t LCG( uint32_t & state ) {                               // linear congruential generator
     241        if ( unlikely( seed == 0 ) ) set_seed( rdtscl() );
     242        else if ( unlikely( state == 0 ) ) state = seed;
     243        return state = 36973 * (state & 65535) + (state >> 16);
     244} // LCG
     245
    231246uint32_t prng( PRNG & prng ) with( prng ) { callcnt += 1; return GENERATOR( state ); }
    232247
    233 void set_seed( uint32_t seed ) { __global_random_seed = seed; GENERATOR( __global_random_state ); }
    234 uint32_t get_seed() { return __global_random_seed; }
    235 uint32_t prng( void ) { return GENERATOR( __global_random_state ); } // [0,UINT_MAX]
     248uint32_t prng( void ) { return GENERATOR( state ); }
    236249
    237250//---------------------------------------
  • libcfa/src/stdlib.hfa

    r12c1eef r5235d49  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jan 13 21:34:46 2022
    13 // Update Count     : 636
     12// Last Modified On : Wed Dec 29 15:30:58 2021
     13// Update Count     : 591
    1414//
    1515
     
    2121#include <stdlib.h>                                                                             // *alloc, strto*, ato*
    2222#include <heap.hfa>
    23 
    2423
    2524// Reduce includes by explicitly defining these routines.
     
    4443//---------------------------------------
    4544
     45// Macro because of returns
     46#define ARRAY_ALLOC$( allocation, alignment, dim ) \
     47        if ( _Alignof(T) <= libAlign() ) return (T *)(void *)allocation( dim, (size_t)sizeof(T) ); /* C allocation */ \
     48        else return (T *)alignment( _Alignof(T), dim, sizeof(T) )
     49
    4650static inline forall( T & | sized(T) ) {
    4751        // CFA safe equivalents, i.e., implicit size specification
    4852
    4953        T * malloc( void ) {
    50                 if ( _Alignof(T) <= libAlign() ) return (T *)malloc( sizeof(T) ); // C allocation
     54                if ( _Alignof(T) <= libAlign() ) return (T *)(void *)malloc( (size_t)sizeof(T) ); // C allocation
    5155                else return (T *)memalign( _Alignof(T), sizeof(T) );
    5256        } // malloc
    5357
    5458        T * aalloc( size_t dim ) {
    55                 if ( _Alignof(T) <= libAlign() ) return (T *)aalloc( dim, sizeof(T) ); // C allocation
    56                 else return (T *)amemalign( _Alignof(T), dim, sizeof(T) );
     59                ARRAY_ALLOC$( aalloc, amemalign, dim );
    5760        } // aalloc
    5861
    5962        T * calloc( size_t dim ) {
    60                 if ( _Alignof(T) <= libAlign() ) return (T *)calloc( dim, sizeof(T) ); // C allocation
    61                 else return (T *)cmemalign( _Alignof(T), dim, sizeof(T) );
     63                ARRAY_ALLOC$( calloc, cmemalign, dim );
    6264        } // calloc
    6365
    6466        T * resize( T * ptr, size_t size ) {                            // CFA resize, eliminate return-type cast
    65                 if ( _Alignof(T) <= libAlign() ) return (T *)resize( (void *)ptr, size ); // CFA resize
    66                 else return (T *)resize( (void *)ptr, _Alignof(T), size ); // CFA resize
     67                if ( _Alignof(T) <= libAlign() ) return (T *)(void *)resize( (void *)ptr, size ); // CFA resize
     68                else return (T *)(void *)resize( (void *)ptr, _Alignof(T), size ); // CFA resize
    6769        } // resize
    6870
    6971        T * realloc( T * ptr, size_t size ) {                           // CFA realloc, eliminate return-type cast
    70                 if ( _Alignof(T) <= libAlign() ) return (T *)realloc( (void *)ptr, size ); // C realloc
    71                 else return (T *)realloc( (void *)ptr, _Alignof(T), size ); // CFA realloc
     72                if ( _Alignof(T) <= libAlign() ) return (T *)(void *)realloc( (void *)ptr, size ); // C realloc
     73                else return (T *)(void *)realloc( (void *)ptr, _Alignof(T), size ); // CFA realloc
    7274        } // realloc
    7375
     
    208210
    209211        forall( TT... | { T * alloc_internal$( void *, T *, size_t, size_t, S_fill(T), TT ); } ) {
     212
    210213                T * alloc_internal$( void *       , T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill, T_resize Resize, TT rest) {
    211214                return alloc_internal$( Resize, (T*)0p, Align, Dim, Fill, rest);
     
    231234                return alloc_internal$( (void*)0p, (T*)0p, (_Alignof(T) > libAlign() ? _Alignof(T) : libAlign()), dim, (S_fill(T)){'0'}, all);
    232235            }
     236
    233237        } // distribution TT
    234238} // distribution T
     
    384388//---------------------------------------
    385389
    386 // Sequential Pseudo Random-Number Generator : generate repeatable sequence of values that appear random.
    387 //
    388 // Declaration :
    389 //   PRNG sprng = { 1009 } - set starting seed versus random seed
    390 //   
    391 // Interface :
    392 //   set_seed( sprng, 1009 ) - set starting seed for ALL kernel threads versus random seed
    393 //   get_seed( sprng ) - read seed
    394 //   prng( sprng ) - generate random value in range [0,UINT_MAX]
    395 //   prng( sprng, u ) - generate random value in range [0,u)
    396 //   prng( sprng, l, u ) - generate random value in range [l,u]
    397 //   calls( sprng ) - number of generated random value so far
    398 //
    399 // Examples : generate random number between 5-21
    400 //   prng( sprng ) % 17 + 5;    values 0-16 + 5 = 5-21
    401 //   prng( sprng, 16 + 1 ) + 5;
    402 //   prng( sprng, 5, 21 );
    403 //   calls( sprng );
    404 
    405390struct PRNG {
    406391        uint32_t callcnt;                                                                       // call count
     
    409394}; // PRNG
    410395
    411 void set_seed( PRNG & prng, uint32_t seed_ );
    412 uint32_t prng( PRNG & prng ) __attribute__(( warn_unused_result )); // [0,UINT_MAX]
     396extern uint32_t prng( PRNG & prng ) __attribute__(( warn_unused_result )); // [0,UINT_MAX]
    413397static inline {
     398        void set_seed( PRNG & prng, uint32_t seed_ ) with( prng ) { state = seed = seed_; } // set seed
    414399        void ?{}( PRNG & prng ) { set_seed( prng, rdtscl() ); } // random seed
    415400        void ?{}( PRNG & prng, uint32_t seed ) { set_seed( prng, seed ); } // fixed seed
     
    420405} // distribution
    421406
    422 // Concurrent Pseudo Random-Number Generator : generate repeatable sequence of values that appear random.
    423 //
    424 // Interface :
    425 //   set_seed( 1009 ) - fixed seed for all kernel threads versus random seed
    426 //   get_seed() - read seed
    427 //   prng() - generate random value in range [0,UINT_MAX]
    428 //   prng( u ) - generate random value in range [0,u)
    429 //   prng( l, u ) - generate random value in range [l,u]
    430 //
    431 // Examples : generate random number between 5-21
    432 //   prng() % 17 + 5;   values 0-16 + 5 = 5-21
    433 //   prng( 16 + 1 ) + 5;
    434 //   prng( 5, 21 );
    435 
    436 void set_seed( uint32_t seed_ ) OPTIONAL_THREAD;
    437 uint32_t get_seed() __attribute__(( warn_unused_result ));
    438 uint32_t prng( void ) __attribute__(( warn_unused_result )) OPTIONAL_THREAD; // [0,UINT_MAX]
     407extern void set_seed( uint32_t seed );                                  // set per thread seed
     408extern uint32_t get_seed();                                                             // get seed
     409extern uint32_t prng( void ) __attribute__(( warn_unused_result )); // [0,UINT_MAX]
    439410static inline {
    440         uint32_t prng( uint32_t u ) __attribute__(( warn_unused_result )) { return prng() % u; } // [0,u)
    441         uint32_t prng( uint32_t l, uint32_t u ) __attribute__(( warn_unused_result )) { return prng( u - l + 1 ) + l; } // [l,u]
     411        uint32_t prng( uint32_t u ) __attribute__(( warn_unused_result ));
     412        uint32_t prng( uint32_t u ) { return prng() % u; }      // [0,u)
     413        uint32_t prng( uint32_t l, uint32_t u ) __attribute__(( warn_unused_result ));
     414        uint32_t prng( uint32_t l, uint32_t u ) { return prng( u - l + 1 ) + l; } // [l,u]
    442415} // distribution
    443416
  • src/AST/Decl.cpp

    r12c1eef r5235d49  
    2626#include "Node.hpp"            // for readonly
    2727#include "Type.hpp"            // for readonly
    28 #include "Expr.hpp"
    2928
    3029namespace ast {
     
    6665        for (auto & tp : this->type_params) {
    6766                ftype->forall.emplace_back(new TypeInstType(tp->name, tp));
    68                 for (auto & ap: tp->assertions) {
    69                         ftype->assertions.emplace_back(new VariableExpr(loc, ap));
    70                 }
    7167        }
    7268        this->type = ftype;
  • src/AST/Decl.hpp

    r12c1eef r5235d49  
    3434// Must be included in *all* AST classes; should be #undef'd at the end of the file
    3535#define MUTATE_FRIEND \
    36         template<typename node_t> friend node_t * mutate(const node_t * node); \
     36    template<typename node_t> friend node_t * mutate(const node_t * node); \
    3737        template<typename node_t> friend node_t * shallowCopy(const node_t * node);
    3838
     
    135135        std::vector< ptr<Expr> > withExprs;
    136136
     137
    137138        FunctionDecl( const CodeLocation & loc, const std::string & name, std::vector<ptr<TypeDecl>>&& forall,
    138139                std::vector<ptr<DeclWithType>>&& params, std::vector<ptr<DeclWithType>>&& returns,
  • src/AST/Eval.hpp

    r12c1eef r5235d49  
    2424template< typename... Args >
    2525UntypedExpr * call( const CodeLocation & loc, const std::string & name, Args &&... args ) {
    26         return new UntypedExpr {
    27                 loc, new NameExpr { loc, name },
     26        return new UntypedExpr { 
     27                loc, new NameExpr { loc, name }, 
    2828                std::vector< ptr< Expr > > { std::forward< Args >( args )... } };
    2929}
  • src/Validate/InitializerLength.cpp

    r12c1eef r5235d49  
    1414//
    1515
    16 #include "InitializerLength.hpp"
     16//#include "InitializerLength.hpp"
    1717
    1818#include "AST/Expr.hpp"
  • src/Validate/InitializerLength.hpp

    r12c1eef r5235d49  
    1414//
    1515
    16 #pragma once
    17 
    18 namespace ast {
    19         class TranslationUnit;
    20 }
    21 
    2216namespace Validate {
    2317
  • tests/device/cpu.cfa

    r12c1eef r5235d49  
    1515
    1616
     17#include <fstream.hfa>
    1718#include <device/cpu.hfa>
    18 #include <limits.hfa>
    19 #include <fstream.hfa>
    2019#include <stdlib.hfa>
    2120
     
    119118
    120119        unsigned found_level = 0;
    121         unsigned found = MAX;
     120        unsigned found = -1u;
    122121        for(i; idxs) {
    123122                unsigned idx = idxs - 1 - i;
     
    137136        }
    138137
    139         /* paranoid */ verify(found != MAX);
     138        /* paranoid */ verify(found != -1u);
    140139        return found;
    141140}
  • tests/io/io-acquire.cfa

    r12c1eef r5235d49  
    1010// Created On       : Mon Mar  1 18:40:09 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jan 14 09:13:18 2022
    13 // Update Count     : 74
     12// Last Modified On : Wed Oct  6 18:04:58 2021
     13// Update Count     : 72
    1414//
    1515
     
    1818#include <mutex_stmt.hfa>
    1919
    20 Duration default_preemption() { return 0; }
    21 
    2220thread T {};
    2321void main( T & ) {
     
    2523
    2624        for ( 100 ) {                                                                           // expression protection
    27                 mutex( sout ) sout | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
     25                mutex(sout) sout | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
    2826        }
    2927        mutex( sout ) {                                                                         // statement protection
     
    5351        int a, b, c, d, e, f, g, h, i;
    5452        for ( 100 ) {                                                                           // expression protection
    55                 mutex( sin ) sin | a | b | c | d | e | f | g | h | i;
     53                mutex(sin) sin | a | b | c | d | e | f | g | h | i;
    5654        }
    5755        mutex( sin ) {                                                                          // statement protection
  • tests/unified_locking/.expect/locks.txt

    r12c1eef r5235d49  
    1111Start Test 6: owner lock and condition variable 3 wait/notify all
    1212Done Test 6
    13 Start Test 7: linear backoff lock and condition variable single wait/notify
     13Start Test 7: fast lock and condition variable single wait/notify
    1414Done Test 7
    15 Start Test 8: linear backoff lock and condition variable 3 wait/notify all
     15Start Test 8: fast lock and condition variable 3 wait/notify all
    1616Done Test 8
    17 Start Test 9: multi acquisiton lock and condition variable multiple acquire and wait/notify
     17Start Test 9: linear backoff lock and condition variable single wait/notify
    1818Done Test 9
    19 Start Test 10: owner lock and condition variable multiple acquire and wait/notify
     19Start Test 10: linear backoff lock and condition variable 3 wait/notify all
    2020Done Test 10
    21 Start Test 11: no lock condition variable wait/notify
     21Start Test 11: multi acquisiton lock and condition variable multiple acquire and wait/notify
    2222Done Test 11
    23 Start Test 12: locked condition variable wait/notify with front()
     23Start Test 12: owner lock and condition variable multiple acquire and wait/notify
    2424Done Test 12
     25Start Test 13: no lock condition variable wait/notify
     26Done Test 13
     27Start Test 14: locked condition variable wait/notify with front()
     28Done Test 14
  • tests/unified_locking/locks.cfa

    r12c1eef r5235d49  
    1515condition_variable( owner_lock ) c_o;
    1616
     17fast_lock f;
     18condition_variable( fast_lock ) c_f;
     19
    1720linear_backoff_then_block_lock l;
    1821condition_variable( linear_backoff_then_block_lock ) c_l;
     
    7174                }
    7275                unlock(s);
     76        }
     77}
     78
     79thread T_C_F_WS1 {};
     80
     81void main( T_C_F_WS1 & this ) {
     82        for (unsigned int i = 0; i < num_times; i++) {
     83                lock(f);
     84                if(empty(c_f) && i != num_times - 1) {
     85                        wait(c_f,f);
     86                }else{
     87                        notify_one(c_f);
     88                }
     89                unlock(f);
     90        }
     91}
     92
     93thread T_C_F_WB1 {};
     94
     95void main( T_C_F_WB1 & this ) {
     96        for (unsigned int i = 0; i < num_times; i++) {
     97                lock(f);
     98                if(counter(c_f) == 3 || i == num_times - 1) {
     99                        notify_all(c_f);
     100                }else{
     101                        wait(c_f,f);
     102                }
     103                unlock(f);
    73104        }
    74105}
     
    286317        printf("Done Test 6\n");
    287318
    288         printf("Start Test 7: linear backoff lock and condition variable single wait/notify\n");
     319        printf("Start Test 7: fast lock and condition variable single wait/notify\n");
     320        {
     321                T_C_F_WS1 t1[2];
     322        }
     323        printf("Done Test 7\n");
     324
     325        printf("Start Test 8: fast lock and condition variable 3 wait/notify all\n");
     326        {
     327                T_C_F_WB1 t1[4];
     328        }
     329        printf("Done Test 8\n");
     330
     331        printf("Start Test 9: linear backoff lock and condition variable single wait/notify\n");
    289332        {
    290333                T_C_L_WS1 t1[2];
    291334        }
    292         printf("Done Test 7\n");
    293 
    294         printf("Start Test 8: linear backoff lock and condition variable 3 wait/notify all\n");
     335        printf("Done Test 9\n");
     336
     337        printf("Start Test 10: linear backoff lock and condition variable 3 wait/notify all\n");
    295338        {
    296339                T_C_L_WB1 t1[4];
    297340        }
    298         printf("Done Test 8\n");
    299 
    300         printf("Start Test 9: multi acquisiton lock and condition variable multiple acquire and wait/notify\n");
     341        printf("Done Test 10\n");
     342
     343        printf("Start Test 11: multi acquisiton lock and condition variable multiple acquire and wait/notify\n");
    301344        {
    302345                T_C_M_WS2 t1[2];
    303346        }
    304         printf("Done Test 9\n");
    305 
    306         printf("Start Test 10: owner lock and condition variable multiple acquire and wait/notify\n");
     347        printf("Done Test 11\n");
     348
     349        printf("Start Test 12: owner lock and condition variable multiple acquire and wait/notify\n");
    307350        {
    308351                T_C_O_WS2 t1[2];
    309352        }
    310         printf("Done Test 10\n");
    311 
    312         printf("Start Test 11: no lock condition variable wait/notify\n");
     353        printf("Done Test 12\n");
     354
     355        printf("Start Test 13: no lock condition variable wait/notify\n");
    313356        {
    314357                T_C_NLW t1;
    315358                T_C_NLS t2;
    316359        }
    317         printf("Done Test 11\n");
    318 
    319         printf("Start Test 12: locked condition variable wait/notify with front()\n");
     360        printf("Done Test 13\n");
     361
     362        printf("Start Test 14: locked condition variable wait/notify with front()\n");
    320363        {
    321364                T_C_S_WNF t1[2];
    322365        }
    323         printf("Done Test 12\n");
    324 }
     366        printf("Done Test 14\n");
     367}
  • tests/unified_locking/mutex_test.hfa

    r12c1eef r5235d49  
    1010        thread$ * id;
    1111        uint32_t sum;
    12         uint32_t cnt;
    1312};
    1413
     
    2827        {
    2928                uint32_t tsum = mo.sum;
    30                 uint32_t cnt = mo.cnt;
    3129                mo.id = me;
    3230                yield(random(5));
    3331                value = ((uint32_t)random()) ^ ((uint32_t)me);
    3432                if(mo.id != me) sout | "Intruder!";
    35                 mo.cnt = cnt + 1;
    3633                mo.sum = tsum + value;
    3734        }
     
    5754        uint32_t sum = -32;
    5855        mo.sum = -32;
    59         mo.cnt = 0;
    6056        processor p[2];
    6157        sout | "Starting";
     
    6763        }
    6864        sout | "Done!";
    69         if(mo.cnt != (13 * num_times)) sout | "Invalid cs count!" | mo.cnt | "vs "| (13 * num_times) | "(13 *" | num_times | ')';
    7065        if(sum == mo.sum) sout | "Match!";
    7166        else sout | "No Match!" | sum | "vs" | mo.sum;
  • tools/jenkins/setup.sh.in

    r12c1eef r5235d49  
    4848                regex1='/([[:alpha:][:digit:]@/_.-]+)'
    4949                regex2='(libcfa[[:alpha:][:digit:].]+) => not found'
    50                 regex3='linux-vdso.so.1|linux-gate.so.1'
     50                regex3='linux-vdso.so.1'
    5151                if [[ $line =~ $regex1 ]]; then
    5252                        retsysdeps+=(${BASH_REMATCH[1]})
Note: See TracChangeset for help on using the changeset viewer.