git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: szager@chromium.org
To: git@vger.kernel.org
Subject: (unknown)
Date: Tue, 18 Mar 2014 17:45:49 -0700	[thread overview]
Message-ID: <5328e8bd.fNxY4x6POKCJfhV6%szager@chromium.org> (raw)

Subject: [PATCH] Enable index-pack threading in msysgit.

This adds a Windows implementation of pread.  Note that it is NOT
safe to intersperse calls to read() and pread() on a file
descriptor.  According to the ReadFile spec, using the 'overlapped'
argument should not affect the implicit position pointer of the
descriptor.  Experiments have shown that this is, in fact, a lie.

To accomodate that fact, this change also incorporates:

http://article.gmane.org/gmane.comp.version-control.git/196042

... which gives each index-pack thread its own file descriptor.
---
 builtin/index-pack.c | 21 ++++++++++++++++-----
 compat/mingw.c       | 31 ++++++++++++++++++++++++++++++-
 compat/mingw.h       |  3 +++
 config.mak.uname     |  1 -
 4 files changed, 49 insertions(+), 7 deletions(-)

diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 2f37a38..c02dd4c 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -51,6 +51,7 @@ struct thread_local {
 #endif
 	struct base_data *base_cache;
 	size_t base_cache_used;
+	int pack_fd;
 };
 
 /*
@@ -91,7 +92,8 @@ static off_t consumed_bytes;
 static unsigned deepest_delta;
 static git_SHA_CTX input_ctx;
 static uint32_t input_crc32;
-static int input_fd, output_fd, pack_fd;
+static const char *curr_pack;
+static int input_fd, output_fd;
 
 #ifndef NO_PTHREADS
 
@@ -134,6 +136,7 @@ static inline void unlock_mutex(pthread_mutex_t *mutex)
  */
 static void init_thread(void)
 {
+	int i;
 	init_recursive_mutex(&read_mutex);
 	pthread_mutex_init(&counter_mutex, NULL);
 	pthread_mutex_init(&work_mutex, NULL);
@@ -141,11 +144,17 @@ static void init_thread(void)
 		pthread_mutex_init(&deepest_delta_mutex, NULL);
 	pthread_key_create(&key, NULL);
 	thread_data = xcalloc(nr_threads, sizeof(*thread_data));
+	for (i = 0; i < nr_threads; i++) {
+		thread_data[i].pack_fd = open(curr_pack, O_RDONLY);
+		if (thread_data[i].pack_fd == -1)
+			die_errno("unable to open %s", curr_pack);
+	}
 	threads_active = 1;
 }
 
 static void cleanup_thread(void)
 {
+	int i;
 	if (!threads_active)
 		return;
 	threads_active = 0;
@@ -155,6 +164,8 @@ static void cleanup_thread(void)
 	if (show_stat)
 		pthread_mutex_destroy(&deepest_delta_mutex);
 	pthread_key_delete(key);
+	for (i = 0; i < nr_threads; i++)
+		close(thread_data[i].pack_fd);
 	free(thread_data);
 }
 
@@ -288,13 +299,13 @@ static const char *open_pack_file(const char *pack_name)
 			output_fd = open(pack_name, O_CREAT|O_EXCL|O_RDWR, 0600);
 		if (output_fd < 0)
 			die_errno(_("unable to create '%s'"), pack_name);
-		pack_fd = output_fd;
+		nothread_data.pack_fd = output_fd;
 	} else {
 		input_fd = open(pack_name, O_RDONLY);
 		if (input_fd < 0)
 			die_errno(_("cannot open packfile '%s'"), pack_name);
 		output_fd = -1;
-		pack_fd = input_fd;
+		nothread_data.pack_fd = input_fd;
 	}
 	git_SHA1_Init(&input_ctx);
 	return pack_name;
