From 19e1ff660db8a6653d67884d10bc830babc1560d Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Sun, 13 Oct 2019 17:16:35 +0200 Subject: improve patch handling in allocator.py * patches are only applied if they aren't applied already * patch no uses -p0 so git diff patches must be adjusted --- src/allocator.py | 14 +++++++++++--- .../glibc/glibc_2.29_no_passive_falsesharing.patch | 6 +++--- .../glibc/glibc_2.29_no_passive_falsesharing_fancy.patch | 6 +++--- src/allocators/scalloc/scalloc_fix_log.patch | 6 +++--- .../supermalloc/remove_faulty_aligned_alloc_test.patch | 6 +++--- .../tcmalloc/tcmalloc_2.7_no_active_falsesharing.patch | 6 +++--- 6 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/allocator.py b/src/allocator.py index b88b046..c418776 100644 --- a/src/allocator.py +++ b/src/allocator.py @@ -89,9 +89,17 @@ class Allocator: print_status("Patching", self.name, "...") for patch in self.patches: with open(patch.format(patchdir=self.patchdir), "rb") as patch_file: - proc = subprocess.run("patch -p1", shell=True, cwd=cwd, + patch_content = patch_file.read() + + # check if patch is already applied + proc = subprocess.run(["patch", "-R", "-p0", "-s", "-f", "--dry-run"], + cwd=cwd, stderr=None, stdout=None, + input=patch_content) + + if proc.returncode != 0: + proc = subprocess.run(["patch", "-p0"], cwd=cwd, stderr=subprocess.PIPE, stdout=stdout, - input=patch_file.read()) + input=patch_content) if proc.returncode: print_debug(proc.stderr, file=sys.stderr) @@ -115,7 +123,6 @@ class Allocator: build_needed = not os.path.isdir(self.dir) buildtimestamp_path = os.path.join(self.dir, ".buildtime") - print_status("Building", self.name, "...") if not build_needed: print_info2("Old build found. Comparing build time with mtime") @@ -133,6 +140,7 @@ class Allocator: if build_needed: self.prepare() + print_status("Building", self.name, "...") if self.build_cmds: stdout = subprocess.PIPE if src.globalvars.verbosity < 2 else None diff --git a/src/allocators/glibc/glibc_2.29_no_passive_falsesharing.patch b/src/allocators/glibc/glibc_2.29_no_passive_falsesharing.patch index 7d0f23f..becbfda 100644 --- a/src/allocators/glibc/glibc_2.29_no_passive_falsesharing.patch +++ b/src/allocators/glibc/glibc_2.29_no_passive_falsesharing.patch @@ -1,7 +1,7 @@ -diff --git a/malloc/malloc.c b/malloc/malloc.c +diff --git malloc/malloc.c malloc/malloc.c index 0abd653be2..eaefd3bd7c 100644 ---- a/malloc/malloc.c -+++ b/malloc/malloc.c +--- malloc/malloc.c ++++ malloc/malloc.c @@ -4194,6 +4194,9 @@ _int_free (mstate av, mchunkptr p, int have_lock) #if USE_TCACHE diff --git a/src/allocators/glibc/glibc_2.29_no_passive_falsesharing_fancy.patch b/src/allocators/glibc/glibc_2.29_no_passive_falsesharing_fancy.patch index 24fbe7a..480d072 100644 --- a/src/allocators/glibc/glibc_2.29_no_passive_falsesharing_fancy.patch +++ b/src/allocators/glibc/glibc_2.29_no_passive_falsesharing_fancy.patch @@ -1,7 +1,7 @@ -diff --git a/malloc/malloc.c b/malloc/malloc.c +diff --git malloc/malloc.c malloc/malloc.c index 0abd653be2..71b2d433ba 100644 ---- a/malloc/malloc.c -+++ b/malloc/malloc.c +--- malloc/malloc.c ++++ malloc/malloc.c @@ -4194,6 +4194,12 @@ _int_free (mstate av, mchunkptr p, int have_lock) #if USE_TCACHE diff --git a/src/allocators/scalloc/scalloc_fix_log.patch b/src/allocators/scalloc/scalloc_fix_log.patch index eaae806..9d4a7d8 100644 --- a/src/allocators/scalloc/scalloc_fix_log.patch +++ b/src/allocators/scalloc/scalloc_fix_log.patch @@ -1,7 +1,7 @@ -diff --git a/src/log.h b/src/log.h +diff --git src/log.h src/log.h index 3edc36d..e1d181c 100644 ---- a/src/log.h -+++ b/src/log.h +--- src/log.h ++++ src/log.h @@ -46,13 +46,13 @@ inline void LogPrintf( snprintf(line_buffer, sizeof(line_buffer), "%d", line); diff --git a/src/allocators/supermalloc/remove_faulty_aligned_alloc_test.patch b/src/allocators/supermalloc/remove_faulty_aligned_alloc_test.patch index dc7f7c4..074f758 100644 --- a/src/allocators/supermalloc/remove_faulty_aligned_alloc_test.patch +++ b/src/allocators/supermalloc/remove_faulty_aligned_alloc_test.patch @@ -1,7 +1,7 @@ -diff --git a/Makefile.include b/Makefile.include +diff --git Makefile.include Makefile.include index bb3cef3..09ee7eb 100644 ---- a/Makefile.include -+++ b/Makefile.include +--- Makefile.include ++++ Makefile.include @@ -37,7 +37,7 @@ default: tests #lib: $(LIB)/libsupermalloc.so #.PHONY: lib diff --git a/src/allocators/tcmalloc/tcmalloc_2.7_no_active_falsesharing.patch b/src/allocators/tcmalloc/tcmalloc_2.7_no_active_falsesharing.patch index c14172d..a76a2f2 100644 --- a/src/allocators/tcmalloc/tcmalloc_2.7_no_active_falsesharing.patch +++ b/src/allocators/tcmalloc/tcmalloc_2.7_no_active_falsesharing.patch @@ -1,7 +1,7 @@ -diff --git a/src/thread_cache.cc b/src/thread_cache.cc +diff --git src/thread_cache.cc src/thread_cache.cc index 6d2f832..2074f4a 100644 ---- a/src/thread_cache.cc -+++ b/src/thread_cache.cc +--- src/thread_cache.cc ++++ src/thread_cache.cc @@ -120,7 +120,11 @@ void* ThreadCache::FetchFromCentralCache(uint32 cl, int32_t byte_size, ASSERT(list->empty()); const int batch_size = Static::sizemap()->num_objects_to_move(cl); -- cgit v1.2.3