summaryrefslogtreecommitdiff
path: root/battery_mitigation/include
diff options
context:
space:
mode:
Diffstat (limited to 'battery_mitigation/include')
-rw-r--r--battery_mitigation/include/battery_mitigation/BatteryMitigation.h45
-rw-r--r--battery_mitigation/include/battery_mitigation/BatteryMitigationService.h172
-rw-r--r--battery_mitigation/include/battery_mitigation/MitigationConfig.h97
-rw-r--r--battery_mitigation/include/battery_mitigation/MitigationThermalManager.h121
-rw-r--r--battery_mitigation/include/battery_mitigation/uapi/brownout_stats.h27
5 files changed, 0 insertions, 462 deletions
diff --git a/battery_mitigation/include/battery_mitigation/BatteryMitigation.h b/battery_mitigation/include/battery_mitigation/BatteryMitigation.h
deleted file mode 100644
index de22b9af..00000000
--- a/battery_mitigation/include/battery_mitigation/BatteryMitigation.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (C) 2022 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 <utils/RefBase.h>
-
-#include "MitigationThermalManager.h"
-
-namespace android {
-namespace hardware {
-namespace google {
-namespace pixel {
-
-using ::android::sp;
-
-class BatteryMitigation : public RefBase {
- public:
- BatteryMitigation(const struct MitigationConfig::Config &cfg);
- bool isMitigationLogTimeValid(std::chrono::system_clock::time_point startTime,
- const char *const logFilePath, const char *const timestampFormat,
- const std::regex pattern);
-
- private:
- MitigationThermalManager *mThermalMgr;
-};
-
-} // namespace pixel
-} // namespace google
-} // namespace hardware
-} // namespace android
diff --git a/battery_mitigation/include/battery_mitigation/BatteryMitigationService.h b/battery_mitigation/include/battery_mitigation/BatteryMitigationService.h
deleted file mode 100644
index 9c697140..00000000
--- a/battery_mitigation/include/battery_mitigation/BatteryMitigationService.h
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * 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 <android-base/chrono_utils.h>
-#include <android-base/file.h>
-#include <android-base/logging.h>
-#include <android-base/parseint.h>
-#include <android-base/properties.h>
-#include <android-base/strings.h>
-#include <errno.h>
-#include <sys/epoll.h>
-#include <sys/eventfd.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <sys/system_properties.h>
-#include <unistd.h>
-#include <utils/RefBase.h>
-
-#include <algorithm>
-#include <cmath>
-#include <map>
-#include <regex>
-#include <thread>
-
-#include "MitigationConfig.h"
-
-#define MIN_SUPPORTED_PLATFORM 2 /* CDT */
-#define MAX_SUPPORTED_PLATFORM 5
-#define NSEC_PER_SEC 1000000000L
-#define BROWNOUT_EVENT_BUF_SIZE 10
-#define DUMP_TIMES 12
-#define EPOLL_MAXEVENTS 12
-#define BUF_SIZE 128
-#define FVP_STATS_SIZE 4096
-#define STAT_NAME_SIZE 48
-#define STATS_MAX_SIZE 64
-#define PMIC_NUM 2
-#define LOOP_TRIG_STATS(idx) for (int idx = 0; idx < MAX_EVENT; idx++)
-
-namespace android {
-namespace hardware {
-namespace google {
-namespace pixel {
-
-using ::android::sp;
-using android::hardware::google::pixel::MitigationConfig;
-
-struct numericStat {
- char name[STAT_NAME_SIZE];
- int value;
-};
-
-struct OdpmInstantPower {
- struct timespec time;
- double value;
-};
-
-struct BrownoutStatsCSVFields {
- const char *const triggered_time;
- const char *const triggered_idx;
- const char *const battery_soc;
- const char *const battery_temp;
- const char *const battery_cycle;
- const char *const voltage_now;
- const char *const current_now;
- const char *const cpu0_freq;
- const char *const cpu1_freq;
- const char *const cpu2_freq;
- const char *const gpu_freq;
- const char *const tpu_freq;
- const char *const aur_freq;
- const char *const odpm_prefix;
-};
-
-struct BrownoutStatsCSVRow {
- struct timespec triggered_time;
- int triggered_idx;
- int min_battery_soc;
- int max_battery_temp;
- int min_battery_cycle;
- int min_voltage_now;
- int max_current_now;
- int min_cpu0_freq;
- int min_cpu1_freq;
- int min_cpu2_freq;
- int min_gpu_freq;
- int min_tpu_freq;
- int min_aur_freq;
-
- double max_main_odpm_instant_power[METER_CHANNEL_MAX];
- double max_sub_odpm_instant_power[METER_CHANNEL_MAX];
-};
-
-struct BrownoutStatsExtend {
- struct brownout_stats brownoutStats;
- char fvpStats[FVP_STATS_SIZE];
- struct numericStat numericStats[STATS_MAX_SIZE];
- timeval eventReceivedTime;
- timeval dumpTime;
- unsigned int eventIdx;
-};
-
-class BatteryMitigationService : public RefBase {
- public:
- BatteryMitigationService(const struct MitigationConfig::EventThreadConfig &eventThreadCfg);
- ~BatteryMitigationService();
-
- void startBrownoutEventThread();
- void stopEventThread(std::atomic_bool &thread_stop, int wakeup_event_fd,
- std::thread &event_thread);
- bool isBrownoutStatsBinarySupported();
- bool isPlatformSupported();
- bool isTimeValid(const char*, std::chrono::system_clock::time_point);
- bool genParsedMeal(const char*);
- bool genLastmealCSV(const char*);
- private:
- struct MitigationConfig::EventThreadConfig cfg;
-
- int storingFd;
- int triggeredStateFd[MAX_EVENT];
- int triggeredStateEpollFd;
- int triggeredStateWakeupEventFd;
- std::thread eventThread;
- std::atomic_bool triggerThreadStop{false};
- int brownoutStatsFd;
- int triggeredIdxFd;
- int triggeredIdxEpollFd;
- int wakeupEventFd;
- std::thread brownoutEventThread;
- std::atomic_bool threadStop{false};
-
- int mainPmicID;
- int subPmicID;
- double mainLpfBitResolutions[METER_CHANNEL_MAX];
- double subLpfBitResolutions[METER_CHANNEL_MAX];
- char *mainLpfChannelNames[METER_CHANNEL_MAX];
- char *subLpfChannelNames[METER_CHANNEL_MAX];
- std::vector<MitigationConfig::numericSysfs> totalNumericSysfsStatPaths;
-
- void BrownoutEventThread();
- void TriggerEventThread();
- void initTotalNumericSysfsPaths();
- void initPmicRelated();
- int initFd();
- int initTrigFd();
- void tearDownBrownoutEventThread();
- void tearDownTriggerEventThread();
- int readNumericStats(struct BrownoutStatsExtend*);
- bool parseBrownoutStatsExtend(FILE *);
- void printBrownoutStatsExtendSummary(FILE *, struct BrownoutStatsExtend *);
- void getBrownoutStatsCSVRow(struct BrownoutStatsExtend *, struct BrownoutStatsCSVRow *);
-};
-
-} // namespace pixel
-} // namespace google
-} // namespace hardware
-} // namespace android
diff --git a/battery_mitigation/include/battery_mitigation/MitigationConfig.h b/battery_mitigation/include/battery_mitigation/MitigationConfig.h
deleted file mode 100644
index 2062d29d..00000000
--- a/battery_mitigation/include/battery_mitigation/MitigationConfig.h
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright (C) 2022 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.
- */
-
-#ifndef HARDWARE_GOOGLE_PIXEL_BATTERY_MITIGATION_CONFIG_H
-#define HARDWARE_GOOGLE_PIXEL_BATTERY_MITIGATION_CONFIG_H
-
-#include "uapi/brownout_stats.h"
-
-namespace android {
-namespace hardware {
-namespace google {
-namespace pixel {
-
-enum TriggeredEvent {
- UVLO1,
- UVLO2,
- OILO1,
- OILO2,
- SMPL,
- MAX_EVENT,
-};
-
-class MitigationConfig {
- public:
- struct Config {
- const std::vector<std::string> SystemPath;
- const std::vector<std::string> FilteredZones;
- const std::vector<std::string> SystemName;
- const char *const LogFilePath;
- const char *const TimestampFormat;
- };
-
- struct numericSysfs {
- std::string name;
- std::string path;
- };
-
- struct numericSysfsList {
- std::string name;
- std::vector<std::string> paths;
- };
-
- struct platformSpecific {
- const std::vector<numericSysfsList> NumericSysfsStatPaths;
- const std::vector<numericSysfsList> NumericSysfsStatDirs;
- };
-
- struct pmicCommon {
- const char *const OdpmDir;
- const char *const OdpmEnabledRailsPath;
- const char *const PmicNamePath;
- };
-
- struct EventThreadConfig {
- const std::vector<numericSysfs> NumericSysfsStatPaths;
- const std::vector<numericSysfs> NumericSysfsStatDirs;
- const char *const TriggeredIdxPath;
- const char *const triggeredStatePath[MAX_EVENT];
- const char *const BrownoutStatsPath;
- const char *const StoringPath;
- const char *const ParsedThismealPath;
- const char *const ParsedLastmealPath;
- const char *const ParsedLastmealCSVPath;
- const char *const FvpStatsPath;
- const std::vector<pmicCommon> PmicCommon;
- const platformSpecific PlatformSpecific;
- };
-
- MitigationConfig(const struct Config &cfg);
-
- private:
- const std::vector<std::string> kSystemPath;
- const std::vector<std::string> kFilteredZones;
- const std::vector<std::string> kSystemName;
- const char *const kLogFilePath;
- const char *const kTimestampFormat;
-};
-
-} // namespace pixel
-} // namespace google
-} // namespace hardware
-} // namespace android
-
-#endif // HARDWARE_GOOGLE_PIXEL_BATTERY_MITIGATION_CONFIG_H
diff --git a/battery_mitigation/include/battery_mitigation/MitigationThermalManager.h b/battery_mitigation/include/battery_mitigation/MitigationThermalManager.h
deleted file mode 100644
index 5b5a3f0a..00000000
--- a/battery_mitigation/include/battery_mitigation/MitigationThermalManager.h
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright (C) 2022 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
-
-#ifndef MITIGATION_THERMAL_MANAGER_H_
-#define MITIGATION_THERMAL_MANAGER_H_
-
-#include <aidl/android/hardware/thermal/BnThermalChangedCallback.h>
-#include <aidl/android/hardware/thermal/IThermal.h>
-#include <android-base/chrono_utils.h>
-#include <android-base/file.h>
-#include <android-base/logging.h>
-#include <android-base/parseint.h>
-#include <android-base/properties.h>
-#include <android-base/strings.h>
-#include <android/binder_auto_utils.h>
-#include <unistd.h>
-#include <utils/Mutex.h>
-
-#include <fstream>
-#include <iostream>
-#include <regex>
-
-#include "MitigationConfig.h"
-
-namespace android {
-namespace hardware {
-namespace google {
-namespace pixel {
-
-using ::aidl::android::hardware::thermal::BnThermalChangedCallback;
-using ::aidl::android::hardware::thermal::IThermal;
-using ::aidl::android::hardware::thermal::Temperature;
-using ::aidl::android::hardware::thermal::TemperatureType;
-using ::aidl::android::hardware::thermal::ThrottlingSeverity;
-using android::hardware::google::pixel::MitigationConfig;
-
-class MitigationThermalManager {
- public:
- static MitigationThermalManager &getInstance();
-
- // delete copy and move constructors and assign operators
- MitigationThermalManager(MitigationThermalManager const &) = delete;
- MitigationThermalManager(MitigationThermalManager &&) = delete;
- MitigationThermalManager &operator=(MitigationThermalManager const &) = delete;
- MitigationThermalManager &operator=(MitigationThermalManager &&) = delete;
-
- private:
- // ThermalCallback implements the HIDL thermal changed callback
- // interface, IThermalChangedCallback.
- void thermalCb(const Temperature &temperature);
- android::base::boot_clock::time_point lastCapturedTime;
-
- class ThermalCallback : public BnThermalChangedCallback {
- public:
- ThermalCallback(std::function<void(const Temperature &)> notify_function)
- : notifyFunction(notify_function) {}
-
- // Callback function. thermal service will call this.
- ndk::ScopedAStatus notifyThrottling(const Temperature &temperature) override {
- if ((temperature.type == TemperatureType::BCL_VOLTAGE) ||
- (temperature.type == TemperatureType::BCL_CURRENT)) {
- notifyFunction(temperature);
- }
- return ndk::ScopedAStatus::ok();
- }
-
- private:
- std::function<void(const Temperature &)> notifyFunction;
- };
-
- static void onThermalAidlBinderDied(void *) {
- LOG(ERROR) << "Thermal AIDL service died, trying to reconnect";
- MitigationThermalManager::getInstance().connectThermalHal();
- }
-
- public:
- MitigationThermalManager();
- ~MitigationThermalManager();
- bool connectThermalHal();
- bool isMitigationTemperature(const Temperature &temperature);
- bool registerCallback();
- void remove();
- void updateConfig(const struct MitigationConfig::Config &cfg);
-
-
- private:
- std::mutex thermal_callback_mutex_;
- std::mutex thermal_hal_mutex_;
- // Thermal hal interface.
- std::shared_ptr<IThermal> thermal;
- // Thermal hal callback object.
- std::shared_ptr<ThermalCallback> callback;
- // Receiver when AIDL thermal hal restart.
- ndk::ScopedAIBinder_DeathRecipient aidlDeathRecipient;
- std::vector<std::string> kSystemPath;
- std::vector<std::string> kFilteredZones;
- std::vector<std::string> kSystemName;
- std::string kLogFilePath;
- std::string kTimestampFormat;
-};
-
-} // namespace pixel
-} // namespace google
-} // namespace hardware
-} // namespace android
-#endif
diff --git a/battery_mitigation/include/battery_mitigation/uapi/brownout_stats.h b/battery_mitigation/include/battery_mitigation/uapi/brownout_stats.h
deleted file mode 100644
index c913e40b..00000000
--- a/battery_mitigation/include/battery_mitigation/uapi/brownout_stats.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-
-#ifndef __BROWNOUT_STATS_H
-#define __BROWNOUT_STATS_H
-
-#define METER_CHANNEL_MAX 12
-#define DATA_LOGGING_LEN 20
-#define TRIGGERED_SOURCE_MAX 17
-
-struct odpm_instant_data {
- struct timespec time;
- unsigned int value[METER_CHANNEL_MAX];
-};
-
-/* Notice: sysfs only allocates a buffer of PAGE_SIZE
- * so the sizeof brownout_stats should be smaller than that
- */
-struct brownout_stats {
- struct timespec triggered_time;
- unsigned int triggered_idx;
-
- struct odpm_instant_data main_odpm_instant_data[DATA_LOGGING_LEN];
- struct odpm_instant_data sub_odpm_instant_data[DATA_LOGGING_LEN];
- unsigned int triggered_state[DATA_LOGGING_LEN];
-};
-
-#endif /* __BROWNOUT_STATS_H */