source: tests/concurrent/preempt.cfa@ d7e9c12

ADT ast-experimental enum forall-pointer-decay pthread-emulation qualifiedEnum
Last change on this file since d7e9c12 was 8e5e945, checked in by Thierry Delisle <tdelisle@…>, 4 years ago

Increase preempt spin timeout and added duration per phase calculation

  • Property mode set to 100644
File size: 1.8 KB
Line 
1#include <clock.hfa>
2#include <fstream.hfa>
3#include <kernel.hfa>
4#include <thread.hfa>
5#include <time.hfa>
6
7#include "long_tests.hfa"
8
9#ifndef PREEMPTION_RATE
10#define PREEMPTION_RATE 10`ms
11#endif
12
13Duration default_preemption() {
14 return PREEMPTION_RATE;
15}
16
17#ifdef TEST_LONG
18static const unsigned long N = 30_000ul;
19#else
20static const unsigned long N = 500ul;
21static volatile Time prev;
22static Duration preempt_durations[6] = { 0 };
23#endif
24
25extern void __cfaabi_check_preemption();
26
27static volatile int counter = 0;
28
29thread worker_t {
30 int value;
31 unsigned long long spin;
32};
33
34void ?{}( worker_t & this, int value ) {
35 this.value = value;
36 this.spin = 0;
37}
38
39void main(worker_t & this) {
40 while(TEST(counter < N)) {
41 if(this.spin > 50_000_000_000) abort | "Worker" | this.value | "has been spinning too long! (" | this.spin | ")";
42 __cfaabi_check_preemption();
43 if( (counter % 7) == this.value ) {
44 __cfaabi_check_preemption();
45 #if !defined(TEST_LONG)
46 Time now = timeHiRes();
47 Duration diff = now - prev;
48 prev = now;
49 #endif
50 int next = __atomic_add_fetch( &counter, 1, __ATOMIC_SEQ_CST );
51 __cfaabi_check_preemption();
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 }
62 __cfaabi_check_preemption();
63 this.spin = 0;
64 }
65 __cfaabi_check_preemption();
66 KICK_WATCHDOG;
67 this.spin++;
68 }
69}
70
71int main(int argc, char* argv[]) {
72 processor p;
73 {
74 prev = timeHiRes();
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;
82 }
83}
Note: See TracBrowser for help on using the repository browser.