Pull in adaptive fixes/improvements and p-p-d integration

This commit is contained in:
Benjamin Berg 2022-02-09 18:14:40 +01:00
parent 82e1a8aee8
commit 4c12904be4
2 changed files with 648 additions and 0 deletions

646
338.patch Normal file
View File

@ -0,0 +1,646 @@
From 877065bb5d2ba1ee10369ba1febc06ee3a4c07b3 Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Wed, 19 Jan 2022 14:18:14 +0100
Subject: [PATCH 1/7] adaptive: Unref UPower client in destructor
---
src/thd_engine_adaptive.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/thd_engine_adaptive.cpp b/src/thd_engine_adaptive.cpp
index ed04cc7c..256eb4aa 100644
--- a/src/thd_engine_adaptive.cpp
+++ b/src/thd_engine_adaptive.cpp
@@ -89,6 +89,7 @@ class _gddv_exception: public std::exception {
} gddv_exception;
cthd_engine_adaptive::~cthd_engine_adaptive() {
+ g_clear_object (&upower_client);
}
int cthd_engine_adaptive::get_type(char *object, int *offset) {
From 94711ae29223415a75240ed943c5caf418416b12 Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Sun, 6 Feb 2022 18:39:28 +0100
Subject: [PATCH 2/7] adaptive: Improve cleanup of dynamic data sources
Clean them all up from the finalizer. Also add a helper function, and do
the same in case the adaptive engine falls back to a static
configuration.
---
src/thd_engine_adaptive.cpp | 17 ++++++++++++-----
src/thd_engine_adaptive.h | 1 +
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/src/thd_engine_adaptive.cpp b/src/thd_engine_adaptive.cpp
index 256eb4aa..24600c97 100644
--- a/src/thd_engine_adaptive.cpp
+++ b/src/thd_engine_adaptive.cpp
@@ -88,8 +88,18 @@ class _gddv_exception: public std::exception {
}
} gddv_exception;
+void cthd_engine_adaptive::destroy_dynamic_sources() {
+ g_clear_object(&upower_client);
+
+ if (tablet_dev) {
+ close(libevdev_get_fd(tablet_dev));
+ libevdev_free(tablet_dev);
+ tablet_dev = NULL;
+ }
+}
+
cthd_engine_adaptive::~cthd_engine_adaptive() {
- g_clear_object (&upower_client);
+ destroy_dynamic_sources();
}
int cthd_engine_adaptive::get_type(char *object, int *offset) {
@@ -1660,10 +1670,7 @@ int cthd_engine_adaptive::thd_engine_start(bool ignore_cpuid_check, bool adaptiv
thd_log_info("Also unable to evaluate any conditions\n");
thd_log_info("Falling back to use configuration with the highest power\n");
- if (tablet_dev)
- libevdev_free(tablet_dev);
-
- // Looks like there is no free call for up_client_new()
+ destroy_dynamic_sources();
int i = find_agressive_target();
thd_log_info("target:%d\n", i);
diff --git a/src/thd_engine_adaptive.h b/src/thd_engine_adaptive.h
index 043c0d6d..330516c5 100644
--- a/src/thd_engine_adaptive.h
+++ b/src/thd_engine_adaptive.h
@@ -161,6 +161,7 @@ class cthd_engine_adaptive: public cthd_engine_default {
int passive_def_only;
int passive_def_processed;
+ void destroy_dynamic_sources();
int get_type(char *object, int *offset);
uint64_t get_uint64(char *object, int *offset);
char* get_string(char *object, int *offset);
From 5103fe63f7f02754e6667b0a70686577f81e4b9b Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Wed, 19 Jan 2022 14:18:53 +0100
Subject: [PATCH 3/7] adaptive: Implement Power Slider following
power-profiles-deamon
This maps the three power-profiles-daemon states to appropriate values
of the power slider DPTF control.
Note that thermald already has the "preference" setting which can be set
to either "PERFORMANCE" or "ENERGY_CONSERVE". As such, an alternative
could be to expand the list of valid preferences and then let p-p-d set
the value via dbus.
---
src/thd_engine_adaptive.cpp | 56 ++++++++++++++++++++++++++++++++++---
src/thd_engine_adaptive.h | 6 +++-
2 files changed, 57 insertions(+), 5 deletions(-)
diff --git a/src/thd_engine_adaptive.cpp b/src/thd_engine_adaptive.cpp
index 24600c97..4d0fd6b2 100644
--- a/src/thd_engine_adaptive.cpp
+++ b/src/thd_engine_adaptive.cpp
@@ -1042,10 +1042,7 @@ int cthd_engine_adaptive::evaluate_platform_type_condition(
int cthd_engine_adaptive::evaluate_power_slider_condition(
struct condition condition) {
- // We don't have a power slider currently, just set it to 75 which
- // equals "Better Performance" (using 100 would be more aggressive).
-
- return compare_condition(condition, 75);
+ return compare_condition(condition, power_slider);
}
int cthd_engine_adaptive::evaluate_ac_condition(struct condition condition) {
@@ -1569,7 +1566,36 @@ void cthd_engine_adaptive::setup_input_devices() {
}
}
+void cthd_engine_adaptive::update_power_slider()
+{
+ g_autoptr(GVariant) active_profile_v = NULL;
+
+ active_profile_v = g_dbus_proxy_get_cached_property (power_profiles_daemon, "ActiveProfile");
+ if (active_profile_v && g_variant_is_of_type (active_profile_v, G_VARIANT_TYPE_STRING)) {
+ const char *active_profile = g_variant_get_string (active_profile_v, NULL);
+
+ if (strcmp (active_profile, "power-saver") == 0)
+ power_slider = 25; /* battery saver */
+ else if (strcmp (active_profile, "balanced") == 0)
+ power_slider = 75; /* better performance */
+ else if (strcmp (active_profile, "performance") == 0)
+ power_slider = 100; /* best performance */
+ else
+ power_slider = 75;
+ } else {
+ power_slider = 75;
+ }
+
+ thd_log_info("Power slider is now set to %d\n", power_slider);
+}
+
+static void power_profiles_changed_cb(cthd_engine_adaptive *engine)
+{
+ engine->update_power_slider();
+}
+
int cthd_engine_adaptive::thd_engine_start(bool ignore_cpuid_check, bool adaptive) {
+ g_autoptr(GDBusConnection) bus = NULL;
char *buf;
csys_fs sysfs("");
size_t size;
@@ -1686,6 +1712,28 @@ int cthd_engine_adaptive::thd_engine_start(bool ignore_cpuid_check, bool adaptiv
set_control_mode(EXCLUSIVE);
+ bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL);
+ if (bus) {
+ power_profiles_daemon = g_dbus_proxy_new_sync (bus,
+ G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
+ NULL,
+ "net.hadess.PowerProfiles",
+ "/net/hadess/PowerProfiles",
+ "net.hadess.PowerProfiles",
+ NULL,
+ NULL);
+
+ if (power_profiles_daemon) {
+ g_signal_connect_swapped (power_profiles_daemon,
+ "g-properties-changed",
+ (GCallback) power_profiles_changed_cb,
+ this);
+ power_profiles_changed_cb(this);
+ } else {
+ thd_log_info("Could not setup DBus watch for power-profiles-daemon");
+ }
+ }
+
evaluate_conditions();
thd_log_info("adaptive engine reached end");
diff --git a/src/thd_engine_adaptive.h b/src/thd_engine_adaptive.h
index 330516c5..bfd6c868 100644
--- a/src/thd_engine_adaptive.h
+++ b/src/thd_engine_adaptive.h
@@ -153,6 +153,7 @@ class cthd_engine_adaptive: public cthd_engine_default {
std::vector<struct psvt> psvts;
std::string int3400_path;
UpClient *upower_client;
+ GDBusProxy *power_profiles_daemon;
struct libevdev *tablet_dev;
int current_condition_set;
int policy_active;
@@ -161,6 +162,8 @@ class cthd_engine_adaptive: public cthd_engine_default {
int passive_def_only;
int passive_def_processed;
+ int power_slider;
+
void destroy_dynamic_sources();
int get_type(char *object, int *offset);
uint64_t get_uint64(char *object, int *offset);
@@ -210,13 +213,14 @@ class cthd_engine_adaptive: public cthd_engine_default {
cthd_engine_default("63BE270F-1C11-48FD-A6F7-3AF253FF3E2D"), upower_client(
NULL), tablet_dev(NULL), current_condition_set(0xffff), policy_active(
0), fallback_id(-1), int3400_base_path(""), passive_def_only(
- 0), passive_def_processed(0) {
+ 0), passive_def_processed(0), power_slider(75) {
}
~cthd_engine_adaptive();
ppcc_t* get_ppcc_param(std::string name);
int thd_engine_start(bool ignore_cpuid_check, bool adaptive);
void update_engine_state();
+ void update_power_slider();
};
int thd_engine_create_adaptive_engine(bool ignore_cpuid_check);
From 86eddff7845ccd4f87b084a0e572d050b33053e0 Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Sun, 6 Feb 2022 18:25:10 +0100
Subject: [PATCH 4/7] engine: Split start into init/start to load sensors
earlier
The adaptive engine needs to have the sensors loaded early on in order
to verify conditions. To make sure this works well, split the start
function into two parts, the first being init and the second being
start.
For adaptive, the start function still does some verification, as the
upower availability is important for the lid state (it should switch to
reading the lid state directly though).
---
src/thd_engine.cpp | 52 +++++++++++++++++++++----------------
src/thd_engine.h | 3 ++-
src/thd_engine_adaptive.cpp | 41 ++++++++++++++++++++++-------
src/thd_engine_adaptive.h | 3 ++-
src/thd_engine_default.cpp | 10 ++++++-
5 files changed, 73 insertions(+), 36 deletions(-)
diff --git a/src/thd_engine.cpp b/src/thd_engine.cpp
index 67308a26..b5289975 100644
--- a/src/thd_engine.cpp
+++ b/src/thd_engine.cpp
@@ -174,9 +174,8 @@ bool cthd_engine::set_preference(const int pref) {
return true;
}
-int cthd_engine::thd_engine_start(bool ignore_cpuid_check, bool adaptive) {
+int cthd_engine::thd_engine_init(bool ignore_cpuid_check, bool adaptive) {
int ret;
- int wake_fds[2];
adaptive_mode = adaptive;
@@ -196,6 +195,34 @@ int cthd_engine::thd_engine_start(bool ignore_cpuid_check, bool adaptive) {
}
}
+ ret = read_thermal_sensors();
+ if (ret != THD_SUCCESS) {
+ thd_log_error("Thermal sysfs Error in reading sensors\n");
+ // This is a fatal error and daemon will exit
+ return THD_FATAL_ERROR;
+ }
+
+ ret = read_cooling_devices();
+ if (ret != THD_SUCCESS) {
+ thd_log_error("Thermal sysfs Error in reading cooling devs\n");
+ // This is a fatal error and daemon will exit
+ return THD_FATAL_ERROR;
+ }
+
+ ret = read_thermal_zones();
+ if (ret != THD_SUCCESS) {
+ thd_log_error("No thermal sensors found\n");
+ // This is a fatal error and daemon will exit
+ return THD_FATAL_ERROR;
+ }
+
+ return THD_SUCCESS;
+}
+
+int cthd_engine::thd_engine_start() {
+ int ret;
+ int wake_fds[2];
+
check_for_rt_kernel();
// Pipe is used for communication between two processes
@@ -228,27 +255,6 @@ int cthd_engine::thd_engine_start(bool ignore_cpuid_check, bool adaptive) {
poll_timeout_msec = poll_interval_sec * 1000;
}
- ret = read_thermal_sensors();
- if (ret != THD_SUCCESS) {
- thd_log_error("Thermal sysfs Error in reading sensors\n");
- // This is a fatal error and daemon will exit
- return THD_FATAL_ERROR;
- }
-
- ret = read_cooling_devices();
- if (ret != THD_SUCCESS) {
- thd_log_error("Thermal sysfs Error in reading cooling devs\n");
- // This is a fatal error and daemon will exit
- return THD_FATAL_ERROR;
- }
-
- ret = read_thermal_zones();
- if (ret != THD_SUCCESS) {
- thd_log_error("No thermal sensors found\n");
- // This is a fatal error and daemon will exit
- return THD_FATAL_ERROR;
- }
-
if (parser.platform_matched()) {
parser.set_default_preference();
int poll_secs = parser.get_polling_interval();
diff --git a/src/thd_engine.h b/src/thd_engine.h
index 4200450b..697ff40a 100644
--- a/src/thd_engine.h
+++ b/src/thd_engine.h
@@ -148,7 +148,8 @@ class cthd_engine {
return control_mode;
}
void thd_engine_thread();
- virtual int thd_engine_start(bool ignore_cpuid_check, bool adaptive = false);
+ virtual int thd_engine_init(bool ignore_cpuid_check, bool adaptive = false);
+ virtual int thd_engine_start();
int thd_engine_stop();
int check_cpu_id();
diff --git a/src/thd_engine_adaptive.cpp b/src/thd_engine_adaptive.cpp
index 4d0fd6b2..232dcd47 100644
--- a/src/thd_engine_adaptive.cpp
+++ b/src/thd_engine_adaptive.cpp
@@ -1594,11 +1594,14 @@ static void power_profiles_changed_cb(cthd_engine_adaptive *engine)
engine->update_power_slider();
}
-int cthd_engine_adaptive::thd_engine_start(bool ignore_cpuid_check, bool adaptive) {
- g_autoptr(GDBusConnection) bus = NULL;
- char *buf;
+int cthd_engine_adaptive::thd_engine_init(bool ignore_cpuid_check, bool adaptive) {
csys_fs sysfs("");
+ char *buf;
size_t size;
+ int res;
+
+ parser_disabled = true;
+ force_mmio_rapl = true;
if (!ignore_cpuid_check) {
check_cpu_id();
@@ -1613,9 +1616,6 @@ int cthd_engine_adaptive::thd_engine_start(bool ignore_cpuid_check, bool adaptiv
return THD_ERROR;
}
- parser_disabled = true;
- force_mmio_rapl = true;
-
if (sysfs.exists("/sys/bus/platform/devices/INT3400:00")) {
int3400_base_path = "/sys/bus/platform/devices/INT3400:00/";
} else if (sysfs.exists("/sys/bus/platform/devices/INTC1040:00")) {
@@ -1626,6 +1626,12 @@ int cthd_engine_adaptive::thd_engine_start(bool ignore_cpuid_check, bool adaptiv
return THD_ERROR;
}
+ /* Read the sensors/zones */
+ res = cthd_engine::thd_engine_init(ignore_cpuid_check, adaptive);
+ if (res != THD_SUCCESS)
+ return res;
+
+
if (sysfs.read(int3400_base_path + "firmware_node/path",
int3400_path) < 0) {
thd_log_debug("Unable to locate INT3400 firmware path\n");
@@ -1664,6 +1670,8 @@ int cthd_engine_adaptive::thd_engine_start(bool ignore_cpuid_check, bool adaptiv
dump_psvt();
dump_apat();
dump_apct();
+
+ delete [] buf;
} catch (std::exception &e) {
thd_log_warn("%s\n", e.what());
delete [] buf;
@@ -1679,9 +1687,18 @@ int cthd_engine_adaptive::thd_engine_start(bool ignore_cpuid_check, bool adaptiv
thd_log_info("IETM.D0 found\n");
passive_def_only = 1;
}
- return cthd_engine::thd_engine_start(ignore_cpuid_check);
+ return THD_SUCCESS;
}
+ return THD_SUCCESS;
+}
+
+int cthd_engine_adaptive::thd_engine_start() {
+ g_autoptr(GDBusConnection) bus = NULL;
+
+ if (passive_def_only)
+ return cthd_engine::thd_engine_start();
+
setup_input_devices();
upower_client = up_client_new();
@@ -1704,7 +1721,6 @@ int cthd_engine_adaptive::thd_engine_start(bool ignore_cpuid_check, bool adaptiv
thd_log_info("fallback id:%d\n", i);
fallback_id = i;
} else {
- delete[] buf;
return THD_ERROR;
}
}
@@ -1737,7 +1753,7 @@ int cthd_engine_adaptive::thd_engine_start(bool ignore_cpuid_check, bool adaptiv
evaluate_conditions();
thd_log_info("adaptive engine reached end");
- return cthd_engine::thd_engine_start(ignore_cpuid_check, adaptive);
+ return cthd_engine::thd_engine_start();
}
int thd_engine_create_adaptive_engine(bool ignore_cpuid_check) {
@@ -1746,7 +1762,12 @@ int thd_engine_create_adaptive_engine(bool ignore_cpuid_check) {
thd_engine->set_poll_interval(thd_poll_interval);
// Initialize thermald objects
- if (thd_engine->thd_engine_start(ignore_cpuid_check, true) != THD_SUCCESS) {
+ if (thd_engine->thd_engine_init(ignore_cpuid_check, true) != THD_SUCCESS) {
+ thd_log_info("THD engine init failed\n");
+ return THD_ERROR;
+ }
+
+ if (thd_engine->thd_engine_start() != THD_SUCCESS) {
thd_log_info("THD engine start failed\n");
return THD_ERROR;
}
diff --git a/src/thd_engine_adaptive.h b/src/thd_engine_adaptive.h
index bfd6c868..d044698d 100644
--- a/src/thd_engine_adaptive.h
+++ b/src/thd_engine_adaptive.h
@@ -218,7 +218,8 @@ class cthd_engine_adaptive: public cthd_engine_default {
~cthd_engine_adaptive();
ppcc_t* get_ppcc_param(std::string name);
- int thd_engine_start(bool ignore_cpuid_check, bool adaptive);
+ int thd_engine_init(bool ignore_cpuid_check, bool adaptive);
+ int thd_engine_start();
void update_engine_state();
void update_power_slider();
};
diff --git a/src/thd_engine_default.cpp b/src/thd_engine_default.cpp
index 2db78505..18635c50 100644
--- a/src/thd_engine_default.cpp
+++ b/src/thd_engine_default.cpp
@@ -838,7 +838,15 @@ int thd_engine_create_default_engine(bool ignore_cpuid_check,
if (conf_file)
thd_engine->set_config_file(conf_file);
- res = thd_engine->thd_engine_start(ignore_cpuid_check);
+ res = thd_engine->thd_engine_init(ignore_cpuid_check);
+ if (res != THD_SUCCESS) {
+ if (res == THD_FATAL_ERROR)
+ thd_log_error("THD engine init failed\n");
+ else
+ thd_log_msg("THD engine init failed\n");
+ }
+
+ res = thd_engine->thd_engine_start();
if (res != THD_SUCCESS) {
if (res == THD_FATAL_ERROR)
thd_log_error("THD engine start failed\n");
From ecdbdb5039dd7f016918f8d734a11670ea062bf7 Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Sun, 6 Feb 2022 19:24:57 +0100
Subject: [PATCH 5/7] adaptive: Open event FD non-blocking and with CLOEXEC
This makes more sense, and it is what libevdev expects by default.
---
src/thd_engine_adaptive.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/thd_engine_adaptive.cpp b/src/thd_engine_adaptive.cpp
index 232dcd47..c546b61e 100644
--- a/src/thd_engine_adaptive.cpp
+++ b/src/thd_engine_adaptive.cpp
@@ -1550,7 +1550,7 @@ void cthd_engine_adaptive::setup_input_devices() {
int fd = -1;
snprintf(fname, sizeof(fname), "/dev/input/%s", namelist[i]->d_name);
- fd = open(fname, O_RDONLY);
+ fd = open(fname, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
if (fd < 0)
continue;
ret = libevdev_new_from_fd(fd, &tablet_dev);
From 9d01731a28f97a6581e6bbe3dc675e140d5336ea Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Sun, 6 Feb 2022 19:25:44 +0100
Subject: [PATCH 6/7] adaptive: Process evdev events for tablet mode
Otherwise the switch will never change, as libevdev will just return the
latest cached value.
---
src/thd_engine_adaptive.cpp | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/thd_engine_adaptive.cpp b/src/thd_engine_adaptive.cpp
index c546b61e..da6a2e60 100644
--- a/src/thd_engine_adaptive.cpp
+++ b/src/thd_engine_adaptive.cpp
@@ -1031,6 +1031,11 @@ int cthd_engine_adaptive::evaluate_platform_type_condition(
int value = 1;
if (tablet_dev) {
+ struct input_event ev;
+
+ while (libevdev_has_event_pending(tablet_dev))
+ libevdev_next_event(tablet_dev, LIBEVDEV_READ_FLAG_NORMAL, &ev);
+
int tablet = libevdev_get_event_value(tablet_dev, EV_SW,
SW_TABLET_MODE);
if (tablet)
From 93c7d2783b28a4b5ec5ca5071881547b5ee65da3 Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Sun, 6 Feb 2022 19:26:38 +0100
Subject: [PATCH 7/7] adaptive: Read the lid state directly from the kernel
The UPower interface for the lid state is deprecated. As such, we should
be reading it directly from the input device. Making the switch is
straight forward, so just do it.
---
src/thd_engine_adaptive.cpp | 43 ++++++++++++++++++++++++++-----------
src/thd_engine_adaptive.h | 1 +
2 files changed, 32 insertions(+), 12 deletions(-)
diff --git a/src/thd_engine_adaptive.cpp b/src/thd_engine_adaptive.cpp
index da6a2e60..3e8b3674 100644
--- a/src/thd_engine_adaptive.cpp
+++ b/src/thd_engine_adaptive.cpp
@@ -94,8 +94,18 @@ void cthd_engine_adaptive::destroy_dynamic_sources() {
if (tablet_dev) {
close(libevdev_get_fd(tablet_dev));
libevdev_free(tablet_dev);
+
+ if (lid_dev == tablet_dev)
+ lid_dev = NULL;
tablet_dev = NULL;
}
+
+ if (lid_dev) {
+ close(libevdev_get_fd(lid_dev));
+ libevdev_free(lid_dev);
+
+ lid_dev = NULL;
+ }
}
cthd_engine_adaptive::~cthd_engine_adaptive() {
@@ -848,7 +858,7 @@ int cthd_engine_adaptive::verify_condition(struct condition condition) {
|| condition.condition == (adaptive_condition) 0) {
return 0;
}
- if (condition.condition == Lid_state && upower_client != NULL)
+ if (condition.condition == Lid_state && lid_dev != NULL)
return 0;
if (condition.condition == Power_source && upower_client != NULL)
return 0;
@@ -1010,11 +1020,16 @@ int cthd_engine_adaptive::evaluate_temperature_condition(
int cthd_engine_adaptive::evaluate_lid_condition(struct condition condition) {
int value = 0;
- bool lid_closed = up_client_get_lid_is_closed(upower_client);
- if (!lid_closed)
- value = 1;
+ if (lid_dev) {
+ struct input_event ev;
+ while (libevdev_has_event_pending(lid_dev))
+ libevdev_next_event(lid_dev, LIBEVDEV_READ_FLAG_NORMAL, &ev);
+
+ int lid_closed = libevdev_get_event_value(lid_dev, EV_SW, SW_LID);
+ value = !lid_closed;
+ }
return compare_condition(condition, value);
}
@@ -1547,10 +1562,9 @@ void cthd_engine_adaptive::setup_input_devices() {
struct dirent **namelist;
int i, ndev, ret;
- tablet_dev = NULL;
-
ndev = scandir("/dev/input", &namelist, is_event_device, versionsort);
for (i = 0; i < ndev; i++) {
+ struct libevdev *dev = NULL;
char fname[267];
int fd = -1;
@@ -1558,16 +1572,21 @@ void cthd_engine_adaptive::setup_input_devices() {
fd = open(fname, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
if (fd < 0)
continue;
- ret = libevdev_new_from_fd(fd, &tablet_dev);
+ ret = libevdev_new_from_fd(fd, &dev);
if (ret) {
close(fd);
continue;
}
- if (libevdev_has_event_code(tablet_dev, EV_SW, SW_TABLET_MODE))
- return;
- libevdev_free(tablet_dev);
- tablet_dev = NULL;
- close(fd);
+
+ if (!tablet_dev && libevdev_has_event_code(dev, EV_SW, SW_TABLET_MODE))
+ tablet_dev = dev;
+ if (!lid_dev && libevdev_has_event_code(dev, EV_SW, SW_LID))
+ lid_dev = dev;
+
+ if (lid_dev != dev && tablet_dev != dev) {
+ libevdev_free(dev);
+ close(fd);
+ }
}
}
diff --git a/src/thd_engine_adaptive.h b/src/thd_engine_adaptive.h
index d044698d..fb55aa4e 100644
--- a/src/thd_engine_adaptive.h
+++ b/src/thd_engine_adaptive.h
@@ -155,6 +155,7 @@ class cthd_engine_adaptive: public cthd_engine_default {
UpClient *upower_client;
GDBusProxy *power_profiles_daemon;
struct libevdev *tablet_dev;
+ struct libevdev *lid_dev;
int current_condition_set;
int policy_active;
int fallback_id;

View File

@ -37,6 +37,8 @@ Requires(pre): shadow-utils
%{?systemd_requires}
# Pull in adaptive fixes/improvements and p-p-d integration
Patch0001: https://github.com/intel/thermal_daemon/pull/338.patch
%description
%{name} monitors and controls platform temperature.