int main(int argc, char **argv) { struct sigaction sig_stop; struct sigaction sig_time; _main = main_init(argc, argv); _log = log_init(); _main->conf = conf_init(argc, argv); _main->work = work_init(); _main->tcp = tcp_init(); _main->node = node_init(); _main->mime = mime_init(); /* Check configuration */ conf_print(); /* Catch SIG INT */ unix_signal(&sig_stop, &sig_time); /* Fork daemon */ unix_fork(log_console(_log)); /* Increase limits */ unix_limits(_main->conf->cores, CONF_EPOLL_MAX_EVENTS); /* Load mime types */ mime_load(); mime_hash(); /* Prepare TCP daemon */ tcp_start(); /* Drop privileges */ unix_dropuid0(); /* Start worker threads */ work_start(); /* Stop worker threads */ work_stop(); /* Stop TCP daemon */ tcp_stop(); mime_free(); node_free(); tcp_free(); work_free(); conf_free(); log_free(_log); main_free(); return 0; }
// called by every thread, copies the backup to each thread's work. void hodl_resync_threads( struct work* work ) { int nonce_index = algo_gate.nonce_index; pthread_barrier_wait( &hodl_barrier ); if ( memcmp( work->data, hodl_work.data, algo_gate.work_cmp_size ) ) { work_free( work ); work_copy( work, &hodl_work ); } work->data[ nonce_index ] = swab32( hodl_work.data[ nonce_index ] ); }
void zr5_init_nonce( struct work* work, struct work* g_work, int thr_id ) { // ignore POK in first word // const int nonce_i = 19; const int wkcmp_sz = 72; // (19-1) * sizeof(uint32_t) uint32_t *nonceptr = algo_gate.get_nonceptr( work->data ); if ( memcmp( &work->data[1], &g_work->data[1], wkcmp_sz ) ) { work_free( work ); work_copy( work, g_work ); *nonceptr = 0xffffffffU / opt_n_threads * thr_id; if ( opt_randomize ) *nonceptr += ( (rand() *4 ) & UINT32_MAX ) / opt_n_threads; } else ++(*nonceptr); }
void std_init_nonceptr ( struct work* work, struct work* g_work, uint32_t **nonceptr, int wkcmp_offset, int wkcmp_sz, int nonce_oft, int thr_id ) { if ( memcmp( &work->data[wkcmp_offset], &g_work->data[wkcmp_offset], wkcmp_sz ) || jsonrpc_2 ? memcmp( ( (uint8_t*) work->data ) + 43, ( (uint8_t*) g_work->data ) + 43, 33 ) : 0 ) { work_free( work ); work_copy( work, g_work ); *nonceptr = (uint32_t*)( ( (char*)work->data ) + nonce_oft ); *nonceptr[0] = 0xffffffffU / opt_n_threads * thr_id; if ( opt_randomize ) *nonceptr[0] += ( (rand() *4 ) & UINT32_MAX ) / opt_n_threads; } else ++(*nonceptr[0]); }
void zr5_get_new_work( struct work* work, struct work* g_work, int thr_id, uint32_t* end_nonce_ptr, bool clean_job ) { // ignore POK in first word // const int nonce_i = 19; const int wkcmp_sz = 72; // (19-1) * sizeof(uint32_t) uint32_t *nonceptr = algo_gate.get_nonceptr( work->data ); if ( memcmp( &work->data[1], &g_work->data[1], wkcmp_sz ) && ( clean_job || ( *nonceptr >= *end_nonce_ptr ) ) ) { work_free( work ); work_copy( work, g_work ); *nonceptr = ( 0xffffffffU / opt_n_threads ) * thr_id; if ( opt_randomize ) *nonceptr += ( (rand() *4 ) & UINT32_MAX ) / opt_n_threads; *end_nonce_ptr = ( 0xffffffffU / opt_n_threads ) * (thr_id+1) - 0x20; } else ++(*nonceptr); }
// called only by thread 0, saves a backup of g_work void hodl_get_new_work( struct work* work, struct work* g_work) { work_free( &hodl_work ); work_copy( &hodl_work, g_work ); hodl_work.data[ algo_gate.nonce_index ] = ( clock() + rand() ) % 9999; }