git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/3] p5302: count up to online-cpus for thread tests

From
Jeff King <peff@peff.net>
Date
Aug 21, 2020, 17:54 UTC
Message-ID
<20200821175451.GB3263141@coredump.intra.peff.net>
In-Reply-To
<20200821175153.GA3263018@coredump.intra.peff.net>

When PERF_EXTRA is enabled, p5302 checks the performance of index-pack with various numbers of threads. This can be useful for deciding what the default should be (which is currently capped at 3 threads based on the results of this script).

However, we only go up to 8 threads, and modern machines may have more. Let's get the number of CPUs from test-tool, and test various numbers of threads between one and that maximum.

Note that the current tests aren't all identical, as we have to set GIT_FORCE_THREADS for the --threads=1 test (which measures the overhead of starting a single worker thread versus the "0" case of using the main thread). To keep the loop simple, we'll keep the "0" case out of it, and set GIT_FORCE_THREADS=1 for all of the other cases (it's a noop for all but the "1" case, since numbers higher than 1 would always need threads).

Note also that we could skip running "test-tool" if PERF_EXTRA isn't set. However, there's some small value in knowing the number of threads, so that we can mark each test as skipped in the output.

Signed-off-by: Jeff King <peff@peff.net>
---
 t/perf/p5302-pack-index.sh | 47 +++++++++++++++++++-------------------
 1 file changed, 24 insertions(+), 23 deletions(-)
diff --git a/t/perf/p5302-pack-index.sh b/t/perf/p5302-pack-index.sh
index 23011ab739..228593d9ad 100755
--- a/t/perf/p5302-pack-index.sh
+++ b/t/perf/p5302-pack-index.sh
@@ -13,35 +13,36 @@ test_expect_success 'repack' '
 	export PACK
 '
 
-test_perf PERF_EXTRA 'index-pack 0 threads' '
-	rm -rf repo.git &&
-	git init --bare repo.git &&
-	GIT_DIR=repo.git git index-pack --threads=1 --stdin < $PACK
+# Rather than counting up and doubling each time, count down from the endpoint,
+# halving each time. That ensures that our final test uses as many threads as
+# CPUs, even if it isn't a power of 2.
+test_expect_success 'set up thread-counting tests' '
+	t=$(test-tool online-cpus) &&
+	threads= &&
+	while test $t -gt 0
+	do
+		threads="$t $threads"
+		t=$((t / 2))
+	done
 '
 
-test_perf PERF_EXTRA 'index-pack 1 thread ' '
-	rm -rf repo.git &&
-	git init --bare repo.git &&
-	GIT_DIR=repo.git GIT_FORCE_THREADS=1 git index-pack --threads=1 --stdin < $PACK
-'
-
-test_perf PERF_EXTRA 'index-pack 2 threads' '
-	rm -rf repo.git &&
-	git init --bare repo.git &&
-	GIT_DIR=repo.git git index-pack --threads=2 --stdin < $PACK
-'
-
-test_perf PERF_EXTRA 'index-pack 4 threads' '
+test_perf PERF_EXTRA 'index-pack 0 threads' '
 	rm -rf repo.git &&
 	git init --bare repo.git &&
-	GIT_DIR=repo.git git index-pack --threads=4 --stdin < $PACK
+	GIT_DIR=repo.git git index-pack --threads=1 --stdin < $PACK
 '
 
-test_perf PERF_EXTRA 'index-pack 8 threads' '
-	rm -rf repo.git &&
-	git init --bare repo.git &&
-	GIT_DIR=repo.git git index-pack --threads=8 --stdin < $PACK
-'
+for t in $threads
+do
+	THREADS=$t
+	export THREADS
+	test_perf PERF_EXTRA "index-pack $t threads" '
+		rm -rf repo.git &&
+		git init --bare repo.git &&
+		GIT_DIR=repo.git GIT_FORCE_THREADS=1 \
+		git index-pack --threads=$THREADS --stdin <$PACK
+	'
+done
 
 test_perf 'index-pack default number of threads' '
 	rm -rf repo.git &&
-- 
2.28.0.694.g07780f7063
Previous: Jeff KingNext: Jeff King
Message 3 of 13 in “index-pack threading defaults”
  1. 0/3 index-pack threading defaultsJeff King, Aug 21, 2020
  2. 1/3 p5302: disable thread-count parameter tests by defaultJeff King, Aug 21, 2020
  3. 2/3 p5302: count up to online-cpus for thread testsJeff King, Aug 21, 2020
  4. Jeff KingAug 21, 2020
  5. 3/3 index-pack: adjust default threading capJeff King, Aug 21, 2020
  6. Eric SunshineAug 21, 2020
  7. Jeff KingAug 21, 2020
  8. brian m. carlsonAug 22, 2020
  9. Jeff KingAug 24, 2020
  10. Eric SunshineAug 24, 2020
  11. Jeff KingAug 21, 2020
  12. Junio C HamanoAug 21, 2020
  13. Jeff KingAug 21, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.