Browse Source

Merge branch 'api_refactor' into myfork

Luke Dashjr 13 years ago
parent
commit
4b3586d4c5
3 changed files with 72 additions and 63 deletions
  1. 68 60
      api.c
  2. 2 2
      driver-opencl.c
  3. 2 1
      miner.h

+ 68 - 60
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,26 +828,38 @@ 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);
-		}
+	tailsprintf(buf, "%c", isjson ? '}' : 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);
 	}
 
-	if (isjson)
-		tailsprintf(buf, "}");
-	else
-		tailsprintf(buf, "%c", SEPARATOR);
+	tailsprintf(buf, "%c", isjson ? '}' : SEPARATOR);
 }
 
 static void gpustatus(int gpu, bool isjson)
@@ -862,9 +884,10 @@ 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 devcount = 0;
 	int i;
 
 	if (total_devices == 0) {
@@ -879,45 +902,29 @@ 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++;
+		func(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);
 }
 
+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;
@@ -1919,6 +1926,7 @@ struct CMDS {
 	{ "version",		apiversion,	false },
 	{ "config",		minerconfig,	false },
 	{ "devs",		devstatus,	false },
+	{ "devdetail",	devdetail,	false },
 	{ "pools",		poolstatus,	false },
 	{ "summary",		summary,	false },
 	{ "gpuenable",		gpuenable,	true },

+ 2 - 2
driver-opencl.c

@@ -1185,7 +1185,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();
 
@@ -1492,7 +1492,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,

+ 2 - 1
miner.h

@@ -205,7 +205,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*);