From nobody Sun Oct 5 20:17:11 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EBCF432C85; Wed, 30 Jul 2025 12:45:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753879551; cv=none; b=AXrn43BRcKagMbpwUoGuBfNEvvdpUfoqmd5bvFkJZS4HLay/s+77QwtKJ6pSl9cCE8Dk6yMupef2qRnaH3IKa3kVnYJcIM0GF4RrvZiemdMHRWd3ClDAh5KhDhQZVpx+uPqUqV0ymD2fX9PvFncCRm5pThMysEdK/Yh8bGZ9wCk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753879551; c=relaxed/simple; bh=MMM2RVExWAbysqb/htJ2BmkgvV8x5F7LLfpeseVNPuQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lVVti/QXAQ++wLRfS48kSFoHpDSbOutfpWCn6uhEgyih9F+LygleHZTHhUMq3E2Fo4VPo3h0+JcYi59aYieRgnIuRca5gIyybJ7dPJ+KXzEHC5Z+bDCZ7seZ9mzJcdRsgxbGM0GHcl6bwiIowDbUgTW7e1IadUt/nYDzQxFa9AI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=mYBhyarX; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=LcjtpVvQ; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="mYBhyarX"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="LcjtpVvQ" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1753879548; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7BpV/z5oEV4aIIRUmysgnNetQqrLpd2YvL5nfa+3+2c=; b=mYBhyarX305VFM1lb65sLXsONjoDi8EBSLkH5nJlrkGpiuYnvxBTBUQr9DM62CRNthMhwt PVOgCDdHVcM6hlv2pN5AafoPRvSzNjlgH0XtC0KhXxNbHRmjbapDG8miF4kX0Rsto8D3r/ yEbx4SP6SIdcVX/4m6aM8AmsoFVrRu0dwLerctxQXrzr4nGyPqemQVIN4cGpZjxJFVJKnc 1cnyAYJqfaDgCgLVYUi3Ml9E7Bq5UU7tl1KI/VvNOH3pl+3SoeuAjfbK9pt7paKjeK5M1c CT4Ge6py4ZYU421TbwAMH8NuqlCxpblm+1SM+6m7e5QMmIu+iQVxICbYtV9pKg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1753879548; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7BpV/z5oEV4aIIRUmysgnNetQqrLpd2YvL5nfa+3+2c=; b=LcjtpVvQf2Ji1rIsIn6tFKJFFyKrz/G7aNm8EETj4/2x3t6UASX3ZTY/Kdap+ah6rNVjqy HxhUQbV3zHLb2hBQ== To: Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Gabriele Monaco , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH 1/5] rv/ltl: Prepare for other monitor types Date: Wed, 30 Jul 2025 14:45:39 +0200 Message-Id: <0d13c61bc6e0dc82108995c9a1d140bad4082039.1753879295.git.namcao@linutronix.de> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" rv/ltl_monitor.h is the template file used by all LTL monitors. But only per-task monitor is supported. Prepare to support for other monitor types: - Change the monitored target type into an opaque type which will be defined differently depending on the monitor type. This type is only defined as struct task_struct * for now. - Separate out the per-task-specific printf format and arguments, so that rv_cond_react() can be shared with other monitor types. No functional change intended. Signed-off-by: Nam Cao Reviewed-by: Gabriele Monaco --- include/linux/rv.h | 1 + include/rv/ltl_monitor.h | 85 +++++++++++-------- .../trace/rv/monitors/pagefault/pagefault.h | 2 + kernel/trace/rv/monitors/sleep/sleep.h | 2 + 4 files changed, 55 insertions(+), 35 deletions(-) diff --git a/include/linux/rv.h b/include/linux/rv.h index 14410a42faef..175438a22641 100644 --- a/include/linux/rv.h +++ b/include/linux/rv.h @@ -28,6 +28,7 @@ struct da_monitor { =20 #ifdef CONFIG_RV_LTL_MONITOR =20 +#define LTL_TASK_MONITOR 0 /* * In the future, if the number of atomic propositions or the size of Buchi * automaton is larger, we can switch to dynamic allocation. For now, the = code diff --git a/include/rv/ltl_monitor.h b/include/rv/ltl_monitor.h index 67031a774e3d..466155fd53e6 100644 --- a/include/rv/ltl_monitor.h +++ b/include/rv/ltl_monitor.h @@ -16,49 +16,63 @@ #error "Please include $(MODEL_NAME).h generated by rvgen" #endif =20 +#if LTL_MONITOR_TYPE =3D=3D LTL_TASK_MONITOR + +#define TARGET_PRINT_FORMAT "%s[%d]" +#define TARGET_PRINT_ARGS(task) task->comm, task->pid + +typedef struct task_struct *monitor_target; + +#endif + #ifdef CONFIG_RV_REACTORS #define RV_MONITOR_NAME CONCATENATE(rv_, MONITOR_NAME) static struct rv_monitor RV_MONITOR_NAME; =20 -static void rv_cond_react(struct task_struct *task) +static void rv_cond_react(monitor_target target) { if (!rv_reacting_on() || !RV_MONITOR_NAME.react) return; - RV_MONITOR_NAME.react("rv: "__stringify(MONITOR_NAME)": %s[%d]: violation= detected\n", - task->comm, task->pid); + + RV_MONITOR_NAME.react( + "rv: "__stringify(MONITOR_NAME)": "TARGET_PRINT_FORMAT": violation detec= ted\n", + TARGET_PRINT_ARGS(target)); } #else -static void rv_cond_react(struct task_struct *task) +static void rv_cond_react(monitor_target target) { } #endif =20 -static int ltl_monitor_slot =3D RV_PER_TASK_MONITOR_INIT; +static void ltl_atoms_fetch(monitor_target target, struct ltl_monitor *mon= ); +static void ltl_atoms_init(monitor_target target, struct ltl_monitor *mon,= bool target_creation); =20 -static void ltl_atoms_fetch(struct task_struct *task, struct ltl_monitor *= mon); -static void ltl_atoms_init(struct task_struct *task, struct ltl_monitor *m= on, bool task_creation); +#if LTL_MONITOR_TYPE =3D=3D LTL_TASK_MONITOR +static int ltl_monitor_slot =3D RV_PER_TASK_MONITOR_INIT; =20 -static struct ltl_monitor *ltl_get_monitor(struct task_struct *task) +static struct ltl_monitor *ltl_get_monitor(monitor_target target) { - return &task->rv[ltl_monitor_slot].ltl_mon; + return &target->rv[ltl_monitor_slot].ltl_mon; } +#endif =20 -static void ltl_task_init(struct task_struct *task, bool task_creation) +static void ltl_target_init(monitor_target target, bool target_creation) { - struct ltl_monitor *mon =3D ltl_get_monitor(task); + struct ltl_monitor *mon =3D ltl_get_monitor(target); =20 memset(&mon->states, 0, sizeof(mon->states)); =20 for (int i =3D 0; i < LTL_NUM_ATOM; ++i) __set_bit(i, mon->unknown_atoms); =20 - ltl_atoms_init(task, mon, task_creation); - ltl_atoms_fetch(task, mon); + ltl_atoms_init(target, mon, target_creation); + ltl_atoms_fetch(target, mon); } =20 +#if LTL_MONITOR_TYPE =3D=3D LTL_TASK_MONITOR static void handle_task_newtask(void *data, struct task_struct *task, unsi= gned long flags) { - ltl_task_init(task, true); + ltl_target_init(task, true); } =20 static int ltl_monitor_init(void) @@ -77,10 +91,10 @@ static int ltl_monitor_init(void) read_lock(&tasklist_lock); =20 for_each_process_thread(g, p) - ltl_task_init(p, false); + ltl_target_init(p, false); =20 for_each_present_cpu(cpu) - ltl_task_init(idle_task(cpu), false); + ltl_target_init(idle_task(cpu), false); =20 read_unlock(&tasklist_lock); =20 @@ -94,17 +108,18 @@ static void ltl_monitor_destroy(void) rv_put_task_monitor_slot(ltl_monitor_slot); ltl_monitor_slot =3D RV_PER_TASK_MONITOR_INIT; } +#endif =20 -static void ltl_illegal_state(struct task_struct *task, struct ltl_monitor= *mon) +static void ltl_illegal_state(monitor_target target, struct ltl_monitor *m= on) { - CONCATENATE(trace_error_, MONITOR_NAME)(task); - rv_cond_react(task); + CONCATENATE(trace_error_, MONITOR_NAME)(target); + rv_cond_react(target); } =20 -static void ltl_attempt_start(struct task_struct *task, struct ltl_monitor= *mon) +static void ltl_attempt_start(monitor_target target, struct ltl_monitor *m= on) { if (rv_ltl_all_atoms_known(mon)) - ltl_start(task, mon); + ltl_start(target, mon); } =20 static inline void ltl_atom_set(struct ltl_monitor *mon, enum ltl_atom ato= m, bool value) @@ -117,7 +132,7 @@ static inline void ltl_atom_set(struct ltl_monitor *mon= , enum ltl_atom atom, boo } =20 static void -ltl_trace_event(struct task_struct *task, struct ltl_monitor *mon, unsigne= d long *next_state) +ltl_trace_event(monitor_target target, struct ltl_monitor *mon, unsigned l= ong *next_state) { const char *format_str =3D "%s"; DECLARE_SEQ_BUF(atoms, 64); @@ -137,10 +152,10 @@ ltl_trace_event(struct task_struct *task, struct ltl_= monitor *mon, unsigned long } } =20 - CONCATENATE(trace_event_, MONITOR_NAME)(task, states, atoms.buffer, next); + CONCATENATE(trace_event_, MONITOR_NAME)(target, states, atoms.buffer, nex= t); } =20 -static void ltl_validate(struct task_struct *task, struct ltl_monitor *mon) +static void ltl_validate(monitor_target target, struct ltl_monitor *mon) { DECLARE_BITMAP(next_states, RV_MAX_BA_STATES) =3D {0}; =20 @@ -152,35 +167,35 @@ static void ltl_validate(struct task_struct *task, st= ruct ltl_monitor *mon) ltl_possible_next_states(mon, i, next_states); } =20 - ltl_trace_event(task, mon, next_states); + ltl_trace_event(target, mon, next_states); =20 memcpy(mon->states, next_states, sizeof(next_states)); =20 if (!rv_ltl_valid_state(mon)) - ltl_illegal_state(task, mon); + ltl_illegal_state(target, mon); } =20 -static void ltl_atom_update(struct task_struct *task, enum ltl_atom atom, = bool value) +static void ltl_atom_update(monitor_target target, enum ltl_atom atom, boo= l value) { - struct ltl_monitor *mon =3D ltl_get_monitor(task); + struct ltl_monitor *mon =3D ltl_get_monitor(target); =20 ltl_atom_set(mon, atom, value); - ltl_atoms_fetch(task, mon); + ltl_atoms_fetch(target, mon); =20 if (!rv_ltl_valid_state(mon)) { - ltl_attempt_start(task, mon); + ltl_attempt_start(target, mon); return; } =20 - ltl_validate(task, mon); + ltl_validate(target, mon); } =20 -static void __maybe_unused ltl_atom_pulse(struct task_struct *task, enum l= tl_atom atom, bool value) +static void __maybe_unused ltl_atom_pulse(monitor_target target, enum ltl_= atom atom, bool value) { - struct ltl_monitor *mon =3D ltl_get_monitor(task); + struct ltl_monitor *mon =3D ltl_get_monitor(target); =20 - ltl_atom_update(task, atom, value); + ltl_atom_update(target, atom, value); =20 ltl_atom_set(mon, atom, !value); - ltl_validate(task, mon); + ltl_validate(target, mon); } diff --git a/kernel/trace/rv/monitors/pagefault/pagefault.h b/kernel/trace/= rv/monitors/pagefault/pagefault.h index c580ec194009..cc825be51ffc 100644 --- a/kernel/trace/rv/monitors/pagefault/pagefault.h +++ b/kernel/trace/rv/monitors/pagefault/pagefault.h @@ -11,6 +11,8 @@ =20 #define MONITOR_NAME pagefault =20 +#define LTL_MONITOR_TYPE LTL_TASK_MONITOR + enum ltl_atom { LTL_PAGEFAULT, LTL_RT, diff --git a/kernel/trace/rv/monitors/sleep/sleep.h b/kernel/trace/rv/monit= ors/sleep/sleep.h index 2ab46fd218d2..c3752bc9f93f 100644 --- a/kernel/trace/rv/monitors/sleep/sleep.h +++ b/kernel/trace/rv/monitors/sleep/sleep.h @@ -11,6 +11,8 @@ =20 #define MONITOR_NAME sleep =20 +#define LTL_MONITOR_TYPE LTL_TASK_MONITOR + enum ltl_atom { LTL_ABORT_SLEEP, LTL_BLOCK_ON_RT_MUTEX, --=20 2.39.5 From nobody Sun Oct 5 20:17:11 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 479ED7E110; Wed, 30 Jul 2025 12:45:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753879551; cv=none; b=S7HnG2sCAOn0jMmtV/3PfJ0V1fq5nxUUbdzoEU3lC5Breb5AMBfQjDwG91XUBOoZnm2q2J2RTIMMzaSqLlq5DeuaZTbYkpXjOv//qLHFntlQbUSYErr6COONdhcq+mJIIP9pv2nB+4e/UlsktSPY8uFrWP69YC16yDsRqFiVD4I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753879551; c=relaxed/simple; bh=I1ppgLn+z/P1wOyVE+T6hdZ7XtSceHZO52uMuEwNRuo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nfe6Yxq54gV/ULPWU10N19GMor3tALPgGn7pd2MsObhrOLpt1RaV4w4yZXqhmEV/f+ShcsB25WoW6S1etRJCLYZeDoBWJVJHNvu/LVq6JMX+ksA3/hzDbJ2Qp1KKvDkW/OLlnwfHxi10b2tnBs4X89k0kwjdp1ptGGzDSt1tTMA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Ys1be1nK; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=i+/HvBf8; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Ys1be1nK"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="i+/HvBf8" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1753879548; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m+9ZvCAvr7r5DZXouvSSC23q/YVNnxkLHU1EznG+3zQ=; b=Ys1be1nKUb5NudMSRrjtttFD+KIJeZYZoIdkI1ndvJK5/BxW1N/55w87Ol4G/7fUWTyl79 7MrqYWPBAvRSYqzzz0iVBN0Q964LOWYolO232+pe177YXo8BmD1kExTQkbsF5lGMaEh/r+ dBJ3RlZsK+oDOMx43iS2YnFHM7wTtiOAWGPWW5QFxej554j7iwWsDks+Hxun3nZ5etNY8Z JacadZhFvb7zfCf+nqcUAXdUr0B+e/wvrd7O532W30Jmz63jhNzON+qY4nwnlE67bfYdb5 qa1TkNvhVET6p86ihuh0aFhy116qSBTS+znGu+eUXZ1ihP5uoDVT8NgOX0loNQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1753879548; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m+9ZvCAvr7r5DZXouvSSC23q/YVNnxkLHU1EznG+3zQ=; b=i+/HvBf8zMqgNl6/NpwOboLU9S4i0pkiyWjl6VmAn0xcsAW5IqGUJ/x7/1F+i5yOxUnnXi L5Kk0dhe/cKdJWCg== To: Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Gabriele Monaco , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH 2/5] rv/ltl: Support per-cpu monitors Date: Wed, 30 Jul 2025 14:45:40 +0200 Message-Id: In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support for per-cpu run-time verification linear temporal logic monitors. This is analogous to deterministic automaton per-cpu monitors. Signed-off-by: Nam Cao --- include/linux/rv.h | 1 + include/rv/ltl_monitor.h | 32 ++++++++++++++++++++++++++ kernel/trace/rv/Kconfig | 4 ++++ kernel/trace/rv/rv_trace.h | 47 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+) diff --git a/include/linux/rv.h b/include/linux/rv.h index 175438a22641..a41ae5980099 100644 --- a/include/linux/rv.h +++ b/include/linux/rv.h @@ -29,6 +29,7 @@ struct da_monitor { #ifdef CONFIG_RV_LTL_MONITOR =20 #define LTL_TASK_MONITOR 0 +#define LTL_CPU_MONITOR 1 /* * In the future, if the number of atomic propositions or the size of Buchi * automaton is larger, we can switch to dynamic allocation. For now, the = code diff --git a/include/rv/ltl_monitor.h b/include/rv/ltl_monitor.h index 466155fd53e6..29bbf86d1a52 100644 --- a/include/rv/ltl_monitor.h +++ b/include/rv/ltl_monitor.h @@ -23,12 +23,21 @@ =20 typedef struct task_struct *monitor_target; =20 +#elif LTL_MONITOR_TYPE =3D=3D LTL_CPU_MONITOR + +#define TARGET_PRINT_FORMAT "%u" +#define TARGET_PRINT_ARGS(cpu) cpu + +typedef unsigned int monitor_target; + #endif =20 #ifdef CONFIG_RV_REACTORS #define RV_MONITOR_NAME CONCATENATE(rv_, MONITOR_NAME) static struct rv_monitor RV_MONITOR_NAME; =20 +static struct ltl_monitor *ltl_get_monitor(monitor_target target); + static void rv_cond_react(monitor_target target) { if (!rv_reacting_on() || !RV_MONITOR_NAME.react) @@ -54,6 +63,13 @@ static struct ltl_monitor *ltl_get_monitor(monitor_targe= t target) { return &target->rv[ltl_monitor_slot].ltl_mon; } +#elif LTL_MONITOR_TYPE =3D=3D LTL_CPU_MONITOR +static struct ltl_monitor *ltl_get_monitor(unsigned int cpu) +{ + static DEFINE_PER_CPU(struct ltl_monitor, ltl_monitor); + + return per_cpu_ptr(<l_monitor, cpu); +} #endif =20 static void ltl_target_init(monitor_target target, bool target_creation) @@ -108,6 +124,22 @@ static void ltl_monitor_destroy(void) rv_put_task_monitor_slot(ltl_monitor_slot); ltl_monitor_slot =3D RV_PER_TASK_MONITOR_INIT; } + +#elif LTL_MONITOR_TYPE =3D=3D LTL_CPU_MONITOR + +static int ltl_monitor_init(void) +{ + unsigned int cpu; + + for_each_possible_cpu(cpu) + ltl_target_init(cpu, false); + return 0; +} + +static void ltl_monitor_destroy(void) +{ +} + #endif =20 static void ltl_illegal_state(monitor_target target, struct ltl_monitor *m= on) diff --git a/kernel/trace/rv/Kconfig b/kernel/trace/rv/Kconfig index 5b4be87ba59d..951c2e0cda25 100644 --- a/kernel/trace/rv/Kconfig +++ b/kernel/trace/rv/Kconfig @@ -16,6 +16,10 @@ config DA_MON_EVENTS_ID select RV_MON_MAINTENANCE_EVENTS bool =20 +config LTL_MON_EVENTS_IMPLICIT + select RV_MON_EVENTS + bool + config LTL_MON_EVENTS_ID select RV_MON_EVENTS bool diff --git a/kernel/trace/rv/rv_trace.h b/kernel/trace/rv/rv_trace.h index 4a6faddac614..f9e5fd044c45 100644 --- a/kernel/trace/rv/rv_trace.h +++ b/kernel/trace/rv/rv_trace.h @@ -177,6 +177,53 @@ DECLARE_EVENT_CLASS(error_ltl_monitor_id, #include #include // Add new monitors based on CONFIG_LTL_MON_EVENTS_ID here + +#ifdef CONFIG_LTL_MON_EVENTS_IMPLICIT +DECLARE_EVENT_CLASS(event_ltl_monitor, + + TP_PROTO(unsigned int cpu, char *states, char *atoms, char *next), + + TP_ARGS(cpu, states, atoms, next), + + TP_STRUCT__entry( + __field(unsigned int, cpu) + __string(states, states) + __string(atoms, atoms) + __string(next, next) + ), + + TP_fast_assign( + __entry->cpu =3D cpu; + __assign_str(states); + __assign_str(atoms); + __assign_str(next); + ), + + TP_printk("cpu%u: (%s) x (%s) -> (%s)", __entry->cpu, + __get_str(states), __get_str(atoms), __get_str(next)) +); + +DECLARE_EVENT_CLASS(error_ltl_monitor, + + TP_PROTO(unsigned int cpu), + + TP_ARGS(cpu), + + TP_STRUCT__entry( + __field(unsigned int, cpu) + ), + + TP_fast_assign( + __entry->cpu =3D cpu; + ), + + TP_printk("cpu%u: violation detected", __entry->cpu) +); +#include +// Add new monitors based on CONFIG_LTL_MON_EVENTS_IMPLICIT here + +#endif /* CONFIG_LTL_MON_EVENTS_IMPLICIT */ + #endif /* CONFIG_LTL_MON_EVENTS_ID */ =20 #ifdef CONFIG_RV_MON_MAINTENANCE_EVENTS --=20 2.39.5 From nobody Sun Oct 5 20:17:11 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD20214885D; Wed, 30 Jul 2025 12:45:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753879552; cv=none; b=pG80VGwI9XTIjcH62UMH8fDgbmHIMPDeAszhtdRar9Ksr07Ujy2FtXqeJp/6Opu9jEaTPHN/WLXAoSO2lK7p8bg/m6FSLx485/hEozIqt8GF6qWJpK4rAaCw6OvGsdiLbfdWB/+b+Jdbo8GBaDT9CoKz5LfocZJksjGoLRZD/F0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753879552; c=relaxed/simple; bh=SG5hsGJtUVJ9pkqGhK5oyhoYPlbt7Y6ZFEaFWl7f/b8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WvuY81/+5bhua5tQxgwQRb97uQivwpDAk+1Zs+CYFiDu2fsrFurwbcFGpnV+ufFoZEks9uEgRQPXoRhDhE5B/pfVT/oiypk1/KhFAjZehMWHMft8DZIkvAbybW2YNOD9odeMy70yQdZzrfPa38IxSjoewHb19yc+kC6kEMfkkVI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=BpaHdrm/; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=t80+L40R; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="BpaHdrm/"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="t80+L40R" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1753879548; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vn7HO/aACdHhIlRnlBToKGaBd3DspogcnJie/zXFTts=; b=BpaHdrm/Os6CVyrQFuALeJhjZFLhW/i/PfWaHEIXi1iVkgxS0d7mRgMXeFHc5KYZDLvHXp KL3rSiL9eArUd4OzjONwVe/Ysi8BIUE2oOPTVn/AszxaI51keCZEAMD79LESYujA2IsnM8 UIcqUH5lU6caJ65+YWquHm919+QN46md07hLgWhxueSiczV5NXEbV0gImwCO9GPcB4167i SwYnbrCY0phiSDrYoG1rA8TErLCdcJaVosQKCR+eNf9HSPlCjOsRwn09cCsjOuFRovoSjW gSdWDiWYE5WBCV5VBqf2YyFjE1QQ56pER/GNE3NGNx0X0Dv+MgnLBMKWVLjlDg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1753879548; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vn7HO/aACdHhIlRnlBToKGaBd3DspogcnJie/zXFTts=; b=t80+L40RAOcgyJUazdJAKICoKEBgVd1a9MTf/6td7j4O/tn1XBCs0W46iDtP2UnUb228lS efMDukPPQaD9qACg== To: Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Gabriele Monaco , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH 3/5] verification/rvgen/ltl: Support per-cpu monitor generation Date: Wed, 30 Jul 2025 14:45:41 +0200 Message-Id: <3c7900721428d9091f70302ea9b6c4577c749f63.1753879295.git.namcao@linutronix.de> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support to generate per-cpu LTL monitors. Similar to generating per-cpu monitors from .dot files, the "-t per_cpu" parameter can be used to generate per-cpu monitors from .ltl files. Signed-off-by: Nam Cao --- tools/verification/rvgen/rvgen/ltl2k.py | 48 ++++++++++++++++--- .../rvgen/rvgen/templates/ltl2k/main.c | 9 ++-- .../rvgen/rvgen/templates/ltl2k/trace.h | 7 ++- 3 files changed, 50 insertions(+), 14 deletions(-) diff --git a/tools/verification/rvgen/rvgen/ltl2k.py b/tools/verification/r= vgen/rvgen/ltl2k.py index b075f98d50c4..0fd3f9963a87 100644 --- a/tools/verification/rvgen/rvgen/ltl2k.py +++ b/tools/verification/rvgen/rvgen/ltl2k.py @@ -57,9 +57,16 @@ class ltl2k(generator.Monitor): template_dir =3D "ltl2k" =20 def __init__(self, file_path, MonitorType, extra_params=3D{}): - if MonitorType !=3D "per_task": - raise NotImplementedError("Only per_task monitor is supported = for LTL") + if MonitorType =3D=3D "per_task": + self._target_arg =3D "struct task_struct *task" + self._target =3D "task" + elif MonitorType =3D=3D "per_cpu": + self._target_arg =3D "unsigned int cpu" + self._target =3D "cpu" + else: + raise NotImplementedError(f"LTL does not support monitor type = {MonitorType}") super().__init__(extra_params) + self.monitor_type =3D MonitorType with open(file_path) as f: self.atoms, self.ba, self.ltl =3D ltl2ba.create_graph(f.read()) self.atoms_abbr =3D abbreviate_atoms(self.atoms) @@ -67,6 +74,13 @@ class ltl2k(generator.Monitor): if not self.name: self.name =3D Path(file_path).stem =20 + def _fill_monitor_type(self) -> str: + if self.monitor_type =3D=3D "per_task": + return "#define LTL_MONITOR_TYPE LTL_TASK_MONITOR" + if self.monitor_type =3D=3D "per_cpu": + return "#define LTL_MONITOR_TYPE LTL_CPU_MONITOR" + assert False + def _fill_states(self) -> str: buf =3D [ "enum ltl_buchi_state {", @@ -174,7 +188,7 @@ class ltl2k(generator.Monitor): =20 def _fill_start(self): buf =3D [ - "static void ltl_start(struct task_struct *task, struct ltl_mo= nitor *mon)", + "static void ltl_start(%s, struct ltl_monitor *mon)" % self._t= arget_arg, "{" ] =20 @@ -205,7 +219,7 @@ class ltl2k(generator.Monitor): buff =3D [] buff.append("static void handle_example_event(void *data, /* XXX: = fill header */)") buff.append("{") - buff.append("\tltl_atom_update(task, LTL_%s, true/false);" % self.= atoms[0]) + buff.append("\tltl_atom_update(%s, LTL_%s, true/false);" % (self._= target, self.atoms[0])) buff.append("}") buff.append("") return '\n'.join(buff) @@ -241,6 +255,9 @@ class ltl2k(generator.Monitor): "" ] =20 + buf.append(self._fill_monitor_type()) + buf.append('') + buf.extend(self._fill_atoms()) buf.append('') =20 @@ -259,13 +276,32 @@ class ltl2k(generator.Monitor): return '\n'.join(buf) =20 def fill_monitor_class_type(self): - return "LTL_MON_EVENTS_ID" + if self.monitor_type =3D=3D "per_task": + return "LTL_MON_EVENTS_ID" + if self.monitor_type =3D=3D "per_cpu": + return "LTL_MON_EVENTS_IMPLICIT" + assert False =20 def fill_monitor_class(self): - return "ltl_monitor_id" + if self.monitor_type =3D=3D "per_task": + return "ltl_monitor_id" + if self.monitor_type =3D=3D "per_cpu": + return "ltl_monitor" + assert False + + def fill_tracepoint_args_skel(self, tp_type): + if tp_type =3D=3D "event": + return \ + ("\tTP_PROTO(%s, char *states, char *atoms, char *next),\n= " % self._target_arg) + \ + ("\tTP_ARGS(%s, states, atoms, next)" % self._target) + if tp_type =3D=3D "error": + return \ + ("\tTP_PROTO(%s),\n" % self._target_arg) + \ + ("\tTP_ARGS(%s)" % self._target) =20 def fill_main_c(self): main_c =3D super().fill_main_c() main_c =3D main_c.replace("%%ATOMS_INIT%%", self.fill_atoms_init()) + main_c =3D main_c.replace("%%TARGET_ARG%%", self._target_arg) =20 return main_c diff --git a/tools/verification/rvgen/rvgen/templates/ltl2k/main.c b/tools/= verification/rvgen/rvgen/templates/ltl2k/main.c index f85d076fbf78..09167efbfbf0 100644 --- a/tools/verification/rvgen/rvgen/templates/ltl2k/main.c +++ b/tools/verification/rvgen/rvgen/templates/ltl2k/main.c @@ -23,7 +23,7 @@ #include "%%MODEL_NAME%%.h" #include =20 -static void ltl_atoms_fetch(struct task_struct *task, struct ltl_monitor *= mon) +static void ltl_atoms_fetch(%%TARGET_ARG%%, struct ltl_monitor *mon) { /* * This is called everytime the Buchi automaton is triggered. @@ -36,13 +36,14 @@ static void ltl_atoms_fetch(struct task_struct *task, s= truct ltl_monitor *mon) */ } =20 -static void ltl_atoms_init(struct task_struct *task, struct ltl_monitor *m= on, bool task_creation) +static void ltl_atoms_init(%%TARGET_ARG%%, struct ltl_monitor *mon, bool t= arget_creation) { /* * This should initialize as many atomic propositions as possible. * - * @task_creation indicates whether the task is being created. This is - * false if the task is already running before the monitor is enabled. + * @target_creation indicates whether the monitored target is being + * created. This is false if the monitor target is already online before + * the monitor is enabled. */ %%ATOMS_INIT%% } diff --git a/tools/verification/rvgen/rvgen/templates/ltl2k/trace.h b/tools= /verification/rvgen/rvgen/templates/ltl2k/trace.h index 49394c4b0f1c..87d3a1308926 100644 --- a/tools/verification/rvgen/rvgen/templates/ltl2k/trace.h +++ b/tools/verification/rvgen/rvgen/templates/ltl2k/trace.h @@ -6,9 +6,8 @@ =20 #ifdef CONFIG_RV_MON_%%MODEL_NAME_UP%% DEFINE_EVENT(event_%%MONITOR_CLASS%%, event_%%MODEL_NAME%%, - TP_PROTO(struct task_struct *task, char *states, char *atoms, char *= next), - TP_ARGS(task, states, atoms, next)); +%%TRACEPOINT_ARGS_SKEL_EVENT%%); + DEFINE_EVENT(error_%%MONITOR_CLASS%%, error_%%MODEL_NAME%%, - TP_PROTO(struct task_struct *task), - TP_ARGS(task)); +%%TRACEPOINT_ARGS_SKEL_ERROR%%); #endif /* CONFIG_RV_MON_%%MODEL_NAME_UP%% */ --=20 2.39.5 From nobody Sun Oct 5 20:17:11 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 17FE6A921; Wed, 30 Jul 2025 12:45:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753879552; cv=none; b=QMai+RClFIIErwubn7FhWNPaVarypzZp2TFg88WK4qK3FFx4JAqcTWoopL9djkS2Iaqm1mEsSQJjLG2Dd514f9CCnCMK3zk84Llz9QT6RRbQOvsWcl/5qMc2gLble0QCeG+XAmBtLdiCOh5Ql+bkBmAek5PC0X6MfH0odiUZP2Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753879552; c=relaxed/simple; bh=0GlN0TUZoy/aEWhdtGatkE2Ui4T36GdSbewZa4kLyJI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fxY8H4m+jWngxhRX3FMup4H8BEVA8/yArSg8H8xy48aCVwUE6XxvROyR6O8pSVB7y4MhfFkO/NgEnDMlgFr56+ILpQ0MoI/m3ArMwaKG7XpOHIfpCAA62xuOreulF9C3hcCDCGB7A9A4n0sy3s7LbgNugqp/nooH3UghlLLZDLg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=1op1n+nn; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=M0Oi0not; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="1op1n+nn"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="M0Oi0not" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1753879549; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4QqSbCislEFx6jLhFMONbQ68T9eOl0FVQg1Th9y8jXo=; b=1op1n+nnWyaJE/VUAIQam9P7ppNEFgaHBOb+0XoRkjMUW1kzbkJBYF2Gr4E0Ma1Cde9b7T 3ubSHaChydTSbfH8DzZ4B4zBCcgpOHWazJWmDcrGYMs8NonnBvQ12TjS7D0kdSUgWzKUI1 IykFDI9gRSqmQXOvPaA6oyk/+Bb7DWT5mBadrymTFZoRdEFG+f29MxTUlKuZK5+HYdASgu GE4ObYhFyddaAwYjh1lN7kYk0kzytyaqpm2Tvi4gSSRPUh6B9YXPJp4VxIrI8kgiLjxxzs lkMlAz/J/it2F/8I3HKATYi7jpggOHdD7UjMwTqMT4mS9Zwo3TWCWUno8Qt2dA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1753879549; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4QqSbCislEFx6jLhFMONbQ68T9eOl0FVQg1Th9y8jXo=; b=M0Oi0notUaVsA1xgF0ZpAACL/VfvqrjEXhzasnyfdF4CiJ2ptvxoDwPrksFRaH1RJ7BuOp e/jEd6fjgHFjiMCQ== To: Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Gabriele Monaco , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , Valentin Schneider Subject: [PATCH 4/5] sched: Add rt task enqueue/dequeue trace points Date: Wed, 30 Jul 2025 14:45:42 +0200 Message-Id: <8f83869a5040bd7cd3096bd12090c1ab110ae5c4.1753879295.git.namcao@linutronix.de> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add trace points into enqueue_task_rt() and dequeue_task_rt(). They are useful to implement RV monitor which validates RT scheduling. Signed-off-by: Nam Cao --- Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Juri Lelli Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Ben Segall Cc: Mel Gorman Cc: Valentin Schneider --- include/trace/events/sched.h | 8 ++++++++ kernel/sched/rt.c | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h index c08893bde255..c38f12f7f903 100644 --- a/include/trace/events/sched.h +++ b/include/trace/events/sched.h @@ -898,6 +898,14 @@ DECLARE_TRACE(sched_set_need_resched, TP_PROTO(struct task_struct *tsk, int cpu, int tif), TP_ARGS(tsk, cpu, tif)); =20 +DECLARE_TRACE(enqueue_task_rt, + TP_PROTO(int cpu, struct task_struct *task), + TP_ARGS(cpu, task)); + +DECLARE_TRACE(dequeue_task_rt, + TP_PROTO(int cpu, struct task_struct *task), + TP_ARGS(cpu, task)); + #endif /* _TRACE_SCHED_H */ =20 /* This part must be outside protection */ diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index e40422c37033..f4d3f5e7fbec 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -1480,6 +1480,8 @@ enqueue_task_rt(struct rq *rq, struct task_struct *p,= int flags) { struct sched_rt_entity *rt_se =3D &p->rt; =20 + trace_enqueue_task_rt_tp(rq->cpu, p); + if (flags & ENQUEUE_WAKEUP) rt_se->timeout =3D 0; =20 @@ -1501,6 +1503,8 @@ static bool dequeue_task_rt(struct rq *rq, struct tas= k_struct *p, int flags) =20 dequeue_pushable_task(rq, p); =20 + trace_dequeue_task_rt_tp(rq->cpu, p); + return true; } =20 --=20 2.39.5 From nobody Sun Oct 5 20:17:11 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4702229993A; Wed, 30 Jul 2025 12:45:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753879555; cv=none; b=e0+TVM7hYswlGWzfghsWzkS6tv38WyuhnFzqc/xdqxzp1xvhAuH/rV6ya4jDgbG470i17WbAP81GUfwbpij0FAfP2N+pWD2eMT0v21xLLK44gYOPLw/UQWGg1ecj1WxX6kGAWH4PYdD7dwu4CDuNmJDdlunM2LgU38H/p0gvsas= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753879555; c=relaxed/simple; bh=Nqqw8GQdbkA2wcGUdKyFw4jWrP7v4bYhHnJ7hECZ5vU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TDi56gDbuV6eg5qCpbOR9wJByOrSujNFdYgwKFHR8Uv5/uDyptpu4YdaIKeMX1x/gRTjYZxBydo1c1e4DPHPYP6kAO/I9S778t9xmIL+m1V4ZhdutLwjxbaY/Zl6Np9WKmKuw3yzuyp+Nvs1mcP2XztBSGHlx7xfB+Pbuu+zzo8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=teYNSu3X; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=izaKvcsx; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="teYNSu3X"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="izaKvcsx" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1753879549; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NsmGN1MF/UyltIqjER+3HwzGgGupyEGtu2ZKTPREJG0=; b=teYNSu3X0Bt9RYo10Ooc8Y1C4rRdcTqfS550PYOGMT0AuIVWethuYENPCYkpPvf8duoXsg 7JnWVRc5/1E6QUJl574rzaCGnx1BbBuIvvuAIzr3iiv4XUdsBfDOhbkrLMKRt9Y5xGKly4 s7xdx8PT56Fq3azulW7dYldF7+BAiApp/revc9N8OWLdxLHv3o6oYnHgVmxlQcQevFGxjH QguMVPANtWI3GQI0N3v2l9NVKpnKbLppPiuWciCaWix3vb+y5KK2bAhVhnWZxVmdvWWKdo e5tQSV16GJHcHHhPbC8+sNfr47tLoSoab8BAV395sBxpHmg2gFPggOdIToa+4w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1753879549; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NsmGN1MF/UyltIqjER+3HwzGgGupyEGtu2ZKTPREJG0=; b=izaKvcsxwEqS/e22LGHCRysoODHOQDd2z2HqM3x/OevPD3sMa4q4XPpk0014FQoGtJvEA3 gFZ9/0hxSDmwvGBw== To: Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Gabriele Monaco , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , Valentin Schneider Subject: [PATCH 5/5] rv: Add rts monitor Date: Wed, 30 Jul 2025 14:45:43 +0200 Message-Id: <20834b8fcd4dfe75642cec2097e29f4c636a33fb.1753879295.git.namcao@linutronix.de> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add "real-time scheduling" monitor, which validates that SCHED_RR and SCHED_FIFO tasks are scheduled before tasks with normal and extensible scheduling policies Signed-off-by: Nam Cao --- Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Juri Lelli Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Ben Segall Cc: Mel Gorman Cc: Valentin Schneider --- Documentation/trace/rv/monitor_sched.rst | 19 ++++ kernel/trace/rv/Kconfig | 1 + kernel/trace/rv/Makefile | 1 + kernel/trace/rv/monitors/rts/Kconfig | 17 +++ kernel/trace/rv/monitors/rts/rts.c | 131 +++++++++++++++++++++++ kernel/trace/rv/monitors/rts/rts.h | 126 ++++++++++++++++++++++ kernel/trace/rv/monitors/rts/rts_trace.h | 15 +++ tools/verification/models/sched/rts.ltl | 5 + 8 files changed, 315 insertions(+) create mode 100644 kernel/trace/rv/monitors/rts/Kconfig create mode 100644 kernel/trace/rv/monitors/rts/rts.c create mode 100644 kernel/trace/rv/monitors/rts/rts.h create mode 100644 kernel/trace/rv/monitors/rts/rts_trace.h create mode 100644 tools/verification/models/sched/rts.ltl diff --git a/Documentation/trace/rv/monitor_sched.rst b/Documentation/trace= /rv/monitor_sched.rst index 3f8381ad9ec7..2f9d62a1af1f 100644 --- a/Documentation/trace/rv/monitor_sched.rst +++ b/Documentation/trace/rv/monitor_sched.rst @@ -396,6 +396,25 @@ preemption is always disabled. On non- ``PREEMPT_RT`` = kernels, the interrupts might invoke a softirq to set ``need_resched`` and wake up a task. This is another special case that is currently not supported by the monitor. =20 +Monitor rts +----------- + +The real-time scheduling monitor validates that tasks with real-time sched= uling +policies (`SCHED_FIFO` and `SCHED_RR`) are always scheduled before tasks w= ith +normal and extensible scheduling policies (`SCHED_OTHER`, `SCHED_BATCH`, +`SCHED_IDLE`, `SCHED_EXT`): + +.. literalinclude:: ../../../tools/verification/models/sched/rts.ltl + +Note that this monitor may report errors if real-time throttling or fair +deadline server is enabled. These mechanisms prevent real-time tasks from +monopolying the CPU by giving tasks with normal and extensible scheduling +policies a chance to run. They give system administrators a chance to kill= a +misbehaved real-time task. However, they violate the scheduling priorities= and +may cause latency to well-behaved real-time tasks. Thus, if you see errors= from +this monitor, consider disabling real-time throttling and the fair deadline +server. + References ---------- =20 diff --git a/kernel/trace/rv/Kconfig b/kernel/trace/rv/Kconfig index 951c2e0cda25..3992ff6ac8b1 100644 --- a/kernel/trace/rv/Kconfig +++ b/kernel/trace/rv/Kconfig @@ -62,6 +62,7 @@ source "kernel/trace/rv/monitors/sts/Kconfig" source "kernel/trace/rv/monitors/nrp/Kconfig" source "kernel/trace/rv/monitors/sssw/Kconfig" source "kernel/trace/rv/monitors/opid/Kconfig" +source "kernel/trace/rv/monitors/rts/Kconfig" # Add new sched monitors here =20 source "kernel/trace/rv/monitors/rtapp/Kconfig" diff --git a/kernel/trace/rv/Makefile b/kernel/trace/rv/Makefile index 750e4ad6fa0f..d7bfc7ae6677 100644 --- a/kernel/trace/rv/Makefile +++ b/kernel/trace/rv/Makefile @@ -17,6 +17,7 @@ obj-$(CONFIG_RV_MON_STS) +=3D monitors/sts/sts.o obj-$(CONFIG_RV_MON_NRP) +=3D monitors/nrp/nrp.o obj-$(CONFIG_RV_MON_SSSW) +=3D monitors/sssw/sssw.o obj-$(CONFIG_RV_MON_OPID) +=3D monitors/opid/opid.o +obj-$(CONFIG_RV_MON_RTS) +=3D monitors/rts/rts.o # Add new monitors here obj-$(CONFIG_RV_REACTORS) +=3D rv_reactors.o obj-$(CONFIG_RV_REACT_PRINTK) +=3D reactor_printk.o diff --git a/kernel/trace/rv/monitors/rts/Kconfig b/kernel/trace/rv/monitor= s/rts/Kconfig new file mode 100644 index 000000000000..1b780bce6133 --- /dev/null +++ b/kernel/trace/rv/monitors/rts/Kconfig @@ -0,0 +1,17 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +config RV_MON_RTS + depends on RV + select RV_LTL_MONITOR + depends on RV_MON_SCHED + default y + select LTL_MON_EVENTS_IMPLICIT + bool "rts monitor" + help + Add support for RTS (real-time scheduling) monitor which validates + that real-time-priority tasks are scheduled before SCHED_OTHER tasks. + + This monitor may report an error if RT throttling or deadline server + is enabled. + + Say Y if you are debugging or testing a real-time system. diff --git a/kernel/trace/rv/monitors/rts/rts.c b/kernel/trace/rv/monitors/= rts/rts.c new file mode 100644 index 000000000000..e23563c47eb1 --- /dev/null +++ b/kernel/trace/rv/monitors/rts/rts.c @@ -0,0 +1,131 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MODULE_NAME "rts" + +#include +#include +#include + +#include "rts.h" +#include + +static DEFINE_PER_CPU(unsigned int, nr_queued); + +static void ltl_atoms_fetch(unsigned int cpu, struct ltl_monitor *mon) +{ +} + +static void ltl_atoms_init(unsigned int cpu, struct ltl_monitor *mon, + bool target_creation) +{ + ltl_atom_set(mon, LTL_SCHED_SWITCH, false); + ltl_atom_set(mon, LTL_SCHED_SWITCH_DL, false); + ltl_atom_set(mon, LTL_SCHED_SWITCH_RT, false); + + /* + * This may not be accurate, there may be enqueued RT tasks. But that's + * okay, the worst we get is a false negative. It will be accurate as + * soon as the CPU no longer has any queued RT task. + */ + ltl_atom_set(mon, LTL_RT_TASK_ENQUEUED, false); +} + +static void handle_enqueue_task_rt(void *data, int cpu, struct task_struct= *task) +{ + unsigned int *queued =3D per_cpu_ptr(&nr_queued, cpu); + + (*queued)++; + ltl_atom_update(cpu, LTL_RT_TASK_ENQUEUED, true); +} + +static void handle_dequeue_task_rt(void *data, int cpu, struct task_struct= *task) +{ + unsigned int *queued =3D per_cpu_ptr(&nr_queued, cpu); + + /* + * This may not be accurate for a short time after the monitor is + * enabled, because there may be enqueued RT tasks which are not counted + * torward nr_queued. But that's okay, the worst we get is a false + * negative. nr_queued will be accurate as soon as the CPU no longer has + * any queued RT task. + */ + if (*queued) + (*queued)--; + if (!*queued) + ltl_atom_update(cpu, LTL_RT_TASK_ENQUEUED, false); +} + +static void handle_sched_switch(void *data, bool preempt, struct task_stru= ct *prev, + struct task_struct *next, unsigned int prev_state) +{ + unsigned int cpu =3D smp_processor_id(); + struct ltl_monitor *mon =3D ltl_get_monitor(cpu); + + ltl_atom_set(mon, LTL_SCHED_SWITCH_RT, rt_task(next)); + ltl_atom_set(mon, LTL_SCHED_SWITCH_DL, dl_task(next)); + ltl_atom_update(cpu, LTL_SCHED_SWITCH, true); + + ltl_atom_set(mon, LTL_SCHED_SWITCH_RT, false); + ltl_atom_set(mon, LTL_SCHED_SWITCH_DL, false); + ltl_atom_update(cpu, LTL_SCHED_SWITCH, false); +} + +static int enable_rts(void) +{ + int retval; + + retval =3D ltl_monitor_init(); + if (retval) + return retval; + + rv_attach_trace_probe("rts", enqueue_task_rt_tp, handle_enqueue_task_rt); + rv_attach_trace_probe("rts", dequeue_task_rt_tp, handle_dequeue_task_rt); + rv_attach_trace_probe("rts", sched_switch, handle_sched_switch); + + return 0; +} + +static void disable_rts(void) +{ + rv_detach_trace_probe("rts", enqueue_task_rt_tp, handle_enqueue_task_rt); + rv_detach_trace_probe("rts", dequeue_task_rt_tp, handle_dequeue_task_rt); + rv_detach_trace_probe("rts", sched_switch, handle_sched_switch); + + ltl_monitor_destroy(); +} + +/* + * This is the monitor register section. + */ +static struct rv_monitor rv_rts =3D { + .name =3D "rts", + .description =3D "Validate that real-time tasks are scheduled before lowe= r-priority tasks", + .enable =3D enable_rts, + .disable =3D disable_rts, +}; + +static int __init register_rts(void) +{ + return rv_register_monitor(&rv_rts, &rv_sched); +} + +static void __exit unregister_rts(void) +{ + rv_unregister_monitor(&rv_rts); +} + +module_init(register_rts); +module_exit(unregister_rts); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Nam Cao "); +MODULE_DESCRIPTION("rts: Validate that real-time tasks are scheduled befor= e lower-priority tasks"); diff --git a/kernel/trace/rv/monitors/rts/rts.h b/kernel/trace/rv/monitors/= rts/rts.h new file mode 100644 index 000000000000..9fbf0d97c1a7 --- /dev/null +++ b/kernel/trace/rv/monitors/rts/rts.h @@ -0,0 +1,126 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * C implementation of Buchi automaton, automatically generated by + * tools/verification/rvgen from the linear temporal logic specification. + * For further information, see kernel documentation: + * Documentation/trace/rv/linear_temporal_logic.rst + */ + +#include + +#define MONITOR_NAME rts + +#define LTL_MONITOR_TYPE LTL_CPU_MONITOR + +enum ltl_atom { + LTL_RT_TASK_ENQUEUED, + LTL_SCHED_SWITCH, + LTL_SCHED_SWITCH_DL, + LTL_SCHED_SWITCH_RT, + LTL_NUM_ATOM +}; +static_assert(LTL_NUM_ATOM <=3D RV_MAX_LTL_ATOM); + +static const char *ltl_atom_str(enum ltl_atom atom) +{ + static const char *const names[] =3D { + "rt_ta_en", + "sc_sw", + "sc_sw_dl", + "sc_sw_rt", + }; + + return names[atom]; +} + +enum ltl_buchi_state { + S0, + S1, + S2, + S3, + S4, + RV_NUM_BA_STATES +}; +static_assert(RV_NUM_BA_STATES <=3D RV_MAX_BA_STATES); + +static void ltl_start(unsigned int cpu, struct ltl_monitor *mon) +{ + bool sched_switch_rt =3D test_bit(LTL_SCHED_SWITCH_RT, mon->atoms); + bool sched_switch_dl =3D test_bit(LTL_SCHED_SWITCH_DL, mon->atoms); + bool sched_switch =3D test_bit(LTL_SCHED_SWITCH, mon->atoms); + bool rt_task_enqueued =3D test_bit(LTL_RT_TASK_ENQUEUED, mon->atoms); + bool val13 =3D !rt_task_enqueued; + bool val8 =3D sched_switch_dl || val13; + bool val9 =3D sched_switch_rt || val8; + bool val6 =3D !sched_switch; + bool val1 =3D !rt_task_enqueued; + + if (val1) + __set_bit(S0, mon->states); + if (val6) + __set_bit(S1, mon->states); + if (val9) + __set_bit(S4, mon->states); +} + +static void +ltl_possible_next_states(struct ltl_monitor *mon, unsigned int state, unsi= gned long *next) +{ + bool sched_switch_rt =3D test_bit(LTL_SCHED_SWITCH_RT, mon->atoms); + bool sched_switch_dl =3D test_bit(LTL_SCHED_SWITCH_DL, mon->atoms); + bool sched_switch =3D test_bit(LTL_SCHED_SWITCH, mon->atoms); + bool rt_task_enqueued =3D test_bit(LTL_RT_TASK_ENQUEUED, mon->atoms); + bool val13 =3D !rt_task_enqueued; + bool val8 =3D sched_switch_dl || val13; + bool val9 =3D sched_switch_rt || val8; + bool val6 =3D !sched_switch; + bool val1 =3D !rt_task_enqueued; + + switch (state) { + case S0: + if (val1) + __set_bit(S0, next); + if (val6) + __set_bit(S1, next); + if (val9) + __set_bit(S4, next); + break; + case S1: + if (val6) + __set_bit(S1, next); + if (val1 && val6) + __set_bit(S2, next); + if (val1 && val9) + __set_bit(S3, next); + if (val9) + __set_bit(S4, next); + break; + case S2: + if (val6) + __set_bit(S1, next); + if (val1 && val6) + __set_bit(S2, next); + if (val1 && val9) + __set_bit(S3, next); + if (val9) + __set_bit(S4, next); + break; + case S3: + if (val1) + __set_bit(S0, next); + if (val6) + __set_bit(S1, next); + if (val9) + __set_bit(S4, next); + break; + case S4: + if (val1) + __set_bit(S0, next); + if (val6) + __set_bit(S1, next); + if (val9) + __set_bit(S4, next); + break; + } +} diff --git a/kernel/trace/rv/monitors/rts/rts_trace.h b/kernel/trace/rv/mon= itors/rts/rts_trace.h new file mode 100644 index 000000000000..0ac9e112a8b0 --- /dev/null +++ b/kernel/trace/rv/monitors/rts/rts_trace.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Snippet to be included in rv_trace.h + */ + +#ifdef CONFIG_RV_MON_RTS +DEFINE_EVENT(event_ltl_monitor, event_rts, + TP_PROTO(unsigned int cpu, char *states, char *atoms, char *next), + TP_ARGS(cpu, states, atoms, next)); + +DEFINE_EVENT(error_ltl_monitor, error_rts, + TP_PROTO(unsigned int cpu), + TP_ARGS(cpu)); +#endif /* CONFIG_RV_MON_RTS */ diff --git a/tools/verification/models/sched/rts.ltl b/tools/verification/m= odels/sched/rts.ltl new file mode 100644 index 000000000000..90872bca46b1 --- /dev/null +++ b/tools/verification/models/sched/rts.ltl @@ -0,0 +1,5 @@ +RULE =3D always (RT_TASK_ENQUEUED imply SCHEDULE_RT_NEXT) + +SCHEDULE_RT_NEXT =3D (not SCHED_SWITCH) until (SCHED_SWITCH_RT or EXCEPTIO= NS) + +EXCEPTIONS =3D SCHED_SWITCH_DL or not RT_TASK_ENQUEUED --=20 2.39.5