Commit 98d789bd93b5d1ff4e2f344bc4695011ec253442

Kano 2012-01-30T15:23:23

Merge remote-tracking branch 'conman/master'

diff --git a/adl.c b/adl.c
index aad827b..d705575 100644
--- a/adl.c
+++ b/adl.c
@@ -66,7 +66,6 @@ static	ADL_ADAPTER_NUMBEROFADAPTERS_GET	ADL_Adapter_NumberOfAdapters_Get;
 static	ADL_ADAPTER_ADAPTERINFO_GET	ADL_Adapter_AdapterInfo_Get;
 static	ADL_ADAPTER_ID_GET		ADL_Adapter_ID_Get;
 static	ADL_OVERDRIVE5_TEMPERATURE_GET	ADL_Overdrive5_Temperature_Get;
-static	ADL_OVERDRIVE5_THERMALDEVICES_ENUM	ADL_Overdrive5_ThermalDevices_Enum;
 static	ADL_OVERDRIVE5_CURRENTACTIVITY_GET	ADL_Overdrive5_CurrentActivity_Get;
 static	ADL_OVERDRIVE5_ODPARAMETERS_GET	ADL_Overdrive5_ODParameters_Get;
 static	ADL_OVERDRIVE5_FANSPEEDINFO_GET	ADL_Overdrive5_FanSpeedInfo_Get;
