[gnome-settings-daemon/rhel/account-and-subman-plugins: 4/23] account: don't poll more frequently than notification period
- From: Ray Strode <halfline src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon/rhel/account-and-subman-plugins: 4/23] account: don't poll more frequently than notification period
- Date: Tue, 13 Apr 2021 14:21:51 +0000 (UTC)
commit 10264ec493b77dffcd7488c96a3bc4d2266b529b
Author: Ray Strode <rstrode redhat com>
Date: Fri Nov 9 10:39:11 2018 -0500
account: don't poll more frequently than notification period
At the moment, if an account has no reason to receive a notification,
the account plugin ends up polling continuously, desperately,
and unsuccessfully trying to find a reason to notify. That leads
to unnecessary CPU utilization.
The reason is an apparent think-o in the code. The code tracks
the last time a notification was shown, so it knows when to show
the next notification later, even if the notification period, or
account policy is updated by the admin in the interim.
The problem is that it's wrong to look at the last notification
time if there's no reason to show a notification. In that case
the wakeup is merely to poll updates on the account policy.
This commit addresses the problem by only looking at the previous
notification time, if it was within the current notification period.
plugins/account/gsd-account-manager.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
---
diff --git a/plugins/account/gsd-account-manager.c b/plugins/account/gsd-account-manager.c
index ff054edd..b48c0fe8 100644
--- a/plugins/account/gsd-account-manager.c
+++ b/plugins/account/gsd-account-manager.c
@@ -234,11 +234,19 @@ queue_periodic_timeout (GsdAccountManager *manager)
}
if (manager->priv->notify_period > 0) {
- gint64 already_elapsed_time;
+ gint64 seconds_since_last_notification;
+ guint seconds_between_notifications;
+ guint seconds_until_next_notification;
- already_elapsed_time = MAX (0, (g_get_monotonic_time () - manager->priv->last_notify_time) /
G_USEC_PER_SEC);
+ seconds_since_last_notification = MAX (0, (g_get_monotonic_time () -
manager->priv->last_notify_time) / G_USEC_PER_SEC);
+ seconds_between_notifications = manager->priv->notify_period * 60;
- manager->priv->notify_period_timeout_id = g_timeout_add_seconds (MAX (0,
manager->priv->notify_period * 60 - already_elapsed_time),
+ if (seconds_since_last_notification > seconds_between_notifications)
+ seconds_until_next_notification = seconds_between_notifications;
+ else
+ seconds_until_next_notification = seconds_between_notifications -
seconds_since_last_notification;
+
+ manager->priv->notify_period_timeout_id = g_timeout_add_seconds
(seconds_until_next_notification,
(GSourceFunc)
on_notify_period_elapsed,
manager);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]