From 142576a961b6e8ba53b38dd43a50a918d3729a06 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Thu, 30 Jun 2011 20:50:52 +1000 Subject: [PATCH] We already have gpu/cpu from id, so use that. Likely the current convoluted code is wrong and leading to segfaults! --- cpu-miner.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/cpu-miner.c b/cpu-miner.c index 6db40436..5777bce2 100644 --- a/cpu-miner.c +++ b/cpu-miner.c @@ -1378,11 +1378,11 @@ int main (int argc, char *argv[]) /* start GPU mining threads */ for (i = 0; i < gpu_threads; i++) { - int gpu = i % nDevs; + int gpu = gpu_from_thr_id(i); thr = &thr_info[i]; thr->id = i; - if (! (i % opt_g_threads)) { + if (!thr->cgpu) { thr->cgpu = calloc(1, sizeof(struct cgpu_info)); if (unlikely(!thr->cgpu)) { applog(LOG_ERR, "Failed to calloc cgpu_info"); @@ -1391,11 +1391,13 @@ int main (int argc, char *argv[]) thr->cgpu->is_gpu = 1; thr->cgpu->cpu_gpu = gpu; } else - thr->cgpu = thr_info[i - (i % opt_g_threads)].cgpu; + thr->cgpu = thr_info[gpu].cgpu; thr->q = tq_new(); - if (!thr->q) + if (!thr->q) { + applog(LOG_ERR, "tq_new failed in starting gpu mining threads"); return 1; + } applog(LOG_INFO, "Init GPU thread %i", i); clStates[i] = initCl(gpu, name, sizeof(name)); @@ -1416,22 +1418,26 @@ int main (int argc, char *argv[]) /* start CPU mining threads */ for (i = gpu_threads; i < gpu_threads + opt_n_threads; i++) { + int cpu = cpu_from_thr_id(i); + thr = &thr_info[i]; thr->id = i; - if (! (i % opt_n_threads)) { + if (!thr->cgpu) { thr->cgpu = calloc(1, sizeof(struct cgpu_info)); if (unlikely(!thr->cgpu)) { applog(LOG_ERR, "Failed to calloc cgpu_info"); return 1; } - thr->cgpu->cpu_gpu = cpu_from_thr_id(i); + thr->cgpu->cpu_gpu = cpu; } else - thr->cgpu = thr_info[cpu_from_thr_id(i - (i % opt_n_threads))].cgpu; + thr->cgpu = thr_info[cpu].cgpu; thr->q = tq_new(); - if (!thr->q) + if (!thr->q) { + applog(LOG_ERR, "tq_new failed in starting cpu mining threads"); return 1; + } if (unlikely(pthread_create(&thr->pth, NULL, miner_thread, thr))) { applog(LOG_ERR, "thread %d create failed", i);