summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2018-02-09 10:59:11 -0800
committerchrome-bot <chrome-bot@chromium.org>2018-02-16 21:41:41 -0800
commit971ef1e03c791e95fe7e1ad8d0ea54da5c4f88d0 (patch)
treea6e3739fcef24e1199d61e0c9a04999d0e693ee3
parent142f511ed172b9fb1f7c378753c06ea136fe572d (diff)
downloadchrome-ec-971ef1e03c791e95fe7e1ad8d0ea54da5c4f88d0.tar.gz
host_command: Count suppressed host commands individually
BUG=chromium:803955 BRANCH=none TEST=Verify counters are printed every hour and before sysjump as follows: [12.540051 HC Suppressed: 0x97=25 0x98=0 0x115=0] Change-Id: I1c1aecf316d233f967f1d2f6ee6c9c16cc59bece Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/912150
-rw-r--r--board/fizz/board.c7
-rw-r--r--board/fizz/board.h3
-rw-r--r--common/host_command.c69
-rw-r--r--include/config.h4
-rw-r--r--include/host_command.h3
5 files changed, 63 insertions, 23 deletions
diff --git a/board/fizz/board.c b/board/fizz/board.c
index cc4450cbcc..212d609f81 100644
--- a/board/fizz/board.c
+++ b/board/fizz/board.c
@@ -54,13 +54,6 @@
#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args)
-uint16_t host_command_suppressed[] = {
- EC_CMD_CONSOLE_SNAPSHOT,
- EC_CMD_CONSOLE_READ,
- EC_CMD_PD_GET_LOG_ENTRY,
- HOST_COMMAND_SUPPRESS_DELIMITER,
-};
-
static void tcpc_alert_event(enum gpio_signal signal)
{
if (!gpio_get_level(GPIO_USB_C0_PD_RST_ODL))
diff --git a/board/fizz/board.h b/board/fizz/board.h
index b9c7b93da6..3ee3e86dd1 100644
--- a/board/fizz/board.h
+++ b/board/fizz/board.h
@@ -29,7 +29,6 @@
#define CONFIG_DPTF
#define CONFIG_FLASH_SIZE 0x80000
#define CONFIG_FPU
-#define CONFIG_SUPPRESS_HOST_COMMANDS
#define CONFIG_I2C
#define CONFIG_I2C_MASTER
#undef CONFIG_LID_SWITCH
@@ -52,6 +51,8 @@
#define CONFIG_THROTTLE_AP
#define CONFIG_CHIPSET_CAN_THROTTLE
#define CONFIG_PWM
+#define CONFIG_SUPPRESSED_HOST_COMMANDS \
+ EC_CMD_CONSOLE_SNAPSHOT, EC_CMD_CONSOLE_READ, EC_CMD_PD_GET_LOG_ENTRY
/* EC console commands */
#define CONFIG_CMD_BUTTON
diff --git a/common/host_command.c b/common/host_command.c
index 3de9c27850..c8d01a3d6f 100644
--- a/common/host_command.c
+++ b/common/host_command.c
@@ -20,6 +20,7 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_HOSTCMD, outstr)
+#define CPRINTF(format, args...) cprintf(CC_HOSTCMD, format, ## args)
#define CPRINTS(format, args...) cprints(CC_HOSTCMD, format, ## args)
#define TASK_EVENT_CMD_PENDING TASK_EVENT_CUSTOM(1)
@@ -78,6 +79,16 @@ static struct host_cmd_handler_args args0;
/* Current host command packet from host, for protocol version 3+ */
static struct host_packet *pkt0;
+/*
+ * Host command suppress
+ */
+#ifdef CONFIG_SUPPRESSED_HOST_COMMANDS
+#define SUPPRESSED_CMD_INTERVAL (60UL * 60 * SECOND)
+static timestamp_t suppressed_cmd_deadline;
+static const uint16_t hc_suppressed_cmd[] = { CONFIG_SUPPRESSED_HOST_COMMANDS };
+static uint32_t hc_suppressed_cnt[ARRAY_SIZE(hc_suppressed_cmd)];
+#endif
+
uint8_t *host_get_memmap(int offset)
{
#ifdef CONFIG_LPC
@@ -413,6 +424,10 @@ static void host_command_init(void)
host_set_single_event(EC_HOST_EVENT_INTERFACE_READY);
HOST_EVENT_CPRINTS("hostcmd init", host_get_events());
#endif
+
+#ifdef CONFIG_SUPPRESSED_HOST_COMMANDS
+ suppressed_cmd_deadline.val = get_time().val + SUPPRESSED_CMD_INTERVAL;
+#endif
}
void host_command_task(void *u)
@@ -560,22 +575,56 @@ DECLARE_HOST_COMMAND(EC_CMD_GET_CMD_VERSIONS,
host_command_get_cmd_versions,
EC_VER_MASK(0) | EC_VER_MASK(1));
-extern uint16_t host_command_suppressed[];
-/* Default suppress list. Define yours in board.c. */
-static uint32_t suppressed_count;
-
static int host_command_is_suppressed(uint16_t cmd)
{
-#ifdef CONFIG_SUPPRESS_HOST_COMMANDS
- uint16_t *p = host_command_suppressed;
- while (*p != HOST_COMMAND_SUPPRESS_DELIMITER) {
- if (*p++ == cmd)
+#ifdef CONFIG_SUPPRESSED_HOST_COMMANDS
+ int i;
+ for (i = 0; i < ARRAY_SIZE(hc_suppressed_cmd); i++) {
+ if (hc_suppressed_cmd[i] == cmd) {
+ hc_suppressed_cnt[i]++;
return 1;
+ }
}
#endif
return 0;
}
+/*
+ * Print & reset suppressed command counters. It should be called periodically
+ * and on important events (e.g. shutdown, sysjump, etc.).
+ */
+static void dump_host_command_suppressed(int force)
+{
+#ifdef CONFIG_SUPPRESSED_HOST_COMMANDS
+ int i;
+
+ if (!force && !timestamp_expired(suppressed_cmd_deadline, NULL))
+ return;
+
+ CPRINTF("[%T HC Suppressed:");
+ for (i = 0; i < ARRAY_SIZE(hc_suppressed_cmd); i++) {
+ CPRINTF(" 0x%x=%d", hc_suppressed_cmd[i], hc_suppressed_cnt[i]);
+ hc_suppressed_cnt[i] = 0;
+ }
+ CPRINTF("]\n");
+ cflush();
+
+ /* Reset the timer */
+ suppressed_cmd_deadline.val = get_time().val + SUPPRESSED_CMD_INTERVAL;
+}
+
+static void dump_host_command_suppressed_(void)
+{
+ dump_host_command_suppressed(1);
+}
+DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN,
+ dump_host_command_suppressed_, HOOK_PRIO_DEFAULT);
+DECLARE_HOOK(HOOK_SYSJUMP,
+ dump_host_command_suppressed_, HOOK_PRIO_DEFAULT);
+#else
+}
+#endif /* CONFIG_SUPPRESSED_HOST_COMMANDS */
+
/**
* Print debug output for the host command request, before it's processed.
*
@@ -595,7 +644,7 @@ static void host_command_debug_request(struct host_cmd_handler_args *args)
if (hcdebug == HCDEBUG_NORMAL) {
uint64_t t = get_time().val;
if (host_command_is_suppressed(args->command)) {
- suppressed_count++;
+ dump_host_command_suppressed(0);
return;
}
if (args->command == hc_prev_cmd &&
@@ -866,7 +915,7 @@ static int command_hcdebug(int argc, char **argv)
ccprintf("Host command debug mode is %s\n",
hcdebug_mode_names[hcdebug]);
- ccprintf("%u suppressed\n", suppressed_count);
+ dump_host_command_suppressed(1);
return EC_SUCCESS;
}
diff --git a/include/config.h b/include/config.h
index a1d197c014..2d7cd658ee 100644
--- a/include/config.h
+++ b/include/config.h
@@ -1637,8 +1637,8 @@
/* Set SKU ID from AP */
#undef CONFIG_HOSTCMD_AP_SET_SKUID
-/* Suppress debug output for commands in host_command_suppressed */
-#undef CONFIG_SUPPRESS_HOST_COMMANDS
+/* List of host commands whose debug output will be suppressed */
+#undef CONFIG_SUPPRESSED_HOST_COMMANDS
/*****************************************************************************/
diff --git a/include/host_command.h b/include/host_command.h
index de99a6894e..f83ffcc616 100644
--- a/include/host_command.h
+++ b/include/host_command.h
@@ -337,7 +337,4 @@ void host_send_sysrq(uint8_t key);
uint32_t get_feature_flags0(void);
uint32_t get_feature_flags1(void);
-/* Used to define the end of host_command_suppressed */
-#define HOST_COMMAND_SUPPRESS_DELIMITER 0xFFFF
-
#endif /* __CROS_EC_HOST_COMMAND_H */