Skip to content

Commit 039e13b

Browse files
dschoGit for Windows Build Agent
authored andcommitted
Detect number of cores better on multi-socket systems (#6108)
While the currently used way to detect the number of CPU cores ond Windows is nice and straight-forward, GetSystemInfo() only [gives us access to the number of processors within the current group.](https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoapi-system_info#members) While that is usually fine for systems with a single physical CPU, separate physical sockets are typically separate groups. Switch to using GetLogicalProcessorInformationEx() to handle multi-socket systems better. I've tested this on a physical single-socket x86-64 and a physical dual-socket x86-64 system, and on a virtual single-socket ARM64 system. Physical [multi-socket ARM64 systems seem to exist](https://cloudbase.it/ampere-altra-industry-leading-arm64-server/), but I don't have access to such hardware and the hypervisor I use apparently can't emulate that either.
2 parents cf51487 + 5ce2b45 commit 039e13b

7 files changed

Lines changed: 45 additions & 9 deletions

File tree

Documentation/git-svn.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ SYNOPSIS
99
--------
1010
[verse]
1111
'git svn' <command> [<options>] [<arguments>]
12+
(UNSUPPORTED!)
1213

1314
DESCRIPTION
1415
-----------

git-svn.perl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,19 @@ sub term_init {
305305
: new Term::ReadLine 'git-svn';
306306
}
307307

308+
sub deprecated_warning {
309+
my @lines = @_;
310+
if (-t STDERR) {
311+
@lines = map { "\e[33m$_\e[0m" } @lines;
312+
}
313+
warn join("\n", @lines), "\n";
314+
}
315+
316+
deprecated_warning(
317+
"WARNING: \`git svn\` is no longer supported by the Git for Windows project.",
318+
"See https://github.com/git-for-windows/git/issues/5405 for details."
319+
);
320+
308321
my $cmd;
309322
for (my $i = 0; $i < @ARGV; $i++) {
310323
if (defined $cmd{$ARGV[$i]}) {

http.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ static long http_retry_after = 0;
162162
static long http_max_retries = 0;
163163
static long http_max_retry_time = 300;
164164

165+
165166
/*
166167
* With the backend being set to `schannel`, setting sslCAinfo would override
167168
* the Certificate Store in cURL v7.60.0 and later, which is not what we want

t/t9108-git-svn-glob.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ test_expect_success 'test disallow multi-globs' '
110110
svn_cmd commit -m "try to try"
111111
) &&
112112
test_must_fail git svn fetch three 2> stderr.three &&
113-
test_cmp expect.three stderr.three
113+
sed "/^WARNING.*no.* supported/{N;d}" <stderr.three >stderr.three.clean &&
114+
test_cmp expect.three stderr.three.clean
114115
'
115116

116117
test_done

t/t9109-git-svn-multi-glob.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ test_expect_success 'test disallow multiple globs' '
161161
svn_cmd commit -m "try to try"
162162
) &&
163163
test_must_fail git svn fetch three 2> stderr.three &&
164-
test_cmp expect.three stderr.three
164+
sed "/^WARNING.*no.* supported/{N;d}" <stderr.three >stderr.three.clean &&
165+
test_cmp expect.three stderr.three.clean
165166
'
166167

167168
test_done

t/t9168-git-svn-partially-globbed-names.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ test_expect_success 'test disallow prefixed multi-globs' '
155155
svn_cmd commit -m "try to try"
156156
) &&
157157
test_must_fail git svn fetch four 2>stderr.four &&
158-
test_cmp expect.four stderr.four &&
158+
sed "/^WARNING.*no.* supported/{N;d}" <stderr.four >stderr.four.clean &&
159+
test_cmp expect.four stderr.four.clean &&
159160
git config --unset svn-remote.four.branches &&
160161
git config --unset svn-remote.four.tags
161162
'
@@ -223,7 +224,8 @@ test_expect_success 'test disallow multiple asterisks in one word' '
223224
svn_cmd commit -m "try to try"
224225
) &&
225226
test_must_fail git svn fetch six 2>stderr.six &&
226-
test_cmp expect.six stderr.six
227+
sed "/^WARNING.*no.* supported/{N;d}" <stderr.six >stderr.six.clean &&
228+
test_cmp expect.six stderr.six.clean
227229
'
228230

229231
test_done

thread-utils.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,28 @@ int online_cpus(void)
2828
#endif
2929

3030
#ifdef GIT_WINDOWS_NATIVE
31-
SYSTEM_INFO info;
32-
GetSystemInfo(&info);
33-
34-
if ((int)info.dwNumberOfProcessors > 0)
35-
return (int)info.dwNumberOfProcessors;
31+
DWORD len = 0;
32+
if (!GetLogicalProcessorInformationEx(RelationProcessorCore, NULL, &len) && GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
33+
uint8_t *buf = malloc(len);
34+
if (buf) {
35+
if (GetLogicalProcessorInformationEx(RelationProcessorCore, (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX) buf, &len)) {
36+
DWORD offset = 0;
37+
int n_cores = 0;
38+
while (offset < len) {
39+
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX info = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX) (buf + offset);
40+
offset += info->Size;
41+
/* The threads within a core always share a single group. We need to count the bits in the mask to get a thread count. */
42+
for (KAFFINITY mask = info->Processor.GroupMask[0].Mask; mask; mask >>= 1)
43+
n_cores += mask &1;
44+
}
45+
if (n_cores) {
46+
free(buf);
47+
return n_cores;
48+
}
49+
}
50+
free(buf);
51+
}
52+
}
3653
#elif defined(hpux) || defined(__hpux) || defined(_hpux)
3754
struct pst_dynamic psd;
3855

0 commit comments

Comments
 (0)