• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2019 Google LLC. 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 #include "ruy/tune.h"
17 
18 #include <algorithm>
19 #include <cstdint>
20 
21 #include "ruy/cpuinfo.h"
22 
23 namespace ruy {
24 
ResolveNow(CpuInfo * cpuinfo)25 Tuning TuningResolver::ResolveNow(CpuInfo* cpuinfo) {
26   return cpuinfo->CurrentCpuIsA55ish() ? Tuning::kA55ish : Tuning::kGeneric;
27 }
28 
TuningResolver()29 TuningResolver::TuningResolver()
30     : expiry_duration_(DurationFromMilliseconds(250)) {}
31 
Resolve(CpuInfo * cpuinfo)32 Tuning TuningResolver::Resolve(CpuInfo* cpuinfo) {
33   if (unresolved_tuning_ != Tuning::kAuto) {
34     return unresolved_tuning_;
35   }
36   TimePoint new_timepoint = CoarseNow();
37   if (last_resolved_tuning_ != Tuning::kAuto &&
38       (new_timepoint - last_resolved_timepoint_) < expiry_duration_) {
39     return last_resolved_tuning_;
40   }
41   last_resolved_timepoint_ = new_timepoint;
42   last_resolved_tuning_ = ResolveNow(cpuinfo);
43   return last_resolved_tuning_;
44 }
45 
46 }  // namespace ruy
47