Skip to content

Fix ttsafe rwlock writer starvation and two big-endian test failures - #6744

Merged
hyoklee merged 11 commits into
HDFGroup:developfrom
hyoklee:fix-glibc-rwlock-writer-starvation
Oct 23, 2026
Merged

hyoklee merged 11 commits into
HDFGroup:developfrom
hyoklee:fix-glibc-rwlock-writer-starvation

Conversation

@hyoklee

@hyoklee hyoklee commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

Describe your changes

This PR fixes three test failures seen on a ppc64 big-endian host (RHEL 7.9, glibc 2.17, POWER8): a reader/writer starvation hang in ttsafe, and two big-endian bugs in tests. All changes are test-only; the library is unchanged.

1. Writer starvation in tts_rwlock (ttsafe hang)

On glibc, H5TS_rwlock_t is a pthread_rwlock_t with default attributes, which prefer readers. In tts_rwlock, the 12 verify_counting reader threads only called H5TS_thread_yield() between read locks, so their critical sections kept overlapping and the 4 count_up_and_down writers never got the lock. H5TEST-ttsafe hung until the CTest timeout on RHEL 7.9 / glibc 2.17 / POWER8 ppc64.

The readers now sleep briefly (H5_nanosleep(10000)) instead of yielding, so the lock is regularly free for the writers. (An earlier revision of this PR made the library lock writer-preferring on glibc; that was dropped after review because it changes lock semantics and can starve readers.)

2. Big-endian test fixes

  • test/API/H5_api_dataset_test.c: test_create_dataset_enum_types() passed &i (a size_t) to H5Tenum_insert() for an int-sized enum and a 32-bit enum. On big-endian systems the library read the zero high-order bytes, so every member had value 0 and h5_api_test_dataset failed with "value redefinition". The test now uses correctly sized int and uint32_t values.
  • HDF5Examples/C/HL/tfiles/h5ex_image2BE.ddl: the big-endian reference listed image8bit and palette as H5T_STD_U8LE instead of H5T_STD_U8BE. Comparing against the wrong reference made H5_H5DUMP-h5ex_image2 run until the 1200 s timeout.

Testing

  • With the earlier library-side fix, ttsafe passed 5 runs in a row on the affected ppc64 host (it hung before). The current test-side fix still needs to be re-verified on that host.
  • A CDash Experimental run of this PR on the ppc64 host (build PR6744/ppc64/rh-7.9/mpich-3.3/gcc-4.8/-sh/f/mp/nr/np=4 on my.cdash.org) showed the two big-endian failures above. With the test fixes applied, h5_api_test_dataset passes and H5_H5DUMP-h5ex_image2 passes in 0.36 s.

Issue ticket number (GitHub or JIRA)

Fixes #6743

Checklist before requesting a review

  • My code conforms to the guidelines in CONTRIBUTING.md
  • I made an entry in release_docs/CHANGELOG.md (bug fixes, new features): test-only changes
  • I added a test (bug fixes, new features): these are fixes to existing tests

🤖 Generated with Claude Code

glibc's default pthread rwlock prefers readers, so the spinning reader
threads in tts_rwlock could starve the writers forever and ttsafe hung
until the CTest timeout (seen with glibc 2.17 on POWER8 ppc64). On
glibc, create the lock with PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP,
matching the C11 and macOS implementations, which block new readers
while a writer is waiting.

Fixes HDFGroup#6743

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Checklist

This PR touches the following areas. Each needs a sign-off
from its listed owners before merging.

✅ All areas have been signed off.

- test/API/H5_api_dataset_test.c: test_create_dataset_enum_types()
  passed a size_t to H5Tenum_insert() for an int-sized (and a 32-bit)
  enum. On big-endian systems the library read the zero high-order
  bytes, so every member had value 0 and the test failed with "value
  redefinition". Use correctly sized int and uint32_t values.
