summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdmond Chung <edmondchung@google.com>2023-05-04 21:23:03 -0700
committerEdmond Chung <edmondchung@google.com>2023-05-27 03:32:41 +0000
commit23d38ea88e35b77a85f8c940078e0f5df2152dc1 (patch)
treeae8d7960f536a5ad8449a744383222f196ee69fd
parent312e68dac762bd9fda592208bb118e7813352b3a (diff)
downloadlwis-android-gs-bluejay-5.10-u-beta5.3.tar.gz
Also: - Better alignment in log for clarity - Only prints on I2C and IOREG types - Also moved lwis_device_crash_info_dump to lwis_debug so it's close to the functions it's calling Bug: 281077148 Test: Log (cherry picked from https://partner-android-review.googlesource.com/q/commit:e6f146eccddb306ee3363e1ff2e9742835d7ee9f) Merged-In: I16f1e35eb906f81aa773b4a312a8c93a1841c114 Change-Id: I16f1e35eb906f81aa773b4a312a8c93a1841c114
-rw-r--r--lwis_debug.c63
-rw-r--r--lwis_debug.h7
-rw-r--r--lwis_device.c15
-rw-r--r--lwis_device.h7
-rw-r--r--lwis_ioctl.c3
5 files changed, 40 insertions, 55 deletions
diff --git a/lwis_debug.c b/lwis_debug.c
index 8e5927e..f3f9501 100644
--- a/lwis_debug.c
+++ b/lwis_debug.c
@@ -23,7 +23,7 @@
#define PRINT_BUFFER_SIZE 128
/* Printing the log buffer line by line as printk does not work well with large chunks of data */
-static void print_to_log(char *buffer)
+static void print_to_log(struct lwis_device *lwis_dev, char *buffer)
{
int size;
char tmpbuf[PRINT_BUFFER_SIZE + 1];
@@ -36,7 +36,7 @@ static void print_to_log(char *buffer)
}
memcpy(tmpbuf, start, size);
tmpbuf[size] = '\0';
- pr_info("%s", tmpbuf);
+ dev_info(lwis_dev->dev, "%s", tmpbuf);
start = end + 1;
end = strchr(start, '\n');
}
@@ -200,18 +200,10 @@ static int generate_event_states_info(struct lwis_device *lwis_dev, char *buffer
return -EINVAL;
}
+ scnprintf(buffer, buffer_size, "=== LWIS EVENT STATES INFO: %s ===\n", lwis_dev->name);
if (lwis_event_dump_cnt >= 0 && lwis_event_dump_cnt <= EVENT_DEBUG_HISTORY_SIZE) {
- scnprintf(tmp_buf, sizeof(tmp_buf), "=== LWIS DUMP LAST %d Received Events ===\n",
- lwis_event_dump_cnt);
- strlcat(buffer, tmp_buf, buffer_size);
traverse_last_events_size = lwis_event_dump_cnt;
- } else if (lwis_event_dump_cnt > EVENT_DEBUG_HISTORY_SIZE) {
- pr_err("lwis_event_dump_cnt (%d) exceed EVENT_DEBUG_HISTORY_SIZE (%d) \n",
- lwis_event_dump_cnt, EVENT_DEBUG_HISTORY_SIZE);
- return -EINVAL;
} else {
- scnprintf(buffer, buffer_size, "=== LWIS EVENT STATES INFO: %s ===\n",
- lwis_dev->name);
traverse_last_events_size = EVENT_DEBUG_HISTORY_SIZE;
}
@@ -220,9 +212,9 @@ static int generate_event_states_info(struct lwis_device *lwis_dev, char *buffer
strlcat(buffer, " No events being monitored\n", buffer_size);
goto exit;
}
- strlcat(buffer, "Enabled Device Events:\n", buffer_size);
+ strlcat(buffer, "Event Counts:\n", buffer_size);
hash_for_each (lwis_dev->event_states, i, state, node) {
- if (state->enable_counter > 0) {
+ if (state->event_counter > 0) {
scnprintf(tmp_buf, sizeof(tmp_buf), "[%2d] ID: 0x%llx Counter: 0x%llx\n",
idx++, state->event_id, state->event_counter);
strlcat(buffer, tmp_buf, buffer_size);
@@ -230,19 +222,15 @@ static int generate_event_states_info(struct lwis_device *lwis_dev, char *buffer
}
}
if (!enabled_event_present) {
- strlcat(buffer, "No enabled events\n", buffer_size);
- }
- if (lwis_event_dump_cnt < 0) {
- strlcat(buffer, "Last Events:\n", buffer_size);
+ strlcat(buffer, " No enabled events\n", buffer_size);
}
+ strlcat(buffer, "Last Events:\n", buffer_size);
idx = lwis_dev->debug_info.cur_event_hist_idx;
for (i = 0; i < traverse_last_events_size; ++i) {
- if (lwis_event_dump_cnt >= 0) {
- if (idx == 0) {
- idx = EVENT_DEBUG_HISTORY_SIZE;
- }
- idx--;
+ idx--;
+ if (idx < 0) {
+ idx = EVENT_DEBUG_HISTORY_SIZE - 1;
}
state = &lwis_dev->debug_info.event_hist[idx].state;
/* Skip uninitialized entries */
@@ -253,12 +241,6 @@ static int generate_event_states_info(struct lwis_device *lwis_dev, char *buffer
lwis_dev->debug_info.event_hist[idx].timestamp);
strlcat(buffer, tmp_buf, buffer_size);
}
- if (lwis_event_dump_cnt < 0) {
- idx++;
- if (idx >= EVENT_DEBUG_HISTORY_SIZE) {
- idx = 0;
- }
- }
}
exit:
@@ -415,7 +397,7 @@ int lwis_debug_print_register_io_history(struct lwis_device *lwis_dev)
dev_err(lwis_dev->dev, "Failed to generate register io history");
goto exit;
}
- print_to_log(buffer);
+ print_to_log(lwis_dev, buffer);
exit:
kfree(buffer);
@@ -434,7 +416,7 @@ int lwis_debug_print_device_info(struct lwis_device *lwis_dev)
dev_err(lwis_dev->dev, "Failed to generate device info");
return ret;
}
- print_to_log(buffer);
+ print_to_log(lwis_dev, buffer);
return 0;
}
@@ -454,7 +436,7 @@ int lwis_debug_print_event_states_info(struct lwis_device *lwis_dev, int lwis_ev
dev_err(lwis_dev->dev, "Failed to generate event states info");
goto exit;
}
- print_to_log(buffer);
+ print_to_log(lwis_dev, buffer);
exit:
kfree(buffer);
return ret;
@@ -476,7 +458,7 @@ int lwis_debug_print_transaction_info(struct lwis_device *lwis_dev)
dev_err(lwis_dev->dev, "Failed to generate transaction info");
goto exit;
}
- print_to_log(buffer);
+ print_to_log(lwis_dev, buffer);
exit:
kfree(buffer);
return ret;
@@ -498,12 +480,27 @@ int lwis_debug_print_buffer_info(struct lwis_device *lwis_dev)
dev_err(lwis_dev->dev, "Failed to generate buffer info");
goto exit;
}
- print_to_log(buffer);
+ print_to_log(lwis_dev, buffer);
exit:
kfree(buffer);
return ret;
}
+void lwis_debug_crash_info_dump(struct lwis_device *lwis_dev)
+{
+ const int event_dump_count = 5;
+
+ /* State dump is only meaningful for I2C and IOREG devices */
+ if (lwis_dev->type != DEVICE_TYPE_I2C && lwis_dev->type != DEVICE_TYPE_IOREG) {
+ return;
+ }
+
+ dev_info(lwis_dev->dev, "LWIS Device (%s) Crash Info Dump:\n", lwis_dev->name);
+
+ /* Dump event states and last 5 received events */
+ lwis_debug_print_event_states_info(lwis_dev, event_dump_count);
+}
+
/* DebugFS specific functions */
#ifdef CONFIG_DEBUG_FS
diff --git a/lwis_debug.h b/lwis_debug.h
index 85996a3..c2604ba 100644
--- a/lwis_debug.h
+++ b/lwis_debug.h
@@ -17,6 +17,13 @@ int lwis_debug_print_transaction_info(struct lwis_device *lwis_dev);
int lwis_debug_print_register_io_history(struct lwis_device *lwis_dev);
int lwis_debug_print_buffer_info(struct lwis_device *lwis_dev);
+/*
+ * lwis_debug_crash_info_dump:
+ * Use the customized function handle to print information from each device registered in LWIS
+ * when usersapce crash.
+ */
+void lwis_debug_crash_info_dump(struct lwis_device *lwis_dev);
+
/* DebugFS specific functions */
int lwis_device_debugfs_setup(struct lwis_device *lwis_dev, struct dentry *dbg_root);
int lwis_device_debugfs_cleanup(struct lwis_device *lwis_dev); \ No newline at end of file
diff --git a/lwis_device.c b/lwis_device.c
index b4c8a44..1ff65b2 100644
--- a/lwis_device.c
+++ b/lwis_device.c
@@ -250,9 +250,9 @@ static int lwis_release(struct inode *node, struct file *fp)
mutex_lock(&lwis_dev->client_lock);
/* Release power if client closed without power down called */
if (is_client_enabled && lwis_dev->enabled > 0) {
- lwis_device_crash_info_dump(lwis_dev);
lwis_dev->enabled--;
if (lwis_dev->enabled == 0) {
+ lwis_debug_crash_info_dump(lwis_dev);
dev_info(lwis_dev->dev, "No more client, power down\n");
rc = lwis_dev_power_down_locked(lwis_dev);
lwis_dev->is_suspended = false;
@@ -1428,19 +1428,6 @@ void lwis_device_info_dump(const char *name, void (*func)(struct lwis_device *))
mutex_unlock(&core.lock);
}
-void lwis_device_crash_info_dump(struct lwis_device *lwis_dev)
-{
- int dump_cnt = 5;
- int64_t timestamp;
-
- pr_info("LWIS Device (%s) Crash Info Dump:\n", lwis_dev->name);
-
- /* Dump Current kernel timestamp && Last 5 Received Event*/
- timestamp = ktime_to_ns(lwis_get_time());
- dev_info(lwis_dev->dev, " AT %lld Dump Last %d Received Events:\n\n", timestamp, dump_cnt);
- lwis_debug_print_event_states_info(lwis_dev, /*lwis_event_dump_cnt=*/dump_cnt);
-}
-
void lwis_save_register_io_info(struct lwis_device *lwis_dev, struct lwis_io_entry *io_entry,
size_t access_size)
{
diff --git a/lwis_device.h b/lwis_device.h
index 2f30aa5..c011775 100644
--- a/lwis_device.h
+++ b/lwis_device.h
@@ -415,13 +415,6 @@ void lwis_dev_power_seq_list_print(struct lwis_device_power_sequence_list *list)
void lwis_device_info_dump(const char *name, void (*func)(struct lwis_device *));
/*
- * lwis_device_crash_info_dump:
- * Use the customized function handle to print information from each device registered in LWIS
- * when usersapce crash.
- */
-void lwis_device_crash_info_dump(struct lwis_device *lwis_dev);
-
-/*
* lwis_save_register_io_info: Saves the register io info in a history buffer
* for better debugability.
*/
diff --git a/lwis_ioctl.c b/lwis_ioctl.c
index 221dd98..6345fd0 100644
--- a/lwis_ioctl.c
+++ b/lwis_ioctl.c
@@ -20,6 +20,7 @@
#include "lwis_allocator.h"
#include "lwis_buffer.h"
#include "lwis_commands.h"
+#include "lwis_debug.h"
#include "lwis_device.h"
#include "lwis_device_dpm.h"
#include "lwis_device_i2c.h"
@@ -733,7 +734,7 @@ static int cmd_dump_debug_state(struct lwis_client *lwis_client, struct lwis_cmd
mutex_lock(&lwis_dev->client_lock);
/* Dump lwis device crash info */
- lwis_device_crash_info_dump(lwis_dev);
+ lwis_debug_crash_info_dump(lwis_dev);
mutex_unlock(&lwis_dev->client_lock);
header->ret_code = 0;