source: tests/io/away_fair.cfa @ e71e94a

ADTast-experimentalenumpthread-emulationqualifiedEnum
Last change on this file since e71e94a was d9d8b9f, checked in by Thierry Delisle <tdelisle@…>, 3 years ago

Away_fair no longer uses private io header

  • Property mode set to 100644
File size: 2.2 KB
RevLine 
[362f760]1//
2// Cforall Version 1.0.0 Copyright (C) 2022 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// away_fair.cfa -- Test that spinning doesn't cause submissions to get stuck.
8//                  This test should work without io_uring but isn't very useful without
9//
10// Author           : Thierry Delisle
11// Created On       : Wed Mar 2 12:56:51 2022
12// Last Modified By :
13// Last Modified On :
14// Update Count     :
15//
16
17#include <bits/defs.hfa>
18#include <fstream.hfa>
19#include <kernel.hfa>
20#include <thread.hfa>
21#include <iofwd.hfa>
22
23Duration default_preemption() {
24        return 0;
25}
26
27enum { TIMES = 1000 };
28
29volatile unsigned counter = 0;
30
31// ----- Spinner -----
32// spins trying to prevent other threads from getting to this processor
33thread Spinner {};
34void ^?{}(Spinner &mutex ) {}
35void main(Spinner &) {
36        unsigned last = 0;
37        for() {
38                unsigned curr = __atomic_load_n(&counter, __ATOMIC_SEQ_CST);
39
40                if(curr >= TIMES) return;
41
42                if(last == curr) {
43                        Pause();
44                        continue;
45                }
46
47                last = curr;
48                yield();
49        }
50}
51
[d9d8b9f]52// ----- Submitter -----
[362f760]53// try to submit io but yield so that it's likely we are moved to the slow path
54thread Submitter {};
55void ^?{}(Submitter &mutex ) {}
[496f92ed]56void main(Submitter & this) {
[362f760]57        for(TIMES) {
58                #if CFA_HAVE_LINUX_IO_URING_H
59                        io_future_t f;
60                        struct io_uring_sqe * sqe;
61                        __u32 idx;
62                        struct $io_context * ctx = cfa_io_allocate(&sqe, &idx, 1);
63
64                        zero_sqe(sqe);
65                        sqe->opcode = IORING_OP_NOP;
66                        sqe->user_data = (uintptr_t)&f;
67                #endif
68
[496f92ed]69                yield( prng( this, 15 ) );
[362f760]70
71                #if CFA_HAVE_LINUX_IO_URING_H
72                        // Submit everything
73                        asm volatile("": : :"memory");
74                        cfa_io_submit( ctx, &idx, 1, false );
75                #endif
76
77                unsigned i = __atomic_add_fetch( &counter, 1, __ATOMIC_SEQ_CST );
78                if(0 == (i % 100)) sout | i;
79
80                #if CFA_HAVE_LINUX_IO_URING_H
81                        wait( f );
82                #endif
83        }
84}
85
86// ----- Yielder -----
87// Add some chaos into the mix
88thread Yielder {};
89void ^?{}(Yielder &mutex ) {}
90void main(Yielder&) {
91        while(TIMES > __atomic_load_n(&counter, __ATOMIC_SEQ_CST)) {
92                yield();
93        }
94}
95
96
97int main() {
98        processor p;
99        sout | "starting";
100        {
101                Yielder y;
102                Spinner s;
103                Submitter io;
104        }
105        sout | "done";
106}
Note: See TracBrowser for help on using the repository browser.