Skip to content

Commit

Permalink
standalone-enc: trivial fixes to _pipe_socketpair_one.c
Browse files Browse the repository at this point in the history
- adjust printf to clarify that this is only one proto_pipe(), and that
  it's happening over a socketpair.

- remove _thread() from function names.
  (In the future, those will run in separate processes.)

- join the enc_thr before the output_thr, since enc_thr is more likely
  to be finished first.
  (Any time difference is likely to be negligible, but it's good
  practice to do it in the right order.)

- adjust pipe_output() to have the same general format as pipe_enc().
  Namely, we'll use a `goto err0;` rather than a direct `return (NULL)`,
  even if there's no change in the return value for success vs. failure.
  • Loading branch information
gperciva committed Jan 4, 2023
1 parent 3c0635e commit 19986b2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion perftests/standalone-enc/standalone.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int pce_perftest(const size_t *, size_t, size_t, size_t);

/**
* pipe_perftest(perfsizes, num_perf, nbytes_perftest, nbytes_warmup):
* Performance test for one proto_pipe().
* Performance test for one proto_pipe() over a socketpair.
*/
int pipe_perftest(const size_t *, size_t, size_t, size_t);

Expand Down
23 changes: 12 additions & 11 deletions perftests/standalone-enc/standalone_pipe_socketpair_one.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pipe_callback_status(void * cookie)

/* Encrypt bytes sent to a socket, and send them to another socket. */
static void *
pipe_enc_thread(void * cookie)
pipe_enc(void * cookie)
{
struct pipe * pipe = cookie;
void * cancel_cookie;
Expand All @@ -77,7 +77,7 @@ pipe_enc_thread(void * cookie)

/* Drain bytes from pipe->out[1] as quickly as possible. */
static void *
pipe_output_thread(void * cookie)
pipe_output(void * cookie)
{
struct pipe * pipe = cookie;
uint8_t mybuf[MAXOUTSIZE];
Expand All @@ -92,11 +92,12 @@ pipe_output_thread(void * cookie)
*/
if ((readlen = read(pipe->out[1], mybuf, MAXOUTSIZE)) == -1) {
warnp("read");
return (NULL);
goto err0;
}
} while (readlen != 0);

/* Success! */
err0:
/* Finished! */
return (NULL);
}

Expand All @@ -108,7 +109,7 @@ pipe_init(void * cookie, uint8_t * buf, size_t buflen)
size_t i;
int rc;

/* Sanity check for pipe_output_thread(). */
/* Sanity check for pipe_output(). */
assert(buflen <= MAXOUTSIZE);

/* Set up encryption key. */
Expand All @@ -135,12 +136,12 @@ pipe_init(void * cookie, uint8_t * buf, size_t buflen)

/* Create the pipe threads. */
if ((rc = pthread_create_blocking_np(&pipe->output_thr, NULL,
pipe_output_thread, pipe))) {
pipe_output, pipe))) {
warn0("pthread_create: %s", strerror(rc));
goto err0;
}
if ((rc = pthread_create_blocking_np(&pipe->enc_thr, NULL,
pipe_enc_thread, pipe))) {
pipe_enc, pipe))) {
warn0("pthread_create: %s", strerror(rc));
goto err0;
}
Expand Down Expand Up @@ -176,11 +177,11 @@ pipe_func(void * cookie, uint8_t * buf, size_t buflen, size_t nreps)
}

/* Wait for threads to finish. */
if ((rc = pthread_join(pipe->output_thr, NULL))) {
if ((rc = pthread_join(pipe->enc_thr, NULL))) {
warn0("pthread_join: %s", strerror(rc));
goto err0;
}
if ((rc = pthread_join(pipe->enc_thr, NULL))) {
if ((rc = pthread_join(pipe->output_thr, NULL))) {
warn0("pthread_join: %s", strerror(rc));
goto err0;
}
Expand Down Expand Up @@ -213,7 +214,7 @@ pipe_cleanup(void * cookie)

/**
* pipe_perftest(perfsizes, num_perf, nbytes_perftest, nbytes_warmup):
* Performance test for one proto_pipe().
* Performance test for one proto_pipe() over a socketpair.
*/
int
pipe_perftest(const size_t * perfsizes, size_t num_perf,
Expand All @@ -222,7 +223,7 @@ pipe_perftest(const size_t * perfsizes, size_t num_perf,
struct pipe pipe_actual;

/* Report what we're doing. */
printf("Testing proto_pipe()\n");
printf("Testing one proto_pipe() over a socketpair\n");

/* Time the function. */
if (perftest_buffers(nbytes_perftest, perfsizes, num_perf,
Expand Down

0 comments on commit 19986b2

Please sign in to comment.