Skip to content

Commit

Permalink
Merge branch 'sp/msysgit'
Browse files Browse the repository at this point in the history
* sp/msysgit:
  compat/ has subdirectories: do not omit them in 'make clean'
  Fix typo in nedmalloc warning fix
  MinGW: Teach Makefile to detect msysgit and apply specific settings
  Fix warnings in nedmalloc when compiling with GCC 4.4.0
  Add custom memory allocator to MinGW and MacOS builds
  MinGW readdir reimplementation to support d_type
  connect.c: Support PuTTY plink and TortoisePlink as SSH on Windows
  git: browsing paths with spaces when using the start command
  MinGW: fix warning about implicit declaration of _getch()
  test-chmtime: work around Windows limitation
  Work around a regression in Windows 7, causing erase_in_line() to crash sometimes
  Quiet make: do not leave Windows behind
  MinGW: GCC >= 4 does not need SNPRINTF_SIZE_CORR anymore

Conflicts:
	Makefile
  • Loading branch information
Junio C Hamano committed Jun 13, 2009
2 parents 0a17b2c + 021fcd9 commit 95ad2a6
Show file tree
Hide file tree
Showing 13 changed files with 7,194 additions and 9 deletions.
28 changes: 23 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ all::
#
# Define NO_CROSS_DIRECTORY_HARDLINKS if you plan to distribute the installed
# programs as a tar, where bin/ and libexec/ might be on different file systems.
#
# Define USE_NED_ALLOCATOR if you want to replace the platforms default
# memory allocators with the nedmalloc allocator written by Niall Douglas.

GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
@$(SHELL_PATH) ./GIT-VERSION-GEN
Expand Down Expand Up @@ -856,7 +859,6 @@ ifneq (,$(findstring MINGW,$(uname_S)))
pathsep = ;
NO_PREAD = YesPlease
NO_OPENSSL = YesPlease
NO_CURL = YesPlease
NO_LIBGEN_H = YesPlease
NO_SYMLINK_HEAD = YesPlease
NO_IPV6 = YesPlease
Expand All @@ -865,7 +867,6 @@ ifneq (,$(findstring MINGW,$(uname_S)))
NO_STRCASESTR = YesPlease
NO_STRLCPY = YesPlease
NO_MEMMEM = YesPlease
NO_PTHREADS = YesPlease
NEEDS_LIBICONV = YesPlease
OLD_ICONV = YesPlease
NO_C99_FORMAT = YesPlease
Expand All @@ -880,14 +881,26 @@ ifneq (,$(findstring MINGW,$(uname_S)))
NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease
NO_NSEC = YesPlease
USE_WIN32_MMAP = YesPlease
USE_NED_ALLOCATOR = YesPlease
UNRELIABLE_FSTAT = UnfortunatelyYes
OBJECT_CREATION_USES_RENAMES = UnfortunatelyNeedsTo
COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat -Icompat/regex -Icompat/fnmatch
COMPAT_CFLAGS += -DSNPRINTF_SIZE_CORR=1
COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
COMPAT_OBJS += compat/mingw.o compat/fnmatch/fnmatch.o compat/regex/regex.o compat/winansi.o
EXTLIBS += -lws2_32
X = .exe
ifneq (,$(wildcard ../THIS_IS_MSYSGIT))
htmldir=doc/git/html/
prefix =
INSTALL = /bin/install
EXTLIBS += /mingw/lib/libz.a
NO_R_TO_GCC_LINKER = YesPlease
INTERNAL_QSORT = YesPlease
THREADED_DELTA_SEARCH = YesPlease
else
NO_CURL = YesPlease
NO_PTHREADS = YesPlease
endif
endif
ifneq (,$(findstring arm,$(uname_M)))
ARM_SHA1 = YesPlease
Expand Down Expand Up @@ -1188,6 +1201,11 @@ ifdef UNRELIABLE_FSTAT
BASIC_CFLAGS += -DUNRELIABLE_FSTAT
endif

