From: Zebediah Figura Subject: Re: [PATCH 1/3] ntdll: Reimplement NtQuerySystemInformation(SystemProcessInformation) using a single server call. Message-Id: <06994577-85ab-fa50-1720-79480fad5aa8@codeweavers.com> Date: Thu, 2 Jul 2020 11:39:45 -0500 In-Reply-To: <64e80382-b34b-5842-d7c4-fd7fba3a04d7@codeweavers.com> References: <20200702031814.1078606-1-zfigura@codeweavers.com> <64e80382-b34b-5842-d7c4-fd7fba3a04d7@codeweavers.com> On 7/2/20 11:24 AM, Rémi Bernon wrote: > On 2020-07-02 05:18, Zebediah Figura wrote: >> Signed-off-by: Zebediah Figura >> --- >> This decreases CPU usage by wineserver from about 65% to about 45% for >> me in >> Street Fighter V, which for some reason calls this 15-20 times per >> second. >> >>   dlls/ntdll/unix/system.c | 177 ++++++++++++++++----------------------- >>   server/process.c         |  56 +++++++++++++ >>   server/protocol.def      |  30 +++++++ >>   server/trace.c           |  34 ++++++++ >>   4 files changed, 191 insertions(+), 106 deletions(-) >> >> diff --git a/dlls/ntdll/unix/system.c b/dlls/ntdll/unix/system.c >> index 7045bc1550b..f89208997e2 100644 >> --- a/dlls/ntdll/unix/system.c >> +++ b/dlls/ntdll/unix/system.c >> @@ -2083,132 +2083,97 @@ NTSTATUS WINAPI NtQuerySystemInformation( >> SYSTEM_INFORMATION_CLASS class, >>         case SystemProcessInformation: >>       { >> -        SYSTEM_PROCESS_INFORMATION *spi = info; >> -        SYSTEM_PROCESS_INFORMATION *last = NULL; >> -        HANDLE handle = 0; >> -        WCHAR procname[1024]; >> -        WCHAR* exename; >> -        DWORD wlen = 0; >> -        DWORD procstructlen = 0; >> +        unsigned int process_count, i, j; >> +        const struct process_info *server_process; >> +        void *buffer = NULL; >>   -        SERVER_START_REQ( create_snapshot ) >> +        if (size && !(buffer = RtlAllocateHeap( GetProcessHeap(), 0, >> size ))) >>           { >> -            req->flags = SNAP_PROCESS | SNAP_THREAD; >> -            if (!(ret = wine_server_call( req ))) handle = >> wine_server_ptr_handle( reply->handle ); >> +            ret = STATUS_NO_MEMORY; >> +            break; >>           } >> -        SERVER_END_REQ; >>   > Shouldn't the allocated buffer size depend on the data to be read? If > there's some very long paths there, the application buffer size may not > be large enough, although it would have been enough to store the process > infos with just their basename. Maybe, though I doubt it matters in practice. SystemProcessInformation is by nature never going to have a stable length. In any case I wanted to avoid having to make even two server calls where one would suffice. > Or the server has to return only > basenames, and assert that the client structures are larger than server > request structures. I guess stripping the rest of the path on the server side isn't a bad idea anyway, though. -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEENTo75Twe9rbPART3DZ01igeheEAFAl7+DdEACgkQDZ01igeh eEAR/Af+Iv9ssm1M86ksUy5qbF/oLgurg5l4jCY/oSo95Z56hWltpdfs3Xy301K4 ZHO3kDRb8HcvSIUnkULcT5JOT/qgtJRBnnly9/dLY9yD+A0TaAq1Ep/tapdkgkkA mtRZKfvIRx7MPUtFwnt/Y1efSnQSZOAaydqzEVRVNaJhgcCnF1ravVF1FS7j36Rx hqNbkHuit9JHQMJCutM5sF5dTjd2TytJtphC/taAzHiiC/V9X9l0Bj3vskpcCdpo QW/PknlO/XjlbxT8eMJk+WgtiqaDPMmeaCjp/zCT7Q2V6aIfuM2rShOcpMAutpox VbD4yRhb5NP4HJRSSpCO/JWjxugCjQ== =SBXA -----END PGP SIGNATURE-----