Browse Source

Merge commit 'd143c27' into hotplug

Luke Dashjr 12 years ago
parent
commit
f104b3e904
3 changed files with 40 additions and 38 deletions
  1. 21 14
      api.c
  2. 18 12
      miner.c
  3. 1 12
      miner.h

+ 21 - 14
api.c

@@ -1204,13 +1204,17 @@ static int pgadevice(int pgaid)
 			continue;
 			continue;
 #endif
 #endif
 		++count;
 		++count;
-		if (count == (pgaid + 1)) {
-			mutex_unlock(&devices_lock);
-			return i;
-		}
+		if (count == (pgaid + 1))
+			goto foundit;
 	}
 	}
+
 	mutex_unlock(&devices_lock);
 	mutex_unlock(&devices_lock);
 	return -1;
 	return -1;
+
+foundit:
+
+	mutex_unlock(&devices_lock);
+	return i;
 }
 }
 #endif
 #endif
 
 
@@ -1574,7 +1578,7 @@ static void pgastatus(struct io_data *io_data, int pga, bool isjson, bool precom
         int dev = pgadevice(pga);
         int dev = pgadevice(pga);
         if (dev < 0) // Should never happen
         if (dev < 0) // Should never happen
                 return;
                 return;
-        devstatus_an(io_data, get_proc_by_id(dev), isjson, precom);
+        devstatus_an(io_data, get_devices(dev), isjson, precom);
 }
 }
 #endif
 #endif
 
 
@@ -1604,7 +1608,7 @@ devinfo_internal(void (*func)(struct io_data *, struct cgpu_info*, bool, bool),
 		io_open = io_add(io_data, COMSTR JSON_DEVS);
 		io_open = io_add(io_data, COMSTR JSON_DEVS);
 
 
 	for (i = 0; i < total_devices; ++i) {
 	for (i = 0; i < total_devices; ++i) {
-		func(io_data, get_proc_by_id(i), isjson, isjson && i > 0);
+		func(io_data, get_devices(i), isjson, isjson && i > 0);
 	}
 	}
 
 
 	if (isjson && io_open)
 	if (isjson && io_open)
@@ -1717,7 +1721,7 @@ static void pgaenable(struct io_data *io_data, __maybe_unused SOCKETTYPE c, char
 		return;
 		return;
 	}
 	}
 
 
-	cgpu = get_proc_by_id(dev);
+	cgpu = get_devices(dev);
 
 
 	applog(LOG_DEBUG, "API: request to pgaenable pgaid %d device %d %s",
 	applog(LOG_DEBUG, "API: request to pgaenable pgaid %d device %d %s",
 			id, dev, cgpu->proc_repr_ns);
 			id, dev, cgpu->proc_repr_ns);
@@ -1767,7 +1771,7 @@ static void pgadisable(struct io_data *io_data, __maybe_unused SOCKETTYPE c, cha
 		return;
 		return;
 	}
 	}
 
 
-	cgpu = get_proc_by_id(dev);
+	cgpu = get_devices(dev);
 
 
 	applog(LOG_DEBUG, "API: request to pgadisable pgaid %d device %d %s",
 	applog(LOG_DEBUG, "API: request to pgadisable pgaid %d device %d %s",
 			id, dev, cgpu->proc_repr_ns);
 			id, dev, cgpu->proc_repr_ns);
@@ -1811,7 +1815,7 @@ static void pgaidentify(struct io_data *io_data, __maybe_unused SOCKETTYPE c, ch
 		return;
 		return;
 	}
 	}
 
 
-	cgpu = get_proc_by_id(dev);
+	cgpu = get_devices(dev);
 	api = cgpu->api;
 	api = cgpu->api;
 
 
 	if (api->identify_device && api->identify_device(cgpu))
 	if (api->identify_device && api->identify_device(cgpu))
