Browse Source
Blake256: squashed commit... Squashed commit of the following: commit c370208bc92ef16557f66e5391faf2b1ad47726f Author: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Wed Sep 3 13:53:01 2014 +0200 hashlog: prepare store of scanned range commit e2cf49a5e956f03deafd266d1a0dd087a2041c99 Author: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Wed Sep 3 12:54:13 2014 +0200 stratum: store server time offset in context commitmaster 1.4-tpruvot1a4391d7ff
Author: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Tue Sep 2 12:40:52 2014 +0200 hashlog: prevent double computing on jobs already done commit049e577301
Author: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Wed Sep 3 09:49:14 2014 +0200 tmp blake log commit43d3e93e1a
Author: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Wed Sep 3 09:29:51 2014 +0200 blake: set a max throughput commit7e595a36ea
Author: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Tue Sep 2 21:13:37 2014 +0200 blake: cleanup, remove d_hash buf, not in a chain host: only bencode if gpu hash was found commitde80c7e9d1
Author: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Tue Sep 2 12:40:44 2014 +0200 blake: remove unused parameter and fix index in d_hash that reduce the speed to 92MH/s but the next commit give us 30 more so, todo: merge the whole checkhash proc in gpu_hash and remove this d_hash buffer... commit2d42ae6de5
Author: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Tue Sep 2 05:09:31 2014 +0200 stratum: handle a small cache of submitted jobs Prevent to send duplicated shares on some pools like hashharder.. This cache keeps submitted job/nounces of the last 15 minutes so, remove exit on repeated duplicate shares, the submitted cache now handles this problem. Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com> commit1b8c3c12fa
Author: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Tue Sep 2 03:38:57 2014 +0200 debug: a new boolean to log or not json rpc data commit1f99aae0ff
Author: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Mon Sep 1 18:49:23 2014 +0200 exit on repeated duplicate shares (to enhance) create a new function proper_exit() to do common stuff on exit... commit530732458a
Author: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Mon Sep 1 12:22:51 2014 +0200 blake: use a constant for threads, reduce mallocated d_hash size and clean a bit more... commit0aeac878ef
Author: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Mon Sep 1 06:12:55 2014 +0200 blake: tune up and cleanup, ~100 MH/s on a normal 750Ti tested on linux and windows (x86 binary)... but there is a high number of duplicated shares... weird commit4a52d0553b
Author: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Mon Sep 1 10:22:32 2014 +0200 debug: show json methods, hide hash/target if ok commit1fb9becc1f
Author: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Mon Sep 1 08:44:19 2014 +0200 cpu-miner: sort algos by name, show reject reason commitbfe96c49b0
Author: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Mon Aug 25 11:21:06 2014 +0200 release 1.4, update README... commitc17d11e377
Author: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Sun Aug 31 08:57:48 2014 +0200 add "blake" 256, 14 rounds (for NEOS blake, not BlakeCoin) also remove "missing" file, its old and not compatible with ubuntu 14.04 to test on windows blake: clean and optimize Release v1.4 with blake (NEOS)
Tanguy Pruvot
10 years ago
16 changed files with 984 additions and 482 deletions
@ -0,0 +1,351 @@
@@ -0,0 +1,351 @@
|
||||
/** |
||||
* Blake-256 Cuda Kernel (Tested on SM 5.0) |
||||
* |
||||
* Tanguy Pruvot - Aug. 2014 |
||||
*/ |
||||
|
||||
#include "miner.h" |
||||
|
||||
extern "C" { |
||||
#include "sph/sph_blake.h" |
||||
#include <stdint.h> |
||||
#include <memory.h> |
||||
} |
||||
|
||||
/* threads per block */ |
||||
#define TPB 128 |
||||
|
||||
/* hash by cpu with blake 256 */ |
||||
extern "C" void blake32hash(void *output, const void *input) |
||||
{ |
||||
unsigned char hash[64]; |
||||
sph_blake256_context ctx; |
||||
sph_blake256_init(&ctx); |
||||
sph_blake256(&ctx, input, 80); |
||||
sph_blake256_close(&ctx, hash); |
||||
memcpy(output, hash, 32); |
||||
} |
||||
|
||||
#include "cuda_helper.h" |
||||
|
||||
// in cpu-miner.c |
||||
extern bool opt_n_threads; |
||||
extern bool opt_benchmark; |
||||
extern int device_map[8]; |
||||
|
||||
extern cudaError_t MyStreamSynchronize(cudaStream_t stream, int situation, int thr_id); |
||||
|
||||
__constant__ |
||||
static uint32_t __align__(32) c_PaddedMessage80[32]; // padded message (80 bytes + padding) |
||||
|
||||
__constant__ |
||||
static uint32_t __align__(32) c_Target[8]; |
||||
|
||||
#define MAXU 0xffffffffU |
||||
|
||||
static uint32_t *d_resNounce[8]; |
||||
static uint32_t *h_resNounce[8]; |
||||
|
||||
__constant__ |
||||
#ifdef WIN32 |
||||
/* what the fuck ! */ |
||||
static uint8_t c_sigma[16][16]; |
||||
const uint8_t host_sigma[16][16] = |
||||
#else |
||||
/* prefer uint32_t to prevent size conversions = speed +5/10 % */ |
||||
static uint32_t __align__(32) c_sigma[16][16]; |
||||
const uint32_t host_sigma[16][16] |
||||
#endif |
||||
= { |
||||
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, |
||||
{14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 }, |
||||
{11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 }, |
||||
{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 }, |
||||
{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 }, |
||||
{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 }, |
||||
{12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 }, |
||||
{13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 }, |
||||
{ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 }, |
||||
{10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 }, |
||||
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, |
||||
{14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 }, |
||||
{11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 }, |
||||
{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 }, |
||||
{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 }, |
||||
{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 } |
||||
}; |
||||
|
||||
__device__ __constant__ |
||||
static const uint32_t __align__(32) c_IV256[8] = { |
||||
SPH_C32(0x6A09E667), SPH_C32(0xBB67AE85), |
||||
SPH_C32(0x3C6EF372), SPH_C32(0xA54FF53A), |
||||
SPH_C32(0x510E527F), SPH_C32(0x9B05688C), |
||||
SPH_C32(0x1F83D9AB), SPH_C32(0x5BE0CD19) |
||||
}; |
||||
|
||||
__device__ __constant__ |
||||
static const uint32_t __align__(32) c_u256[16] = { |
||||
SPH_C32(0x243F6A88), SPH_C32(0x85A308D3), |
||||
SPH_C32(0x13198A2E), SPH_C32(0x03707344), |
||||
SPH_C32(0xA4093822), SPH_C32(0x299F31D0), |
||||
SPH_C32(0x082EFA98), SPH_C32(0xEC4E6C89), |
||||
SPH_C32(0x452821E6), SPH_C32(0x38D01377), |
||||
SPH_C32(0xBE5466CF), SPH_C32(0x34E90C6C), |
||||
SPH_C32(0xC0AC29B7), SPH_C32(0xC97C50DD), |
||||
SPH_C32(0x3F84D5B5), SPH_C32(0xB5470917) |
||||
}; |
||||
|
||||
#if 0 |
||||
#define GS(m0, m1, c0, c1, a, b, c, d) do { \ |
||||
a = SPH_T32(a + b + (m0 ^ c1)); \ |
||||
d = SPH_ROTR32(d ^ a, 16); \ |
||||
c = SPH_T32(c + d); \ |
||||
b = SPH_ROTR32(b ^ c, 12); \ |
||||
a = SPH_T32(a + b + (m1 ^ c0)); \ |
||||
d = SPH_ROTR32(d ^ a, 8); \ |
||||
c = SPH_T32(c + d); \ |
||||
b = SPH_ROTR32(b ^ c, 7); \ |
||||
} while (0) |
||||
|
||||
#define ROUND_S(r) do { \ |
||||
GS(Mx(r, 0x0), Mx(r, 0x1), CSx(r, 0x0), CSx(r, 0x1), v[0], v[4], v[0x8], v[0xC]); \ |
||||
GS(Mx(r, 0x2), Mx(r, 0x3), CSx(r, 0x2), CSx(r, 0x3), v[1], v[5], v[0x9], v[0xD]); \ |
||||
GS(Mx(r, 0x4), Mx(r, 0x5), CSx(r, 0x4), CSx(r, 0x5), v[2], v[6], v[0xA], v[0xE]); \ |
||||
GS(Mx(r, 0x6), Mx(r, 0x7), CSx(r, 0x6), CSx(r, 0x7), v[3], v[7], v[0xB], v[0xF]); \ |
||||
GS(Mx(r, 0x8), Mx(r, 0x9), CSx(r, 0x8), CSx(r, 0x9), v[0], v[5], v[0xA], v[0xF]); \ |
||||
GS(Mx(r, 0xA), Mx(r, 0xB), CSx(r, 0xA), CSx(r, 0xB), v[1], v[6], v[0xB], v[0xC]); \ |
||||
GS(Mx(r, 0xC), Mx(r, 0xD), CSx(r, 0xC), CSx(r, 0xD), v[2], v[7], v[0x8], v[0xD]); \ |
||||
GS(Mx(r, 0xE), Mx(r, 0xF), CSx(r, 0xE), CSx(r, 0xF), v[3], v[4], v[0x9], v[0xE]); \ |
||||
} while (0) |
||||
#endif |
||||
|
||||
#define GS(a,b,c,d,x) { \ |
||||
const uint32_t idx1 = c_sigma[i][x]; \ |
||||
const uint32_t idx2 = c_sigma[i][x+1]; \ |
||||
v[a] += (m[idx1] ^ u256[idx2]) + v[b]; \ |
||||
v[d] = SPH_ROTL32(v[d] ^ v[a], 16); \ |
||||
v[c] += v[d]; \ |
||||
v[b] = SPH_ROTR32(v[b] ^ v[c], 12); \ |
||||
\ |
||||
v[a] += (m[idx2] ^ u256[idx1]) + v[b]; \ |
||||
v[d] = SPH_ROTR32(v[d] ^ v[a], 8); \ |
||||
v[c] += v[d]; \ |
||||
v[b] = SPH_ROTR32(v[b] ^ v[c], 7); \ |
||||
} |
||||
|
||||
#define BLAKE256_ROUNDS 14 |
||||
|
||||
__device__ static |
||||
void blake256_compress(uint32_t *h, const uint32_t *block, const uint32_t T0) |
||||
{ |
||||
uint32_t /* __align__(8) */ v[16]; |
||||
uint32_t /* __align__(8) */ m[16]; |
||||
|
||||
const uint32_t* u256 = c_u256; |
||||
|
||||
//#pragma unroll |
||||
for (int i = 0; i < 16; ++i) { |
||||
m[i] = block[i]; |
||||
} |
||||
|
||||
//#pragma unroll 8 |
||||
for(int i = 0; i < 8; i++) |
||||
v[i] = h[i]; |
||||
|
||||
v[ 8] = u256[0]; |
||||
v[ 9] = u256[1]; |
||||
v[10] = u256[2]; |
||||
v[11] = u256[3]; |
||||
|
||||
v[12] = u256[4] ^ T0; |
||||
v[13] = u256[5] ^ T0; |
||||
v[14] = u256[6]; |
||||
v[15] = u256[7]; |
||||
|
||||
//#pragma unroll |
||||
for (int i = 0; i < BLAKE256_ROUNDS; i++) { |
||||
/* column step */ |
||||
GS(0, 4, 0x8, 0xC, 0); |
||||
GS(1, 5, 0x9, 0xD, 2); |
||||
GS(2, 6, 0xA, 0xE, 4); |
||||
GS(3, 7, 0xB, 0xF, 6); |
||||
/* diagonal step */ |
||||
GS(0, 5, 0xA, 0xF, 0x8); |
||||
GS(1, 6, 0xB, 0xC, 0xA); |
||||
GS(2, 7, 0x8, 0xD, 0xC); |
||||
GS(3, 4, 0x9, 0xE, 0xE); |
||||
} |
||||
|
||||
//#pragma unroll 16 |
||||
for(int i = 0; i < 16; i++) |
||||
h[i % 8] ^= v[i]; |
||||
} |
||||
|
||||
__global__ |
||||
void blake256_gpu_hash_80(uint32_t threads, uint32_t startNounce, uint32_t *resNounce) |
||||
{ |
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x); |
||||
if (thread < threads) |
||||
{ |
||||
const uint32_t nounce = startNounce + thread; |
||||
uint32_t /* __align__(8) */ msg[16]; |
||||
uint32_t h[8]; |
||||
|
||||
#pragma unroll |
||||
for(int i=0; i<8; i++) |
||||
h[i] = c_IV256[i]; |
||||
|
||||
blake256_compress(h, c_PaddedMessage80, 0x200); /* 512 = 0x200 */ |
||||
|
||||
// ------ Close: Bytes 64 to 80 ------ |
||||
|
||||
msg[0] = c_PaddedMessage80[16]; |
||||
msg[1] = c_PaddedMessage80[17]; |
||||
msg[2] = c_PaddedMessage80[18]; |
||||
msg[3] = nounce; /* our tested value */ |
||||
msg[4] = 0x80000000UL; //cuda_swab32(0x80U); |
||||
|
||||
msg[5] = 0; // uchar[17 to 55] |
||||
msg[6] = 0; |
||||
msg[7] = 0; |
||||
msg[8] = 0; |
||||
msg[9] = 0; |
||||
msg[10] = 0; |
||||
msg[11] = 0; |
||||
msg[12] = 0; |
||||
|
||||
msg[13] = 1; |
||||
msg[14] = 0; |
||||
msg[15] = 0x280; |
||||
|
||||
blake256_compress(h, msg, 0x280); |
||||
|
||||
for (int i = 7; i >= 0; i--) { |
||||
uint32_t hash = cuda_swab32(h[i]); |
||||
if (hash > c_Target[i]) { |
||||
return; |
||||
} |
||||
if (hash < c_Target[i]) { |
||||
break; |
||||
} |
||||
} |
||||
|
||||
/* keep the smallest nounce, hmm... */ |
||||
if(resNounce[0] > nounce) |
||||
resNounce[0] = nounce; |
||||
} |
||||
} |
||||
|
||||
__host__ |
||||
uint32_t blake256_cpu_hash_80(int thr_id, uint32_t threads, uint32_t startNounce) |
||||
{ |
||||
const int threadsperblock = TPB; |
||||
uint32_t result = MAXU; |
||||
|
||||
dim3 grid((threads + threadsperblock-1)/threadsperblock); |
||||
dim3 block(threadsperblock); |
||||
size_t shared_size = 0; |
||||
|
||||
/* Check error on Ctrl+C or kill to prevent segfaults on exit */ |
||||
if (cudaMemset(d_resNounce[thr_id], 0xff, sizeof(uint32_t)) != cudaSuccess) |
||||
return result; |
||||
|
||||
blake256_gpu_hash_80<<<grid, block, shared_size>>>(threads, startNounce, d_resNounce[thr_id]); |
||||
cudaDeviceSynchronize(); |
||||
if (cudaSuccess == cudaMemcpy(h_resNounce[thr_id], d_resNounce[thr_id], sizeof(uint32_t), cudaMemcpyDeviceToHost)) { |
||||
cudaThreadSynchronize(); |
||||
result = *h_resNounce[thr_id]; |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
__host__ |
||||
void blake256_cpu_setBlock_80(uint32_t *pdata, const uint32_t *ptarget) |
||||
{ |
||||
uint32_t PaddedMessage[32]; |
||||
memcpy(PaddedMessage, pdata, 80); |
||||
memset(&PaddedMessage[20], 0, 48); |
||||
CUDA_SAFE_CALL(cudaMemcpyToSymbol(c_PaddedMessage80, PaddedMessage, sizeof(PaddedMessage), 0, cudaMemcpyHostToDevice)); |
||||
CUDA_SAFE_CALL(cudaMemcpyToSymbol(c_sigma, host_sigma, sizeof(host_sigma), 0, cudaMemcpyHostToDevice)); |
||||
CUDA_SAFE_CALL(cudaMemcpyToSymbol(c_Target, ptarget, 32, 0, cudaMemcpyHostToDevice)); |
||||
} |
||||
|
||||
extern "C" int scanhash_blake32(int thr_id, uint32_t *pdata, const uint32_t *ptarget, |
||||
uint32_t max_nonce, unsigned long *hashes_done) |
||||
{ |
||||
const uint32_t first_nonce = pdata[19]; |
||||
static bool init[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; |
||||
uint32_t throughput = min(TPB * 2048, max_nonce - first_nonce); |
||||
int rc = 0; |
||||
|
||||
if (opt_benchmark) |
||||
((uint32_t*)ptarget)[7] = 0x00000f; |
||||
|
||||
if (!init[thr_id]) { |
||||
if (opt_n_threads > 1) { |
||||
CUDA_SAFE_CALL(cudaSetDevice(device_map[thr_id])); |
||||
} |
||||
CUDA_SAFE_CALL(cudaMallocHost(&h_resNounce[thr_id], sizeof(uint32_t))); |
||||
CUDA_SAFE_CALL(cudaMalloc(&d_resNounce[thr_id], sizeof(uint32_t))); |
||||
init[thr_id] = true; |
||||
} |
||||
|
||||
if (throughput < (TPB * 2048)) |
||||
applog(LOG_WARNING, "throughput=%u, start=%x, max=%x", throughput, first_nonce, max_nonce); |
||||
|
||||
blake256_cpu_setBlock_80(pdata, ptarget); |
||||
|
||||
do { |
||||
// GPU HASH |
||||
uint32_t foundNonce = blake256_cpu_hash_80(thr_id, throughput, pdata[19]); |
||||
if (foundNonce != 0xffffffff) |
||||
{ |
||||
uint32_t endiandata[20]; |
||||
uint32_t vhashcpu[8]; |
||||
uint32_t Htarg = ptarget[7]; |
||||
|
||||
for (int k=0; k < 20; k++) |
||||
be32enc(&endiandata[k], pdata[k]); |
||||
|
||||
if (opt_debug && !opt_quiet) { |
||||
applog(LOG_DEBUG, "throughput=%u, start=%x, max=%x, pdata=%08x...%08x", |
||||
throughput, first_nonce, max_nonce, endiandata[0], endiandata[7]); |
||||
applog_hash((unsigned char *)pdata); |
||||
} |
||||
|
||||
be32enc(&endiandata[19], foundNonce); |
||||
|
||||
blake32hash(vhashcpu, endiandata); |
||||
|
||||
if (vhashcpu[7] <= Htarg && fulltest(vhashcpu, ptarget)) |
||||
{ |
||||
pdata[19] = foundNonce; |
||||
rc = 1; |
||||
goto exit_scan; |
||||
} |
||||
else if (vhashcpu[7] > Htarg) { |
||||
applog(LOG_WARNING, "GPU #%d: result for nounce %08x is not in range: %x > %x", thr_id, foundNonce, vhashcpu[7], Htarg); |
||||
} |
||||
else if (vhashcpu[6] > ptarget[6]) { |
||||
applog(LOG_WARNING, "GPU #%d: hash[6] for nounce %08x is not in range: %x > %x", thr_id, foundNonce, vhashcpu[6], ptarget[6]); |
||||
} |
||||
else { |
||||
applog(LOG_WARNING, "GPU #%d: result for nounce %08x does not validate on CPU!", thr_id, foundNonce); |
||||
} |
||||
} |
||||
|
||||
pdata[19] += throughput; |
||||
|
||||
} while (pdata[19] < max_nonce && !work_restart[thr_id].restart); |
||||
|
||||
exit_scan: |
||||
*hashes_done = pdata[19] - first_nonce + 1; |
||||
// reset the device to allow multiple instances |
||||
if (opt_n_threads == 1) { |
||||
CUDA_SAFE_CALL(cudaDeviceReset()); |
||||
init[thr_id] = false; |
||||
} |
||||
// wait proper end of all threads |
||||
cudaDeviceSynchronize(); |
||||
return rc; |
||||
} |
@ -1 +1,9 @@
@@ -1 +1,9 @@
|
||||
./configure "CFLAGS=-O3" "CXXFLAGS=-O3" --with-cuda=/usr/local/cuda |
||||
# possible additional CUDA_CFLAGS |
||||
#-gencode=arch=compute_50,code=\"sm_50,compute_50\" |
||||
#-gencode=arch=compute_35,code=\"sm_35,compute_35\" |
||||
#-gencode=arch=compute_30,code=\"sm_30,compute_30\" |
||||
|
||||
#--ptxas-options=\"-v -dlcm=cg\"" |
||||
|
||||
CUDA_CFLAGS="-O2" ./configure "CFLAGS=-O2" "CXXFLAGS=-O2" --with-cuda=/usr/local/cuda |
||||
|
||||
|
@ -0,0 +1,226 @@
@@ -0,0 +1,226 @@
|
||||
#include <stdlib.h> |
||||
#include <memory.h> |
||||
#include <map> |
||||
|
||||
#include "miner.h" |
||||
|
||||
#define HI_DWORD(u64) ((uint32_t) (u64 >> 32)) |
||||
#define LO_DWORD(u64) ((uint32_t) u64) |
||||
#define MK_HI64(u32) (0x100000000ULL * u32) |
||||
|
||||
struct hashlog_data { |
||||
uint32_t tm_sent; |
||||
uint32_t scanned_from; |
||||
uint32_t scanned_to; |
||||
uint32_t last_from; |
||||
uint32_t tm_add; |
||||
uint32_t tm_upd; |
||||
}; |
||||
|
||||
static std::map<uint64_t, hashlog_data> tlastshares; |
||||
|
||||
#define LOG_PURGE_TIMEOUT 5*60 |
||||
|
||||
/**
|
||||
* str hex to uint32 |
||||
*/ |
||||
static uint64_t hextouint(char* jobid) |
||||
{ |
||||
char *ptr; |
||||
return strtoull(jobid, &ptr, 16); |
||||
} |
||||
|
||||
/**
|
||||
* @return time of a job/nonce submission (or last nonce if nonce is 0) |
||||
*/ |
||||
extern "C" uint32_t hashlog_already_submittted(char* jobid, uint32_t nonce) |
||||
{ |
||||
uint32_t ret = 0; |
||||
uint64_t njobid = hextouint(jobid); |
||||
uint64_t key = (njobid << 32) + nonce; |
||||
if (nonce == 0) { |
||||
// search last submitted nonce for job
|
||||
ret = hashlog_get_last_sent(jobid); |
||||
} else if (tlastshares.find(key) != tlastshares.end()) { |
||||
hashlog_data data = tlastshares[key]; |
||||
ret = data.tm_sent; |
||||
} |
||||
return ret; |
||||
} |
||||
/**
|
||||
* Store submitted nonces of a job |
||||
*/ |
||||
extern "C" void hashlog_remember_submit(char* jobid, uint32_t nonce) |
||||
{ |
||||
uint64_t njobid = hextouint(jobid); |
||||
uint64_t keyall = (njobid << 32); |
||||
uint64_t key = keyall + nonce; |
||||
struct hashlog_data data; |
||||
|
||||
data = tlastshares[keyall]; |
||||
data.tm_upd = data.tm_sent = (uint32_t) time(NULL); |
||||
if (data.tm_add == 0) |
||||
data.tm_add = data.tm_upd; |
||||
tlastshares[key] = data; |
||||
} |
||||
|
||||
/**
|
||||
* Update job scanned range |
||||
*/ |
||||
extern "C" void hashlog_remember_scan_range(char* jobid, uint32_t scanned_from, uint32_t scanned_to) |
||||
{ |
||||
uint64_t njobid = hextouint(jobid); |
||||
uint64_t keyall = (njobid << 32); |
||||
uint64_t range = hashlog_get_scan_range(jobid); |
||||
struct hashlog_data data; |
||||
|
||||
// global scan range of a job
|
||||
data = tlastshares[keyall]; |
||||
if (range == 0) { |
||||
memset(&data, 0, sizeof(data)); |
||||
} else { |
||||
// get min and max from all sent records
|
||||
data.scanned_from = LO_DWORD(range); |
||||
data.scanned_to = HI_DWORD(range); |
||||
} |
||||
|
||||
if (data.tm_add == 0) |
||||
data.tm_add = (uint32_t) time(NULL); |
||||
|
||||
data.last_from = scanned_from; |
||||
|
||||
if (scanned_from < scanned_to) { |
||||
if (data.scanned_from == 0) |
||||
data.scanned_from = scanned_from ? scanned_from : 1; // min 1
|
||||
else if (scanned_from < data.scanned_from) // || scanned_to == (data.scanned_from - 1)
|
||||
data.scanned_from = scanned_from; |
||||
if (data.scanned_to == 0 || scanned_from == data.scanned_to + 1) |
||||
data.scanned_to = scanned_to; |
||||
} |
||||
|
||||
data.tm_upd = (uint32_t) time(NULL); |
||||
|
||||
tlastshares[keyall] = data; |
||||
/* applog(LOG_BLUE, "job %s range : %x %x -> %x %x", jobid,
|
||||
scanned_from, scanned_to, data.scanned_from, data.scanned_to); */ |
||||
} |
||||
|
||||
/**
|
||||
* Returns the range of a job |
||||
* @return uint64_t to|from |
||||
*/ |
||||
extern "C" uint64_t hashlog_get_scan_range(char* jobid) |
||||
{ |
||||
uint64_t ret = 0; |
||||
uint64_t njobid = hextouint(jobid); |
||||
uint64_t keypfx = (njobid << 32); |
||||
struct hashlog_data data; |
||||
data.scanned_from = 0; |
||||
data.scanned_to = 0; |
||||
std::map<uint64_t, hashlog_data>::iterator i = tlastshares.begin(); |
||||
while (i != tlastshares.end()) { |
||||
if ((keypfx & i->first) == keypfx && i->second.scanned_to > ret) { |
||||
if (i->second.scanned_to > data.scanned_to) |
||||
data.scanned_to = i->second.scanned_to; |
||||
if (i->second.scanned_from < data.scanned_from || data.scanned_from == 0) |
||||
data.scanned_from = i->second.scanned_from; |
||||
} |
||||
i++; |
||||
} |
||||
ret = data.scanned_from; |
||||
ret += MK_HI64(data.scanned_to); |
||||
return ret; |
||||
} |
||||
|
||||
/**
|
||||
* Search last submitted nonce for a job |
||||
* @return max nonce |
||||
*/ |
||||
extern "C" uint32_t hashlog_get_last_sent(char* jobid) |
||||
{ |
||||
uint32_t nonce = 0; |
||||
uint64_t njobid = hextouint(jobid); |
||||
uint64_t keypfx = (njobid << 32); |
||||
std::map<uint64_t, hashlog_data>::iterator i = tlastshares.begin(); |
||||
while (i != tlastshares.end()) { |
||||
if ((keypfx & i->first) == keypfx && i->second.tm_sent > 0) { |
||||
nonce = LO_DWORD(i->first); |
||||
} |
||||
i++; |
||||
} |
||||
return nonce; |
||||
} |
||||
|
||||
/**
|
||||
* Remove entries of a job... |
||||
*/ |
||||
extern "C" void hashlog_purge_job(char* jobid) |
||||
{ |
||||
int deleted = 0; |
||||
uint64_t njobid = hextouint(jobid); |
||||
uint64_t keypfx = (njobid << 32); |
||||
uint32_t sz = tlastshares.size(); |
||||
std::map<uint64_t, hashlog_data>::iterator i = tlastshares.begin(); |
||||
while (i != tlastshares.end()) { |
||||
if ((keypfx & i->first) == keypfx) { |
||||
deleted++; |
||||
tlastshares.erase(i++); |
||||
} |
||||
else ++i; |
||||
} |
||||
if (opt_debug && deleted) { |
||||
applog(LOG_DEBUG, "hashlog: purge job %s, del %d/%d", jobid, deleted, sz); |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* Remove old entries to reduce memory usage |
||||
*/ |
||||
extern "C" void hashlog_purge_old(void) |
||||
{ |
||||
int deleted = 0; |
||||
uint32_t now = (uint32_t) time(NULL); |
||||
uint32_t sz = tlastshares.size(); |
||||
std::map<uint64_t, hashlog_data>::iterator i = tlastshares.begin(); |
||||
while (i != tlastshares.end()) { |
||||
if ((now - i->second.tm_sent) > LOG_PURGE_TIMEOUT) { |
||||
deleted++; |
||||
tlastshares.erase(i++); |
||||
} |
||||
else ++i; |
||||
} |
||||
if (opt_debug && deleted) { |
||||
applog(LOG_DEBUG, "hashlog: %d/%d purged", deleted, sz); |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* Reset the submitted nonces cache |
||||
*/ |
||||
extern "C" void hashlog_purge_all(void) |
||||
{ |
||||
tlastshares.clear(); |
||||
} |
||||
|
||||
/**
|
||||
* Used to debug ranges... |
||||
*/ |
||||
extern "C" void hashlog_dump_job(char* jobid) |
||||
{ |
||||
if (opt_debug) { |
||||
int deleted = 0; |
||||
uint64_t njobid = hextouint(jobid); |
||||
uint64_t keypfx = (njobid << 32); |
||||
uint32_t sz = tlastshares.size(); |
||||
std::map<uint64_t, hashlog_data>::iterator i = tlastshares.begin(); |
||||
while (i != tlastshares.end()) { |
||||
if ((keypfx & i->first) == keypfx) { |
||||
applog(LOG_BLUE, "job %s range : %x %x %s added %x upd %x", jobid, |
||||
i->second.scanned_from, i->second.scanned_to, |
||||
i->second.tm_sent ? "sent" : "", |
||||
i->second.tm_add, i->second.tm_upd);/* */ |
||||
} |
||||
i++; |
||||
} |
||||
} |
||||
} |
@ -1,367 +0,0 @@
@@ -1,367 +0,0 @@
|
||||
#! /bin/sh |
||||
# Common stub for a few missing GNU programs while installing. |
||||
|
||||
scriptversion=2006-05-10.23 |
||||
|
||||
# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006 |
||||
# Free Software Foundation, Inc. |
||||
# Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996. |
||||
|
||||
# This program is free software; you can redistribute it and/or modify |
||||
# it under the terms of the GNU General Public License as published by |
||||
# the Free Software Foundation; either version 2, or (at your option) |
||||
# any later version. |
||||
|
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
|
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
||||
# 02110-1301, USA. |
||||
|
||||
# As a special exception to the GNU General Public License, if you |
||||
# distribute this file as part of a program that contains a |
||||
# configuration script generated by Autoconf, you may include it under |
||||
# the same distribution terms that you use for the rest of that program. |
||||
|
||||
if test $# -eq 0; then |
||||
echo 1>&2 "Try \`$0 --help' for more information" |
||||
exit 1 |
||||
fi |
||||
|
||||
run=: |
||||
sed_output='s/.* --output[ =]\([^ ]*\).*/\1/p' |
||||
sed_minuso='s/.* -o \([^ ]*\).*/\1/p' |
||||
|
||||
# In the cases where this matters, `missing' is being run in the |
||||
# srcdir already. |
||||
if test -f configure.ac; then |
||||
configure_ac=configure.ac |
||||
else |
||||
configure_ac=configure.in |
||||
fi |
||||
|
||||
msg="missing on your system" |
||||
|
||||
case $1 in |
||||
--run) |
||||
# Try to run requested program, and just exit if it succeeds. |
||||
run= |
||||
shift |
||||
"$@" && exit 0 |
||||
# Exit code 63 means version mismatch. This often happens |
||||
# when the user try to use an ancient version of a tool on |
||||
# a file that requires a minimum version. In this case we |
||||
# we should proceed has if the program had been absent, or |
||||
# if --run hadn't been passed. |
||||
if test $? = 63; then |
||||
run=: |
||||
msg="probably too old" |
||||
fi |
||||
;; |
||||
|
||||
-h|--h|--he|--hel|--help) |
||||
echo "\ |
||||
$0 [OPTION]... PROGRAM [ARGUMENT]... |
||||
|
||||
Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an |
||||
error status if there is no known handling for PROGRAM. |
||||
|
||||
Options: |
||||
-h, --help display this help and exit |
||||
-v, --version output version information and exit |
||||
--run try to run the given command, and emulate it if it fails |
||||
|
||||
Supported PROGRAM values: |
||||
aclocal touch file \`aclocal.m4' |
||||
autoconf touch file \`configure' |
||||
autoheader touch file \`config.h.in' |
||||
autom4te touch the output file, or create a stub one |
||||
automake touch all \`Makefile.in' files |
||||
bison create \`y.tab.[ch]', if possible, from existing .[ch] |
||||
flex create \`lex.yy.c', if possible, from existing .c |
||||
help2man touch the output file |
||||
lex create \`lex.yy.c', if possible, from existing .c |
||||
makeinfo touch the output file |
||||
tar try tar, gnutar, gtar, then tar without non-portable flags |
||||
yacc create \`y.tab.[ch]', if possible, from existing .[ch] |
||||
|
||||
Send bug reports to <bug-automake@gnu.org>." |
||||
exit $? |
||||
;; |
||||
|
||||
-v|--v|--ve|--ver|--vers|--versi|--versio|--version) |
||||
echo "missing $scriptversion (GNU Automake)" |
||||
exit $? |
||||
;; |
||||
|
||||
-*) |
||||
echo 1>&2 "$0: Unknown \`$1' option" |
||||
echo 1>&2 "Try \`$0 --help' for more information" |
||||
exit 1 |
||||
;; |
||||
|
||||
esac |
||||
|
||||
# Now exit if we have it, but it failed. Also exit now if we |
||||
# don't have it and --version was passed (most likely to detect |
||||
# the program). |
||||
case $1 in |
||||
lex|yacc) |
||||
# Not GNU programs, they don't have --version. |
||||
;; |
||||
|
||||
tar) |
||||
if test -n "$run"; then |
||||
echo 1>&2 "ERROR: \`tar' requires --run" |
||||
exit 1 |
||||
elif test "x$2" = "x--version" || test "x$2" = "x--help"; then |
||||
exit 1 |
||||
fi |
||||
;; |
||||
|
||||
*) |
||||
if test -z "$run" && ($1 --version) > /dev/null 2>&1; then |
||||
# We have it, but it failed. |
||||
exit 1 |
||||
elif test "x$2" = "x--version" || test "x$2" = "x--help"; then |
||||
# Could not run --version or --help. This is probably someone |
||||
# running `$TOOL --version' or `$TOOL --help' to check whether |
||||
# $TOOL exists and not knowing $TOOL uses missing. |
||||
exit 1 |
||||
fi |
||||
;; |
||||
esac |
||||
|
||||
# If it does not exist, or fails to run (possibly an outdated version), |
||||
# try to emulate it. |
||||
case $1 in |
||||
aclocal*) |
||||
echo 1>&2 "\ |
||||
WARNING: \`$1' is $msg. You should only need it if |
||||
you modified \`acinclude.m4' or \`${configure_ac}'. You might want |
||||
to install the \`Automake' and \`Perl' packages. Grab them from |
||||
any GNU archive site." |
||||
touch aclocal.m4 |
||||
;; |
||||
|
||||
autoconf) |
||||
echo 1>&2 "\ |
||||
WARNING: \`$1' is $msg. You should only need it if |
||||
you modified \`${configure_ac}'. You might want to install the |
||||
\`Autoconf' and \`GNU m4' packages. Grab them from any GNU |
||||
archive site." |
||||
touch configure |
||||
;; |
||||
|
||||
autoheader) |
||||
echo 1>&2 "\ |
||||
WARNING: \`$1' is $msg. You should only need it if |
||||
you modified \`acconfig.h' or \`${configure_ac}'. You might want |
||||
to install the \`Autoconf' and \`GNU m4' packages. Grab them |
||||
from any GNU archive site." |
||||
files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}` |
||||
test -z "$files" && files="config.h" |
||||
touch_files= |
||||
for f in $files; do |
||||
case $f in |
||||
*:*) touch_files="$touch_files "`echo "$f" | |
||||
sed -e 's/^[^:]*://' -e 's/:.*//'`;; |
||||
*) touch_files="$touch_files $f.in";; |
||||
esac |
||||
done |
||||
touch $touch_files |
||||
;; |
||||
|
||||
automake*) |
||||
echo 1>&2 "\ |
||||
WARNING: \`$1' is $msg. You should only need it if |
||||
you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'. |
||||
You might want to install the \`Automake' and \`Perl' packages. |
||||
Grab them from any GNU archive site." |
||||
find . -type f -name Makefile.am -print | |
||||
sed 's/\.am$/.in/' | |
||||
while read f; do touch "$f"; done |
||||
;; |
||||
|
||||
autom4te) |
||||
echo 1>&2 "\ |
||||
WARNING: \`$1' is needed, but is $msg. |
||||
You might have modified some files without having the |
||||
proper tools for further handling them. |
||||
You can get \`$1' as part of \`Autoconf' from any GNU |
||||
archive site." |
||||
|
||||
file=`echo "$*" | sed -n "$sed_output"` |
||||
test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"` |
||||
if test -f "$file"; then |
||||
touch $file |
||||
else |
||||
test -z "$file" || exec >$file |
||||
echo "#! /bin/sh" |
||||
echo "# Created by GNU Automake missing as a replacement of" |
||||
echo "# $ $@" |
||||
echo "exit 0" |
||||
chmod +x $file |
||||
exit 1 |
||||
fi |
||||
;; |
||||
|
||||
bison|yacc) |
||||
echo 1>&2 "\ |
||||
WARNING: \`$1' $msg. You should only need it if |
||||
you modified a \`.y' file. You may need the \`Bison' package |
||||
in order for those modifications to take effect. You can get |
||||
\`Bison' from any GNU archive site." |
||||
rm -f y.tab.c y.tab.h |
||||
if test $# -ne 1; then |
||||
eval LASTARG="\${$#}" |
||||
case $LASTARG in |
||||
*.y) |
||||
SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'` |
||||
if test -f "$SRCFILE"; then |
||||
cp "$SRCFILE" y.tab.c |
||||
fi |
||||
SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'` |
||||
if test -f "$SRCFILE"; then |
||||
cp "$SRCFILE" y.tab.h |
||||
fi |
||||
;; |
||||
esac |
||||
fi |
||||
if test ! -f y.tab.h; then |
||||
echo >y.tab.h |
||||
fi |
||||
if test ! -f y.tab.c; then |
||||
echo 'main() { return 0; }' >y.tab.c |
||||
fi |
||||
;; |
||||
|
||||
lex|flex) |
||||
echo 1>&2 "\ |
||||
WARNING: \`$1' is $msg. You should only need it if |
||||
you modified a \`.l' file. You may need the \`Flex' package |
||||
in order for those modifications to take effect. You can get |
||||
\`Flex' from any GNU archive site." |
||||
rm -f lex.yy.c |
||||
if test $# -ne 1; then |
||||
eval LASTARG="\${$#}" |
||||
case $LASTARG in |
||||
*.l) |
||||
SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'` |
||||
if test -f "$SRCFILE"; then |
||||
cp "$SRCFILE" lex.yy.c |
||||
fi |
||||
;; |
||||
esac |
||||
fi |
||||
if test ! -f lex.yy.c; then |
||||
echo 'main() { return 0; }' >lex.yy.c |
||||
fi |
||||
;; |
||||
|
||||
help2man) |
||||
echo 1>&2 "\ |
||||
WARNING: \`$1' is $msg. You should only need it if |
||||
you modified a dependency of a manual page. You may need the |
||||
\`Help2man' package in order for those modifications to take |
||||
effect. You can get \`Help2man' from any GNU archive site." |
||||
|
||||
file=`echo "$*" | sed -n "$sed_output"` |
||||
test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"` |
||||
if test -f "$file"; then |
||||
touch $file |
||||
else |
||||
test -z "$file" || exec >$file |
||||
echo ".ab help2man is required to generate this page" |
||||
exit 1 |
||||
fi |
||||
;; |
||||
|
||||
makeinfo) |
||||
echo 1>&2 "\ |
||||
WARNING: \`$1' is $msg. You should only need it if |
||||
you modified a \`.texi' or \`.texinfo' file, or any other file |
||||
indirectly affecting the aspect of the manual. The spurious |
||||
call might also be the consequence of using a buggy \`make' (AIX, |
||||
DU, IRIX). You might want to install the \`Texinfo' package or |
||||
the \`GNU make' package. Grab either from any GNU archive site." |
||||
# The file to touch is that specified with -o ... |
||||
file=`echo "$*" | sed -n "$sed_output"` |
||||
test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"` |
||||
if test -z "$file"; then |
||||
# ... or it is the one specified with @setfilename ... |
||||
infile=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'` |
||||
file=`sed -n ' |
||||
/^@setfilename/{ |
||||
s/.* \([^ ]*\) *$/\1/ |
||||
p |
||||
q |
||||
}' $infile` |
||||
# ... or it is derived from the source name (dir/f.texi becomes f.info) |
||||
test -z "$file" && file=`echo "$infile" | sed 's,.*/,,;s,.[^.]*$,,'`.info |
||||
fi |
||||
# If the file does not exist, the user really needs makeinfo; |
||||
# let's fail without touching anything. |
||||
test -f $file || exit 1 |
||||
touch $file |
||||
;; |
||||
|
||||
tar) |
||||
shift |
||||
|
||||
# We have already tried tar in the generic part. |
||||
# Look for gnutar/gtar before invocation to avoid ugly error |
||||
# messages. |
||||
if (gnutar --version > /dev/null 2>&1); then |
||||
gnutar "$@" && exit 0 |
||||
fi |
||||
if (gtar --version > /dev/null 2>&1); then |
||||
gtar "$@" && exit 0 |
||||
fi |
||||
firstarg="$1" |
||||
if shift; then |
||||
case $firstarg in |
||||
*o*) |
||||
firstarg=`echo "$firstarg" | sed s/o//` |
||||
tar "$firstarg" "$@" && exit 0 |
||||
;; |
||||
esac |
||||
case $firstarg in |
||||
*h*) |
||||
firstarg=`echo "$firstarg" | sed s/h//` |
||||
tar "$firstarg" "$@" && exit 0 |
||||
;; |
||||
esac |
||||
fi |
||||
|
||||
echo 1>&2 "\ |
||||
WARNING: I can't seem to be able to run \`tar' with the given arguments. |
||||
You may want to install GNU tar or Free paxutils, or check the |
||||
command line arguments." |
||||
exit 1 |
||||
;; |
||||
|
||||
*) |
||||
echo 1>&2 "\ |
||||
WARNING: \`$1' is needed, and is $msg. |
||||
You might have modified some files without having the |
||||
proper tools for further handling them. Check the \`README' file, |
||||
it often tells you about the needed prerequisites for installing |
||||
this package. You may also peek at any GNU archive site, in case |
||||
some other package would contain this missing \`$1' program." |
||||
exit 1 |
||||
;; |
||||
esac |
||||
|
||||
exit 0 |
||||
|
||||
# Local variables: |
||||
# eval: (add-hook 'write-file-hooks 'time-stamp) |
||||
# time-stamp-start: "scriptversion=" |
||||
# time-stamp-format: "%:y-%02m-%02d.%02H" |
||||
# time-stamp-end: "$" |
||||
# End: |
Loading…
Reference in new issue