gcc/libgcc/config
Matteo Italia 05ad8fb55a libgcc: fix Win32 CV abnormal spurious wakeups in timed wait [PR113850]
Fix a typo in __gthr_win32_abs_to_rel_time that caused it to return a
relative time in seconds instead of milliseconds. As a consequence,
__gthr_win32_cond_timedwait called SleepConditionVariableCS with a
1000x shorter timeout; this caused ~1000x more spurious wakeups in
CV timed waits such as std::condition_variable::wait_for or wait_until,
resulting generally in much higher CPU usage.

This can be demonstrated by this sample program:

```

int main() {
    std::condition_variable cv;
    std::mutex mx;
    bool pass = false;

    auto thread_fn = [&](bool timed) {
        int wakeups = 0;
        using sc = std::chrono::system_clock;
        auto before = sc::now();
        std::unique_lock<std::mutex> ml(mx);
        if (timed) {
            cv.wait_for(ml, std::chrono::seconds(2), [&]{
                ++wakeups;
                return pass;
            });
        } else {
            cv.wait(ml, [&]{
                ++wakeups;
                return pass;
            });
        }
        printf("pass: %d; wakeups: %d; elapsed: %d ms\n", pass, wakeups,
                int((sc::now() - before) / std::chrono::milliseconds(1)));
        pass = false;
    };

    {
        // timed wait, let expire
        std::thread t(thread_fn, true);
        t.join();
    }

    {
        // timed wait, wake up explicitly after 1 second
        std::thread t(thread_fn, true);
        std::this_thread::sleep_for(std::chrono::seconds(1));
        {
            std::unique_lock<std::mutex> ml(mx);
            pass = true;
        }
        cv.notify_all();
        t.join();
    }

    {
        // non-timed wait, wake up explicitly after 1 second
        std::thread t(thread_fn, false);
        std::this_thread::sleep_for(std::chrono::seconds(1));
        {
            std::unique_lock<std::mutex> ml(mx);
            pass = true;
        }
        cv.notify_all();
        t.join();
    }
    return 0;
}
```

On builds based on non-affected threading models (e.g. POSIX on Linux,
or winpthreads or MCF on Win32) the output is something like
```
pass: 0; wakeups: 2; elapsed: 2000 ms
pass: 1; wakeups: 2; elapsed: 991 ms
pass: 1; wakeups: 2; elapsed: 996 ms
```

while with the Win32 threading model we get
```
pass: 0; wakeups: 1418; elapsed: 2000 ms
pass: 1; wakeups: 479; elapsed: 988 ms
pass: 1; wakeups: 2; elapsed: 992 ms
```
(notice the huge number of wakeups in the timed wait cases only).

This commit fixes the conversion, adjusting the final division by
NSEC100_PER_SEC to use NSEC100_PER_MSEC instead (already defined in the
file and not used in any other place, so probably just a typo).

libgcc/ChangeLog:

	PR libgcc/113850
	* config/i386/gthr-win32-cond.c (__gthr_win32_abs_to_rel_time):
	fix absolute timespec to relative milliseconds count
	conversion (it incorrectly returned seconds instead of
	milliseconds); this avoids spurious wakeups in
	__gthr_win32_cond_timedwait
