Kshitij Sisodia | da2ec06 | 2022-04-01 14:43:53 +0100 | [diff] [blame] | 1 | /* |
| 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 |
| 18 | extern "C" { |
| 19 | #endif |
| 20 | |
| 21 | #include "timer_native.h" |
| 22 | |
Kshitij Sisodia | da2ec06 | 2022-04-01 14:43:53 +0100 | [diff] [blame] | 23 | #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 | |
| 31 | void platform_reset_counters() { /* Nothing to do */ } |
| 32 | |
Kshitij Sisodia | 4cc4021 | 2022-04-08 09:54:53 +0100 | [diff] [blame] | 33 | void platform_get_counters(pmu_counters* counters) |
Kshitij Sisodia | da2ec06 | 2022-04-01 14:43:53 +0100 | [diff] [blame] | 34 | { |
| 35 | struct timespec current_time; |
Kshitij Sisodia | 4cc4021 | 2022-04-08 09:54:53 +0100 | [diff] [blame] | 36 | counters->num_counters = 0; |
| 37 | counters->initialised = true; |
Kshitij Sisodia | da2ec06 | 2022-04-01 14:43:53 +0100 | [diff] [blame] | 38 | clock_gettime(1, ¤t_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 Sisodia | 4cc4021 | 2022-04-08 09:54:53 +0100 | [diff] [blame] | 43 | counters->counters[0].value = microseconds; |
| 44 | counters->counters[0].name = "Duration"; |
| 45 | counters->counters[0].unit = "microseconds"; |
| 46 | ++counters->num_counters; |
Kshitij Sisodia | da2ec06 | 2022-04-01 14:43:53 +0100 | [diff] [blame] | 47 | #endif /* NUM_PMU_COUNTERS > 0 */ |
Kshitij Sisodia | da2ec06 | 2022-04-01 14:43:53 +0100 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | #ifdef __cplusplus |
| 51 | } |
| 52 | #endif |