From 06bfaa124940d95e8b981d926ef868af93796c40 Mon Sep 17 00:00:00 2001 From: Jay D Dee Date: Mon, 21 Dec 2020 13:25:33 -0500 Subject: [PATCH] v3.15.5 --- RELEASE_NOTES | 5 +++++ algo-gate-api.h | 2 +- algo/hodl/hodl-gate.c | 7 ++++--- algo/nist5/zr5.c | 4 ++-- algo/quark/hmq1725-4way.c | 2 +- algo/yespower/yespower-blake2b.c | 11 ++++++++++- algo/yespower/yespower-opt.c | 12 ++++++++++- configure | 20 +++++++++---------- configure.ac | 2 +- cpu-miner.c | 34 +++++++++++++++++--------------- miner.h | 3 ++- util.c | 3 ++- 12 files changed, 67 insertions(+), 38 deletions(-) diff --git a/RELEASE_NOTES b/RELEASE_NOTES index ef8fac2..1e2f27a 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -65,6 +65,11 @@ If not what makes it happen or not happen? Change Log ---------- +v3.15.5 + +Fix stratum jobs lost if 2 jobs received in less than one second. + + v3.15.4 Fixed yescryptr16 broken in v3.15.3. diff --git a/algo-gate-api.h b/algo-gate-api.h index af29ecb..c578f85 100644 --- a/algo-gate-api.h +++ b/algo-gate-api.h @@ -162,7 +162,7 @@ bool ( *ready_to_mine ) ( struct work*, struct stratum_ctx*, int ); bool ( *do_this_thread ) ( int ); // After do_this_thread -void ( *resync_threads ) ( struct work* ); +void ( *resync_threads ) ( int, struct work* ); // No longer needed json_t* (*longpoll_rpc_call) ( CURL*, int*, char* ); diff --git a/algo/hodl/hodl-gate.c b/algo/hodl/hodl-gate.c index 2618309..ca94fd3 100644 --- a/algo/hodl/hodl-gate.c +++ b/algo/hodl/hodl-gate.c @@ -99,13 +99,13 @@ void hodl_build_block_header( struct work* g_work, uint32_t version, // called only by thread 0, saves a backup of g_work void hodl_get_new_work( struct work* work, struct work* g_work) { - pthread_rwlock_rdlock( &g_work_lock ); +// pthread_rwlock_rdlock( &g_work_lock ); work_free( &hodl_work ); work_copy( &hodl_work, g_work ); hodl_work.data[ algo_gate.nonce_index ] = ( clock() + rand() ) % 9999; - pthread_rwlock_unlock( &g_work_lock ); +// pthread_rwlock_unlock( &g_work_lock ); } json_t *hodl_longpoll_rpc_call( CURL *curl, int *err, char* lp_url ) @@ -125,7 +125,7 @@ json_t *hodl_longpoll_rpc_call( CURL *curl, int *err, char* lp_url ) } // called by every thread, copies the backup to each thread's work. -void hodl_resync_threads( struct work* work ) +void hodl_resync_threads( int thr_id, struct work* work ) { int nonce_index = algo_gate.nonce_index; pthread_barrier_wait( &hodl_barrier ); @@ -135,6 +135,7 @@ void hodl_resync_threads( struct work* work ) work_copy( work, &hodl_work ); } work->data[ nonce_index ] = swab32( hodl_work.data[ nonce_index ] ); + work_restart[thr_id].restart = 0; } bool hodl_do_this_thread( int thr_id ) diff --git a/algo/nist5/zr5.c b/algo/nist5/zr5.c index 6152091..da1090f 100644 --- a/algo/nist5/zr5.c +++ b/algo/nist5/zr5.c @@ -156,7 +156,7 @@ int scanhash_zr5( struct work *work, uint32_t max_nonce, void zr5_get_new_work( struct work* work, struct work* g_work, int thr_id, uint32_t* end_nonce_ptr ) { - pthread_rwlock_rdlock( &g_work_lock ); +// pthread_rwlock_rdlock( &g_work_lock ); // ignore POK in first word const int wkcmp_sz = 72; // (19-1) * sizeof(uint32_t) @@ -174,7 +174,7 @@ void zr5_get_new_work( struct work* work, struct work* g_work, int thr_id, else ++(*nonceptr); - pthread_rwlock_unlock( &g_work_lock ); +// pthread_rwlock_unlock( &g_work_lock ); } void zr5_display_pok( struct work* work ) diff --git a/algo/quark/hmq1725-4way.c b/algo/quark/hmq1725-4way.c index e742efa..b9d4626 100644 --- a/algo/quark/hmq1725-4way.c +++ b/algo/quark/hmq1725-4way.c @@ -912,7 +912,7 @@ extern void hmq1725_4way_hash(void *state, const void *input) sph_whirlpool512_full( &ctx.whirlpool, hash2, hash2, 64 ); sph_whirlpool512_full( &ctx.whirlpool, hash3, hash3, 64 ); -// A = fugue serial, B = sha512 prarallel +// A = fugue serial, B = sha512 parallel intrlv_4x64( vhash, hash0, hash1, hash2, hash3, 512 ); diff --git a/algo/yespower/yespower-blake2b.c b/algo/yespower/yespower-blake2b.c index 4f54201..8dd85c4 100644 --- a/algo/yespower/yespower-blake2b.c +++ b/algo/yespower/yespower-blake2b.c @@ -259,15 +259,24 @@ static inline void salsa20_simd_unshuffle(const salsa20_blk_t *Bin, #define WRITE_X(out) \ (out).q[0] = X0; (out).q[1] = X1; (out).q[2] = X2; (out).q[3] = X3; -#ifdef __XOP__ +#if defined(__AVX512VL__) + +#define ARX(out, in1, in2, s) \ + out = _mm_xor_si128(out, _mm_rol_epi32(_mm_add_epi32(in1, in2), s)); + +#elif defined(__XOP__) + #define ARX(out, in1, in2, s) \ out = _mm_xor_si128(out, _mm_roti_epi32(_mm_add_epi32(in1, in2), s)); + #else + #define ARX(out, in1, in2, s) { \ __m128i tmp = _mm_add_epi32(in1, in2); \ out = _mm_xor_si128(out, _mm_slli_epi32(tmp, s)); \ out = _mm_xor_si128(out, _mm_srli_epi32(tmp, 32 - s)); \ } + #endif #define SALSA20_2ROUNDS \ diff --git a/algo/yespower/yespower-opt.c b/algo/yespower/yespower-opt.c index a17cea3..e21e4f1 100644 --- a/algo/yespower/yespower-opt.c +++ b/algo/yespower/yespower-opt.c @@ -165,6 +165,7 @@ static inline void salsa20_simd_unshuffle(const salsa20_blk_t *Bin, } #ifdef __SSE2__ + #define DECL_X \ __m128i X0, X1, X2, X3; #define DECL_Y \ @@ -174,15 +175,24 @@ static inline void salsa20_simd_unshuffle(const salsa20_blk_t *Bin, #define WRITE_X(out) \ (out).q[0] = X0; (out).q[1] = X1; (out).q[2] = X2; (out).q[3] = X3; -#ifdef __XOP__ +#if defined(__AVX512VL__) + +#define ARX(out, in1, in2, s) \ + out = _mm_xor_si128(out, _mm_rol_epi32(_mm_add_epi32(in1, in2), s)); + +#elif defined(__XOP__) + #define ARX(out, in1, in2, s) \ out = _mm_xor_si128(out, _mm_roti_epi32(_mm_add_epi32(in1, in2), s)); + #else + #define ARX(out, in1, in2, s) { \ __m128i tmp = _mm_add_epi32(in1, in2); \ out = _mm_xor_si128(out, _mm_slli_epi32(tmp, s)); \ out = _mm_xor_si128(out, _mm_srli_epi32(tmp, 32 - s)); \ } + #endif #define SALSA20_2ROUNDS \ diff --git a/configure b/configure index d9066d9..80d8d21 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for cpuminer-opt 3.15.4. +# Generated by GNU Autoconf 2.69 for cpuminer-opt 3.15.5. # # # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. @@ -577,8 +577,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='cpuminer-opt' PACKAGE_TARNAME='cpuminer-opt' -PACKAGE_VERSION='3.15.4' -PACKAGE_STRING='cpuminer-opt 3.15.4' +PACKAGE_VERSION='3.15.5' +PACKAGE_STRING='cpuminer-opt 3.15.5' PACKAGE_BUGREPORT='' PACKAGE_URL='' @@ -1332,7 +1332,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures cpuminer-opt 3.15.4 to adapt to many kinds of systems. +\`configure' configures cpuminer-opt 3.15.5 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1404,7 +1404,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of cpuminer-opt 3.15.4:";; + short | recursive ) echo "Configuration of cpuminer-opt 3.15.5:";; esac cat <<\_ACEOF @@ -1509,7 +1509,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -cpuminer-opt configure 3.15.4 +cpuminer-opt configure 3.15.5 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -2012,7 +2012,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by cpuminer-opt $as_me 3.15.4, which was +It was created by cpuminer-opt $as_me 3.15.5, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -2993,7 +2993,7 @@ fi # Define the identity of the package. PACKAGE='cpuminer-opt' - VERSION='3.15.4' + VERSION='3.15.5' cat >>confdefs.h <<_ACEOF @@ -6690,7 +6690,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by cpuminer-opt $as_me 3.15.4, which was +This file was extended by cpuminer-opt $as_me 3.15.5, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -6756,7 +6756,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -cpuminer-opt config.status 3.15.4 +cpuminer-opt config.status 3.15.5 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/configure.ac b/configure.ac index 8f0cc3f..31bdb56 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([cpuminer-opt], [3.15.4]) +AC_INIT([cpuminer-opt], [3.15.5]) AC_PREREQ([2.59c]) AC_CANONICAL_SYSTEM diff --git a/cpu-miner.c b/cpu-miner.c index e459e62..3761313 100644 --- a/cpu-miner.c +++ b/cpu-miner.c @@ -1192,7 +1192,7 @@ static int share_result( int result, struct work *work, sprintf( bres, "B%d", solved_block_count ); stale = work ? work->data[ algo_gate.ntime_index ] != g_work.data[ algo_gate.ntime_index ] : false; - if ( reason ) stale = stale || strstr( reason, "Invalid job id" ); + if ( reason ) stale = stale || strstr( reason, "job" ); if ( stale ) { stale_share_count++; @@ -1956,8 +1956,6 @@ void std_get_new_work( struct work* work, struct work* g_work, int thr_id, uint32_t *nonceptr = work->data + algo_gate.nonce_index; bool force_new_work = false; - pthread_rwlock_rdlock( &g_work_lock ); - if ( have_stratum ) force_new_work = work->job_id ? strtoul( work->job_id, NULL, 16 ) != strtoul( g_work->job_id, NULL, 16 ) @@ -1973,8 +1971,6 @@ void std_get_new_work( struct work* work, struct work* g_work, int thr_id, } else ++(*nonceptr); - - pthread_rwlock_unlock( &g_work_lock ); } bool std_ready_to_mine( struct work* work, struct stratum_ctx* stratum, @@ -1990,13 +1986,14 @@ bool std_ready_to_mine( struct work* work, struct stratum_ctx* stratum, static void stratum_gen_work( struct stratum_ctx *sctx, struct work *g_work ) { - // Safer than testing the job id - bool new_job = *get_stratum_job_ntime() - != g_work->data[ algo_gate.ntime_index ]; + bool new_job; pthread_rwlock_wrlock( &g_work_lock ); pthread_mutex_lock( &sctx->work_lock ); + new_job = sctx->new_job; + sctx->new_job = false; + free( g_work->job_id ); g_work->job_id = strdup( sctx->job.job_id ); g_work->xnonce2_len = sctx->xnonce2_size; @@ -2009,8 +2006,12 @@ static void stratum_gen_work( struct stratum_ctx *sctx, struct work *g_work ) g_work->targetdiff = sctx->job.diff / ( opt_target_factor * opt_diff_factor ); diff_to_hash( g_work->target, g_work->targetdiff ); + // Increment extranonce2 - for ( int t = 0; t < sctx->xnonce2_size && !( ++sctx->job.xnonce2[t] ); t++ ); + for ( int t = 0; + t < sctx->xnonce2_size && !( ++sctx->job.xnonce2[t] ); + t++ ); + g_work_time = time(NULL); restart_threads(); @@ -2032,7 +2033,7 @@ static void stratum_gen_work( struct stratum_ctx *sctx, struct work *g_work ) else if ( last_block_height != sctx->block_height ) applog( LOG_BLUE, "New Block %d, Job %s", sctx->block_height, g_work->job_id ); - else if ( new_job && g_work->job_id ) + else if ( g_work->job_id && new_job ) applog( LOG_BLUE, "New Work: Block %d, Net diff %.5g, Job %s", sctx->block_height, net_diff, g_work->job_id ); else if ( !opt_quiet ) @@ -2240,10 +2241,15 @@ static void *miner_thread( void *userdata ) pthread_rwlock_unlock( &g_work_lock ); } + pthread_rwlock_rdlock( &g_work_lock ); + algo_gate.get_new_work( &work, &g_work, thr_id, &end_nonce ); + work_restart[thr_id].restart = 0; + + pthread_rwlock_unlock( &g_work_lock ); } // do_this_thread - algo_gate.resync_threads( &work ); + algo_gate.resync_threads( thr_id, &work ); if ( unlikely( !algo_gate.ready_to_mine( &work, &stratum, thr_id ) ) ) continue; @@ -2309,7 +2315,6 @@ static void *miner_thread( void *userdata ) // init time if ( firstwork_time == 0 ) firstwork_time = time(NULL); - work_restart[thr_id].restart = 0; hashes_done = 0; gettimeofday( (struct timeval *) &tv_start, NULL ); @@ -2731,7 +2736,6 @@ static void *stratum_thread(void *userdata ) pthread_rwlock_wrlock( &g_work_lock ); g_work_time = 0; pthread_rwlock_unlock( &g_work_lock ); -// restart_threads(); if ( !stratum_connect( &stratum, stratum.url ) || !stratum_subscribe( &stratum ) || !stratum_authorize( &stratum, rpc_user, rpc_pass ) ) @@ -2757,9 +2761,7 @@ static void *stratum_thread(void *userdata ) report_summary_log( ( stratum_diff != stratum.job.diff ) && ( stratum_diff != 0. ) ); - if ( stratum.job.job_id && ( !g_work_time - || ( *get_stratum_job_ntime() - != g_work.data[ algo_gate.ntime_index ] ) ) ) + if ( stratum.new_job ) stratum_gen_work( &stratum, &g_work ); if ( likely( stratum_socket_full( &stratum, opt_timeout ) ) ) diff --git a/miner.h b/miner.h index 626ab09..63f17f0 100644 --- a/miner.h +++ b/miner.h @@ -444,7 +444,8 @@ struct stratum_ctx { struct work work __attribute__ ((aligned (64))); pthread_mutex_t work_lock; - int block_height; + int block_height; + bool new_job; } __attribute__ ((aligned (64))); bool stratum_socket_full(struct stratum_ctx *sctx, int timeout); diff --git a/util.c b/util.c index decd65b..5df1eb9 100644 --- a/util.c +++ b/util.c @@ -2172,7 +2172,8 @@ bool stratum_handle_method(struct stratum_ctx *sctx, const char *s) if (!strcasecmp(method, "mining.notify")) { ret = stratum_notify(sctx, params); - goto out; + sctx->new_job = true; + goto out; } if (!strcasecmp(method, "mining.ping")) { // cgminer 4.7.1+ if (opt_debug) applog(LOG_DEBUG, "Pool ping");