@@ -115,8 +114,9 @@ static bool fanspeed_twin(struct gpu_adl *ga, struct gpu_adl *other_ga)
 
 void init_adl(int nDevs)
 {
-	int i, j, devices = 0, last_adapter = -1, gpu = 0, dummy = 0;
+	int result, i, j, devices = 0, last_adapter = -1, gpu = 0, dummy = 0;
 	struct gpu_adapters adapters[MAX_GPUDEVICES], vadapters[MAX_GPUDEVICES];
+	bool devs_match = true;
 
 #if defined (LINUX)
 	hDLL = dlopen( "libatiadlxx.so", RTLD_LAZY|RTLD_GLOBAL);
@@ -143,7 +143,6 @@ void init_adl(int nDevs)
 	ADL_Adapter_AdapterInfo_Get = (ADL_ADAPTER_ADAPTERINFO_GET) GetProcAddress(hDLL,"ADL_Adapter_AdapterInfo_Get");
 	ADL_Adapter_ID_Get = (ADL_ADAPTER_ID_GET) GetProcAddress(hDLL,"ADL_Adapter_ID_Get");
 	ADL_Overdrive5_Temperature_Get = (ADL_OVERDRIVE5_TEMPERATURE_GET) GetProcAddress(hDLL,"ADL_Overdrive5_Temperature_Get");
-	ADL_Overdrive5_ThermalDevices_Enum = (ADL_OVERDRIVE5_THERMALDEVICES_ENUM) GetProcAddress(hDLL,"ADL_Overdrive5_ThermalDevices_Enum");
 	ADL_Overdrive5_CurrentActivity_Get = (ADL_OVERDRIVE5_CURRENTACTIVITY_GET) GetProcAddress(hDLL, "ADL_Overdrive5_CurrentActivity_Get");
 	ADL_Overdrive5_ODParameters_Get = (ADL_OVERDRIVE5_ODPARAMETERS_GET) GetProcAddress(hDLL, "ADL_Overdrive5_ODParameters_Get");
 	ADL_Overdrive5_FanSpeedInfo_Get = (ADL_OVERDRIVE5_FANSPEEDINFO_GET) GetProcAddress(hDLL, "ADL_Overdrive5_FanSpeedInfo_Get");
@@ -159,7 +158,7 @@ void init_adl(int nDevs)
 	if (!ADL_Main_Control_Create || !ADL_Main_Control_Destroy ||
 		!ADL_Adapter_NumberOfAdapters_Get || !ADL_Adapter_AdapterInfo_Get ||
 		!ADL_Adapter_ID_Get || !ADL_Overdrive5_Temperature_Get ||
-		!ADL_Overdrive5_ThermalDevices_Enum || !ADL_Overdrive5_CurrentActivity_Get ||
+		!ADL_Overdrive5_CurrentActivity_Get ||
 		!ADL_Overdrive5_ODParameters_Get || !ADL_Overdrive5_FanSpeedInfo_Get ||
 		!ADL_Overdrive5_FanSpeed_Get || !ADL_Overdrive5_FanSpeed_Set ||
 		!ADL_Overdrive5_ODPerformanceLevels_Get || !ADL_Overdrive5_ODPerformanceLevels_Set ||
@@ -171,19 +170,22 @@ void init_adl(int nDevs)
 
 	// Initialise ADL. The second parameter is 1, which means:
 	// retrieve adapter information only for adapters that are physically present and enabled in the system
-	if (ADL_Main_Control_Create (ADL_Main_Memory_Alloc, 1) != ADL_OK) {
-		applog(LOG_INFO, "ADL Initialisation Error!");
+	result = ADL_Main_Control_Create (ADL_Main_Memory_Alloc, 1);
+	if (result != ADL_OK) {
+		applog(LOG_INFO, "ADL Initialisation Error! Error %d!", result);
 		return ;
 	}
 
-	if (ADL_Main_Control_Refresh() != ADL_OK) {
-		applog(LOG_INFO, "ADL Refresh Error!");
+	result = ADL_Main_Control_Refresh();
+	if (result != ADL_OK) {
+		applog(LOG_INFO, "ADL Refresh Error! Error %d!", result);
 		return ;
 	}
 
 	// Obtain the number of adapters for the system
-	if (ADL_Adapter_NumberOfAdapters_Get ( &iNumberAdapters ) != ADL_OK) {
-		applog(LOG_INFO, "Cannot get the number of adapters!\n");
+	result = ADL_Adapter_NumberOfAdapters_Get (&iNumberAdapters);
+	if (result != ADL_OK) {
+		applog(LOG_INFO, "Cannot get the number of adapters! Error %d!", result);
 		return ;
 	}
 
@@ -193,8 +195,9 @@ void init_adl(int nDevs)
 
 		lpInfo->iSize = sizeof(lpInfo);
 		// Get the AdapterInfo structure for all adapters in the system
-		if (ADL_Adapter_AdapterInfo_Get (lpInfo, sizeof (AdapterInfo) * iNumberAdapters) != ADL_OK) {
-			applog(LOG_INFO, "ADL_Adapter_AdapterInfo_Get Error!");
+		result = ADL_Adapter_AdapterInfo_Get (lpInfo, sizeof (AdapterInfo) * iNumberAdapters);
+		if (result != ADL_OK) {
+			applog(LOG_INFO, "ADL_Adapter_AdapterInfo_Get Error! Error %d", result);
 			return ;
 		}
 	} else {
@@ -209,8 +212,9 @@ void init_adl(int nDevs)
 
 		iAdapterIndex = lpInfo[i].iAdapterIndex;
 		/* Get unique identifier of the adapter, 0 means not AMD */
-		if (ADL_Adapter_ID_Get(iAdapterIndex, &lpAdapterID) != ADL_OK) {
-			applog(LOG_INFO, "Failed to ADL_Adapter_ID_Get");
+		result = ADL_Adapter_ID_Get(iAdapterIndex, &lpAdapterID);
+		if (result != ADL_OK) {
+			applog(LOG_INFO, "Failed to ADL_Adapter_ID_Get. Error %d", result);
 			continue;
 		}
 
@@ -245,8 +249,11 @@ void init_adl(int nDevs)
 		 * opencl enumerated devices and the ADL enumerated
 		 * ones, we have to assume they're in the same order.*/
 		if (++devices > nDevs) {
-			applog(LOG_ERR, "ADL found more devices than opencl");
-			return;
+			applog(LOG_ERR, "ADL found more devices than opencl!");
+			applog(LOG_ERR, "There is possibly at least one GPU that doesn't support OpenCL");
+			devs_match = false;
+			devices = nDevs;
+			break;
 		}
 		last_adapter = lpAdapterID;
 
@@ -256,24 +263,36 @@ void init_adl(int nDevs)
 		}
 	}
 
-	/* Windows has some kind of random ordering for bus number IDs and
-	 * ordering the GPUs according to ascending order fixes it. Linux
-	 * has usually sequential but decreasing order instead! */
-	for (i = 0; i < devices; i++) {
-		int j, virtual_gpu = 0;
+	if (devs_match && devices == nDevs) {
+		/* Windows has some kind of random ordering for bus number IDs and
+		 * ordering the GPUs according to ascending order fixes it. Linux
+		 * has usually sequential but decreasing order instead! */
+		for (i = 0; i < devices; i++) {
+			int j, virtual_gpu = 0;
 
-		for (j = 0; j < devices; j++) {
-			if (i == j)
-				continue;
+			for (j = 0; j < devices; j++) {
+				if (i == j)
+					continue;
 #ifdef WIN32
-			if (adapters[j].iBusNumber < adapters[i].iBusNumber)
+				if (adapters[j].iBusNumber < adapters[i].iBusNumber)
 #else
-			if (adapters[j].iBusNumber > adapters[i].iBusNumber)
+				if (adapters[j].iBusNumber > adapters[i].iBusNumber)
 #endif
-				virtual_gpu++;
+					virtual_gpu++;
+			}
+			if (virtual_gpu != i)
+				applog(LOG_INFO, "Mapping device %d to GPU %d according to Bus Number order",
+				       i, virtual_gpu);
+			vadapters[virtual_gpu].virtual_gpu = i;
+			vadapters[virtual_gpu].id = adapters[i].id;
 		}
-		vadapters[virtual_gpu].virtual_gpu = i;
-		vadapters[virtual_gpu].id = adapters[i].id;
+	} else {
+		if (devices < nDevs) {
+			applog(LOG_ERR, "ADL found less devices than opencl!");
+			applog(LOG_ERR, "There is possibly more than one display attached to a GPU");
+		}
+		applog(LOG_ERR, "WARNING: Number of OpenCL and ADL devices does not match!");
+		applog(LOG_ERR, "Hardware monitoring may NOT match up with devices!");
 	}
 
 	for (gpu = 0; gpu < devices; gpu++) {
@@ -288,8 +307,9 @@ void init_adl(int nDevs)
 		gpus[gpu].virtual_gpu = vadapters[gpu].virtual_gpu;
 
 		/* Get unique identifier of the adapter, 0 means not AMD */
-		if (ADL_Adapter_ID_Get(iAdapterIndex, &lpAdapterID) != ADL_OK) {
-			applog(LOG_INFO, "Failed to ADL_Adapter_ID_Get");
+		result = ADL_Adapter_ID_Get(iAdapterIndex, &lpAdapterID);
+		if (result != ADL_OK) {
+			applog(LOG_INFO, "Failed to ADL_Adapter_ID_Get. Error %d", result);
 			continue;
 		}
 
@@ -302,6 +322,7 @@ void init_adl(int nDevs)
 			continue;
 		}
 
+		applog(LOG_INFO, "GPU %d %s hardware monitoring enabled", gpu, lpInfo[i].strAdapterName);
 		gpus[gpu].has_adl = true;
 		/* Flag adl as active if any card is successfully activated */
 		adl_active = true;
@@ -316,10 +337,6 @@ void init_adl(int nDevs)
 		ga->DefPerfLev = NULL;
 		ga->twin = NULL;
 
-		ga->lpThermalControllerInfo.iSize=sizeof(ADLThermalControllerInfo);
-		if (ADL_Overdrive5_ThermalDevices_Enum(iAdapterIndex, 0, &ga->lpThermalControllerInfo) != ADL_OK)
-			applog(LOG_INFO, "Failed to ADL_Overdrive5_ThermalDevices_Enum");
-
 		ga->lpOdParameters.iSize = sizeof(ADLODParameters);
 		if (ADL_Overdrive5_ODParameters_Get(iAdapterIndex, &ga->lpOdParameters) != ADL_OK)
 			applog(LOG_INFO, "Failed to ADL_Overdrive5_ODParameters_Get");
@@ -1136,8 +1153,9 @@ void change_autosettings(int gpu)
 	}
 }
 
-void change_gpusettings(int gpu)
+void change_gpusettings(int disp_gpu)
 {
+	int gpu = gpus[disp_gpu].virtual_gpu;
 	struct gpu_adl *ga = &gpus[gpu].adl;
 	float fval, fmin = 0, fmax = 0;
 	int val, imin = 0, imax = 0;
diff --git a/adl.h b/adl.h
index 50bd5b8..8e54983 100644
--- a/adl.h
+++ b/adl.h
@@ -16,13 +16,13 @@ int gpu_fanspeed(int gpu);
 int gpu_fanpercent(int gpu);
 bool gpu_stats(int gpu, float *temp, int *engineclock, int *memclock, float *vddc,
 	       int *activity, int *fanspeed, int *fanpercent, int *powertune);
-void change_gpusettings(int gpu);
+void change_gpusettings(int disp_gpu);
 void gpu_autotune(int gpu, bool *enable);
 void clear_adl(int nDevs);
 #else /* HAVE_ADL */
 #define adl_active (0)
 static inline void init_adl(int nDevs) {}
-static inline void change_gpusettings(int gpu) { }
+static inline void change_gpusettings(int disp_gpu) { }
 static inline void clear_adl(int nDevs) {}
 #endif
 #endif
diff --git a/main.c b/main.c
index 0995172..713253c 100644
--- a/main.c
+++ b/main.c
@@ -997,11 +997,13 @@ static char *set_float_0_to_99(const char *arg, float *f)
 	return NULL;
 }
 
+#ifdef USE_BITFORCE
 static char *add_serial(char *arg)
 {
 	string_elist_add(arg, &scan_devices);
 	return NULL;
 }
+#endif
 
 static char *set_devices(char *arg)
 {
@@ -2329,7 +2331,7 @@ static bool submit_upstream_work(const struct work *work)
 		curl_easy_setopt(curl, CURLOPT_FRESH_CONNECT, 1);
 
 	/* issue JSON-RPC request */
-	val = json_rpc_call(curl, pool->rpc_url, pool->rpc_userpass, s, false, false, &rolltime, pool);
+	val = json_rpc_call(curl, pool->rpc_url, pool->rpc_userpass, s, false, false, &rolltime, pool, true);
 	if (unlikely(!val)) {
 		applog(LOG_INFO, "submit_upstream_work json_rpc_call failed");
 		if (!pool_tset(pool, &pool->submit_fail)) {
@@ -2480,7 +2482,7 @@ retry:
 	 * failure so retry a few times before giving up */
 	while (!val && retries++ < 3) {
 		val = json_rpc_call(curl, pool->rpc_url, pool->rpc_userpass, rpc_req,
-			    false, false, &work->rolltime, pool);
+			    false, false, &work->rolltime, pool, false);
 		if (donor(pool) && !val) {
 			if (opt_debug)
 				applog(LOG_DEBUG, "Donor pool lagging");
@@ -3991,7 +3993,7 @@ static bool pool_active(struct pool *pool, bool pinging)
 
 	applog(LOG_INFO, "Testing pool %s", pool->rpc_url);
 	val = json_rpc_call(curl, pool->rpc_url, pool->rpc_userpass, rpc_req,
-			true, false, &rolltime, pool);
+			true, false, &rolltime, pool, false);
 
 	if (val) {
 		struct work *work = make_work();
@@ -4719,7 +4721,7 @@ new_longpoll:
 	while (1) {
 		gettimeofday(&start, NULL);
 		val = json_rpc_call(curl, lp_url, pool->rpc_userpass, rpc_req,
-				    false, true, &rolltime, pool);
+				    false, true, &rolltime, pool, false);
 		if (likely(val)) {
 			convert_to_work(val, rolltime, pool);
 			failures = 0;
diff --git a/miner.h b/miner.h
index cfc5ec9..fcef5e5 100644
--- a/miner.h
+++ b/miner.h
@@ -207,7 +207,6 @@ struct gpu_adl {
 	ADLFanSpeedInfo lpFanSpeedInfo;
 	ADLFanSpeedValue lpFanSpeedValue;
 	ADLFanSpeedValue DefFanSpeedValue;
-	ADLThermalControllerInfo lpThermalControllerInfo;
 
 	int iEngineClock;
 	int iMemoryClock;
@@ -454,7 +453,7 @@ extern pthread_rwlock_t netacc_lock;
 extern const uint32_t sha256_init_state[];
 extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass,
 			     const char *rpc_req, bool, bool, bool *,
-			     struct pool *pool);
+			     struct pool *pool, bool);
 extern char *bin2hex(const unsigned char *p, size_t len);
 extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len);
 
diff --git a/util.c b/util.c
index aab5070..733d8ad 100644
--- a/util.c
+++ b/util.c
@@ -305,7 +305,7 @@ static void set_nettime(void)
 json_t *json_rpc_call(CURL *curl, const char *url,
 		      const char *userpass, const char *rpc_req,
 		      bool probe, bool longpoll, bool *rolltime,
-		      struct pool *pool)
+		      struct pool *pool, bool share)
 {
 	json_t *val, *err_val, *res_val;
 	int rc;
@@ -336,7 +336,7 @@ json_t *json_rpc_call(CURL *curl, const char *url,
 	curl_easy_setopt(curl, CURLOPT_URL, url);
 	curl_easy_setopt(curl, CURLOPT_ENCODING, "");
 	curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
-	if (!opt_delaynet)
+	if (!opt_delaynet || share)
 		curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 1);
 	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, all_data_cb);
 	curl_easy_setopt(curl, CURLOPT_WRITEDATA, &all_data);
@@ -380,7 +380,7 @@ json_t *json_rpc_call(CURL *curl, const char *url,
 
 	curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
 
-	if (opt_delaynet) {
+	if (opt_delaynet && !share) {
 		long long now_msecs, last_msecs;
 		struct timeval now, last;