• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_CORE_PLATFORM_PROFILE_UTILS_ANDROID_ARMV7A_CPU_UTILS_HELPER_H_
17 #define TENSORFLOW_CORE_PLATFORM_PROFILE_UTILS_ANDROID_ARMV7A_CPU_UTILS_HELPER_H_
18 
19 #include <sys/types.h>
20 
21 #include "tensorflow/core/platform/macros.h"
22 #include "tensorflow/core/platform/profile_utils/i_cpu_utils_helper.h"
23 #include "tensorflow/core/platform/types.h"
24 
25 #if defined(__ANDROID__) && (__ANDROID_API__ >= 21) && \
26     (defined(__ARM_ARCH_7A__) || defined(__aarch64__))
27 
28 struct perf_event_attr;
29 
30 namespace tensorflow {
31 namespace profile_utils {
32 
33 // Implementation of CpuUtilsHelper for Android armv7a
34 class AndroidArmV7ACpuUtilsHelper : public ICpuUtilsHelper {
35  public:
36   AndroidArmV7ACpuUtilsHelper() = default;
37   void ResetClockCycle() final;
38   uint64 GetCurrentClockCycle() final;
39   void EnableClockCycleProfiling(bool enable) final;
40   int64 CalculateCpuFrequency() final;
41 
42  private:
43   static constexpr int INVALID_FD = -1;
44   static constexpr int64 INVALID_CPU_FREQUENCY = -1;
45 
46   void InitializeInternal();
47 
48   // syscall __NR_perf_event_open with arguments
49   int OpenPerfEvent(perf_event_attr *const hw_event, const pid_t pid,
50                     const int cpu, const int group_fd,
51                     const unsigned long flags);
52 
53   int64 ReadCpuFrequencyFile(const int cpu_id, const char *const type);
54 
55   bool is_initialized_{false};
56   int fd_{INVALID_FD};
57 
58   TF_DISALLOW_COPY_AND_ASSIGN(AndroidArmV7ACpuUtilsHelper);
59 };
60 
61 }  // namespace profile_utils
62 }  // namespace tensorflow
63 
64 #endif  // defined(__ANDROID__) && (__ANDROID_API__ >= 21) &&
65         // (defined(__ARM_ARCH_7A__) || defined(__aarch64__))
66 
67 #endif  // TENSORFLOW_CORE_PLATFORM_PROFILE_UTILS_ANDROID_ARMV7A_CPU_UTILS_HELPER_H_
68