Set priority of various threads if possible.
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
diff --git a/cgminer.c b/cgminer.c
index 0398e96..1137521 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -4451,6 +4451,30 @@ void zero_stats(void)
}
}
+static void set_highprio(void)
+{
+#ifndef WIN32
+ int ret = nice(-10);
+
+ if (!ret)
+ applog(LOG_DEBUG, "Unable to set thread to high priority");
+#else
+ SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
+#endif
+}
+
+static void set_lowprio(void)
+{
+#ifndef WIN32
+ int ret = nice(10);
+
+ if (!ret)
+ applog(LOG_INFO, "Unable to set thread to low priority");
+#else
+ SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_LOWEST);
+#endif
+}
+
#ifdef HAVE_CURSES
static void display_pools(void)
{
@@ -4856,6 +4880,7 @@ static void *api_thread(void *userdata)
RenameThread("api");
+ set_lowprio();
api(api_thr_id);
PTH(mythr) = 0L;
@@ -6516,6 +6541,7 @@ void *miner_thread(void *userdata)
applog(LOG_DEBUG, "Waiting on sem in miner thread");
cgsem_wait(&mythr->sem);
+ set_highprio();
drv->hash_work(mythr);
out:
drv->thread_shutdown(mythr);
@@ -6794,6 +6820,8 @@ static void *watchpool_thread(void __maybe_unused *userdata)
RenameThread("watchpool");
+ set_lowprio();
+
while (42) {
struct timeval now;
int i;
@@ -6877,6 +6905,7 @@ static void *watchdog_thread(void __maybe_unused *userdata)
RenameThread("watchdog");
+ set_lowprio();
memset(&zero_tv, 0, sizeof(struct timeval));
cgtime(&rotate_tv);
@@ -7664,6 +7693,8 @@ static void *hotplug_thread(void __maybe_unused *userdata)
RenameThread("hotplug");
+ set_lowprio();
+
hotplug_mode = true;
cgsleep_ms(5000);