Change the --device parameter parsing and configuration to use ranges and comma separated values.
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
diff --git a/cgminer.c b/cgminer.c
index 3bf959f..1e6eef3 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -110,7 +110,9 @@ bool opt_restart = true;
static bool opt_nogpu;
struct list_head scan_devices;
-static signed int devices_enabled;
+static bool devices_enabled[MAX_DEVICES];
+static int opt_devs_enabled;
+static bool opt_display_devs;
static bool opt_removedisabled;
int total_devices;
struct cgpu_info **devices;
@@ -576,21 +578,52 @@ static char *add_serial(char *arg)
}
#endif
+void get_intrange(char *arg, int *val1, int *val2)
+{
+ if (sscanf(arg, "%d-%d", val1, val2) == 1)
+ *val2 = *val1;
+}
+
static char *set_devices(char *arg)
{
- int i = strtol(arg, &arg, 0);
+ int i, val1 = 0, val2 = 0;
+ char *nextptr;
if (*arg) {
if (*arg == '?') {
- devices_enabled = -1;
+ opt_display_devs = true;
return NULL;
}
- return "Invalid device number";
+ } else
+ return "Invalid device parameters";
+
+ nextptr = strtok(arg, ",");
+ if (nextptr == NULL)
+ return "Invalid parameters for set devices";
+ get_intrange(nextptr, &val1, &val2);
+ if (val1 < 0 || val1 > MAX_DEVICES || val2 < 0 || val2 > MAX_DEVICES ||
+ val1 > val2) {
+ return "Invalid value passed to set devices";
+ }
+
+ for (i = val1; i <= val2; i++) {
+ devices_enabled[i] = true;
+ opt_devs_enabled++;
+ }
+
+ while ((nextptr = strtok(NULL, ",")) != NULL) {
+ get_intrange(nextptr, &val1, &val2);
+ if (val1 < 0 || val1 > MAX_DEVICES || val2 < 0 || val2 > MAX_DEVICES ||
+ val1 > val2) {
+ return "Invalid value passed to set devices";
+ }
+
+ for (i = val1; i <= val2; i++) {
+ devices_enabled[i] = true;
+ opt_devs_enabled++;
+ }
}
- if (i < 0 || i >= (int)(sizeof(devices_enabled) * 8) - 1)
- return "Invalid device number";
- devices_enabled |= 1 << i;
return NULL;
}
@@ -921,7 +954,7 @@ static struct opt_table opt_config_table[] = {
"Enable debug output"),
OPT_WITH_ARG("--device|-d",
set_devices, NULL, NULL,
- "Select device to use, (Use repeat -d for multiple devices, default: all)"),
+ "Select device to use, one value, range and/or comma separated (e.g. 0-2,4) default: all"),
OPT_WITHOUT_ARG("--disable-gpu|-G",
opt_set_bool, &opt_nogpu,
#ifdef HAVE_OPENCL
@@ -4007,11 +4040,24 @@ void write_config(FILE *fcfg)
fprintf(fcfg, ",\n\"stop-time\" : \"%d:%d\"", schedstop.tm.tm_hour, schedstop.tm.tm_min);
if (opt_socks_proxy && *opt_socks_proxy)
fprintf(fcfg, ",\n\"socks-proxy\" : \"%s\"", json_escape(opt_socks_proxy));
- if (devices_enabled) {
- for (i = 0; i < (int)(sizeof(devices_enabled) * 8) - 1; ++i) {
- if (devices_enabled & (1 << i))
- fprintf(fcfg, ",\n\"device\" : \"%d\"", i);
+ if (opt_devs_enabled) {
+ fprintf(fcfg, ",\n\"device\" : \"");
+ bool extra_devs = false;
+
+ for (i = 0; i < MAX_DEVICES; i++) {
+ if (devices_enabled[i]) {
+ int startd = i;
+
+ if (extra_devs)
+ fprintf(fcfg, ",");
+ while (i < MAX_DEVICES && devices_enabled[i + 1])
+ ++i;
+ fprintf(fcfg, "%d", startd);
+ if (i > startd)
+ fprintf(fcfg, "-%d", i);
+ }
}
+ fprintf(fcfg, "\"");
}
if (opt_removedisabled)
fprintf(fcfg, ",\n\"remove-disabled\" : true");
@@ -7321,7 +7367,7 @@ int main(int argc, char *argv[])
}
#ifdef HAVE_CURSES
- if (opt_realquiet || devices_enabled == -1)
+ if (opt_realquiet || opt_display_devs)
use_curses = false;
if (use_curses)
@@ -7417,7 +7463,7 @@ int main(int argc, char *argv[])
avalon_drv.drv_detect();
#endif
- if (devices_enabled == -1) {
+ if (opt_display_devs) {
applog(LOG_ERR, "Devices detected:");
for (i = 0; i < total_devices; ++i) {
struct cgpu_info *cgpu = devices[i];
@@ -7430,9 +7476,9 @@ int main(int argc, char *argv[])
}
mining_threads = 0;
- if (devices_enabled) {
- for (i = 0; i < (int)(sizeof(devices_enabled) * 8) - 1; ++i) {
- if (devices_enabled & (1 << i)) {
+ if (opt_devs_enabled) {
+ for (i = 0; i < MAX_DEVICES; i++) {
+ if (devices_enabled[i]) {
if (i >= total_devices)
quit (1, "Command line options set a device that doesn't exist");
enable_device(devices[i]);
diff --git a/driver-opencl.c b/driver-opencl.c
index a1fef8b..501b411 100644
--- a/driver-opencl.c
+++ b/driver-opencl.c
@@ -285,14 +285,6 @@ char *set_gpu_map(char *arg)
return NULL;
}
-void get_intrange(char *arg, int *val1, int *val2)
-{
- if (sscanf(arg, "%d-%d", val1, val2) == 1) {
- *val2 = *val1;
- *val1 = 0;
- }
-}
-
char *set_gpu_engine(char *arg)
{
int i, val1 = 0, val2 = 0, device = 0;
diff --git a/miner.h b/miner.h
index 410df53..63b387f 100644
--- a/miner.h
+++ b/miner.h
@@ -919,12 +919,14 @@ extern void api(int thr_id);
extern struct pool *current_pool(void);
extern int enabled_pools;
+extern void get_intrange(char *arg, int *val1, int *val2);
extern bool detect_stratum(struct pool *pool, char *url);
extern void print_summary(void);
extern struct pool *add_pool(void);
extern bool add_pool_details(struct pool *pool, bool live, char *url, char *user, char *pass);
#define MAX_GPUDEVICES 16
+#define MAX_DEVICES 4096
#define MIN_INTENSITY -10
#define _MIN_INTENSITY_STR "-10"