From: Fernand Sieber <sieberf@amazon.com>
To: <linux-kernel@vger.kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>
Cc: <linux-trace-kernel@vger.kernel.org>,
James Gowans <jgowans@amazon.com>, <nh-open-source@amazon.com>
Subject: [PATCH] sched: Add core cookie update tracepoint
Date: Tue, 28 Jan 2025 13:34:09 +0200 [thread overview]
Message-ID: <20250128113410.263994-1-sieberf@amazon.com> (raw)
ftrace based analysis can be used to qualify correct behavior of cookie based
applications. Security posture can be verified by tracing the amount of time
that tasks with different cookies collocate on hyperthread siblings and
asserting that it is kept to a minimum. Performance posture can be we measured
by minimizing foce idle (when an hyperthread is kept idle because it doesn't
have a runnable task matching the cookie of its sibling). It is necessary
for the application doing such an analyis to know the cookie associated with
each task at any point in time.
While the task to cookie mapping is driven by userspace and thus can
alternatively be supplied through a custom side channel to an application
analysing a trace, it is more convenient and accurate if the mapping is already
part of the trace. Given that these events are infrequent the induced
overhead is negligible.
Signed-off-by: Fernand Sieber <sieberf@amazon.com>
---
include/trace/events/sched.h | 30 ++++++++++++++++++++++++++++++
kernel/sched/core_sched.c | 1 +
2 files changed, 31 insertions(+)
diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h
index 9ea4c404bd4e..6034acbc1893 100644
--- a/include/trace/events/sched.h
+++ b/include/trace/events/sched.h
@@ -769,6 +769,36 @@ TRACE_EVENT(sched_wake_idle_without_ipi,
TP_printk("cpu=%d", __entry->cpu)
);
+#ifdef CONFIG_SCHED_CORE
+/*
+ * Tracepoint for assigning cookies.
+ */
+TRACE_EVENT(sched_setcookie,
+
+ TP_PROTO(struct task_struct *tsk, unsigned long cookie),
+
+ TP_ARGS(tsk, cookie),
+
+ TP_STRUCT__entry(
+ __array(char, comm, TASK_COMM_LEN)
+ __field(pid_t, pid)
+ __field(unsigned long, oldcookie)
+ __field(unsigned long, newcookie)
+ ),
+
+ TP_fast_assign(
+ memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
+ __entry->pid = tsk->pid;
+ __entry->oldcookie = tsk->core_cookie;
+ __entry->newcookie = cookie;
+ ),
+
+ TP_printk("comm=%s pid=%d oldcookie=%lx newcookie=%lx",
+ __entry->comm, __entry->pid,
+ __entry->oldcookie, __entry->newcookie)
+);
+#endif
+
/*
* Following tracepoints are not exported in tracefs and provide hooking
* mechanisms only for testing and debugging purposes.
diff --git a/kernel/sched/core_sched.c b/kernel/sched/core_sched.c
index 1ef98a93eb1d..0321ccd9f944 100644
--- a/kernel/sched/core_sched.c
+++ b/kernel/sched/core_sched.c
@@ -71,6 +71,7 @@ static unsigned long sched_core_update_cookie(struct task_struct *p,
sched_core_dequeue(rq, p, DEQUEUE_SAVE);
old_cookie = p->core_cookie;
+ trace_sched_setcookie(p, cookie);
p->core_cookie = cookie;
/*
--
2.43.0
Amazon Development Centre (South Africa) (Proprietary) Limited
29 Gogosoa Street, Observatory, Cape Town, Western Cape, 7925, South Africa
Registration Number: 2004 / 034463 / 07
reply other threads:[~2025-01-28 11:35 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20250128113410.263994-1-sieberf@amazon.com \
--to=sieberf@amazon.com \
--cc=jgowans@amazon.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=nh-open-source@amazon.com \
--cc=peterz@infradead.org \
--cc=vincent.guittot@linaro.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox