51 Commits

Author SHA1 Message Date
Hui
699f196055
[libc++] remove yield from atomic::wait (#120012)
This is to address the issue where `yield` can cause the thread to be
assigned to the lowest priority.
I have done lots of experiments: see the comments here:
https://github.com/llvm/llvm-project/pull/84471#issuecomment-2522723549

And for this patch, the benchmark has been performed on a 16 core M4 MAX
CPU MacBook Pro.
dylib compiled with Release mode and the test compiled with
optimization=speed

```
Comparing ../../../build_atomic_yield2/ref_new2.json to ../../../build_atomic_yield2/no_yield_new2.json
Benchmark                                                                                                                  Time             CPU      Time Old      Time New       CPU Old       CPU New
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
BM_1_atomic_1_waiter_1_notifier<KeepNotifying, NumHighPrioTasks<0>>/262144                                              +0.0460         +0.0392      14949926      15637503      13633314      14167327
BM_1_atomic_1_waiter_1_notifier<KeepNotifying, NumHighPrioTasks<0>>/524288                                              +0.0299         +0.0290      24369327      25099004      24367214      25073900
BM_1_atomic_1_waiter_1_notifier<KeepNotifying, NumHighPrioTasks<0>>/1048576                                             +0.0648         +0.0640      48149060      51268517      48144857      51226733
BM_1_atomic_1_waiter_1_notifier<NotifyEveryNus<50>, NumHighPrioTasks<0>>/4096                                           +0.0000         -0.8765     204815500     204823427     204514333      25265071
BM_1_atomic_1_waiter_1_notifier<NotifyEveryNus<50>, NumHighPrioTasks<0>>/8192                                           +0.0000         -0.8747     409637520     409640821     408997500      51228071
BM_1_atomic_1_waiter_1_notifier<NotifyEveryNus<50>, NumHighPrioTasks<0>>/16384                                          +0.0001         -0.8737     819244417     819351256     817022000     103217000
BM_1_atomic_1_waiter_1_notifier<NotifyEveryNus<100>, NumHighPrioTasks<0>>/4096                                          +0.0000         -0.9029     409607694     409624937     271866333      26410600
BM_1_atomic_1_waiter_1_notifier<NotifyEveryNus<100>, NumHighPrioTasks<0>>/8192                                          +0.0001         -0.9017     819168417     819269339     542784000      53352429
BM_1_atomic_1_waiter_1_notifier<NotifyEveryNus<100>, NumHighPrioTasks<0>>/16384                                         +0.0001         -0.9012    1638361750    1638522929    1089486000     107684571
BM_1_atomic_1_waiter_1_notifier<KeepNotifying, NumHighPrioTasks<4>>/262144                                              +0.3178         +0.3068      12777744      16838266      12764732      16681233
BM_1_atomic_1_waiter_1_notifier<KeepNotifying, NumHighPrioTasks<4>>/524288                                              +0.2231         +0.2225      26889415      32887842      26864138      32840550
BM_1_atomic_1_waiter_1_notifier<KeepNotifying, NumHighPrioTasks<4>>/1048576                                             +0.1809         +0.1799      56103004      66251660      56048000      66129583
BM_1_atomic_1_waiter_1_notifier<NotifyEveryNus<50>, NumHighPrioTasks<4>>/4096                                           -0.0029         -0.8708     205509986     204906011     204277333      26399538
BM_1_atomic_1_waiter_1_notifier<NotifyEveryNus<50>, NumHighPrioTasks<4>>/8192                                           +0.0001         -0.8711     410286709     410314199     408608000      52667692
BM_1_atomic_1_waiter_1_notifier<NotifyEveryNus<50>, NumHighPrioTasks<4>>/16384                                          -0.0019         -0.8713     821042916     819476441     816274000     105077000
BM_1_atomic_1_waiter_1_notifier<NotifyEveryNus<100>, NumHighPrioTasks<4>>/4096                                          -0.0005         -0.9015     409825792     409638429     273145333      26896400
BM_1_atomic_1_waiter_1_notifier<NotifyEveryNus<100>, NumHighPrioTasks<4>>/8192                                          -0.0027         -0.9014     821528125     819285433     545661000      53775308
BM_1_atomic_1_waiter_1_notifier<NotifyEveryNus<100>, NumHighPrioTasks<4>>/16384                                         -0.0041         -0.9014    1645204459    1638538077    1091726000     107647000
BM_1_atomic_1_waiter_1_notifier<KeepNotifying, NumHighPrioTasks<7>>/16                                                  -0.4835         -0.4836          1609           831          1609           831
BM_1_atomic_1_waiter_1_notifier<KeepNotifying, NumHighPrioTasks<7>>/32                                                  -0.4398         -0.4399          3167          1774          3166          1773
BM_1_atomic_1_waiter_1_notifier<KeepNotifying, NumHighPrioTasks<7>>/64                                                  -0.4705         -0.4705          6323          3348          6323          3348
BM_1_atomic_1_waiter_1_notifier<NotifyEveryNus<50>, NumHighPrioTasks<7>>/8                                              +0.0005         -0.8683        400109        400314        399256         52575
BM_1_atomic_1_waiter_1_notifier<NotifyEveryNus<50>, NumHighPrioTasks<7>>/16                                             +0.0005         -0.8683        800055        800483        798797        105165
BM_1_atomic_1_waiter_1_notifier<NotifyEveryNus<50>, NumHighPrioTasks<7>>/32                                             +0.0003         -0.8680       1600058       1600585       1597266        210903
BM_1_atomic_1_waiter_1_notifier<NotifyEveryNus<100>, NumHighPrioTasks<7>>/8                                             +0.0004         -0.8976        800006        800365        531802         54441
BM_1_atomic_1_waiter_1_notifier<NotifyEveryNus<100>, NumHighPrioTasks<7>>/16                                            +0.0005         -0.8982       1599965       1600765       1064885        108429
BM_1_atomic_1_waiter_1_notifier<NotifyEveryNus<100>, NumHighPrioTasks<7>>/32                                            +0.0005         -0.8993       3199905       3201437       2129243        214343
BM_1_atomic_multi_waiter_1_notifier<KeepNotifying, NumWaitingThreads<3>, NumHighPrioTasks<0>>/16384                     -0.0226         -0.0261        972539        950519        971198        945828
BM_1_atomic_multi_waiter_1_notifier<KeepNotifying, NumWaitingThreads<3>, NumHighPrioTasks<0>>/32768                     -0.0198         -0.0221       1933294       1895054       1930720       1888094
BM_1_atomic_multi_waiter_1_notifier<KeepNotifying, NumWaitingThreads<3>, NumHighPrioTasks<0>>/65536                     -0.0031         -0.0039       3835138       3823094       3827785       3812836
BM_1_atomic_multi_waiter_1_notifier<KeepNotifying, NumWaitingThreads<7>, NumHighPrioTasks<0>>/4096                      +0.4380         +0.4294        571762        822185        570245        815115
BM_1_atomic_multi_waiter_1_notifier<KeepNotifying, NumWaitingThreads<7>, NumHighPrioTasks<0>>/8192                      +0.0735         +0.0680       1223881       1313880       1221350       1304439
BM_1_atomic_multi_waiter_1_notifier<KeepNotifying, NumWaitingThreads<7>, NumHighPrioTasks<0>>/16384                     +0.1222         +0.1205       2442071       2740519       2433105       2726274
BM_1_atomic_multi_waiter_1_notifier<KeepNotifying, NumWaitingThreads<15>, NumHighPrioTasks<0>>/1024                     +0.1527         +1.2188        196081        226031         62647        139001
BM_1_atomic_multi_waiter_1_notifier<KeepNotifying, NumWaitingThreads<15>, NumHighPrioTasks<0>>/2048                     +0.0757         +0.4838        387858        417228        129250        191780
BM_1_atomic_multi_waiter_1_notifier<KeepNotifying, NumWaitingThreads<15>, NumHighPrioTasks<0>>/4096                     -0.0355         -0.2443        812827        784003        378109        285722
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<50>, NumWaitingThreads<3>, NumHighPrioTasks<0>>/1024                 +0.0002         -0.0873      51202059      51211089      51135714      46670867
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<50>, NumWaitingThreads<3>, NumHighPrioTasks<0>>/2048                 +0.0001         -0.0864     102424970     102432359     102287571      93452000
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<50>, NumWaitingThreads<3>, NumHighPrioTasks<0>>/4096                 +0.0000         -0.0865     204828250     204834229     204528667     186845250
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<50>, NumWaitingThreads<7>, NumHighPrioTasks<0>>/256                  +0.0003         -0.1681      12801752      12805016      12786382      10636485
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<50>, NumWaitingThreads<7>, NumHighPrioTasks<0>>/512                  +0.0001         -0.1686      25601940      25604893      25565481      21254515
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<50>, NumWaitingThreads<7>, NumHighPrioTasks<0>>/1024                 +0.0000         -0.1569      51210789      51211539      51150143      43122500
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<50>, NumWaitingThreads<15>, NumHighPrioTasks<0>>/64                  +0.0064         -0.3503       3210430       3230869       2856780       1856063
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<50>, NumWaitingThreads<15>, NumHighPrioTasks<0>>/128                 +0.0034         -0.3534       6410529       6432308       5704792       3688942
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<50>, NumWaitingThreads<15>, NumHighPrioTasks<0>>/256                 +0.0011         -0.3600      12821419      12835646      11455934       7331250
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<100>, NumWaitingThreads<3>, NumHighPrioTasks<0>>/256                 +0.0003         +0.0034      25600089      25608062      24375034      24457172
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<100>, NumWaitingThreads<3>, NumHighPrioTasks<0>>/512                 +0.0002         -0.0000      51203798      51211795      48859857      48858500
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<100>, NumWaitingThreads<3>, NumHighPrioTasks<0>>/1024                +0.0003         +0.0008     102411321     102437524      97694429      97777286
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<100>, NumWaitingThreads<7>, NumHighPrioTasks<0>>/64                  +0.0002         -0.0464       6399846       6401009       6070487       5789091
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<100>, NumWaitingThreads<7>, NumHighPrioTasks<0>>/128                 +0.0002         -0.0457      12799914      12802544      12069966      11518836
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<100>, NumWaitingThreads<7>, NumHighPrioTasks<0>>/256                 +0.0001         -0.0513      25599724      25602105      24202862      22962032
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<100>, NumWaitingThreads<15>, NumHighPrioTasks<0>>/16                 -0.0060         +0.2575       1611779       1602148        956236       1202492
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<100>, NumWaitingThreads<15>, NumHighPrioTasks<0>>/32                 -0.0064         +0.2964       3221485       3200918       1883540       2441728
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<100>, NumWaitingThreads<15>, NumHighPrioTasks<0>>/64                 -0.0046         +0.3087       6432692       6403368       3701725       4844611
BM_1_atomic_multi_waiter_1_notifier<KeepNotifying, NumWaitingThreads<3>, NumHighPrioTasks<4>>/256                       -0.0536         -0.0592         27458         25988         27402         25780
BM_1_atomic_multi_waiter_1_notifier<KeepNotifying, NumWaitingThreads<3>, NumHighPrioTasks<4>>/512                       -0.0469         -0.0527         54745         52175         54628         51750
BM_1_atomic_multi_waiter_1_notifier<KeepNotifying, NumWaitingThreads<3>, NumHighPrioTasks<4>>/1024                      -0.0297         -0.0340        108312        105095        108047        104378
BM_1_atomic_multi_waiter_1_notifier<KeepNotifying, NumWaitingThreads<7>, NumHighPrioTasks<4>>/64                        -0.2445         -0.2722         15109         11414         14711         10708
BM_1_atomic_multi_waiter_1_notifier<KeepNotifying, NumWaitingThreads<7>, NumHighPrioTasks<4>>/128                       -0.3132         -0.3515         32494         22317         32063         20794
BM_1_atomic_multi_waiter_1_notifier<KeepNotifying, NumWaitingThreads<7>, NumHighPrioTasks<4>>/256                       -0.1397         -0.1834         52801         45424         52170         42602
BM_1_atomic_multi_waiter_1_notifier<KeepNotifying, NumWaitingThreads<15>, NumHighPrioTasks<4>>/16                       +0.1679         +1.0248         28973         33837         13243         26814
BM_1_atomic_multi_waiter_1_notifier<KeepNotifying, NumWaitingThreads<15>, NumHighPrioTasks<4>>/32                       -0.0481         +0.7901         39155         37273         16072         28771
BM_1_atomic_multi_waiter_1_notifier<KeepNotifying, NumWaitingThreads<15>, NumHighPrioTasks<4>>/64                       -0.2075         +0.7568         57547         45606         19582         34402
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<50>, NumWaitingThreads<3>, NumHighPrioTasks<4>>/256                  -0.0001         -0.0807      12802693      12800886      12775327      11744119
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<50>, NumWaitingThreads<3>, NumHighPrioTasks<4>>/512                  -0.0021         -0.0867      25655056      25601315      25590407      23371667
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<50>, NumWaitingThreads<3>, NumHighPrioTasks<4>>/1024                 -0.0007         -0.0832      51238801      51201975      51099071      46845733
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<50>, NumWaitingThreads<7>, NumHighPrioTasks<4>>/64                   +0.0016         -0.2411       3200714       3205846       3176841       2410756
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<50>, NumWaitingThreads<7>, NumHighPrioTasks<4>>/128                  +0.0008         -0.2373       6404239       6409102       6359649       4850544
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<50>, NumWaitingThreads<7>, NumHighPrioTasks<4>>/256                  +0.0000         -0.2286      12805839      12806032      12713018       9806653
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<50>, NumWaitingThreads<15>, NumHighPrioTasks<4>>/16                  +0.0272         +0.0563        811198        833264        482220        509345
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<50>, NumWaitingThreads<15>, NumHighPrioTasks<4>>/32                  +0.0097         +0.0454       1617205       1632962        957801       1001264
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<50>, NumWaitingThreads<15>, NumHighPrioTasks<4>>/64                  +0.0050         +0.0389       3217997       3234130       1927921       2002868
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<100>, NumWaitingThreads<3>, NumHighPrioTasks<4>>/256                 +0.0000         -0.0009      25599763      25601039      24520071      24497071
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<100>, NumWaitingThreads<3>, NumHighPrioTasks<4>>/512                 +0.0001         -0.0017      51200354      51203628      49086786      49005500
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<100>, NumWaitingThreads<3>, NumHighPrioTasks<4>>/1024                +0.0001         +0.0013     102400369     102409744      97931143      98060857
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<100>, NumWaitingThreads<7>, NumHighPrioTasks<4>>/64                  -0.0017         +0.0128       6410821       6400104       5529150       5600008
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<100>, NumWaitingThreads<7>, NumHighPrioTasks<4>>/128                 -0.0011         +0.0215      12817263      12803569      11025889      11263032
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<100>, NumWaitingThreads<7>, NumHighPrioTasks<4>>/256                 -0.0005         +0.0193      25612704      25600332      22089065      22515677
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<100>, NumWaitingThreads<15>, NumHighPrioTasks<4>>/16                 -0.0164         +0.7969       1627422       1600798        665736       1196236
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<100>, NumWaitingThreads<15>, NumHighPrioTasks<4>>/32                 -0.0095         +0.8362       3231500       3200840       1290017       2368789
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<100>, NumWaitingThreads<15>, NumHighPrioTasks<4>>/64                 -0.0050         +0.7319       6433401       6401180       2747936       4759115
BM_1_atomic_multi_waiter_1_notifier<KeepNotifying, NumWaitingThreads<3>, NumHighPrioTasks<7>>/16                        +0.0155         +0.0092          1177          1195          1171          1181
BM_1_atomic_multi_waiter_1_notifier<KeepNotifying, NumWaitingThreads<3>, NumHighPrioTasks<7>>/32                        -0.0135         -0.0145          2103          2074          2095          2064
BM_1_atomic_multi_waiter_1_notifier<KeepNotifying, NumWaitingThreads<3>, NumHighPrioTasks<7>>/64                        +0.0022         +0.0009          3832          3841          3820          3823
BM_1_atomic_multi_waiter_1_notifier<KeepNotifying, NumWaitingThreads<7>, NumHighPrioTasks<7>>/8                        +13.9131         +9.5298          2074         30931          2041         21495
BM_1_atomic_multi_waiter_1_notifier<KeepNotifying, NumWaitingThreads<7>, NumHighPrioTasks<7>>/16                        +5.9980         +3.9816          3168         22172          3124         15563
BM_1_atomic_multi_waiter_1_notifier<KeepNotifying, NumWaitingThreads<7>, NumHighPrioTasks<7>>/32                        +3.8681         +2.3515          5412         26348          5321         17833
BM_1_atomic_multi_waiter_1_notifier<KeepNotifying, NumWaitingThreads<15>, NumHighPrioTasks<7>>/4                        +0.1312         +0.4845         31938         36127         12666         18803
BM_1_atomic_multi_waiter_1_notifier<KeepNotifying, NumWaitingThreads<15>, NumHighPrioTasks<7>>/8                        -0.0475         +0.0775         39196         37336         18078         19479
BM_1_atomic_multi_waiter_1_notifier<KeepNotifying, NumWaitingThreads<15>, NumHighPrioTasks<7>>/16                       -0.3146         -0.3853         57548         39441         31743         19513
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<50>, NumWaitingThreads<3>, NumHighPrioTasks<7>>/8                    -0.0012         -0.0916        400610        400149        399248        362679
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<50>, NumWaitingThreads<3>, NumHighPrioTasks<7>>/16                   -0.0032         -0.0904        802940        800342        798964        726744
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<50>, NumWaitingThreads<3>, NumHighPrioTasks<7>>/32                   -0.0030         -0.0911       1604860       1600044       1598235       1452647
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<50>, NumWaitingThreads<7>, NumHighPrioTasks<7>>/4                    +0.0348         -0.3515        202073        209107        199452        129352
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<50>, NumWaitingThreads<7>, NumHighPrioTasks<7>>/8                    -0.0004         -0.3628        406727        406545        400942        255464
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<50>, NumWaitingThreads<7>, NumHighPrioTasks<7>>/16                   -0.0176         -0.3705        821725        807256        803722        505959
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<50>, NumWaitingThreads<15>, NumHighPrioTasks<7>>/2                   +0.0575         +0.0699        138530        146498         79463         85020
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<50>, NumWaitingThreads<15>, NumHighPrioTasks<7>>/4                   -0.2307         -0.4182        327417        251885        222502        129448
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<50>, NumWaitingThreads<15>, NumHighPrioTasks<7>>/8                   -0.4166         -0.5733        765495        446598        535265        228384
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<100>, NumWaitingThreads<3>, NumHighPrioTasks<7>>/8                   +0.0001         +0.0022        800108        800227        759501        761200
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<100>, NumWaitingThreads<3>, NumHighPrioTasks<7>>/16                  +0.0002         +0.0052       1599998       1600327       1515336       1523162
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<100>, NumWaitingThreads<3>, NumHighPrioTasks<7>>/32                  -0.0004         +0.0029       3201730       3200529       3037191       3045996
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<100>, NumWaitingThreads<7>, NumHighPrioTasks<7>>/4                   -0.0063         +0.3625        402752        400231        231304        315156
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<100>, NumWaitingThreads<7>, NumHighPrioTasks<7>>/8                   -0.0029         +0.5760        802313        799998        401474        632716
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<100>, NumWaitingThreads<7>, NumHighPrioTasks<7>>/16                  -0.0014         +0.4607       1602184       1600012        877859       1282310
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<100>, NumWaitingThreads<15>, NumHighPrioTasks<7>>/2                  -0.0492         +0.3586        212875        202398        100437        136457
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<100>, NumWaitingThreads<15>, NumHighPrioTasks<7>>/4                  -0.0927         +0.4432        444857        403606        181089        261350
BM_1_atomic_multi_waiter_1_notifier<NotifyEveryNus<100>, NumWaitingThreads<15>, NumHighPrioTasks<7>>/8                  -0.0704         +0.8210        861808        801099        318774        580489
BM_N_atomics_N_waiter_N_notifier<KeepNotifying, NumberOfAtomics<2>, NumHighPrioTasks<0>>/4096                           -0.0730         -0.0762        333804        309427        333180        307803
BM_N_atomics_N_waiter_N_notifier<KeepNotifying, NumberOfAtomics<2>, NumHighPrioTasks<0>>/8192                           -0.0775         -0.0795        701228        646853        700065        644381
BM_N_atomics_N_waiter_N_notifier<KeepNotifying, NumberOfAtomics<2>, NumHighPrioTasks<0>>/16384                          +0.0245         +0.0229       1328777       1361291       1326360       1356745
BM_N_atomics_N_waiter_N_notifier<KeepNotifying, NumberOfAtomics<3>, NumHighPrioTasks<0>>/1024                           -0.0541         -0.0562        201559        190662        201259        189940
BM_N_atomics_N_waiter_N_notifier<KeepNotifying, NumberOfAtomics<3>, NumHighPrioTasks<0>>/2048                           -0.1959         -0.1986        416092        334584        415412        332927
BM_N_atomics_N_waiter_N_notifier<KeepNotifying, NumberOfAtomics<3>, NumHighPrioTasks<0>>/4096                           -0.1699         -0.1710        811966        674040        810157        671584
BM_N_atomics_N_waiter_N_notifier<KeepNotifying, NumberOfAtomics<5>, NumHighPrioTasks<0>>/1024                           +0.1383         +0.1301        379893        432426        377756        426885
BM_N_atomics_N_waiter_N_notifier<KeepNotifying, NumberOfAtomics<5>, NumHighPrioTasks<0>>/2048                           +0.0396         +0.0339        822384        854937        818110        845866
BM_N_atomics_N_waiter_N_notifier<KeepNotifying, NumberOfAtomics<5>, NumHighPrioTasks<0>>/4096                           +0.2499         +0.2451       1350161       1687588       1345121       1674845
BM_N_atomics_N_waiter_N_notifier<KeepNotifying, NumberOfAtomics<7>, NumHighPrioTasks<0>>/256                            +0.0042         +0.0101        213598        214487        199282        201303
BM_N_atomics_N_waiter_N_notifier<KeepNotifying, NumberOfAtomics<7>, NumHighPrioTasks<0>>/512                            -0.1034         -0.1065        428033        383755        409546        365945
BM_N_atomics_N_waiter_N_notifier<KeepNotifying, NumberOfAtomics<7>, NumHighPrioTasks<0>>/1024                           -0.0972         -0.1064        833189        752165        810146        723952
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<50>, NumberOfAtomics<2>, NumHighPrioTasks<0>>/1024                      +0.0001         -0.1103      51201684      51204581      51124714      45485867
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<50>, NumberOfAtomics<2>, NumHighPrioTasks<0>>/2048                      -0.0000         -0.1202     102409167     102405120     102243857      89953750
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<50>, NumberOfAtomics<2>, NumHighPrioTasks<0>>/4096                      +0.0000         -0.1166     204807125     204813833     204453333     180618500
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<50>, NumberOfAtomics<3>, NumHighPrioTasks<0>>/256                       +0.0002         -0.1623      12803624      12806161      12778727      10704806
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<50>, NumberOfAtomics<3>, NumHighPrioTasks<0>>/512                       -0.0002         -0.1414      25607327      25603223      25551852      21939152
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<50>, NumberOfAtomics<3>, NumHighPrioTasks<0>>/1024                      -0.0002         -0.1653      51212196      51202776      51126643      42673625
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<50>, NumberOfAtomics<5>, NumHighPrioTasks<0>>/256                       -0.0002         -0.0709      12805016      12802157      12784636      11878785
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<50>, NumberOfAtomics<5>, NumHighPrioTasks<0>>/512                       -0.0002         -0.1182      25611565      25606346      25560815      22540033
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<50>, NumberOfAtomics<5>, NumHighPrioTasks<0>>/1024                      -0.0002         -0.0813      51220762      51208122      51121071      46963571
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<50>, NumberOfAtomics<7>, NumHighPrioTasks<0>>/64                        +0.0012         -0.2125       3219858       3223858       3194027       2515373
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<50>, NumberOfAtomics<7>, NumHighPrioTasks<0>>/128                       -0.0370         -0.2643       6668396       6421601       6563402       4828970
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<50>, NumberOfAtomics<7>, NumHighPrioTasks<0>>/256                       -0.0288         -0.2220      13220067      12839487      13073964      10172062
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<100>, NumberOfAtomics<2>, NumHighPrioTasks<0>>/256                      -0.0000         -0.0105      25602159      25600917      24178138      23923759
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<100>, NumberOfAtomics<2>, NumHighPrioTasks<0>>/512                      +0.0000         -0.0175      51201819      51203125      48569867      47718143
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<100>, NumberOfAtomics<2>, NumHighPrioTasks<0>>/1024                     +0.0001         -0.0118     102404155     102414482      96908714      95760857
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<100>, NumberOfAtomics<3>, NumHighPrioTasks<0>>/256                      +0.0000         -0.0574      25599943      25600621      25326679      23871733
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<100>, NumberOfAtomics<3>, NumHighPrioTasks<0>>/512                      +0.0001         -0.0813      51200525      51206978      50459500      46355867
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<100>, NumberOfAtomics<3>, NumHighPrioTasks<0>>/1024                     +0.0001         -0.0774     102400405     102409875     101483571      93631000
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<100>, NumberOfAtomics<5>, NumHighPrioTasks<0>>/128                      -0.0002         +0.0456      12802792      12800864      11731131      12265881
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<100>, NumberOfAtomics<5>, NumHighPrioTasks<0>>/256                      -0.0000         +0.0649      25601667      25601070      22686065      24157862
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<100>, NumberOfAtomics<5>, NumHighPrioTasks<0>>/512                      -0.0005         +0.0513      51224453      51200650      45549867      47885533
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<100>, NumberOfAtomics<7>, NumHighPrioTasks<0>>/64                       -0.0014         +0.2205       6408711       6400039       4698868       5734934
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<100>, NumberOfAtomics<7>, NumHighPrioTasks<0>>/128                      +0.0155         +0.2459      12810413      13009276       9163080      11416117
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<100>, NumberOfAtomics<7>, NumHighPrioTasks<0>>/256                      +0.0081         +0.2304      25603646      25811111      18779784      23106867
BM_N_atomics_N_waiter_N_notifier<KeepNotifying, NumberOfAtomics<2>, NumHighPrioTasks<4>>/128                            -0.1103         -0.1108         24307         21625         24256         21568
BM_N_atomics_N_waiter_N_notifier<KeepNotifying, NumberOfAtomics<2>, NumHighPrioTasks<4>>/256                            +0.0637         +0.0574         45588         48491         45498         48112
BM_N_atomics_N_waiter_N_notifier<KeepNotifying, NumberOfAtomics<2>, NumHighPrioTasks<4>>/512                            -0.0519         -0.0539         90764         86054         90527         85648
BM_N_atomics_N_waiter_N_notifier<KeepNotifying, NumberOfAtomics<3>, NumHighPrioTasks<4>>/128                            +0.1161         +0.1083         28810         32155         28722         31832
BM_N_atomics_N_waiter_N_notifier<KeepNotifying, NumberOfAtomics<3>, NumHighPrioTasks<4>>/256                            +0.1152         +0.1094         64670         72123         64461         71512
BM_N_atomics_N_waiter_N_notifier<KeepNotifying, NumberOfAtomics<3>, NumHighPrioTasks<4>>/512                            -0.0804         -0.0993        125916        115796        125476        113010
BM_N_atomics_N_waiter_N_notifier<KeepNotifying, NumberOfAtomics<5>, NumHighPrioTasks<4>>/64                             +0.2682         -0.2446         53787         68210         51896         39203
BM_N_atomics_N_waiter_N_notifier<KeepNotifying, NumberOfAtomics<5>, NumHighPrioTasks<4>>/128                            +0.5732         -0.4832        103915        163474        100825         52105
BM_N_atomics_N_waiter_N_notifier<KeepNotifying, NumberOfAtomics<5>, NumHighPrioTasks<4>>/256                            +0.1283         -0.4606        211518        238645        203852        109957
BM_N_atomics_N_waiter_N_notifier<KeepNotifying, NumberOfAtomics<7>, NumHighPrioTasks<4>>/16                             -0.1526         +0.1523         59673         50567         23275         26819
BM_N_atomics_N_waiter_N_notifier<KeepNotifying, NumberOfAtomics<7>, NumHighPrioTasks<4>>/32                             -0.0492         +0.7075         82796         78719         24187         41298
BM_N_atomics_N_waiter_N_notifier<KeepNotifying, NumberOfAtomics<7>, NumHighPrioTasks<4>>/64                             -0.0712         +0.0764        150268        139570         55304         59527
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<50>, NumberOfAtomics<2>, NumHighPrioTasks<4>>/128                       -0.0004         -0.0828       6402859       6400308       6380145       5851557
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<50>, NumberOfAtomics<2>, NumHighPrioTasks<4>>/256                       -0.0002         -0.0370      12802978      12801020      12769107      12296293
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<50>, NumberOfAtomics<2>, NumHighPrioTasks<4>>/512                       -0.0028         -0.0799      25674170      25601862      25612667      23566586
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<50>, NumberOfAtomics<3>, NumHighPrioTasks<4>>/128                       -0.0004         -0.0672       6402990       6400344       6382100       5953248
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<50>, NumberOfAtomics<3>, NumHighPrioTasks<4>>/256                       -0.0004         -0.0841      12806197      12801334      12765891      11691661
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<50>, NumberOfAtomics<3>, NumHighPrioTasks<4>>/512                       -0.0006         -0.0574      25615708      25601085      25533250      24067828
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<50>, NumberOfAtomics<5>, NumHighPrioTasks<4>>/32                        -0.0163         -0.2801       1645647       1618805       1614735       1162471
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<50>, NumberOfAtomics<5>, NumHighPrioTasks<4>>/64                        -0.0211         -0.2501       3285234       3216045       3217295       2412509
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<50>, NumberOfAtomics<5>, NumHighPrioTasks<4>>/128                       -0.0502         -0.2956       6755976       6416549       6653264       4686407
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<50>, NumberOfAtomics<7>, NumHighPrioTasks<4>>/8                         -0.0815         -0.2227        534476        490942        337482        262341
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<50>, NumberOfAtomics<7>, NumHighPrioTasks<4>>/16                        +0.0973         -0.0629       1071127       1175390        664897        623053
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<50>, NumberOfAtomics<7>, NumHighPrioTasks<4>>/32                        -0.2263         -0.3717       2297477       1777444       1488023        934861
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<100>, NumberOfAtomics<2>, NumHighPrioTasks<4>>/64                       -0.0000         +0.0183       6400348       6400261       6145171       6257342
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<100>, NumberOfAtomics<2>, NumHighPrioTasks<4>>/128                      +0.0000         +0.0194      12800545      12800759      12279474      12517804
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<100>, NumberOfAtomics<2>, NumHighPrioTasks<4>>/256                      +0.0001         +0.0111      25601568      25602976      24636179      24909821
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<100>, NumberOfAtomics<3>, NumHighPrioTasks<4>>/64                       -0.0000         +0.0545       6400600       6400444       5795288       6111077
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<100>, NumberOfAtomics<3>, NumHighPrioTasks<4>>/128                      +0.0001         +0.0474      12800507      12801355      11566729      12114860
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<100>, NumberOfAtomics<3>, NumHighPrioTasks<4>>/256                      +0.0000         +0.0423      25601503      25601760      23281967      24267276
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<100>, NumberOfAtomics<5>, NumHighPrioTasks<4>>/32                       +0.0005         +0.2842       3201968       3203421       2175379       2793615
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<100>, NumberOfAtomics<5>, NumHighPrioTasks<4>>/64                       -0.0003         +0.3807       6402555       6400496       4052465       5595309
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<100>, NumberOfAtomics<5>, NumHighPrioTasks<4>>/128                      -0.0003         +0.3827      12804155      12800925       8114370      11219400
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<100>, NumberOfAtomics<7>, NumHighPrioTasks<4>>/8                        +0.0262         +0.1272        821954        843475        503297        567320
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<100>, NumberOfAtomics<7>, NumHighPrioTasks<4>>/16                       +0.0298         +0.3134       1634476       1683172        901978       1184619
BM_N_atomics_N_waiter_N_notifier<NotifyEveryNus<100>, NumberOfAtomics<7>, NumHighPrioTasks<4>>/32                       +0.0147         +0.2925       3244262       3291994       1721000       2224350
OVERALL_GEOMEAN                                                                                                         +0.0185         -0.1876             0             0             0             0

```

---------

Co-authored-by: Hui Xie <huixie@Huis-MacBook-Pro.local>
Co-authored-by: Hui Xie <huixie@Mac.broadband>
2025-01-18 14:50:53 +00:00
Nikolas Klauser
f69585235e
[libc++] Put _LIBCPP_NODEBUG on all internal aliases (#118710)
This significantly reduces the amount of debug information generated
for codebases using libc++, without hurting the debugging experience.
2025-01-08 11:12:59 -05:00
Louis Dionne
0e34f3f496
[libc++] Extract a clean base support API for std::atomic (#118129)
This patch documents the underlying API for implementing atomics on a
platform.

This doesn't change the operations that std::atomic is based on, but it
reorganizes the C11 / GCC implementation split to make it clearer what's
the base support layer and what's not.
2024-12-09 09:14:17 -05:00
Louis Dionne
c8060423fe
[libc++] Drop dependency on __functional/operations.h from <atomic> (#117302)
This should reduce the preprocessed size of the atomic header and other
headers in the synchronization library.
2024-12-03 16:57:17 -05:00
Louis Dionne
d681e1030f
[libc++] Refactor atomic_wait using lambdas (#115746)
Now that we've dropped support for older C++ dialects in the
synchronization library, we can use lambdas to clarify some of the code
used to implement atomic_wait.
2024-11-27 14:49:57 -05:00
Louis Dionne
3a63407686
[libc++] Make __atomic_base into an implementation detail of std::atomic (#115764)
The __atomic_base base class is only useful to conditionalize the
operations we provide inside std::atomic. It shouldn't be used directly
from other places in the library which can use std::atomic directly
instead.

Since we've granularized our includes, using std::atomic directly should
not make much of a difference compile-time wise.

This patch starts using std::atomic directly from other classes like
std::barrier and std::latch. Changing this shouldn't be an ABI break
since both classes have the same size and layout.

The benefits of this patch are isolating other parts of the code base
from implementation details of std::atomic and simplifying the mental
model for std::atomic's layers of implementation by making it clear that
__atomic_base is only an implementation detail of std::atomic.
2024-11-20 00:35:14 +01:00
Nikolas Klauser
c6f3b7bcd0
[libc++] Refactor the configuration macros to being always defined (#112094)
This is a follow-up to #89178. This updates the `<__config_site>`
macros.
2024-11-06 10:39:19 +01:00
Nikolas Klauser
e99c4906e4
[libc++] Granularize <cstddef> includes (#108696) 2024-10-31 02:20:10 +01:00
Nikolas Klauser
ba87515fea
[libc++][RFC] Always define internal feature test macros (#89178)
Currently, the library-internal feature test macros are only defined if
the feature is not available, and always have the prefix
`_LIBCPP_HAS_NO_`. This patch changes that, so that they are always
defined and have the prefix `_LIBCPP_HAS_` instead. This changes the
canonical use of these macros to `#if _LIBCPP_HAS_FEATURE`, which means
that using an undefined macro (e.g. due to a missing include) is
diagnosed now. While this is rather unlikely currently, a similar change
in `<__configuration/availability.h>` caught a few bugs. This also
improves readability, since it removes the double-negation of `#ifndef
_LIBCPP_HAS_NO_FEATURE`.

The current patch only touches the macros defined in `<__config>`. If
people are happy with this approach, I'll make a follow-up PR to also
change the macros defined in `<__config_site>`.
2024-10-12 09:49:52 +02:00
Louis Dionne
09e3a36058
[libc++][modules] Fix missing and incorrect includes (#108850)
This patch adds a large number of missing includes in the libc++ headers
and the test suite. Those were found as part of the effort to move
towards a mostly monolithic top-level std module.
2024-09-16 15:06:20 -04:00
Louis Dionne
d6832a611a
[libc++][modules] Modularize <cstddef> (#107254)
Many headers include `<cstddef>` just for size_t, and pulling in
additional content (e.g. the traits used for std::byte) is unnecessary.
To solve this problem, this patch splits up `<cstddef>` into
subcomponents so that headers can include only the parts that they
actually require.

This has the added benefit of making the modules build a lot stricter
with respect to IWYU, and also providing a canonical location where we
define `std::size_t` and friends (which were previously defined in
multiple headers like `<cstddef>` and `<ctime>`).

After this patch, there's still many places in the codebase where we
include `<cstddef>` when `<__cstddef/size_t.h>` would be sufficient.
This patch focuses on removing `<cstddef>` includes from __type_traits
to make these headers non-circular with `<cstddef>`. Additional
refactorings can be tackled separately.
2024-09-05 08:28:33 -04:00
Nikolas Klauser
5c717d6b1d
[libc++] re-enable clang-tidy in the CI and fix any issues (#102658)
It looks like we've accidentally disabled clang-tidy in the CI. This
re-enables it and fixes the issues accumulated while it was disabled.
2024-08-10 10:08:41 +02:00
Damien L-G
59ca618e3b
[libc++] Increase atomic_ref's required alignment for small types (#99654)
This patch increases the alignment requirement for std::atomic_ref
such that we can guarantee lockfree operations more often. Specifically,
we require types that are 1, 2, 4, 8, or 16 bytes in size to be aligned
to at least their size to be used with std::atomic_ref.

This is the case for most types, however a notable exception is
`long long` on x86, which is 8 bytes in length but has an alignment
of 4.

As a result of this patch, one has to be more careful about the
alignment of objects used with std::atomic_ref. Failure to provide
a properly-aligned object to std::atomic_ref is a precondition 
violation and is technically UB. On the flipside, this allows us
to provide an atomic_ref that is actually lockfree more often, 
which is an important QOI property.

More information in the discussion at https://github.com/llvm/llvm-project/pull/99570#issuecomment-2237668661.

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2024-08-01 10:39:27 -04:00
Louis Dionne
bf1666fb0b
[libc++] Drop support for the C++20 Synchronization Library before C++20 (#82008)
When we initially implemented the C++20 synchronization library, we
reluctantly accepted for the implementation to be backported to C++03
upon request from the person who provided the patch. This was when we
were only starting to have experience with the issues this can create,
so we flinched. Nowadays, we have a much stricter stance about not
backporting features to previous standards.

We have recently started fixing several bugs (and near bugs) in our
implementation of the synchronization library. A recurring theme during
these reviews has been how difficult to understand the current code is,
and upon inspection it becomes clear that being able to use a few recent
C++ features (in particular lambdas) would help a great deal. The code
would still be pretty intricate, but it would be a lot easier to reason
about the flow of callbacks through things like
__thread_poll_with_backoff.

As a result, this patch drops support for the synchronization library
before C++20. This makes us more strictly conforming and opens the door
to major simplifications, in particular around atomic_wait which was
supported all the way to C++03.

This change will probably have some impact on downstream users, however
since the C++20 synchronization library was added only in LLVM 10 (~3
years ago) and it's quite a niche feature, the set of people trying to
use this part of the library before C++20 should be reasonably small.
2024-07-31 17:53:09 -04:00
Louis Dionne
cc1dfb37aa
[libc++] Fix bug in atomic_ref's calculation of lock_free-ness (#99570)
The builtin __atomic_always_lock_free takes into account the type of the
pointer provided as the second argument. Because we were passing void*,
rather than T*, the calculation failed. This meant that
atomic_ref<T>::is_always_lock_free was only true for char & bool.

This bug exists elsewhere in the atomic library (when using GCC, we fail
to pass a pointer at all, and we fail to correctly align the atomic like
_Atomic would).

This change also attempts to start sorting out testing difficulties with
this function that caused the bug to exist by using the 
__GCC_ATOMIC_(CHAR|SHORT|INT|LONG|LLONG|POINTER)_IS_LOCK_FREE predefined
macros to establish an expected value for `is_always_lock_free` and 
`is_lock_free` for the respective types, as well as types with matching 
sizes and compatible alignment values.

Using these compiler pre-defines we can actually validate that certain
types, like char and int, are actually always lock free like they are on
every platform in the wild.

Note that this patch was actually authored by Eric Fiselier but I picked 
up the patch and GitHub won't let me set Eric as the primary author.

Co-authored-by: Eric Fiselier <eric@efcs.ca>
2024-07-26 14:10:06 -04:00
Nikolas Klauser
731db06a87
[libc++] Get the GCC build mostly clean of warnings (#96604)
The GCC build has gotten to the point where it's often hard to find the
actual error in the build log. We should look into enabling these
warnings again in the future, but it looks like a lot of them are
bogous.
2024-06-25 17:31:41 +02:00
Nikolas Klauser
1f98ac095e
[libc++][NFC] Replace _NOEXCEPT and _LIBCPP_CONSTEXPR macros with the keywords in C++11 code (#96387) 2024-06-23 22:03:41 +02:00
Louis Dionne
e2c2ffbe7a
[libc++][NFC] Run clang-format on libcxx/include again (#95874)
As time went by, a few files have become mis-formatted w.r.t.
clang-format. This was made worse by the fact that formatting was not
being enforced in extensionless headers. This commit simply brings all
of libcxx/include in-line with clang-format again.

We might have to do this from time to time as we update our clang-format
version, but frankly this is really low effort now that we've formatted
everything once.
2024-06-18 09:13:45 -04:00
Nikolas Klauser
6b4b29f859
[libc++][NFC] Remove unnecessary parens in static_asserts (#95605)
These were required a long time ago due to `static_assert` not actually
being available in C++03. Now `static_assert` is simply mapped to
`_Static_assert` in C++03, making the additional parens unnecessary.
2024-06-18 10:45:30 +02:00
Nikolas Klauser
4748b494e1
[libc++] Mark a few functions in the dylib as noexcept (#94098)
This avoids generating landing pads in some of the `atomic` functions
that will never be used, since these functions never throw exceptions.
2024-06-11 22:18:51 -04:00
Louis Dionne
04f01a2b9c
[libc++] Make the __availability header a sub-header of __config (#93083)
In essence, this header has always been related to configuration of
the library but we didn't want to put it inside <__config> due to
complexity reasons. Now that we have sub-headers in <__config>, we
can move <__availability> to it and stop including it everywhere since
we already obtain the required macros via <__config>.
2024-05-28 18:29:11 -07:00
Damien L-G
42ba740aff
[libc++] Implement C++20 atomic_ref (#76647)
Implement the std::atomic_ref class template by reusing atomic_base_impl.
Based on the work from https://reviews.llvm.org/D72240
2024-05-21 15:54:08 -07:00
Louis Dionne
9ddedf07ed
[libc++] Deprecate the C++20 synchronization library before C++20 (#86410)
When we initially implemented the C++20 synchronization library, we
reluctantly accepted for the implementation to be backported to C++03
upon request from the person who provided the patch. This was when we
were only starting to have experience with the issues this can create,
so we flinched. Nowadays, we have a much stricter stance about not
backporting features to previous standards.

We have recently started fixing several bugs (and near bugs) in our
implementation of the synchronization library. A recurring theme during
these reviews has been how difficult to understand the current code is,
and upon inspection it becomes clear that being able to use a few recent
C++ features (in particular lambdas) would help a great deal. The code
would still be pretty intricate, but it would be a lot easier to reason
about the flow of callbacks through things like
__thread_poll_with_backoff.

As a result, this patch deprecates support for the synchronization
library before C++20. In the next release, we can remove that support
entirely.
2024-04-16 10:57:48 -04:00
Nikolas Klauser
580f60484e
[libc++][NFC] Merge is{,_nothrow,_trivially}{,_copy,_move,_default}{_assignable,_constructible} (#85308)
These headers have become very small by using compiler builtins, often
containing only two declarations. This merges these headers, since
there doesn't seem to be much of a benefit keeping them separate.

Specifically, `is_{,_nothrow,_trivially}{assignable,constructible}` are
kept and the `copy`, `move` and `default` versions of these type traits
are moved in to the respective headers.
2024-03-18 08:29:44 +01:00
Hui
1f613bce19
[libc++] refactor cxx_atomic_wait to make it reusable for atomic_ref (#81427)
The goal of this patch is to make `atomic`'s wait functions to be
reusable by `atomic_ref`.
https://github.com/llvm/llvm-project/pull/76647

First, this patch is built on top of
https://github.com/llvm/llvm-project/pull/80596 , to reduce the future
merge conflicts.

This patch made the following functions as "API"s to be used by
`atomic`, `atomic_flag`, `semaphore`, `latch`, `atomic_ref`

```
__atomic_wait
__atomic_wait_unless
__atomic_notify_one
__atomic_notify_all
```

These functions are made generic to support `atomic` type and
`atomic_ref`. There are two customisation points.

```
// How to load the value from the given type (with a memory order)
__atomic_load
```


```
// what is the contention address that the platform `wait` function is going to monitor
__atomic_contention_address
```


For `atomic_ref` (not implemented in this patch), the `load` and
`address` function will be different, because
- it does not use the "atomic abstraction layer" so the `load` operation
will be some gcc builtin
- the contention address will be the user's actual type that the
`atomic_ref` is pointing to
2024-03-02 14:50:52 +00:00
Hui
1a0c988ebd [libc++][NFC] rename variable in atomic_sync
As discussed in https://github.com/llvm/llvm-project/pull/81427/files#r1509266817
rename the variable as a separate commit
2024-03-01 19:52:14 +00:00
Louis Dionne
37dca605c9
[libc++] Clean up includes of <__assert> (#80091)
Originally, we used __libcpp_verbose_abort to handle assertion failures.
That function was declared from all public headers. Since we don't use
that mechanism anymore, we don't need to declare __libcpp_verbose_abort
from all public headers, and we can clean up a lot of unnecessary
includes.

This patch also moves the definition of the various assertion categories
to the <__assert> header, since we now rely on regular IWYU for these
assertion macros.

rdar://105510916
2024-02-29 10:12:22 -05:00
Nikolas Klauser
1530034166
[libc++] Remove unnecessary includes from <atomic> (#82880)
This reduces the include time of `<atomic>` from 135ms to 88ms.
2024-02-28 21:14:35 +01:00
Louis Dionne
3761ad01e1
[libc++] Remove _LIBCPP_ATOMIC_ONLY_USE_BUILTINS (#82000)
As discussed in #76647, _LIBCPP_ATOMIC_ONLY_USE_BUILTINS is a
questionable configuration option. It makes our implementation of
std::atomic even more complicated than it already is for a limited
benefit.

Indeed, the original goal of that setting was to decouple libc++ from
libraries like compiler-rt and libatomic in Freestanding mode. We didn't
have a clear understanding of goals and non-goals of Freestanding back
then, but nowadays we do have a better understanding that removing all
dependencies of libc++ in Freestanding is a non-goal. We should still be
able to depend on builtins like those defined in compiler-rt for
implementing our atomic operations in Freestanding. Freestanding means
that there is no underlying operating system, not that there is no
toolchain available.

This patch removes the configuration option. This should have a very
limited fallout since that configuration was only enabled with
-ffreestanding, and libc++ basically doesn't work out of the box on
Freestanding platforms today.

The benefits are a slightly simpler implementation of std::atomic,
getting rid of one of the ABI-incompatible representations of
std::atomic, and clearing the way for proper Freestanding support to
eventually land in the library.

Fixes #81286
2024-02-27 17:31:02 -05:00
Jan Kokemüller
95ebf2be0e
[libc++] Refactor the predicate taking variant of __cxx_atomic_wait (#80596)
This is a follow-up PR to
<https://github.com/llvm/llvm-project/pull/79265>. It aims to be a
gentle refactoring of the `__cxx_atomic_wait` function that takes a
predicate.

The key idea here is that this function's signature is changed to look
like this (`std::function` used just for clarity):

```c++
__cxx_atomic_wait_fn(Atp*, std::function<bool(Tp &)> poll, memory_order __order);
```

...where `Tp` is the corresponding `value_type` to the atomic variable
type `Atp`. The function's semantics are similar to `atomic`s `.wait()`,
but instead of having a hardcoded predicate (is the loaded value unequal
to `old`?) the predicate is specified explicitly.

The `poll` function may change its argument, and it is very important
that if it returns `false`, it leaves its current understanding of the
atomic's value in the argument. Internally, `__cxx_atomic_wait_fn`
dispatches to two waiting mechanisms, depending on the type of the
atomic variable:

1. If the atomic variable can be waited on directly (for example,
Linux's futex mechanism only supports waiting on 32 bit long variables),
the value of the atomic variable (which `poll` made its decision on) is
then given to the underlying system wait function (e.g. futex).
2. If the atomic variable can not be waited on directly, there is a
global pool of atomics that are used for this task. The ["eventcount"
pattern](<https://gist.github.com/mratsim/04a29bdd98d6295acda4d0677c4d0041>)
is employed to make this possible.

The eventcount pattern needs a "monitor" variable which is read before
the condition is checked another time. libcxx has the
`__libcpp_atomic_monitor` function for this. However, this function only
has to be called in case "2", i.e. when the eventcount is actually used.
In case "1", the futex is used directly, so the monitor must be the
value of the atomic variable that the `poll` function made its decision
on to continue blocking. Previously, `__libcpp_atomic_monitor` was
_also_ used in case "1". This was the source of the ABA style bug that
PR#79265 fixed.

However, the solution in PR#79265 has some disadvantages:

- It exposes internals such as `cxx_contention_t` or the fact that
`__libcpp_thread_poll_with_backoff` needs two functions to higher level
constructs such as `semaphore`.
- It doesn't prevent consumers calling `__cxx_atomic_wait` in an error
prone way, i.e. by providing to it a predicate that doesn't take an
argument. This makes ABA style issues more likely to appear.

Now, `__cxx_atomic_wait_fn` takes just _one_ function, which is then
transformed into the `poll` and `backoff` callables needed by
`__libcpp_thread_poll_with_backoff`.

Aside from the `__cxx_atomic_wait` changes, the only other change is the
weakening of the initial atomic load of `semaphore`'s `try_acquire` into
`memory_order_relaxed` and the CAS inside the loop is changed from
`strong` to `weak`. Both weakenings should be fine, since the CAS is
called in a loop, and the "acquire" semantics of `try_acquire` come from
the CAS, not from the initial load.
2024-02-19 14:28:51 +00:00
Hui
825658856d
[libc++] fix counting_semaphore lost wakeups (#79265)
Fixes #77659
Fixes #46357

Picked up from https://reviews.llvm.org/D114119
2024-02-05 13:59:48 +00:00
Louis Dionne
7162fd750e
[libc++] Split the monolithic __threading_support header (#79654)
The <__threading_support> header is a huge beast and it's really
difficult to navigate. I find myself struggling to find what I want
every time I have to open it, and I've been considering splitting it up
for years for that reason.

This patch aims not to contain any functional change. The various
implementations of the threading base are simply moved to separate
headers and then the individual headers are simplified in mechanical
ways. For example, we used to have redundant declarations of all the
functions at the top of `__threading_support`, and those are removed
since they are not needed anymore. The various #ifdefs are also
simplified and removed when they become unnecessary.

Finally, this patch adds documentation for the API we expect from any
threading implementation.
2024-01-30 08:35:15 -05:00
Mark de Wever
5b7bb56a05 [libc++] Clang-tidy enable modernize-use-nullptr.
Clang-tidy 18 no longer has false positives with the spaceship operator.
Note that I'm quite sure there are more occurrences in our headers that
are not caught.

This relands https://github.com/llvm/llvm-project/pull/76659 with fixes
tested in https://github.com/llvm/llvm-project/pull/78746.
2024-01-21 13:08:18 +01:00
Konstantin Varlamov
94da2b21ee
Revert "[libc++] Clang-tidy enable modernize-use-nullptr. (#76659)" (#78409)
This reverts commit 020ea3e8d1075ab4a388ecd0d6e7a9d4cd415392.

This seems to break `test/libcxx/clang_tidy.gen.py/regex.sh.cpp` (in
C++03 mode for some reason):

```
2024-01-17T07:32:22.1759374Z # RUN: at line 12
2024-01-17T07:32:22.1773919Z clang-tidy-18 /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/test/libcxx/clang_tidy.gen.py/regex.sh.cpp --warnings-as-errors=* -header-filter=.* --config-file=/home/runner/_work/llvm-project/llvm-project/libcxx/.clang-tidy -- -Wweak-vtables -nostdinc++ -I /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1 -I /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1 -I /home/runner/_work/llvm-project/llvm-project/libcxx/test/support -std=c++03 -Werror -Wall -Wctad-maybe-unsupported -Wextra -Wshadow -Wundef -Wunused-template -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-noexcept-type -Wno-atomic-alignment -Wno-reserved-module-identifier -Wdeprecated-copy -Wdeprecated-copy-dtor -Wno-user-defined-literals -Wno-tautological-compare -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -Wno-local-type-template-args -Wno-c++11-extensions -Wno-unknown-pragmas -Wno-pass-failed -Wno-mismatched-new-delete -Wno-redundant-move -Wno-self-move -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_ENABLE_EXPERIMENTAL -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_NONE -Werror=thread-safety -Wuser-defined-warnings  -fno-modules
2024-01-17T07:32:22.1803227Z # executed command: clang-tidy-18 /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/test/libcxx/clang_tidy.gen.py/regex.sh.cpp '--warnings-as-errors=*' '-header-filter=.*' --config-file=/home/runner/_work/llvm-project/llvm-project/libcxx/.clang-tidy -- -Wweak-vtables -nostdinc++ -I /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1 -I /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1 -I /home/runner/_work/llvm-project/llvm-project/libcxx/test/support -std=c++03 -Werror -Wall -Wctad-maybe-unsupported -Wextra -Wshadow -Wundef -Wunused-template -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-noexcept-type -Wno-atomic-alignment -Wno-reserved-module-identifier -Wdeprecated-copy -Wdeprecated-copy-dtor -Wno-user-defined-literals -Wno-tautological-compare -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -Wno-local-type-template-args -Wno-c++11-extensions -Wno-unknown-pragmas -Wno-pass-failed -Wno-mismatched-new-delete -Wno-redundant-move -Wno-self-move -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_ENABLE_EXPERIMENTAL -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_NONE -Werror=thread-safety -Wuser-defined-warnings -fno-modules
2024-01-17T07:32:22.1817757Z # .---command stdout------------
2024-01-17T07:32:22.1820160Z # | /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1/__iterator/iterator_traits.h:124:50: error: use nullptr [modernize-use-nullptr,-warnings-as-errors]
2024-01-17T07:32:22.1822498Z # |   124 |   static const bool value = decltype(__test<_Tp>(0, 0, 0, 0, 0))::value;
2024-01-17T07:32:22.1823337Z # |       |                                                  ^
2024-01-17T07:32:22.1824052Z # |       |                                                  nullptr
2024-01-17T07:32:22.1826651Z # | /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1/__iterator/iterator_traits.h:124:53: error: use nullptr [modernize-use-nullptr,-warnings-as-errors]
2024-01-17T07:32:22.1829325Z # |   124 |   static const bool value = decltype(__test<_Tp>(0, 0, 0, 0, 0))::value;
2024-01-17T07:32:22.1831137Z # |       |                                                     ^
2024-01-17T07:32:22.1831963Z # |       |                                                     nullptr
2024-01-17T07:32:22.1834149Z # | /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1/__iterator/iterator_traits.h:124:56: error: use nullptr [modernize-use-nullptr,-warnings-as-errors]
2024-01-17T07:32:22.1848711Z # |   124 |   static const bool value = decltype(__test<_Tp>(0, 0, 0, 0, 0))::value;
2024-01-17T07:32:22.1849506Z # |       |                                                        ^
2024-01-17T07:32:22.1849997Z # |       |                                                        nullptr
2024-01-17T07:32:22.1851528Z # | /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1/__iterator/iterator_traits.h:124:59: error: use nullptr [modernize-use-nullptr,-warnings-as-errors]
2024-01-17T07:32:22.1853391Z # |   124 |   static const bool value = decltype(__test<_Tp>(0, 0, 0, 0, 0))::value;
2024-01-17T07:32:22.1854277Z # |       |                                                           ^
2024-01-17T07:32:22.1854841Z # |       |                                                           nullptr
2024-01-17T07:32:22.1856314Z # | /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1/__iterator/iterator_traits.h:124:62: error: use nullptr [modernize-use-nullptr,-warnings-as-errors]
2024-01-17T07:32:22.1857768Z # |   124 |   static const bool value = decltype(__test<_Tp>(0, 0, 0, 0, 0))::value;
2024-01-17T07:32:22.1858493Z # |       |                                                              ^
2024-01-17T07:32:22.1858998Z # |       |                                                              nullptr
2024-01-17T07:32:22.1859503Z # `-----------------------------
2024-01-17T07:32:22.1859900Z # .---command stderr------------
2024-01-17T07:32:22.1860259Z # | 43 warnings generated.
2024-01-17T07:32:22.1860710Z # | Suppressed 33 warnings (33 in non-user code).
2024-01-17T07:32:22.1861809Z # | Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
2024-01-17T07:32:22.1862750Z # | 5 warnings treated as errors
2024-01-17T07:32:22.1863229Z # `-----------------------------
2024-01-17T07:32:22.1863622Z # error: command failed with exit status: 1
```

(see
https://github.com/llvm/llvm-project/actions/runs/7552394884/job/20561192096)
2024-01-17 01:30:52 -08:00
Mark de Wever
020ea3e8d1
[libc++] Clang-tidy enable modernize-use-nullptr. (#76659)
Clang-tidy 18 no longer has false positives with the spaceship operator.
Note that I'm quite sure there are more occurrences in our headers that
are not caught.
2024-01-17 08:22:43 +01:00
Louis Dionne
9783f28cbb
[libc++] Format the code base (#74334)
This patch runs clang-format on all of libcxx/include and libcxx/src, in
accordance with the RFC discussed at [1]. Follow-up patches will format
the benchmarks, the test suite and remaining parts of the code. I'm
splitting this one into its own patch so the diff is a bit easier to
review.

This patch was generated with:

   find libcxx/include libcxx/src -type f \
      | grep -v 'module.modulemap.in' \
      | grep -v 'CMakeLists.txt' \
      | grep -v 'README.txt' \
      | grep -v 'libcxx.imp' \
      | grep -v '__config_site.in' \
      | xargs clang-format -i

A Git merge driver is available in libcxx/utils/clang-format-merge-driver.sh
to help resolve merge and rebase issues across these formatting changes.

[1]: https://discourse.llvm.org/t/rfc-clang-formatting-all-of-libc-once-and-for-all
2023-12-18 14:01:33 -05:00
Louis Dionne
6f0c52e56f
[libc++] Refactor atomic_{unsigned,signed}_lock_free (#73041)
Their definition was a bit roundabout and it was actually wrong since
atomic_unsigned_lock_free would be a signed type whenever
__cxx_contention_t is lock free, which is most of the time.

Fixes #72968
2023-11-22 14:54:40 -05:00
Hui
de7fbfeef5
[libc++] Floating Point Atomic (#67799)
- implement P0020R6 Floating Point Atomic

Differential Revision: https://reviews.llvm.org/D153981
2023-11-22 11:48:49 +00:00
Louis Dionne
553ae2f866
[libc++] Remove outdated _LIBCPP_CLANG_VER check (#71759)
We always use Clang >= 16 now, so the check for Clang >= 14 is
tautological. As a drive-by, clang-format the header.
2023-11-09 09:09:39 -10:00
Louis Dionne
208a6d97f5
[libc++] Fix inconsistency between is_lock_free and is_always_lock_free (#68109)
std::atomic is implemented with the following (confusing!) hierarchy of
types:

     std::atomic<T> : std::__atomic_base<T> { ... };
     std::__atomic_base<T> {
          std::__cxx_atomic_impl<T> __impl;
     };
     std::__cxx_atomic_impl<T> {
          _Atomic(T) __val;
     };

Inside std::__atomic_base, we implement the is_lock_free() and
is_always_lock_free() functions. However, we used to implement them
inconsistently:
- is_always_lock_free() is based on whether __cxx_atomic_impl<T> is
always lock free (using the builtin), which means that we include any
potential padding added by _Atomic(T) into the determination.
- is_lock_free() was based on whether T is lock free (using the
builtin), which meant that we did not take into account any potential
padding added by _Atomic(T).

It is important to note that the padding added by _Atomic(T) can turn a
type that wouldn't be lock free into a lock free type, for example by
making its size become a power of two.

The inconsistency of how the two functions were implemented could lead
to cases where is_always_lock_free() would return true, but
is_lock_free() would then return false. This is the case for example of
the following type, which is always lock free on arm64 but was
incorrectly reported as !is_lock_free() before this patch:

     struct Foo { float x[3]; };

This patch switches the determination of is_lock_free() to be based on
__cxx_atomic_impl<T> instead to match how we determine
is_always_lock_free().

rdar://115324353
2023-10-18 19:58:24 -07:00
Nikolas Klauser
475bd19ee8 [libc++][NFC] Refactor return type enable_ifs to defaulted template arguments
This brings most of the enable_ifs in libc++ to the same style. It also has the nice side-effect of reducing the size of names of these symbols, since the depedent return type is shorter.

Reviewed By: #libc, ldionne

Spies: ldionne, libcxx-commits

Differential Revision: https://reviews.llvm.org/D157736
2023-08-15 12:19:21 -07:00
Nikolas Klauser
c04bcadf30 [libc++][NFC] Use _LIBCPP_STD_VER instead of __cpp_lib_atomic_is_always_lock_free
Reviewed By: #libc, ldionne, Mordante

Spies: Mordante, libcxx-commits

Differential Revision: https://reviews.llvm.org/D150421
2023-05-13 16:27:03 -07:00
Nikolas Klauser
83ce139721 [libc++] Add hide_from_abi check for classes
We already have a clang-tidy check for making sure that `_LIBCPP_HIDE_FROM_ABI` is on free functions. This patch extends this to class members. The places where we don't check for `_LIBCPP_HIDE_FROM_ABI` are classes for which we have an instantiation in the library.

Reviewed By: ldionne, Mordante, #libc

Spies: jplehr, mikhail.ramalho, sstefan1, libcxx-commits, krytarowski, miyuki, smeenai

Differential Revision: https://reviews.llvm.org/D142332
2023-04-16 15:23:23 +02:00
Nikolas Klauser
173476ea04 [libc++] Add __decay_t and use it instead of decay<>::type
This avoids instantiating lots of types.

Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D146984
2023-03-31 02:22:48 +02:00
Nikolas Klauser
4668dd8c4a [libc++] Run clang-tidy in all configurations that are run in the Docker container
Reviewed By: ldionne, Mordante, #libc

Spies: libcxx-commits, arichardson

Differential Revision: https://reviews.llvm.org/D143333
2023-02-28 19:14:58 +01:00
Mark de Wever
f41f392520 [libc++] Fixes operator& hijacking atomic types.
This uses std::addressof everywherein atomic. This is not strictly
needed for the integral and floating point specializations. They should
not be used by user defined types. But it's easier to fix everything.

Note these changes are made using a WIP clang-tidy plugin.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D144786
2023-02-27 19:23:13 +01:00
Nikolas Klauser
7ced7e84c0 [libc++][NFC] Replace typedef with using declarations in <__atomic/*>
Reviewed By: Mordante, #libc

Spies: arichardson, libcxx-commits

Differential Revision: https://reviews.llvm.org/D144259
2023-02-22 14:49:39 +01:00
Nikolas Klauser
b69963eb3f [libc++] Fix header includes in <__atomic/cxx_atomic_impl.h>
Reviewed By: #libc, philnik

Spies: Mordante, paulkirth, libcxx-commits

Differential Revision: https://reviews.llvm.org/D144307
2023-02-18 14:23:24 +01:00
Nikolas Klauser
ef3a3b0726 [libc++][NFC] Replace _VSTD and _LIBCPP_INLINE_VISIBILITY in <__atomic/*>
Reviewed By: Mordante, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D144258
2023-02-17 21:54:07 +01:00
Nikolas Klauser
21a543656c [libc++] Add missing include in <__atomic/cxx_atomic_impl.h> 2023-02-17 19:33:25 +01:00