Cygwin: drop support for systems not supporting processor groups

i. e., Vista/2008.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2021-10-29 18:11:27 +02:00
parent 4bc8f1adb4
commit 687c4bad28
6 changed files with 58 additions and 169 deletions

View File

@ -665,26 +665,15 @@ format_proc_cpuinfo (void *, char *&destbuf)
WORD cpu_group = cpu_number / num_cpu_per_group;
KAFFINITY cpu_mask = 1L << (cpu_number % num_cpu_per_group);
GROUP_AFFINITY affinity = {
.Mask = cpu_mask,
.Group = cpu_group,
};
if (wincap.has_processor_groups ())
{
GROUP_AFFINITY affinity = {
.Mask = cpu_mask,
.Group = cpu_group,
};
if (!SetThreadGroupAffinity (GetCurrentThread (), &affinity,
&orig_group_affinity))
system_printf ("SetThreadGroupAffinity(%x,%d (%x/%d)) failed %E", cpu_mask, cpu_group, cpu_number, cpu_number);
orig_affinity_mask = 1; /* Just mark success. */
}
else
{
orig_affinity_mask = SetThreadAffinityMask (GetCurrentThread (),
1 << cpu_number);
if (orig_affinity_mask == 0)
debug_printf ("SetThreadAffinityMask failed %E");
}
if (!SetThreadGroupAffinity (GetCurrentThread (), &affinity,
&orig_group_affinity))
system_printf ("SetThreadGroupAffinity(%x,%d (%x/%d)) failed %E", cpu_mask, cpu_group, cpu_number, cpu_number);
orig_affinity_mask = 1; /* Just mark success. */
/* I'm not sure whether the thread changes processor immediately
and I'm not sure whether this function will cause the thread
to be rescheduled */
@ -1668,13 +1657,8 @@ format_proc_cpuinfo (void *, char *&destbuf)
}
if (orig_affinity_mask != 0)
{
if (wincap.has_processor_groups ())
SetThreadGroupAffinity (GetCurrentThread (), &orig_group_affinity,
NULL);
else
SetThreadAffinityMask (GetCurrentThread (), orig_affinity_mask);
}
SetThreadGroupAffinity (GetCurrentThread (), &orig_group_affinity,
NULL);
print ("\n");
}

View File

