blob: ae5b4973bf542f796137de53a70823fadfbe7e1a [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
Kshitij Sisodiada2ec062022-04-01 14:43:53 +010023#include <time.h>
24#include <string.h>
25
26#define MILLISECONDS_IN_SECOND 1000
27#define MICROSECONDS_IN_SECOND 1000000
28#define NANOSECONDS_IN_MILLISECOND 1000000
29#define NANOSECONDS_IN_MICROSECOND 1000
30
31void platform_reset_counters() { /* Nothing to do */ }
32
Kshitij Sisodia4cc40212022-04-08 09:54:53 +010033void platform_get_counters(pmu_counters* counters)
Kshitij Sisodiada2ec062022-04-01 14:43:53 +010034{
35 struct timespec current_time;
Kshitij Sisodia4cc40212022-04-08 09:54:53 +010036 counters->num_counters = 0;
37 counters->initialised = true;
Kshitij Sisodiada2ec062022-04-01 14:43:53 +010038 clock_gettime(1, &current_time);
39 uint64_t microseconds = (current_time.tv_sec * MICROSECONDS_IN_SECOND) +
40 (current_time.tv_nsec / NANOSECONDS_IN_MICROSECOND);
41
42#if NUM_PMU_COUNTERS > 0
Kshitij Sisodia4cc40212022-04-08 09:54:53 +010043 counters->counters[0].value = microseconds;
44 counters->counters[0].name = "Duration";
45 counters->counters[0].unit = "microseconds";
46 ++counters->num_counters;
Kshitij Sisodiada2ec062022-04-01 14:43:53 +010047#endif /* NUM_PMU_COUNTERS > 0 */
Kshitij Sisodiada2ec062022-04-01 14:43:53 +010048}
49
50#ifdef __cplusplus
51}
52#endif