118 Commits

Author SHA1 Message Date
Mike Kruskal
7dac70835c Expose gloop peer friendship for testing
PiperOrigin-RevId: 895336821
Change-Id: I178e7d654e45de4af6bba133b496115c6d37adc1
2026-04-06 08:17:56 -07:00
Mike Kruskal
1bcce1bda4 Internal functionality
PiperOrigin-RevId: 882667993
Change-Id: I47f0d92b58caa9cc137ae92e8b568277dd9b1d78
2026-03-12 10:37:49 -07:00
Derek Mauro
de9ab52205 No-op changes to relative timeout support code.
PiperOrigin-RevId: 847827629
Change-Id: I84dec0fafa6cdbb8ffee013f9d5ad9b3cb977ee4
2025-12-22 11:19:58 -08:00
Chris Kennelly
0f1abc9b73 Inline internal usages of pointerful SpinLockHolder/MutexLock.
PiperOrigin-RevId: 789441157
Change-Id: I2ed5d12f4b9725edbe3fd6cf629a0563a2f2d739
2025-07-31 12:59:26 -07:00
Chris Kennelly
3e0d9ff64a Inline SpinLock Lock->lock, Unlock->unlock internal to Abseil.
PiperOrigin-RevId: 788531193
Change-Id: Icca9ff096c2ec2fc0662f1f94ecfb232a8492974
2025-07-29 11:12:36 -07:00
Evan Brown
492fccd3ba Skip flaky expectations in waiter_test for MSVC.
PiperOrigin-RevId: 782040454
Change-Id: Ia51834a4c871b6bbf4748805656b7e68169239d6
2025-07-11 11:01:41 -07:00
Abseil Team
2b320cbfaa Fix includes and fuse constructors of SpinLock.
PiperOrigin-RevId: 774835829
Change-Id: I0fa7cab1b98c1b7222de0acd71b7846df693f1e2
2025-06-23 10:32:42 -07:00
Derek Mauro
67cab0c465 Cleanups related to benchmarks
* Fix many benchmarks to be cc_binary instead of cc_test
  * Add a few benchmarks for StrFormat
  * Add benchmarks for Substitute
  * Add benchmarks for Damerau-Levenshtein distance used in flags

PiperOrigin-RevId: 738448552
Change-Id: I521f4b2ef9116c9895b44c32d27e94507380bee8
2025-03-19 10:21:06 -07:00
Derek Mauro
0856410fc6 graphcycles_test: Avoid applying a non-zero offset to a null pointer
Applying a non-zero offset to a null pointer is undefined behavior.

Our UBSAN tests were missing `-fno-sanitize-recover`, which
means UBSAN logs a warning, but the program continues,
causing the test not to fail.

`-fno-sanitize-recover` will be added once all errors are fixed.

PiperOrigin-RevId: 733395060
Change-Id: Ibf71d0d2a27fac14f0c33dbdf83f4089645b8b37
2025-03-04 11:08:39 -08:00
Derek Mauro
feb3d276d4 Remove ABSL_INTERNAL_NEED_REDUNDANT_CONSTEXPR_DECL
which is longer needed with the C++17 floor

PiperOrigin-RevId: 729365281
Change-Id: Ife5e778ead193bb37150b9799099e92f53252cb4
2025-02-20 21:07:28 -08:00
Evan Brown
c8977ff7b5 Avoid flaky expectation in WaitDurationWoken test case in MSVC.
PiperOrigin-RevId: 715017153
Change-Id: Icbbf70f3694e3a098b2c150eb927bfb0d2504d52
2025-01-13 10:14:56 -08:00
Abseil Team
162dc789f1 It seems like commit abc9b916a9 did not work as intended.
PiperOrigin-RevId: 676486501
Change-Id: I874097a85486534150ce4c2f814d20be9d8b3b1f
2024-09-19 11:09:27 -07:00
Abseil Team
abc9b916a9 Attempt to fix flaky Abseil waiter/sleep tests
The existing implementation uses wall-clock time. However, wall clock can drastically differ from the internal system clock, because the system can be suspended and then resumed.

We want to account for at least some kinds of suspensions that might occur during automated testing, such as VM suspension or hypervisor preemption ("steal time"). These are tricky cases, because the physical (host) CPU is still running -- just the logical (guest) virtual CPU isn't. Therefore, we need to ensure that our time measurements exclude elapsed host-only time.

