From 84ffcbc51b74fd9eeb0f3795b5383e943b13ee99 Mon Sep 17 00:00:00 2001 From: Kano Date: Fri, 14 Jun 2013 01:09:50 +1000 Subject: [PATCH] Use mining start time for device MH/U calculations --- api.c | 32 ++++++++++++++++++++++++++++---- cgminer.c | 45 +++++++++++++++++++++++++++++++++++++++++---- driver-modminer.c | 2 ++ miner.h | 2 ++ usbutils.c | 21 +++++++++++++++++++++ usbutils.h | 1 + 6 files changed, 95 insertions(+), 8 deletions(-) diff --git a/api.c b/api.c index ae7f6745..0d35fc60 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 33780b73..0837078a 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 67a5b957..1502a5f8 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 ecced72d..ff32c289 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 483f6f46..38062763 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 e9c794a8..5d3f2634 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);