Browse Source

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.

nfactor-troky
ckolivas 11 years ago
parent
commit
6d7471237d
  1. 94
      cgminer.c
  2. 2
      driver-avalon.c
  3. 2
      driver-bflsc.c
  4. 2
      driver-bitforce.c
  5. 2
      driver-bitfury.c
  6. 2
      driver-icarus.c
  7. 2
      driver-modminer.c
  8. 6
      driver-opencl.c
  9. 2
      driver-ztex.c
  10. 3
      miner.h

94
cgminer.c

@ -119,7 +119,7 @@ bool opt_scrypt;
#endif #endif
#endif #endif
bool opt_restart = true; bool opt_restart = true;
static bool opt_nogpu; bool opt_nogpu;
struct list_head scan_devices; struct list_head scan_devices;
static bool devices_enabled[MAX_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_flush_work noop_reinit_device
#define noop_queue_full noop_get_stats #define noop_queue_full noop_get_stats
/* Fill missing driver drv functions with noops */ /* 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) if (!drv->drv_detect)
drv->drv_detect = &noop_null; drv->drv_detect = &noop_detect;
if (!drv->reinit_device) if (!drv->reinit_device)
drv->reinit_device = &noop_reinit_device; drv->reinit_device = &noop_reinit_device;
if (!drv->get_statline_before) if (!drv->get_statline_before)
@ -7544,8 +7542,6 @@ bool add_cgpu(struct cgpu_info *cgpu)
cgpu->last_device_valid_work = time(NULL); cgpu->last_device_valid_work = time(NULL);
mutex_unlock(&stats_lock); mutex_unlock(&stats_lock);
fill_device_drv(cgpu);
if (hotplug_mode) if (hotplug_mode)
devices[total_devices + new_devices++] = cgpu; devices[total_devices + new_devices++] = cgpu;
else else
@ -7655,29 +7651,11 @@ static void *hotplug_thread(void __maybe_unused *userdata)
new_devices = 0; new_devices = 0;
new_threads = 0; new_threads = 0;
#ifdef USE_ICARUS /* Use the DRIVER_PARSE_COMMANDS macro to detect all
icarus_drv.drv_detect(); * devices */
#endif #define DRIVER_ADD_COMMAND(X) X##_drv.drv_detect(true);
DRIVER_PARSE_COMMANDS
#ifdef USE_BFLSC #undef DRIVER_ADD_COMMAND
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
if (new_devices) if (new_devices)
hotplug_process(); hotplug_process();
@ -7883,48 +7861,20 @@ int main(int argc, char *argv[])
} }
#endif #endif
#ifdef HAVE_OPENCL /* Use the DRIVER_PARSE_COMMANDS macro to fill all the device_drvs */
if (!opt_nogpu) #define DRIVER_ADD_COMMAND(X) fill_device_drv(&X##_drv);
opencl_drv.drv_detect(); DRIVER_PARSE_COMMANDS
gpu_threads = 0; #undef DRIVER_ADD_COMMAND
#endif
#ifdef USE_ICARUS if (opt_scrypt)
if (!opt_scrypt) opencl_drv.drv_detect(false);
icarus_drv.drv_detect(); else {
#endif /* Use the DRIVER_PARSE_COMMANDS macro to detect all devices */
#define DRIVER_ADD_COMMAND(X) X##_drv.drv_detect(false);
#ifdef USE_BFLSC DRIVER_PARSE_COMMANDS
if (!opt_scrypt) #undef DRIVER_ADD_COMMAND
bflsc_drv.drv_detect(); }
#endif gpu_threads = 0;
#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_display_devs) { if (opt_display_devs) {
applog(LOG_ERR, "Devices detected:"); applog(LOG_ERR, "Devices detected:");

2
driver-avalon.c

