Changeset 56ac392


Ignore:
Timestamp:
Apr 21, 2021, 3:02:42 PM (3 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
7711064
Parents:
b374dbc
Message:

Moved single_sem to rq_bench.hpp which was duplicated across multiple fibre benchmarks.

Location:
benchmark/readyQ
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • benchmark/readyQ/cycle.cpp

    rb374dbc r56ac392  
    33#include <libfibre/fibre.h>
    44
    5 class __attribute__((aligned(128))) bench_sem {
    6         Fibre * volatile ptr = nullptr;
    7 public:
    8         inline bool wait() {
    9                 static Fibre * const ready  = reinterpret_cast<Fibre * const>(1ull);
    10                 for(;;) {
    11                         Fibre * expected = this->ptr;
    12                         if(expected == ready) {
    13                                 if(__atomic_compare_exchange_n(&this->ptr, &expected, nullptr, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    14                                         return false;
    15                                 }
    16                         }
    17                         else {
    18                                 /* paranoid */ assert( expected == nullptr );
    19                                 if(__atomic_compare_exchange_n(&this->ptr, &expected, fibre_self(), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    20                                         fibre_park();
    21                                         return true;
    22                                 }
    23                         }
    24 
    25                 }
    26         }
    27 
    28         inline bool post() {
    29                 static Fibre * const ready  = reinterpret_cast<Fibre * const>(1ull);
    30                 for(;;) {
    31                         Fibre * expected = this->ptr;
    32                         if(expected == ready) return false;
    33                         if(expected == nullptr) {
    34                                 if(__atomic_compare_exchange_n(&this->ptr, &expected, ready, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    35                                         return false;
    36                                 }
    37                         }
    38                         else {
    39                                 if(__atomic_compare_exchange_n(&this->ptr, &expected, nullptr, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    40                                         fibre_unpark( expected );
    41                                         return true;
    42                                 }
    43                         }
    44                 }
    45         }
    46 };
    475struct Partner {
    486        unsigned long long count  = 0;
  • benchmark/readyQ/locality.cpp

    rb374dbc r56ac392  
    99        uint64_t dmigs = 0;
    1010        uint64_t gmigs = 0;
    11 };
    12 
    13 class __attribute__((aligned(128))) bench_sem {
    14         Fibre * volatile ptr = nullptr;
    15 public:
    16         inline bool wait() {
    17                 static Fibre * const ready  = reinterpret_cast<Fibre * const>(1ull);
    18                 for(;;) {
    19                         Fibre * expected = this->ptr;
    20                         if(expected == ready) {
    21                                 if(__atomic_compare_exchange_n(&this->ptr, &expected, nullptr, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    22                                         return false;
    23                                 }
    24                         }
    25                         else {
    26                                 /* paranoid */ assert( expected == nullptr );
    27                                 if(__atomic_compare_exchange_n(&this->ptr, &expected, fibre_self(), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    28                                         fibre_park();
    29                                         return true;
    30                                 }
    31                         }
    32 
    33                 }
    34         }
    35 
    36         inline bool post() {
    37                 static Fibre * const ready  = reinterpret_cast<Fibre * const>(1ull);
    38                 for(;;) {
    39                         Fibre * expected = this->ptr;
    40                         if(expected == ready) return false;
    41                         if(expected == nullptr) {
    42                                 if(__atomic_compare_exchange_n(&this->ptr, &expected, ready, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    43                                         return false;
    44                                 }
    45                         }
    46                         else {
    47                                 if(__atomic_compare_exchange_n(&this->ptr, &expected, nullptr, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    48                                         fibre_unpark( expected );
    49                                         return true;
    50                                 }
    51                         }
    52                 }
    53         }
    5411};
    5512
  • benchmark/readyQ/rq_bench.hpp

    rb374dbc r56ac392  
    66#include <time.h>                                                                               // timespec
    77#include <sys/time.h>                                                                   // timeval
     8
     9typedef __uint128_t __lehmer64_state_t;
     10static inline uint64_t __lehmer64( __lehmer64_state_t & state ) {
     11        state *= 0xda942042e4dd58b5;
     12        return state >> 64;
     13}
    814
    915enum { TIMEGRAN = 1000000000LL };                                       // nanosecond granularity, except for timeval
     
    7581}
    7682
     83class Fibre;
     84int fibre_park();
     85int fibre_unpark( Fibre * );
     86Fibre * fibre_self();
     87
     88class __attribute__((aligned(128))) bench_sem {
     89        Fibre * volatile ptr = nullptr;
     90public:
     91        inline bool wait() {
     92                static Fibre * const ready  = reinterpret_cast<Fibre *>(1ull);
     93                for(;;) {
     94                        Fibre * expected = this->ptr;
     95                        if(expected == ready) {
     96                                if(__atomic_compare_exchange_n(&this->ptr, &expected, nullptr, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
     97                                        return false;
     98                                }
     99                        }
     100                        else {
     101                                /* paranoid */ assert( expected == nullptr );
     102                                if(__atomic_compare_exchange_n(&this->ptr, &expected, fibre_self(), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
     103                                        fibre_park();
     104                                        return true;
     105                                }
     106                        }
     107
     108                }
     109        }
     110
     111        inline bool post() {
     112                static Fibre * const ready  = reinterpret_cast<Fibre *>(1ull);
     113                for(;;) {
     114                        Fibre * expected = this->ptr;
     115                        if(expected == ready) return false;
     116                        if(expected == nullptr) {
     117                                if(__atomic_compare_exchange_n(&this->ptr, &expected, ready, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
     118                                        return false;
     119                                }
     120                        }
     121                        else {
     122                                if(__atomic_compare_exchange_n(&this->ptr, &expected, nullptr, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
     123                                        fibre_unpark( expected );
     124                                        return true;
     125                                }
     126                        }
     127                }
     128        }
     129};
     130
    77131// ==========================================================================================
    78132#include <cstdlib>
     
    188242                this->help       = help;
    189243                this->variable   = reinterpret_cast<void*>(&variable);
    190                 this->parse_fun  = reinterpret_cast<bool (*)(const char *, void * )>(static_cast<bool (*)(const char *, T & )>(parse));
     244                #pragma GCC diagnostic push
     245                #pragma GCC diagnostic ignored "-Wcast-function-type"
     246                                this->parse_fun  = reinterpret_cast<bool (*)(const char *, void * )>(static_cast<bool (*)(const char *, T & )>(parse));
     247                #pragma GCC diagnostic pop
    191248        }
    192249
     
    197254                this->help       = help;
    198255                this->variable   = reinterpret_cast<void*>(&variable);
    199                 this->parse_fun  = reinterpret_cast<bool (*)(const char *, void * )>(parse);
     256                #pragma GCC diagnostic push
     257                #pragma GCC diagnostic ignored "-Wcast-function-type"
     258                        this->parse_fun  = reinterpret_cast<bool (*)(const char *, void * )>(parse);
     259                #pragma GCC diagnostic pop
    200260        }
    201261};
Note: See TracChangeset for help on using the changeset viewer.