Commit d3c257a49 for llama.cpp
commit d3c257a493b31cf06a4e724ab4648d6f1a3e5e1e
Author: Alexey Kopytko <alexey@kopytko.com>
Date: Wed Nov 25 00:12:26 2026 +0900
context : prevent excessive CPU polling without OpenMP (#32378)
* common : prevent polling while GPU computes (on Metal or without OpenMP)
* use AudioWorkIntervalCreate to keep the thread on P-cores
* Revert "use AudioWorkIntervalCreate to keep the thread on P-cores"
This reverts commit a7270d23c0695a0194d3146de838db32e2a976e3.
diff --git a/ggml/src/ggml-cpu/ggml-cpu.cpp b/ggml/src/ggml-cpu/ggml-cpu.cpp
index f6a9f5cba..385898106 100644
--- a/ggml/src/ggml-cpu/ggml-cpu.cpp
+++ b/ggml/src/ggml-cpu/ggml-cpu.cpp
@@ -692,6 +692,9 @@ static void * ggml_backend_cpu_get_proc_address(ggml_backend_reg_t reg, const ch
if (strcmp(name, "ggml_threadpool_free") == 0) {
return (void *)ggml_threadpool_free;
}
+ if (strcmp(name, "ggml_threadpool_pause") == 0) {
+ return (void *)ggml_threadpool_pause;
+ }
if (strcmp(name, "ggml_backend_cpu_set_threadpool") == 0) {
return (void *)ggml_backend_cpu_set_threadpool;
}
diff --git a/src/llama-context.cpp b/src/llama-context.cpp
index 4caca65f3..93f8a72ed 100644
--- a/src/llama-context.cpp
+++ b/src/llama-context.cpp
@@ -3108,12 +3108,15 @@ ggml_status llama_context::graph_compute(
int n_threads = batched ? cparams.n_threads_batch : cparams.n_threads;
ggml_threadpool_t tp = batched ? threadpool_batch : threadpool;
+ decltype(ggml_threadpool_pause) * pause_fn = nullptr;
+
if (backend_cpu != nullptr) {
auto * reg = ggml_backend_dev_backend_reg(ggml_backend_get_device(backend_cpu));
auto * set_threadpool_fn = (decltype(ggml_backend_cpu_set_threadpool) *) ggml_backend_reg_get_proc_address(reg, "ggml_backend_cpu_set_threadpool");
if (set_threadpool_fn) {
set_threadpool_fn(backend_cpu, tp);
}
+ pause_fn = (decltype(ggml_threadpool_pause) *) ggml_backend_reg_get_proc_address(reg, "ggml_threadpool_pause");
}
// set the number of threads for all the backends
@@ -3128,6 +3131,11 @@ ggml_status llama_context::graph_compute(
LLAMA_LOG_ERROR("%s: ggml_backend_sched_graph_compute_async failed with error %d\n", __func__, status);
}
+ // stop polling while the other backends wrap up
+ if (tp != nullptr && pause_fn != nullptr && ggml_backend_sched_get_n_splits(sched.get()) > 1) {
+ pause_fn(tp);
+ }
+
// fprintf(stderr, "splits: %d\n", ggml_backend_sched_get_n_splits(sched));
return status;