Browse Source

fix broken disabled devices when remove-disabled is set

djm34
Jan Berdajs 11 years ago
parent
commit
1c2de13498
  1. 20
      api.c
  2. 44
      sgminer.c

20
api.c

@ -2507,7 +2507,7 @@ static void notify(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __maybe @@ -2507,7 +2507,7 @@ static void notify(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __maybe
{
struct cgpu_info *cgpu;
bool io_open = false;
int i;
int i, j;
if (total_devices == 0) {
message(io_data, MSG_NODEVS, 0, NULL, isjson);
@ -2519,9 +2519,10 @@ static void notify(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __maybe @@ -2519,9 +2519,10 @@ static void notify(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __maybe
if (isjson)
io_open = io_add(io_data, COMSTR JSON_NOTIFY);
for (i = 0; i < total_devices; i++) {
for (i = 0, j = 0; i < total_devices; i++) {
cgpu = get_devices(i);
notifystatus(io_data, i, cgpu, isjson, group);
if (!opt_removedisabled || cgpu->deven != DEV_DISABLED)
notifystatus(io_data, j++, cgpu, isjson, group);
}
if (isjson && io_open)
@ -2534,7 +2535,7 @@ static void devdetails(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __m @@ -2534,7 +2535,7 @@ static void devdetails(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __m
char buf[TMPBUFSIZ];
bool io_open = false;
struct cgpu_info *cgpu;
int i;
int i, j;
if (total_devices == 0) {
message(io_data, MSG_NODEVS, 0, NULL, isjson);
@ -2546,10 +2547,12 @@ static void devdetails(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __m @@ -2546,10 +2547,12 @@ static void devdetails(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __m
if (isjson)
io_open = io_add(io_data, COMSTR JSON_DEVDETAILS);
for (i = 0; i < total_devices; i++) {
for (i = 0, j = 0; i < total_devices; i++) {
cgpu = get_devices(i);
root = api_add_int(root, "DEVDETAILS", &i, false);
if (opt_removedisabled && cgpu->deven == DEV_DISABLED) continue;
root = api_add_int(root, "DEVDETAILS", &j, false);
root = api_add_string(root, "Name", cgpu->drv->name, false);
root = api_add_int(root, "ID", &(cgpu->device_id), false);
root = api_add_string(root, "Driver", cgpu->drv->dname, false);
@ -2557,8 +2560,9 @@ static void devdetails(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __m @@ -2557,8 +2560,9 @@ static void devdetails(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __m
root = api_add_const(root, "Model", cgpu->name ? cgpu->name : BLANK, false);
root = api_add_const(root, "Device Path", cgpu->device_path ? cgpu->device_path : BLANK, false);
root = print_data(root, buf, isjson, isjson && (i > 0));
root = print_data(root, buf, isjson, isjson && (j > 0));
io_add(io_data, buf);
j++;
}
if (isjson && io_open)
@ -2659,7 +2663,7 @@ static void minerstats(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __m @@ -2659,7 +2663,7 @@ static void minerstats(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __m
for (j = 0; j < total_devices; j++) {
cgpu = get_devices(j);
if (cgpu && cgpu->drv) {
if (cgpu && cgpu->drv && (!opt_removedisabled || cgpu->deven != DEV_DISABLED)) {
if (cgpu->drv->get_api_stats)
extra = cgpu->drv->get_api_stats(cgpu);
else

44
sgminer.c

@ -203,7 +203,6 @@ int total_devices; @@ -203,7 +203,6 @@ int total_devices;
static int most_devices;
struct cgpu_info **devices;
int mining_threads;
static int sgminer_id_count = 0;
#ifdef HAVE_CURSES
bool use_curses = true;
@ -507,7 +506,7 @@ struct cgpu_info *get_devices(int id) @@ -507,7 +506,7 @@ struct cgpu_info *get_devices(int id)
return cgpu;
}
void enable_device(struct cgpu_info *cgpu);
void enable_device(int i);
static void sharelog(const char*disposition, const struct work*work)
{
@ -5983,21 +5982,15 @@ static void enable_devices(void) @@ -5983,21 +5982,15 @@ static void enable_devices(void)
int i;
//enable/disable devices as needed
sgminer_id_count = 0;
if(opt_devs_enabled)
{
for (i = 0; i < total_devices; i++)
{
//device should be enabled
if(devices_enabled[i])
enable_device(devices[i]);
enable_device(i);
else
{
//if option is set to not remove disabled, enable device
if(!opt_removedisabled)
enable_device(devices[i]);
//mark as disabled
devices[i]->deven = DEV_DISABLED;
}
@ -6007,7 +6000,7 @@ static void enable_devices(void) @@ -6007,7 +6000,7 @@ static void enable_devices(void)
else
{
for (i = 0; i < total_devices; ++i)
enable_device(devices[i]);
enable_device(i);
}
}
@ -6030,12 +6023,8 @@ static void apply_initial_gpu_settings(struct pool *pool) @@ -6030,12 +6023,8 @@ static void apply_initial_gpu_settings(struct pool *pool)
//assign pool devices if any
if(!empty_string((opt = get_pool_setting(pool->devices, ((!empty_string(default_profile.devices))?default_profile.devices:"all"))))) {
if (opt_removedisabled) {
applog(LOG_ERR, "Changing enabled devices is not possible when remove-disabled is set.");
} else {
set_devices((char *)opt);
}
}
//lookup gap
if(!empty_string((opt = get_pool_setting(pool->lookup_gap, default_profile.lookup_gap))))
@ -6373,13 +6362,9 @@ static void get_work_prepare_thread(struct thr_info *mythr, struct work *work) @@ -6373,13 +6362,9 @@ static void get_work_prepare_thread(struct thr_info *mythr, struct work *work)
//assign pool devices if any
if(!empty_string((opt = get_pool_setting(work->pool->devices, ((!empty_string(default_profile.devices))?default_profile.devices:"all"))))) {
if (opt_removedisabled) {
applog(LOG_ERR, "Changing enabled devices is not possible when remove-disabled is set.");
} else {
set_devices((char *)opt);
}
}
}
//lookup gap
if(opt_isset(options, SWITCHER_APPLY_LG))
@ -7375,7 +7360,8 @@ static void *watchdog_thread(void __maybe_unused *userdata) @@ -7375,7 +7360,8 @@ static void *watchdog_thread(void __maybe_unused *userdata)
count = 0;
for (i = 0; i < total_devices; i++) {
cgpu = get_devices(i);
if (cgpu) curses_print_devstatus(cgpu, count++);
if (cgpu && (!opt_removedisabled || cgpu->deven != DEV_DISABLED))
curses_print_devstatus(cgpu, count++);
}
}
@ -8000,13 +7986,11 @@ void fill_device_drv(struct device_drv *drv) @@ -8000,13 +7986,11 @@ void fill_device_drv(struct device_drv *drv)
drv->working_diff = 1;
}
void enable_device(struct cgpu_info *cgpu)
void enable_device(int i)
{
cgpu->deven = DEV_ENABLED;
wr_lock(&devices_lock);
devices[cgpu->sgminer_id = sgminer_id_count++] = cgpu;
wr_unlock(&devices_lock);
rd_lock(&devices_lock);
devices[i]->deven = DEV_ENABLED;
rd_unlock(&devices_lock);
}
struct _cgpu_devid_counter {
@ -8410,19 +8394,17 @@ int main(int argc, char *argv[]) @@ -8410,19 +8394,17 @@ int main(int argc, char *argv[])
if (devices_enabled[i]) {
if (i >= total_devices)
quit (1, "Command line options set a device that doesn't exist");
enable_device(devices[i]);
enable_device(i);
mining_threads += devices[i]->threads;
} else if (i < total_devices) {
if (!opt_removedisabled) {
enable_device(devices[i]);
mining_threads += devices[i]->threads;
}
devices[i]->deven = DEV_DISABLED;
if (!opt_removedisabled)
mining_threads += devices[i]->threads;
}
}
} else {
for (i = 0; i < total_devices; ++i) {
enable_device(devices[i]);
enable_device(i);
mining_threads += devices[i]->threads;
}
}

Loading…
Cancel
Save