Unfortunately the correctness of a method depends on the nature & configuration of each VM and the guest. For example, it can depend whether RDTSC is virtualized, or on whether the host and guest support accounting for steal time. Windows, for example, appears to only support steal time measurements if the hypervisor is Hyper-V.

Since this is all for the sake of testing, we use a simpler trick that we hope will work around the problem on our systems: we subtract the so-called "interrupt time bias" from the system uptime in Windows. The interrupt time bias includes sleep/hibernation time, and seems to advance during for VM suspensions as well, so it may take care of the problem.

PiperOrigin-RevId: 675654840
Change-Id: I66150b18912175fa72609d3f137e3ea4fee8fc43
2024-09-17 11:59:38 -07:00
Abseil Team
70502ae69d Add comments about ThreadIdentity struct allocation behavior.
PiperOrigin-RevId: 662586240
Change-Id: Ibee60b935da5d8135ac99b6caf00b3c035ecfd89
2024-08-13 11:19:06 -07:00
Abseil Team
0d9c2fc763 Replace signed integer overflow, since that's undefined behavior, with unsigned integer overflow.
PiperOrigin-RevId: 648730502
Change-Id: I662c365c59be9e51f565fd215d284a96b7bd8743
2024-07-02 08:41:39 -07:00
Evan Brown
93763764d7 Disable flaky test cases in kernel_timeout_internal_test.
PiperOrigin-RevId: 645054874
Change-Id: Ic4a820b47edfa71bd3e1f149d54f00ac3c1d16a6
2024-06-20 09:12:48 -07:00
Evan Brown
9755364a0d Increase slop time on MSVC in PerThreadSemTest.Timeouts again due to continued flakiness.
PiperOrigin-RevId: 643372086
Change-Id: I8fb2acc0e5ad35113e865bf008a531f3442a9295
2024-06-14 09:40:06 -07:00
Derek Mauro
ac810bee5a Remove test references to absl::SharedBitGen, which was never part of
the open source release. This was only used in tests that never ran
as part in the open source release.

PiperOrigin-RevId: 636167506
Change-Id: Iafc33bd768307fe9ee77b181369635012abf2245
2024-05-22 08:00:33 -07:00
Evan Brown
a41e0168bf Fix flaky test failures on MSVC.
PiperOrigin-RevId: 616951235
Change-Id: I2d6e95a432285c3f79ef8484848e88e06973f51f
2024-03-18 14:39:40 -07:00
Evan Brown
53e6dae02b Fix flaky MSVC test failures by using longer slop time.
PiperOrigin-RevId: 613326708
Change-Id: I6e5ca195f208b8da0d21d70b5a035bfdc64f866d
2024-03-06 13:41:59 -08:00
Abseil Team
59daf188bc Increase GraphCycles::PointerMap size
PiperOrigin-RevId: 612509928
Change-Id: I90de2e6bd229bf5cf71a27e9c491bc2794e9265f
2024-03-04 10:59:58 -08:00
Derek Mauro
2f77684e8d Avoid using both Win32Waiter and PthreadWaiter on MinGW,
and use StdcppWaiter instead.

There are various flavors of MinGW, some of which support pthread,
and some of which support Win32. Instead of figuring out which
platform is being used, just use the generic implementation.

PiperOrigin-RevId: 580565507
Change-Id: Ia85fd7496f1e6ebdeadb95202f0039e844826118
2023-11-08 09:56:16 -08:00
Derek Mauro
7aef7808d6 kernel_timeout_test: Add Apple to the list of slow platforms because
it runs on non-dedicated Kokoro

PiperOrigin-RevId: 558874605
Change-Id: Iba35f558ab8c967f98a3176af056e76341fb67c3
2023-08-21 12:53:37 -07:00
Derek Mauro
06fded412d Add StdcppWaiter to the end of the list of waiter implementations
Since ABSL_INTERNAL_HAVE_STDCPP_WAITER is defined on all systems
it is effectively a fallback. I left the condition there in case
we have to disable it on some platform in the future.

