summaryrefslogtreecommitdiff
path: root/common/fpsensor.c
diff options
context:
space:
mode:
authorAseda Aboagye <aaboagye@google.com>2018-08-03 10:42:36 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-08-10 05:08:33 -0700
commita8226e33836ed99dbde26e754e61222ad5a647bd (patch)
tree2b8005388c285658e5c656e49b9ee2af2e5d5c40 /common/fpsensor.c
parent003c9d50b7ff38041dbd3582f386bc886a68dba5 (diff)
downloadchrome-ec-a8226e33836ed99dbde26e754e61222ad5a647bd.tar.gz
fpsensor: Add timing statistics.
This commit adds some basic timing statistics around fingerprint capture, matching, and overall timing for returning a response for a fingerprint. A new host command is added, EC_CMD_FP_STATS, which returns these metrics. Additionally, ectool has been extended with the `fpstats` to command retrieve these metrics. BUG=b:111316382 BRANCH=None TEST=Flash nocturne_fp, perform capture and match, view results using ectool and verify that they are reasonable. Change-Id: Ib675116eebc8131d7b30e721d00eccfdb8905821 Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/1162961 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Nicolas Norvez <norvez@chromium.org>
Diffstat (limited to 'common/fpsensor.c')
-rw-r--r--common/fpsensor.c41
1 files changed, 40 insertions, 1 deletions
diff --git a/common/fpsensor.c b/common/fpsensor.c
index a8a1f00507..10e7fb6369 100644
--- a/common/fpsensor.c
+++ b/common/fpsensor.c
@@ -75,6 +75,14 @@ static uint32_t user_id[FP_CONTEXT_USERID_WORDS];
static uint32_t fp_events;
static uint32_t sensor_mode;
+/* Timing statistics. */
+static uint32_t capture_time_us;
+static uint32_t matching_time_us;
+static uint32_t overall_time_us;
+static timestamp_t overall_t0;
+static uint8_t timestamps_invalid;
+static int8_t template_matched;
+
/* Interrupt line from the fingerprint sensor */
void fps_event(enum gpio_signal signal)
{
@@ -141,28 +149,37 @@ static uint32_t fp_process_enroll(void)
static uint32_t fp_process_match(void)
{
+ timestamp_t t0 = get_time();
int res = -1;
uint32_t updated = 0;
int32_t fgr = -1;
/* match finger against current templates */
+ template_matched = -1;
CPRINTS("Matching/%d ...", templ_valid);
if (templ_valid)
res = fp_finger_match(fp_template[0], templ_valid, fp_buffer,
&fgr, &updated);
CPRINTS("Match =>%d (finger %d)", res, fgr);
- if (res < 0)
+ if (res < 0) {
res = EC_MKBP_FP_ERR_MATCH_NO_INTERNAL;
+ timestamps_invalid |= FPSTATS_MATCHING_INV;
+ } else {
+ template_matched = (int8_t)fgr;
+ }
if (res == EC_MKBP_FP_ERR_MATCH_YES_UPDATED)
templ_dirty |= updated;
+ matching_time_us = time_since32(t0);
return EC_MKBP_FP_MATCH | EC_MKBP_FP_ERRCODE(res)
| ((fgr << EC_MKBP_FP_MATCH_IDX_OFFSET) & EC_MKBP_FP_MATCH_IDX_MASK);
}
static void fp_process_finger(void)
{
+ timestamp_t t0 = get_time();
int res = fp_sensor_acquire_image_with_mode(fp_buffer,
FP_CAPTURE_TYPE(sensor_mode));
+ capture_time_us = time_since32(t0);
if (!res) {
uint32_t evt = EC_MKBP_FP_IMAGE_READY;
@@ -175,10 +192,13 @@ static void fp_process_finger(void)
evt = fp_process_match();
sensor_mode &= ~FP_MODE_ANY_CAPTURE;
+ overall_time_us = time_since32(overall_t0);
send_mkbp_event(evt);
/* go back to lower power mode */
clock_enable_module(MODULE_FAST_CPU, 0);
+ } else {
+ timestamps_invalid |= FPSTATS_CAPTURE_INV;
}
}
#endif /* HAVE_FP_PRIVATE_DRIVER */
@@ -240,6 +260,8 @@ void fp_task(void)
else
fp_sensor_low_power();
} else if (evt & (TASK_EVENT_SENSOR_IRQ | TASK_EVENT_TIMER)) {
+ overall_t0 = get_time();
+ timestamps_invalid = 0;
gpio_disable_interrupt(GPIO_FPS_INT);
if (sensor_mode & FP_MODE_ANY_DETECT_FINGER) {
st = fp_sensor_finger_status();
@@ -412,6 +434,23 @@ static int fp_command_frame(struct host_cmd_handler_args *args)
}
DECLARE_HOST_COMMAND(EC_CMD_FP_FRAME, fp_command_frame, EC_VER_MASK(0));
+static int fp_command_stats(struct host_cmd_handler_args *args)
+{
+ struct ec_response_fp_stats *r = args->response;
+
+ r->capture_time_us = capture_time_us;
+ r->matching_time_us = matching_time_us;
+ r->overall_time_us = overall_time_us;
+ r->overall_t0.lo = overall_t0.le.lo;
+ r->overall_t0.hi = overall_t0.le.hi;
+ r->timestamps_invalid = timestamps_invalid;
+ r->template_matched = template_matched;
+
+ args->response_size = sizeof(struct ec_response_fp_stats);
+ return EC_RES_SUCCESS;
+}
+DECLARE_HOST_COMMAND(EC_CMD_FP_STATS, fp_command_stats, EC_VER_MASK(0));
+
static int fp_command_template(struct host_cmd_handler_args *args)
{
const struct ec_params_fp_template *params = args->params;