From 3ffffd23749d277aa7b9d961ccfb456ffe2bc47d Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sat, 21 Apr 2012 14:40:25 -0400 Subject: [PATCH 1/8] Bugfix: Don't error on DEVS command if all devices are PGAs --- api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api.c b/api.c index 77ab5c2498..cffc16cdd5 100644 --- a/api.c +++ b/api.c @@ -919,7 +919,7 @@ static void devstatus(__maybe_unused SOCKETTYPE c, __maybe_unused char *param, b int devcount = 0; int i; - if (nDevs == 0 && opt_n_threads == 0) { + if (total_devices == 0) { strcpy(io_buffer, message(MSG_NODEVS, 0, NULL, isjson)); return; } From d7372d1b76c91a21f7f4d9cf7050cf9fc0b2e72d Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sat, 21 Apr 2012 15:31:10 -0400 Subject: [PATCH 2/8] API: Refactor device status into a single common function --- api.c | 203 ++++++++++++++++++++++++---------------------------------- 1 file changed, 82 insertions(+), 121 deletions(-) diff --git a/api.c b/api.c index cffc16cdd5..bbc30b1012 100644 --- a/api.c +++ b/api.c @@ -163,6 +163,7 @@ static const char *SICK = "Sick"; static const char *NOSTART = "NoStart"; static const char *DISABLED = "Disabled"; static const char *ALIVE = "Alive"; +static const char *UNKNOWN = "Unknown"; #define _DYNAMIC "D" static const char *DYNAMIC = _DYNAMIC; @@ -770,149 +771,109 @@ static void minerconfig(__maybe_unused SOCKETTYPE c, __maybe_unused char *param, strcat(io_buffer, buf); } -static void gpustatus(int gpu, bool isjson) +static const char* +bool2str(bool b) { - char intensity[20]; - char buf[BUFSIZ]; - char *enabled; - char *status; - float gt, gv; - int ga, gf, gp, gc, gm, pt; + return b ? YES : NO; +} - if (gpu >= 0 && gpu < nDevs) { - struct cgpu_info *cgpu = &gpus[gpu]; +static const char* +status2str(enum alive status) +{ + switch (status) { + case LIFE_WELL: + return ALIVE; + case LIFE_SICK: + return SICK; + case LIFE_DEAD: + return DEAD; + case LIFE_NOSTART: + return NOSTART; + default: + return UNKNOWN; + } +} - cgpu->utility = cgpu->accepted / ( total_secs ? total_secs : 1 ) * 60; +#ifdef HAVE_OPENCL +extern struct device_api opencl_api; +#endif +static void devstatus_an(char *buf, struct cgpu_info *cgpu, bool isjson) +{ + tailsprintf(buf, isjson + ? "{\"%s\":%d,\"Enabled\":\"%s\",\"Status\":\"%s\",\"Temperature\":%.2f" + : "%s=%d,Enabled=%s,Status=%s,Temperature=%.2f", + cgpu->api->name, cgpu->device_id, + bool2str(cgpu->deven != DEV_DISABLED), + status2str(cgpu->status), + cgpu->temp + ); +#ifdef HAVE_OPENCL + if (cgpu->api == &opencl_api) { + float gt, gv; + int ga, gf, gp, gc, gm, pt; #ifdef HAVE_ADL if (!gpu_stats(gpu, >, &gc, &gm, &gv, &ga, &gf, &gp, &pt)) #endif gt = gv = gm = gc = ga = gf = gp = pt = 0; - - if (cgpu->deven != DEV_DISABLED) - enabled = (char *)YES; - else - enabled = (char *)NO; - - if (cgpu->status == LIFE_DEAD) - status = (char *)DEAD; - else if (cgpu->status == LIFE_SICK) - status = (char *)SICK; - else if (cgpu->status == LIFE_NOSTART) - status = (char *)NOSTART; - else - status = (char *)ALIVE; - + tailsprintf(buf, isjson + ? ",\"Fan Speed\":%d,\"Fan Percent\":%d,\"GPU Clock\":%d,\"Memory Clock\":%d,\"GPU Voltage\":%.3f,\"GPU Activity\":%d,\"Powertune\":%d" + : ",Fan Speed=%d,Fan Percent=%d,GPU Clock=%d,Memory Clock=%d,GPU Voltage=%.3f,GPU Activity=%d,Powertune=%d", + gf, gp, gc, gm, gv, ga, pt + ); + } +#endif + tailsprintf(buf, isjson + ? ",\"MHS av\":%.2f,\"MHS %ds\":%.2f,\"Accepted\":%d,\"Rejected\":%d,\"Hardware Errors\":%d,\"Utility\":%.2f" + : ",MHS av=%.2f,MHS %ds=%.2f,Accepted=%d,Rejected=%d,Hardware Errors=%d,Utility=%.2f", + cgpu->total_mhashes / total_secs, opt_log_interval, cgpu->rolling, + cgpu->accepted, cgpu->rejected, cgpu->hw_errors, + cgpu->utility + ); +#ifdef HAVE_OPENCL + if (cgpu->api == &opencl_api) { + char intensity[20]; if (cgpu->dynamic) strcpy(intensity, DYNAMIC); else sprintf(intensity, "%d", cgpu->intensity); - - if (isjson) - sprintf(buf, "{\"GPU\":%d,\"Enabled\":\"%s\",\"Status\":\"%s\",\"Temperature\":%.2f,\"Fan Speed\":%d,\"Fan Percent\":%d,\"GPU Clock\":%d,\"Memory Clock\":%d,\"GPU Voltage\":%.3f,\"GPU Activity\":%d,\"Powertune\":%d,\"MHS av\":%.2f,\"MHS %ds\":%.2f,\"Accepted\":%d,\"Rejected\":%d,\"Hardware Errors\":%d,\"Utility\":%.2f,\"Intensity\":\"%s\",\"Last Share Pool\":%d,\"Last Share Time\":%lu,\"Total MH\":%.4f}", - gpu, enabled, status, gt, gf, gp, gc, gm, gv, ga, pt, - cgpu->total_mhashes / total_secs, opt_log_interval, cgpu->rolling, - cgpu->accepted, cgpu->rejected, cgpu->hw_errors, - cgpu->utility, intensity, - ((unsigned long)(cgpu->last_share_pool_time) > 0) ? cgpu->last_share_pool : -1, - (unsigned long)(cgpu->last_share_pool_time), cgpu->total_mhashes); - else - sprintf(buf, "GPU=%d,Enabled=%s,Status=%s,Temperature=%.2f,Fan Speed=%d,Fan Percent=%d,GPU Clock=%d,Memory Clock=%d,GPU Voltage=%.3f,GPU Activity=%d,Powertune=%d,MHS av=%.2f,MHS %ds=%.2f,Accepted=%d,Rejected=%d,Hardware Errors=%d,Utility=%.2f,Intensity=%s,Last Share Pool=%d,Last Share Time=%lu,Total MH=%.4f%c", - gpu, enabled, status, gt, gf, gp, gc, gm, gv, ga, pt, - cgpu->total_mhashes / total_secs, opt_log_interval, cgpu->rolling, - cgpu->accepted, cgpu->rejected, cgpu->hw_errors, - cgpu->utility, intensity, - ((unsigned long)(cgpu->last_share_pool_time) > 0) ? cgpu->last_share_pool : -1, - (unsigned long)(cgpu->last_share_pool_time), cgpu->total_mhashes, SEPARATOR); - - strcat(io_buffer, buf); + tailsprintf(buf, isjson + ? ",\"Intensity\":\"%s\"" + : ",Intensity=%s", + intensity + ); } +#endif + tailsprintf(buf, isjson + ? ",\"Last Share Pool\":%d,\"Last Share Time\":%lu,\"Total MH\":%.4f}" + : ",Last Share Pool=%d,Last Share Time=%lu,Total MH=%.4f", + ((unsigned long)(cgpu->last_share_pool_time) > 0) ? cgpu->last_share_pool : -1, + (unsigned long)(cgpu->last_share_pool_time), cgpu->total_mhashes); + if (!isjson) + tailsprintf(buf, "%c", SEPARATOR); } -#if defined(USE_BITFORCE) || defined(USE_ICARUS) -static void pgastatus(int pga, bool isjson) +static void gpustatus(int gpu, bool isjson) { - char buf[BUFSIZ]; - char *enabled; - char *status; - int numpga = numpgas(); - - if (numpga > 0 && pga >= 0 && pga < numpga) { - int dev = pgadevice(pga); - if (dev < 0) // Should never happen - return; - - struct cgpu_info *cgpu = devices[dev]; - - cgpu->utility = cgpu->accepted / ( total_secs ? total_secs : 1 ) * 60; - - if (cgpu->deven != DEV_DISABLED) - enabled = (char *)YES; - else - enabled = (char *)NO; - - if (cgpu->status == LIFE_DEAD) - status = (char *)DEAD; - else if (cgpu->status == LIFE_SICK) - status = (char *)SICK; - else if (cgpu->status == LIFE_NOSTART) - status = (char *)NOSTART; - else - status = (char *)ALIVE; - - if (isjson) - sprintf(buf, "{\"PGA\":%d,\"Name\":\"%s\",\"ID\":%d,\"Enabled\":\"%s\",\"Status\":\"%s\",\"Temperature\":%.2f,\"MHS av\":%.2f,\"MHS %ds\":%.2f,\"Accepted\":%d,\"Rejected\":%d,\"Hardware Errors\":%d,\"Utility\":%.2f,\"Last Share Pool\":%d,\"Last Share Time\":%lu,\"Total MH\":%.4f}", - pga, cgpu->api->name, cgpu->device_id, - enabled, status, cgpu->temp, - cgpu->total_mhashes / total_secs, opt_log_interval, cgpu->rolling, - cgpu->accepted, cgpu->rejected, cgpu->hw_errors, cgpu->utility, - ((unsigned long)(cgpu->last_share_pool_time) > 0) ? cgpu->last_share_pool : -1, - (unsigned long)(cgpu->last_share_pool_time), cgpu->total_mhashes); - else - sprintf(buf, "PGA=%d,Name=%s,ID=%d,Enabled=%s,Status=%s,Temperature=%.2f,MHS av=%.2f,MHS %ds=%.2f,Accepted=%d,Rejected=%d,Hardware Errors=%d,Utility=%.2f,Last Share Pool=%d,Last Share Time=%lu,Total MH=%.4f%c", - pga, cgpu->api->name, cgpu->device_id, - enabled, status, cgpu->temp, - cgpu->total_mhashes / total_secs, opt_log_interval, cgpu->rolling, - cgpu->accepted, cgpu->rejected, cgpu->hw_errors, cgpu->utility, - ((unsigned long)(cgpu->last_share_pool_time) > 0) ? cgpu->last_share_pool : -1, - (unsigned long)(cgpu->last_share_pool_time), cgpu->total_mhashes, SEPARATOR); + if (gpu < 0 || gpu >= nDevs) + return; + devstatus_an(io_buffer, &gpus[gpu], isjson); +} - strcat(io_buffer, buf); - } +static void pgastatus(int pga, bool isjson) +{ + int dev = pgadevice(pga); + if (dev < 0) // Should never happen + return; + devstatus_an(io_buffer, devices[dev], isjson); } -#endif -#ifdef WANT_CPUMINE static void cpustatus(int cpu, bool isjson) { - char buf[BUFSIZ]; - - if (opt_n_threads > 0 && cpu >= 0 && cpu < num_processors) { - struct cgpu_info *cgpu = &cpus[cpu]; - - cgpu->utility = cgpu->accepted / ( total_secs ? total_secs : 1 ) * 60; - - if (isjson) - sprintf(buf, "{\"CPU\":%d,\"MHS av\":%.2f,\"MHS %ds\":%.2f,\"Accepted\":%d,\"Rejected\":%d,\"Utility\":%.2f,\"Last Share Pool\":%d,\"Last Share Time\":%lu,\"Total MH\":%.4f}", - cpu, cgpu->total_mhashes / total_secs, - opt_log_interval, cgpu->rolling, - cgpu->accepted, cgpu->rejected, - cgpu->utility, - ((unsigned long)(cgpu->last_share_pool_time) > 0) ? cgpu->last_share_pool : -1, - (unsigned long)(cgpu->last_share_pool_time), cgpu->total_mhashes); - else - sprintf(buf, "CPU=%d,MHS av=%.2f,MHS %ds=%.2f,Accepted=%d,Rejected=%d,Utility=%.2f,Last Share Pool=%d,Last Share Time=%lu,Total MH=%.4f%c", - cpu, cgpu->total_mhashes / total_secs, - opt_log_interval, cgpu->rolling, - cgpu->accepted, cgpu->rejected, - cgpu->utility, - ((unsigned long)(cgpu->last_share_pool_time) > 0) ? cgpu->last_share_pool : -1, - (unsigned long)(cgpu->last_share_pool_time), cgpu->total_mhashes, SEPARATOR); - - strcat(io_buffer, buf); - } + if (opt_n_threads <= 0 || cpu < 0 || cpu >= num_processors) + return; + devstatus_an(io_buffer, &cpus[cpu], isjson); } -#endif static void devstatus(__maybe_unused SOCKETTYPE c, __maybe_unused char *param, bool isjson) { From 9dad7a836fdc0057d0e03220966caf54493c0058 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sat, 21 Apr 2012 16:03:47 -0400 Subject: [PATCH 3/8] API: Append Driver, Kernel, Model, and Device Path to device information --- api.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/api.c b/api.c index bbc30b1012..0d92b560e0 100644 --- a/api.c +++ b/api.c @@ -845,11 +845,22 @@ static void devstatus_an(char *buf, struct cgpu_info *cgpu, bool isjson) } #endif tailsprintf(buf, isjson - ? ",\"Last Share Pool\":%d,\"Last Share Time\":%lu,\"Total MH\":%.4f}" + ? ",\"Last Share Pool\":%d,\"Last Share Time\":%lu,\"Total MH\":%.4f" : ",Last Share Pool=%d,Last Share Time=%lu,Total MH=%.4f", ((unsigned long)(cgpu->last_share_pool_time) > 0) ? cgpu->last_share_pool : -1, (unsigned long)(cgpu->last_share_pool_time), cgpu->total_mhashes); - if (!isjson) + + tailsprintf(buf, isjson ? ",\"Driver\":\"%s\"" : ",Driver=%s", cgpu->api->dname); + if (cgpu->kname) + tailsprintf(buf, isjson ? ",\"Kernel\":\"%s\"" : ",Kernel=%s", cgpu->kname); + if (cgpu->name) + tailsprintf(buf, isjson ? ",\"Model\":\"%s\"" : ",Model=%s", cgpu->name); + if (cgpu->device_path) + tailsprintf(buf, isjson ? ",\"Device Path\":\"%s\"" : ",Device Path=%s", cgpu->device_path); + + if (isjson) + tailsprintf(buf, "}"); + else tailsprintf(buf, "%c", SEPARATOR); } From 74b93784f698d465f66df0bd533b275931d0408d Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sat, 21 Apr 2012 20:17:50 -0400 Subject: [PATCH 4/8] API: Move device-specific information fetching to the device API model with a new get_extra_device_info function --- api.c | 49 ++++++++++++++++--------------------------------- driver-opencl.c | 29 +++++++++++++++++++++++++++++ miner.h | 1 + 3 files changed, 46 insertions(+), 33 deletions(-) diff --git a/api.c b/api.c index 0d92b560e0..3835338025 100644 --- a/api.c +++ b/api.c @@ -794,10 +794,6 @@ status2str(enum alive status) } } -#ifdef HAVE_OPENCL -extern struct device_api opencl_api; -#endif - static void devstatus_an(char *buf, struct cgpu_info *cgpu, bool isjson) { tailsprintf(buf, isjson @@ -808,21 +804,6 @@ static void devstatus_an(char *buf, struct cgpu_info *cgpu, bool isjson) status2str(cgpu->status), cgpu->temp ); -#ifdef HAVE_OPENCL - if (cgpu->api == &opencl_api) { - float gt, gv; - int ga, gf, gp, gc, gm, pt; -#ifdef HAVE_ADL - if (!gpu_stats(gpu, >, &gc, &gm, &gv, &ga, &gf, &gp, &pt)) -#endif - gt = gv = gm = gc = ga = gf = gp = pt = 0; - tailsprintf(buf, isjson - ? ",\"Fan Speed\":%d,\"Fan Percent\":%d,\"GPU Clock\":%d,\"Memory Clock\":%d,\"GPU Voltage\":%.3f,\"GPU Activity\":%d,\"Powertune\":%d" - : ",Fan Speed=%d,Fan Percent=%d,GPU Clock=%d,Memory Clock=%d,GPU Voltage=%.3f,GPU Activity=%d,Powertune=%d", - gf, gp, gc, gm, gv, ga, pt - ); - } -#endif tailsprintf(buf, isjson ? ",\"MHS av\":%.2f,\"MHS %ds\":%.2f,\"Accepted\":%d,\"Rejected\":%d,\"Hardware Errors\":%d,\"Utility\":%.2f" : ",MHS av=%.2f,MHS %ds=%.2f,Accepted=%d,Rejected=%d,Hardware Errors=%d,Utility=%.2f", @@ -830,20 +811,6 @@ static void devstatus_an(char *buf, struct cgpu_info *cgpu, bool isjson) cgpu->accepted, cgpu->rejected, cgpu->hw_errors, cgpu->utility ); -#ifdef HAVE_OPENCL - if (cgpu->api == &opencl_api) { - char intensity[20]; - if (cgpu->dynamic) - strcpy(intensity, DYNAMIC); - else - sprintf(intensity, "%d", cgpu->intensity); - tailsprintf(buf, isjson - ? ",\"Intensity\":\"%s\"" - : ",Intensity=%s", - intensity - ); - } -#endif tailsprintf(buf, isjson ? ",\"Last Share Pool\":%d,\"Last Share Time\":%lu,\"Total MH\":%.4f" : ",Last Share Pool=%d,Last Share Time=%lu,Total MH=%.4f", @@ -858,6 +825,22 @@ static void devstatus_an(char *buf, struct cgpu_info *cgpu, bool isjson) if (cgpu->device_path) tailsprintf(buf, isjson ? ",\"Device Path\":\"%s\"" : ",Device Path=%s", cgpu->device_path); + if (cgpu->api->get_extra_device_info) { + json_t *info = cgpu->api->get_extra_device_info(cgpu), *value; + const char *key, *tmpl = isjson ? ",\"%s\":%s" : ",%s=%s"; + char *vdump; + + json_object_foreach(info, key, value) { + if (isjson || !json_is_string(value)) + vdump = json_dumps(value, JSON_COMPACT | JSON_ENCODE_ANY); + else + vdump = strdup(json_string_value(value)); + tailsprintf(buf, tmpl, key, vdump); + free(vdump); + } + json_decref(info); + } + if (isjson) tailsprintf(buf, "}"); else diff --git a/driver-opencl.c b/driver-opencl.c index da9a597ced..2e98337924 100644 --- a/driver-opencl.c +++ b/driver-opencl.c @@ -1154,6 +1154,34 @@ static void get_opencl_statline(char *buf, struct cgpu_info *gpu) tailsprintf(buf, " I:%2d", gpu->intensity); } +static json_t* +get_opencl_extra_device_info(struct cgpu_info *gpu) +{ + json_t *info = json_object(); + + float gt, gv; + int ga, gf, gp, gc, gm, pt; +#ifdef HAVE_ADL + if (!gpu_stats(gpu->device_id, >, &gc, &gm, &gv, &ga, &gf, &gp, &pt)) +#endif + gt = gv = gm = gc = ga = gf = gp = pt = 0; + json_object_set(info, "Fan Speed", json_integer(gf)); + json_object_set(info, "Fan Percent", json_integer(gp)); + json_object_set(info, "GPU Clock", json_integer(gc)); + json_object_set(info, "Memory Clock", json_integer(gm)); + json_object_set(info, "GPU Voltage", json_real(gv)); + json_object_set(info, "GPU Activity", json_integer(ga)); + json_object_set(info, "Powertune", json_integer(pt)); + + json_object_set(info, "Intensity", + gpu->dynamic + ? json_string("D") + : json_integer(gpu->intensity) + ); + + return info; +} + struct opencl_thread_data { cl_int (*queue_kernel_parameters)(_clState *, dev_blk_ctx *, cl_uint); uint32_t *res; @@ -1434,6 +1462,7 @@ struct device_api opencl_api = { .get_statline_before = get_opencl_statline_before, #endif .get_statline = get_opencl_statline, + .get_extra_device_info = get_opencl_extra_device_info, .thread_prepare = opencl_thread_prepare, .thread_init = opencl_thread_init, .free_work = opencl_free_work, diff --git a/miner.h b/miner.h index 7d0354cc3f..b90a14b3f6 100644 --- a/miner.h +++ b/miner.h @@ -197,6 +197,7 @@ struct device_api { void (*reinit_device)(struct cgpu_info*); void (*get_statline_before)(char*, struct cgpu_info*); void (*get_statline)(char*, struct cgpu_info*); + json_t* (*get_extra_device_info)(struct cgpu_info*); // Thread-specific functions bool (*thread_prepare)(struct thr_info*); From d0462430564e5f0e4a85ac3e66ec56493e663f16 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sat, 21 Apr 2012 20:34:47 -0400 Subject: [PATCH 5/8] Collapse multiple tailsprintfs into a single one --- api.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/api.c b/api.c index 3835338025..fddca895f8 100644 --- a/api.c +++ b/api.c @@ -797,27 +797,20 @@ status2str(enum alive status) static void devstatus_an(char *buf, struct cgpu_info *cgpu, bool isjson) { tailsprintf(buf, isjson - ? "{\"%s\":%d,\"Enabled\":\"%s\",\"Status\":\"%s\",\"Temperature\":%.2f" - : "%s=%d,Enabled=%s,Status=%s,Temperature=%.2f", + ? "{\"%s\":%d,\"Enabled\":\"%s\",\"Status\":\"%s\",\"Temperature\":%.2f,\"MHS av\":%.2f,\"MHS %ds\":%.2f,\"Accepted\":%d,\"Rejected\":%d,\"Hardware Errors\":%d,\"Utility\":%.2f,\"Last Share Pool\":%d,\"Last Share Time\":%lu,\"Total MH\":%.4f,\"Driver\":\"%s\"" + : "%s=%d,Enabled=%s,Status=%s,Temperature=%.2f,MHS av=%.2f,MHS %ds=%.2f,Accepted=%d,Rejected=%d,Hardware Errors=%d,Utility=%.2f,Last Share Pool=%d,Last Share Time=%lu,Total MH=%.4f,Driver=%s", cgpu->api->name, cgpu->device_id, bool2str(cgpu->deven != DEV_DISABLED), status2str(cgpu->status), - cgpu->temp - ); - tailsprintf(buf, isjson - ? ",\"MHS av\":%.2f,\"MHS %ds\":%.2f,\"Accepted\":%d,\"Rejected\":%d,\"Hardware Errors\":%d,\"Utility\":%.2f" - : ",MHS av=%.2f,MHS %ds=%.2f,Accepted=%d,Rejected=%d,Hardware Errors=%d,Utility=%.2f", + cgpu->temp, cgpu->total_mhashes / total_secs, opt_log_interval, cgpu->rolling, cgpu->accepted, cgpu->rejected, cgpu->hw_errors, - cgpu->utility - ); - tailsprintf(buf, isjson - ? ",\"Last Share Pool\":%d,\"Last Share Time\":%lu,\"Total MH\":%.4f" - : ",Last Share Pool=%d,Last Share Time=%lu,Total MH=%.4f", + cgpu->utility, ((unsigned long)(cgpu->last_share_pool_time) > 0) ? cgpu->last_share_pool : -1, - (unsigned long)(cgpu->last_share_pool_time), cgpu->total_mhashes); + (unsigned long)(cgpu->last_share_pool_time), cgpu->total_mhashes, + cgpu->api->dname + ); - tailsprintf(buf, isjson ? ",\"Driver\":\"%s\"" : ",Driver=%s", cgpu->api->dname); if (cgpu->kname) tailsprintf(buf, isjson ? ",\"Kernel\":\"%s\"" : ",Kernel=%s", cgpu->kname); if (cgpu->name) From f4e9426193cb904adba265c8119501c8eba8da8c Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Mon, 23 Apr 2012 09:14:54 -0400 Subject: [PATCH 6/8] API: Refactor devstatus method to make it simpler --- api.c | 35 +++-------------------------------- 1 file changed, 3 insertions(+), 32 deletions(-) diff --git a/api.c b/api.c index fddca895f8..b16a0ad87a 100644 --- a/api.c +++ b/api.c @@ -864,7 +864,6 @@ static void cpustatus(int cpu, bool isjson) static void devstatus(__maybe_unused SOCKETTYPE c, __maybe_unused char *param, bool isjson) { - int devcount = 0; int i; if (total_devices == 0) { @@ -879,41 +878,13 @@ static void devstatus(__maybe_unused SOCKETTYPE c, __maybe_unused char *param, b strcat(io_buffer, JSON_DEVS); } - for (i = 0; i < nDevs; i++) { - if (isjson && devcount > 0) + for (i = 0; i < total_devices; ++i) { + if (isjson && i) strcat(io_buffer, COMMA); - gpustatus(i, isjson); - - devcount++; + devstatus_an(io_buffer, devices[i], isjson); } -#if defined(USE_BITFORCE) || defined(USE_ICARUS) - int numpga = numpgas(); - - if (numpga > 0) - for (i = 0; i < numpga; i++) { - if (isjson && devcount > 0) - strcat(io_buffer, COMMA); - - pgastatus(i, isjson); - - devcount++; - } -#endif - -#ifdef WANT_CPUMINE - if (opt_n_threads > 0) - for (i = 0; i < num_processors; i++) { - if (isjson && devcount > 0) - strcat(io_buffer, COMMA); - - cpustatus(i, isjson); - - devcount++; - } -#endif - if (isjson) strcat(io_buffer, JSON_CLOSE); } From db233721f5364c45a5b2b90f53bddc89ff570040 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Mon, 23 Apr 2012 09:27:47 -0400 Subject: [PATCH 7/8] Divide device info into "detail" (static information) and "status" (dynamic information), adding a new "devdetail" JSON API method to get the former --- api.c | 93 ++++++++++++++++++++++++++++++++++++------------- driver-opencl.c | 4 +-- miner.h | 3 +- 3 files changed, 72 insertions(+), 28 deletions(-) diff --git a/api.c b/api.c index b16a0ad87a..fdcfb4c468 100644 --- a/api.c +++ b/api.c @@ -794,20 +794,30 @@ status2str(enum alive status) } } -static void devstatus_an(char *buf, struct cgpu_info *cgpu, bool isjson) +static void +append_kv(char *buf, json_t*info, bool isjson) +{ + json_t *value; + const char *key, *tmpl = isjson ? ",\"%s\":%s" : ",%s=%s"; + char *vdump; + + json_object_foreach(info, key, value) { + if (isjson || !json_is_string(value)) + vdump = json_dumps(value, JSON_COMPACT | JSON_ENCODE_ANY); + else + vdump = strdup(json_string_value(value)); + tailsprintf(buf, tmpl, key, vdump); + free(vdump); + } +} + +static void +devdetail_an(char *buf, struct cgpu_info *cgpu, bool isjson) { tailsprintf(buf, isjson - ? "{\"%s\":%d,\"Enabled\":\"%s\",\"Status\":\"%s\",\"Temperature\":%.2f,\"MHS av\":%.2f,\"MHS %ds\":%.2f,\"Accepted\":%d,\"Rejected\":%d,\"Hardware Errors\":%d,\"Utility\":%.2f,\"Last Share Pool\":%d,\"Last Share Time\":%lu,\"Total MH\":%.4f,\"Driver\":\"%s\"" - : "%s=%d,Enabled=%s,Status=%s,Temperature=%.2f,MHS av=%.2f,MHS %ds=%.2f,Accepted=%d,Rejected=%d,Hardware Errors=%d,Utility=%.2f,Last Share Pool=%d,Last Share Time=%lu,Total MH=%.4f,Driver=%s", + ? "{\"%s\":%d,Driver=%s" + : "%s=%d,Driver=%s", cgpu->api->name, cgpu->device_id, - bool2str(cgpu->deven != DEV_DISABLED), - status2str(cgpu->status), - cgpu->temp, - cgpu->total_mhashes / total_secs, opt_log_interval, cgpu->rolling, - cgpu->accepted, cgpu->rejected, cgpu->hw_errors, - cgpu->utility, - ((unsigned long)(cgpu->last_share_pool_time) > 0) ? cgpu->last_share_pool : -1, - (unsigned long)(cgpu->last_share_pool_time), cgpu->total_mhashes, cgpu->api->dname ); @@ -818,19 +828,37 @@ static void devstatus_an(char *buf, struct cgpu_info *cgpu, bool isjson) if (cgpu->device_path) tailsprintf(buf, isjson ? ",\"Device Path\":\"%s\"" : ",Device Path=%s", cgpu->device_path); - if (cgpu->api->get_extra_device_info) { - json_t *info = cgpu->api->get_extra_device_info(cgpu), *value; - const char *key, *tmpl = isjson ? ",\"%s\":%s" : ",%s=%s"; - char *vdump; + if (cgpu->api->get_extra_device_detail) { + json_t *info = cgpu->api->get_extra_device_detail(cgpu); + append_kv(buf, info, isjson); + json_decref(info); + } - json_object_foreach(info, key, value) { - if (isjson || !json_is_string(value)) - vdump = json_dumps(value, JSON_COMPACT | JSON_ENCODE_ANY); - else - vdump = strdup(json_string_value(value)); - tailsprintf(buf, tmpl, key, vdump); - free(vdump); - } + if (isjson) + tailsprintf(buf, "}"); + else + tailsprintf(buf, "%c", SEPARATOR); +} + +static void devstatus_an(char *buf, struct cgpu_info *cgpu, bool isjson) +{ + tailsprintf(buf, isjson + ? "{\"%s\":%d,\"Enabled\":\"%s\",\"Status\":\"%s\",\"Temperature\":%.2f,\"MHS av\":%.2f,\"MHS %ds\":%.2f,\"Accepted\":%d,\"Rejected\":%d,\"Hardware Errors\":%d,\"Utility\":%.2f,\"Last Share Pool\":%d,\"Last Share Time\":%lu,\"Total MH\":%.4f" + : "%s=%d,Enabled=%s,Status=%s,Temperature=%.2f,MHS av=%.2f,MHS %ds=%.2f,Accepted=%d,Rejected=%d,Hardware Errors=%d,Utility=%.2f,Last Share Pool=%d,Last Share Time=%lu,Total MH=%.4f", + cgpu->api->name, cgpu->device_id, + bool2str(cgpu->deven != DEV_DISABLED), + status2str(cgpu->status), + cgpu->temp, + cgpu->total_mhashes / total_secs, opt_log_interval, cgpu->rolling, + cgpu->accepted, cgpu->rejected, cgpu->hw_errors, + cgpu->utility, + ((unsigned long)(cgpu->last_share_pool_time) > 0) ? cgpu->last_share_pool : -1, + (unsigned long)(cgpu->last_share_pool_time), cgpu->total_mhashes + ); + + if (cgpu->api->get_extra_device_status) { + json_t *info = cgpu->api->get_extra_device_status(cgpu); + append_kv(buf, info, isjson); json_decref(info); } @@ -862,7 +890,9 @@ static void cpustatus(int cpu, bool isjson) devstatus_an(io_buffer, &cpus[cpu], isjson); } -static void devstatus(__maybe_unused SOCKETTYPE c, __maybe_unused char *param, bool isjson) +static void +devinfo_internal(void (*func)(char*, struct cgpu_info*, bool), + __maybe_unused SOCKETTYPE c, __maybe_unused char *param, bool isjson) { int i; @@ -882,13 +912,25 @@ static void devstatus(__maybe_unused SOCKETTYPE c, __maybe_unused char *param, b if (isjson && i) strcat(io_buffer, COMMA); - devstatus_an(io_buffer, devices[i], isjson); + func(io_buffer, devices[i], isjson); } if (isjson) strcat(io_buffer, JSON_CLOSE); } +static void +devdetail(SOCKETTYPE c, char *param, bool isjson) +{ + return devinfo_internal(devdetail_an, c, param, isjson); +} + +static void +devstatus(SOCKETTYPE c, char *param, bool isjson) +{ + return devinfo_internal(devstatus_an, c, param, isjson); +} + static void gpudev(__maybe_unused SOCKETTYPE c, char *param, bool isjson) { int id; @@ -1890,6 +1932,7 @@ struct CMDS { { "version", apiversion, false }, { "config", minerconfig, false }, { "devs", devstatus, false }, + { "devdetail", devdetail, false }, { "pools", poolstatus, false }, { "summary", summary, false }, { "gpuenable", gpuenable, true }, diff --git a/driver-opencl.c b/driver-opencl.c index 2e98337924..fca93eef71 100644 --- a/driver-opencl.c +++ b/driver-opencl.c @@ -1155,7 +1155,7 @@ static void get_opencl_statline(char *buf, struct cgpu_info *gpu) } static json_t* -get_opencl_extra_device_info(struct cgpu_info *gpu) +get_opencl_extra_device_status(struct cgpu_info *gpu) { json_t *info = json_object(); @@ -1462,7 +1462,7 @@ struct device_api opencl_api = { .get_statline_before = get_opencl_statline_before, #endif .get_statline = get_opencl_statline, - .get_extra_device_info = get_opencl_extra_device_info, + .get_extra_device_status = get_opencl_extra_device_status, .thread_prepare = opencl_thread_prepare, .thread_init = opencl_thread_init, .free_work = opencl_free_work, diff --git a/miner.h b/miner.h index b90a14b3f6..b9bfb676a9 100644 --- a/miner.h +++ b/miner.h @@ -197,7 +197,8 @@ struct device_api { void (*reinit_device)(struct cgpu_info*); void (*get_statline_before)(char*, struct cgpu_info*); void (*get_statline)(char*, struct cgpu_info*); - json_t* (*get_extra_device_info)(struct cgpu_info*); + json_t* (*get_extra_device_detail)(struct cgpu_info*); + json_t* (*get_extra_device_status)(struct cgpu_info*); // Thread-specific functions bool (*thread_prepare)(struct thr_info*); From 08342856aa4c7798dd82e967dbcf75438cea09b3 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Mon, 23 Apr 2012 09:29:49 -0400 Subject: [PATCH 8/8] API: Simplify end-of-device marker --- api.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/api.c b/api.c index fdcfb4c468..fe081d5ad3 100644 --- a/api.c +++ b/api.c @@ -834,10 +834,7 @@ devdetail_an(char *buf, struct cgpu_info *cgpu, bool isjson) json_decref(info); } - if (isjson) - tailsprintf(buf, "}"); - else - tailsprintf(buf, "%c", SEPARATOR); + tailsprintf(buf, "%c", isjson ? '}' : SEPARATOR); } static void devstatus_an(char *buf, struct cgpu_info *cgpu, bool isjson) @@ -862,10 +859,7 @@ static void devstatus_an(char *buf, struct cgpu_info *cgpu, bool isjson) json_decref(info); } - if (isjson) - tailsprintf(buf, "}"); - else - tailsprintf(buf, "%c", SEPARATOR); + tailsprintf(buf, "%c", isjson ? '}' : SEPARATOR); } static void gpustatus(int gpu, bool isjson)