PiperOrigin-RevId: 555629066
Change-Id: I76ca78c7f36d1d02dc4950a44c66903a2aaf2a52
2023-08-10 13:29:28 -07:00
Abseil Team
be85b347a8 Add Support for mmap on Qualcomm Hexagon DSP targets.
PiperOrigin-RevId: 548709037
Change-Id: I6eb03553299265660aa0abc180ae0f197a416ba4
2023-07-17 09:08:06 -07:00
Abseil Team
cffa80b913 absl: reformat Mutex-related files
Reformat Mutex-related files so that incremental formatting changes
don't distract during review of logical changes.
These files are subtle and any unnecessary diffs make reviews harder.

No changes besides running clang-format.

PiperOrigin-RevId: 541981737
Change-Id: I41cccb7a97158c78d17adaff6fe553c2c9c2b9ed
2023-06-20 10:54:11 -07:00
Andy Getzendanner
5274782148 Migrate most RAW_LOGs and RAW_CHECKs in tests to regular LOG and CHECK.
The non-RAW_ versions provide better output but weren't available when most of these tests were written.

There are just a couple spots where RAW_ is actually needed, e.g. signal handlers and malloc hooks.

Also fix a couple warnings in layout_test.cc newly surfaced because the optimizer understands CHECK_XX differently than INTERNAL_CHECK.

PiperOrigin-RevId: 534584435
Change-Id: I8d36fa809ffdaae5a3813064bd602cb8611c1613
2023-05-23 15:47:23 -07:00
Abseil Team
7e22b3022e Nop change.
PiperOrigin-RevId: 530238518
Change-Id: I2bfca582c0734f7e6943c5359730a2857809e2d2
2023-05-08 01:42:15 -07:00
Oleg Lyovin
c0d58db0c0 PR #1433: Fix incorrect timespec definition on 32-bit platforms with 64-bit time_t
Imported from GitHub PR https://github.com/abseil/abseil-cpp/pull/1433

Some 32-bit configurations may use 64-bit time_t, which leads to different layout of userspace timespec and the one expected by SYS_futex implementation in kernel. In particular the issue occurs when using musl libc which has switched to unconditional 64-bit time_t definition.

This patch introduces custom struct timespec with two longs when old SYS_futex is used to match the kernel timespec definition.
Merge 2eaca415da825b3f31a90f58a35bdef2b6d2a6c5 into f8bf909108

Merging this change closes #1433

COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/1433 from olegartys:futex_time64_bug 2eaca415da825b3f31a90f58a35bdef2b6d2a6c5
PiperOrigin-RevId: 528796119
Change-Id: Idaa952f64bd97c6dc9703a8b44deac43e29ff9ae
2023-05-02 08:52:27 -07:00
Copybara-Service
4ffaea74c1 Merge pull request #1416 from AtariDreams:fill
PiperOrigin-RevId: 526675031
Change-Id: Ib84423ccea2d0183166194a0916a97a7ed32915c
2023-04-24 09:59:58 -07:00
Derek Mauro
f8bf909108 Support pthread_cond_clockwait() and sem_clockwait() on Android
for __ANDROID_API__ >= 30

69010802d0%5E%21/libc/include/pthread.h

PiperOrigin-RevId: 525815479
Change-Id: I88cd1a06a4f7bb5380ff7c1e6a8f45e2b04b7df8
2023-04-20 12:16:23 -07:00
Evan Brown
9686b7be44 Fix flaky test failures.
PiperOrigin-RevId: 525808747
Change-Id: I01aeef6b8558673bf1fc38a948dcecf00300b641
2023-04-20 11:51:02 -07:00
Rose
a26fc02d1e Prefer copy_n and fill_n over copy and fill where appropriate.
This lets us avoid having to do the addition manually.
2023-04-19 13:35:57 -04:00
Derek Mauro
c5f310de3b Don't override clock_gettime in the KernelTimeout and Waiter
tests under sanitizers. The overrides break the sanitizers.

PiperOrigin-RevId: 524037272
Change-Id: I85b87d3870c488cb316505e94b394c6f98e9f60f
2023-04-13 10:25:56 -07:00
Derek Mauro
c23acb9b56 Synchronization: Consolidate the logic for whether steady clocks are supported
for relative timeouts

