summaryrefstree
path: root/kernel/drivers/vision/dsp/dsp-time.c
blob: 5c4fd46daa240939780d05be97888d9a6daaa1ec (plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// SPDX-License-Identifier: GPL-2.0
/*
 * Samsung Exynos SoC series dsp driver
 *
 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
 *              http://www.samsung.com/
 */

#include "dsp-log.h"
#include "dsp-time.h"

void dsp_time_get_timestamp(struct dsp_time *time, int opt)
{
	dsp_enter();
	if (opt == TIMESTAMP_START)
		getrawmonotonic(&time->start);
	else if (opt == TIMESTAMP_END)
		getrawmonotonic(&time->end);
	else
		dsp_warn("time opt is invaild(%d)\n", opt);
	dsp_leave();
}

void dsp_time_get_interval(struct dsp_time *time)
{
	time->interval = timespec_sub(time->end, time->start);
}

void dsp_time_print(struct dsp_time *time, const char *f, ...)
{
	char buf[128];
	va_list args;
	int len;

	dsp_enter();
	dsp_time_get_interval(time);

	va_start(args, f);
	len = vsnprintf(buf, sizeof(buf), f, args);
	va_end(args);

	if (len > 0)
		dsp_info("[%5lu.%06lu ms] %s\n",
				time->interval.tv_sec * 1000UL +
				time->interval.tv_nsec / 1000000UL,
				(time->interval.tv_nsec % 1000000UL),
				buf);
	else
		dsp_info("[%5lu.%06lu ms] INVALID\n",
				time->interval.tv_sec * 1000UL +
				time->interval.tv_nsec / 1000000UL,
				(time->interval.tv_nsec % 1000000UL));
	dsp_leave();
}