From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id D89813857C6F; Fri, 29 Oct 2021 19:03:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D89813857C6F Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: drop support for systems not supporting processor groups X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/master X-Git-Oldrev: 4bc8f1adb462946c9f23b06295eed792574242aa X-Git-Newrev: 687c4bad2877c4770431fa5e11b2582cf83bf316 Message-Id: <20211029190337.D89813857C6F@sourceware.org> Date: Fri, 29 Oct 2021 19:03:37 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Oct 2021 19:03:38 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=687c4bad2877c4770431fa5e11b2582cf83bf316 commit 687c4bad2877c4770431fa5e11b2582cf83bf316 Author: Corinna Vinschen Date: Fri Oct 29 18:11:27 2021 +0200 Cygwin: drop support for systems not supporting processor groups i. e., Vista/2008. Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/fhandler_proc.cc | 38 +++-------- winsup/cygwin/miscfuncs.cc | 8 +-- winsup/cygwin/sched.cc | 150 +++++++++++++---------------------------- winsup/cygwin/sysconf.cc | 22 ------ winsup/cygwin/wincap.cc | 11 --- winsup/cygwin/wincap.h | 2 - 6 files changed, 60 insertions(+), 171 deletions(-) diff --git a/winsup/cygwin/fhandler_proc.cc b/winsup/cygwin/fhandler_proc.cc index a3b5b16a9..c8074dd22 100644 --- a/winsup/cygwin/fhandler_proc.cc +++ b/winsup/cygwin/fhandler_proc.cc @@ -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); - - 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"); - } + 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. */ /* 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"); } diff --git a/winsup/cygwin/miscfuncs.cc b/winsup/cygwin/miscfuncs.cc index adf9a3d0f..fcb082216 100644 --- a/winsup/cygwin/miscfuncs.cc +++ b/winsup/cygwin/miscfuncs.cc @@ -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; diff --git a/winsup/cygwin/sched.cc b/winsup/cygwin/sched.cc index 84df7b9e6..d7bad8527 100644 --- a/winsup/cygwin/sched.cc +++ b/winsup/cygwin/sched.cc @@ -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) - { - 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 + if (!GetThreadGroupAffinity (thread, &ga)) { - 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; - } - - 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); + 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 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; diff --git a/winsup/cygwin/sysconf.cc b/winsup/cygwin/sysconf.cc index 70cdb0fbd..a78302805 100644 --- a/winsup/cygwin/sysconf.cc +++ b/winsup/cygwin/sysconf.cc @@ -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; diff --git a/winsup/cygwin/wincap.cc b/winsup/cygwin/wincap.cc index 6c4bcd08e..63b0a261d 100644 --- a/winsup/cygwin/wincap.cc +++ b/winsup/cygwin/wincap.cc @@ -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, diff --git a/winsup/cygwin/wincap.h b/winsup/cygwin/wincap.h index 764519616..0d86a80e4 100644 --- a/winsup/cygwin/wincap.h +++ b/winsup/cygwin/wincap.h @@ -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)