@@ -2667,6 +2671,7 @@ void notifystatus(struct io_data *io_data, int device, struct cgpu_info *cgpu, b
 
 
 static void notify(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __maybe_unused char *param, bool isjson, char group)
 static void notify(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __maybe_unused char *param, bool isjson, char group)
 {
 {
+	struct cgpu_info *cgpu;
 	bool io_open = false;
 	bool io_open = false;
 	int i;
 	int i;
 
 
@@ -2680,8 +2685,10 @@ static void notify(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __maybe
 	if (isjson)
 	if (isjson)
 		io_open = io_add(io_data, COMSTR JSON_NOTIFY);
 		io_open = io_add(io_data, COMSTR JSON_NOTIFY);
 
 
-	for (i = 0; i < total_devices; i++)
-		notifystatus(io_data, i, get_proc_by_id(i), isjson, group);
+	for (i = 0; i < total_devices; i++) {
+		cgpu = get_devices(i);
+		notifystatus(io_data, i, cgpu, isjson, group);
+	}
 
 
 	if (isjson && io_open)
 	if (isjson && io_open)
 		io_close(io_data);
 		io_close(io_data);
@@ -2706,7 +2713,7 @@ static void devdetails(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __m
 		io_open = io_add(io_data, COMSTR JSON_DEVDETAILS);
 		io_open = io_add(io_data, COMSTR JSON_DEVDETAILS);
 
 
 	for (i = 0; i < total_devices; i++) {
 	for (i = 0; i < total_devices; i++) {
-		cgpu = get_proc_by_id(i);
+		cgpu = get_devices(i);
 
 
 		root = api_add_int(root, "DEVDETAILS", &i, false);
 		root = api_add_int(root, "DEVDETAILS", &i, false);
 		root = api_add_device_identifier(root, cgpu);
 		root = api_add_device_identifier(root, cgpu);
@@ -2815,7 +2822,7 @@ static void minerstats(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __m
 
 
 	i = 0;
 	i = 0;
 	for (j = 0; j < total_devices; j++) {
 	for (j = 0; j < total_devices; j++) {
-		cgpu = get_proc_by_id(j);
+		cgpu = get_devices(j);
 
 
 		if (cgpu && cgpu->api) {
 		if (cgpu && cgpu->api) {
 			if (cgpu->api->get_api_stats)
 			if (cgpu->api->get_api_stats)
@@ -3057,7 +3064,7 @@ static void pgaset(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __maybe
 		return;
 		return;
 	}
 	}
 
 
-	cgpu = get_proc_by_id(dev);
+	cgpu = get_devices(dev);
 	api = cgpu->api;
 	api = cgpu->api;
 
 
 	char *set = strchr(opt, ',');
 	char *set = strchr(opt, ',');

+ 18 - 12
miner.c

@@ -431,6 +431,16 @@ static struct cgpu_info *get_thr_cgpu(int thr_id)
 	return thr->cgpu;
 	return thr->cgpu;
 }
 }
 
 
+struct cgpu_info *get_devices(int id)
+{
+	struct cgpu_info *cgpu;
+
+	mutex_lock(&devices_lock);
+	cgpu = devices[id];
+	mutex_unlock(&devices_lock);
+	return cgpu;
+}
+
 static void sharelog(const char*disposition, const struct work*work)
 static void sharelog(const char*disposition, const struct work*work)
 {
 {
 	char *target, *hash, *data;
 	char *target, *hash, *data;
@@ -1010,7 +1020,7 @@ static void load_temp_config()
 	target_n = temp_target_str;
 	target_n = temp_target_str;
 
 
 	for (i = 0; i < total_devices; ++i) {
 	for (i = 0; i < total_devices; ++i) {
-		cgpu = get_proc_by_id(i);
+		cgpu = get_devices(i);
 		
 		
 		// cutoff default may be specified by driver during probe; otherwise, opt_cutofftemp (const)
 		// cutoff default may be specified by driver during probe; otherwise, opt_cutofftemp (const)
 		if (!cgpu->cutofftemp)
 		if (!cgpu->cutofftemp)
@@ -5199,7 +5209,7 @@ void zero_stats(void)
 	zero_bestshare();
 	zero_bestshare();
 
 
 	for (i = 0; i < total_devices; ++i) {
 	for (i = 0; i < total_devices; ++i) {
-		struct cgpu_info *cgpu = get_proc_by_id(i);
+		struct cgpu_info *cgpu = get_devices(i);
 
 
 		mutex_lock(&hash_lock);
 		mutex_lock(&hash_lock);
 		cgpu->total_mhashes = 0;
 		cgpu->total_mhashes = 0;
@@ -7410,7 +7420,7 @@ static void *watchdog_thread(void __maybe_unused *userdata)
 			
 			
 			for (i = 0; i < total_devices; ++i)
 			for (i = 0; i < total_devices; ++i)
 			{
 			{
-				struct cgpu_info *cgpu = get_proc_by_id(i);
+				struct cgpu_info *cgpu = get_devices(i);
 				
 				
 				/* Don't touch disabled devices */
 				/* Don't touch disabled devices */
 				if (cgpu->deven == DEV_DISABLED)
 				if (cgpu->deven == DEV_DISABLED)
@@ -7420,15 +7430,12 @@ static void *watchdog_thread(void __maybe_unused *userdata)
 		}
 		}
 
 
 		for (i = 0; i < total_devices; ++i) {
 		for (i = 0; i < total_devices; ++i) {
-			struct cgpu_info *cgpu;
-			struct thr_info *thr;
+			struct cgpu_info *cgpu = get_devices(i);
+			struct thr_info *thr = cgpu->thr[0];
 			enum dev_enable *denable;
 			enum dev_enable *denable;
 			char *dev_str = cgpu->proc_repr;
 			char *dev_str = cgpu->proc_repr;
 			int gpu;
 			int gpu;
 
 
-			cgpu = get_proc_by_id(i);
-			thr = cgpu->thr[0];
-			
 			if (cgpu->api->get_stats)
 			if (cgpu->api->get_stats)
 			  cgpu->api->get_stats(cgpu);
 			  cgpu->api->get_stats(cgpu);
 
 
@@ -7631,10 +7638,9 @@ void print_summary(void)
 	}
 	}
 
 
 	applog(LOG_WARNING, "Summary of per device statistics:\n");
 	applog(LOG_WARNING, "Summary of per device statistics:\n");
-	for (i = 0; i < total_devices; ++i)
-	{
-		struct cgpu_info *cgpu;
-		cgpu = get_proc_by_id(i);
+	for (i = 0; i < total_devices; ++i) {
+		struct cgpu_info *cgpu = get_devices(i);
+
 		if ((!cgpu->proc_id) && cgpu->next_proc)
 		if ((!cgpu->proc_id) && cgpu->next_proc)
 		{
 		{
 			// Device summary line
 			// Device summary line

+ 1 - 12
miner.h

@@ -1175,18 +1175,7 @@ extern void free_work(struct work *work);
 extern void __copy_work(struct work *work, const struct work *base_work);
 extern void __copy_work(struct work *work, const struct work *base_work);
 extern struct work *copy_work(const struct work *base_work);
 extern struct work *copy_work(const struct work *base_work);
 extern struct thr_info *get_thread(int thr_id);
 extern struct thr_info *get_thread(int thr_id);
-
-static inline
-struct cgpu_info *get_proc_by_id(int i)
-{
-	struct cgpu_info *proc;
-
-	mutex_lock(&devices_lock);
-	proc = devices[i];
-	mutex_unlock(&devices_lock);
-	return proc;
-}
-
+extern struct cgpu_info *get_devices(int id);
 
 
 enum api_data_type {
 enum api_data_type {
 	API_ESCAPE,
 	API_ESCAPE,