Changeset 72b1800 for doc


Ignore:
Timestamp:
Dec 15, 2020, 12:51:15 PM (9 months ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
arm-eh, jacob/cs343-translation, master, new-ast-unique-expr
Children:
2dd0689, 54eb1bb3, 72a3aff
Parents:
90ecade
Message:

Some previous in progress work.
Commited only so it stops showing in my git status.

Location:
doc/theses/thierry_delisle_PhD/code/readQ_example
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/thierry_delisle_PhD/code/readQ_example/Makefile

    r90ecade r72b1800  
    1 all: gui-proto
     1all: gui-proto-pthread gui-proto-fibre gui-proto-cforall
     2
     3PRECIOUS: thrdlib/libthrd-pthread.so thrdlib/libthrd-fibre.so thrdlib/libthrd-cforall.so
    24
    35CXXFLAGS = -fpic -g -O0 -I.
    46
    5 gui-proto: proto-gui/main.o thrdlib/thread.o
    6         $(CXX) -pthread -ldl -o ${@} ${^} -ftls-model=initial-exec
     7thrdlib/libthrd-%.so:
     8        +${MAKE} -C thrdlib libthrd-$*.so
     9
     10gui-proto-%: proto-gui/main.o thrdlib/libthrd-%.so Makefile
     11        $(CXX) -Lthrdlib -Wl,--rpath,thrdlib -pthread -o $@ $< -lthrd-$*
     12
     13CFAINC=${HOME}/local/include/cfa-dev
     14CFALIB=${HOME}/local/lib/cfa-dev/x64-debug
     15CFAFLAGS=-z execstack -ftls-model=initial-exec -L${CFALIB} -Wl,-rpath,${CFALIB}
     16
     17gui-proto-cforall: proto-gui/main.o thrdlib/libthrd-cforall.so Makefile
     18        $(CXX) -Lthrdlib -Wl,--rpath,thrdlib ${CFAFLAGS} -pthread -o $@ $< -lthrd-cforall -Wl,--push-state,--no-as-needed -lcfathread -lcfa -ldl -lm -Wl,--pop-state
  • doc/theses/thierry_delisle_PhD/code/readQ_example/proto-gui/main.cpp

    r90ecade r72b1800  
    1111#include <getopt.h>
    1212using thrdlib::thread_t;
    13 
    14 
    15 extern __attribute__((aligned(128))) thread_local struct {
    16         void * volatile this_thread;
    17         void * volatile this_processor;
    18         void * volatile this_stats;
    19 
    20         struct {
    21                 volatile unsigned short disable_count;
    22                 volatile bool enabled;
    23                 volatile bool in_progress;
    24         } preemption_state;
    25 
    26         #if defined(__SIZEOF_INT128__)
    27                 __uint128_t rand_seed;
    28         #else
    29                 uint64_t rand_seed;
    30         #endif
    31         struct {
    32                 uint64_t fwd_seed;
    33                 uint64_t bck_seed;
    34         } ready_rng;
    35 } kernelTLS __attribute__ ((tls_model ( "initial-exec" )));
    3613
    3714//--------------------
     
    148125}
    149126
     127typedef uint64_t __wyhash64_state_t;
     128static inline uint64_t __wyhash64( __wyhash64_state_t & state ) {
     129        state += 0x60bee2bee120fc15;
     130        __uint128_t tmp;
     131        tmp = (__uint128_t) state * 0xa3b195354a39b70d;
     132        uint64_t m1 = (tmp >> 64) ^ tmp;
     133        tmp = (__uint128_t)m1 * 0x1b03738712fad5c9;
     134        uint64_t m2 = (tmp >> 64) ^ tmp;
     135        return m2;
     136}
     137
    150138void Simulator( thread_t self ) {
    151139        for(unsigned i = 0; i < nproduce; i++) {
     
    156144                }
    157145
     146                __wyhash64_state_t state = 0;
     147
    158148                // Write the frame information
    159149                frame.number = i;
    160150                for( unsigned x = 0; x < fsize; x++ ) {
    161                         frame.data[x] = i;
     151                        frame.data[x] = __wyhash64(state);
    162152                }
    163153                std::cout << "Simulated " << i << std::endl;
     
    187177
    188178                std::cout << "Rendered " << i << std::endl;
    189                 assert(total == i * fsize);
     179                // assert(total == i * fsize);
    190180
    191181                // Release
     
    201191int main(int argc, char * argv[]) {
    202192        nframes  = 3;
    203         fsize    = 1000;
     193        fsize    = 3840 * 2160 * 4 * 4;
    204194        nproduce = 60;
    205 
    206         const char * framework;
    207195
    208196        for(;;) {
     
    222210                        // Exit Case
    223211                        case -1:
    224                                 /* paranoid */ assert(optind <= argc);
    225                                 if( optind == argc ) {
    226                                         std::cerr << "Must specify a framework" << std::endl;
    227                                         goto usage;
    228 
    229                                 }
    230                                 framework = argv[optind];
    231212                                goto run;
    232213                        case 'b':
     
    261242                                std::cerr << opt << std::endl;
    262243                        usage:
    263                                 std::cerr << "Usage: " << argv[0] << " [options] framework" << std::endl;
     244                                std::cerr << "Usage: " << argv[0] << " [options]" << std::endl;
    264245                                std::cerr << std::endl;
    265246                                std::cerr << "  -b, --buff=COUNT    Number of frames to buffer" << std::endl;
     
    270251        }
    271252        run:
    272         assert( framework );
    273 
    274253        frames.reset(new Frame[nframes]);
    275254        for(unsigned i = 0; i < nframes; i++) {
     
    280259        std::cout << "(Buffering " << nframes << ")" << std::endl;
    281260
    282         thrdlib::init( framework, 2 );
     261        thrdlib::init( 2 );
    283262
    284263        thread_t stats     = thrdlib::create( Stats );
  • doc/theses/thierry_delisle_PhD/code/readQ_example/thrdlib/Makefile

    r90ecade r72b1800  
    1 all: fibre.so pthread.so cforall.so
     1all: fibre.so libthrd-pthread.so.so cforall.so
    22
    33clean:
    4         rm -rf fibre.so pthread.so
     4        rm -rf fibre.so libthrd-pthread.so.so cforall.so
    55
    66CXXFLAGS=-Wall -Wextra -O3 -g -fpic -std=c++17 -pthread -ftls-model=initial-exec
    77
    8 pthread.so: pthread.cpp Makefile
    9         $(CXX) $(CXXFLAGS) -shared -o ${@} ${<}
     8libthrd-pthread.so: thread.cpp thread.hpp Makefile
     9        $(CXX) $(CXXFLAGS) -shared -o $@ $< -DWITH_PTHREADS
    1010
    11 fibre.so: fibre.cpp Makefile
    12         $(CXX) $(CXXFLAGS) -shared -o ${@} ${<} -lfibre
     11libthrd-fibre.so: thread.cpp thread.hpp Makefile
     12        $(CXX) $(CXXFLAGS) -shared -o $@ $< -DWITH_LIBFIBRE -lfibre
    1313
    1414CFAINC=${HOME}/local/include/cfa-dev
     
    1616CFAFLAGS=-z execstack -I${CFAINC} -I${CFAINC}/concurrency -L${CFALIB} -Wl,-rpath,${CFALIB}
    1717
    18 cforall.so: cforall.cpp Makefile
    19         $(CXX) $(CXXFLAGS) $(CFAFLAGS) -shared -o ${@} ${<} -lcfathread -lcfa -ldl -lm
     18libthrd-cforall.so: thread.cpp thread.hpp Makefile
     19        $(CXX) $(CXXFLAGS) $(CFAFLAGS) -shared -o $@ $< -DWITH_CFORALL -Wl,--push-state,--no-as-needed -lcfathread -lcfa -ldl -lm -Wl,--pop-state
  • doc/theses/thierry_delisle_PhD/code/readQ_example/thrdlib/pthread.hpp

    r90ecade r72b1800  
     1#pragma once
     2
    13#include <pthread.h>
    24#include <errno.h>
     
    9799        // Basic kernel features
    98100        void thrdlib_init( int ) {}
     101        void thrdlib_clean( void ) {}
    99102}
  • doc/theses/thierry_delisle_PhD/code/readQ_example/thrdlib/thread.cpp

    r90ecade r72b1800  
    1 #include "thread.hpp"
     1#if !defined(WITH_PTHREADS) && !defined(WITH_LIBFIBRE) && !defined(WITH_CFORALL)
     2#error must define WITH_PTHREADS, WITH_LIBFIBRE or WITH_CFORALL
     3#endif
    24
    3 #include <cstdarg>                                                                              // va_start, va_end
    4 #include <cstdio>
    5 #include <cstring>                                                                              // strlen
    6 extern "C" {
    7         #include <unistd.h>                                                                             // _exit, getpid
    8         #include <signal.h>
    9         #include <dlfcn.h>                                                                              // dlopen, dlsym
    10         #include <execinfo.h>                                                                   // backtrace, messages
    11 }
     5#ifdef WITH_PTHREADS
     6#include "pthread.hpp"
     7#endif
     8#ifdef WITH_LIBFIBRE
     9#include "fibre.hpp"
     10#endif
     11#ifdef WITH_CFORALL
     12#include "cforall.hpp"
     13#endif
    1214
    13 #include <iostream>
    14 #include <string>
     15namespace thrdlib {
     16        //--------------------
     17        // Basic thread support
     18        void * create( void (*main)( void * ) ) { return (thread_t)thrdlib_create(  (void (*)( thread_t )) main ); }
     19        void join  ( void * handle ) { thrdlib_join  ((thread_t)handle); }
     20        void park  ( void * handle ) { thrdlib_park  ((thread_t)handle); }
     21        void unpark( void * handle ) { thrdlib_unpark((thread_t)handle); }
     22        void yield( void )  { thrdlib_yield(); }
    1523
    16 using thrdlib::thread_t;
    17 
    18 thread_t (*thrdlib::create)( void (*main)( thread_t ) ) = nullptr;
    19 void (*thrdlib::join)( thread_t handle ) = nullptr;
    20 void (*thrdlib::park)( thread_t handle ) = nullptr;
    21 void (*thrdlib::unpark)( thread_t handle ) = nullptr;
    22 void (*thrdlib::yield)( void ) = nullptr;
    23 void (*lib_clean)(void) = nullptr;
    24 
    25 typedef void (*fptr_t)();
    26 static fptr_t open_symbol( void * library, const char * symbol, bool required ) {
    27         void * ptr = dlsym( library, symbol );
    28 
    29         const char * error = dlerror();
    30         if ( required && error ) {
    31                 std::cerr << "Fetching symbol '" << symbol << "' failed with error '" << error << "'\n";
    32                 std::abort();
    33         }
    34 
    35         return (fptr_t)ptr;
    36 }
    37 
    38 //--------------------
    39 // Basic kernel features
    40 void thrdlib::init( const char * name, int procs ) {
    41         std::string file = __FILE__;
    42         std::size_t found = file.find_last_of("/");
    43         std::string libname = file.substr(0,found+1) + name + ".so";
    44 
    45         std::cout << "Use framework " << name << "(" << libname << ")\n";
    46 
    47         void * library = dlopen( libname.c_str(), RTLD_NOW );
    48         if ( const char * error = dlerror() ) {
    49                 std::cerr << "Could not open library '" << libname << "' from name '" << name <<"'\n";
    50                 std::cerr << "Error was : '" << error << "'\n";
    51                 std::abort();
    52         }
    53 
    54         void (*lib_init)( int ) = (void (*)( int ))open_symbol( library, "thrdlib_init", false );
    55         lib_clean = open_symbol( library, "thrdlib_clean" , false );
    56 
    57         thrdlib::create = (typeof(thrdlib::create))open_symbol( library, "thrdlib_create", true  );
    58         thrdlib::join   = (typeof(thrdlib::join  ))open_symbol( library, "thrdlib_join"  , true  );
    59         thrdlib::park   = (typeof(thrdlib::park  ))open_symbol( library, "thrdlib_park"  , true  );
    60         thrdlib::unpark = (typeof(thrdlib::unpark))open_symbol( library, "thrdlib_unpark", true  );
    61         thrdlib::yield  = (typeof(thrdlib::yield ))open_symbol( library, "thrdlib_yield" , true  );
    62 
    63         lib_init( procs );
    64 }
    65 
    66 void thrdlib::clean( void ) {
    67         if(lib_clean) lib_clean();
    68 }
     24        //--------------------
     25        // Basic kernel features
     26        void init( int procs ) { thrdlib_init(procs); }
     27        void clean( void ) { thrdlib_clean(); }
     28};
  • doc/theses/thierry_delisle_PhD/code/readQ_example/thrdlib/thread.hpp

    r90ecade r72b1800  
    66        //--------------------
    77        // Basic thread support
    8         extern thread_t (*create)( void (*main)( thread_t ) );
    9         extern void (*join)( thread_t handle );
    10         extern void (*park)( thread_t handle );
    11         extern void (*unpark)( thread_t handle );
    12         extern void (*yield)( void ) ;
     8        extern thread_t create( void (*main)( thread_t ) );
     9        extern void join( thread_t handle );
     10        extern void park( thread_t handle );
     11        extern void unpark( thread_t handle );
     12        extern void yield( void ) ;
    1313
    1414        //--------------------
    1515        // Basic kernel features
    16         extern void init( const char * name, int procs );
     16        extern void init( int procs );
    1717        extern void clean( void );
    1818};
Note: See TracChangeset for help on using the changeset viewer.