* [LTP] [PATCH] getrusage03: Forcing context switches to update resource usage
@ 2024-08-05 6:36 Li Wang
2024-08-05 6:58 ` Li Wang
2024-09-17 11:16 ` Cyril Hrubis
0 siblings, 2 replies; 4+ messages in thread
From: Li Wang @ 2024-08-05 6:36 UTC (permalink / raw)
To: ltp; +Cc: Scott Weaver
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 <scweaver@redhat.com>
Signed-off-by: Li Wang <liwang@redhat.com>
---
testcases/kernel/syscalls/getrusage/getrusage03.h | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/testcases/kernel/syscalls/getrusage/getrusage03.h b/testcases/kernel/syscalls/getrusage/getrusage03.h
index 8bee0b9e5..58a98b430 100644
--- a/testcases/kernel/syscalls/getrusage/getrusage03.h
+++ b/testcases/kernel/syscalls/getrusage/getrusage03.h
@@ -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;
@@ -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");
--
2.45.2
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [LTP] [PATCH] getrusage03: Forcing context switches to update resource usage
2024-08-05 6:36 [LTP] [PATCH] getrusage03: Forcing context switches to update resource usage Li Wang
@ 2024-08-05 6:58 ` Li Wang
2024-09-17 11:16 ` Cyril Hrubis
1 sibling, 0 replies; 4+ messages in thread
From: Li Wang @ 2024-08-05 6:58 UTC (permalink / raw)
To: ltp; +Cc: Scott Weaver
I proposed a patch in upstream ML:
https://lists.linux.it/pipermail/ltp/2024-August/039693.html
On Mon, Aug 5, 2024 at 2:36 PM Li Wang <liwang@redhat.com> wrote:
> 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 <scweaver@redhat.com>
> Signed-off-by: Li Wang <liwang@redhat.com>
> ---
> testcases/kernel/syscalls/getrusage/getrusage03.h | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/testcases/kernel/syscalls/getrusage/getrusage03.h
> b/testcases/kernel/syscalls/getrusage/getrusage03.h
> index 8bee0b9e5..58a98b430 100644
> --- a/testcases/kernel/syscalls/getrusage/getrusage03.h
> +++ b/testcases/kernel/syscalls/getrusage/getrusage03.h
> @@ -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;
> @@ -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");
> --
> 2.45.2
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>
>
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [LTP] [PATCH] getrusage03: Forcing context switches to update resource usage
2024-08-05 6:36 [LTP] [PATCH] getrusage03: Forcing context switches to update resource usage Li Wang
2024-08-05 6:58 ` Li Wang
@ 2024-09-17 11:16 ` Cyril Hrubis
2024-09-18 3:19 ` Li Wang
1 sibling, 1 reply; 4+ messages in thread
From: Cyril Hrubis @ 2024-09-17 11:16 UTC (permalink / raw)
To: Li Wang; +Cc: Scott Weaver, ltp
Hi!
> 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 <scweaver@redhat.com>
> Signed-off-by: Li Wang <liwang@redhat.com>
This looks forgotten but should probably go in before the release...
Anyways:
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [LTP] [PATCH] getrusage03: Forcing context switches to update resource usage
2024-09-17 11:16 ` Cyril Hrubis
@ 2024-09-18 3:19 ` Li Wang
0 siblings, 0 replies; 4+ messages in thread
From: Li Wang @ 2024-09-18 3:19 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: Scott Weaver, ltp
On Tue, Sep 17, 2024 at 7:18 PM Cyril Hrubis <chrubis@suse.cz> wrote:
> Hi!
> > 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 <scweaver@redhat.com>
> > Signed-off-by: Li Wang <liwang@redhat.com>
>
> This looks forgotten but should probably go in before the release...
>
> Anyways:
>
> Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
>
Thank you, patch pushed.
The worth to say that I created the separated function
force_context_switches
to accept an argument for setting context switch times, because I think
maybe
other tests also need that, so in the future if we catch something failure
like
ru_maxrss updating issue, we could move this function to LTP library.
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-09-18 3:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-05 6:36 [LTP] [PATCH] getrusage03: Forcing context switches to update resource usage Li Wang
2024-08-05 6:58 ` Li Wang
2024-09-17 11:16 ` Cyril Hrubis
2024-09-18 3:19 ` Li Wang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox