Bug#1085302: llvm-toolchain-19: Refactor and portability for awk code which calculates NJOBS
Santiago Vila
sanvila at debian.org
Fri Oct 18 00:08:03 BST 2024
Package: llvm-toolchain-19
Version: 1:19.1.2-1
Tags: patch
Dear LLVM maintainers:
The code which calculates NJOBS from available memory,
namely this:
[...] print n==1 || n2<=1 ? 1 : n2<=n ? n2 : n
does not work when awk is original-awk. This is reported here upstream:
https://github.com/onetrueawk/awk/issues/233
The simple fix is to add some parenthesis here and there, which as a bonus
makes the code a little bit more readable and easier to understand.
While we are at it, I've made the code a little bit shorter. The new code
calculates "mt" by parsing /proc/meminfo, as before, but then, in the same
awk invocation, we just use the final value in the END block.
Patch attached.
Thanks.
-------------- next part --------------
--- a/debian/rules
+++ b/debian/rules
@@ -82,9 +82,8 @@ ifneq (,$(filter $(DEB_HOST_ARCH), $(FLANG_ARCHS)))
else
MEM_PER_CPU=2100
endif
-NJOBS := $(shell mt=`awk '/^(MemAvail|SwapFree)/ { mt += $$2 } END {print mt}' /proc/meminfo`; \
- awk -vn=$(NCPUS) -vmt=$$mt -vm=$(MEM_PER_CPU) \
- 'END { mt/=1024; n2 = int(mt/m); print n==1 || n2<=1 ? 1 : n2<=n ? n2 : n }' < /dev/null)
+NJOBS := $(shell awk -vn=$(NCPUS) -vm=$(MEM_PER_CPU) '/^(MemAvail|SwapFree)/ { mt += $$2 } \
+ END { n2 = int(mt/1024/m); print (n==1 || n2<=1) ? 1 : (n2<=n ? n2 : n) }' /proc/meminfo)
TIME_COMMAND = $(CURDIR)/debian/usage-wrapper.py $(SUMMARY_ONLY) -j $(NJOBS) --base-memory -m 4.0 -o usage-$(notdir $@)-$(DEB_HOST_ARCH).svg
TIME_BIN := $(if $(wildcard /usr/bin/time),/usr/bin/time,/bin/time)
More information about the Pkg-llvm-team
mailing list