Changes in / [42daeb4:3bb12921]
- Files:
-
- 1 deleted
- 16 edited
-
libcfa/src/bits/locks.hfa (modified) (3 diffs)
-
libcfa/src/concurrency/invoke.h (modified) (2 diffs)
-
libcfa/src/concurrency/io.cfa (modified) (1 diff)
-
libcfa/src/concurrency/kernel.cfa (modified) (2 diffs)
-
libcfa/src/concurrency/kernel/fwd.hfa (modified) (3 diffs)
-
libcfa/src/concurrency/kernel/startup.cfa (modified) (2 diffs)
-
libcfa/src/concurrency/ready_queue.cfa (modified) (1 diff)
-
libcfa/src/concurrency/thread.cfa (modified) (4 diffs)
-
libcfa/src/device/cpu.cfa (modified) (1 diff)
-
libcfa/src/device/cpu.hfa (modified) (1 diff)
-
libcfa/src/fstream.cfa (modified) (2 diffs)
-
libcfa/src/startup.cfa (modified) (3 diffs)
-
libcfa/src/stdlib.cfa (modified) (2 diffs)
-
libcfa/src/stdlib.hfa (modified) (5 diffs)
-
tests/io/io-acquire.cfa (modified) (3 diffs)
-
tests/io/io-acquire2.cfa (deleted)
-
tools/jenkins/setup.sh.in (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/bits/locks.hfa
r42daeb4 r3bb12921 31 31 // previous thread to acquire the lock 32 32 void* prev_thrd; 33 // keep track of number of times we had to spin, just in case the number is unexpectedly huge34 size_t spin_count;35 33 #endif 36 34 }; … … 50 48 static inline void ?{}( __spinlock_t & this ) { 51 49 this.lock = 0; 52 #ifdef __CFA_DEBUG__53 this.spin_count = 0;54 #endif55 50 } 56 51 … … 77 72 for ( unsigned int i = 1;; i += 1 ) { 78 73 if ( (this.lock == 0) && (__atomic_test_and_set( &this.lock, __ATOMIC_ACQUIRE ) == 0) ) break; 79 #ifdef __CFA_DEBUG__80 this.spin_count++;81 #endif82 74 #ifndef NOEXPBACK 83 75 // exponential spin -
libcfa/src/concurrency/invoke.h
r42daeb4 r3bb12921 10 10 // Created On : Tue Jan 17 12:27:26 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Jan 9 19:06:45202213 // Update Count : 4 812 // Last Modified On : Thu Jan 6 16:37:40 2022 13 // Update Count : 47 14 14 // 15 15 … … 211 211 struct processor * last_proc; 212 212 213 uint32_t random_state; // fast random numbers214 215 213 #if defined( __CFA_WITH_VERIFY__ ) 216 214 void * canary; -
libcfa/src/concurrency/io.cfa
r42daeb4 r3bb12921 548 548 /* paranoid */ verify( proc == __cfaabi_tls.this_processor ); 549 549 /* paranoid */ verify( ! __preemption_enabled() ); 550 551 return true;552 550 } 553 551 #endif -
libcfa/src/concurrency/kernel.cfa
r42daeb4 r3bb12921 554 554 /* paranoid */ verify( 0x0D15EA5E0D15EA5Ep == thrd->canary ); 555 555 556 const bool local = thrd->state != Start; 556 557 if (thrd->preempted == __NO_PREEMPTION) thrd->state = Ready; 557 558 … … 736 737 737 738 // 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 } 739 int fd = __atomic_load_n(&this->procs.fd, __ATOMIC_SEQ_CST); 743 740 744 741 // If no one is sleeping, we are done -
libcfa/src/concurrency/kernel/fwd.hfa
r42daeb4 r3bb12921 77 77 78 78 static inline uint64_t __tls_rand() { 79 return80 79 #if defined(__SIZEOF_INT128__) 81 __lehmer64( kernelTLS().rand_seed );80 return __lehmer64( kernelTLS().rand_seed ); 82 81 #else 83 __xorshift64( kernelTLS().rand_seed );82 return __xorshift64( kernelTLS().rand_seed ); 84 83 #endif 85 84 } … … 92 91 93 92 static inline unsigned __tls_rand_fwd() { 93 94 94 kernelTLS().ready_rng.fwd_seed = (A * kernelTLS().ready_rng.fwd_seed + C) & (M - 1); 95 95 return kernelTLS().ready_rng.fwd_seed >> D; … … 112 112 } 113 113 } 114 115 114 116 115 117 extern void disable_interrupts(); -
libcfa/src/concurrency/kernel/startup.cfa
r42daeb4 r3bb12921 101 101 extern void __wake_proc(processor *); 102 102 extern int cfa_main_returned; // from interpose.cfa 103 extern uint32_t __global_random_seed;104 103 105 104 //----------------------------------------------------------------------------- … … 490 489 preferred = ready_queue_new_preferred(); 491 490 last_proc = 0p; 492 random_state = __global_random_seed;493 491 #if defined( __CFA_WITH_VERIFY__ ) 494 492 canary = 0x0D15EA5E0D15EA5Ep; -
libcfa/src/concurrency/ready_queue.cfa
r42daeb4 r3bb12921 681 681 // Actually pop the list 682 682 struct thread$ * thrd; 683 #if defined(USE_WORK_STEALING) || defined(USE_CPU_WORK_STEALING) 684 unsigned long long tsc_before = ts(lane); 685 #endif 683 unsigned long long tsc_before = ts(lane); 686 684 unsigned long long tsv; 687 685 [thrd, tsv] = pop(lane); -
libcfa/src/concurrency/thread.cfa
r42daeb4 r3bb12921 10 10 // Created On : Tue Jan 17 12:27:26 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jan 12 18:46:48 202213 // Update Count : 3612 // Last Modified On : Wed Dec 4 09:17:49 2019 13 // Update Count : 9 14 14 // 15 15 … … 27 27 uint64_t thread_rand(); 28 28 29 extern uint32_t __global_random_seed;30 31 29 //----------------------------------------------------------------------------- 32 30 // Thread ctors and dtors 33 void ?{}( thread$ & this, const char * const name, cluster & cl, void * storage, size_t storageSize ) with( this ) {31 void ?{}(thread$ & this, const char * const name, cluster & cl, void * storage, size_t storageSize ) with( this ) { 34 32 context{ 0p, 0p }; 35 33 self_cor{ name, storage, storageSize }; … … 47 45 preferred = ready_queue_new_preferred(); 48 46 last_proc = 0p; 49 random_state = __global_random_seed;50 47 #if defined( __CFA_WITH_VERIFY__ ) 51 48 canary = 0x0D15EA5E0D15EA5Ep; … … 180 177 return ret; 181 178 } 182 183 #define GENERATOR LCG184 185 static inline uint32_t MarsagliaXor( uint32_t & state ) {186 uint32_t ret = state;187 state ^= state << 6;188 state ^= state >> 21;189 state ^= state << 7;190 return ret;191 } // MarsagliaXor192 193 static inline uint32_t LCG( uint32_t & state ) { // linear congruential generator194 uint32_t ret = state;195 state = 36969 * (state & 65535) + (state >> 16); // 36969 is NOT prime! No not change it!196 return ret;197 } // LCG198 199 void set_seed( uint32_t seed ) {200 active_thread()->random_state = __global_random_seed = seed;201 GENERATOR( active_thread()->random_state );202 } // set_seed203 uint32_t prng( void ) { return GENERATOR( active_thread()->random_state ); } // [0,UINT_MAX]204 179 205 180 // Local Variables: // -
libcfa/src/device/cpu.cfa
r42daeb4 r3bb12921 427 427 unsigned c = pairings[i].cpu; 428 428 unsigned llc_id = pairings[i].id; 429 unsigned width = maps[llc_id].raw->width; 429 430 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; 431 433 entries[c].start = start; 432 entries[c].self = start + (maps[llc_id].count++); 433 entries[c].cache = llc_id; 434 entries[c].self = self; 434 435 } 435 436 -
libcfa/src/device/cpu.hfa
r42daeb4 r3bb12921 16 16 #include <stddef.h> 17 17 18 // Map from cpu entry to a structure detailling cpus with common topologies19 // Note that the cpu-groups are contiguous so the indexing is different from20 // the cpu indexing21 18 struct cpu_map_entry_t { 22 // Where this particular cpu is in the group23 19 unsigned self; 24 25 // Starting index of the cpus with the same topology26 20 unsigned start; 27 28 // Number of cpus with the same topology29 21 unsigned count; 30 31 // Index of the cache this entry describes32 unsigned cache;33 22 }; 34 23 -
libcfa/src/fstream.cfa
r42daeb4 r3bb12921 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jan 10 08:45:05 202213 // Update Count : 51 312 // Last Modified On : Sun Oct 10 11:23:05 2021 13 // Update Count : 512 14 14 // 15 15 … … 52 52 inline void setPrt$( ofstream & os, bool state ) { os.prt$ = state; } 53 53 54 inline void lock( ofstream & os ) with( os ) { lock( os.lock$ ); }54 inline void lock( ofstream & os ) with( os ) { lock( os.lock$ ); } 55 55 inline void unlock( ofstream & os ) { unlock( os.lock$ ); } 56 56 -
libcfa/src/startup.cfa
r42daeb4 r3bb12921 10 10 // Created On : Tue Jul 24 16:21:57 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jan 12 18:51:24 202213 // Update Count : 5112 // Last Modified On : Sat Jan 9 23:18:23 2021 13 // Update Count : 34 14 14 // 15 15 … … 18 18 #include <stdlib.h> // getenv 19 19 #include "startup.hfa" 20 #include "bits/defs.hfa"21 22 extern uint32_t __global_random_seed, __global_random_state;23 20 24 21 extern "C" { … … 51 48 void __cfaabi_core_startup( void ) __attribute__(( constructor( STARTUP_PRIORITY_CORE ) )); 52 49 void __cfaabi_core_startup( void ) { 53 __global_random_state = __global_random_seed = rdtscl();54 50 __cfaabi_interpose_startup(); 55 51 __cfaabi_device_startup(); -
libcfa/src/stdlib.cfa
r42daeb4 r3bb12921 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jan 12 18:52:41202213 // Update Count : 5 8212 // Last Modified On : Mon Jan 3 09:36:27 2022 13 // Update Count : 519 14 14 // 15 15 16 16 #include "stdlib.hfa" 17 //#include "concurrency/kernel/fwd.hfa"18 #include "concurrency/invoke.h" // random_state19 17 20 18 //--------------------------------------- … … 223 221 //--------------------------------------- 224 222 225 // Pipelined to allow OoO overlap with reduced dependencies. Critically, return the current value, and compute and store 226 // the next value. 223 static uint32_t seed = 0; // current seed 224 static thread_local uint32_t state; // random state 225 226 void set_seed( uint32_t seed_ ) { state = seed = seed_; } 227 uint32_t get_seed() { return seed; } 227 228 228 229 #define GENERATOR LCG 229 230 230 static inline uint32_t MarsagliaXor( uint32_t & state ) { 231 uint32_t ret = state; 231 inline uint32_t MarsagliaXor( uint32_t & state ) { 232 if ( unlikely( seed == 0 ) ) set_seed( rdtscl() ); 233 else if ( unlikely( state == 0 ) ) state = seed; 232 234 state ^= state << 6; 233 235 state ^= state >> 21; 234 236 state ^= state << 7; 235 return ret;237 return state; 236 238 } // MarsagliaXor 237 239 238 static inline uint32_t LCG( uint32_t & state ) {// linear congruential generator239 uint32_t ret = state;240 state = 36969 * (state & 65535) + (state >> 16); // 36969 is NOT prime! No not change it!241 return ret;240 inline 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 = 36969 * (state & 65535) + (state >> 16); // 36969 is NOT prime! 242 244 } // LCG 243 245 244 uint32_t __global_random_seed; // sequential/concurrent245 uint32_t __global_random_state; // sequential only246 247 void set_seed( PRNG & prng, uint32_t seed_ ) with( prng ) { state = seed = seed_; GENERATOR( state ); } // set seed248 246 uint32_t prng( PRNG & prng ) with( prng ) { callcnt += 1; return GENERATOR( state ); } 249 247 250 void set_seed( uint32_t seed ) { __global_random_seed = seed; GENERATOR( __global_random_state ); } 251 uint32_t get_seed() { return __global_random_seed; } 252 uint32_t prng( void ) { return GENERATOR( __global_random_state ); } // [0,UINT_MAX] 248 uint32_t prng( void ) { return GENERATOR( state ); } 253 249 254 250 //--------------------------------------- -
libcfa/src/stdlib.hfa
r42daeb4 r3bb12921 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jan 12 18:56:13202213 // Update Count : 62112 // Last Modified On : Sun Jan 2 22:53:57 2022 13 // Update Count : 594 14 14 // 15 15 … … 21 21 #include <stdlib.h> // *alloc, strto*, ato* 22 22 #include <heap.hfa> 23 24 23 25 24 // Reduce includes by explicitly defining these routines. … … 386 385 //--------------------------------------- 387 386 388 // Sequential Pseudo Random-Number Generator : generate repeatable sequence of values that appear random.389 //390 // Declaration :391 // PRNG sprng = { 1009 } - set starting seed versus random seed392 //393 // Interface :394 // set_seed( sprng, 1009 ) - set starting seed for ALL kernel threads versus random seed395 // get_seed( sprng ) - read seed396 // prng( sprng ) - generate random value in range [0,UINT_MAX]397 // prng( sprng, u ) - generate random value in range [0,u)398 // prng( sprng, l, u ) - generate random value in range [l,u]399 // calls( sprng ) - number of generated random value so far400 //401 // Examples : generate random number between 5-21402 // prng( sprng ) % 17 + 5; values 0-16 + 5 = 5-21403 // prng( sprng, 16 + 1 ) + 5;404 // prng( sprng, 5, 21 );405 // calls( sprng );406 407 387 struct PRNG { 408 388 uint32_t callcnt; // call count … … 411 391 }; // PRNG 412 392 413 void set_seed( PRNG & prng, uint32_t seed_ ); 414 uint32_t prng( PRNG & prng ) __attribute__(( warn_unused_result )); // [0,UINT_MAX] 393 extern uint32_t prng( PRNG & prng ) __attribute__(( warn_unused_result )); // [0,UINT_MAX] 415 394 static inline { 395 void set_seed( PRNG & prng, uint32_t seed_ ) with( prng ) { state = seed = seed_; } // set seed 416 396 void ?{}( PRNG & prng ) { set_seed( prng, rdtscl() ); } // random seed 417 397 void ?{}( PRNG & prng, uint32_t seed ) { set_seed( prng, seed ); } // fixed seed … … 422 402 } // distribution 423 403 424 // Concurrent Pseudo Random-Number Generator : generate repeatable sequence of values that appear random. 425 // 426 // Interface : 427 // set_seed( 1009 ) - fixed seed for all kernel threads versus random seed 428 // get_seed() - read seed 429 // prng() - generate random value in range [0,UINT_MAX] 430 // prng( u ) - generate random value in range [0,u) 431 // prng( l, u ) - generate random value in range [l,u] 432 // 433 // Examples : generate random number between 5-21 434 // prng() % 17 + 5; values 0-16 + 5 = 5-21 435 // prng( 16 + 1 ) + 5; 436 // prng( 5, 21 ); 437 438 void set_seed( uint32_t seed_ ) OPTIONAL_THREAD; 439 uint32_t get_seed() __attribute__(( warn_unused_result )); 440 uint32_t prng( void ) __attribute__(( warn_unused_result )) OPTIONAL_THREAD; // [0,UINT_MAX] 404 extern void set_seed( uint32_t seed ); // set per thread seed 405 extern uint32_t get_seed(); // get seed 406 extern uint32_t prng( void ) __attribute__(( warn_unused_result )); // [0,UINT_MAX] 441 407 static inline { 442 uint32_t prng( uint32_t u ) __attribute__(( warn_unused_result )) { return prng() % u; } // [0,u) 443 uint32_t prng( uint32_t l, uint32_t u ) __attribute__(( warn_unused_result )) { return prng( u - l + 1 ) + l; } // [l,u] 408 uint32_t prng( uint32_t u ) __attribute__(( warn_unused_result )); 409 uint32_t prng( uint32_t u ) { return prng() % u; } // [0,u) 410 uint32_t prng( uint32_t l, uint32_t u ) __attribute__(( warn_unused_result )); 411 uint32_t prng( uint32_t l, uint32_t u ) { return prng( u - l + 1 ) + l; } // [l,u] 444 412 } // distribution 445 413 -
tests/io/io-acquire.cfa
r42daeb4 r3bb12921 10 10 // Created On : Mon Mar 1 18:40:09 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jan 10 07:57:12 202213 // Update Count : 7 312 // Last Modified On : Wed Oct 6 18:04:58 2021 13 // Update Count : 72 14 14 // 15 15 … … 23 23 24 24 for ( 100 ) { // expression protection 25 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; 26 26 } 27 27 mutex( sout ) { // statement protection … … 51 51 int a, b, c, d, e, f, g, h, i; 52 52 for ( 100 ) { // expression protection 53 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; 54 54 } 55 55 mutex( sin ) { // statement protection -
tools/jenkins/setup.sh.in
r42daeb4 r3bb12921 48 48 regex1='/([[:alpha:][:digit:]@/_.-]+)' 49 49 regex2='(libcfa[[:alpha:][:digit:].]+) => not found' 50 regex3='linux-vdso.so.1 |linux-gate.so.1'50 regex3='linux-vdso.so.1' 51 51 if [[ $line =~ $regex1 ]]; then 52 52 retsysdeps+=(${BASH_REMATCH[1]})
Note:
See TracChangeset
for help on using the changeset viewer.