source: tests/concurrent/preempt.cfa @ 376c632a

ADTast-experimentalenumforall-pointer-decaypthread-emulationqualifiedEnum
Last change on this file since 376c632a was 8e5e945, checked in by Thierry Delisle <tdelisle@…>, 2 years ago

Increase preempt spin timeout and added duration per phase calculation

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[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]13Duration default_preemption() {
[11dbfe1]14        return PREEMPTION_RATE;
15}
16
[7bdcac1]17#ifdef TEST_LONG
[b2fe1c9]18static const unsigned long N = 30_000ul;
19#else
20static const unsigned long N = 500ul;
[8e5e945]21static volatile Time prev;
22static Duration preempt_durations[6] = { 0 };
[b2fe1c9]23#endif
24
[b68fc85]25extern void __cfaabi_check_preemption();
26
[11dbfe1]27static volatile int counter = 0;
28
[0322865c]29thread worker_t {
[11dbfe1]30        int value;
[8e5e945]31        unsigned long long spin;
[11dbfe1]32};
33
[2afec66]34void ?{}( worker_t & this, int value ) {
35        this.value = value;
[1612315]36        this.spin = 0;
[11dbfe1]37}
38
[83a071f9]39void 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
71int 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}
Note: See TracBrowser for help on using the repository browser.