Changeset f5a51db for tests/concurrent/preempt.cfa
- Timestamp:
- Feb 8, 2022, 11:53:13 AM (4 years ago)
- Branches:
- ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
- Children:
- cc7bbe6
- Parents:
- 97c215f (diff), 1cf8a9f (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/concurrent/preempt.cfa
r97c215f rf5a51db 1 #include <clock.hfa> 2 #include <fstream.hfa> 1 3 #include <kernel.hfa> 2 4 #include <thread.hfa> … … 21 23 extern void __cfaabi_check_preemption(); 22 24 23 static volatile int counter = 0; 25 static struct { 26 volatile int counter; 27 volatile Time prev; 28 Duration durations[6]; 29 } globals; 24 30 25 31 thread worker_t { 26 32 int value; 33 unsigned long long spin; 27 34 }; 28 35 29 36 void ?{}( worker_t & this, int value ) { 30 37 this.value = value; 38 this.spin = 0; 31 39 } 32 40 33 41 void main(worker_t & this) { 34 while(TEST(counter < N)) { 42 while(TEST(globals.counter < N)) { 43 if(this.spin > 50_000_000_000) abort | "Worker" | this.value | "has been spinning too long! (" | this.spin | ")"; 35 44 __cfaabi_check_preemption(); 36 if( ( counter % 7) == this.value ) {45 if( (globals.counter % 7) == this.value ) { 37 46 __cfaabi_check_preemption(); 38 int next = __atomic_add_fetch( &counter, 1, __ATOMIC_SEQ_CST ); 47 #if !defined(TEST_LONG) 48 Time now = timeHiRes(); 49 Duration diff = now - globals.prev; 50 globals.prev = now; 51 #endif 52 int next = __atomic_add_fetch( &globals.counter, 1, __ATOMIC_SEQ_CST ); 39 53 __cfaabi_check_preemption(); 40 if( (next % 100) == 0 ) printf("%d\n", (int)next); 54 if( (next % 100) == 0 ) { 55 #if !defined(TEST_LONG) 56 unsigned idx = next / 100; 57 if (idx >= 6) abort | "Idx from next is invalid: " | idx | "vs" | next; 58 globals.durations[idx] = diff; 59 if(diff > 12`s) serr | "Duration suspiciously large:" | diff; 60 #endif 61 printf("%d\n", (int)next); 62 63 } 41 64 __cfaabi_check_preemption(); 65 this.spin = 0; 42 66 } 43 67 __cfaabi_check_preemption(); 44 68 KICK_WATCHDOG; 69 this.spin++; 45 70 } 46 71 } … … 48 73 int main(int argc, char* argv[]) { 49 74 processor p; 75 globals.counter = 0; 76 globals.durations[0] = 0; 77 globals.durations[1] = 0; 78 globals.durations[2] = 0; 79 globals.durations[3] = 0; 80 globals.durations[4] = 0; 81 globals.durations[5] = 0; 50 82 { 83 globals.prev = timeHiRes(); 51 84 worker_t w0 = 0; 52 85 worker_t w1 = 1;
Note:
See TracChangeset
for help on using the changeset viewer.