xref: /aosp_15_r20/external/executorch/runtime/platform/clock.h (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 /**
10  * @file
11  * Clock and timing related methods.
12  */
13 
14 #pragma once
15 
16 #include <executorch/runtime/platform/platform.h>
17 
18 namespace executorch {
19 namespace runtime {
20 
21 /**
22  * Convert an interval from units of system ticks to nanoseconds.
23  * The conversion ratio is platform-dependent, and thus depends on
24  * the platform implementation of et_pal_ticks_to_ns_multiplier().
25  *
26  * @param[in] ticks The interval length in system ticks.
27  * @retval The interval length in nanoseconds.
28  */
ticks_to_ns(et_timestamp_t ticks)29 inline uint64_t ticks_to_ns(et_timestamp_t ticks) {
30   et_tick_ratio_t ratio = et_pal_ticks_to_ns_multiplier();
31   return static_cast<uint64_t>(ticks) * ratio.numerator / ratio.denominator;
32 }
33 
34 } // namespace runtime
35 } // namespace executorch
36 
37 namespace torch {
38 namespace executor {
39 // TODO(T197294990): Remove these deprecated aliases once all users have moved
40 // to the new `::executorch` namespaces.
41 using ::executorch::runtime::ticks_to_ns;
42 } // namespace executor
43 } // namespace torch
44