Use macro expansion to iterate over all device drivers without needing to explicitly code in support in all places. Pass a hotplug bool to the detect() function to prevent opencl trying to hogplug GPUs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
diff --git a/cgminer.c b/cgminer.c
index 6fad18e..9f39a7e 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -119,7 +119,7 @@ bool opt_scrypt;
#endif
#endif
bool opt_restart = true;
-static bool opt_nogpu;
+bool opt_nogpu;
struct list_head scan_devices;
static bool devices_enabled[MAX_DEVICES];
@@ -7434,19 +7434,17 @@ static void noop_thread_enable(struct thr_info __maybe_unused *thr)
{
}
-static void noop_null(void)
+static void noop_detect(bool __maybe_unused hotplug)
{
}
#define noop_flush_work noop_reinit_device
#define noop_queue_full noop_get_stats
/* Fill missing driver drv functions with noops */
-void fill_device_drv(struct cgpu_info *cgpu)
+void fill_device_drv(struct device_drv *drv)
{
- struct device_drv *drv = cgpu->drv;
-
if (!drv->drv_detect)
- drv->drv_detect = &noop_null;
+ drv->drv_detect = &noop_detect;
if (!drv->reinit_device)
drv->reinit_device = &noop_reinit_device;
if (!drv->get_statline_before)
@@ -7544,8 +7542,6 @@ bool add_cgpu(struct cgpu_info *cgpu)
cgpu->last_device_valid_work = time(NULL);
mutex_unlock(&stats_lock);
- fill_device_drv(cgpu);
-
if (hotplug_mode)
devices[total_devices + new_devices++] = cgpu;
else
@@ -7655,29 +7651,11 @@ static void *hotplug_thread(void __maybe_unused *userdata)
new_devices = 0;
new_threads = 0;
-#ifdef USE_ICARUS
- icarus_drv.drv_detect();
-#endif
-
-#ifdef USE_BFLSC
- bflsc_drv.drv_detect();
-#endif
-
-#ifdef USE_BITFORCE
- bitforce_drv.drv_detect();
-#endif
-
-#ifdef USE_BITFURY
- bitfury_drv.drv_detect();
-#endif
-
-#ifdef USE_MODMINER
- modminer_drv.drv_detect();
-#endif
-
-#ifdef USE_AVALON
- avalon_drv.drv_detect();
-#endif
+ /* Use the DRIVER_PARSE_COMMANDS macro to detect all
+ * devices */
+#define DRIVER_ADD_COMMAND(X) X##_drv.drv_detect(true);
+ DRIVER_PARSE_COMMANDS
+#undef DRIVER_ADD_COMMAND
if (new_devices)
hotplug_process();
@@ -7883,48 +7861,20 @@ int main(int argc, char *argv[])
}
#endif
-#ifdef HAVE_OPENCL
- if (!opt_nogpu)
- opencl_drv.drv_detect();
- gpu_threads = 0;
-#endif
+ /* Use the DRIVER_PARSE_COMMANDS macro to fill all the device_drvs */
+#define DRIVER_ADD_COMMAND(X) fill_device_drv(&X##_drv);
+ DRIVER_PARSE_COMMANDS
+#undef DRIVER_ADD_COMMAND
-#ifdef USE_ICARUS
- if (!opt_scrypt)
- icarus_drv.drv_detect();
-#endif
-
-#ifdef USE_BFLSC
- if (!opt_scrypt)
- bflsc_drv.drv_detect();
-#endif
-
-#ifdef USE_BITFORCE
- if (!opt_scrypt)
- bitforce_drv.drv_detect();
-#endif
-
-#ifdef USE_BITFURY
- if (!opt_scrypt)
- bitfury_drv.drv_detect();
-#endif
-
-#ifdef USE_MODMINER
- if (!opt_scrypt)
- modminer_drv.drv_detect();
-#endif
-
-#ifdef USE_ZTEX
- if (!opt_scrypt)
- ztex_drv.drv_detect();
-#endif
-
- /* Detect avalon last since it will try to claim the device regardless
- * as detection is unreliable. */
-#ifdef USE_AVALON
- if (!opt_scrypt)
- avalon_drv.drv_detect();
-#endif
+ if (opt_scrypt)
+ opencl_drv.drv_detect(false);
+ else {
+ /* Use the DRIVER_PARSE_COMMANDS macro to detect all devices */
+#define DRIVER_ADD_COMMAND(X) X##_drv.drv_detect(false);
+ DRIVER_PARSE_COMMANDS
+#undef DRIVER_ADD_COMMAND
+ }
+ gpu_threads = 0;
if (opt_display_devs) {
applog(LOG_ERR, "Devices detected:");
diff --git a/driver-avalon.c b/driver-avalon.c
index d6cd71d..6abdaeb 100644
--- a/driver-avalon.c
+++ b/driver-avalon.c
@@ -799,7 +799,7 @@ shin:
return false;
}
-static void avalon_detect(void)
+static void avalon_detect(bool __maybe_unused hotplug)
{
usb_detect(&avalon_drv, avalon_detect_one);
}
diff --git a/driver-bflsc.c b/driver-bflsc.c
index 5ace03d..bebed38 100644
--- a/driver-bflsc.c
+++ b/driver-bflsc.c
@@ -893,7 +893,7 @@ shin:
return false;
}
-static void bflsc_detect(void)
+static void bflsc_detect(bool __maybe_unused hotplug)
{
usb_detect(&bflsc_drv, bflsc_detect_one);
}
diff --git a/driver-bitforce.c b/driver-bitforce.c
index f28dc1e..6cd0d52 100644
--- a/driver-bitforce.c
+++ b/driver-bitforce.c
@@ -288,7 +288,7 @@ shin:
return false;
}
-static void bitforce_detect(void)
+static void bitforce_detect(bool __maybe_unused hotplug)
{
usb_detect(&bitforce_drv, bitforce_detect_one);
}
diff --git a/driver-bitfury.c b/driver-bitfury.c
index 0d72b91..9708fe6 100644
--- a/driver-bitfury.c
+++ b/driver-bitfury.c
@@ -150,7 +150,7 @@ out:
return false;
}
-static void bitfury_detect(void)
+static void bitfury_detect(bool __maybe_unused hotplug)
{
usb_detect(&bitfury_drv, bitfury_detect_one);
}
diff --git a/driver-icarus.c b/driver-icarus.c
index 0773ad5..a42988b 100644
--- a/driver-icarus.c
+++ b/driver-icarus.c
@@ -926,7 +926,7 @@ shin:
return false;
}
-static void icarus_detect()
+static void icarus_detect(bool __maybe_unused hotplug)
{
usb_detect(&icarus_drv, icarus_detect_one);
}
diff --git a/driver-modminer.c b/driver-modminer.c
index 3a80986..0672c99 100644
--- a/driver-modminer.c
+++ b/driver-modminer.c
@@ -237,7 +237,7 @@ shin:
return false;
}
-static void modminer_detect()
+static void modminer_detect(bool __maybe_unused hotplug)
{
usb_detect(&modminer_drv, modminer_detect_one);
}
diff --git a/driver-opencl.c b/driver-opencl.c
index b6ad37d..d7b663a 100644
--- a/driver-opencl.c
+++ b/driver-opencl.c
@@ -581,7 +581,7 @@ char *set_intensity(char *arg)
void print_ndevs(int *ndevs)
{
opt_log_output = true;
- opencl_drv.drv_detect();
+ opencl_drv.drv_detect(false);
clear_adl(*ndevs);
applog(LOG_INFO, "%i GPU devices max detected", *ndevs);
}
@@ -1227,10 +1227,12 @@ void *reinit_gpu(__maybe_unused void *userdata)
#ifdef HAVE_OPENCL
-static void opencl_detect()
+static void opencl_detect(bool hotplug)
{
int i;
+ if (opt_nogpu || hotplug)
+ return;
nDevs = clDevicesNum();
if (nDevs < 0) {
applog(LOG_ERR, "clDevicesNum returned error, no GPUs usable");
diff --git a/driver-ztex.c b/driver-ztex.c
index f806717..ee0c0a9 100644
--- a/driver-ztex.c
+++ b/driver-ztex.c
@@ -52,7 +52,7 @@ static void ztex_releaseFpga(struct libztex_device* ztex)
}
}
-static void ztex_detect(void)
+static void ztex_detect(bool __maybe_unused hotplug)
{
int cnt;
int i,j;
diff --git a/miner.h b/miner.h
index 1dddf3d..be92b83 100644
--- a/miner.h
+++ b/miner.h
@@ -329,7 +329,7 @@ struct device_drv {
char *name;
// DRV-global functions
- void (*drv_detect)();
+ void (*drv_detect)(bool);
// Device-specific functions
void (*reinit_device)(struct cgpu_info *);
@@ -914,6 +914,7 @@ extern bool opt_api_listen;
extern bool opt_api_network;
extern bool opt_delaynet;
extern bool opt_restart;
+extern bool opt_nogpu;
extern char *opt_icarus_options;
extern char *opt_icarus_timing;
extern bool opt_worktime;