Skip to content

common: fix return value check for setpriority#18412

Merged
ggerganov merged 2 commits into
ggml-org:masterfrom
o7si:setpriority
Dec 29, 2025
Merged

common: fix return value check for setpriority#18412
ggerganov merged 2 commits into
ggml-org:masterfrom
o7si:setpriority

Conversation

@o7si
Copy link
Copy Markdown
Contributor

@o7si o7si commented Dec 27, 2025

On macOS and POSIX systems, a return value of 0 from getpriority() indicates success.

RETURN VALUES
     Since getpriority() can legitimately return the value -1, it is necessary to clear the external variable errno prior to
     the call, then check it afterward to determine if a -1 is an error or a legitimate value.  The setpriority() call returns
     0 if there is no error, or -1 if there is.

The ! operator in the code should be removed.

llama.cpp/common/common.cpp

Lines 254 to 257 in 06705fd

if (!setpriority(PRIO_PROCESS, 0, p)) {
LOG_WRN("failed to set process priority %d : %s (%d)\n", prio, strerror(errno), errno);
return false;
}

Additionally, the Windows version's logic for SetPriorityClass is correct, since it returns 0 to indicate failure.

llama.cpp/common/common.cpp

Lines 228 to 231 in 06705fd

if (!SetPriorityClass(GetCurrentProcess(), p)) {
LOG_WRN("failed to set process priority class %d : (%d)\n", prio, (int) GetLastError());
return false;
}

@o7si o7si requested a review from ggerganov as a code owner December 27, 2025 16:17
@ggerganov ggerganov merged commit daa242d into ggml-org:master Dec 29, 2025
65 of 71 checks passed
blime4 referenced this pull request in blime4/llama.cpp Feb 5, 2026
* common: fix return value check for setpriority

* tools: add logging for process priority setting
Seunghhon pushed a commit to Seunghhon/llama.cpp that referenced this pull request Apr 26, 2026
* common: fix return value check for setpriority

* tools: add logging for process priority setting
ljubomirj pushed a commit to ljubomirj/llama.cpp that referenced this pull request May 6, 2026
* common: fix return value check for setpriority

* tools: add logging for process priority setting
my-other-github-account pushed a commit to my-other-github-account/llama.cpp that referenced this pull request May 15, 2026
* common: fix return value check for setpriority

* tools: add logging for process priority setting
my-other-github-account pushed a commit to my-other-github-account/llama.cpp that referenced this pull request May 15, 2026
* common: fix return value check for setpriority

* tools: add logging for process priority setting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants