Changes in / [54eb1bb3:dd92fe9]
- Files:
-
- 1 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/thierry_delisle_PhD/code/readQ_example/Makefile
r54eb1bb3 rdd92fe9 1 all: gui-proto-pthread gui-proto-fibre gui-proto-cforall 2 3 PRECIOUS: thrdlib/libthrd-pthread.so thrdlib/libthrd-fibre.so thrdlib/libthrd-cforall.so 1 all: gui-proto 4 2 5 3 CXXFLAGS = -fpic -g -O0 -I. 6 4 7 thrdlib/libthrd-%.so: 8 +${MAKE} -C thrdlib libthrd-$*.so 9 10 gui-proto-%: proto-gui/main.o thrdlib/libthrd-%.so Makefile 11 $(CXX) -Lthrdlib -Wl,--rpath,thrdlib -pthread -o $@ $< -lthrd-$* 12 13 CFAINC=${HOME}/local/include/cfa-dev 14 CFALIB=${HOME}/local/lib/cfa-dev/x64-debug 15 CFAFLAGS=-z execstack -ftls-model=initial-exec -L${CFALIB} -Wl,-rpath,${CFALIB} 16 17 gui-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 5 gui-proto: proto-gui/main.o thrdlib/thread.o 6 $(CXX) -pthread -ldl -o ${@} ${^} -ftls-model=initial-exec -
doc/theses/thierry_delisle_PhD/code/readQ_example/proto-gui/main.cpp
r54eb1bb3 rdd92fe9 11 11 #include <getopt.h> 12 12 using 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" ))); 13 36 14 37 //-------------------- … … 125 148 } 126 149 127 typedef uint64_t __wyhash64_state_t;128 static 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 138 150 void Simulator( thread_t self ) { 139 151 for(unsigned i = 0; i < nproduce; i++) { … … 144 156 } 145 157 146 __wyhash64_state_t state = 0;147 148 158 // Write the frame information 149 159 frame.number = i; 150 160 for( unsigned x = 0; x < fsize; x++ ) { 151 frame.data[x] = __wyhash64(state);161 frame.data[x] = i; 152 162 } 153 163 std::cout << "Simulated " << i << std::endl; … … 177 187 178 188 std::cout << "Rendered " << i << std::endl; 179 //assert(total == i * fsize);189 assert(total == i * fsize); 180 190 181 191 // Release … … 191 201 int main(int argc, char * argv[]) { 192 202 nframes = 3; 193 fsize = 3840 * 2160 * 4 * 4;203 fsize = 1000; 194 204 nproduce = 60; 205 206 const char * framework; 195 207 196 208 for(;;) { … … 210 222 // Exit Case 211 223 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]; 212 231 goto run; 213 232 case 'b': … … 242 261 std::cerr << opt << std::endl; 243 262 usage: 244 std::cerr << "Usage: " << argv[0] << " [options] " << std::endl;263 std::cerr << "Usage: " << argv[0] << " [options] framework" << std::endl; 245 264 std::cerr << std::endl; 246 265 std::cerr << " -b, --buff=COUNT Number of frames to buffer" << std::endl; … … 251 270 } 252 271 run: 272 assert( framework ); 273 253 274 frames.reset(new Frame[nframes]); 254 275 for(unsigned i = 0; i < nframes; i++) { … … 259 280 std::cout << "(Buffering " << nframes << ")" << std::endl; 260 281 261 thrdlib::init( 2 );282 thrdlib::init( framework, 2 ); 262 283 263 284 thread_t stats = thrdlib::create( Stats ); -
doc/theses/thierry_delisle_PhD/code/readQ_example/thrdlib/Makefile
r54eb1bb3 rdd92fe9 1 all: fibre.so libthrd-pthread.so.so cforall.so1 all: fibre.so pthread.so cforall.so 2 2 3 3 clean: 4 rm -rf fibre.so libthrd-pthread.so.so cforall.so4 rm -rf fibre.so pthread.so 5 5 6 6 CXXFLAGS=-Wall -Wextra -O3 -g -fpic -std=c++17 -pthread -ftls-model=initial-exec 7 7 8 libthrd-pthread.so: thread.cpp thread.hpp Makefile9 $(CXX) $(CXXFLAGS) -shared -o $ @ $< -DWITH_PTHREADS8 pthread.so: pthread.cpp Makefile 9 $(CXX) $(CXXFLAGS) -shared -o ${@} ${<} 10 10 11 libthrd-fibre.so: thread.cpp thread.hpp Makefile12 $(CXX) $(CXXFLAGS) -shared -o $ @ $< -DWITH_LIBFIBRE-lfibre11 fibre.so: fibre.cpp Makefile 12 $(CXX) $(CXXFLAGS) -shared -o ${@} ${<} -lfibre 13 13 14 14 CFAINC=${HOME}/local/include/cfa-dev … … 16 16 CFAFLAGS=-z execstack -I${CFAINC} -I${CFAINC}/concurrency -L${CFALIB} -Wl,-rpath,${CFALIB} 17 17 18 libthrd-cforall.so: thread.cpp thread.hpp Makefile19 $(CXX) $(CXXFLAGS) $(CFAFLAGS) -shared -o $ @ $< -DWITH_CFORALL -Wl,--push-state,--no-as-needed -lcfathread -lcfa -ldl -lm -Wl,--pop-state18 cforall.so: cforall.cpp Makefile 19 $(CXX) $(CXXFLAGS) $(CFAFLAGS) -shared -o ${@} ${<} -lcfathread -lcfa -ldl -lm -
doc/theses/thierry_delisle_PhD/code/readQ_example/thrdlib/pthread.hpp
r54eb1bb3 rdd92fe9 1 #pragma once2 3 1 #include <pthread.h> 4 2 #include <errno.h> … … 99 97 // Basic kernel features 100 98 void thrdlib_init( int ) {} 101 void thrdlib_clean( void ) {}102 99 } -
doc/theses/thierry_delisle_PhD/code/readQ_example/thrdlib/thread.cpp
r54eb1bb3 rdd92fe9 1 #if !defined(WITH_PTHREADS) && !defined(WITH_LIBFIBRE) && !defined(WITH_CFORALL) 2 #error must define WITH_PTHREADS, WITH_LIBFIBRE or WITH_CFORALL 3 #endif 1 #include "thread.hpp" 4 2 5 #i fdef WITH_PTHREADS6 #include "pthread.hpp"7 # endif8 #ifdef WITH_LIBFIBRE 9 #include "fibre.hpp" 10 #endif 11 #ifdef WITH_CFORALL 12 #include "cforall.hpp" 13 #endif 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 } 14 12 15 namespace 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(); } 13 #include <iostream> 14 #include <string> 23 15 24 //-------------------- 25 // Basic kernel features 26 void init( int procs ) { thrdlib_init(procs); } 27 void clean( void ) { thrdlib_clean(); } 28 }; 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 } -
doc/theses/thierry_delisle_PhD/code/readQ_example/thrdlib/thread.hpp
r54eb1bb3 rdd92fe9 6 6 //-------------------- 7 7 // 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 ) ; 13 13 14 14 //-------------------- 15 15 // Basic kernel features 16 extern void init( int procs );16 extern void init( const char * name, int procs ); 17 17 extern void clean( void ); 18 18 };
Note: See TracChangeset
for help on using the changeset viewer.