Skip to content

Commit

Permalink
stress-msyncmany: add some LIKELY/UNLIKELY branch hints
Browse files Browse the repository at this point in the history
Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
  • Loading branch information
ColinIanKing committed Jan 28, 2025
1 parent 1a9500f commit 77b1523
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions stress-msyncmany.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ static int stress_msyncmany_child(stress_args_t *args, void *context)
for (n = 0; stress_continue_flag() && (n < (size_t)max); n++) {
uint64_t *ptr;

if (!stress_continue(args))
if (UNLIKELY(!stress_continue(args)))
break;
if ((g_opt_flags & OPT_FLAGS_OOM_AVOID) && stress_low_memory(page_size))
break;

ptr = (uint64_t *)mmap(NULL, page_size, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0);
if (ptr == MAP_FAILED)
if (UNLIKELY(ptr == MAP_FAILED))
break;
if (!mapped)
mapped = ptr;
Expand All @@ -88,7 +88,7 @@ static int stress_msyncmany_child(stress_args_t *args, void *context)
*mapped = pattern;

ret = msync((void *)mapped, args->page_size, MS_SYNC | MS_INVALIDATE);
if (ret < 0) {
if (UNLIKELY(ret < 0)) {
pr_fail("%s: msync failed, errno=%d (%s)\n",
args->name, errno, strerror(errno));
rc = EXIT_FAILURE;
Expand All @@ -97,14 +97,14 @@ static int stress_msyncmany_child(stress_args_t *args, void *context)
for (i = 0; i < n; i++) {
const uint64_t *ptr = (uint64_t *)mappings[i];

if (!ptr)
if (UNLIKELY(!ptr))
continue;
if (UNLIKELY(*ptr != pattern)) {
pr_fail("%s: failed: mapping %zd at %p contained %" PRIx64 " and not %" PRIx64 "\n",
args->name, i, (const void *)ptr, *ptr, pattern);
rc = EXIT_FAILURE;
failed++;
if (failed >= 5)
if (UNLIKELY(failed >= 5))
break;
}
}
Expand Down

0 comments on commit 77b1523

Please sign in to comment.