ifdef USE_NED_ALLOCATOR
COMPAT_CFLAGS += -DUSE_NED_ALLOCATOR -DOVERRIDE_STRDUP -DNDEBUG -DREPLACE_SYSTEM_ALLOCATOR -Icompat/nedmalloc
COMPAT_OBJS += compat/nedmalloc/nedmalloc.o
endif

ifeq ($(TCLTK_PATH),)
NO_TCLTK=NoThanks
endif
Expand Down Expand Up @@ -1262,7 +1280,7 @@ SHELL = $(SHELL_PATH)

all:: shell_compatibility_test $(ALL_PROGRAMS) $(BUILT_INS) $(OTHER_PROGRAMS) GIT-BUILD-OPTIONS
ifneq (,$X)
$(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) git$X)), test '$p' -ef '$p$X' || $(RM) '$p';)
$(QUIET_BUILT_IN)$(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) git$X)), test '$p' -ef '$p$X' || $(RM) '$p';)
endif

all::
Expand Down Expand Up @@ -1704,7 +1722,7 @@ distclean: clean
$(RM) configure

clean:
$(RM) *.o mozilla-sha1/*.o arm/*.o ppc/*.o compat/*.o xdiff/*.o \
$(RM) *.o mozilla-sha1/*.o arm/*.o ppc/*.o compat/*.o compat/*/*.o xdiff/*.o \
$(LIB_FILE) $(XDIFF_LIB)
$(RM) $(ALL_PROGRAMS) $(BUILT_INS) git$X
$(RM) $(TEST_PROGRAMS)
Expand Down
60 changes: 60 additions & 0 deletions compat/mingw.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "../git-compat-util.h"
#include "win32.h"
#include <conio.h>
#include "../strbuf.h"

unsigned int _CRT_fmode = _O_BINARY;
Expand Down Expand Up @@ -1171,3 +1172,62 @@ char *getpass(const char *prompt)
fputs("\n", stderr);
return strbuf_detach(&buf, NULL);
}

#ifndef NO_MINGW_REPLACE_READDIR
/* MinGW readdir implementation to avoid extra lstats for Git */
struct mingw_DIR
{
struct _finddata_t dd_dta; /* disk transfer area for this dir */
struct mingw_dirent dd_dir; /* Our own implementation, including d_type */
long dd_handle; /* _findnext handle */
int dd_stat; /* 0 = next entry to read is first entry, -1 = off the end, positive = 0 based index of next entry */
char dd_name[1]; /* given path for dir with search pattern (struct is extended) */
};

struct dirent *mingw_readdir(DIR *dir)
{
WIN32_FIND_DATAA buf;
HANDLE handle;
struct mingw_DIR *mdir = (struct mingw_DIR*)dir;

if (!dir->dd_handle) {
errno = EBADF; /* No set_errno for mingw */
return NULL;
}

if (dir->dd_handle == (long)INVALID_HANDLE_VALUE && dir->dd_stat == 0)
{
handle = FindFirstFileA(dir->dd_name, &buf);
DWORD lasterr = GetLastError();
dir->dd_handle = (long)handle;
if (handle == INVALID_HANDLE_VALUE && (lasterr != ERROR_NO_MORE_FILES)) {
errno = err_win_to_posix(lasterr);
return NULL;
}
} else if (dir->dd_handle == (long)INVALID_HANDLE_VALUE) {
return NULL;
} else if (!FindNextFileA((HANDLE)dir->dd_handle, &buf)) {
DWORD lasterr = GetLastError();
FindClose((HANDLE)dir->dd_handle);
dir->dd_handle = (long)INVALID_HANDLE_VALUE;
/* POSIX says you shouldn't set errno when readdir can't
find any more files; so, if another error we leave it set. */
if (lasterr != ERROR_NO_MORE_FILES)
errno = err_win_to_posix(lasterr);
return NULL;
}

/* We get here if `buf' contains valid data. */
strcpy(dir->dd_dir.d_name, buf.cFileName);
++dir->dd_stat;

/* Set file type, based on WIN32_FIND_DATA */
mdir->dd_dir.d_type = 0;
if (buf.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
mdir->dd_dir.d_type |= DT_DIR;
else
mdir->dd_dir.d_type |= DT_REG;

return (struct dirent*)&dir->dd_dir;
}
#endif // !NO_MINGW_REPLACE_READDIR
29 changes: 29 additions & 0 deletions compat/mingw.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,32 @@ int main(int argc, const char **argv) \
return mingw_main(argc, argv); \
} \
static int mingw_main(c,v)

