1*ec779b8eSAndroid Build Coastguard Worker /* 2*ec779b8eSAndroid Build Coastguard Worker * Copyright (C) 2014 The Android Open Source Project 3*ec779b8eSAndroid Build Coastguard Worker * 4*ec779b8eSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*ec779b8eSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*ec779b8eSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*ec779b8eSAndroid Build Coastguard Worker * 8*ec779b8eSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*ec779b8eSAndroid Build Coastguard Worker * 10*ec779b8eSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*ec779b8eSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*ec779b8eSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*ec779b8eSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*ec779b8eSAndroid Build Coastguard Worker * limitations under the License. 15*ec779b8eSAndroid Build Coastguard Worker */ 16*ec779b8eSAndroid Build Coastguard Worker 17*ec779b8eSAndroid Build Coastguard Worker #pragma once 18*ec779b8eSAndroid Build Coastguard Worker 19*ec779b8eSAndroid Build Coastguard Worker #include <type_traits> 20*ec779b8eSAndroid Build Coastguard Worker 21*ec779b8eSAndroid Build Coastguard Worker #include "Configuration.h" 22*ec779b8eSAndroid Build Coastguard Worker #include "FastThreadState.h" 23*ec779b8eSAndroid Build Coastguard Worker 24*ec779b8eSAndroid Build Coastguard Worker namespace android { 25*ec779b8eSAndroid Build Coastguard Worker 26*ec779b8eSAndroid Build Coastguard Worker // The FastThreadDumpState keeps a cache of FastThread statistics that can be logged by dumpsys. 27*ec779b8eSAndroid Build Coastguard Worker // Each individual native word-sized field is accessed atomically. But the 28*ec779b8eSAndroid Build Coastguard Worker // overall structure is non-atomic, that is there may be an inconsistency between fields. 29*ec779b8eSAndroid Build Coastguard Worker // No barriers or locks are used for either writing or reading. 30*ec779b8eSAndroid Build Coastguard Worker // Only POD types are permitted, and the contents shouldn't be trusted (i.e. do range checks). 31*ec779b8eSAndroid Build Coastguard Worker // It has a different lifetime than the FastThread, and so it can't be a member of FastThread. 32*ec779b8eSAndroid Build Coastguard Worker struct FastThreadDumpState { 33*ec779b8eSAndroid Build Coastguard Worker FastThreadDumpState(); 34*ec779b8eSAndroid Build Coastguard Worker 35*ec779b8eSAndroid Build Coastguard Worker FastThreadState::Command mCommand = FastThreadState::INITIAL; // current command 36*ec779b8eSAndroid Build Coastguard Worker uint32_t mUnderruns = 0; // total number of underruns 37*ec779b8eSAndroid Build Coastguard Worker uint32_t mOverruns = 0; // total number of overruns 38*ec779b8eSAndroid Build Coastguard Worker struct timespec mMeasuredWarmupTs{}; // measured warmup time 39*ec779b8eSAndroid Build Coastguard Worker uint32_t mWarmupCycles = 0; // number of loop cycles required to warmup 40*ec779b8eSAndroid Build Coastguard Worker 41*ec779b8eSAndroid Build Coastguard Worker #ifdef FAST_THREAD_STATISTICS 42*ec779b8eSAndroid Build Coastguard Worker // Recently collected samples of per-cycle monotonic time, thread CPU time, and CPU frequency. 43*ec779b8eSAndroid Build Coastguard Worker // kSamplingN is max size of sampling frame (statistics), and must be a power of 2 <= 0x8000. 44*ec779b8eSAndroid Build Coastguard Worker // The sample arrays are virtually allocated based on this compile-time constant, 45*ec779b8eSAndroid Build Coastguard Worker // but are only initialized and used based on the runtime parameter mSamplingN. 46*ec779b8eSAndroid Build Coastguard Worker static const uint32_t kSamplingN = 0x8000; 47*ec779b8eSAndroid Build Coastguard Worker // Compile-time constant for a "low RAM device", must be a power of 2 <= kSamplingN. 48*ec779b8eSAndroid Build Coastguard Worker // This value was chosen such that each array uses 1 small page (4 Kbytes). 49*ec779b8eSAndroid Build Coastguard Worker static const uint32_t kSamplingNforLowRamDevice = 0x400; 50*ec779b8eSAndroid Build Coastguard Worker // Corresponding runtime maximum size of sample arrays, must be a power of 2 <= kSamplingN. 51*ec779b8eSAndroid Build Coastguard Worker uint32_t mSamplingN = 0; 52*ec779b8eSAndroid Build Coastguard Worker // The bounds define the interval of valid samples, and are represented as follows: 53*ec779b8eSAndroid Build Coastguard Worker // newest open (excluded) endpoint = lower 16 bits of bounds, modulo N 54*ec779b8eSAndroid Build Coastguard Worker // oldest closed (included) endpoint = upper 16 bits of bounds, modulo N 55*ec779b8eSAndroid Build Coastguard Worker // Number of valid samples is newest - oldest. 56*ec779b8eSAndroid Build Coastguard Worker uint32_t mBounds = 0; // bounds for mMonotonicNs, mThreadCpuNs, and mCpukHz 57*ec779b8eSAndroid Build Coastguard Worker // The elements in the *Ns arrays are in units of nanoseconds <= 3999999999. 58*ec779b8eSAndroid Build Coastguard Worker uint32_t mMonotonicNs[kSamplingN]; // delta monotonic (wall clock) time 59*ec779b8eSAndroid Build Coastguard Worker uint32_t mLoadNs[kSamplingN]; // delta CPU load in time 60*ec779b8eSAndroid Build Coastguard Worker #ifdef CPU_FREQUENCY_STATISTICS 61*ec779b8eSAndroid Build Coastguard Worker uint32_t mCpukHz[kSamplingN]; // absolute CPU clock frequency in kHz, bits 0-3 are CPU# 62*ec779b8eSAndroid Build Coastguard Worker #endif 63*ec779b8eSAndroid Build Coastguard Worker 64*ec779b8eSAndroid Build Coastguard Worker // Increase sampling window after construction, must be a power of 2 <= kSamplingN 65*ec779b8eSAndroid Build Coastguard Worker void increaseSamplingN(uint32_t samplingN); 66*ec779b8eSAndroid Build Coastguard Worker #endif 67*ec779b8eSAndroid Build Coastguard Worker 68*ec779b8eSAndroid Build Coastguard Worker }; // struct FastThreadDumpState 69*ec779b8eSAndroid Build Coastguard Worker 70*ec779b8eSAndroid Build Coastguard Worker // No virtuals. 71*ec779b8eSAndroid Build Coastguard Worker static_assert(!std::is_polymorphic_v<FastThreadDumpState>); 72*ec779b8eSAndroid Build Coastguard Worker 73*ec779b8eSAndroid Build Coastguard Worker } // namespace android 74