@@ -542,7 +553,7 @@ static void *unpack_data(struct object_entry *obj,
 
 	do {
 		ssize_t n = (len < 64*1024) ? len : 64*1024;
-		n = pread(pack_fd, inbuf, n, from);
+		n = pread(get_thread_data()->pack_fd, inbuf, n, from);
 		if (n < 0)
 			die_errno(_("cannot pread pack file"));
 		if (!n)
@@ -1490,7 +1501,7 @@ static void show_pack_info(int stat_only)
 int cmd_index_pack(int argc, const char **argv, const char *prefix)
 {
 	int i, fix_thin_pack = 0, verify = 0, stat_only = 0;
-	const char *curr_pack, *curr_index;
+	const char *curr_index;
 	const char *index_name = NULL, *pack_name = NULL;
 	const char *keep_name = NULL, *keep_msg = NULL;
 	char *index_name_buf = NULL, *keep_name_buf = NULL;
diff --git a/compat/mingw.c b/compat/mingw.c
index 383cafe..6cc85d6 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -329,7 +329,36 @@ int mingw_mkdir(const char *path, int mode)
 	return ret;
 }
 
-int mingw_open (const char *filename, int oflags, ...)
+
+ssize_t mingw_pread(int fd, void *buf, size_t count, off64_t offset)
+{
+	HANDLE hand = (HANDLE)_get_osfhandle(fd);
+	if (hand == INVALID_HANDLE_VALUE) {
+		errno = EBADF;
+		return -1;
+	}
+
+	LARGE_INTEGER offset_value;
+	offset_value.QuadPart = offset;
+
+	DWORD bytes_read = 0;
+	OVERLAPPED overlapped = {0};
+	overlapped.Offset = offset_value.LowPart;
+	overlapped.OffsetHigh = offset_value.HighPart;
+	BOOL result = ReadFile(hand, buf, count, &bytes_read, &overlapped);
+
+	ssize_t ret = bytes_read;
+
+	if (!result && GetLastError() != ERROR_HANDLE_EOF)
+	{
+		errno = err_win_to_posix(GetLastError());
+		ret = -1;
+	}
+
+	return ret;
+}
+
+int mingw_open(const char *filename, int oflags, ...)
 {
 	va_list args;
 	unsigned mode;
diff --git a/compat/mingw.h b/compat/mingw.h
index 08b83fe..377ba50 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -174,6 +174,9 @@ int mingw_unlink(const char *pathname);
 int mingw_rmdir(const char *path);
 #define rmdir mingw_rmdir
 
+ssize_t mingw_pread(int fd, void *buf, size_t count, off64_t offset);
+#define pread mingw_pread
+
 int mingw_open (const char *filename, int oflags, ...);
 #define open mingw_open
 
diff --git a/config.mak.uname b/config.mak.uname
index e8acc39..b405524 100644
--- a/config.mak.uname
+++ b/config.mak.uname
@@ -474,7 +474,6 @@ ifeq ($(uname_S),NONSTOP_KERNEL)
 endif
 ifneq (,$(findstring MINGW,$(uname_S)))
 	pathsep = ;
-	NO_PREAD = YesPlease
 	NEEDS_CRYPTO_WITH_SSL = YesPlease
 	NO_LIBGEN_H = YesPlease
 	NO_POLL = YesPlease
-- 
1.9.0.279.gdc9e3eb

             reply	other threads:[~2014-03-19  0:45 UTC|newest]

Thread overview: 161+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-19  0:45 szager [this message]
  -- strict thread matches above, loose matches on Subject: below --
2016-06-16  3:54 (unknown) 岸洋介
2016-06-12  9:38 (unknown), Financial Service
2016-06-07 14:01 [PATCH v3 0/6] send-email: cleaner tests and quote email Tom Russello
2016-06-08 13:01 ` (unknown), Samuel GROOT
2016-05-16 15:58 (unknown), Nathan Wendt
2016-04-11 19:04 (unknown), miwilliams
2016-04-11 16:02 (unknown) Michael S. Tsirkin
2016-03-28 13:38 (unknown), ratheesh kannoth
2015-12-16  3:02 (unknown), David Greene
2015-12-16  5:57 ` (unknown) Junio C Hamano
2015-12-16  8:44   ` (unknown) Patrick Steinhardt
2015-12-18 17:35     ` (unknown) David Greene
2015-12-14 13:14 (unknown) Ros Sothen
2015-11-06  3:34 (unknown), David Greene
2015-09-28 17:55 (unknown), Kosta Zertsekel
2015-09-19 10:58 (unknown), 戸島達哉
2015-09-01  2:13 (unknown), David Turner
2015-08-05 12:47 (unknown) Ivan Chernyavsky
2015-05-12 12:38 (unknown), Varis Van Rob
2015-05-11 17:56 (unknown), dturner
2015-04-08 20:44 (unknown), Mamta Upadhyay
2015-03-13  1:34 (unknown) cody.taylor
2015-02-25  8:53 (unknown) stefan leijen
2015-02-17 18:14 [PATCH] read-cache.c: free cache entry when refreshing fails Junio C Hamano
2015-02-17 18:27 ` (unknown), Stefan Beller
2015-01-12 20:59 (unknown), امير الاحزان
2014-10-30 12:23 (unknown), Fedor Eftimitsa
2014-09-28 10:51 (unknown) bambecapuno06
2014-09-08 11:36 (unknown), R. Klomp
2014-08-26 11:16 (unknown), mail
2014-07-15 16:31 (unknown), Woody Wu
2014-06-17 17:13 (unknown), David Turner
2014-06-01 21:24 (unknown), C. Benson Manica
2014-05-22 22:35 (unknown), Mrs. Jiang Ming
2014-04-19 14:27 (unknown), Siegel, Suzan
2014-03-05  8:43 (unknown) Stephanie Bennett
2014-02-20  0:55 (unknown) Bozhidar Bozhev
2013-12-18 14:09 (unknown) Maxime Coste
2013-08-07 12:54 (unknown), a a
2013-05-25  3:57 (unknown), Kirill Berezin
2013-05-20  9:58 [PATCH 0/6] t5000: add test for pax extended header generation René Scharfe
2013-05-20  9:58 ` [PATCH 6/6] t5000: test long filenames René Scharfe
2013-05-20 19:55   ` Eric Sunshine
     [not found]     ` <CAPig+cTitT9Z+2pxeNh3dXi4b7X738qpkUnEmTi2yvQoCPtHqA@mail.g mail.com>
2013-05-20 20:01       ` (unknown), Marty Landman
2013-05-17 18:02 (unknown), ASHISH VERMA
2012-12-28 16:43 (unknown) Eric S. Raymond
2012-12-28 19:33 ` (unknown) Junio C Hamano
2012-10-17 12:16 (unknown), Marco Siegl | buerosiegl.com
2012-06-12 21:12 (unknown), rohit sood
2012-05-06 14:17 (unknown), Bruce Zu
2012-05-06 14:13 (unknown), Bruce Zu
2012-05-06 13:54 (unknown), Bruce Zu
2012-03-13 12:18 (unknown), Adam Kicak
2012-02-15  3:12 (unknown), Chris Leong
2012-02-09 23:58 (unknown), Zbigniew Jędrzejewski-Szmek
2012-02-08  0:41 (unknown), mstormo
2012-02-05 20:41 [PATCH] Change include order in two compat/ files to avoid compiler warning Junio C Hamano
2012-02-05 22:32 ` (unknown), Ben Walton
2012-01-10 23:56 (unknown), Steven Line
2011-11-10 22:56 (unknown), Marcel Schaible
2011-11-02 16:38 (unknown), Ben Walton
2011-08-18  6:36 (unknown) milki
2011-08-04 17:27 (unknown) Hin-Tak Leung
2011-05-26  9:02 (unknown) Nicole Hamilt
2011-02-02 17:31 (unknown), Kamol Siesan
2010-12-28 22:56 (unknown), COCA COLA
2010-12-27  6:07 (unknown), COCA COLA
2010-09-20 16:37 (unknown), Leonid Podolny
2010-09-17 18:39 (unknown), Michael Scholl
2010-05-07 21:46 (unknown), Mr Chen Guan
2010-05-07 21:46 (unknown), Mr Chen Guan
2010-05-07 21:46 (unknown), Mr Chen Guan
2010-03-25  5:53 (unknown) выгнать 
2010-03-19 21:12 (unknown), Michael Cox
2010-03-08 21:56 (unknown) Timur Aydin
2010-02-25  5:55 (unknown), yingshou guo
2010-01-22  2:14 (unknown), Horst H. von Brand
2009-09-12 13:00 (unknown) Tito
2009-07-24 21:21 [PATCH 0/2] Section renaming can lose content Alex Vandiver
2009-07-24 21:21 ` [PATCH 1/2] Make section_name_match start on '[', and return the length on success Alex Vandiver
2009-07-24 21:21   ` [PATCH 2/2] After renaming a section, print any trailing variable definitions Alex Vandiver
2009-07-24 22:11     ` Nanako Shiraishi
2009-07-24 23:39       ` Junio C Hamano
2009-07-25  0:28         ` (unknown), Nanako Shiraishi
2009-07-16 19:22 (unknown) Henrik Austad
2009-06-23  1:07 (unknown) Larry D'Anna
2009-05-27 13:28 (unknown), David Forman
2009-05-13  5:11 (unknown), Tom H
2009-05-11 18:57 (unknown) Don Slutz
2009-05-11 18:57 (unknown) Don Slutz
2009-05-11 18:57 (unknown) Don Slutz
2009-05-11 18:57 (unknown) Don Slutz
2009-05-11 18:57 (unknown) Don Slutz
2009-05-11 18:57 (unknown) Don Slutz
2009-05-11 18:57 (unknown) Don Slutz
2009-05-10 22:48 [JGIT PATCH 1/2] Fix deadlock in native git protocol client for upload-pack Shawn O. Pearce
2009-05-10 22:48 ` [JGIT PATCH 2/2] Decrease the fetch pack client buffer to the lower minimum Shawn O. Pearce
2009-05-11  0:43   ` Junio C Hamano
2009-05-11  0:55     ` Shawn O. Pearce
2009-05-11  3:51       ` Junio C Hamano
2009-05-11 14:10         ` Shawn O. Pearce
2009-05-11 14:23           ` (unknown), Carl Mercier
2009-05-07 17:01 (unknown), Bevan Watkiss
2009-04-16 23:17 (unknown), Fawad Hassan Ismail
2009-03-30  5:03 (unknown), David Aguilar
2009-03-27 20:39 (unknown), Lachlan Deck
2009-03-16 19:06 undoing something John Dlugosz
2009-03-16 19:14 ` Junio C Hamano
2009-03-16 19:48   ` John Dlugosz
2009-03-16 21:45     ` (unknown), Nanako Shiraishi
2009-03-13  8:21 (unknown) Werner Riener
2009-02-06  9:45 (unknown), info
2009-02-06  9:43 (unknown), info
2009-01-09 19:02 (unknown) nathan.panike
2008-10-05 23:36 (unknown), Robin Rosenberg
2008-08-21 19:15 (unknown) bpeeluk
2008-08-13 14:54 (unknown), aneesh.kumar
2008-06-23 20:54 (unknown), VIP Casino Club
2008-06-16 20:02 (unknown) amery
2008-06-16 19:42 (unknown) amery
2008-05-10 22:32 (unknown), Krzysztof Kowalczyk
2008-01-20 21:59 (unknown), Marc-André Lureau
2007-12-05 19:00 [PATCH 0/6] builtin-remote Johannes Schindelin
2007-12-05 19:00 ` (unknown) Johannes Schindelin
2007-11-26 20:00 (unknown) Michael Dressel
2007-11-11 13:08 (unknown) Michael Dressel
2007-11-01 20:44 (unknown), Francesco Pretto
2007-11-01 14:23 (unknown) Heikki Orsila
2007-10-22 18:16 (unknown) racin
2007-10-13  4:01 (unknown), Michael Witten
2007-09-04 13:59 (unknown) Russ Brown
2007-08-19 22:04 (unknown) Luciano Rocha
2007-07-01 18:25 (unknown) Sean D'Epagnier
2007-06-13  0:50 [PATCH] Interpret :/<pattern> as a regular expression Johannes Schindelin
2007-06-13  4:52 ` Junio C Hamano
2007-06-13 11:17   ` (unknown) Johannes Schindelin
2007-06-03 15:30 (unknown) Randal L. Schwartz
2007-05-06  3:51 (unknown), Aaron Gray
2007-04-04 16:59 (unknown) Geert Bosch
2007-03-18  9:36 [wishlist] git branch -d -r remotename Sam Vilain
2007-03-18 11:01 ` Sam Vilain
2007-03-18 11:01   ` Sam Vilain
2007-03-18 19:42     ` Junio C Hamano
2007-03-18 21:46       ` Sam Vilain
2007-03-19  6:18         ` Junio C Hamano
2007-03-19  6:40           ` Junio C Hamano
2007-03-19 23:37             ` (unknown) Sam Vilain
2006-11-21 22:24 (unknown) Johannes Schindelin
2006-10-25 14:50 (unknown) andyparkins
2006-10-25 14:49 (unknown) andyparkins
2006-10-25 18:41 ` (unknown) Junio C Hamano
2006-10-25 14:49 (unknown) andyparkins
2006-10-25 14:47 (unknown) andyparkins
2006-10-25 14:53 ` (unknown) Jakub Narebski
2006-10-25 15:10   ` (unknown) Andy Parkins
2006-10-25 15:31     ` (unknown) Karl Hasselström
2006-10-25 18:38     ` (unknown) Junio C Hamano
2006-10-25 22:03       ` (unknown) Andy Parkins
2006-10-25 22:16         ` (unknown) Junio C Hamano
2006-10-25 22:20           ` (unknown) Junio C Hamano
2006-10-26  7:14             ` (unknown) Andy Parkins
2006-10-26 13:22             ` (unknown) Josef Weidendorfer
2006-10-26 15:35               ` (unknown) Linus Torvalds
2006-10-25 22:16         ` (unknown) Shawn Pearce
2006-10-20 14:24 (unknown) andyparkins
2006-10-20 14:24 (unknown) andyparkins
2006-10-20 14:21 (unknown) andyparkins
2006-10-20 13:25 (unknown) andyparkins
2006-10-05  1:54 (unknown), JOSEPH KULIG
2006-09-24 21:55 (unknown) sonny132390
2006-09-21  4:04 (unknown) Nicolas Pitre
2006-09-09 21:46 (unknown), Rajkumar S
2006-08-18 10:35 (unknown), Wolfgang Denk
2006-07-01 15:33 (unknown), Mark
2006-05-26 15:16 (unknown) Juergen Ruehle
2006-05-21 23:53 (unknown) J. Bruce Fields
2006-05-21 23:53 ` (unknown) J. Bruce Fields
2006-05-21 23:53   ` (unknown) J. Bruce Fields
2006-03-28 19:31 (unknown) CustomerDepartament
2006-01-30 18:50 (unknown) Mark Wooding
2005-10-05  6:10 (unknown), Willem Swart
2005-07-23  9:10 (unknown) Junio Hamano
2005-05-28 14:15 (unknown) Thomas Glanzmann
2005-04-26 19:14 (unknown) Bram Cohen
2005-04-22 22:19 (unknown), atani
2005-04-18 22:45 (unknown), Matt W.
2005-04-16  0:51 (unknown) Scott Wright
2005-04-14 22:47 (unknown) Timo Hirvonen
2005-04-14 22:43 (unknown) Timo Hirvonen
2005-04-14 22:30 (unknown), Timo Hirvonen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5328e8bd.fNxY4x6POKCJfhV6%szager@chromium.org \
    --to=szager@chromium.org \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).