2024-02-16 23:47:16 +00:00
..
aarch64 libgcc: Avoid warnings on __gcc_nested_func_ptr_created [PR113402] 2024-02-01 21:10:10 +01:00
alpha Update copyright years. 2024-01-03 12:19:35 +01:00
arc Update copyright years. 2024-01-03 12:19:35 +01:00
arm Update copyright years. 2024-01-03 12:19:35 +01:00
avr Update copyright years. 2024-01-03 12:19:35 +01:00
bfin Update copyright years. 2024-01-03 12:19:35 +01:00
bpf
c6x Update copyright years. 2024-01-03 12:19:35 +01:00
cris Update copyright years. 2024-01-03 12:19:35 +01:00
csky Update copyright years. 2024-01-03 12:19:35 +01:00
epiphany Update copyright years. 2024-01-03 12:19:35 +01:00
fr30 Update copyright years. 2024-01-03 12:19:35 +01:00
frv Update copyright years. 2024-01-03 12:19:35 +01:00
ft32 Update copyright years. 2024-01-03 12:19:35 +01:00
gcn amdgcn: additional gfx1030/gfx1100 support 2024-01-26 11:38:47 +00:00
h8300 Update copyright years. 2024-01-03 12:19:35 +01:00
i386 libgcc: fix Win32 CV abnormal spurious wakeups in timed wait [PR113850] 2024-02-16 23:47:16 +00:00
ia64 Update copyright years. 2024-01-03 12:19:35 +01:00
iq2000 Update copyright years. 2024-01-03 12:19:35 +01:00
libbid Update copyright years. 2024-01-03 12:19:35 +01:00
lm32 Update copyright years. 2024-01-03 12:19:35 +01:00
loongarch Update copyright years. 2024-01-03 12:19:35 +01:00
m32c Update copyright years. 2024-01-03 12:19:35 +01:00
m32r Update copyright years. 2024-01-03 12:19:35 +01:00
m68k Update copyright years. 2024-01-03 12:19:35 +01:00
mcore Update copyright years. 2024-01-03 12:19:35 +01:00
microblaze Update copyright years. 2024-01-03 12:19:35 +01:00
mips Update copyright years. 2024-01-03 12:19:35 +01:00
mmix Update copyright years. 2024-01-03 12:19:35 +01:00
moxie Update copyright years. 2024-01-03 12:19:35 +01:00
msp430 Update copyright years. 2024-01-03 12:19:35 +01:00
nds32 Update copyright years. 2024-01-03 12:19:35 +01:00
nios2 Update copyright years. 2024-01-03 12:19:35 +01:00
nvptx Update copyright years. 2024-01-03 12:19:35 +01:00
or1k Update copyright years. 2024-01-03 12:19:35 +01:00
pa Update copyright years. 2024-01-03 12:19:35 +01:00
pdp11
pru Update copyright years. 2024-01-03 12:19:35 +01:00
riscv Update copyright years. 2024-01-03 12:19:35 +01:00
rl78 Update copyright years. 2024-01-03 12:19:35 +01:00
rs6000 Update copyright years. 2024-01-03 12:19:35 +01:00
rx Update copyright years. 2024-01-03 12:19:35 +01:00
s390 Update copyright years. 2024-01-03 12:19:35 +01:00
score Update copyright years. 2024-01-03 12:19:35 +01:00
sh Update copyright years. 2024-01-03 12:19:35 +01:00
sol2 Update copyright years. 2024-01-03 12:19:35 +01:00
sparc Update copyright years. 2024-01-03 12:19:35 +01:00
stormy16 Update copyright years. 2024-01-03 12:19:35 +01:00
v850 Update copyright years. 2024-01-03 12:19:35 +01:00
vax Update copyright years. 2024-01-03 12:19:35 +01:00
visium Update copyright years. 2024-01-03 12:19:35 +01:00
vms Update copyright years. 2024-01-03 12:19:35 +01:00
xtensa Update copyright years. 2024-01-03 12:19:35 +01:00
darwin-64.c Update copyright years. 2024-01-03 12:19:35 +01:00
darwin-crt-tm.c Update copyright years. 2024-01-03 12:19:35 +01:00
darwin-crt3.c Update copyright years. 2024-01-03 12:19:35 +01:00
darwin-unwind.ver libgcc, Darwin: Build a libgcc_s.1 for backwards compatibility. 2021-12-08 19:53:28 +00:00
darwin10-unwind-find-enc-func.c Darwin, libgcc : Adjust min version supported for the OS. 2023-05-19 09:06:01 +01:00
gthr-lynx.h Update copyright years. 2024-01-03 12:19:35 +01:00
gthr-rtems.h Update copyright years. 2024-01-03 12:19:35 +01:00
gthr-vxworks-cond.c Update copyright years. 2024-01-03 12:19:35 +01:00
gthr-vxworks-thread.c Update copyright years. 2024-01-03 12:19:35 +01:00
gthr-vxworks-tls.c Update copyright years. 2024-01-03 12:19:35 +01:00
gthr-vxworks.c Update copyright years. 2024-01-03 12:19:35 +01:00
gthr-vxworks.h Update copyright years. 2024-01-03 12:19:35 +01:00
hardfp.c Update copyright years. 2024-01-03 12:19:35 +01:00
libgcc-glibc.ver Update copyright years. 2024-01-03 12:19:35 +01:00
libgcc-libsystem.ver
no-sfp-machine.h
no-unwind.h
t-crtfm
t-crtstuff-pic
t-darwin libgcc: Make heap trampoline support dynamic [PR113403]. 2024-01-30 09:33:09 +00:00
t-darwin-ehs Darwin, libgcc: Fix build errors on powerpc-darwin8. 2022-03-04 16:44:54 +00:00
t-darwin-min-1 Darwin, libgcc : Adjust min version supported for the OS. 2023-05-19 09:06:01 +01:00
t-darwin-min-5 Darwin, libgcc : Adjust min version supported for the OS. 2023-05-19 09:06:01 +01:00
t-darwin-min-8 Darwin, libgcc : Adjust min version supported for the OS. 2023-05-19 09:06:01 +01:00
t-darwin-rpath Config,Darwin: Allow for configuring Darwin to use embedded runpath. 2023-10-22 19:30:02 +01:00
t-dfprules
t-eh-dw2-dip
t-fdpbit
t-fixedpoint-gnu-prefix
t-fpbit
t-freebsd-thread
t-gnu-prefix
t-gthr-noweak
t-gthr-vxworks
t-gthr-vxworksae
t-hardfp Update copyright years. 2024-01-03 12:19:35 +01:00
t-hardfp-sfdf Update copyright years. 2024-01-03 12:19:35 +01:00
t-libgcc-pic
t-libunwind
t-libunwind-elf Update copyright years. 2024-01-03 12:19:35 +01:00
t-linux
t-openbsd-thread
t-rtems
t-slibgcc Update copyright years. 2024-01-03 12:19:35 +01:00
t-slibgcc-darwin Config,Darwin: Allow for configuring Darwin to use embedded runpath. 2023-10-22 19:30:02 +01:00
t-slibgcc-elf-ver
t-slibgcc-fuchsia Update copyright years. 2024-01-03 12:19:35 +01:00
t-slibgcc-gld
t-slibgcc-gld-nover
t-slibgcc-hpux
t-slibgcc-libgcc Update copyright years. 2024-01-03 12:19:35 +01:00
t-slibgcc-nolc-override
t-slibgcc-sld
t-slibgcc-vms
t-softfp Update copyright years. 2024-01-03 12:19:35 +01:00
t-softfp-compat
t-softfp-excl
t-softfp-sfdf
t-softfp-sfdftf libgcc _BitInt support [PR102989] 2023-09-06 17:33:05 +02:00
t-softfp-tf libgcc _BitInt support [PR102989] 2023-09-06 17:33:05 +02:00
t-stack
t-tls
t-vxcrtstuff
t-vxcrtstuffS Tigthen libc_internal and crtstuff for VxWorks shared objects 2021-12-13 18:03:03 +00:00
t-vxworks Adjust LIBGCC2_INCLUDES for VxWorks and augment comment 2022-10-02 09:33:00 +00:00
t-vxworksae
unwind-dw2-fde-darwin.c Update copyright years. 2024-01-03 12:19:35 +01:00
vxcrtstuff.c Improve comments and INITFINI macro use in vxcrtsutff.c 2022-09-29 18:02:21 +00:00