Merge branch 'ae/pack-autothread'

* ae/pack-autothread:
  Revert "pack-objects: Print a message describing the number of threads for packing"
  pack-objects: Print a message describing the number of threads for packing
  pack-objects: Add runtime detection of online CPU's
This commit is contained in:
Junio C Hamano 2008-02-27 11:54:03 -08:00
commit 3c972e1ec4
6 changed files with 69 additions and 4 deletions

View File

@ -812,6 +812,8 @@ pack.threads::
warning. This is meant to reduce packing time on multiprocessor warning. This is meant to reduce packing time on multiprocessor
machines. The required amount of memory for the delta search window machines. The required amount of memory for the delta search window
is however multiplied by the number of threads. is however multiplied by the number of threads.
Specifying 0 will cause git to auto-detect the number of CPU's
and set the number of threads accordingly.
pack.indexVersion:: pack.indexVersion::
Specify the default pack index version. Valid values are 1 for Specify the default pack index version. Valid values are 1 for

View File

@ -177,6 +177,8 @@ base-name::
This is meant to reduce packing time on multiprocessor machines. This is meant to reduce packing time on multiprocessor machines.
The required amount of memory for the delta search window is The required amount of memory for the delta search window is
however multiplied by the number of threads. however multiplied by the number of threads.
Specifying 0 will cause git to auto-detect the number of CPU's
and set the number of threads accordingly.
--index-version=<version>[,<offset>]:: --index-version=<version>[,<offset>]::
This is intended to be used by the test suite only. It allows This is intended to be used by the test suite only. It allows

View File

@ -741,6 +741,7 @@ endif
ifdef THREADED_DELTA_SEARCH ifdef THREADED_DELTA_SEARCH
BASIC_CFLAGS += -DTHREADED_DELTA_SEARCH BASIC_CFLAGS += -DTHREADED_DELTA_SEARCH
EXTLIBS += -lpthread EXTLIBS += -lpthread
LIB_OBJS += thread-utils.o
endif endif
ifeq ($(TCLTK_PATH),) ifeq ($(TCLTK_PATH),)

View File

@ -16,6 +16,7 @@
#include "progress.h" #include "progress.h"
#ifdef THREADED_DELTA_SEARCH #ifdef THREADED_DELTA_SEARCH
#include "thread-utils.h"
#include <pthread.h> #include <pthread.h>
#endif #endif
@ -1852,11 +1853,11 @@ static int git_pack_config(const char *k, const char *v)
} }
if (!strcmp(k, "pack.threads")) { if (!strcmp(k, "pack.threads")) {
delta_search_threads = git_config_int(k, v); 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)", die("invalid number of threads specified (%d)",
delta_search_threads); delta_search_threads);
#ifndef THREADED_DELTA_SEARCH #ifndef THREADED_DELTA_SEARCH
if (delta_search_threads > 1) if (delta_search_threads != 1)
warning("no threads support, ignoring %s", k); warning("no threads support, ignoring %s", k);
#endif #endif
return 0; return 0;
@ -2122,10 +2123,10 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
if (!prefixcmp(arg, "--threads=")) { if (!prefixcmp(arg, "--threads=")) {
char *end; char *end;
delta_search_threads = strtoul(arg+10, &end, 0); 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); usage(pack_usage);
#ifndef THREADED_DELTA_SEARCH #ifndef THREADED_DELTA_SEARCH
if (delta_search_threads > 1) if (delta_search_threads != 1)
warning("no threads support, " warning("no threads support, "
"ignoring %s", arg); "ignoring %s", arg);
#endif #endif
@ -2235,6 +2236,11 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
if (!pack_to_stdout && thin) if (!pack_to_stdout && thin)
die("--thin cannot be used to build an indexable pack."); 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(); prepare_packed_git();
if (progress) if (progress)

48
thread-utils.c Normal file
View File

@ -0,0 +1,48 @@
#include "cache.h"
#ifdef _WIN32
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
#elif defined(hpux) || defined(__hpux) || defined(_hpux)
# include <sys/pstat.h>
#endif
/*
* By doing this in two steps we can at least get
* the function to be somewhat coherent, even
* with this disgusting nest of #ifdefs.
*/
#ifndef _SC_NPROCESSORS_ONLN
# ifdef _SC_NPROC_ONLN
# define _SC_NPROCESSORS_ONLN _SC_NPROC_ONLN
# elif defined _SC_CRAY_NCPU
# define _SC_NPROCESSORS_ONLN _SC_CRAY_NCPU
# endif
#endif
int online_cpus(void)
{
#ifdef _SC_NPROCESSORS_ONLN
long ncpus;
#endif
#ifdef _WIN32
SYSTEM_INFO info;
GetSystemInfo(&info);
if ((int)info.dwNumberOfProcessors > 0)
return (int)info.dwNumberOfProcessors;
#elif defined(hpux) || defined(__hpux) || defined(_hpux)
struct pst_dynamic psd;
if (!pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0))
return (int)psd.psd_proc_cnt;
#endif
#ifdef _SC_NPROCESSORS_ONLN
if ((ncpus = (long)sysconf(_SC_NPROCESSORS_ONLN)) > 0)
return (int)ncpus;
#endif
return 1;
}

6
thread-utils.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef THREAD_COMPAT_H
#define THREAD_COMPAT_H
extern int online_cpus(void);
#endif /* THREAD_COMPAT_H */