@ -799,7 +799,7 @@ shin:
return false; return false;
} }
static void avalon_detect(void) static void avalon_detect(bool __maybe_unused hotplug)
{ {
usb_detect(&avalon_drv, avalon_detect_one); usb_detect(&avalon_drv, avalon_detect_one);
} }

2
driver-bflsc.c

@ -893,7 +893,7 @@ shin:
return false; return false;
} }
static void bflsc_detect(void) static void bflsc_detect(bool __maybe_unused hotplug)
{ {
usb_detect(&bflsc_drv, bflsc_detect_one); usb_detect(&bflsc_drv, bflsc_detect_one);
} }

2
driver-bitforce.c

@ -288,7 +288,7 @@ shin:
return false; return false;
} }
static void bitforce_detect(void) static void bitforce_detect(bool __maybe_unused hotplug)
{ {
usb_detect(&bitforce_drv, bitforce_detect_one); usb_detect(&bitforce_drv, bitforce_detect_one);
} }

2
driver-bitfury.c

@ -150,7 +150,7 @@ out:
return false; return false;
} }
static void bitfury_detect(void) static void bitfury_detect(bool __maybe_unused hotplug)
{ {
usb_detect(&bitfury_drv, bitfury_detect_one); usb_detect(&bitfury_drv, bitfury_detect_one);
} }

2
driver-icarus.c

@ -926,7 +926,7 @@ shin:
return false; return false;
} }
static void icarus_detect() static void icarus_detect(bool __maybe_unused hotplug)
{ {
usb_detect(&icarus_drv, icarus_detect_one); usb_detect(&icarus_drv, icarus_detect_one);
} }

2
driver-modminer.c

@ -237,7 +237,7 @@ shin:
return false; return false;
} }
static void modminer_detect() static void modminer_detect(bool __maybe_unused hotplug)
{ {
usb_detect(&modminer_drv, modminer_detect_one); usb_detect(&modminer_drv, modminer_detect_one);
} }

6
driver-opencl.c

@ -581,7 +581,7 @@ char *set_intensity(char *arg)
void print_ndevs(int *ndevs) void print_ndevs(int *ndevs)
{ {
opt_log_output = true; opt_log_output = true;
opencl_drv.drv_detect(); opencl_drv.drv_detect(false);
clear_adl(*ndevs); clear_adl(*ndevs);
applog(LOG_INFO, "%i GPU devices max detected", *ndevs); applog(LOG_INFO, "%i GPU devices max detected", *ndevs);
} }
@ -1227,10 +1227,12 @@ void *reinit_gpu(__maybe_unused void *userdata)
#ifdef HAVE_OPENCL #ifdef HAVE_OPENCL
static void opencl_detect() static void opencl_detect(bool hotplug)
{ {
int i; int i;
if (opt_nogpu || hotplug)
return;
nDevs = clDevicesNum(); nDevs = clDevicesNum();
if (nDevs < 0) { if (nDevs < 0) {
applog(LOG_ERR, "clDevicesNum returned error, no GPUs usable"); applog(LOG_ERR, "clDevicesNum returned error, no GPUs usable");

2
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 cnt;
int i,j; int i,j;

3
miner.h

@ -329,7 +329,7 @@ struct device_drv {
char *name; char *name;
// DRV-global functions // DRV-global functions
void (*drv_detect)(); void (*drv_detect)(bool);
// Device-specific functions // Device-specific functions
void (*reinit_device)(struct cgpu_info *); void (*reinit_device)(struct cgpu_info *);
@ -914,6 +914,7 @@ extern bool opt_api_listen;
extern bool opt_api_network; extern bool opt_api_network;
extern bool opt_delaynet; extern bool opt_delaynet;
extern bool opt_restart; extern bool opt_restart;
extern bool opt_nogpu;
extern char *opt_icarus_options; extern char *opt_icarus_options;
extern char *opt_icarus_timing; extern char *opt_icarus_timing;
extern bool opt_worktime; extern bool opt_worktime;

Loading…
Cancel
Save