Merge pull request #443 from kanoi/master Use mining start time for device MH/U calculations
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
diff --git a/api.c b/api.c
index ae7f674..0d35fc6 100644
--- a/api.c
+++ b/api.c
@@ -1581,8 +1581,20 @@ static void ascstatus(struct io_data *io_data, int asc, bool isjson, bool precom
struct cgpu_info *cgpu = get_devices(dev);
float temp = cgpu->temp;
+ struct timeval now;
+ double dev_runtime;
- cgpu->utility = cgpu->accepted / ( total_secs ? total_secs : 1 ) * 60;
+ if (cgpu->dev_start_tv.tv_sec == 0)
+ dev_runtime = total_secs;
+ else {
+ cgtime(&now);
+ dev_runtime = tdiff(&now, &(cgpu->dev_start_tv));
+ }
+
+ if (dev_runtime < 1.0)
+ dev_runtime = 1.0;
+
+ cgpu->utility = cgpu->accepted / dev_runtime * 60;
if (cgpu->deven != DEV_DISABLED)
enabled = (char *)YES;
@@ -1597,7 +1609,7 @@ static void ascstatus(struct io_data *io_data, int asc, bool isjson, bool precom
root = api_add_string(root, "Enabled", enabled, false);
root = api_add_string(root, "Status", status, false);
root = api_add_temp(root, "Temperature", &temp, false);
- double mhs = cgpu->total_mhashes / total_secs;
+ double mhs = cgpu->total_mhashes / dev_runtime;
root = api_add_mhs(root, "MHS av", &mhs, false);
char mhsname[27];
sprintf(mhsname, "MHS %ds", opt_log_interval);
@@ -1643,6 +1655,18 @@ static void pgastatus(struct io_data *io_data, int pga, bool isjson, bool precom
struct cgpu_info *cgpu = get_devices(dev);
double frequency = 0;
float temp = cgpu->temp;
+ struct timeval now;
+ double dev_runtime;
+
+ if (cgpu->dev_start_tv.tv_sec == 0)
+ dev_runtime = total_secs;
+ else {
+ cgtime(&now);
+ dev_runtime = tdiff(&now, &(cgpu->dev_start_tv));
+ }
+
+ if (dev_runtime < 1.0)
+ dev_runtime = 1.0;
#ifdef USE_ZTEX
if (cgpu->drv->drv_id == DRIVER_ZTEX && cgpu->device_ztex)
@@ -1653,7 +1677,7 @@ static void pgastatus(struct io_data *io_data, int pga, bool isjson, bool precom
frequency = cgpu->clock;
#endif
- cgpu->utility = cgpu->accepted / ( total_secs ? total_secs : 1 ) * 60;
+ cgpu->utility = cgpu->accepted / dev_runtime * 60;
if (cgpu->deven != DEV_DISABLED)
enabled = (char *)YES;
@@ -1668,7 +1692,7 @@ static void pgastatus(struct io_data *io_data, int pga, bool isjson, bool precom
root = api_add_string(root, "Enabled", enabled, false);
root = api_add_string(root, "Status", status, false);
root = api_add_temp(root, "Temperature", &temp, false);
- double mhs = cgpu->total_mhashes / total_secs;
+ double mhs = cgpu->total_mhashes / dev_runtime;
root = api_add_mhs(root, "MHS av", &mhs, false);
char mhsname[27];
sprintf(mhsname, "MHS %ds", opt_log_interval);
diff --git a/cgminer.c b/cgminer.c
index 33780b7..0837078 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -1989,8 +1989,20 @@ static void get_statline(char *buf, struct cgpu_info *cgpu)
{
char displayed_hashes[16], displayed_rolling[16];
uint64_t dh64, dr64;
+ struct timeval now;
+ double dev_runtime;
+
+ if (cgpu->dev_start_tv.tv_sec == 0)
+ dev_runtime = total_secs;
+ else {
+ cgtime(&now);
+ dev_runtime = tdiff(&now, &(cgpu->dev_start_tv));
+ }
- dh64 = (double)cgpu->total_mhashes / total_secs * 1000000ull;
+ if (dev_runtime < 1.0)
+ dev_runtime = 1.0;
+
+ dh64 = (double)cgpu->total_mhashes / dev_runtime * 1000000ull;
dr64 = (double)cgpu->rolling * 1000000ull;
suffix_string(dh64, displayed_hashes, 4);
suffix_string(dr64, displayed_rolling, 4);
@@ -2070,6 +2082,8 @@ static void curses_print_devstatus(struct cgpu_info *cgpu, int count)
char logline[256];
char displayed_hashes[16], displayed_rolling[16];
uint64_t dh64, dr64;
+ struct timeval now;
+ double dev_runtime;
if (opt_compact)
return;
@@ -2077,7 +2091,17 @@ static void curses_print_devstatus(struct cgpu_info *cgpu, int count)
if (devcursor + count > LINES - 2)
return;
- cgpu->utility = cgpu->accepted / total_secs * 60;
+ if (cgpu->dev_start_tv.tv_sec == 0)
+ dev_runtime = total_secs;
+ else {
+ cgtime(&now);
+ dev_runtime = tdiff(&now, &(cgpu->dev_start_tv));
+ }
+
+ if (dev_runtime < 1.0)
+ dev_runtime = 1.0;
+
+ cgpu->utility = cgpu->accepted / dev_runtime * 60;
wmove(statuswin,devcursor + count, 0);
wprintw(statuswin, " %s %*d: ", cgpu->drv->name, dev_width, cgpu->device_id);
@@ -2085,7 +2109,7 @@ static void curses_print_devstatus(struct cgpu_info *cgpu, int count)
cgpu->drv->get_statline_before(logline, cgpu);
wprintw(statuswin, "%s", logline);
- dh64 = (double)cgpu->total_mhashes / total_secs * 1000000ull;
+ dh64 = (double)cgpu->total_mhashes / dev_runtime * 1000000ull;
dr64 = (double)cgpu->rolling * 1000000ull;
suffix_string(dh64, displayed_hashes, 4);
suffix_string(dr64, displayed_rolling, 4);
@@ -2432,6 +2456,8 @@ static bool submit_upstream_work(struct work *work, CURL *curl, bool resubmit)
struct timeval tv_submit, tv_submit_reply;
char hashshow[64 + 4] = "";
char worktime[200] = "";
+ struct timeval now;
+ double dev_runtime;
cgpu = get_thr_cgpu(thr_id);
@@ -2570,7 +2596,17 @@ static bool submit_upstream_work(struct work *work, CURL *curl, bool resubmit)
share_result(val, res, err, work, hashshow, resubmit, worktime);
- cgpu->utility = cgpu->accepted / total_secs * 60;
+ if (cgpu->dev_start_tv.tv_sec == 0)
+ dev_runtime = total_secs;
+ else {
+ cgtime(&now);
+ dev_runtime = tdiff(&now, &(cgpu->dev_start_tv));
+ }
+
+ if (dev_runtime < 1.0)
+ dev_runtime = 1.0;
+
+ cgpu->utility = cgpu->accepted / dev_runtime * 60;
if (!opt_realquiet)
print_status(thr_id);
@@ -7170,6 +7206,7 @@ static void hotplug_process()
cgpu->thr = malloc(sizeof(*cgpu->thr) * (cgpu->threads+1));
cgpu->thr[cgpu->threads] = NULL;
cgpu->status = LIFE_INIT;
+ cgtime(&(cgpu->dev_start_tv));
for (j = 0; j < cgpu->threads; ++j) {
thr = get_thread(mining_threads);
diff --git a/driver-modminer.c b/driver-modminer.c
index 67a5b95..1502a5f 100644
--- a/driver-modminer.c
+++ b/driver-modminer.c
@@ -552,6 +552,8 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
// Give it a 2/3s delay after programming
nmsleep(666);
+ usb_set_dev_start(modminer);
+
return true;
undame:
;
diff --git a/miner.h b/miner.h
index ecced72..ff32c28 100644
--- a/miner.h
+++ b/miner.h
@@ -555,6 +555,8 @@ struct cgpu_info {
unsigned int queued_count;
bool shutdown;
+
+ struct timeval dev_start_tv;
};
extern bool add_cgpu(struct cgpu_info*);
diff --git a/usbutils.c b/usbutils.c
index 483f6f4..3806276 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -2690,6 +2690,27 @@ uint32_t usb_buffer_size(struct cgpu_info *cgpu)
return cgusb->bufamt;
}
+// Need to set all devices with matching usbdev
+void usb_set_dev_start(struct cgpu_info *cgpu)
+{
+ struct cg_usb_device *cgusb = cgpu->usbdev;
+ struct cgpu_info *cgpu2;
+ struct timeval now;
+
+ // If the device wasn't dropped
+ if (cgusb != NULL) {
+ int i;
+
+ cgtime(&now);
+
+ for (i = 0; i < total_devices; i++) {
+ cgpu2 = get_devices(i);
+ if (cgpu2->usbdev == cgusb)
+ copy_time(&(cgpu2->dev_start_tv), &now);
+ }
+ }
+}
+
void usb_cleanup()
{
struct cgpu_info *cgpu;
diff --git a/usbutils.h b/usbutils.h
index e9c794a..5d3f263 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -290,6 +290,7 @@ void usb_buffer_enable(struct cgpu_info *cgpu);
void usb_buffer_disable(struct cgpu_info *cgpu);
void usb_buffer_clear(struct cgpu_info *cgpu);
uint32_t usb_buffer_size(struct cgpu_info *cgpu);
+void usb_set_dev_start(struct cgpu_info *cgpu);
void usb_cleanup();
void usb_initialise();
void *usb_resource_thread(void *userdata);