From bebef42dbd98ee79b01413d2901f0997fe8b69b2 Mon Sep 17 00:00:00 2001 From: Qais Yousef Date: Thu, 21 Dec 2023 19:04:11 +0000 Subject: [PATCH 1/3] init.storage.rc: Set rq_affinity to 2 When rq_affinity is 1, it will default to servicing the softirq on the same CPU that has serviced the interrupt. By setting it to 2, completions are processed by the CPU core that submitted the I/O. Bug: 311655524 Signed-off-by: Qais Yousef Change-Id: I21421f97f069083793fe2e2fa51739dac12eca1d --- storage/init.storage.rc | 1 + 1 file changed, 1 insertion(+) diff --git a/storage/init.storage.rc b/storage/init.storage.rc index 141f8f0..948e820 100644 --- a/storage/init.storage.rc +++ b/storage/init.storage.rc @@ -10,6 +10,7 @@ on default_storage_mode # Block write /dev/sys/block/by-name/rootdisk/queue/iostats 1 write /dev/sys/block/by-name/rootdisk/queue/nr_requests 128 + write /dev/sys/block/by-name/rootdisk/queue/rq_affinity 2 # UFS write /dev/sys/block/bootdevice/clkgate_enable 1 From 40b75d505cf13296b130c7599797a785924080e1 Mon Sep 17 00:00:00 2001 From: Darren Hsu Date: Wed, 20 Dec 2023 20:12:32 +0800 Subject: [PATCH 2/3] powerstats: introduce display MRR state residency data provider Display team introduces new refresh rate residency in kernel. Current display data provider is polling data from state sysfs. To reduce CPU loading and improve efficiency, we should get rid of polling data provider and create new data provider to read data from time_in_state sysfs in PowerStatsHAL. Bug: 316260832 Test: vts-tradefed run vts -m VtsHalPowerStatsTargetTest Change-Id: I4d9886f13207e41f13defd89ea2c19614918a570 Signed-off-by: Darren Hsu --- .../DisplayMrrStateResidencyDataProvider.cpp | 169 ++++++++++++++++++ .../DisplayMrrStateResidencyDataProvider.h | 68 +++++++ 2 files changed, 237 insertions(+) create mode 100644 powerstats/DisplayMrrStateResidencyDataProvider.cpp create mode 100644 powerstats/include/DisplayMrrStateResidencyDataProvider.h diff --git a/powerstats/DisplayMrrStateResidencyDataProvider.cpp b/powerstats/DisplayMrrStateResidencyDataProvider.cpp new file mode 100644 index 0000000..8ab9af4 --- /dev/null +++ b/powerstats/DisplayMrrStateResidencyDataProvider.cpp @@ -0,0 +1,169 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "DisplayMrrStateResidencyDataProvider.h" + +#include +#include +#include + +using android::base::ParseInt; +using android::base::ParseUint; +using android::base::Split; +using android::base::Trim; + +static const std::string TIME_IN_STATE = "time_in_state"; +static const std::string AVAILABLE_STATE = "available_disp_stats"; +static const std::vector DISP_STATE = { "On", "HBM", "LP", "Off" }; + +namespace aidl { +namespace android { +namespace hardware { +namespace power { +namespace stats { + +DisplayMrrStateResidencyDataProvider::DisplayMrrStateResidencyDataProvider( + const std::string& name, const std::string& path) : mName(name), mPath(path) { + mConfigs = std::vector(); + std::string statePath = mPath + AVAILABLE_STATE; + std::unique_ptr fp(fopen(statePath.c_str(), "r"), fclose); + if (fp) { + char *line = nullptr; + size_t len = 0; + Config config = { .state = 0, .resX = 0, .resY = 0, .rr = 0 }; + while (getline(&line, &len, fp.get()) != -1) { + if (parseAvailableState(line, &config)) { + mConfigs.push_back(config); + } else { + PLOG(ERROR) << "Failed to parse display config for [" << std::string(line) + << "] from " << statePath; + mConfigs.clear(); + break; + } + } + free(line); + } else { + PLOG(ERROR) << "Failed to open file " << statePath; + } +} + +bool DisplayMrrStateResidencyDataProvider::parseConfig( + char const *line, Config *config, uint64_t *duration) { + std::vector parts = Split(line, " "); + + if (duration == nullptr) { + if (parts.size() != 4) return false; + } else { + if (parts.size() != 5) return false; + + if (!ParseUint(Trim(parts[4]), duration)) return false; + } + + if (!ParseInt(Trim(parts[0]), &config->state)) return false; + if (!ParseInt(Trim(parts[1]), &config->resX)) return false; + if (!ParseInt(Trim(parts[2]), &config->resY)) return false; + if (!ParseInt(Trim(parts[3]), &config->rr)) return false; + + return true; +} + +bool DisplayMrrStateResidencyDataProvider::parseAvailableState( + char const *line, Config *config) { + return parseConfig(line, config, nullptr); +} + +bool DisplayMrrStateResidencyDataProvider::parseTimeInState( + char const *line, Config *config, uint64_t *duration) { + return parseConfig(line, config, duration); +} + +bool DisplayMrrStateResidencyDataProvider::getStateResidencies( + std::unordered_map> *residencies) { + if (mConfigs.empty()) { + LOG(ERROR) << "Display MRR state list is empty!"; + return false; + } + + std::string path = mPath + TIME_IN_STATE; + std::unique_ptr fp(fopen(path.c_str(), "r"), fclose); + if (!fp) { + PLOG(ERROR) << "Failed to open file " << path; + return false; + } + + std::vector stateResidencies; + for (int i = 0; i < mConfigs.size(); i++) { + StateResidency s = {.id = i, .totalTimeInStateMs = 0}; + stateResidencies.push_back(s); + } + + char *line = nullptr; + size_t len = 0; + Config config = { .state = 0, .resX = 0, .resY = 0, .rr = 0 }; + uint64_t duration; + std::vector::const_iterator found; + while (getline(&line, &len, fp.get()) != -1) { + if (parseTimeInState(line, &config, &duration)) { + found = std::find(mConfigs.begin(), mConfigs.end(), config); + if (found != mConfigs.end()) { + stateResidencies[found - mConfigs.begin()].totalTimeInStateMs = duration; + } else { + LOG(ERROR) << "Failed to find config for [" << std::string(line) + << "] in display MRR state list"; + } + } else { + LOG(ERROR) << "Failed to parse state and duration from [" << std::string(line) << "]"; + free(line); + return false; + } + } + + residencies->emplace(mName, stateResidencies); + + free(line); + + return true; +} + +std::unordered_map> DisplayMrrStateResidencyDataProvider::getInfo() +{ + int32_t dispId; + std::string name; + std::vector states; + for (int32_t id = 0; id < mConfigs.size(); id++) { + dispId = mConfigs[id].state; + if (dispId >= DISP_STATE.size()) { + LOG(ERROR) << "Display state id " << dispId << " is out of bound"; + return {}; + } + + name = DISP_STATE[dispId]; + if (dispId != DISP_STATE.size() - 1) { + name += ": " + std::to_string(mConfigs[id].resX) + + "x" + std::to_string(mConfigs[id].resY) + + "@" + std::to_string(mConfigs[id].rr); + } + State s = { .id = id, .name = name }; + states.push_back(s); + } + + return {{ mName, states }}; +} + +} // namespace stats +} // namespace power +} // namespace hardware +} // namespace android +} // namespace aidl diff --git a/powerstats/include/DisplayMrrStateResidencyDataProvider.h b/powerstats/include/DisplayMrrStateResidencyDataProvider.h new file mode 100644 index 0000000..81ea17e --- /dev/null +++ b/powerstats/include/DisplayMrrStateResidencyDataProvider.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once + +#include + +namespace aidl { +namespace android { +namespace hardware { +namespace power { +namespace stats { + +class DisplayMrrStateResidencyDataProvider : public PowerStats::IStateResidencyDataProvider { + public: + DisplayMrrStateResidencyDataProvider(const std::string& name, const std::string& path); + ~DisplayMrrStateResidencyDataProvider() = default; + + /* + * See IStateResidencyDataProvider::getStateResidencies + */ + bool getStateResidencies( + std::unordered_map> *residencies) override; + + /* + * See IStateResidencyDataProvider::getInfo + */ + std::unordered_map> getInfo() override; + + private: + struct Config { + int32_t state; // Display state (On, HBM, LP, Off) + int32_t resX; // Resolution X + int32_t resY; // Resolution Y + int32_t rr; // Refresh rate + + bool operator==(const Config& r) const { + return state == r.state && resX == r.resX && resY == r.resY && rr == r.rr; + } + }; + + bool parseConfig(char const *line, Config *config, uint64_t *duration); + bool parseAvailableState(char const *line, Config *config); + bool parseTimeInState(char const *line, Config *config, uint64_t *duration); + bool loadAvailableState(); + + const std::string mName; + const std::string mPath; + std::vector mConfigs; +}; + +} // namespace stats +} // namespace power +} // namespace hardware +} // namespace android +} // namespace aidl From e23d5c44d0f21b364e73c107131a3586fad6c754 Mon Sep 17 00:00:00 2001 From: Carter Hsu Date: Fri, 22 Dec 2023 01:35:51 +0000 Subject: [PATCH 3/3] Allow hal_audio_default to access DMA and TPU property 12-19 13:46:27.396000 1041 4222 4222 W gsenet/4949: type=1400 audit(0.0:51): avc: denied { read } for name="u:object_r:vendor_edgetpu_runtime_prop:s0" dev="tmpfs" ino=399 scontext=u:r:hal_audio_default:s0 tcontext=u:object_r:vendor_edgetpu_runtime_prop:s0 tclass=file permissive=0 12-19 13:46:27.396000 1041 4222 4222 I auditd : type=1400 audit(0.0:52): avc: denied { read } for comm="gsenet/4949" name="system" dev="tmpfs" ino=1217 scontext=u:r:hal_audio_default:s0 tcontext=u:object_r:dmabuf_system_heap_device:s0 tclass=chr_file permissive=0 12-19 13:46:27.396000 1041 4222 4222 W gsenet/4949: type=1400 audit(0.0:52): avc: denied { read } for name="system" dev="tmpfs" ino=1217 scontext=u:r:hal_audio_default:s0 tcontext=u:object_r:dmabuf_system_heap_device:s0 tclass=chr_file permissive=0 Bug: 317032803 Test: Verified by test build Change-Id: Ifc2b720615b2ee9b74de163c128962411bbe0d4e Signed-off-by: Carter Hsu --- edgetpu/sepolicy/hal_audio_default.te | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/edgetpu/sepolicy/hal_audio_default.te b/edgetpu/sepolicy/hal_audio_default.te index 2646fcc..523770c 100644 --- a/edgetpu/sepolicy/hal_audio_default.te +++ b/edgetpu/sepolicy/hal_audio_default.te @@ -12,3 +12,7 @@ binder_call(hal_audio_default, edgetpu_app_server) # Allow audio HAL to read tflite Darwinn delegate properties get_prop(hal_audio_default, vendor_tflite_delegate_prop) +get_prop(hal_audio_default, vendor_edgetpu_runtime_prop) + +# Allow DMA Buf access. +allow hal_audio_default dmabuf_system_heap_device:chr_file r_file_perms;