File: latency.c

package info (click to toggle)
crust-firmware 0.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,900 kB
  • sloc: ansic: 19,341; yacc: 596; lex: 479; makefile: 334; asm: 215; sh: 136; python: 42
file content (28 lines) | stat: -rw-r--r-- 672 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
 * Copyright © 2020-2022 The Crust Firmware Authors.
 * SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-only
 */

#include <counter.h>
#include <debug.h>
#include <division.h>
#include <system.h>

#define ITERATIONS 10000

static uint32_t cycles;
static uint32_t iterations;
static uint8_t  last_state;

void
debug_print_latency(uint8_t current_state)
{
	if (current_state != last_state) {
		cycles     = cycle_counter_read();
		iterations = 0;
		last_state = current_state;
	} else if (iterations < ITERATIONS && ++iterations == ITERATIONS) {
		info("State %u: %u cycles/iteration", current_state,
		     udiv_round(cycle_counter_read() - cycles, ITERATIONS));
	}
}