#ifndef NO_MINGW_REPLACE_READDIR
/*
* A replacement of readdir, to ensure that it reads the file type at
* the same time. This avoid extra unneeded lstats in git on MinGW
*/
#undef DT_UNKNOWN
#undef DT_DIR
#undef DT_REG
#undef DT_LNK
#define DT_UNKNOWN 0
#define DT_DIR 1
#define DT_REG 2
#define DT_LNK 3

struct mingw_dirent
{
long d_ino; /* Always zero. */
union {
unsigned short d_reclen; /* Always zero. */
unsigned char d_type; /* Reimplementation adds this */
};
unsigned short d_namlen; /* Length of name in d_name. */
char d_name[FILENAME_MAX]; /* File name. */
};
#define dirent mingw_dirent
#define readdir(x) mingw_readdir(x)
struct dirent *mingw_readdir(DIR *dir);
#endif // !NO_MINGW_REPLACE_READDIR
23 changes: 23 additions & 0 deletions compat/nedmalloc/License.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
136 changes: 136 additions & 0 deletions compat/nedmalloc/Readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
nedalloc v1.05 15th June 2008:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

by Niall Douglas (http://www.nedprod.com/programs/portable/nedmalloc/)

Enclosed is nedalloc, an alternative malloc implementation for multiple
threads without lock contention based on dlmalloc v2.8.4. It is more
or less a newer implementation of ptmalloc2, the standard allocator in
Linux (which is based on dlmalloc v2.7.0) but also contains a per-thread
cache for maximum CPU scalability.

It is licensed under the Boost Software License which basically means
you can do anything you like with it. This does not apply to the malloc.c.h
file which remains copyright to others.

It has been tested on win32 (x86), win64 (x64), Linux (x64), FreeBSD (x64)
and Apple MacOS X (x86). It works very well on all of these and is very
significantly faster than the system allocator on all of these platforms.

By literally dropping in this allocator as a replacement for your system
allocator, you can see real world improvements of up to three times in normal
code!

To use:
-=-=-=-
Drop in nedmalloc.h, nedmalloc.c and malloc.c.h into your project.
Configure using the instructions in nedmalloc.h. Run and enjoy.

To test, compile test.c. It will run a comparison between your system
allocator and nedalloc and tell you how much faster nedalloc is. It also
serves as an example of usage.

Notes:
-=-=-=
If you want the very latest version of this allocator, get it from the
TnFOX SVN repository at svn://svn.berlios.de/viewcvs/tnfox/trunk/src/nedmalloc

Because of how nedalloc allocates an mspace per thread, it can cause
severe bloating of memory usage under certain allocation patterns.
You can substantially reduce this wastage by setting MAXTHREADSINPOOL
or the threads parameter to nedcreatepool() to a fraction of the number of
threads which would normally be in a pool at once. This will reduce
bloating at the cost of an increase in lock contention. If allocated size
is less than THREADCACHEMAX, locking is avoided 90-99% of the time and
if most of your allocations are below this value, you can safely set
MAXTHREADSINPOOL to one.

You will suffer memory leakage unless you call neddisablethreadcache()
per pool for every thread which exits. This is because nedalloc cannot
portably know when a thread exits and thus when its thread cache can
be returned for use by other code. Don't forget pool zero, the system pool.

For C++ type allocation patterns (where the same sizes of memory are
regularly allocated and deallocated as objects are created and destroyed),
the threadcache always benefits performance. If however your allocation
patterns are different, searching the threadcache may significantly slow
down your code - as a rule of thumb, if cache utilisation is below 80%
(see the source for neddisablethreadcache() for how to enable debug
printing in release mode) then you should disable the thread cache for
that thread. You can compile out the threadcache code by setting
THREADCACHEMAX to zero.

Speed comparisons:
-=-=-=-=-=-=-=-=-=
See Benchmarks.xls for details.

The enclosed test.c can do two things: it can be a torture test or a speed
test. The speed test is designed to be a representative synthetic
memory allocator test. It works by randomly mixing allocations with frees
with half of the allocation sizes being a two power multiple less than
512 bytes (to mimic C++ stack instantiated objects) and the other half
being a simple random value less than 16Kb.

The real world code results are from Tn's TestIO benchmark. This is a
heavily multithreaded and memory intensive benchmark with a lot of branching
and other stuff modern processors don't like so much. As you'll note, the
test doesn't show the benefits of the threadcache mostly due to the saturation
of the memory bus being the limiting factor.

ChangeLog:
-=-=-=-=-=
v1.05 15th June 2008:
* { 1042 } Added error check for TLSSET() and TLSFREE() macros. Thanks to
Markus Elfring for reporting this.
* { 1043 } Fixed a segfault when freeing memory allocated using
nedindependent_comalloc(). Thanks to Pavel Vozenilek for reporting this.

v1.04 14th July 2007:
* Fixed a bug with the new optimised implementation that failed to lock
on a realloc under certain conditions.
* Fixed lack of thread synchronisation in InitPool() causing pool corruption
* Fixed a memory leak of thread cache contents on disabling. Thanks to Earl
Chew for reporting this.
* Added a sanity check for freed blocks being valid.
* Reworked test.c into being a torture test.
* Fixed GCC assembler optimisation misspecification

v1.04alpha_svn915 7th October 2006:
* Fixed failure to unlock thread cache list if allocating a new list failed.
Thanks to Dmitry Chichkov for reporting this. Futher thanks to Aleksey Sanin.
* Fixed realloc(0, <size>) segfaulting. Thanks to Dmitry Chichkov for
reporting this.
* Made config defines #ifndef so they can be overriden by the build system.
Thanks to Aleksey Sanin for suggesting this.
* Fixed deadlock in nedprealloc() due to unnecessary locking of preferred
thread mspace when mspace_realloc() always uses the original block's mspace
anyway. Thanks to Aleksey Sanin for reporting this.
* Made some speed improvements by hacking mspace_malloc() to no longer lock
its mspace, thus allowing the recursive mutex implementation to be removed
with an associated speed increase. Thanks to Aleksey Sanin for suggesting this.
* Fixed a bug where allocating mspaces overran its max limit. Thanks to
Aleksey Sanin for reporting this.

v1.03 10th July 2006:
* Fixed memory corruption bug in threadcache code which only appeared with >4
threads and in heavy use of the threadcache.

v1.02 15th May 2006:
* Integrated dlmalloc v2.8.4, fixing the win32 memory release problem and
improving performance still further. Speed is now up to twice the speed of v1.01
(average is 67% faster).
* Fixed win32 critical section implementation. Thanks to Pavel Kuznetsov
for reporting this.
* Wasn't locking mspace if all mspaces were locked. Thanks to Pavel Kuznetsov
for reporting this.
* Added Apple Mac OS X support.

v1.01 24th February 2006:
* Fixed multiprocessor scaling problems by removing sources of cache sloshing
* Earl Chew <earl_chew <at> agilent <dot> com> sent patches for the following:
1. size2binidx() wasn't working for default code path (non x86)
2. Fixed failure to release mspace lock under certain circumstances which
caused a deadlock

v1.00 1st January 2006:
* First release
Loading

0 comments on commit 95ad2a6

Please sign in to comment.