From 271b0447132a3aa8e77f2d86cd77b42b750c15d2 Mon Sep 17 00:00:00 2001 From: "H.G.Muller" Date: Tue, 18 Jun 2019 11:38:57 +0200 Subject: [PATCH] Add option -nice to lower engine priority To enable the GUI to lower engine priority without lowering the priority of the adapter process, a new argument '-nice N' can be used on UCI2WB to delegate that task to it. --- UCI2WB.c | 10 ++++++---- uci2wb.pod | 7 ++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/UCI2WB.c b/UCI2WB.c index 08d5252..10b1f6d 100644 --- a/UCI2WB.c +++ b/UCI2WB.c @@ -52,7 +52,7 @@ int statDepth, statScore, statNodes, statTime, currNr, size, collect, nr, sm, in char currMove[20], moveMap[500][10], /* for analyze mode */ canPonder[20], threadOpt[20], varList[8000], anaOpt[20], checkOptions[8192] = "Ponder"; char pvs[99][999], board[100]; // XQ board for UCCI char *nameWord = "name ", *valueWord = "value ", *wTime = "w", *bTime = "b", *wInc = "winc", *bInc = "binc", newGame; // keywords that differ in UCCI -int unit = 1, drawOffer, scores[99], mpvSP, maxDepth, ponderAlways, newCnt; +int unit = 1, drawOffer, scores[99], mpvSP, maxDepth, ponderAlways, newCnt, priority; FILE *toE, *fromE, *fromF; int pid; @@ -694,9 +694,9 @@ StartEngine(char *cmdLine, char *dir) if (! fSuccess) return GetLastError(); -// if (0) { // in the future we could trigger this by an argument -// SetPriorityClass(piProcInfo.hProcess, GetWin32Priority(appData.niceEngines)); -// } + if (priority > 0) { // for now only implement all lowered priorityies the same way + SetPriorityClass(piProcInfo.hProcess, BELOW_NORMAL_PRIORITY_CLASS); + } /* Close the handles we don't need in the parent */ CloseHandle(piProcInfo.hThread); @@ -723,6 +723,7 @@ StartEngine(char *cmdLine, char *dir) strcpy(buf, cmdLine); p = buf; for (i=0;;) { argv[i++] = p; p = strchr(p, ' '); if (p == NULL) break; *p++ = 0; } argv[i] = NULL; + if(priority) i = nice(priority); execvp(argv[0], argv); // startup engine perror(argv[0]); exit(1); // could not start engine; quit. @@ -745,6 +746,7 @@ main(int argc, char **argv) if(argc == 2 && !strcmp(argv[1], "-v")) { printf("UCI2WB " VERSION " by H.G.Muller\n"); exit(0); } if(argc > 1 && !strcmp(argv[1], "debug")) { debug = 1; argc--; argv++; } if(argc > 1 && !strcmp(argv[1], "-var")) { strcpy(varList+1, argv[2]); *varList = ','; argc-=2; argv+=2; } + if(argc > 2 && !strcmp(argv[1], "-nice")) { sscanf(argv[2], "%d", &priority); argc-=2; argv+=2; } if(argc > 1 && argv[1][0] == '-') { sc = argv[1][1]; argc--; argv++; } if(argc < 2) { printf("usage is: U%cI2WB [debug] [-s] []\n", sc-32); exit(-1); } if(argc > 2) dir = argv[2]; diff --git a/uci2wb.pod b/uci2wb.pod index 5ccd18e..72117fe 100644 --- a/uci2wb.pod +++ b/uci2wb.pod @@ -5,7 +5,7 @@ uci2wb - Protocol adapter for UCI dialects to XBoard =head1 SYNOPSIS -B [debug] [-var ] [-c|-s|-x] engine [directory] +B [debug] [-var ] [-nice ] [-c|-s|-x] engine [directory] =head1 DESCRIPTION @@ -50,6 +50,11 @@ So if these are not the standard variants implied by the protocol choice, (but, f.e. seirawan or 6x6+6_shogi) it has to be configured on the uci2wb command line through this option. +=item B<-nice > + +Runs the engine processes at the requested priority; +positive values lower the priority. + =item B Makes uci2wb report to the GUI everything it receives from the engine, -- 2.17.1