Bitcoin Forum
June 30, 2024, 02:19:00 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: pooler-cpuminer witch timer to START/STOP mining  (Read 1763 times)
kuzea (OP)
Newbie
*
Offline Offline

Activity: 1
Merit: 0


View Profile
October 07, 2013, 08:29:48 AM
Last edit: October 07, 2013, 05:30:18 PM by kuzea
 #1

I makes some changes to pooler-cpuminer-2.3.2 to make it to start or stop at specified time

new parameters
-i, --starttime      time of day to start mining (in format HHMM default: 2100)
-f, --stoptime      time of day to stop mining (in format HHMM default: 0800)

I need this changes to mining on my servers nightly
i veriffied these only on windows

these is the patch for pooler-cpuminer-2.3.2
https://docs.google.com/file/d/0B77YthddIabZQkhaSl8zTFo4UUU/edit?usp=sharing


cpu-miner.c
Code:
diff U3B cpu-miner.c cpu-miner.c
--- cpu-miner.c Wed Jul 10 15:00:52 2013
+++ cpu-miner.c Mon Oct 07 00:13:55 2013
@@ -41,6 +41,8 @@
 #define PROGRAM_NAME "minerd"
 #define DEF_RPC_URL "http://127.0.0.1:9332/"
 #define LP_SCANTIME 60
+#define TIME_START 1260
+#define TIME_STOP 480
 
 #ifdef __linux /* Linux specific policy and affinity management */
 #include <sched.h>
@@ -143,6 +145,12 @@
 struct work_restart *work_restart = NULL;
 static struct stratum_ctx stratum;
 
+//integer values of minutes for simplifie calcules 19:37 = 19*60+37
+static int time_start = TIME_START;
+static int time_stop = TIME_STOP;
+static int time_to_sleep = 0;
+
+
 pthread_mutex_t applog_lock;
 pthread_mutex_t stats_lock;
 
@@ -178,6 +186,8 @@
                           (default: retry indefinitely)\n\
   -R, --retry-pause=N   time to pause between retries, in seconds (default: 30)\n\
   -T, --timeout=N       network timeout, in seconds (default: 270)\n\
+  -i, --starttime time of day to start mining (in format HHMM default: 2100)\n\
+  -f, --stoptime time of day to stop mining (in format HHMM default: 0800)\n\
   -s, --scantime=N      upper bound on time spent scanning current work when\n\
                           long polling is unavailable, in seconds (default: 5)\n\
       --no-longpoll     disable X-Long-Polling support\n\
@@ -236,6 +246,8 @@
  { "url", 1, NULL, 'o' },
  { "user", 1, NULL, 'u' },
  { "userpass", 1, NULL, 'O' },
+ { "starttime", 1, NULL, 'i' },
+ { "stoptime", 1, NULL, 'f' },
  { "version", 0, NULL, 'V' },
  { 0, 0, 0, 0 }
 };
@@ -696,6 +708,13 @@
  }
 
  while (1) {
+ time_to_sleep=pause_interval(time_start,time_stop);
+ if (time_to_sleep>0)
+ {
+ applog(LOG_INFO, "PAUSE for dinner in  %d s", time_to_sleep);
+ sleep(time_to_sleep);
+ applog(LOG_INFO, "END PAUSE got to work ");
+ }
  unsigned long hashes_done;
  struct timeval tv_start, tv_end, diff;
  int64_t max64;
@@ -854,7 +873,9 @@
  while (1) {
  json_t *val, *soval;
  int err;
-
+ if (time_to_sleep)
+ sleep(time_to_sleep);
+
  val = json_rpc_call(curl, lp_url, rpc_userpass, rpc_req,
     false, true, &err);
  if (have_stratum) {
@@ -944,6 +966,8 @@
  applog(LOG_INFO, "Starting Stratum on %s", stratum.url);
 
  while (1) {
+ if (time_to_sleep)
+ sleep(time_to_sleep);
  int failures = 0;
 
  while (!stratum.curl) {
@@ -1177,6 +1201,18 @@
  break;
  case 'S':
  use_syslog = true;
+ break;
+ case 'i':
+ v = atoi(arg);
+ if (v <= 0 || v > 2359) /* sanity check */
+ show_usage_and_exit(1);
+ time_start = (v/100)*60+(v%100);
+ break;
+ case 'f':
+ v = atoi(arg);
+ if (v <= 0 || v > 2359) /* sanity check */
+ show_usage_and_exit(1);
+ time_stop = (v/100)*60+(v%100);
  break;
  case 'V':
  show_version_and_exit();

miner.h
Code:
diff U3B miner.h miner.h
--- miner.h Wed Jul 10 15:00:52 2013
+++ miner.h Sun Oct 06 09:27:04 2013
@@ -190,7 +190,8 @@
 extern char *bin2hex(const unsigned char *p, size_t len);
 extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len);
 extern int timeval_subtract(struct timeval *result, struct timeval *x,
- struct timeval *y);
+ struct timeval *y);
+extern int   pause_interval(int starttime, int endtime) ;
 extern bool fulltest(const uint32_t *hash, const uint32_t *target);
 extern void diff_to_target(uint32_t *target, double diff);

 util.c
Code:
diff U3B util.c util.c
--- util.c Thu Jul 04 16:21:22 2013
+++ util.c Mon Oct 07 00:29:49 2013
@@ -35,6 +35,8 @@
 #include "miner.h"
 #include "elist.h"
 
+#include <time.h>
+
 struct data_buffer {
  void *buf;
  size_t len;
@@ -511,6 +513,25 @@
 
  /* Return 1 if result is negative. */
  return x->tv_sec < y->tv_sec;
+}
+
+int pause_interval(int starttime, int endtime)
+{
+ int pause_hours = 0, pause_mins =0;
+
+ int loc_time;
+ time_t t = time(NULL);
+ struct tm *tbuf = localtime(&t);
+ loc_time = tbuf->tm_hour*60+tbuf->tm_min;
+
+ if((starttime > endtime && loc_time>endtime && loc_time<starttime) ||
+ (starttime < endtime && (loc_time<starttime ||loc_time>endtime)))
+ {
+ pause_mins = starttime-loc_time;
+ if(pause_mins<0)
+ pause_mins+=60*24;
+ }
+ return  pause_mins*60;
 }
 
 bool fulltest(const uint32_t *hash, const uint32_t *target)


Im newbie on this forum but I hope anyone write to https://bitcointalk.org/index.php?topic=55038.0


-------------------------
sorry for my bad english
b!z
Legendary
*
Offline Offline

Activity: 1582
Merit: 1010



View Profile
October 07, 2013, 10:39:48 AM
 #2

Interesting patch, thank you for sharing it. I think some other members might benefit from this.
Razorr
Newbie
*
Offline Offline

Activity: 30
Merit: 0


View Profile
October 08, 2013, 09:37:00 AM
 #3

This cgwatcher is pretty good.

http://infinitecointalk.org/index.php?topic=51.0
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!