Make the number of queued work items configurable and default to 2.
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
diff --git a/cpu-miner.c b/cpu-miner.c
index 117353d..d381def 100644
--- a/cpu-miner.c
+++ b/cpu-miner.c
@@ -121,6 +121,7 @@ static bool opt_quiet = false;
static int opt_retries = 10;
static int opt_fail_pause = 30;
static int opt_log_interval = 5;
+static int opt_queue = 2;
int opt_vectors;
int opt_worksize;
int opt_scantime = 60;
@@ -192,14 +193,14 @@ static struct option_help options_help[] = {
{ "gpu-threads N",
"(-g N) Number of threads per-GPU (0 - 10, default: 2)" },
- { "intensity",
+ { "intensity N",
"(-I) Intensity of scanning (0 - 14, default 4)" },
- { "log",
- "(-l) Interval in seconds between log output (default: 5)" },
+ { "log N",
+ "(-l N) Interval in seconds between log output (default: 5)" },
{ "ndevs",
- "(-n) Display number of detected GPUs" },
+ "(-n) Display number of detected GPUs and exit" },
{ "no-longpoll",
"Disable X-Long-Polling support (default: enabled)" },
@@ -211,6 +212,9 @@ static struct option_help options_help[] = {
{ "protocol-dump",
"(-P) Verbose dump of protocol-level activities (default: off)" },
+ { "queue N",
+ "(-Q N) Number of work items to queue (1 - 10, default 2)" },
+
{ "quiet",
"(-q) Disable per-thread hashmeter output (default: off)" },
@@ -264,6 +268,7 @@ static struct option options[] = {
{ "no-longpoll", 0, NULL, 1003 },
{ "pass", 1, NULL, 'p' },
{ "protocol-dump", 0, NULL, 'P' },
+ { "queue", 1, NULL, 'Q' },
{ "quiet", 0, NULL, 'q' },
{ "retries", 1, NULL, 'r' },
{ "retry-pause", 1, NULL, 'R' },
@@ -719,9 +724,10 @@ static bool queue_request(void)
static bool get_work(struct work *work)
{
struct thr_info *thr = &thr_info[0];
+ static bool first_work = true;
struct work *work_heap;
bool ret = false;
- static bool first_work = true;
+ unsigned int i;
get_new:
if (unlikely(!queue_request()))
@@ -737,15 +743,27 @@ get_new:
free(work_heap);
if (opt_debug)
applog(LOG_DEBUG, "New block detected, discarding old work");
+ for (i = 1; i < opt_queue; i++) {
+ /* Pop off all the work. Cancelling the requests would
+ * be better but tricky. */
+ work_heap = tq_pop(thr->q, NULL);
+ if (unlikely(!work_heap))
+ goto out;
+ free(work_heap);
+ if (unlikely(!queue_request()))
+ goto out;
+ }
goto get_new;
}
if (unlikely(first_work)) {
first_work = false;
- /* send for another work request for the next time get_work
+ /* send for extra work requests for the next time get_work
* is called. */
- if (unlikely(!queue_request()))
- goto out_free;
+ for (i = 1; i < opt_queue; i++) {
+ if (unlikely(!queue_request()))
+ goto out_free;
+ }
}
memcpy(work, work_heap, sizeof(*work));
@@ -1252,6 +1270,13 @@ static void parse_arg (int key, char *arg)
case 'P':
opt_protocol = true;
break;
+ case 'Q':
+ v = atoi(arg);
+ if (v < 1 || v > 10)
+ show_usage();
+
+ opt_queue = v;
+ break;
case 'q':
opt_quiet = true;
break;