Browse Source

API: Move device-specific information fetching to the device API model with a new get_extra_device_info function

Luke Dashjr 14 years ago
parent
commit
74b93784f6
3 changed files with 46 additions and 33 deletions
  1. 16 33
      api.c
  2. 29 0
      driver-opencl.c
  3. 1 0
      miner.h

+ 16 - 33
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)
 static void devstatus_an(char *buf, struct cgpu_info *cgpu, bool isjson)
 {
 {
 	tailsprintf(buf, isjson
 	tailsprintf(buf, isjson
@@ -808,21 +804,6 @@ static void devstatus_an(char *buf, struct cgpu_info *cgpu, bool isjson)
 			status2str(cgpu->status),
 			status2str(cgpu->status),
 			cgpu->temp
 			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, &gt, &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
 	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"
 				: ",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->accepted, cgpu->rejected, cgpu->hw_errors,
 			cgpu->utility
 			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
 	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",
 				: ",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)
 	if (cgpu->device_path)
 		tailsprintf(buf, isjson ? ",\"Device Path\":\"%s\"" : ",Device Path=%s", 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)
 	if (isjson)
 		tailsprintf(buf, "}");
 		tailsprintf(buf, "}");
 	else
 	else

+ 29 - 0
driver-opencl.c

@@ -1154,6 +1154,34 @@ static void get_opencl_statline(char *buf, struct cgpu_info *gpu)
 	tailsprintf(buf, " I:%2d", gpu->intensity);
 	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, &gt, &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 {
 struct opencl_thread_data {
 	cl_int (*queue_kernel_parameters)(_clState *, dev_blk_ctx *, cl_uint);
 	cl_int (*queue_kernel_parameters)(_clState *, dev_blk_ctx *, cl_uint);
 	uint32_t *res;
 	uint32_t *res;
@@ -1434,6 +1462,7 @@ struct device_api opencl_api = {
 	.get_statline_before = get_opencl_statline_before,
 	.get_statline_before = get_opencl_statline_before,
 #endif
 #endif
 	.get_statline = get_opencl_statline,
 	.get_statline = get_opencl_statline,
+	.get_extra_device_info = get_opencl_extra_device_info,
 	.thread_prepare = opencl_thread_prepare,
 	.thread_prepare = opencl_thread_prepare,
 	.thread_init = opencl_thread_init,
 	.thread_init = opencl_thread_init,
 	.free_work = opencl_free_work,
 	.free_work = opencl_free_work,

+ 1 - 0
miner.h

@@ -197,6 +197,7 @@ struct device_api {
 	void (*reinit_device)(struct cgpu_info*);
 	void (*reinit_device)(struct cgpu_info*);
 	void (*get_statline_before)(char*, struct cgpu_info*);
 	void (*get_statline_before)(char*, struct cgpu_info*);
 	void (*get_statline)(char*, struct cgpu_info*);
 	void (*get_statline)(char*, struct cgpu_info*);
+	json_t* (*get_extra_device_info)(struct cgpu_info*);
 
 
 	// Thread-specific functions
 	// Thread-specific functions
 	bool (*thread_prepare)(struct thr_info*);
 	bool (*thread_prepare)(struct thr_info*);