diff options
author | Andreas Ericsson <ae@op5.se> | 2008-02-22 20:11:56 -0600 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2008-02-23 12:00:32 -0800 |
commit | 833e3df17188e48b2d31db0966a4051dad5e03b9 (patch) | |
tree | 265fb9405efb644ff564ac1b77991d62795006a2 /builtin-pack-objects.c | |
parent | 923d44aeb7cb6d21eeb459fdc1b58137e37c2b1c (diff) | |
download | git-833e3df17188e48b2d31db0966a4051dad5e03b9.tar.gz git-833e3df17188e48b2d31db0966a4051dad5e03b9.tar.xz |
pack-objects: Add runtime detection of online CPU's
Packing objects can be done in parallell nowadays, but it's
only done if the config option pack.threads is set to a value
above 1. Because of that, the code-path used is often not the
most optimal one.
This patch adds a routine to detect the number of online CPU's
at runtime (online_cpus()). When pack.threads (or --threads=) is
given a value of 0, the number of threads is set to the number of
online CPU's. This feature is also documented.
As per Nicolas Pitre's recommendations, the default is still to
run pack-objects single-threaded unless explicitly activated,
either by configuration or by command line parameter.
The routine online_cpus() is a rework of "numcpus.c", written by
one Philip Willoughby <pgw99@doc.ic.ac.uk>. numcpus.c is in the
public domain and can presently be downloaded from
http://csgsoft.doc.ic.ac.uk/numcpus/
Signed-off-by: Andreas Ericsson <ae@op5.se>
Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-pack-objects.c')
-rw-r--r-- | builtin-pack-objects.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index d2bb12e57..586ae1197 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -16,6 +16,7 @@ #include "progress.h" #ifdef THREADED_DELTA_SEARCH +#include "thread-utils.h" #include <pthread.h> #endif @@ -1852,11 +1853,11 @@ static int git_pack_config(const char *k, const char *v) } if (!strcmp(k, "pack.threads")) { delta_search_threads = git_config_int(k, v); - if (delta_search_threads < 1) + if (delta_search_threads < 0) die("invalid number of threads specified (%d)", delta_search_threads); #ifndef THREADED_DELTA_SEARCH - if (delta_search_threads > 1) + if (delta_search_threads != 1) warning("no threads support, ignoring %s", k); #endif return 0; @@ -2122,10 +2123,10 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) if (!prefixcmp(arg, "--threads=")) { char *end; delta_search_threads = strtoul(arg+10, &end, 0); - if (!arg[10] || *end || delta_search_threads < 1) + if (!arg[10] || *end || delta_search_threads < 0) usage(pack_usage); #ifndef THREADED_DELTA_SEARCH - if (delta_search_threads > 1) + if (delta_search_threads != 1) warning("no threads support, " "ignoring %s", arg); #endif @@ -2235,6 +2236,11 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) if (!pack_to_stdout && thin) die("--thin cannot be used to build an indexable pack."); +#ifdef THREADED_DELTA_SEARCH + if (!delta_search_threads) /* --threads=0 means autodetect */ + delta_search_threads = online_cpus(); +#endif + prepare_packed_git(); if (progress) |