From: Ben Peart <Ben.Peart@microsoft.com>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: "David.Turner@twosigma.com" <David.Turner@twosigma.com>,
"avarab@gmail.com" <avarab@gmail.com>,
"christian.couder@gmail.com" <christian.couder@gmail.com>,
"git@vger.kernel.org" <git@vger.kernel.org>,
"gitster@pobox.com" <gitster@pobox.com>,
"pclouds@gmail.com" <pclouds@gmail.com>,
"peff@peff.net" <peff@peff.net>
Subject: RE: [PATCH v6 12/12] fsmonitor: add a performance test
Date: Mon, 18 Sep 2017 18:19:54 +0000 [thread overview]
Message-ID: <MWHPR21MB04789C11E37F58FF9BC11C51F4630@MWHPR21MB0478.namprd21.prod.outlook.com> (raw)
In-Reply-To: <alpine.DEB.2.21.1.1709181615040.219280@virtualbox>
> -----Original Message-----
> From: Johannes Schindelin [mailto:Johannes.Schindelin@gmx.de]
> Sent: Monday, September 18, 2017 10:25 AM
> To: Ben Peart <Ben.Peart@microsoft.com>
> Cc: David.Turner@twosigma.com; avarab@gmail.com;
> christian.couder@gmail.com; git@vger.kernel.org; gitster@pobox.com;
> pclouds@gmail.com; peff@peff.net
> Subject: Re: [PATCH v6 12/12] fsmonitor: add a performance test
>
> Hi Ben,
>
> sorry for not catching this earlier:
>
> On Fri, 15 Sep 2017, Ben Peart wrote:
>
> > [...]
> > +
> > +int cmd_dropcaches(void)
> > +{
> > + HANDLE hProcess = GetCurrentProcess();
> > + HANDLE hToken;
> > + int status;
> > +
> > + if (!OpenProcessToken(hProcess, TOKEN_QUERY |
> TOKEN_ADJUST_PRIVILEGES, &hToken))
> > + return error("Can't open current process token");
> > +
> > + if (!GetPrivilege(hToken, "SeProfileSingleProcessPrivilege", 1))
> > + return error("Can't get SeProfileSingleProcessPrivilege");
> > +
> > + CloseHandle(hToken);
> > +
> > + HMODULE ntdll = LoadLibrary("ntdll.dll");
>
Thanks Johannes, I'll fix that.
> Git's source code still tries to abide by C90, and for simplicity's sake, this
> extends to the Windows-specific part. Therefore, the `ntdll` variable needs to
> be declared at the beginning of the function (I do agree that it makes for
> better code to reduce the scope of variables, but C90 simply did not allow
> variables to be declared in the middle of functions).
>
> I wanted to send a patch address this in the obvious way, but then I
> encountered these lines:
>
> > + DWORD(WINAPI *NtSetSystemInformation)(INT, PVOID, ULONG) =
> > + (DWORD(WINAPI *)(INT, PVOID,
> ULONG))GetProcAddress(ntdll, "NtSetSystemInformation");
> > + if (!NtSetSystemInformation)
> > + return error("Can't get function addresses, wrong Windows
> > +version?");
>
> It turns out that we have seen this plenty of times in Git for Windows'
> fork, so much so that we came up with a nice helper to make this all a bit
> more robust and a bit more obvious, too: the DECLARE_PROC_ADDR and
> INIT_PROC_ADDR helpers in compat/win32/lazyload.h.
>
> Maybe this would be the perfect excuse to integrate this patch into upstream
> Git?
This patch is pretty hefty already. How about you push this capability
upstream and I take advantage of it in a later patch. :)
This would be the patch (you can also cherry-pick it from
> 25c4dc3a73352e72e995594cf1b4afa46e93d040 in
> https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.
> com%2Fdscho%2Fgit&data=02%7C01%7CBen.Peart%40microsoft.com%7C96
> 4027bdc1f34a033c1f08d4fea1056e%7C72f988bf86f141af91ab2d7cd011db47
> %7C1%7C0%7C636413414914282865&sdata=jyvu6G7myRY9UA1XxWx2tDZ%
> 2BWsIWqLTRMT8WfzEGe5g%3D&reserved=0):
>
> -- snip --
> From 25c4dc3a73352e72e995594cf1b4afa46e93d040 Mon Sep 17 00:00:00
> 2001
> From: Johannes Schindelin <johannes.schindelin@gmx.de>
> Date: Tue, 10 Jan 2017 23:14:20 +0100
> Subject: [PATCH] Win32: simplify loading of DLL functions
>
> Dynamic loading of DLL functions is duplicated in several places in Git for
> Windows' source code.
>
> This patch adds a pair of macros to simplify the process: the
> DECLARE_PROC_ADDR(<dll>, <return-type>, <function-name>,
> ...<function-parameter-types>...) macro to be used at the beginning of a
> code block, and the INIT_PROC_ADDR(<function-name>) macro to call before
> using the declared function. The return value of the INIT_PROC_ADDR() call
> has to be checked; If it is NULL, the function was not found in the specified
> DLL.
>
> Example:
>
> DECLARE_PROC_ADDR(kernel32.dll, BOOL, CreateHardLinkW,
> LPCWSTR, LPCWSTR, LPSECURITY_ATTRIBUTES);
>
> if (!INIT_PROC_ADDR(CreateHardLinkW))
> return error("Could not find CreateHardLinkW() function";
>
> if (!CreateHardLinkW(source, target, NULL))
> return error("could not create hardlink from %S to %S",
> source, target);
> return 0;
>
> Signed-off-by: Karsten Blees <blees@dcon.de>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
> compat/win32/lazyload.h | 44
> ++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 44 insertions(+)
> create mode 100644 compat/win32/lazyload.h
>
> diff --git a/compat/win32/lazyload.h b/compat/win32/lazyload.h new file
> mode 100644 index 00000000000..91c10dad2fb
> --- /dev/null
> +++ b/compat/win32/lazyload.h
> @@ -0,0 +1,44 @@
> +#ifndef LAZYLOAD_H
> +#define LAZYLOAD_H
> +
> +/* simplify loading of DLL functions */
> +
> +struct proc_addr {
> + const char *const dll;
> + const char *const function;
> + FARPROC pfunction;
> + unsigned initialized : 1;
> +};
> +
> +/* Declares a function to be loaded dynamically from a DLL. */ #define
> +DECLARE_PROC_ADDR(dll, rettype, function, ...) \
> + static struct proc_addr proc_addr_##function = \
> + { #dll, #function, NULL, 0 }; \
> + static rettype (WINAPI *function)(__VA_ARGS__)
> +
> +/*
> + * Loads a function from a DLL (once-only).
> + * Returns non-NULL function pointer on success.
> + * Returns NULL + errno == ENOSYS on failure.
> + */
> +#define INIT_PROC_ADDR(function) \
> + (function = get_proc_addr(&proc_addr_##function))
> +
> +static inline void *get_proc_addr(struct proc_addr *proc) {
> + /* only do this once */
> + if (!proc->initialized) {
> + HANDLE hnd;
> + proc->initialized = 1;
> + hnd = LoadLibraryExA(proc->dll, NULL,
> + LOAD_LIBRARY_SEARCH_SYSTEM32);
> + if (hnd)
> + proc->pfunction = GetProcAddress(hnd, proc-
> >function);
> + }
> + /* set ENOSYS if DLL or function was not found */
> + if (!proc->pfunction)
> + errno = ENOSYS;
> + return proc->pfunction;
> +}
> +
> +#endif
> -- snap --
>
> With this patch, this fixup to your patch would make things compile (you can
> also cherry-pick d05996fb61027512b8ab31a36c4a7a677dea11bb from my
> fork):
>
> -- snipsnap --
> From d05996fb61027512b8ab31a36c4a7a677dea11bb Mon Sep 17 00:00:00
> 2001
> From: Johannes Schindelin <johannes.schindelin@gmx.de>
> Date: Mon, 18 Sep 2017 14:56:40 +0200
> Subject: [PATCH] fixup! fsmonitor: add a performance test
>
> ---
> t/helper/test-drop-caches.c | 16 ++++++----------
> 1 file changed, 6 insertions(+), 10 deletions(-)
>
> diff --git a/t/helper/test-drop-caches.c b/t/helper/test-drop-caches.c index
> 717079865cb..b27358528f7 100644
> --- a/t/helper/test-drop-caches.c
> +++ b/t/helper/test-drop-caches.c
> @@ -1,6 +1,7 @@
> #include "git-compat-util.h"
>
> #if defined(GIT_WINDOWS_NATIVE)
> +#include "compat/win32/lazyload.h"
>
> int cmd_sync(void)
> {
> @@ -82,6 +83,9 @@ int cmd_dropcaches(void)
> HANDLE hProcess = GetCurrentProcess();
> HANDLE hToken;
> int status;
> + SYSTEM_MEMORY_LIST_COMMAND command;
> + DECLARE_PROC_ADDR(ntll,
> + DWORD, NtSetSystemInformation, INT, PVOID,
> ULONG);
>
> if (!OpenProcessToken(hProcess, TOKEN_QUERY |
> TOKEN_ADJUST_PRIVILEGES, &hToken))
> return error("Can't open current process token"); @@ -91,16
> +95,10 @@ int cmd_dropcaches(void)
>
> CloseHandle(hToken);
>
> - HMODULE ntdll = LoadLibrary("ntdll.dll");
> - if (!ntdll)
> - return error("Can't load ntdll.dll, wrong Windows
> version?");
> -
> - DWORD(WINAPI *NtSetSystemInformation)(INT, PVOID, ULONG) =
> - (DWORD(WINAPI *)(INT, PVOID,
> ULONG))GetProcAddress(ntdll,
> "NtSetSystemInformation");
> - if (!NtSetSystemInformation)
> + if (!INIT_PROC_ADDR(NtSetSystemInformation))
> return error("Can't get function addresses, wrong Windows
> version?");
>
> - SYSTEM_MEMORY_LIST_COMMAND command =
> MemoryPurgeStandbyList;
> + command = MemoryPurgeStandbyList;
> status = NtSetSystemInformation(
> SystemMemoryListInformation,
> &command,
> @@ -111,8 +109,6 @@ int cmd_dropcaches(void)
> else if (status != STATUS_SUCCESS)
> error("Unable to execute the memory list command %d",
> status);
>
> - FreeLibrary(ntdll);
> -
> return status;
> }
>
> --
> 2.14.1.windows.1.510.g0cb6d35d23
next prev parent reply other threads:[~2017-09-18 18:20 UTC|newest]
Thread overview: 137+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-10 13:40 [PATCH v5 0/7] Fast git status via a file system watcher Ben Peart
2017-06-10 13:40 ` [PATCH v5 1/7] bswap: add 64 bit endianness helper get_be64 Ben Peart
2017-06-10 13:40 ` [PATCH v5 2/7] dir: make lookup_untracked() available outside of dir.c Ben Peart
2017-06-10 13:40 ` [PATCH v5 3/7] fsmonitor: teach git to optionally utilize a file system monitor to speed up detecting new or changed files Ben Peart
2017-06-27 15:43 ` Christian Couder
2017-07-03 21:25 ` Ben Peart
2017-06-10 13:40 ` [PATCH v5 4/7] fsmonitor: add test cases for fsmonitor extension Ben Peart
2017-06-27 16:20 ` Christian Couder
2017-07-07 18:50 ` Ben Peart
2017-06-10 13:40 ` [PATCH v5 5/7] fsmonitor: add documentation for the " Ben Peart
2017-06-10 13:40 ` [PATCH v5 6/7] fsmonitor: add a sample query-fsmonitor hook script for Watchman Ben Peart
2017-06-10 13:40 ` [PATCH v5 7/7] fsmonitor: add a performance test Ben Peart
2017-06-10 14:04 ` Ben Peart
2017-06-12 22:04 ` Junio C Hamano
2017-06-14 14:12 ` Ben Peart
2017-06-14 18:36 ` Junio C Hamano
2017-07-07 18:14 ` Ben Peart
2017-07-07 18:35 ` Junio C Hamano
2017-07-07 19:07 ` Ben Peart
2017-07-07 19:33 ` David Turner
2017-07-08 7:19 ` Christian Couder
2017-06-28 5:11 ` [PATCH v5 0/7] Fast git status via a file system watcher Christian Couder
2017-07-10 13:36 ` Ben Peart
2017-07-10 14:40 ` Ben Peart
2017-09-15 19:20 ` [PATCH v6 00/12] " Ben Peart
2017-09-15 19:20 ` [PATCH v6 01/12] bswap: add 64 bit endianness helper get_be64 Ben Peart
2017-09-15 19:20 ` [PATCH v6 02/12] preload-index: add override to enable testing preload-index Ben Peart
2017-09-15 19:20 ` [PATCH v6 03/12] update-index: add a new --force-write-index option Ben Peart
2017-09-15 19:20 ` [PATCH v6 04/12] fsmonitor: teach git to optionally utilize a file system monitor to speed up detecting new or changed files Ben Peart
2017-09-15 21:35 ` David Turner
2017-09-18 13:07 ` Ben Peart
2017-09-18 13:32 ` David Turner
2017-09-18 13:49 ` Ben Peart
2017-09-15 19:20 ` [PATCH v6 05/12] fsmonitor: add documentation for the fsmonitor extension Ben Peart
2017-09-15 19:43 ` David Turner
2017-09-18 13:27 ` Ben Peart
2017-09-17 8:03 ` Junio C Hamano
2017-09-18 13:29 ` Ben Peart
2017-09-15 19:20 ` [PATCH v6 06/12] ls-files: Add support in ls-files to display the fsmonitor valid bit Ben Peart
2017-09-15 20:34 ` David Turner
2017-09-15 19:20 ` [PATCH v6 07/12] update-index: add fsmonitor support to update-index Ben Peart
2017-09-15 19:20 ` [PATCH v6 08/12] fsmonitor: add a test tool to dump the index extension Ben Peart
2017-09-17 8:02 ` Junio C Hamano
2017-09-18 13:38 ` Ben Peart
2017-09-18 15:43 ` Torsten Bögershausen
2017-09-18 16:28 ` Ben Peart
2017-09-19 14:16 ` Torsten Bögershausen
2017-09-19 15:36 ` Ben Peart
2017-09-15 19:20 ` [PATCH v6 09/12] split-index: disable the fsmonitor extension when running the split index test Ben Peart
2017-09-19 20:43 ` Jonathan Nieder
2017-09-20 17:11 ` Ben Peart
2017-09-20 17:46 ` Jonathan Nieder
2017-09-21 0:05 ` Ben Peart
2017-09-15 19:20 ` [PATCH v6 10/12] fsmonitor: add test cases for fsmonitor extension Ben Peart
2017-09-15 22:00 ` David Turner
2017-09-19 19:32 ` David Turner
2017-09-19 20:30 ` Ben Peart
2017-09-16 15:27 ` Torsten Bögershausen
2017-09-17 5:43 ` [PATCH v1 1/1] test-lint: echo -e (or -E) is not portable tboegi
2017-09-19 20:37 ` Jonathan Nieder
2017-09-20 13:49 ` Torsten Bögershausen
2017-09-22 1:04 ` Junio C Hamano
2017-09-18 14:06 ` [PATCH v6 10/12] fsmonitor: add test cases for fsmonitor extension Ben Peart
2017-09-17 4:47 ` Junio C Hamano
2017-09-18 15:25 ` Ben Peart
2017-09-19 20:34 ` Jonathan Nieder
2017-09-15 19:20 ` [PATCH v6 11/12] fsmonitor: add a sample integration script for Watchman Ben Peart
2017-09-15 19:20 ` [PATCH v6 12/12] fsmonitor: add a performance test Ben Peart
2017-09-15 21:56 ` David Turner
2017-09-18 14:24 ` Johannes Schindelin
2017-09-18 18:19 ` Ben Peart [this message]
2017-09-19 15:28 ` Johannes Schindelin
2017-09-19 19:27 ` [PATCH v7 00/12] Fast git status via a file system watcher Ben Peart
2017-09-19 19:27 ` [PATCH v7 01/12] bswap: add 64 bit endianness helper get_be64 Ben Peart
2017-09-19 19:27 ` [PATCH v7 02/12] preload-index: add override to enable testing preload-index Ben Peart
2017-09-20 22:06 ` Stefan Beller
2017-09-21 0:02 ` Ben Peart
2017-09-21 0:44 ` Stefan Beller
2017-09-19 19:27 ` [PATCH v7 03/12] update-index: add a new --force-write-index option Ben Peart
2017-09-20 5:47 ` Junio C Hamano
2017-09-20 14:58 ` Ben Peart
2017-09-21 1:46 ` Junio C Hamano
2017-09-21 2:06 ` Ben Peart
2017-09-21 2:18 ` Junio C Hamano
2017-09-21 2:32 ` Junio C Hamano
2017-09-19 19:27 ` [PATCH v7 04/12] fsmonitor: teach git to optionally utilize a file system monitor to speed up detecting new or changed files Ben Peart
2017-09-20 2:28 ` Junio C Hamano
2017-09-20 16:19 ` Ben Peart
2017-09-21 2:00 ` Junio C Hamano
2017-09-21 2:24 ` Ben Peart
2017-09-21 14:35 ` Ben Peart
2017-09-22 1:02 ` Junio C Hamano
2017-09-20 6:23 ` Junio C Hamano
2017-09-20 16:29 ` Ben Peart
2017-09-19 19:27 ` [PATCH v7 05/12] fsmonitor: add documentation for the fsmonitor extension Ben Peart
2017-09-20 10:00 ` Martin Ågren
2017-09-20 17:02 ` Ben Peart
2017-09-20 17:11 ` Martin Ågren
2017-09-19 19:27 ` [PATCH v7 06/12] ls-files: Add support in ls-files to display the fsmonitor valid bit Ben Peart
2017-09-19 19:46 ` David Turner
2017-09-19 20:44 ` Ben Peart
2017-09-19 21:27 ` David Turner
2017-09-19 22:44 ` Ben Peart
2017-09-19 19:27 ` [PATCH v7 07/12] update-index: add fsmonitor support to update-index Ben Peart
2017-09-19 19:27 ` [PATCH v7 08/12] fsmonitor: add a test tool to dump the index extension Ben Peart
2017-09-19 19:27 ` [PATCH v7 09/12] split-index: disable the fsmonitor extension when running the split index test Ben Peart
2017-09-19 19:27 ` [PATCH v7 10/12] fsmonitor: add test cases for fsmonitor extension Ben Peart
2017-09-19 19:27 ` [PATCH v7 11/12] fsmonitor: add a sample integration script for Watchman Ben Peart
2017-09-19 19:27 ` [PATCH v7 12/12] fsmonitor: add a performance test Ben Peart
2017-09-22 16:35 ` [PATCH v8 00/12] Fast git status via a file system watcher Ben Peart
2017-09-22 16:35 ` [PATCH v8 01/12] bswap: add 64 bit endianness helper get_be64 Ben Peart
2017-09-22 23:37 ` Martin Ågren
2017-09-23 23:31 ` Ben Peart
2017-09-24 3:51 ` Jeff King
2017-09-24 3:52 ` Junio C Hamano
2017-09-22 16:35 ` [PATCH v8 02/12] preload-index: add override to enable testing preload-index Ben Peart
2017-09-22 16:35 ` [PATCH v8 03/12] update-index: add a new --force-write-index option Ben Peart
2017-09-22 16:35 ` [PATCH v8 04/12] fsmonitor: teach git to optionally utilize a file system monitor to speed up detecting new or changed files Ben Peart
2017-09-22 16:35 ` [PATCH v8 05/12] fsmonitor: add documentation for the fsmonitor extension Ben Peart
2017-09-22 16:35 ` [PATCH v8 06/12] ls-files: Add support in ls-files to display the fsmonitor valid bit Ben Peart
2017-09-22 16:35 ` [PATCH v8 07/12] update-index: add fsmonitor support to update-index Ben Peart
2017-09-22 16:35 ` [PATCH v8 08/12] fsmonitor: add a test tool to dump the index extension Ben Peart
2017-09-22 23:37 ` Martin Ågren
2017-09-23 23:33 ` Ben Peart
2017-09-24 3:51 ` Junio C Hamano
2017-09-22 16:35 ` [PATCH v8 09/12] split-index: disable the fsmonitor extension when running the split index test Ben Peart
2017-09-22 16:35 ` [PATCH v8 10/12] fsmonitor: add test cases for fsmonitor extension Ben Peart
2017-09-22 16:35 ` [PATCH v8 11/12] fsmonitor: add a sample integration script for Watchman Ben Peart
2017-09-22 16:35 ` [PATCH v8 12/12] fsmonitor: add a performance test Ben Peart
2017-09-29 2:20 ` [PATCH v8 00/12] Fast git status via a file system watcher Junio C Hamano
2017-09-29 12:07 ` Ben Peart
2017-10-01 8:24 ` Junio C Hamano
2017-10-03 19:48 ` Ben Peart
2017-10-04 2:09 ` Junio C Hamano
2017-10-04 6:38 ` Alex Vandiver
2017-10-04 12:48 ` Ben Peart
2017-10-04 12:27 ` Ben Peart
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=MWHPR21MB04789C11E37F58FF9BC11C51F4630@MWHPR21MB0478.namprd21.prod.outlook.com \
--to=ben.peart@microsoft.com \
--cc=David.Turner@twosigma.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=avarab@gmail.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=pclouds@gmail.com \
--cc=peff@peff.net \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).