Message ID | 20210517233609.610248-2-badhri@google.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v1,1/2] usb: typec: tcpm: Expose tcpm logs through a misc device | expand |
On Mon, May 17, 2021 at 04:36:09PM -0700, Badhri Jagan Sridharan wrote: > 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"); Again, no, this we know better than to add new module parameters, this is not ok. greg k-h
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);
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(-)