PiperOrigin-RevId: 523789416
Change-Id: Ide4cfdcae9ea7bffca3355c80ea9c8833a9536e6
2023-04-12 13:27:28 -07:00
Derek Mauro
1a72ea7bb8 Synchronization: Support true relative timeouts using the POSIX
proposed standard pthread_cond_clockwait() and sem_clockwait().
These are currently implemented in glibc >= 2.30.

These methods take a clock and use an absolute time with reference
to that clock, so KernelTimeout now can produce these values.

PiperOrigin-RevId: 522824226
Change-Id: Ife98713f6f95d800b1f8e52d5364a3dbebc4f8a6
2023-04-08 09:52:56 -07:00
Derek Mauro
a880427b38 Synchronization: Support true relative timeouts on Apple platforms
using the non-portable pthread_cond_timedwait_relative_np()

PiperOrigin-RevId: 522340555
Change-Id: I08682f74d8d94965330f12274c7a92632b1a29f1
2023-04-06 08:19:57 -07:00
Evan Brown
ed7c1ee121 Fix flakiness issues in timing tests.
PiperOrigin-RevId: 519939158
Change-Id: I9b049fa55167ed4064f3909887eec7bc52601677
2023-03-27 23:46:38 -07:00
Derek Mauro
276f88cb77 Add an implementation of Waiter that uses std::mutex/std::condition_variable
This implementation may at some point become the default on some
platforms.  Currently not all platforms have widespread support for
both real absolute timeouts or real relative timeouts (here "real"
means without converting to the other timeout type which is the only
one supported by the underlying APIs). In this case we can defer to
their standard library to implement correct support.

This is not currently the default on any platform

Note: The size of WaiterState had to increase to fit the new implementation
PiperOrigin-RevId: 518266646
Change-Id: I7f246646a960d6e1b155f9de0bf2f681c5d3d245
2023-03-21 07:31:48 -07:00
Derek Mauro
396e9764cd Synchronization: Refactor Waiter to allow us to write tests
Instead of being only able to test the platform Waiter implementation,
this allows us to be able to test all Waiter implementations that
build on a specific platform.

A unittest is added that tests all implementations that work for the
platform, and allows us to check that the expected one is being used
by printing the name of the selected implementation.

PiperOrigin-RevId: 518072415
Change-Id: Ie9e6fcd9d8283b4038e6f4e68a304d2adcc04b19
2023-03-20 14:11:09 -07:00
Tom Rybka
0697762c62 Increase the timeout of Windows for the kernel timeout tests.
Windows tests often run in Emulation, and even with KVM we can still timeout.

PiperOrigin-RevId: 517192968
Change-Id: I3b4e435f8ac8ad1e7eab6f043c051fa75efed64b
2023-03-16 12:20:51 -07:00
Derek Mauro
6d41348a3c Synchronization: Add support for true relative timeouts using
monotonic clocks on Linux when the implementation uses futexes

After this change, when synchronization methods that wait are passed
an absl::Duration to limit the wait time, these methods will wait for
that interval, even if the system clock is changed (subject to any
limitations with how CLOCK_MONOTONIC keeps track of time). In other
words, an observer measuring the time with a stop watch will now see
the correct interval, even if the system clock is changed. Previously,
the duration was added to the current time, and methods would wait
until that time was reached on the possibly changed realtime system
clock.

The behavior of the synchronization methods that take an absl::Time is
unchanged.  These methods always wait until the absolute point in time
is reached and respect changes to the system clock. In other words, an
observer will always see the timeout occur when a wall clock reaches
that time, even if the clock is manipulated externally.

Note: ABSL_PREDICT_FALSE was removed from the error case in Futex as
timeouts are handled by this case, and timeouts are part of normal
operation.
PiperOrigin-RevId: 516534869
Change-Id: Ib70b83e4be3f9e3f1727646975a21a1d30acb242
2023-03-14 08:42:14 -07:00
Derek Mauro
7f47b00fca Synchronization: Change KernelTimeout to always store absolute
timeouts, but when a relative timeout is provided, the timeout is an
absolute timeout against a steady clock (when possible). This allows
methods that return relative timeouts to automatically recompute the
remaining duration, for instance, on suprious wakeups.

