Changeset 26fd986 for benchmark/schedint


Ignore:
Timestamp:
Jan 21, 2020, 6:14:34 PM (5 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
5518719
Parents:
c12869e
Message:

update benchmarks for concurrency paper

Location:
benchmark/schedint
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • benchmark/schedint/JavaThread.java

    rc12869e r26fd986  
    6363                synchronized(m) {
    6464                        s.start();
    65                         while( !Monitor.go ) {
     65                        while( ! Monitor.go ) { // waiter must start first
    6666                                Thread.yield();
    6767                        }
  • benchmark/schedint/cfa1.cfa

    rc12869e r26fd986  
    77
    88volatile int go = 0;
     9
    910condition c;
    1011monitor M {} m1;
     
    1314        signal( c );
    1415}
    15 
    1616void __attribute__((noinline)) wait( M & mutex p1 ) {
    1717        go = 1;
     
    1919                wait( c );
    2020        }
    21         go = 0;
    2221}
    2322
    2423thread T {};
    2524void main( T & ) {
    26         while ( go == 0 ) { yield(); }
     25        while ( go == 0 ) { yield(); } // waiter must start first
    2726        BENCH(
    28                 while ( go == 1 ) { call( m1 ); },
     27                for ( times ) { call( m1 ); },
    2928                result
    3029        )
  • benchmark/schedint/cfa2.cfa

    rc12869e r26fd986  
    77
    88volatile int go = 0;
     9
    910condition c;
    1011monitor M {} m1, m2;
     
    1314        signal( c );
    1415}
    15 
    1616void __attribute__((noinline)) wait( M & mutex p1, M & mutex p2 ) {
    1717        go = 1;
     
    1919                wait( c );
    2020        }
    21         go = 0;
    2221}
    2322
    2423thread T {};
    2524void main( T & ) {
    26         while ( go == 0 ) { yield(); }
     25        while ( go == 0 ) { yield(); } // waiter must start first
    2726        BENCH(
    28                 while ( go == 1 ) { call( m1, m2 ); },
     27                for ( times ) { call( m1, m2 ); },
    2928                result
    3029        )
  • benchmark/schedint/cfa4.cfa

    rc12869e r26fd986  
    44#include <stdio.h>
    55
    6 #include "bench.h"
     6#include "../bench.h"
    77
    88volatile int go = 0;
     9
    910condition c;
    1011monitor M {} m1, m2, m3, m4;
     
    1314        signal( c );
    1415}
    15 
    1616void __attribute__((noinline)) wait( M & mutex p1, M & mutex p2, M & mutex p3, M & mutex p4 ) {
    1717        go = 1;
     
    1919                wait( c );
    2020        }
    21         go = 0;
    2221}
    2322
    2423thread T {};
    2524void main( T & ) {
    26         while ( go == 0 ) { yield(); }
     25        while ( go == 0 ) { yield(); } // waiter must start first
    2726        BENCH(
    28                 while ( go == 1 ) { call( m1, m2, m3, m4 ); },
     27                for ( times ) { call( m1, m2, m3, m4 ); },
    2928                result
    3029        )
  • benchmark/schedint/pthreads.c

    rc12869e r26fd986  
    66volatile int go = 0;
    77
     8pthread_mutex_t m;
    89pthread_cond_t c;
    9 pthread_mutex_t m;
    1010
    1111void __attribute__((noinline)) call() {
    12         pthread_mutex_lock(&m);
    13         pthread_cond_signal(&c);
    14         pthread_mutex_unlock(&m);
     12        pthread_mutex_lock( &m );
     13        pthread_cond_signal( &c );
     14        pthread_mutex_unlock( &m );
    1515}
    1616
    17 int __attribute__((noinline)) wait() {
     17void __attribute__((noinline)) wait() {
    1818        pthread_mutex_lock(&m);
    1919        go = 1;
     20        for ( size_t i = 0; i < times; i++ ) {
     21                pthread_cond_wait( &c, &m );
     22        }
     23        go = 0;
     24        pthread_mutex_unlock( &m );
     25}
     26
     27void * thread_main( __attribute__((unused)) void * arg ) {
     28        while ( go == 0 ) { sched_yield(); } // waiter must start first
     29        // barging for lock acquire => may not execute N times
    2030        BENCH(
    21                 for (size_t i = 0; i < times; i++) {
    22                         pthread_cond_wait(&c, &m);
    23                 },
     31                while ( go == 1 ) { call(); },
    2432                result
    2533        )
    2634        printf( "%g\n", result );
    27         go = 0;
    28         pthread_mutex_unlock(&m);
    29         return 0;
    30 }
    31 
    32 void* thread_main(__attribute__((unused)) void * arg ) {
    33         while(go == 0) { sched_yield(); }
    34         while(go == 1) { call(); }
    3535        return NULL;
    3636}
     
    3939        BENCH_START()
    4040        pthread_t thread;
    41         if (pthread_create(&thread, NULL, thread_main, NULL) < 0) {
     41        if ( pthread_create( &thread, NULL, thread_main, NULL ) < 0 ) {
    4242                perror( "failure" );
    4343                return 1;
    4444        }
    4545        wait();
    46         if (pthread_join( thread, NULL) < 0) {
     46        if ( pthread_join( thread, NULL ) < 0 ) {
    4747                perror( "failure" );
    4848                return 1;
  • benchmark/schedint/rust.rs

    rc12869e r26fd986  
    1818
    1919        let th = thread::spawn( move || {
    20                 while *m2.lock().unwrap() == 0 {
     20                while *m2.lock().unwrap() == 0 { // waiter must start first
    2121                        thread::yield_now();
    2222                }
  • benchmark/schedint/upp.cc

    rc12869e r26fd986  
    1111                cond.signal();
    1212        }
     13        void __attribute__((noinline)) wait() {
     14                go = 1;
     15                for ( size_t i = 0; i < times; i++ ) {
     16                        cond.wait();
     17                }
     18        }
     19} m;
    1320
    14         int __attribute__((noinline)) wait() {
    15                 go = 1;
     21_Task T {
     22        void main() {
     23                while ( go == 0 ) { yield(); } // waiter must start first
    1624                BENCH(
    17                         for (size_t i = 0; i < times; i++) {
    18                                 cond.wait();
     25                        for ( size_t i = 0; i < times; i++ ) {
     26                                m.call();
    1927                        },
    2028                        result
    2129                )
    2230                printf( "%g\n", result );
    23                 go = 0;
    24                 return 0;
    25         }
    26 };
    27 
    28 M m;
    29 
    30 _Task T {
    31         void main() {
    32                 while(go == 0) { yield(); }
    33                 while(go == 1) { m.call(); }
    34 
    3531        }
    3632};
     
    3935        BENCH_START()
    4036        T t;
    41         return m.wait();
     37        m.wait();
    4238}
    4339
Note: See TracChangeset for help on using the changeset viewer.