diff options
-rw-r--r-- | android.hardware.thermal@2.0-service.qti-v2.rc | 5 | ||||
-rw-r--r-- | thermalMonitorNetlink.cpp | 21 | ||||
-rw-r--r-- | thermalMonitorNetlink.h | 6 | ||||
-rw-r--r-- | thermalUtilsNetlink.cpp | 45 | ||||
-rw-r--r-- | thermalUtilsNetlink.h | 2 |
5 files changed, 69 insertions, 10 deletions
diff --git a/android.hardware.thermal@2.0-service.qti-v2.rc b/android.hardware.thermal@2.0-service.qti-v2.rc index a1100b6..29d9cbc 100644 --- a/android.hardware.thermal@2.0-service.qti-v2.rc +++ b/android.hardware.thermal@2.0-service.qti-v2.rc @@ -1,4 +1,5 @@ # Copyright (c) 2021, The Linux Foundation. All rights reserved. +# Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are @@ -32,7 +33,3 @@ service android.thermal-hal /vendor/bin/hw/android.hardware.thermal@2.0-service. class hal user root group root - -on boot - wait /sys/kernel/boot_adsp/boot - restart android.thermal-hal diff --git a/thermalMonitorNetlink.cpp b/thermalMonitorNetlink.cpp index b8e7128..f081363 100644 --- a/thermalMonitorNetlink.cpp +++ b/thermalMonitorNetlink.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, The Linux Foundation. All rights reserved. + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -73,11 +74,13 @@ int thermal_family_cb(struct nl_msg *n, void *data) } ThermalMonitor::ThermalMonitor(const eventMonitorCB &inp_event_cb, - const eventMonitorCB &inp_sample_cb): + const eventMonitorCB &inp_sample_cb, + const eventCreateMonitorCB &inp_event_create_cb): event_group(-1), sample_group(-1), event_cb(inp_event_cb), - sample_cb(inp_sample_cb) + sample_cb(inp_sample_cb), + event_create_cb(inp_event_create_cb) { monitor_shutdown = false; } @@ -99,6 +102,7 @@ int ThermalMonitor::event_parse(struct nl_msg *n, void *data) struct genlmsghdr *hdr = genlmsg_hdr(nl_hdr); struct nlattr *attrs[THERMAL_GENL_ATTR_MAX + 1]; int tzn = -1, trip = -1; + const char *tz_name = ""; genlmsg_parse(nl_hdr, 0, attrs, THERMAL_GENL_ATTR_MAX, NULL); @@ -111,10 +115,19 @@ int ThermalMonitor::event_parse(struct nl_msg *n, void *data) if (attrs[THERMAL_GENL_ATTR_TZ_TRIP_ID]) trip = nla_get_u32( attrs[THERMAL_GENL_ATTR_TZ_TRIP_ID]); - LOG(INFO) << "thermal_nl_event: TZ:" << tzn << " Trip:" - << trip << "event:" << hdr->cmd << std::endl; + LOG(DEBUG) << "thermal_nl_event: TZ:" << tzn << " Trip:" + << trip << "event:" << (int)hdr->cmd << std::endl; event_cb(tzn, trip); break; + case THERMAL_GENL_EVENT_TZ_CREATE: + if (attrs[THERMAL_GENL_ATTR_TZ_ID]) + tzn = nla_get_u32(attrs[THERMAL_GENL_ATTR_TZ_ID]); + if (attrs[THERMAL_GENL_ATTR_TZ_NAME]) + tz_name = nla_get_string(attrs[THERMAL_GENL_ATTR_TZ_NAME]); + LOG(DEBUG) << "thermal_nl_event: TZ_CREATE: TZ:" << tzn << " TZ_NAME:" + << tz_name << "event:" << (int)hdr->cmd << std::endl; + event_create_cb(tzn, tz_name); + break; } return 0; diff --git a/thermalMonitorNetlink.h b/thermalMonitorNetlink.h index 7ad87dd..7e42690 100644 --- a/thermalMonitorNetlink.h +++ b/thermalMonitorNetlink.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, The Linux Foundation. All rights reserved. + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -46,11 +47,13 @@ namespace V2_0 { namespace implementation { using eventMonitorCB = std::function<void(int, int)>; +using eventCreateMonitorCB = std::function<void(int, const char *)>; class ThermalMonitor { public: ThermalMonitor(const eventMonitorCB &inp_event_cb, - const eventMonitorCB &inp_sample_cb); + const eventMonitorCB &inp_sample_cb, + const eventCreateMonitorCB &inp_event_create_cb); ~ThermalMonitor(); void parse_and_notify(char *inp_buf, ssize_t len); @@ -68,6 +71,7 @@ class ThermalMonitor { int event_group, sample_group; bool monitor_shutdown; eventMonitorCB event_cb, sample_cb; + eventCreateMonitorCB event_create_cb; int fetch_group_id(); int send_nl_msg(struct nl_msg *msg); diff --git a/thermalUtilsNetlink.cpp b/thermalUtilsNetlink.cpp index b709404..2b340f8 100644 --- a/thermalUtilsNetlink.cpp +++ b/thermalUtilsNetlink.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, The Linux Foundation. All rights reserved. + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -52,6 +53,9 @@ ThermalUtils::ThermalUtils(const ueventCB &inp_cb): std::placeholders::_2), std::bind(&ThermalUtils::sampleParse, this, std::placeholders::_1, + std::placeholders::_2), + std::bind(&ThermalUtils::eventCreateParse, this, + std::placeholders::_1, std::placeholders::_2)), cb(inp_cb) { @@ -72,8 +76,8 @@ ThermalUtils::ThermalUtils(const ueventCB &inp_cb): cmnInst.estimateSeverity(sens); cmnInst.initThreshold(sens); } - monitor.start(); } + monitor.start(); ret = cmnInst.initCdev(); if (ret > 0) { is_cdev_init = true; @@ -121,6 +125,45 @@ void ThermalUtils::sampleParse(int tzn, int temp) return Notify(sens); } +void ThermalUtils::eventCreateParse(int tzn, const char *name) +{ + int ret = 0; + std::vector<struct therm_sensor> sensorList; + std::vector<struct target_therm_cfg> therm_cfg = cfg.fetchConfig(); + std::vector<struct target_therm_cfg>::iterator it_vec; + std::vector<std::string>::iterator it; + + if (isSensorInitialized()) + return; + for (it_vec = therm_cfg.begin(); + it_vec != therm_cfg.end(); it_vec++) { + for (it = it_vec->sensor_list.begin(); + it != it_vec->sensor_list.end(); it++) { + if (!it->compare(name)) + break; + } + if (it != it_vec->sensor_list.end()) + break; + } + if (it_vec == therm_cfg.end()) { + LOG(DEBUG) << "sensor is not monitored:" << tzn + << std::endl; + return; + } + ret = cmnInst.initThermalZones(therm_cfg); + if (ret > 0) { + is_sensor_init = true; + sensorList = cmnInst.fetch_sensor_list(); + std::lock_guard<std::mutex> _lock(sens_cb_mutex); + for (struct therm_sensor sens: sensorList) { + thermalConfig[sens.tzn] = sens; + cmnInst.read_temperature(sens); + cmnInst.estimateSeverity(sens); + cmnInst.initThreshold(sens); + } + } +} + int ThermalUtils::readTemperatures(hidl_vec<Temperature_1_0>& temp) { std::unordered_map<int, struct therm_sensor>::iterator it; diff --git a/thermalUtilsNetlink.h b/thermalUtilsNetlink.h index 7d9abff..dc72f5c 100644 --- a/thermalUtilsNetlink.h +++ b/thermalUtilsNetlink.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, The Linux Foundation. All rights reserved. + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -81,6 +82,7 @@ class ThermalUtils { void eventParse(int tzn, int trip); void sampleParse(int tzn, int temp); + void eventCreateParse(int tzn, const char *name); void Notify(struct therm_sensor& sens); }; |