From: John Sperbeck <jsperbeck@google.com>
To: Petr Mladek <pmladek@suse.com>
Cc: Steven Rostedt <rostedt@goodmis.org>,
John Ogness <john.ogness@linutronix.de>,
linux-kernel@vger.kernel.org,
John Sperbeck <jsperbeck@google.com>
Subject: [PATCH] kernel: count warnings and make count accessible to userspace
Date: Tue, 18 Jan 2022 06:04:31 +0000 [thread overview]
Message-ID: <20220118060431.1368538-1-jsperbeck@google.com> (raw)
When testing, it's common to consider a warning to be a test failure,
but it's currently awkward to determine which of multiple sequential
tests is responsible for triggering a warning. Scraping dmesg or
/var/log/messages is somewhat expensive and error-prone. Setting
panic_on_warn is reliable, but spoils test runs for minor issues.
Looking at the taint bit is also reliable, but only works for a single
warning.
We can track the warning count and expose it as a sysfs file. Test
infrastructures can snapshot the value before and after a test. If
the value changes, they can do more expensive things like extracting
logs.
Signed-off-by: John Sperbeck <jsperbeck@google.com>
---
kernel/panic.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/kernel/panic.c b/kernel/panic.c
index cefd7d82366f..5262c2a0ebf4 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -571,6 +571,8 @@ struct warn_args {
va_list args;
};
+static atomic_t __maybe_unused warn_counter;
+
void __warn(const char *file, int line, void *caller, unsigned taint,
struct pt_regs *regs, struct warn_args *args)
{
@@ -612,6 +614,8 @@ void __warn(const char *file, int line, void *caller, unsigned taint,
/* Just a warning, don't kill lockdep. */
add_taint(taint, LOCKDEP_STILL_OK);
+
+ atomic_inc(&warn_counter);
}
#ifndef __WARN_FLAGS
@@ -667,6 +671,7 @@ static __init int register_warn_debugfs(void)
/* Don't care about failure */
debugfs_create_file_unsafe("clear_warn_once", 0200, NULL, NULL,
&clear_warn_once_fops);
+ debugfs_create_atomic_t("warn_count", 0444, NULL, &warn_counter);
return 0;
}
--
2.34.1.703.g22d0c6ccf7-goog
next reply other threads:[~2022-01-18 6:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-18 6:04 John Sperbeck [this message]
2022-01-19 12:01 ` Petr Mladek
2022-01-22 20:58 ` John Sperbeck
2022-01-25 8:52 ` Petr Mladek
2022-01-27 0:23 ` John Sperbeck
2022-02-11 10:34 ` Petr Mladek
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=20220118060431.1368538-1-jsperbeck@google.com \
--to=jsperbeck@google.com \
--cc=john.ogness@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.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
Powered by JetHome