Skip to content

Commit

Permalink
Merge pull request #5 from HDFGroup/feature/vfd_swmr
Browse files Browse the repository at this point in the history
Feature/vfd swmr
  • Loading branch information
vchoi-hdfgroup authored Apr 13, 2021
2 parents fef0001 + d9e9fe0 commit 62198a3
Show file tree
Hide file tree
Showing 7 changed files with 543 additions and 299 deletions.
17 changes: 10 additions & 7 deletions test/genall5.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* of the same name.
*/

#include <err.h>
#include "cache_common.h"
#include "vfd_swmr_common.h" /* for below_speed_limit() */
#include "genall5.h"
Expand Down Expand Up @@ -412,7 +413,7 @@ vrfy_ns_grp_c(hid_t fid, const char *group_name, unsigned nlinks)
gid = H5Gopen2(fid, group_name, H5P_DEFAULT);

if (gid <= 0) {
failure_mssg = "vrfy_ns_grp_c: H5Gopen2() failed";
failure_mssg = "vrfy_ns_grp_c: H5Gopen2 failed";
return false;
}

Expand Down Expand Up @@ -2753,12 +2754,14 @@ tend_zoo(hid_t fid, const char *base_path, struct timespec *lastmsgtime, zoo_con
}
out:
if (!ok) {
if (HDstrcmp(failure_mssg, last_failure_mssg) != 0)
*lastmsgtime = (struct timespec){.tv_sec = 0, .tv_nsec = 0};

if (below_speed_limit(lastmsgtime, &config.msgival)) {
last_failure_mssg = failure_mssg;
HDfprintf(stderr, "%s: %s", __func__, failure_mssg);
/* Currently not used: this step makes sure the operation doesn't take too long.
* Any test that sets config.msgival or lastmsgtime to 0 will skip this step */
if (strcmp(failure_mssg, last_failure_mssg) != 0 && ((config.msgival.tv_sec || config.msgival.tv_nsec))
&& (lastmsgtime->tv_sec || lastmsgtime->tv_nsec)) {
if (below_speed_limit(lastmsgtime, &config.msgival)) {
last_failure_mssg = failure_mssg;
warnx("%s: %s", __func__, failure_mssg);
}
}
}
return ok;
Expand Down
14 changes: 6 additions & 8 deletions test/testvfdswmr.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -575,24 +575,23 @@ done
# read and written by VFD SWMR.
#
if [ ${do_zoo:-no} = yes ]; then
[ -e ./fifo ] && rm -f ./fifo
mkfifo -m 0600 ./fifo
rm -f ./shared_tick_num
echo launch vfd_swmr_zoo_writer
STDIN_PATH="./fifo" catch_out_err_and_rc vfd_swmr_zoo_writer \
../vfd_swmr_zoo_writer -m 1000 -q &
catch_out_err_and_rc vfd_swmr_zoo_writer \
../vfd_swmr_zoo_writer -q &
pid_writer=$!

STDOUT_PATH="./fifo" catch_out_err_and_rc vfd_swmr_zoo_reader \
../vfd_swmr_zoo_reader -q -W &
# -l is the expected maximal number of ticks from the writer's finishing zoo creation or deletion
# to the reader's finishing validation of zoo creation or deletion
catch_out_err_and_rc vfd_swmr_zoo_reader \
../vfd_swmr_zoo_reader -l 4 -q &
pid_reader=$!

# Wait for the reader to finish before signalling the
# writer to quit: the writer holds the file open so that the
# reader will find the shadow file when it opens
# the .h5 file.
wait $pid_reader
kill -USR1 $(cat vfd_swmr_zoo_writer.pid)
wait $pid_writer

# Collect exit code of the reader
Expand All @@ -608,7 +607,6 @@ if [ ${do_zoo:-no} = yes ]; then
fi

# Clean up output files
rm -f ./fifo
rm -f vfd_swmr_zoo_writer.{out,rc}
rm -f vfd_swmr_zoo_reader.*.{out,rc}
fi
Expand Down
9 changes: 0 additions & 9 deletions test/vfd_swmr.c
Original file line number Diff line number Diff line change
Expand Up @@ -848,15 +848,6 @@ test_writer_create_open_flush(void)
return 1;
} /* test_writer_create_open_flush() */

