Commit f602f7b
committed
SCP: Fix scp_asynch_check cross-thread interference
Address a Clang/LLVM sanitizer warning that scp_asynch_check is written
by both the AIO and main threads, one thread potentially clobbering the
other's value.
The "scp_asynch_check = 0" at scp.c:239 is where the thread sanitizer
detects the issue. This check is supposed to cause the main thread to
process I/O updates on the next AIO_CHECK_EVENT code's execution. To
preserve that behavior, AIO_CHECK_EVENT now executes AIO_UPDATE_QUEUE
when either sim_asynch_check decrements below 0 or there is work to be
done on the AIO queue (sim_asynch_queue != QUEUE_HEAD.)
Code refactoring:
- Eliminate the asymmetry between the lock-based (mutex) and lock-free
implementations.
- Lock-free: AIO_ILOCK/AIO_IUNLOCK do not reacquire sim_asynch_lock
when compiler intrinsics are present (GCC, Clang, MS C and DEC C on
Itanium.)
- Lock-based: If DONT_USE_AIO_INTRINSICS is defined, the AIO
implementation becomes lock-based via mutexes and AIO_ILOCK/-
AIO_IUNLOCK recursively acquire/release sim_asynch_lock.
- AIO defaults to the lock-based implementation if compiler intrinsics
are not available.
- GCC, Clang: Prefer the __atomic intrinsics over the deprecated
__sync intrinsics. The __sync intrinics still exist for older GCC
compilers.
- sim_asynch_lock is a recursive mutex for both lock-based and
lock-free implementations. Eliminates implementation asymmetry.
- AIO_CHECK_EVENT invokes AIO_ILOCK and AIO_IUNLOCK so that the lock-based
code cannot alter sim_asynch_queue when checking for pending I/O work.
- sim_debug_io_lock: Debug output serialization lock. Previously,
sim_asynch_lock was semantically overloaded to serialize output from
_sim_debug_write_flush. This lock provides better semantic clarity.
- New builder script flag to disable AIO lock-free, force AIO lock-based code:
- cmake-builder.ps1 -noaiointrinsics ...
- cmake-builder.sh -no-aio-intrinics ...1 parent 29d3900 commit f602f7b
7 files changed
Lines changed: 18829 additions & 18720 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
226 | 226 | | |
227 | 227 | | |
228 | 228 | | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
229 | 232 | | |
230 | 233 | | |
231 | 234 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
517 | 517 | | |
518 | 518 | | |
519 | 519 | | |
520 | | - | |
| 520 | + | |
521 | 521 | | |
522 | | - | |
523 | | - | |
524 | | - | |
| 522 | + | |
| 523 | + | |
525 | 524 | | |
526 | | - | |
527 | | - | |
| 525 | + | |
| 526 | + | |
528 | 527 | | |
529 | 528 | | |
530 | 529 | | |
531 | | - | |
532 | | - | |
533 | 530 | | |
534 | 531 | | |
535 | 532 | | |
536 | 533 | | |
537 | 534 | | |
538 | | - | |
| 535 | + | |
539 | 536 | | |
540 | 537 | | |
541 | 538 | | |
| |||
547 | 544 | | |
548 | 545 | | |
549 | 546 | | |
550 | | - | |
551 | | - | |
| 547 | + | |
552 | 548 | | |
553 | 549 | | |
554 | 550 | | |
| |||
559 | 555 | | |
560 | 556 | | |
561 | 557 | | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
562 | 569 | | |
563 | 570 | | |
564 | 571 | | |
| |||
575 | 582 | | |
576 | 583 | | |
577 | 584 | | |
578 | | - | |
| 585 | + | |
579 | 586 | | |
580 | 587 | | |
581 | 588 | | |
582 | 589 | | |
583 | 590 | | |
584 | 591 | | |
585 | 592 | | |
586 | | - | |
587 | | - | |
588 | | - | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
589 | 596 | | |
590 | 597 | | |
591 | 598 | | |
| |||
594 | 601 | | |
595 | 602 | | |
596 | 603 | | |
597 | | - | |
598 | | - | |
599 | | - | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
600 | 607 | | |
601 | 608 | | |
602 | 609 | | |
| |||
630 | 637 | | |
631 | 638 | | |
632 | 639 | | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
633 | 643 | | |
634 | 644 | | |
635 | 645 | | |
| |||
0 commit comments