diff options
| author | Onur Gündüz <ogunduz@gmail.com> | 2026-06-27 00:58:05 +0200 |
|---|---|---|
| committer | Onur Gündüz <ogunduz@gmail.com> | 2026-06-27 01:03:41 +0200 |
| commit | af55803d0dff9eb692c760c8d486e736c945061d (patch) | |
| tree | 0875a1112bf98304e445e0544c4309670d6f4769 /libffwd/threadpool.c | |
| parent | 0f861b7f3098750ddee4f6570f3be228d1da5320 (diff) | |
| download | ffwd-af55803d0dff9eb692c760c8d486e736c945061d.tar.gz ffwd-af55803d0dff9eb692c760c8d486e736c945061d.zip | |
chore: clean up comment formatting and wording
Diffstat (limited to 'libffwd/threadpool.c')
| -rw-r--r-- | libffwd/threadpool.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/libffwd/threadpool.c b/libffwd/threadpool.c index 2521a6d..6cb4252 100644 --- a/libffwd/threadpool.c +++ b/libffwd/threadpool.c @@ -1,5 +1,5 @@ /* - * tp.c - CPU thread pool + * CPU thread pool. */ #if defined(__linux__) && !defined(_GNU_SOURCE) @@ -116,15 +116,19 @@ void tp_set_threads(int n) { } #ifndef __APPLE__ -/* CPU bandwidth this process may actually use, in whole cores, or 0 if there - * is no cgroup limit. Containers (Docker --cpus, Kubernetes, RunPod) expose - * every host CPU through sysconf()/cpuset, but the CFS quota caps the CPU time - * the process really gets. Sizing the BLAS/thread pool to the host count then - * oversubscribes that quota: the threads spend the period's budget early and - * the scheduler throttles them for the rest of each period, which adds large, - * bursty stalls (e.g. a 16-thread default against a 5.1-core quota ran the - * 0.6B model ~2x slower than a 5-thread pool). Floor, not ceil, so a fully - * busy pool stays under the quota and never trips throttling. */ +/* CPU quota available to this process, in whole cores, or 0 if uncapped. + * Containers such as Docker --cpus, Kubernetes, and RunPod may expose every host + * CPU through sysconf()/cpuset, while CFS quota limits the CPU time the process + * can actually use. + * + * Sizing the BLAS/thread pool to the host CPU count oversubscribes that quota: + * threads use the period budget early, then get throttled for the rest of the + * period, causing large bursty stalls. Example: a 16-thread default against a + * 5.1-core quota ran the 0.6B model about 2x slower than a 5-thread pool. + * + * Floor instead of ceil, so a fully busy pool stays under quota and avoids + * throttling. + */ static int cgroup_cpu_quota(void) { /* cgroup v2: "/sys/fs/cgroup/cpu.max" is "<quota> <period>", or * "max <period>" when unlimited. */ |