/* Sleep for `tenths` tenths of a second */
static void
decisleep(uint32_t tenths)
{
uint64_t nsec = tenths * 100 * 1000 * 1000;

H5_nanosleep(nsec);
}

/*-------------------------------------------------------------------------
* Function: test_writer_md()
*
Expand Down
9 changes: 9 additions & 0 deletions test/vfd_swmr_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ below_speed_limit(struct timespec *last, const struct timespec *ival)
return result;
}

/* Sleep for `tenths` tenths of a second. */
void
decisleep(uint32_t tenths)
{
uint64_t nsec = tenths * 100 * 1000 * 1000;

H5_nanosleep(nsec);
}

/* Like vsnprintf(3), but abort the program with an error message on
* `stderr` if the buffer is too small or some other error occurs.
*/
Expand Down
3 changes: 2 additions & 1 deletion test/vfd_swmr_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ H5TEST_DLLVAR int verbosity;
extern "C" {
#endif

H5TEST_DLL hbool_t below_speed_limit(struct timespec *, const struct timespec *);
H5TEST_DLL bool below_speed_limit(struct timespec *, const struct timespec *);
H5TEST_DLL void decisleep(uint32_t tenths);

H5TEST_DLL estack_state_t estack_get_state(void);
H5TEST_DLL estack_state_t disable_estack(void);
Expand Down
59 changes: 30 additions & 29 deletions test/vfd_swmr_group_writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,32 @@ typedef struct {
unsigned int nsteps;
unsigned int update_interval;
bool use_vfd_swmr;
bool use_named_pipes;
} state_t;

#define ALL_HID_INITIALIZER \
(state_t) \
{ \
.file = H5I_INVALID_HID, .one_by_one_sid = H5I_INVALID_HID, .filename = "", \
.filetype = H5T_NATIVE_UINT32, .asteps = 10, .csteps = 10, .nsteps = 100, .update_interval = READER_WAIT_TICKS, \
.use_vfd_swmr = true \
.use_vfd_swmr = true, \
.use_named_pipes = true \
}

static void
usage(const char *progname)
{
fprintf(stderr, "usage: %s [-S] [-a steps] [-b] [-c]\n"
" [-n iterations] [-u numb_ticks]\n"
" [-n iterations] [-N] [-q] [-u numb_ticks]\n"
"\n"
"-S: do not use VFD SWMR\n"
"-a steps: `steps` between adding attributes\n"
"-b: write data in big-endian byte order\n"
"-c steps: `steps` between communication between the writer and reader\n"
"-n ngroups: the number of groups\n"
"-N: do not use named pipes, mainly for running the writer and reader seperately\n"
"-u numb_tcks: `numb_ticks` for the reader to wait before verification\n"
"-q: silence printouts, few messages\n"
"\n",
progname);
exit(EXIT_FAILURE);
Expand Down Expand Up @@ -83,7 +87,7 @@ state_init(state_t *s, int argc, char **argv)
if (tfile)
HDfree(tfile);

while ((ch = getopt(argc, argv, "SWa:bc:n:qu:")) != -1) {
while ((ch = getopt(argc, argv, "Sa:bc:n:Nqu:")) != -1) {
switch (ch) {
case 'S':
s->use_vfd_swmr = false;
Expand Down Expand Up @@ -120,6 +124,9 @@ state_init(state_t *s, int argc, char **argv)
case 'b':
s->filetype = H5T_STD_U32BE;
break;
case 'N':
s->use_named_pipes = false;
break;
case 'q':
verbosity = 0;
break;
Expand Down Expand Up @@ -334,15 +341,6 @@ verify_group(state_t *s, unsigned int which)
return false;
}

/* Sleep for `tenths` tenths of a second */
static void
decisleep(uint32_t tenths)
{
uint64_t nsec = tenths * 100 * 1000 * 1000;

H5_nanosleep(nsec);
}

int
main(int argc, char **argv)
{
Expand Down Expand Up @@ -413,7 +411,7 @@ main(int argc, char **argv)
* two-way communication so that the two sides can move forward together.
* One is for the writer to write to the reader.
* The other one is for the reader to signal the writer. */
if (writer) {
if (s.use_named_pipes && writer) {
/* Writer creates two named pipes(FIFO) */
if (HDmkfifo(fifo_writer_to_reader, 0600) < 0) {
H5_FAILED(); AT();
Expand All @@ -430,13 +428,13 @@ main(int argc, char **argv)
}

/* Both the writer and reader open the pipes */
if ((fd_writer_to_reader = HDopen(fifo_writer_to_reader, O_RDWR)) < 0) {
if (s.use_named_pipes && (fd_writer_to_reader = HDopen(fifo_writer_to_reader, O_RDWR)) < 0) {
H5_FAILED(); AT();
printf("HDopen failed\n");
goto error;
}

if ((fd_reader_to_writer = HDopen(fifo_reader_to_writer, O_RDWR)) < 0) {
if (s.use_named_pipes && (fd_reader_to_writer = HDopen(fifo_reader_to_writer, O_RDWR)) < 0) {
H5_FAILED(); AT();
printf("HDopen failed\n");
goto error;
Expand All @@ -451,14 +449,15 @@ main(int argc, char **argv)
printf("write_group failed\n");

/* At communication interval, notifies the reader about the failture and quit */
if (step % s.csteps == 0) {
if (s.use_named_pipes && (step % s.csteps == 0)) {
notify = -1;
HDwrite(fd_writer_to_reader, &notify, sizeof(int));
goto error;
}

goto error;
} else {
/* At communication interval, notifies the reader and waits for its response */
if (step % s.csteps == 0) {
if (s.use_named_pipes && (step % s.csteps == 0)) {
/* Bump up the value of notify to notice the reader to start to read */
notify++;
if (HDwrite(fd_writer_to_reader, &notify, sizeof(int)) < 0) {
Expand Down Expand Up @@ -506,7 +505,7 @@ main(int argc, char **argv)

/* At communication interval, waits for the writer to finish creation before starting verification
*/
if (step % s.csteps == 0) {
if (s.use_named_pipes && (step % s.csteps == 0)) {
/* The writer should have bumped up the value of notify.
* Do the same with verify and confirm it */
verify++;
Expand All @@ -532,21 +531,23 @@ main(int argc, char **argv)
}

/* Wait for a few ticks for the update to happen */
decisleep(config.tick_len * s.update_interval);
if (s.use_named_pipes)
decisleep(config.tick_len * s.update_interval);

/* Start to verify group */
if (!verify_group(&s, step)) {
H5_FAILED(); AT();
printf("verify_group failed\n");

/* At communication interval, tell the writer about the failure and exit */
if (step % s.csteps == 0) {
if (s.use_named_pipes && (step % s.csteps == 0)) {
notify = -1;
HDwrite(fd_reader_to_writer, &notify, sizeof(int));
goto error;
}

goto error;
} else {
if (step % s.csteps == 0) {
if (s.use_named_pipes && (step % s.csteps == 0)) {
/* Send back the same nofity value for acknowledgement to tell the writer
* move to the next step */
if (HDwrite(fd_reader_to_writer, &notify, sizeof(int)) < 0) {
Expand Down Expand Up @@ -578,20 +579,20 @@ main(int argc, char **argv)
}

/* Both the writer and reader close the named pipes */
if (HDclose(fd_writer_to_reader) < 0) {
if (s.use_named_pipes && HDclose(fd_writer_to_reader) < 0) {
H5_FAILED(); AT();
printf("HDclose failed\n");
goto error;
}

if (HDclose(fd_reader_to_writer) < 0) {
if (s.use_named_pipes && HDclose(fd_reader_to_writer) < 0) {
H5_FAILED(); AT();
printf("HDclose failed\n");
goto error;
}

/* Reader finishes last and deletes the named pipes */
if(!writer) {
if(s.use_named_pipes && !writer) {
if(HDremove(fifo_writer_to_reader) != 0) {
H5_FAILED(); AT();
printf("HDremove failed\n");
Expand All @@ -614,13 +615,13 @@ main(int argc, char **argv)
H5Fclose(s.file);
} H5E_END_TRY;

if (fd_writer_to_reader >= 0)
if (s.use_named_pipes && fd_writer_to_reader >= 0)
HDclose(fd_writer_to_reader);

if (fd_reader_to_writer >= 0)
if (s.use_named_pipes && fd_reader_to_writer >= 0)
HDclose(fd_reader_to_writer);

if(!writer) {
if(s.use_named_pipes && !writer) {
HDremove(fifo_writer_to_reader);
HDremove(fifo_reader_to_writer);
}
Expand Down
Loading

0 comments on commit 62198a3

Please sign in to comment.