All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gabriele Monaco <gmonaco@redhat.com>
To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
	Steven Rostedt <rostedt@goodmis.org>,
	Gabriele Monaco <gmonaco@redhat.com>,
	Masami Hiramatsu <mhiramat@kernel.org>
Cc: Nam Cao <namcao@linutronix.de>, Wen Yang <wen.yang@linux.dev>,
	Juri Lelli <juri.lelli@redhat.com>
Subject: [PATCH 09/10] rv: Add KUnit test for throttle monitor
Date: Tue, 29 Sep 2026 14:49:07 +0200	[thread overview]
Message-ID: <20260929124908.177676-10-gmonaco@redhat.com> (raw)
In-Reply-To: <20260929124908.177676-1-gmonaco@redhat.com>

Add a test case for the throttle monitor to validate reactions occur
when a task:
 * gets throttled on time but switched back in without replenish
 * runs longer than its runtime

Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
---
 kernel/trace/rv/monitors/throttle/throttle.c  | 17 +++++++
 .../rv/monitors/throttle/throttle_kunit.c     | 44 +++++++++++++++++++
 .../rv/monitors/throttle/throttle_kunit.h     | 34 ++++++++++++++
 kernel/trace/rv/rv_monitors_test.c            |  2 +
 4 files changed, 97 insertions(+)
 create mode 100644 kernel/trace/rv/monitors/throttle/throttle_kunit.c
 create mode 100644 kernel/trace/rv/monitors/throttle/throttle_kunit.h

diff --git a/kernel/trace/rv/monitors/throttle/throttle.c b/kernel/trace/rv/monitors/throttle/throttle.c
index b22a2abe59fe..2b181c46b7b6 100644
--- a/kernel/trace/rv/monitors/throttle/throttle.c
+++ b/kernel/trace/rv/monitors/throttle/throttle.c
@@ -283,3 +283,20 @@ module_exit(unregister_throttle);
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Gabriele Monaco <gmonaco@redhat.com>");
 MODULE_DESCRIPTION("throttle: throttle dl entities when they use up their runtime.");
+
+#if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_TEST)
+#include <kunit/visibility.h>
+#include "throttle_kunit.h"
+
+const struct rv_throttle_ops rv_throttle_ops = {
+	.mon = RV_MON_OPS_INIT(),
+	.handle_dl_replenish = handle_dl_replenish,
+	.handle_dl_throttle = handle_dl_throttle,
+	.handle_sched_enqueue = handle_sched_enqueue,
+	.handle_sched_switch = handle_sched_switch,
+	.handle_sys_enter = handle_sys_enter,
+	.handle_newtask = handle_newtask,
+	.handle_dl_server_stop = handle_dl_server_stop,
+};
+EXPORT_SYMBOL_IF_KUNIT(rv_throttle_ops);
+#endif
diff --git a/kernel/trace/rv/monitors/throttle/throttle_kunit.c b/kernel/trace/rv/monitors/throttle/throttle_kunit.c
new file mode 100644
index 000000000000..8194095dbab8
--- /dev/null
+++ b/kernel/trace/rv/monitors/throttle/throttle_kunit.c
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/kernel.h>
+#include <linux/rv.h>
+#include <rv/kunit.h>
+#include <trace/events/sched.h>
+#include "throttle_kunit.h"
+
+#if IS_REACHABLE(CONFIG_RV_MON_THROTTLE)
+
+static void rv_test_throttle(struct kunit *test)
+{
+	struct task_struct *target = rv_kunit_alloc_mock_task(test);
+	struct task_struct *other = rv_kunit_alloc_mock_task(test);
+	struct rv_kunit_ctx *ctx = test->priv;
+
+	prepare_test(test, &rv_throttle_ops.mon);
+
+	target->pid = 99;
+	target->policy = SCHED_DEADLINE;
+	target->dl.runtime = 10000;
+	target->dl.deadline = 20000;
+
+	rv_throttle_ops.handle_newtask(NULL, target, 0);
+
+	/* Task gets throttled on time but switched back in without replenish */
+	rv_throttle_ops.handle_sched_switch(NULL, 0, other, target, TASK_RUNNING);
+	rv_throttle_ops.handle_dl_replenish(NULL, &target->dl, 0, DL_TASK);
+	udelay(9);
+	rv_throttle_ops.handle_dl_throttle(NULL, &target->dl, 0, DL_TASK);
+	RV_KUNIT_EXPECT_NO_REACTION(test, ctx);
+	rv_throttle_ops.handle_sched_switch(NULL, 0, other, target, TASK_RUNNING);
+	RV_KUNIT_EXPECT_REACTION(test, ctx);
+
+	/* Task runs longer than runtime */
+	rv_throttle_ops.handle_sched_switch(NULL, 0, other, target, TASK_RUNNING);
+	rv_throttle_ops.handle_dl_replenish(NULL, &target->dl, 0, DL_TASK);
+	udelay(10 + TICK_USEC);
+	rv_throttle_ops.handle_dl_throttle(NULL, &target->dl, 0, DL_TASK);
+	RV_KUNIT_EXPECT_REACTION(test, ctx);
+}
+
+#else
+#define rv_test_throttle rv_test_stub
+#endif
diff --git a/kernel/trace/rv/monitors/throttle/throttle_kunit.h b/kernel/trace/rv/monitors/throttle/throttle_kunit.h
new file mode 100644
index 000000000000..d730497deca4
--- /dev/null
+++ b/kernel/trace/rv/monitors/throttle/throttle_kunit.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Automatically generated by rvgen kunit.
+ * May need manual intervention for function prototypes that couldn't be
+ * found (e.g. are in another file) or variables to be exported.
+ */
+
+#ifndef __THROTTLE_KUNIT_H
+#define __THROTTLE_KUNIT_H
+
+#if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_TEST)
+
+#include <linux/rv.h>
+#include <rv/kunit.h>
+
+extern const struct rv_throttle_ops {
+	struct rv_kunit_mon mon;
+	void (*handle_dl_replenish)(void *data, struct sched_dl_entity *dl_se,
+				int cpu, u8 type);
+	void (*handle_dl_throttle)(void *data, struct sched_dl_entity *dl_se,
+			       int cpu, u8 type);
+	void (*handle_sched_enqueue)(void *data, struct task_struct *tsk, int cpu);
+	void (*handle_sched_switch)(void *data, bool preempt,
+				struct task_struct *prev,
+				struct task_struct *next,
+				unsigned int prev_state);
+	void (*handle_sys_enter)(void *data, struct pt_regs *regs, long id);
+	void (*handle_newtask)(void *data, struct task_struct *task, u64 flags);
+	void (*handle_dl_server_stop)(void *data, struct sched_dl_entity *dl_se,
+				  int cpu, u8 type);
+} rv_throttle_ops;
+#endif
+
+#endif /* __THROTTLE_KUNIT_H */
diff --git a/kernel/trace/rv/rv_monitors_test.c b/kernel/trace/rv/rv_monitors_test.c
index 3ad11195e664..13af7e26205c 100644
--- a/kernel/trace/rv/rv_monitors_test.c
+++ b/kernel/trace/rv/rv_monitors_test.c
@@ -151,6 +151,7 @@ static void rv_test_dummy(struct kunit *test)
 #include "monitors/sts/sts_kunit.c"
 #include "monitors/opid/opid_kunit.c"
 #include "monitors/nomiss/nomiss_kunit.c"
