- Timestamp:
- Oct 2, 2022, 10:00:43 PM (2 years ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- 815943f
- Parents:
- f704974 (diff), f92e7b9 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- libcfa/src
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/assert.cfa
rf704974 rae151cf 25 25 26 26 #define CFA_ASSERT_FMT "Cforall Assertion error \"%s\" from program \"%s\" in \"%s\" at line %d in file \"%s\"" 27 #define CFA_WARNING_FMT "Cforall Assertion warning \"%s\" from program \"%s\" in \"%s\" at line %d in file \"%s\"" 27 28 28 29 // called by macro assert in assert.h … … 48 49 abort(); 49 50 } 51 52 // called by macro warnf 53 // would be cool to remove libcfa_public but it's needed for libcfathread 54 void __assert_warn_f( const char assertion[], const char file[], unsigned int line, const char function[], const char fmt[], ... ) libcfa_public { 55 __cfaabi_bits_acquire(); 56 __cfaabi_bits_print_nolock( STDERR_FILENO, CFA_WARNING_FMT ": ", assertion, __progname, function, line, file ); 57 58 va_list args; 59 va_start( args, fmt ); 60 __cfaabi_bits_print_vararg( STDERR_FILENO, fmt, args ); 61 va_end( args ); 62 63 __cfaabi_bits_print_nolock( STDERR_FILENO, "\n" ); 64 __cfaabi_bits_release(); 65 } 50 66 } 51 67 -
libcfa/src/concurrency/alarm.cfa
rf704974 rae151cf 55 55 this.period = period; 56 56 this.thrd = thrd; 57 this. timeval= __kernel_get_time() + alarm;57 this.deadline = __kernel_get_time() + alarm; 58 58 set = false; 59 59 type = User; … … 64 64 this.period = period; 65 65 this.proc = proc; 66 this. timeval= __kernel_get_time() + alarm;66 this.deadline = __kernel_get_time() + alarm; 67 67 set = false; 68 68 type = Kernel; … … 72 72 this.initial = alarm; 73 73 this.period = period; 74 this. timeval= __kernel_get_time() + alarm;74 this.deadline = __kernel_get_time() + alarm; 75 75 set = false; 76 76 type = Callback; … … 85 85 void insert( alarm_list_t * this, alarm_node_t * n ) { 86 86 alarm_node_t * it = & (*this)`first; 87 while( it && (n-> timeval > it->timeval) ) {87 while( it && (n->deadline > it->deadline) ) { 88 88 it = & (*it)`next; 89 89 } … … 116 116 117 117 Time curr = __kernel_get_time(); 118 __cfadbg_print_safe( preemption, " KERNEL: alarm inserting %p (%lu -> %lu).\n", this, curr.tn, this-> timeval.tn );118 __cfadbg_print_safe( preemption, " KERNEL: alarm inserting %p (%lu -> %lu).\n", this, curr.tn, this->deadline.tn ); 119 119 insert( &alarms, this ); 120 __kernel_set_timer( this-> timeval- curr);120 __kernel_set_timer( this->deadline - curr); 121 121 this->set = true; 122 122 } -
libcfa/src/concurrency/alarm.hfa
rf704974 rae151cf 57 57 }; 58 58 59 Time timeval;// actual time at which the alarm goes off59 Time deadline; // actual time at which the alarm goes off 60 60 enum alarm_type type; // true if this is not a user defined alarm 61 61 bool set :1; // whether or not the alarm has be registered -
libcfa/src/concurrency/io.cfa
rf704974 rae151cf 201 201 __atomic_unlock(&ctx->cq.lock); 202 202 203 touch_tsc( cltr->sched.io.tscs, ctx->cq.id, ts_prev, ts_next );203 touch_tsc( cltr->sched.io.tscs, ctx->cq.id, ts_prev, ts_next, false ); 204 204 205 205 return true; 206 206 } 207 207 208 bool __cfa_io_drain( processor * proc ) {208 bool __cfa_io_drain( struct processor * proc ) { 209 209 bool local = false; 210 210 bool remote = false; … … 243 243 /* paranoid */ verify( io.tscs[target].t.tv != ULLONG_MAX ); 244 244 HELP: if(target < ctxs_count) { 245 const unsigned long long cutoff = calc_cutoff(ctsc, ctx->cq.id, ctxs_count, io.data, io.tscs, __shard_factor.io );246 const unsigned long long age = moving_average(ctsc, io.tscs[target].t.tv, io.tscs[target].t.ma );245 const unsigned long long cutoff = calc_cutoff(ctsc, ctx->cq.id, ctxs_count, io.data, io.tscs, __shard_factor.io, false); 246 const unsigned long long age = moving_average(ctsc, io.tscs[target].t.tv, io.tscs[target].t.ma, false); 247 247 __cfadbg_print_safe(io, "Kernel I/O: Help attempt on %u from %u, age %'llu vs cutoff %'llu, %s\n", target, ctx->cq.id, age, cutoff, age > cutoff ? "yes" : "no"); 248 248 if(age <= cutoff) break HELP; … … 273 273 } 274 274 275 bool __cfa_io_flush( processor * proc ) {275 bool __cfa_io_flush( struct processor * proc ) { 276 276 /* paranoid */ verify( ! __preemption_enabled() ); 277 277 /* paranoid */ verify( proc ); … … 353 353 354 354 disable_interrupts(); 355 processor * proc = __cfaabi_tls.this_processor;355 struct processor * proc = __cfaabi_tls.this_processor; 356 356 io_context$ * ctx = proc->io.ctx; 357 357 /* paranoid */ verify( __cfaabi_tls.this_processor ); … … 433 433 disable_interrupts(); 434 434 __STATS__( true, if(!lazy) io.submit.eagr += 1; ) 435 processor * proc = __cfaabi_tls.this_processor;435 struct processor * proc = __cfaabi_tls.this_processor; 436 436 io_context$ * ctx = proc->io.ctx; 437 437 /* paranoid */ verify( __cfaabi_tls.this_processor ); … … 641 641 642 642 #if defined(CFA_WITH_IO_URING_IDLE) 643 bool __kernel_read( processor * proc, io_future_t & future, iovec & iov, int fd) {643 bool __kernel_read(struct processor * proc, io_future_t & future, iovec & iov, int fd) { 644 644 io_context$ * ctx = proc->io.ctx; 645 645 /* paranoid */ verify( ! __preemption_enabled() ); … … 692 692 } 693 693 694 void __cfa_io_idle( processor * proc ) {694 void __cfa_io_idle( struct processor * proc ) { 695 695 iovec iov; 696 696 __atomic_acquire( &proc->io.ctx->cq.lock ); -
libcfa/src/concurrency/io/types.hfa
rf704974 rae151cf 127 127 struct __attribute__((aligned(64))) io_context$ { 128 128 io_arbiter$ * arbiter; 129 processor * proc;129 struct processor * proc; 130 130 131 131 __outstanding_io_queue ext_sq; -
libcfa/src/concurrency/kernel/cluster.cfa
rf704974 rae151cf 254 254 } 255 255 256 static void assign_list(unsigned & valrq, unsigned & valio, dlist( processor) & list, unsigned count) {257 processor * it = &list`first;256 static void assign_list(unsigned & valrq, unsigned & valio, dlist(struct processor) & list, unsigned count) { 257 struct processor * it = &list`first; 258 258 for(unsigned i = 0; i < count; i++) { 259 259 /* paranoid */ verifyf( it, "Unexpected null iterator, at index %u of %u\n", i, count); … … 278 278 279 279 #if defined(CFA_HAVE_LINUX_IO_URING_H) 280 static void assign_io(io_context$ ** data, size_t count, dlist( processor) & list) {281 processor * it = &list`first;280 static void assign_io(io_context$ ** data, size_t count, dlist(struct processor) & list) { 281 struct processor * it = &list`first; 282 282 while(it) { 283 283 /* paranoid */ verifyf( it, "Unexpected null iterator\n"); -
libcfa/src/concurrency/kernel/cluster.hfa
rf704974 rae151cf 21 21 #include <limits.h> 22 22 23 #include "clock.hfa" 24 23 25 //----------------------------------------------------------------------- 24 26 // Calc moving average based on existing average, before and current time. 25 static inline unsigned long long moving_average(unsigned long long currtsc, unsigned long long instsc, unsigned long long old_avg) { 26 /* paranoid */ verifyf( old_avg < 15000000000000, "Suspiciously large previous average: %'llu (%llx)\n", old_avg, old_avg ); 27 static inline unsigned long long moving_average(unsigned long long currtsc, unsigned long long instsc, unsigned long long old_avg, bool strict) { 28 (void)strict; // disable the warning around the fact this is unused in release. 29 /* paranoid */ warnf( !strict || old_avg < 33_000_000_000, "Suspiciously large previous average: %'llu (%llx), %'ldms \n", old_avg, old_avg, program()`ms ); 27 30 28 31 const unsigned long long new_val = currtsc > instsc ? currtsc - instsc : 0; … … 31 34 const unsigned long long old_weight = total_weight - new_weight; 32 35 const unsigned long long ret = ((new_weight * new_val) + (old_weight * old_avg)) / total_weight; 36 37 /* paranoid */ warnf( !strict || ret < 33_000_000_000, "Suspiciously large new average after %'ldms cputime: %'llu (%llx) from %'llu-%'llu (%'llu, %'llu) and %'llu\n", program()`ms, ret, ret, currtsc, instsc, new_val, new_val / 1000000, old_avg ); 33 38 return ret; 34 39 } 35 40 36 static inline void touch_tsc(__timestamp_t * tscs, size_t idx, unsigned long long ts_prev, unsigned long long ts_next ) {41 static inline void touch_tsc(__timestamp_t * tscs, size_t idx, unsigned long long ts_prev, unsigned long long ts_next, bool strict) { 37 42 if (ts_next == ULLONG_MAX) return; 38 43 unsigned long long now = rdtscl(); 39 44 unsigned long long pma = __atomic_load_n(&tscs[ idx ].t.ma, __ATOMIC_RELAXED); 40 45 __atomic_store_n(&tscs[ idx ].t.tv, ts_next, __ATOMIC_RELAXED); 41 __atomic_store_n(&tscs[ idx ].t.ma, moving_average(now, ts_prev, pma ), __ATOMIC_RELAXED);46 __atomic_store_n(&tscs[ idx ].t.ma, moving_average(now, ts_prev, pma, strict), __ATOMIC_RELAXED); 42 47 } 43 48 … … 51 56 Data_t * data, 52 57 __timestamp_t * tscs, 53 const unsigned shard_factor 58 const unsigned shard_factor, 59 bool strict 54 60 ) { 55 61 unsigned start = procid; … … 59 65 if(ptsc != ULLONG_MAX) { 60 66 /* paranoid */ verify( start + i < count ); 61 unsigned long long tsc = moving_average(ctsc, ptsc, tscs[start + i].t.ma );67 unsigned long long tsc = moving_average(ctsc, ptsc, tscs[start + i].t.ma, strict); 62 68 if(tsc > max) max = tsc; 63 69 } -
libcfa/src/concurrency/preemption.cfa
rf704974 rae151cf 104 104 static inline alarm_node_t * get_expired( alarm_list_t * alarms, Time currtime ) { 105 105 if( ! & (*alarms)`first ) return 0p; // If no alarms return null 106 if( (*alarms)`first. timeval>= currtime ) return 0p; // If alarms head not expired return null106 if( (*alarms)`first.deadline >= currtime ) return 0p; // If alarms head not expired return null 107 107 return pop(alarms); // Otherwise just pop head 108 108 } … … 140 140 if( period > 0 ) { 141 141 __cfadbg_print_buffer_local( preemption, " KERNEL: alarm period is %lu.\n", period`ns ); 142 node-> timeval= currtime + period; // Alarm is periodic, add currtime to it (used cached current time)142 node->deadline = currtime + period; // Alarm is periodic, add currtime to it (used cached current time) 143 143 insert( alarms, node ); // Reinsert the node for the next time it triggers 144 144 } … … 147 147 // If there are still alarms pending, reset the timer 148 148 if( & (*alarms)`first ) { 149 Duration delta = (*alarms)`first. timeval- currtime;149 Duration delta = (*alarms)`first.deadline - currtime; 150 150 __kernel_set_timer( delta ); 151 151 } -
libcfa/src/concurrency/ready_queue.cfa
rf704974 rae151cf 62 62 //----------------------------------------------------------------------- 63 63 __attribute__((hot)) void push(struct cluster * cltr, struct thread$ * thrd, unpark_hint hint) with (cltr->sched) { 64 processor * const proc = kernelTLS().this_processor;64 struct processor * const proc = kernelTLS().this_processor; 65 65 const bool external = (!proc) || (cltr != proc->cltr); 66 66 const bool remote = hint == UNPARK_REMOTE; … … 116 116 /* paranoid */ verify( kernelTLS().this_processor->rdq.id < lanes_count ); 117 117 118 processor * const proc = kernelTLS().this_processor;118 struct processor * const proc = kernelTLS().this_processor; 119 119 unsigned this = proc->rdq.id; 120 120 /* paranoid */ verify( this < lanes_count ); … … 139 139 /* paranoid */ verify( readyQ.tscs[target].t.tv != ULLONG_MAX ); 140 140 if(target < lanes_count) { 141 const unsigned long long cutoff = calc_cutoff(ctsc, proc->rdq.id, lanes_count, cltr->sched.readyQ.data, cltr->sched.readyQ.tscs, __shard_factor.readyq );142 const unsigned long long age = moving_average(ctsc, readyQ.tscs[target].t.tv, readyQ.tscs[target].t.ma );141 const unsigned long long cutoff = calc_cutoff(ctsc, proc->rdq.id, lanes_count, cltr->sched.readyQ.data, cltr->sched.readyQ.tscs, __shard_factor.readyq, true); 142 const unsigned long long age = moving_average(ctsc, readyQ.tscs[target].t.tv, readyQ.tscs[target].t.ma, false); 143 143 __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"); 144 144 if(age > cutoff) { … … 214 214 __STATS( stats.success++; ) 215 215 216 touch_tsc(readyQ.tscs, w, ts_prev, ts_next );216 touch_tsc(readyQ.tscs, w, ts_prev, ts_next, true); 217 217 218 218 thrd->preferred = w / __shard_factor.readyq; -
libcfa/src/stdhdr/assert.h
rf704974 rae151cf 27 27 #define assertf( expr, fmt, ... ) ((expr) ? ((void)0) : __assert_fail_f(__VSTRINGIFY__(expr), __FILE__, __LINE__, __PRETTY_FUNCTION__, fmt, ## __VA_ARGS__ )) 28 28 29 void __assert_warn_f( const char assertion[], const char file[], unsigned int line, const char function[], const char fmt[], ... ) __attribute__((format( printf, 5, 6) )); 29 30 void __assert_fail_f( const char assertion[], const char file[], unsigned int line, const char function[], const char fmt[], ... ) __attribute__((noreturn, format( printf, 5, 6) )); 30 31 #endif 31 32 32 33 #if !defined(NDEBUG) && (defined(__CFA_DEBUG__) || defined(__CFA_VERIFY__)) 34 #define __CFA_WITH_VERIFY__ 33 35 #define verify(x) assert(x) 34 36 #define verifyf(x, ...) assertf(x, __VA_ARGS__) 35 37 #define verifyfail(...) 36 #define __CFA_WITH_VERIFY__38 #define warnf( expr, fmt, ... ) ({ static bool check_once##__LINE__ = false; if( false == check_once##__LINE__ && false == (expr)) { check_once##__LINE__ = true; __assert_warn_f(__VSTRINGIFY__(expr), __FILE__, __LINE__, __PRETTY_FUNCTION__, fmt, ## __VA_ARGS__ ); } }) 37 39 #else 38 40 #define verify(x) 39 41 #define verifyf(x, ...) 40 42 #define verifyfail(...) 43 #define warnf( expr, fmt, ... ) 41 44 #endif 42 45
Note: See TracChangeset
for help on using the changeset viewer.