Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/non_rec_rwlock' into locking_pro…
Browse files Browse the repository at this point in the history
…tocol
  • Loading branch information
qkoziol committed Jun 6, 2024
2 parents fdc614a + 1aedb39 commit b72a4c3
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 11 deletions.
1 change: 1 addition & 0 deletions CMakeVOL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ if (HDF5_VOL_ALLOW_EXTERNAL MATCHES "GIT" OR HDF5_VOL_ALLOW_EXTERNAL MATCHES "LO
set (HDF5_LIBRARIES "${HDF5_LIBSH_TARGET};${LINK_LIBS};${LINK_COMP_LIBS};$<$<BOOL:${HDF5_ENABLE_PARALLEL}>:MPI::MPI_C>")
set (HDF5_INCLUDE_DIRS "${HDF5_SRC_INCLUDE_DIRS};${HDF5_SRC_BINARY_DIR};$<$<BOOL:${HDF5_ENABLE_PARALLEL}>:${MPI_C_INCLUDE_DIRS}>")
set (HDF5_IS_PARALLEL ${H5_HAVE_PARALLEL})
set (HDF5_VERSION ${HDF5_PACKAGE_VERSION})

set (HDF5_C_LIBRARIES "${HDF5_LIBRARIES}")

Expand Down
5 changes: 4 additions & 1 deletion release_docs/RELEASE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,10 @@ New Features

Tools:
------
-
- Allow h5repack to reserve space for a user block without a file

This is useful for users who want to reserve space
in the file for future use without requiring a file to copy.


High-Level APIs:
Expand Down
21 changes: 14 additions & 7 deletions src/H5TSpool.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ struct H5TS_pool_t {
H5TS_mutex_t mutex; /* Mutex to control access to pool struct */
H5TS_cond_t cond;

bool shutdown; /* Pool is shutting down */
unsigned num_threads; /* # of threads in pool */
H5TS_atomic_uint_t active_threads; /* # of threads in pool */
H5TS_thread_t *threads; /* Array of worker threads in pool */
bool shutdown; /* Pool is shutting down */
unsigned num_threads; /* # of threads in pool */
H5TS_atomic_uint_t active_threads; /* # of threads in pool */
unsigned sleeping_workers; /* # of workers currently sleeping */
H5TS_thread_t *threads; /* Array of worker threads in pool */

H5TS_pool_task_t *head, *tail; /* Task queue */
};
Expand Down Expand Up @@ -153,9 +154,12 @@ H5TS__pool_do(void *_pool)
H5TS_atomic_fetch_add_uint(&pool->active_threads, 1);

/* If queue is empty and pool is not shutting down, wait for a task */
while (NULL == pool->head && !pool->shutdown)
while (NULL == pool->head && !pool->shutdown) {
pool->sleeping_workers++;
if (H5_UNLIKELY(H5TS_cond_wait(&pool->cond, &pool->mutex) < 0))
HGOTO_DONE((H5TS_thread_ret_t)-1);
pool->sleeping_workers--;
}

/* If there's a task, invoke it, else we're shutting down */
if (NULL != pool->head) {
Expand Down Expand Up @@ -192,9 +196,12 @@ H5TS__pool_do(void *_pool)
have_mutex = true;

/* If queue is empty and pool is not shutting down, wait for a task */
while (NULL == pool->head && !pool->shutdown)
while (NULL == pool->head && !pool->shutdown) {
pool->sleeping_workers++;
if (H5_UNLIKELY(H5TS_cond_wait(&pool->cond, &pool->mutex) < 0))
HGOTO_DONE((H5TS_thread_ret_t)-1);
pool->sleeping_workers--;
}

/* If there's a task, invoke it, else we're shutting down */
if (NULL != pool->head) {
Expand Down Expand Up @@ -362,7 +369,7 @@ H5TS_pool_add_task(H5TS_pool_t *pool, H5TS_thread_start_func_t func, void *ctx)
task = NULL;

/* Wake up any sleeping worker */
if (H5_UNLIKELY(H5TS_cond_broadcast(&pool->cond) < 0))
if (pool->sleeping_workers > 0 && H5_UNLIKELY(H5TS_cond_signal(&pool->cond) < 0))
HGOTO_DONE(FAIL);

done:
Expand Down
8 changes: 6 additions & 2 deletions tools/src/h5repack/h5repack.c
Original file line number Diff line number Diff line change
Expand Up @@ -746,8 +746,12 @@ check_options(pack_opt_t *options)
}
}

if (options->ublock_filename == NULL && options->ublock_size != 0)
H5TOOLS_GOTO_ERROR((-1), "file name missing for user block");
if (options->ublock_filename == NULL && options->ublock_size != 0) {
if (options->verbose > 0) {
printf("Warning: user block file name missing. Reserving a size of %ld...\n",
options->ublock_size);
}
}

/*------------------------------------------------------------------------
* Verify alignment options; threshold is zero default but alignment not
Expand Down
2 changes: 1 addition & 1 deletion tools/src/h5repack/h5repack_copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ copy_objects(const char *fnamein, const char *fnameout, pack_opt_t *options)
*-------------------------------------------------------------------------
*/

if (options->ublock_size > 0) {
if (options->ublock_filename != NULL && options->ublock_size > 0) {
if (copy_user_block(options->ublock_filename, fnameout, options->ublock_size) < 0)
H5TOOLS_GOTO_ERROR((-1), "Could not copy user block. Exiting...");
}
Expand Down
48 changes: 48 additions & 0 deletions tools/test/h5repack/CMakeTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,51 @@
)
endmacro ()

macro (ADD_H5_VERIFY_USERBLOCK testname userblocksize testfile)
if (NOT HDF5_USING_ANALYSIS_TOOL)
add_test (
NAME H5REPACK_VERIFY_USERBLOCK-${testname}-clear-objects
COMMAND ${CMAKE_COMMAND} -E remove testfiles/out-${testname}.${testfile}
)
add_test (
NAME H5REPACK_VERIFY_USERBLOCK-${testname}
COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:h5repack> --enable-error-stack ${ARGN} ${PROJECT_BINARY_DIR}/testfiles/${testfile} ${PROJECT_BINARY_DIR}/testfiles/out-${testname}.${testfile}
)
set_tests_properties (H5REPACK_VERIFY_USERBLOCK-${testname} PROPERTIES
DEPENDS H5REPACK_VERIFY_USERBLOCK-${testname}-clear-objects
)
if ("H5REPACK_VERIFY_USERBLOCK-${testname}" MATCHES "${HDF5_DISABLE_TESTS_REGEX}")
set_tests_properties (H5REPACK_VERIFY_USERBLOCK-${testname} PROPERTIES DISABLED true)
endif ()
add_test (
NAME H5REPACK_VERIFY_USERBLOCK-${testname}_DMP
COMMAND "${CMAKE_COMMAND}"
-D "TEST_EMULATOR=${CMAKE_CROSSCOMPILING_EMULATOR}"
-D "TEST_PROGRAM=$<TARGET_FILE:h5dump>"
-D "TEST_ARGS:STRING=-H;-B;out-${testname}.${testfile}"
-D "TEST_FOLDER=${PROJECT_BINARY_DIR}/testfiles"
-D "TEST_OUTPUT=${testfile}-${testname}-v.out"
-D "TEST_EXPECT=${resultcode}"
-D "TEST_FILTER:STRING=USERBLOCK_SIZE ${userblocksize}"
-D "TEST_REFERENCE=USERBLOCK_SIZE ${userblocksize}"
-P "${HDF_RESOURCES_DIR}/grepTest.cmake"
)
set_tests_properties (H5REPACK_VERIFY_USERBLOCK-${testname}_DMP PROPERTIES
DEPENDS H5REPACK_VERIFY_USERBLOCK-${testname}
)
if ("H5REPACK_VERIFY_USERBLOCK-${testname}_DMP" MATCHES "${HDF5_DISABLE_TESTS_REGEX}")
set_tests_properties (H5REPACK_VERIFY_USERBLOCK-${testname}_DMP PROPERTIES DISABLED true)
endif ()
add_test (
NAME H5REPACK_VERIFY_USERBLOCK-${testname}-clean-objects
COMMAND ${CMAKE_COMMAND} -E remove testfiles/out-${testname}.${testfile}
)
set_tests_properties (H5REPACK_VERIFY_USERBLOCK-${testname}-clean-objects PROPERTIES
DEPENDS H5REPACK_VERIFY_USERBLOCK-${testname}_DMP
)
endif ()
endmacro ()

macro (ADD_H5_TEST_META testname testfile)
# Remove any output file left over from previous test run
add_test (
Expand Down Expand Up @@ -1719,6 +1764,9 @@
set (arg ${FILE1} -u ${PROJECT_BINARY_DIR}/testfiles/ublock.bin -b 2048)
ADD_H5_TEST (add_userblock "TEST" ${arg})

# add a userblock reserve to file
ADD_H5_VERIFY_USERBLOCK (reserve_userblock 2048 ${FILE1} -b 2048)

# add alignment
set (arg ${FILE1} -t 1 -a 1)
ADD_H5_TEST (add_alignment "TEST" ${arg})
Expand Down
4 changes: 4 additions & 0 deletions tools/test/h5repack/h5repack.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -1805,6 +1805,10 @@ fi
arg="h5repack_objs.h5 -u ublock.bin -b 2048"
TOOLTEST add_userblock $arg

# reserve a userblock to file
arg="h5repack_objs.h5 -b 2048"
TOOLTEST reserve_userblock $arg

# add alignment
arg="h5repack_objs.h5 -t 1 -a 1 "
TOOLTEST add_alignment $arg
Expand Down

0 comments on commit b72a4c3

Please sign in to comment.