Skip to content

Commit

Permalink
hashlog: prepare store of scanned range
Browse files Browse the repository at this point in the history
  • Loading branch information
tpruvot committed Sep 3, 2014
1 parent e2cf49a commit c370208
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
8 changes: 6 additions & 2 deletions blake32.cu
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,15 @@ extern "C" int scanhash_blake32(int thr_id, uint32_t *pdata, const uint32_t *pta
uint32_t vhashcpu[8];
uint32_t Htarg = ptarget[7];

applog(LOG_WARNING, "throughput=%u, start=%x, max=%x, pdata=%x", throughput, first_nonce, max_nonce, pdata[0]);

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);
Expand Down
3 changes: 2 additions & 1 deletion ccminer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ copy "$(CudaToolkitBinDir)\cudart64*.dll" "$(OutDir)"</Command>
<TargetMachinePlatform Condition="'$(Platform)'=='x64'">64</TargetMachinePlatform>
</CudaCompile>
<CudaCompile Include="blake32.cu">
<MaxRegCount>64</MaxRegCount>
<AdditionalOptions Condition="'$(Configuration)'=='Release'">--ptxas-options=-O2 %(AdditionalOptions)</AdditionalOptions>
<AdditionalOptions Condition="'$(Configuration)'=='Debug'">%(AdditionalOptions)</AdditionalOptions>
</CudaCompile>
Expand Down Expand Up @@ -561,4 +562,4 @@ copy "$(CudaToolkitBinDir)\cudart64*.dll" "$(OutDir)"</Command>
<ImportGroup Label="ExtensionTargets">
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 6.5.targets" />
</ImportGroup>
</Project>
</Project>
4 changes: 3 additions & 1 deletion cpu-miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ static bool submit_upstream_work(CURL *curl, struct work *work)
goto out;
}

hashlog_remember_submit(work->job_id, nonce);
hashlog_remember_submit(work->job_id, nonce, 0);

} else {

Expand Down Expand Up @@ -834,6 +834,8 @@ static void stratum_gen_work(struct stratum_ctx *sctx, struct work *work)
diff_to_target(work->target, sctx->job.diff / (65536.0 * opt_difficulty));
else if (opt_algo == ALGO_FUGUE256 || opt_algo == ALGO_GROESTL || opt_algo == ALGO_DMD_GR || opt_algo == ALGO_FRESH)
diff_to_target(work->target, sctx->job.diff / (256.0 * opt_difficulty));
else if (opt_algo == ALGO_BLAKE)
diff_to_target(work->target, sctx->job.diff / (16.0 * opt_difficulty));
else
diff_to_target(work->target, sctx->job.diff / opt_difficulty);
}
Expand Down
27 changes: 19 additions & 8 deletions hashlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
#define HI_DWORD(u64) ((uint32_t) (u64 >> 32))
#define LO_DWORD(u64) ((uint32_t) u64)

static std::map<uint64_t, uint32_t> tlastshares;
struct hashlog_data {
uint32_t ntime;
uint32_t scanned_from;
uint32_t scanned_to;
};

static std::map<uint64_t, hashlog_data> tlastshares;

#define LOG_PURGE_TIMEOUT 15*60

Expand All @@ -23,11 +29,15 @@ static uint64_t hextouint(char* jobid)
/**
* Store submitted nonces of a job
*/
extern "C" void hashlog_remember_submit(char* jobid, uint32_t nonce)
extern "C" void hashlog_remember_submit(char* jobid, uint32_t nonce, uint64_t range)
{
uint64_t njobid = hextouint(jobid);
uint64_t key = (njobid << 32) + nonce;
tlastshares[key] = (uint32_t) time(NULL);
struct hashlog_data data;
data.ntime = (uint32_t) time(NULL);
data.scanned_from = LO_DWORD(range);
data.scanned_to = HI_DWORD(range);
tlastshares[key] = data;
}

/**
Expand All @@ -39,7 +49,7 @@ extern "C" uint32_t hashlog_get_last_sent(char* jobid)
uint32_t ret = 0;
uint64_t njobid = hextouint(jobid);
uint64_t keypfx = (njobid << 32);
std::map<uint64_t, uint32_t>::iterator i = tlastshares.begin();
std::map<uint64_t, hashlog_data>::iterator i = tlastshares.begin();
while (i != tlastshares.end()) {
if ((keypfx & i->first) == keypfx && LO_DWORD(i->first) > ret) {
ret = LO_DWORD(i->first);
Expand All @@ -61,7 +71,8 @@ extern "C" uint32_t hashlog_already_submittted(char* jobid, uint32_t nonce)
// search last submitted nonce for job
ret = hashlog_get_last_sent(jobid);
} else if (tlastshares.find(key) != tlastshares.end()) {
ret = (uint32_t) tlastshares[key];
hashlog_data data = tlastshares[key];
ret = data.ntime;
}
return ret;
}
Expand All @@ -73,7 +84,7 @@ extern "C" void hashlog_purge_job(char* jobid)
{
uint64_t njobid = hextouint(jobid);
uint64_t keypfx = (njobid << 32);
std::map<uint64_t, uint32_t>::iterator i = tlastshares.begin();
std::map<uint64_t, hashlog_data>::iterator i = tlastshares.begin();
while (i != tlastshares.end()) {
if ((keypfx & i->first) == keypfx)
tlastshares.erase(i);
Expand All @@ -89,9 +100,9 @@ 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, uint32_t>::iterator i = tlastshares.begin();
std::map<uint64_t, hashlog_data>::iterator i = tlastshares.begin();
while (i != tlastshares.end()) {
if ((now - i->second) > LOG_PURGE_TIMEOUT) {
if ((now - i->second.ntime) > LOG_PURGE_TIMEOUT) {
deleted++;
tlastshares.erase(i);
}
Expand Down
3 changes: 2 additions & 1 deletion miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ struct work_restart {

extern bool opt_debug;
extern bool opt_debug_rpc;
extern bool opt_quiet;
extern bool opt_protocol;
extern int opt_timeout;
extern bool want_longpoll;
Expand Down Expand Up @@ -390,7 +391,7 @@ bool stratum_subscribe(struct stratum_ctx *sctx);
bool stratum_authorize(struct stratum_ctx *sctx, const char *user, const char *pass);
bool stratum_handle_method(struct stratum_ctx *sctx, const char *s);

void hashlog_remember_submit(char* jobid, uint32_t nounce);
void hashlog_remember_submit(char* jobid, uint32_t nounce, uint64_t range);
uint32_t hashlog_already_submittted(char* jobid, uint32_t nounce);
uint32_t hashlog_get_last_sent(char* jobid);
void hashlog_purge_old(void);
Expand Down

0 comments on commit c370208

Please sign in to comment.