Skip to content

Commit

Permalink
getrusage03: Forcing context switches to update resource usage
Browse files Browse the repository at this point in the history
Our CI sporadically complains that this test grandchild's MAXRSS did not reach
the expected 300MB size.

    12 getrusage03.c:86: TFAIL: child.children = 258048, expected 307200

As the ru_maxrss value is generally updated at certain intervals or under
specific conditions, such as page faults or context switches. There may be
delay between the completion of memset() and the update of ru_maxrss.

To address this issue, we create a function to force context switches by
calling sched_yield() multiple times. This approach helps to ensure that
the system has the opportunity to update the ru_maxrss value more promptly.

Reproted-by: Scott Weaver <[email protected]>
Signed-off-by: Li Wang <[email protected]>
Reviewed-by: Cyril Hrubis <[email protected]>
  • Loading branch information
wangli5665 committed Sep 18, 2024
1 parent 62cebaf commit 3f63ff5
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions testcases/kernel/syscalls/getrusage/getrusage03.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,19 @@
#ifndef LTP_GETRUSAGE03_H
#define LTP_GETRUSAGE03_H

#include <sched.h>
#include "tst_test.h"

#define DELTA_MAX 20480

static void force_context_switches(int iterations)
{
tst_res(TINFO, "Forcing context switch %d times", iterations);

for (int i = 0; i < iterations; i++)
sched_yield();
}

static void consume_mb(int consume_nr)
{
void *ptr;
Expand All @@ -22,6 +31,8 @@ static void consume_mb(int consume_nr)
ptr = SAFE_MALLOC(size);
memset(ptr, 0, size);

force_context_switches(10);

SAFE_FILE_LINES_SCANF("/proc/self/status", "VmSwap: %lu", &vmswap_size);
if (vmswap_size > 0)
tst_brk(TBROK, "VmSwap is not zero");
Expand Down

0 comments on commit 3f63ff5

Please sign in to comment.