PiperOrigin-RevId: 516304139
Change-Id: I7d739cb50dd749eba5dba7ac6c34d18dc53703ed
2023-03-13 13:24:46 -07:00
Abseil Team
ed8428015f Rollback Mutex relative timeout support because of internal incompatibility
PiperOrigin-RevId: 515427893
Change-Id: I89e8756fcf400459b0226d14785c6511ad3e380b
2023-03-09 13:39:41 -08:00
Derek Mauro
b75a3ff4af Synchronization: Add support for true relative timeouts using
monotonic clocks on Linux when the implementation uses futexes

After this change, when synchronization methods that wait are passed
an absl::Duration to limit the wait time, these methods will wait for
that interval, even if the system clock is changed (subject to any
limitations with how CLOCK_MONOTONIC keeps track of time). In other
words, an observer measuring the time with a stop watch will now see
the correct interval, even if the system clock is changed. Previously,
the duration was added to the current time, and methods would wait
until that time was reached on the possibly changed realtime system
clock.

The behavior of the synchronization methods that take an absl::Time is
unchanged.  These methods always wait until the absolute point in time
is reached and respect changes to the system clock. In other words, an
observer will always see the timeout occur when a wall clock reaches
that time, even if the clock is manipulated externally.

Note: ABSL_PREDICT_FALSE was removed from the error case in Futex as
timeouts are handled by this case, and timeouts are part of normal
operation.
PiperOrigin-RevId: 515043788
Change-Id: I151127b588065bd1316273f36d7c946545c2c892
2023-03-08 08:25:20 -08:00
Abseil Team
1d07cfede2 Rollback because of internal incompatibility.
PiperOrigin-RevId: 512979517
Change-Id: I7fe38ed246e42e6f8eb322e15c3b299215163168
2023-02-28 10:48:54 -08:00
Derek Mauro
ed37a45a37 Synchronization: Add support for true relative timeouts using
monotonic clocks on Linux when the implementation uses futexes

After this change, when synchronization methods that wait are passed
an absl::Duration to limit the wait time, these methods will wait for
that interval, even if the system clock is changed (subject to any
limitations with how CLOCK_MONOTONIC keeps track of time). In other
words, an observer measuring the time with a stop watch will now see
the correct interval, even if the system clock is changed. Previously,
the duration was added to the current time, and methods would wait
until that time was reached on the possibly changed realtime system
clock.

The behavior of the synchronization methods that take an absl::Time is
unchanged.  These methods always wait until the absolute point in time
is reached and respect changes to the system clock. In other words, an
observer will always see the timeout occur when a wall clock reaches
that time, even if the clock is manipulated externally.

Note: ABSL_PREDICT_FALSE was removed from the error case in Futex as
timeouts are handled by this case, and timeouts are part of normal
operation.
PiperOrigin-RevId: 510405347
Change-Id: I0b3ea390de97014cfa353079ae2e0c1c637aca69
2023-02-17 05:17:52 -08:00
Derek Mauro
0372af19f2 Add KernelTimeout methods that convert the timeout to the
std::chrono methods used by std::condition_variable.

A followup change will add an implemention of
synchronization_internal::Waiter that can use
std:mutex/std::condition_variable to implement the per-thread
semaphore that absl::Mutex waits on. This implementation may at some
point become the default on platforms such as Windows where there
doesn't seem to be an easy way of supporting real absolute timeouts. In
this case we can defer to their standard library to implement correct
support.
PiperOrigin-RevId: 510204786
Change-Id: Icf4d695013fd060abbd53dae23e71ea36f731565
2023-02-16 11:53:15 -08:00
Derek Mauro
b540445781 KernelTimeout optimization: Use absl::GetCurrentTimeNanos()
instead of absl::ToUnixNanos(absl::Now());

PiperOrigin-RevId: 509829866
Change-Id: Ib34362762304ad6eb7980a1227d717069b84f656
2023-02-15 07:41:08 -08:00
Derek Mauro
fa4855403c Rewrite KernelTimeout to support both absolute and relative timeouts
APIs that take KernelTimeout as a parameter can now query if an
absolute or relative timeout was requested. If the underlying API can
only use one type of timeout, the code will do a reasonable
conversion.

The goal is to eventually enable the possibility of using wait times
that are based on monotonic clocks that are safe against system clock
steps.

PiperOrigin-RevId: 508541507
Change-Id: Id08bf13515f3e1bfd78d88393cde98a6fd3ef72c
2023-02-09 19:45:48 -08:00