Browse Source

opencl: Support for reading temperature from free software radeon drivers via libsensors

Luke Dashjr 12 years ago
parent
commit
ebcdb29718
3 changed files with 95 additions and 4 deletions
  1. 4 0
      Makefile.am
  2. 36 0
      configure.ac
  3. 55 4
      driver-opencl.c

+ 4 - 0
Makefile.am

@@ -62,6 +62,10 @@ bfgminer_SOURCES += ocl.c ocl.h findnonce.c findnonce.h
 bfgminer_SOURCES += adl.c adl.h adl_functions.h
 bfgminer_SOURCES += *.cl
 
+if HAVE_SENSORS
+bfgminer_LDADD += $(sensors_LIBS)
+endif
+
 if HAS_SCRYPT
 bfgminer_SOURCES += scrypt.c scrypt.h
 endif

+ 36 - 0
configure.ac

@@ -216,6 +216,33 @@ AC_SUBST(JANSSON_LIBS)
 if test "x$opencl" = xyes; then
 	adl="yes"
 	
+AC_ARG_WITH([sensors],[Build with libsensors monitoring],[true],[with_sensors=auto])
+if test "x$opencl" != xyes; then
+	with_sensors=no
+fi
+if test "x$with_sensors" != xno; then
+	AC_MSG_CHECKING([for libsensors])
+	save_LIBS="${LIBS}"
+	LIBS="$LIBS -lsensors"
+	AC_LINK_IFELSE([AC_LANG_PROGRAM([
+		#include <stddef.h>
+		#include <sensors/sensors.h>
+	],[
+		const sensors_chip_name *cn;
+		cn = sensors_get_detected_chips(NULL, NULL);
+	])],[
+		with_sensors=yes
+		sensors_LIBS="-lsensors"
+		AC_DEFINE([HAVE_SENSORS], [1], [Defined if libsensors was found])
+		AC_MSG_RESULT([yes])
+	],[
+		with_sensors=no
+		AC_MSG_RESULT([no])
+	])
+	LIBS="$save_LIBS"
+fi
+AC_SUBST(sensors_LIBS)
+
 AC_ARG_ENABLE([adl],
 	[AC_HELP_STRING([--disable-adl],[Build without ADL monitoring (default enabled)])],
 	[adl=$enableval]
@@ -463,6 +490,7 @@ AM_CONDITIONAL([NEED_DYNCLOCK], [test x$icarus$modminer$x6500$ztex != xnonono])
 AM_CONDITIONAL([NEED_FPGAUTILS], [test x$avalon$icarus$bitforce$modminer$x6500$ztex != xnononono])
 AM_CONDITIONAL([HAS_SCRYPT], [test x$scrypt = xyes])
 AM_CONDITIONAL([HAVE_CURSES], [test x$curses = xyes])
+AM_CONDITIONAL([HAVE_SENSORS], [test x$with_sensors = xyes])
 AM_CONDITIONAL([HAVE_CYGWIN], [test x$have_cygwin = xtrue])
 AM_CONDITIONAL([HAVE_WINDOWS], [test x$have_win32 = xtrue])
 AM_CONDITIONAL([HAVE_x86_64], [test x$have_x86_64 = xtrue])
@@ -747,6 +775,14 @@ else
 	echo "  OpenCL...............: Disabled"
 fi
 
+if test "x$with_sensors" = xyes; then
+	echo "    sensors.monitoring.: Enabled"
+elif test "x$opencl" = xyes; then
+	echo "    sensors.monitoring.: Disabled"
+else
+	echo "    sensors.monitoring.: n/a"
+fi
+
 if test "x$adl" = xyes; then
 	echo "    ADL.monitoring.....: Enabled"
 elif test "x$opencl" = xyes; then

+ 55 - 4
driver-opencl.c

@@ -289,6 +289,15 @@ extern int gpu_fanpercent(int gpu);
 #endif
 
 
+#ifdef HAVE_SENSORS
+#include <sensors/sensors.h>
+
+struct opencl_device_data {
+	const sensors_chip_name *sensor;
+};
+#endif
+
+
 #ifdef HAVE_OPENCL
 char *set_vector(char *arg)
 {
@@ -1434,6 +1443,17 @@ static void opencl_detect()
 	if (opt_g_threads == -1)
 		opt_g_threads = 2;
 
+#ifdef HAVE_SENSORS
+	struct opencl_device_data *data;
+	const sensors_chip_name *cn;
+	int c = 0;
+	
+	sensors_init(NULL);
+	sensors_chip_name cnm;
+	if (sensors_parse_chip_name("radeon-*", &cnm))
+		c = -1;
+#endif
+
 	for (i = 0; i < nDevs; ++i) {
 		struct cgpu_info *cgpu;
 
@@ -1444,6 +1464,15 @@ static void opencl_detect()
 		cgpu->device_id = i;
 		cgpu->threads = opt_g_threads;
 		cgpu->virtual_gpu = i;
+		
+#ifdef HAVE_SENSORS
+		cn = (c == -1) ? NULL : sensors_get_detected_chips(&cnm, &c);
+		cgpu->cgpu_data = data = malloc(sizeof(*data));
+		*data = (struct opencl_device_data){
+			.sensor = cn,
+		};
+#endif
+		
 		add_cgpu(cgpu);
 	}
 
@@ -1456,9 +1485,33 @@ static void reinit_opencl_device(struct cgpu_info *gpu)
 	tq_push(thr_info[gpur_thr_id].q, gpu);
 }
 
-#ifdef HAVE_ADL
 static void get_opencl_statline_before(char *buf, struct cgpu_info *gpu)
 {
+#ifdef HAVE_SENSORS
+	struct opencl_device_data *data = gpu->cgpu_data;
+	if (data->sensor)
+	{
+		const sensors_chip_name *cn = data->sensor;
+		const sensors_feature *feat;
+		for (int f = 0; (feat = sensors_get_features(cn, &f)); )
+		{
+			const sensors_subfeature *subf;
+			subf = sensors_get_subfeature(cn, feat, SENSORS_SUBFEATURE_TEMP_INPUT);
+			if (!(subf && subf->flags & SENSORS_MODE_R))
+				continue;
+			
+			double val;
+			int rc = sensors_get_value(cn, subf->number, &val);
+			if (rc)
+				continue;
+			
+			gpu->temp = val;
+			tailsprintf(buf, "%5.1fC         | ", val);
+			return;
+		}
+	}
+#endif
+#ifdef HAVE_ADL
 	if (gpu->has_adl) {
 		int gpuid = gpu->device_id;
 		float gt = gpu_temp(gpuid);
@@ -1478,9 +1531,9 @@ static void get_opencl_statline_before(char *buf, struct cgpu_info *gpu)
 		tailsprintf(buf, "| ");
 	}
 	else
+#endif
 		tailsprintf(buf, "               | ");
 }
-#endif
 
 static struct api_data*
 get_opencl_api_extra_device_status(struct cgpu_info *gpu)
@@ -1778,9 +1831,7 @@ struct device_api opencl_api = {
 	.name = "OCL",
 	.api_detect = opencl_detect,
 	.reinit_device = reinit_opencl_device,
-#ifdef HAVE_ADL
 	.get_statline_before = get_opencl_statline_before,
-#endif
 	.get_api_extra_device_status = get_opencl_api_extra_device_status,
 	.thread_prepare = opencl_thread_prepare,
 	.thread_init = opencl_thread_init,