+#include "monitors/throttle/throttle_kunit.c"
 #include "monitors/pagefault/pagefault_kunit.c"
 #include "monitors/sleep/sleep_kunit.c"
 
@@ -161,6 +162,7 @@ static struct kunit_case rv_mon_test_cases[] = {
 	KUNIT_CASE(rv_test_sts),
 	KUNIT_CASE(rv_test_opid),
 	KUNIT_CASE(rv_test_nomiss),
+	KUNIT_CASE(rv_test_throttle),
 	KUNIT_CASE(rv_test_pagefault),
 	KUNIT_CASE(rv_test_sleep),
 	{}
-- 
2.55.0


  parent reply	other threads:[~2026-09-29 12:50 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-29 12:48 [PATCH 00/10] rv: Add remaining deadline monitors Gabriele Monaco
2026-09-29 12:48 ` [PATCH 01/10] rv: Force environment reset action on HA monitor start Gabriele Monaco
2026-09-29 12:49 ` [PATCH 02/10] rv: Remove unused ha_monitor_env_invalid() Gabriele Monaco
2026-09-29 12:49 ` [PATCH 03/10] rv: Cache timer budget when starting HA timers Gabriele Monaco
2026-09-29 13:06   ` sashiko-bot
2026-09-29 12:49 ` [PATCH 04/10] tools/rvgen: Default to HA_TIMER_WHEEL for jiffy clocks Gabriele Monaco
2026-09-29 12:49 ` [PATCH 05/10] sched: Add task enqueue/dequeue trace points Gabriele Monaco
2026-09-29 12:49 ` [PATCH 06/10] rv: Add enqueue/dequeue to snroc monitor Gabriele Monaco
2026-09-29 12:49 ` [PATCH 07/10] rv: Add throttle deadline monitor Gabriele Monaco
2026-09-29 13:18   ` sashiko-bot
2026-09-29 12:49 ` [PATCH 08/10] rv: Add dl_server specific monitors Gabriele Monaco
2026-09-29 13:24   ` sashiko-bot
2026-09-29 12:49 ` Gabriele Monaco [this message]
2026-09-29 13:18   ` [PATCH 09/10] rv: Add KUnit test for throttle monitor sashiko-bot
2026-09-29 12:49 ` [PATCH 10/10] selftests/verification: Lower stressor priority in rv_deadline Gabriele Monaco

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260929124908.177676-10-gmonaco@redhat.com \
    --to=gmonaco@redhat.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=namcao@linutronix.de \
    --cc=rostedt@goodmis.org \
    --cc=wen.yang@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.