blob: 590975f1ddfb4570871aba9799d4e50795e44108 [file] [log] [blame]
Kshitij Sisodiada2ec062022-04-01 14:43:53 +01001/*
2 * Copyright (c) 2021 Arm Limited. All rights reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21#include "timer_native.h"
22
23#include "log_macros.h"
24
25#include <time.h>
26#include <string.h>
27
28#define MILLISECONDS_IN_SECOND 1000
29#define MICROSECONDS_IN_SECOND 1000000
30#define NANOSECONDS_IN_MILLISECOND 1000000
31#define NANOSECONDS_IN_MICROSECOND 1000
32
33void platform_reset_counters() { /* Nothing to do */ }
34
35pmu_counters platform_get_counters(void)
36{
37 struct timespec current_time;
38 pmu_counters platform_counters = {
39 .num_counters = 0,
40 .initialised = true
41 };
42 clock_gettime(1, &current_time);
43 uint64_t microseconds = (current_time.tv_sec * MICROSECONDS_IN_SECOND) +
44 (current_time.tv_nsec / NANOSECONDS_IN_MICROSECOND);
45
46#if NUM_PMU_COUNTERS > 0
47 platform_counters.counters[0].value = microseconds;
48 platform_counters.counters[0].name = "Duration";
49 platform_counters.counters[0].unit = "microseconds";
50 ++platform_counters.num_counters;
51#endif /* NUM_PMU_COUNTERS > 0 */
52
53 return platform_counters;
54}
55
56#ifdef __cplusplus
57}
58#endif