[8e5e945] | 1 | #include <clock.hfa> |
---|
[c0f881b] | 2 | #include <fstream.hfa> |
---|
[096a2ff] | 3 | #include <kernel.hfa> |
---|
[73abe95] | 4 | #include <thread.hfa> |
---|
| 5 | #include <time.hfa> |
---|
[11dbfe1] | 6 | |
---|
[dc8511c] | 7 | #include "long_tests.hfa" |
---|
[7bdcac1] | 8 | |
---|
[11dbfe1] | 9 | #ifndef PREEMPTION_RATE |
---|
[8ad6533] | 10 | #define PREEMPTION_RATE 10`ms |
---|
[11dbfe1] | 11 | #endif |
---|
| 12 | |
---|
[8ad6533] | 13 | Duration default_preemption() { |
---|
[11dbfe1] | 14 | return PREEMPTION_RATE; |
---|
| 15 | } |
---|
| 16 | |
---|
[7bdcac1] | 17 | #ifdef TEST_LONG |
---|
[b2fe1c9] | 18 | static const unsigned long N = 30_000ul; |
---|
| 19 | #else |
---|
| 20 | static const unsigned long N = 500ul; |
---|
[8e5e945] | 21 | static volatile Time prev; |
---|
| 22 | static Duration preempt_durations[6] = { 0 }; |
---|
[b2fe1c9] | 23 | #endif |
---|
| 24 | |
---|
[b68fc85] | 25 | extern void __cfaabi_check_preemption(); |
---|
| 26 | |
---|
[11dbfe1] | 27 | static volatile int counter = 0; |
---|
| 28 | |
---|
[0322865c] | 29 | thread worker_t { |
---|
[11dbfe1] | 30 | int value; |
---|
[8e5e945] | 31 | unsigned long long spin; |
---|
[11dbfe1] | 32 | }; |
---|
| 33 | |
---|
[2afec66] | 34 | void ?{}( worker_t & this, int value ) { |
---|
| 35 | this.value = value; |
---|
[1612315] | 36 | this.spin = 0; |
---|
[11dbfe1] | 37 | } |
---|
| 38 | |
---|
[83a071f9] | 39 | void main(worker_t & this) { |
---|
[7bdcac1] | 40 | while(TEST(counter < N)) { |
---|
[8e5e945] | 41 | if(this.spin > 50_000_000_000) abort | "Worker" | this.value | "has been spinning too long! (" | this.spin | ")"; |
---|
[b68fc85] | 42 | __cfaabi_check_preemption(); |
---|
[83a071f9] | 43 | if( (counter % 7) == this.value ) { |
---|
[b68fc85] | 44 | __cfaabi_check_preemption(); |
---|
[8e5e945] | 45 | #if !defined(TEST_LONG) |
---|
| 46 | Time now = timeHiRes(); |
---|
| 47 | Duration diff = now - prev; |
---|
| 48 | prev = now; |
---|
| 49 | #endif |
---|
[c701332a] | 50 | int next = __atomic_add_fetch( &counter, 1, __ATOMIC_SEQ_CST ); |
---|
[b68fc85] | 51 | __cfaabi_check_preemption(); |
---|
[8e5e945] | 52 | if( (next % 100) == 0 ) { |
---|
| 53 | #if !defined(TEST_LONG) |
---|
| 54 | unsigned idx = next / 100; |
---|
| 55 | if (idx >= 6) abort | "Idx from next is invalid: " | idx | "vs" | next; |
---|
| 56 | preempt_durations[idx] = diff; |
---|
| 57 | if(diff > 12`s) serr | "Duration suspiciously large:" | diff; |
---|
| 58 | #endif |
---|
| 59 | printf("%d\n", (int)next); |
---|
| 60 | |
---|
| 61 | } |
---|
[b68fc85] | 62 | __cfaabi_check_preemption(); |
---|
[b200492] | 63 | this.spin = 0; |
---|
[11dbfe1] | 64 | } |
---|
[b68fc85] | 65 | __cfaabi_check_preemption(); |
---|
[7bdcac1] | 66 | KICK_WATCHDOG; |
---|
[1612315] | 67 | this.spin++; |
---|
[11dbfe1] | 68 | } |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | int main(int argc, char* argv[]) { |
---|
| 72 | processor p; |
---|
| 73 | { |
---|
[8e5e945] | 74 | prev = timeHiRes(); |
---|
[0322865c] | 75 | worker_t w0 = 0; |
---|
| 76 | worker_t w1 = 1; |
---|
| 77 | worker_t w2 = 2; |
---|
| 78 | worker_t w3 = 3; |
---|
| 79 | worker_t w4 = 4; |
---|
| 80 | worker_t w5 = 5; |
---|
| 81 | worker_t w6 = 6; |
---|
[11dbfe1] | 82 | } |
---|
[2afec66] | 83 | } |
---|