blob: 7cd832c729ea8f90eed866d2a116c819117dc51e [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
Kshitij Sisodia4cc40212022-04-08 09:54:53 +010035void platform_get_counters(pmu_counters* counters)
Kshitij Sisodiada2ec062022-04-01 14:43:53 +010036{
37 struct timespec current_time;
Kshitij Sisodia4cc40212022-04-08 09:54:53 +010038 counters->num_counters = 0;
39 counters->initialised = true;
Kshitij Sisodiada2ec062022-04-01 14:43:53 +010040 clock_gettime(1, &current_time);
41 uint64_t microseconds = (current_time.tv_sec * MICROSECONDS_IN_SECOND) +
42 (current_time.tv_nsec / NANOSECONDS_IN_MICROSECOND);
43
44#if NUM_PMU_COUNTERS > 0
Kshitij Sisodia4cc40212022-04-08 09:54:53 +010045 counters->counters[0].value = microseconds;
46 counters->counters[0].name = "Duration";
47 counters->counters[0].unit = "microseconds";
48 ++counters->num_counters;
Kshitij Sisodiada2ec062022-04-01 14:43:53 +010049#endif /* NUM_PMU_COUNTERS > 0 */
Kshitij Sisodiada2ec062022-04-01 14:43:53 +010050}
51
52#ifdef __cplusplus
53}
54#endif