Ignore:
Timestamp:
Feb 8, 2022, 11:53:13 AM (4 years ago)
Author:
Michael Brooks <mlbrooks@…>
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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/concurrent/preempt.cfa

    r97c215f rf5a51db  
     1#include <clock.hfa>
     2#include <fstream.hfa>
    13#include <kernel.hfa>
    24#include <thread.hfa>
     
    2123extern void __cfaabi_check_preemption();
    2224
    23 static volatile int counter = 0;
     25static struct {
     26        volatile int counter;
     27        volatile Time prev;
     28        Duration durations[6];
     29} globals;
    2430
    2531thread worker_t {
    2632        int value;
     33        unsigned long long spin;
    2734};
    2835
    2936void ?{}( worker_t & this, int value ) {
    3037        this.value = value;
     38        this.spin = 0;
    3139}
    3240
    3341void 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 | ")";
    3544                __cfaabi_check_preemption();
    36                 if( (counter % 7) == this.value ) {
     45                if( (globals.counter % 7) == this.value ) {
    3746                        __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 );
    3953                        __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                        }
    4164                        __cfaabi_check_preemption();
     65                        this.spin = 0;
    4266                }
    4367                __cfaabi_check_preemption();
    4468                KICK_WATCHDOG;
     69                this.spin++;
    4570        }
    4671}
     
    4873int main(int argc, char* argv[]) {
    4974        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;
    5082        {
     83                globals.prev = timeHiRes();
    5184                worker_t w0 = 0;
    5285                worker_t w1 = 1;
Note: See TracChangeset for help on using the changeset viewer.