Browse Source

Abstract hasehs_done2 which keeps track of time deltas per thr on its own

Luke Dashjr 12 years ago
parent
commit
597b32a55a
4 changed files with 12 additions and 9 deletions
  1. 9 0
      deviceapi.c
  2. 1 0
      deviceapi.h
  3. 1 9
      driver-getwork.c
  4. 1 0
      miner.h

+ 9 - 0
deviceapi.c

@@ -84,6 +84,15 @@ bool hashes_done(struct thr_info *thr, int64_t hashes, struct timeval *tvp_hashe
 	return true;
 }
 
+bool hashes_done2(struct thr_info *thr, int64_t hashes, uint32_t *max_nonce)
+{
+	struct timeval tv_now, tv_delta;
+	timer_set_now(&tv_now);
+	timersub(&tv_now, &thr->_tv_last_hashes_done_call, &tv_delta);
+	thr->_tv_last_hashes_done_call = tv_now;
+	return hashes_done(thr, hashes, &tv_delta, max_nonce);
+}
+
 /* A generic wait function for threads that poll that will wait a specified
  * time tdiff waiting on a work restart request. Returns zero if the condition
  * was met (work restart requested) or ETIMEDOUT if not.

+ 1 - 0
deviceapi.h

@@ -10,6 +10,7 @@
 extern void request_work(struct thr_info *);
 extern struct work *get_work(struct thr_info *);
 extern bool hashes_done(struct thr_info *, int64_t hashes, struct timeval *tvp_hashes, uint32_t *max_nonce);
+extern bool hashes_done2(struct thr_info *, int64_t hashes, uint32_t *max_nonce);
 extern void mt_disable_start(struct thr_info *);
 extern void mt_disable_finish(struct thr_info *);
 extern void mt_disable(struct thr_info *);  // blocks until reenabled

+ 1 - 9
driver-getwork.c

@@ -28,7 +28,6 @@ struct getwork_client {
 	char *username;
 	struct cgpu_info *cgpu;
 	struct work *work;
-	struct timeval tv_hashes_done;
 	
 	UT_hash_handle hh;
 };
@@ -293,14 +292,7 @@ int handle_getwork(struct MHD_Connection *conn, bytes_t *upbuf)
 	
 out:
 	if (hashesdone)
-	{
-		struct timeval tv_now, tv_delta;
-		long long lld = strtoll(hashesdone, NULL, 0);
-		timer_set_now(&tv_now);
-		timersub(&tv_now, &client->tv_hashes_done, &tv_delta);
-		client->tv_hashes_done = tv_now;
-		hashes_done(thr, lld, &tv_delta, NULL);
-	}
+		hashes_done2(thr, strtoll(hashesdone, NULL, 0), NULL);
 	
 	free(user);
 	free(idstr);

+ 1 - 0
miner.h

@@ -619,6 +619,7 @@ struct thr_info {
 	uint64_t hashes_done;
 	struct timeval tv_hashes_done;
 	struct timeval tv_lastupdate;
+	struct timeval _tv_last_hashes_done_call;
 
 	bool	pause;
 	time_t	getwork;