@ -1047,11 +1047,9 @@ __get_cpus_per_group (void)
(PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX) tp.c_get ();
DWORD lpi_size = NT_MAX_PATH;
/* Fake a SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX group info block on Vista
systems. This may be over the top but if the below code just using
ActiveProcessorCount turns out to be insufficient, we can build on that. */
if (!wincap.has_processor_groups ()
|| !GetLogicalProcessorInformationEx (RelationGroup, lpi, &lpi_size))
/* Fake a SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX group info block if
GetLogicalProcessorInformationEx fails for some reason. */
if (!GetLogicalProcessorInformationEx (RelationGroup, lpi, &lpi_size))
{
lpi_size = sizeof *lpi;
lpi->Relationship = RelationGroup;

View File

@ -416,9 +416,6 @@ EXPORT_ALIAS (sched_yield, pthread_yield)
int
sched_getcpu ()
{
if (!wincap.has_processor_groups ())
return (int) GetCurrentProcessorNumber ();
PROCESSOR_NUMBER pnum;
GetCurrentProcessorNumberEx (&pnum);
@ -520,33 +517,18 @@ whichgroup (size_t sizeof_set, const cpu_set_t *set)
int
sched_get_thread_affinity (HANDLE thread, size_t sizeof_set, cpu_set_t *set)
{
GROUP_AFFINITY ga;
int status = 0;
if (thread)
{
memset (set, 0, sizeof_set);
if (wincap.has_processor_groups () && __get_group_count () > 1)
if (!GetThreadGroupAffinity (thread, &ga))
{
GROUP_AFFINITY ga;
if (!GetThreadGroupAffinity (thread, &ga))
{
status = geterrno_from_win_error (GetLastError (), EPERM);
goto done;
}
setgroup (sizeof_set, set, ga.Group, ga.Mask);
}
else
{
THREAD_BASIC_INFORMATION tbi;
status = NtQueryInformationThread (thread, ThreadBasicInformation,
&tbi, sizeof (tbi), NULL);
if (NT_SUCCESS (status))
setgroup (sizeof_set, set, 0, tbi.AffinityMask);
else
status = geterrno_from_nt_status (status);
status = geterrno_from_win_error (GetLastError (), EPERM);
goto done;
}
setgroup (sizeof_set, set, ga.Group, ga.Mask);
}
else
status = ESRCH;
@ -570,6 +552,8 @@ __sched_getaffinity_sys (pid_t pid, size_t sizeof_set, cpu_set_t *set)
p->dwProcessId) : GetCurrentProcess ();
KAFFINITY procmask;
KAFFINITY sysmask;
USHORT groupcount = __CPU_GROUPMAX;
USHORT grouparray[__CPU_GROUPMAX];
if (!GetProcessAffinityMask (process, &procmask, &sysmask))
{
@ -577,23 +561,15 @@ __sched_getaffinity_sys (pid_t pid, size_t sizeof_set, cpu_set_t *set)
goto done;
}
memset (set, 0, sizeof_set);
if (wincap.has_processor_groups () && __get_group_count () > 1)
{
USHORT groupcount = __CPU_GROUPMAX;
USHORT grouparray[__CPU_GROUPMAX];
if (!GetProcessGroupAffinity (process, &groupcount, grouparray))
{
status = geterrno_from_win_error (GetLastError (), EPERM);
goto done;
}
if (!GetProcessGroupAffinity (process, &groupcount, grouparray))
{
status = geterrno_from_win_error (GetLastError (), EPERM);
goto done;
}
KAFFINITY miscmask = groupmask (__get_cpus_per_group ());
for (int i = 0; i < groupcount; i++)
setgroup (sizeof_set, set, grouparray[i], miscmask);
}
else
setgroup (sizeof_set, set, 0, procmask);
KAFFINITY miscmask = groupmask (__get_cpus_per_group ());
for (int i = 0; i < groupcount; i++)
setgroup (sizeof_set, set, grouparray[i], miscmask);
}
else
status = ESRCH;
@ -625,41 +601,24 @@ sched_getaffinity (pid_t pid, size_t sizeof_set, cpu_set_t *set)
int
sched_set_thread_affinity (HANDLE thread, size_t sizeof_set, const cpu_set_t *set)
{
GROUP_AFFINITY ga;
int group = whichgroup (sizeof_set, set);
int status = 0;
if (thread)
{
if (wincap.has_processor_groups () && __get_group_count () > 1)
if (group < 0)
{
GROUP_AFFINITY ga;
if (group < 0)
{
status = EINVAL;
goto done;
}
memset (&ga, 0, sizeof (ga));
ga.Mask = getgroup (sizeof_set, set, group);
ga.Group = group;
if (!SetThreadGroupAffinity (thread, &ga, NULL))
{
status = geterrno_from_win_error (GetLastError (), EPERM);
goto done;
}
status = EINVAL;
goto done;
}
else
memset (&ga, 0, sizeof (ga));
ga.Mask = getgroup (sizeof_set, set, group);
ga.Group = group;
if (!SetThreadGroupAffinity (thread, &ga, NULL))
{
if (group != 0)
{
status = EINVAL;
goto done;
}
if (!SetThreadAffinityMask (thread, getgroup (sizeof_set, set, 0)))
{
status = geterrno_from_win_error (GetLastError (), EPERM);
goto done;
}
status = geterrno_from_win_error (GetLastError (), EPERM);
goto done;
}
}
else
@ -672,6 +631,8 @@ done:
int
sched_setaffinity (pid_t pid, size_t sizeof_set, const cpu_set_t *set)
{
USHORT groupcount = __CPU_GROUPMAX;
USHORT grouparray[__CPU_GROUPMAX];
int group = whichgroup (sizeof_set, set);
HANDLE process = 0;
int status = 0;
@ -682,49 +643,30 @@ sched_setaffinity (pid_t pid, size_t sizeof_set, const cpu_set_t *set)
process = pid && pid != myself->pid ?
OpenProcess (PROCESS_SET_INFORMATION, FALSE,
p->dwProcessId) : GetCurrentProcess ();
if (wincap.has_processor_groups () && __get_group_count () > 1)
if (!GetProcessGroupAffinity (process, &groupcount, grouparray))
{
status = geterrno_from_win_error (GetLastError (), EPERM);
goto done;
}
if (group < 0)
{
USHORT groupcount = __CPU_GROUPMAX;
USHORT grouparray[__CPU_GROUPMAX];
if (!GetProcessGroupAffinity (process, &groupcount, grouparray))
{
status = geterrno_from_win_error (GetLastError (), EPERM);
goto done;
}
if (group < 0)
{
status = EINVAL;
goto done;
}
if (groupcount == 1 && grouparray[0] == group)
{
if (!SetProcessAffinityMask (process, getgroup (sizeof_set, set, group)))
status = geterrno_from_win_error (GetLastError (), EPERM);
goto done;
}
/* If we get here, the user is trying to add the process to another
group or move it from current group to another group. These ops
are not allowed by Windows. One has to move one or more of the
process' threads to the new group(s) one by one. Here, we bail.
*/
status = EINVAL;
goto done;
}
else
if (groupcount == 1 && grouparray[0] == group)
{
if (group != 0)
{
status = EINVAL;
goto done;
}
if (!SetProcessAffinityMask (process, getgroup (sizeof_set, set, 0)))
{
status = geterrno_from_win_error (GetLastError (), EPERM);
goto done;
}
if (!SetProcessAffinityMask (process, getgroup (sizeof_set, set, group)))
status = geterrno_from_win_error (GetLastError (), EPERM);
goto done;
}
/* If we get here, the user is trying to add the process to another
group or move it from current group to another group. These ops
are not allowed by Windows. One has to move one or more of the
process' threads to the new group(s) one by one. Here, we bail.
*/
status = EINVAL;
goto done;
}
else
status = ESRCH;

View File

@ -42,28 +42,6 @@ __nt_query_system (PSYSTEM_BASIC_INFORMATION psbi)
static long
get_nproc_values (int in)
{
if (!wincap.has_processor_groups ()) /* Pre Windows 7 */
{
SYSTEM_BASIC_INFORMATION sbi;
if (!__nt_query_system (&sbi))
return -1;
switch (in)
{
case _SC_NPROCESSORS_CONF:
return sbi.NumberProcessors;
case _SC_NPROCESSORS_ONLN:
{
int i = 0;
do
if (sbi.ActiveProcessors & 1)
i++;
while (sbi.ActiveProcessors >>= 1);
return i;
}
}
}
tmp_pathbuf tp;
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX lpi, plpi;
DWORD lpi_size = NT_MAX_PATH;

View File

@ -28,7 +28,6 @@ wincaps wincap_vista __attribute__((section (".cygwin_dll_common"), shared)) = {
has_console_logon_sid:false,
has_precise_system_time:false,
has_microsoft_accounts:false,
has_processor_groups:false,
has_broken_prefetchvm:false,
has_new_pebteb_region:false,
has_broken_whoami:true,
@ -61,7 +60,6 @@ wincaps wincap_7 __attribute__((section (".cygwin_dll_common"), shared)) = {
has_console_logon_sid:true,
has_precise_system_time:false,
has_microsoft_accounts:false,
has_processor_groups:true,
has_broken_prefetchvm:false,
has_new_pebteb_region:false,
has_broken_whoami:true,
@ -94,7 +92,6 @@ wincaps wincap_8 __attribute__((section (".cygwin_dll_common"), shared)) = {
has_console_logon_sid:true,
has_precise_system_time:true,
has_microsoft_accounts:true,
has_processor_groups:true,
has_broken_prefetchvm:false,
has_new_pebteb_region:false,
has_broken_whoami:false,
@ -127,7 +124,6 @@ wincaps wincap_8_1 __attribute__((section (".cygwin_dll_common"), shared)) = {
has_console_logon_sid:true,
has_precise_system_time:true,
has_microsoft_accounts:true,
has_processor_groups:true,
has_broken_prefetchvm:false,
has_new_pebteb_region:false,
has_broken_whoami:false,
@ -160,7 +156,6 @@ wincaps wincap_10_1507 __attribute__((section (".cygwin_dll_common"), shared))
has_console_logon_sid:true,
has_precise_system_time:true,
has_microsoft_accounts:true,
has_processor_groups:true,
has_broken_prefetchvm:true,
has_new_pebteb_region:false,
has_broken_whoami:false,
@ -193,7 +188,6 @@ wincaps wincap_10_1607 __attribute__((section (".cygwin_dll_common"), shared))
has_console_logon_sid:true,
has_precise_system_time:true,
has_microsoft_accounts:true,
has_processor_groups:true,
has_broken_prefetchvm:true,
has_new_pebteb_region:false,
has_broken_whoami:false,
@ -226,7 +220,6 @@ wincaps wincap_10_1703 __attribute__((section (".cygwin_dll_common"), shared)) =
has_console_logon_sid:true,
has_precise_system_time:true,
has_microsoft_accounts:true,
has_processor_groups:true,
has_broken_prefetchvm:false,
has_new_pebteb_region:true,
has_broken_whoami:false,
@ -259,7 +252,6 @@ wincaps wincap_10_1709 __attribute__((section (".cygwin_dll_common"), shared)) =
has_console_logon_sid:true,
has_precise_system_time:true,
has_microsoft_accounts:true,
has_processor_groups:true,
has_broken_prefetchvm:false,
has_new_pebteb_region:true,
has_broken_whoami:false,
@ -292,7 +284,6 @@ wincaps wincap_10_1803 __attribute__((section (".cygwin_dll_common"), shared)) =
has_console_logon_sid:true,
has_precise_system_time:true,
has_microsoft_accounts:true,
has_processor_groups:true,
has_broken_prefetchvm:false,
has_new_pebteb_region:true,
has_broken_whoami:false,
@ -325,7 +316,6 @@ wincaps wincap_10_1809 __attribute__((section (".cygwin_dll_common"), shared)) =
has_console_logon_sid:true,
has_precise_system_time:true,
has_microsoft_accounts:true,
has_processor_groups:true,
has_broken_prefetchvm:false,
has_new_pebteb_region:true,
has_broken_whoami:false,
@ -358,7 +348,6 @@ wincaps wincap_10_1903 __attribute__((section (".cygwin_dll_common"), shared)) =
has_console_logon_sid:true,
has_precise_system_time:true,
has_microsoft_accounts:true,
has_processor_groups:true,
has_broken_prefetchvm:false,
has_new_pebteb_region:true,
has_broken_whoami:false,

View File

@ -22,7 +22,6 @@ struct wincaps
unsigned has_console_logon_sid : 1;
unsigned has_precise_system_time : 1;
unsigned has_microsoft_accounts : 1;
unsigned has_processor_groups : 1;
unsigned has_broken_prefetchvm : 1;
unsigned has_new_pebteb_region : 1;
unsigned has_broken_whoami : 1;
@ -87,7 +86,6 @@ public:
bool IMPLEMENT (has_console_logon_sid)
bool IMPLEMENT (has_precise_system_time)
bool IMPLEMENT (has_microsoft_accounts)
bool IMPLEMENT (has_processor_groups)
bool IMPLEMENT (has_broken_prefetchvm)
bool IMPLEMENT (has_new_pebteb_region)
bool IMPLEMENT (has_broken_whoami)