- HDF5Examples/C/HL/tfiles/h5ex_image2BE.ddl: the big-endian reference
  listed the image8bit and palette datasets as H5T_STD_U8LE instead of
  H5T_STD_U8BE. The mismatch made H5_H5DUMP-h5ex_image2 compare a
  ~41,000-line output against the wrong reference until it timed out.

Both were seen on ppc64 big-endian (RHEL 7.9).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hyoklee
hyoklee requested a review from brtnfld as a code owner October 17, 2026 00:39
@github-actions
github-actions Bot removed the request for review from brtnfld October 17, 2026 00:39
@hyoklee hyoklee changed the title Fix writer starvation in the internal rwlock on glibc Fix rwlock writer starvation on glibc and two big-endian test failures Oct 17, 2026
@github-actions
github-actions Bot removed the request for review from glennsong09 October 17, 2026 00:39
# Conflicts:
#	release_docs/CHANGELOG.md
@hyoklee
hyoklee force-pushed the fix-glibc-rwlock-writer-starvation branch from 9e82cd2 to e8c79ce Compare October 22, 2026 02:38
@github-actions
github-actions Bot requested a review from lrknox October 22, 2026 21:20
@hyoklee hyoklee added this to the HDF5 2.3.0 milestone Oct 23, 2026
@hyoklee hyoklee added Component - C Library Core C library issues (usually in the src directory) Component - Testing Code in test or testpar directories, GitHub workflows labels Oct 23, 2026
Comment thread src/H5TSrwlock.c Outdated
*/
if (H5_UNLIKELY(pthread_rwlockattr_init(&attr)))
HGOTO_DONE(FAIL);
if (H5_UNLIKELY(pthread_rwlockattr_setkind_np(&attr, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP))) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be the default without some kind of opt-in mechanism as it changes the semantics and can also just lead to starving readers

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I've reverted the library change (and its CHANGELOG entry) in d27bce2, so H5TS_rwlock_init() is back to default attributes. The hang is now fixed in the test instead: the verify_counting readers only yielded between read locks, so with glibc's reader-preferring lock their critical sections kept overlapping and the writers never got in. They now sleep briefly (H5_nanosleep) so the lock is regularly free for the writers.

Per review, don't change the library's rwlock to writer-preferring on
glibc: that changes lock semantics for all users and can starve readers.
Revert the H5TSrwlock.c change and its CHANGELOG entry.

Instead, fix tts_rwlock: the verify_counting readers only called
H5TS_thread_yield() between read locks, so with glibc's reader-preferring
default lock their critical sections kept overlapping and the writers
never got in (hang on ppc64 / glibc 2.17). Sleep briefly instead so the
lock is regularly free for the writers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hyoklee hyoklee changed the title Fix rwlock writer starvation on glibc and two big-endian test failures Fix ttsafe rwlock writer starvation and two big-endian test failures Oct 23, 2026
@github-actions
github-actions Bot removed the request for review from lrknox October 23, 2026 19:37
Comment thread test/ttsafe_rwlock.c
* readers' critical sections keep overlapping and the writers
* can starve. Sleeping briefly leaves gaps where the lock is free.
*/
H5_nanosleep(10000);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine for now, but the test likely needs reconsideration since this should be able to be handled better with some synchronization primitive

@github-actions

Copy link
Copy Markdown
Contributor

🎉 All checklist items are signed off — @hyoklee, this PR is ready to merge.

@github-actions github-actions Bot added the checklist-complete All review checklist areas are signed off label Oct 23, 2026
@hyoklee
hyoklee merged commit 62c5dd2 into HDFGroup:develop Oct 23, 2026
131 checks passed
@github-project-automation github-project-automation Bot moved this from To be triaged to Done in HDF5 - TRIAGE & TRACK Oct 23, 2026
@hyoklee
hyoklee deleted the fix-glibc-rwlock-writer-starvation branch October 23, 2026 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

checklist-complete All review checklist areas are signed off Component - C Library Core C library issues (usually in the src directory) Component - Testing Code in test or testpar directories, GitHub workflows

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Test failures on ppc64 big-endian/glibc: ttsafe rwlock hang, enum API test, h5ex_image2 reference

2 participants