All of lore.kernel.org
 help / color / mirror / Atom feed
From: Badhri Jagan Sridharan <badhri@google.com>
To: Guenter Roeck <linux@roeck-us.net>,
	Heikki Krogerus <heikki.krogerus@linux.intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	Kyle Tso <kyletso@google.com>,
	Badhri Jagan Sridharan <badhri@google.com>
Subject: [PATCH v1 2/2] usb: typec: tcpm: Add module parameter to wrap around logs
Date: Mon, 17 May 2021 16:36:09 -0700	[thread overview]
Message-ID: <20210517233609.610248-2-badhri@google.com> (raw)
In-Reply-To: <20210517233609.610248-1-badhri@google.com>

When the buffer is full, TCPM stops logging into the buffer.
This change adds log_wraparound module parameter which when set
flushes out the oldest log entries (FIFO) to make way for the
newer ones.

Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
---
 drivers/usb/typec/tcpm/tcpm.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index b79194919b27..a369decade60 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -38,6 +38,10 @@ static bool modparam_log_misc_dev;
 module_param_named(log_misc_dev, modparam_log_misc_dev, bool, 0444);
 MODULE_PARM_DESC(log_misc_dev, "Expose tcpm logs through misc device");
 
+static bool modparam_log_wraparound;
+module_param_named(log_wraparound, modparam_log_wraparound, bool, 0444);
+MODULE_PARM_DESC(log_wraparound, "Wrap around logs");
+
 #define FOREACH_STATE(S)			\
 	S(INVALID_STATE),			\
 	S(TOGGLING),			\
@@ -597,7 +601,7 @@ static void _tcpm_log(struct tcpm_port *port, const char *fmt, va_list args)
 
 	vsnprintf(tmpbuffer, sizeof(tmpbuffer), fmt, args);
 
-	if (tcpm_log_full(port)) {
+	if (!modparam_log_wraparound && tcpm_log_full(port)) {
 		port->logbuffer_head = max(port->logbuffer_head - 1, 0);
 		strcpy(tmpbuffer, "overflow");
 	}
@@ -621,6 +625,9 @@ static void _tcpm_log(struct tcpm_port *port, const char *fmt, va_list args)
 		  (unsigned long)ts_nsec, rem_nsec / 1000,
 		  tmpbuffer);
 	port->logbuffer_head = (port->logbuffer_head + 1) % LOG_BUFFER_ENTRIES;
+	if (modparam_log_wraparound && port->logbuffer_head == port->logbuffer_tail)
+		port->logbuffer_tail =
+			(port->logbuffer_tail + 1) % LOG_BUFFER_ENTRIES;
 
 abort:
 	mutex_unlock(&port->logbuffer_lock);
@@ -733,7 +740,7 @@ static int tcpm_log_show(struct seq_file *s, void *v)
 		seq_printf(s, "%s\n", port->logbuffer[tail]);
 		tail = (tail + 1) % LOG_BUFFER_ENTRIES;
 	}
-	if (!seq_has_overflowed(s))
+	if (!modparam_log_wraparound && !seq_has_overflowed(s))
 		port->logbuffer_tail = tail;
 	mutex_unlock(&port->logbuffer_lock);
 
-- 
2.31.1.751.gd2f1c929bd-goog


  reply	other threads:[~2021-05-17 23:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-17 23:36 [PATCH v1 1/2] usb: typec: tcpm: Expose tcpm logs through a misc device Badhri Jagan Sridharan
2021-05-17 23:36 ` Badhri Jagan Sridharan [this message]
2021-05-18 13:31   ` [PATCH v1 2/2] usb: typec: tcpm: Add module parameter to wrap around logs Greg Kroah-Hartman
2021-05-18 13:00 ` [PATCH v1 1/2] usb: typec: tcpm: Expose tcpm logs through a misc device Heikki Krogerus
2021-05-18 13:31   ` Greg Kroah-Hartman
2021-05-18 13:32 ` Greg Kroah-Hartman

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=20210517233609.610248-2-badhri@google.com \
    --to=badhri@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=kyletso@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=linux@roeck-us.net \
    /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.