Re: Powersaving Patch for NetworkManager



Hi Dan,

I added a simple wrapper for g_timeout_add_seconds.


Jan Kantert

Dan Williams schrieb:
On Tue, 2008-11-25 at 13:38 +0100, Jan Kantert wrote:
Hi,

according to powertop Network Manager wakes up my cpu about once every
two seconds. Thats does not sound much but on an idle desktop with 10
wake ups per seconds thats 5%. I wanted my laptop's cpu to stay longer
in sleepstates so I wrote a little patch (against trunk) to replace
g_timeout_add with g_timeout_add_seconds (where possible), which uses
more rough granularity. This helps to aggregate timeouts and will
statistically wake up the cpu less frequently.

Good thing to do, but you'll need to check the glib version being used,
and if it's not >= 2.14, re-implement g_timeout_add_seconds() in
NetworkManagerUtils.c, which should simply call g_timeout_add or
whatever.  Care to respin?

Thanks!
Dan

Greetings,
Jan Kantert


_______________________________________________
NetworkManager-list mailing list
NetworkManager-list gnome org
http://mail.gnome.org/mailman/listinfo/networkmanager-list



Index: vpn-daemons/pptp/src/nm-pptp-service.c
===================================================================
--- vpn-daemons/pptp/src/nm-pptp-service.c	(Revision 4333)
+++ vpn-daemons/pptp/src/nm-pptp-service.c	(Arbeitskopie)
@@ -364,7 +364,7 @@
 #define NM_PPTP_PLUGIN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_PPTP_PLUGIN, NMPptpPluginPrivate))
 
 #define NM_PPTP_PPPD_PLUGIN PLUGINDIR "/nm-pptp-pppd-plugin.so"
-#define NM_PPTP_WAIT_PPPD 10000 /* 10 seconds */
+#define NM_PPTP_WAIT_PPPD 10 /* 10 seconds */
 #define PPTP_SERVICE_SECRET_TRIES "pptp-service-secret-tries"
 
 typedef struct {
@@ -870,7 +870,7 @@
 	NM_PPTP_PLUGIN_GET_PRIVATE (plugin)->pid = pid;
 	g_child_watch_add (pid, pppd_watch_cb, plugin);
 
-	priv->ppp_timeout_handler = g_timeout_add (NM_PPTP_WAIT_PPPD, pppd_timed_out, plugin);
+	priv->ppp_timeout_handler = g_timeout_add_seconds (NM_PPTP_WAIT_PPPD, pppd_timed_out, plugin);
 
 	return TRUE;
 }
@@ -1088,7 +1088,7 @@
 
 	if (priv->pid) {
 		if (kill (priv->pid, SIGTERM) == 0)
-			g_timeout_add (2000, ensure_killed, GINT_TO_POINTER (priv->pid));
+			g_timeout_add_seconds (2, ensure_killed, GINT_TO_POINTER (priv->pid));
 		else
 			kill (priv->pid, SIGKILL);
 
Index: vpn-daemons/openvpn/src/nm-openvpn-service.c
===================================================================
--- vpn-daemons/openvpn/src/nm-openvpn-service.c	(Revision 4333)
+++ vpn-daemons/openvpn/src/nm-openvpn-service.c	(Arbeitskopie)
@@ -975,7 +975,7 @@
 
 	if (priv->pid) {
 		if (kill (priv->pid, SIGTERM) == 0)
-			g_timeout_add (2000, ensure_killed, GINT_TO_POINTER (priv->pid));
+			g_timeout_add_seconds (2, ensure_killed, GINT_TO_POINTER (priv->pid));
 		else
 			kill (priv->pid, SIGKILL);
 
Index: vpn-daemons/vpnc/src/nm-vpnc-service.c
===================================================================
--- vpn-daemons/vpnc/src/nm-vpnc-service.c	(Revision 4333)
+++ vpn-daemons/vpnc/src/nm-vpnc-service.c	(Arbeitskopie)
@@ -524,7 +524,7 @@
 
 	if (priv->pid) {
 		if (kill (priv->pid, SIGTERM) == 0)
-			g_timeout_add (2000, ensure_killed, GINT_TO_POINTER (priv->pid));
+			g_timeout_add_seconds (2, ensure_killed, GINT_TO_POINTER (priv->pid));
 		else
 			kill (priv->pid, SIGKILL);
 
Index: src/dhcp-manager/nm-dhcp-manager.c
===================================================================
--- src/dhcp-manager/nm-dhcp-manager.c	(Revision 4333)
+++ src/dhcp-manager/nm-dhcp-manager.c	(Arbeitskopie)
@@ -602,7 +602,7 @@
 		timeout = NM_DHCP_TIMEOUT;
 
 	/* Set up a timeout on the transaction to kill it after the timeout */
-	device->timeout_id = g_timeout_add (timeout * 1000,
+	device->timeout_id = g_timeout_add_seconds (timeout,
 	                                    nm_dhcp_manager_handle_timeout,
 	                                    device);
 
Index: src/NetworkManagerUtils.c
===================================================================
--- src/NetworkManagerUtils.c	(Revision 4333)
+++ src/NetworkManagerUtils.c	(Arbeitskopie)
@@ -504,3 +504,14 @@
 	g_object_unref (dbus_mgr);
 }
 
+#if !GLIB_CHECK_VERSION(2,14,0)
+static inline guint
+g_timeout_add_seconds (guint interval,
+                       GSourceFunc function,
+                       gpointer data)
+{
+    g_return_val_if_fail (function != NULL, 0);
+ 
+    return g_timeout_add_full (G_PRIORITY_DEFAULT, interval * 1000, function, data, NULL);
+}
+#endif /* !GLIB_CHECK_VERSION(2,14,0) */
Index: src/nm-device-ethernet.c
===================================================================
--- src/nm-device-ethernet.c	(Revision 4333)
+++ src/nm-device-ethernet.c	(Arbeitskopie)
@@ -991,7 +991,7 @@
 
 			/* Start the link timeout so we allow some time for reauthentication */
 			if (!priv->link_timeout_id)
-				priv->link_timeout_id = g_timeout_add (15000, link_timeout_cb, dev);
+				priv->link_timeout_id = g_timeout_add_seconds (15, link_timeout_cb, dev);
 		}
 	}
 
@@ -1156,7 +1156,7 @@
 											self);
 
 	/* Set up a timeout on the connection attempt to fail it after 25 seconds */
-	priv->supplicant.con_timeout_id = g_timeout_add (25000, supplicant_connection_timeout_cb, self);
+	priv->supplicant.con_timeout_id = g_timeout_add_seconds (25, supplicant_connection_timeout_cb, self);
 
 	return TRUE;
 }
Index: src/nm-hal-manager.c
===================================================================
--- src/nm-hal-manager.c	(Revision 4333)
+++ src/nm-hal-manager.c	(Arbeitskopie)
@@ -500,7 +500,7 @@
 	killswitch_poll_cleanup (self);
 
 	/* Schedule next poll */
-	priv->killswitch_poll_id = g_timeout_add (RFKILL_POLL_FREQUENCY * 1000,
+	priv->killswitch_poll_id = g_timeout_add_seconds (RFKILL_POLL_FREQUENCY,
 	                                          poll_killswitches,
 	                                          self);
 }
Index: src/nm-manager.c
===================================================================
--- src/nm-manager.c	(Revision 4333)
+++ src/nm-manager.c	(Arbeitskopie)
@@ -95,7 +95,7 @@
                                                    GHashTable *properties,
                                                    gpointer user_data);
 
-#define SSD_POKE_INTERVAL 120000
+#define SSD_POKE_INTERVAL 120
 
 typedef struct {
 	DBusGMethodInvocation *context;
@@ -1389,7 +1389,7 @@
 
 out:
 	/* Reschedule the poke */
-	priv->poke_id = g_timeout_add (SSD_POKE_INTERVAL, poke_system_settings_daemon_cb, (gpointer) manager);
+	priv->poke_id = g_timeout_add_seconds (SSD_POKE_INTERVAL, poke_system_settings_daemon_cb, (gpointer) manager);
 
 	return FALSE;
 }
@@ -2134,7 +2134,7 @@
 		info->scope = scope;
 		info->connection_path = g_strdup (connection_path);
 		info->specific_object_path = g_strdup (real_sop);
-		info->timeout_id = g_timeout_add (5000, wait_for_connection_expired, manager);
+		info->timeout_id = g_timeout_add_seconds (5, wait_for_connection_expired, manager);
 
 		// FIXME: should probably be per-device, not global to the manager
 		NM_MANAGER_GET_PRIVATE (manager)->pending_connection_info = info;
Index: src/nm-gsm-device.c
===================================================================
--- src/nm-gsm-device.c	(Revision 4333)
+++ src/nm-gsm-device.c	(Arbeitskopie)
@@ -354,7 +354,7 @@
 	if (priv->pending_id)
 		g_source_remove (priv->pending_id);
 
-	priv->pending_id = g_timeout_add (1000, automatic_registration_again, self);
+	priv->pending_id = g_timeout_add_seconds (1, automatic_registration_again, self);
 }
 
 static void
Index: src/dnsmasq-manager/nm-dnsmasq-manager.c
===================================================================
--- src/dnsmasq-manager/nm-dnsmasq-manager.c	(Revision 4333)
+++ src/dnsmasq-manager/nm-dnsmasq-manager.c	(Arbeitskopie)
@@ -450,7 +450,7 @@
 
 	if (priv->pid) {
 		if (kill (priv->pid, SIGTERM) == 0)
-			g_timeout_add (2000, ensure_killed, GINT_TO_POINTER (priv->pid));
+			g_timeout_add_seconds (2, ensure_killed, GINT_TO_POINTER (priv->pid));
 		else {
 			kill (priv->pid, SIGKILL);
 
Index: src/nm-device-wifi.c
===================================================================
--- src/nm-device-wifi.c	(Revision 4333)
+++ src/nm-device-wifi.c	(Arbeitskopie)
@@ -910,7 +910,7 @@
 	NMDeviceWifi *self = NM_DEVICE_WIFI (dev);
 	NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
 
-	priv->periodic_source_id = g_timeout_add (6000, nm_device_wifi_periodic_update, self);
+	priv->periodic_source_id = g_timeout_add_seconds (6, nm_device_wifi_periodic_update, self);
 	return TRUE;
 }
 
@@ -1717,7 +1717,7 @@
 		    || (nm_device_get_state (NM_DEVICE (self)) == NM_DEVICE_STATE_ACTIVATED))
 			factor = 1;
 
-		priv->pending_scan_id = g_timeout_add (priv->scan_interval * 1000,
+		priv->pending_scan_id = g_timeout_add_seconds (priv->scan_interval,
 											   request_wireless_scan,
 											   self);
 
@@ -2274,7 +2274,7 @@
 			 * while to scan.
 			 */
 			if (!priv->link_timeout_id) {
-				priv->link_timeout_id = g_timeout_add (priv->scanning ? 30000 : 15000,
+				priv->link_timeout_id = g_timeout_add_seconds (priv->scanning ? 30 : 15,
 				                                       link_timeout_cb, self);
 			}
 		}
@@ -2573,7 +2573,7 @@
 	priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
 
 	/* Set up a timeout on the connection attempt to fail it after 25 seconds */
-	id = g_timeout_add (25000, supplicant_connection_timeout_cb, self);
+	id = g_timeout_add_seconds (25, supplicant_connection_timeout_cb, self);
 	if (id <= 0) {
 		nm_warning ("Activation (%s/wireless): couldn't start supplicant "
 		            "timeout timer.",
Index: src/nm-device.c
===================================================================
--- src/nm-device.c	(Revision 4333)
+++ src/nm-device.c	(Arbeitskopie)
@@ -204,7 +204,7 @@
 	 * system settings service a chance to figure out whether the device is
 	 * managed or not.
 	 */
-	priv->start_timer = g_timeout_add (4000, device_start, dev);
+	priv->start_timer = g_timeout_add_seconds (4, device_start, dev);
 
 	priv->initialized = TRUE;
 	return object;
@@ -830,7 +830,7 @@
 	priv->aipd_watch = g_child_watch_add (priv->aipd_pid, aipd_watch_cb, self);
 
 	/* Start a timeout to bound the address attempt */
-	priv->aipd_timeout = g_timeout_add (20000, aipd_timeout_cb, self);
+	priv->aipd_timeout = g_timeout_add_seconds (20, aipd_timeout_cb, self);
 
 	return TRUE;
 }
Index: src/supplicant-manager/nm-supplicant-manager.c
===================================================================
--- src/supplicant-manager/nm-supplicant-manager.c	(Revision 4333)
+++ src/supplicant-manager/nm-supplicant-manager.c	(Arbeitskopie)
@@ -29,7 +29,7 @@
 #include "nm-marshal.h"
 #include "nm-utils.h"
 
-#define SUPPLICANT_POKE_INTERVAL 120000
+#define SUPPLICANT_POKE_INTERVAL 120
 
 typedef struct {
 	NMDBusManager *	dbus_mgr;
@@ -106,7 +106,7 @@
 
 out:
 	/* Reschedule the poke */	
-	priv->poke_id = g_timeout_add (SUPPLICANT_POKE_INTERVAL,
+	priv->poke_id = g_timeout_add_seconds (SUPPLICANT_POKE_INTERVAL,
 	                               poke_supplicant_cb,
 	                               (gpointer) self);
 
Index: src/supplicant-manager/nm-supplicant-interface.c
===================================================================
--- src/supplicant-manager/nm-supplicant-interface.c	(Revision 4333)
+++ src/supplicant-manager/nm-supplicant-interface.c	(Arbeitskopie)
@@ -579,7 +579,7 @@
 		return;
 
 	/* Only fetch scan results every 4s max, but initially do it right away */
-	priv->scan_results_timeout = g_timeout_add (priv->last_scan ? 4000 : 0,
+	priv->scan_results_timeout = g_timeout_add_seconds (priv->last_scan ? 4 : 0,
 	                                            request_scan_results,
 	                                            user_data);
 }
Index: src/nm-dbus-manager.c
===================================================================
--- src/nm-dbus-manager.c	(Revision 4333)
+++ src/nm-dbus-manager.c	(Arbeitskopie)
@@ -158,7 +158,7 @@
 start_reconnection_timeout (NMDBusManager *self)
 {
 	/* Schedule timeout for reconnection attempts */
-	g_timeout_add (3000, nm_dbus_manager_reconnect, self);
+	g_timeout_add_seconds (3, nm_dbus_manager_reconnect, self);
 }
 
 char *
Index: src/ppp-manager/nm-ppp-manager.c
===================================================================
--- src/ppp-manager/nm-ppp-manager.c	(Revision 4333)
+++ src/ppp-manager/nm-ppp-manager.c	(Arbeitskopie)
@@ -65,7 +65,7 @@
 #include "nm-ppp-manager-glue.h"
 
 #define NM_PPPD_PLUGIN PLUGINDIR "/nm-pppd-plugin.so"
-#define NM_PPP_WAIT_PPPD 15000 /* 10 seconds */
+#define NM_PPP_WAIT_PPPD 15 /* 15 seconds */
 #define PPP_MANAGER_SECRET_TRIES "ppp-manager-secret-tries"
 
 typedef struct {
@@ -342,7 +342,7 @@
 
 	priv->monitor_fd = socket (AF_INET, SOCK_DGRAM, 0);
 	if (priv->monitor_fd > 0)
-		priv->monitor_id = g_timeout_add (5000, monitor_cb, manager);
+		priv->monitor_id = g_timeout_add_seconds (5, monitor_cb, manager);
 	else
 		nm_warning ("Could not open pppd monitor: %s", strerror (errno));
 }
@@ -936,7 +936,7 @@
 	nm_debug ("ppp started with pid %d", priv->pid);
 
 	priv->ppp_watch_id = g_child_watch_add (priv->pid, (GChildWatchFunc) ppp_watch_cb, manager);
-	priv->ppp_timeout_handler = g_timeout_add (NM_PPP_WAIT_PPPD, pppd_timed_out, manager);
+	priv->ppp_timeout_handler = g_timeout_add_seconds (NM_PPP_WAIT_PPPD, pppd_timed_out, manager);
 	priv->act_req = g_object_ref (req);
 
  out:
@@ -1035,7 +1035,7 @@
 
 	if (priv->pid) {
 		if (kill (priv->pid, SIGTERM) == 0)
-			g_timeout_add (2000, ensure_killed, GINT_TO_POINTER (priv->pid));
+			g_timeout_add_seconds (2, ensure_killed, GINT_TO_POINTER (priv->pid));
 		else {
 			kill (priv->pid, SIGKILL);
 
Index: src/vpn-manager/nm-vpn-connection.c
===================================================================
--- src/vpn-manager/nm-vpn-connection.c	(Revision 4333)
+++ src/vpn-manager/nm-vpn-connection.c	(Arbeitskopie)
@@ -571,7 +571,7 @@
 		                                 NM_VPN_CONNECTION_STATE_REASON_NONE);
 		
 		/* 40 second timeout waiting for IP config signal from VPN service */
-		priv->ipconfig_timeout = g_timeout_add (40000, nm_vpn_connection_ip_config_timeout, connection);
+		priv->ipconfig_timeout = g_timeout_add_seconds (40, nm_vpn_connection_ip_config_timeout, connection);
 	}
 }
 
Index: src/vpn-manager/nm-vpn-service.c
===================================================================
--- src/vpn-manager/nm-vpn-service.c	(Revision 4333)
+++ src/vpn-manager/nm-vpn-service.c	(Arbeitskopie)
@@ -249,7 +249,7 @@
 		         nm_vpn_service_get_name (service), priv->dbus_service, priv->pid);
 
 		priv->service_child_watch = g_child_watch_add (priv->pid, vpn_service_watch_cb, service);
-		priv->service_start_timeout = g_timeout_add (5000, nm_vpn_service_timeout, service);
+		priv->service_start_timeout = g_timeout_add_seconds (5, nm_vpn_service_timeout, service);
 	} else {
 		nm_warning ("VPN service '%s': could not launch the VPN service. error: (%d) %s.",
 		            nm_vpn_service_get_name (service), spawn_error->code, spawn_error->message);
@@ -291,7 +291,7 @@
 
 		if (priv->connections == NULL) {
 			/* schedule a timeout (10 seconds) to destroy the service */
-			g_timeout_add (10000, destroy_service, user_data);
+			g_timeout_add_seconds (10, destroy_service, user_data);
 		}
 		break;
 	default:
@@ -436,7 +436,7 @@
 
 	if (priv->pid) {
 		if (kill (priv->pid, SIGTERM) == 0)
-			g_timeout_add (2000, ensure_killed, GINT_TO_POINTER (priv->pid));
+			g_timeout_add_seconds (2, ensure_killed, GINT_TO_POINTER (priv->pid));
 		else {
 			kill (priv->pid, SIGKILL);
 
Index: src/nm-serial-device.c
===================================================================
--- src/nm-serial-device.c	(Revision 4333)
+++ src/nm-serial-device.c	(Arbeitskopie)
@@ -285,8 +285,8 @@
 		g_source_remove (priv->timeout_id);
 	}
 
-	priv->timeout_id = g_timeout_add_full (G_PRIORITY_DEFAULT,
-								    timeout * 1000,
+	priv->timeout_id = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT,
+								    timeout,
 								    nm_serial_device_timed_out,
 								    self,
 								    nm_serial_device_timeout_removed);
Index: gfilemonitor/inotify-diag.c
===================================================================
--- gfilemonitor/inotify-diag.c	(Revision 4333)
+++ gfilemonitor/inotify-diag.c	(Arbeitskopie)
@@ -31,7 +31,7 @@
 #include "inotify-path.h"
 #include "inotify-diag.h"
 
-#define DIAG_DUMP_TIME 20000 /* 20 seconds */
+#define DIAG_DUMP_TIME 20 /* 20 seconds */
 
 G_LOCK_EXTERN (inotify_lock);
 
@@ -70,5 +70,5 @@
   if (!g_getenv ("GVFS_INOTIFY_DIAG"))
     return;
 	
-  g_timeout_add (DIAG_DUMP_TIME, id_dump, NULL);
+  g_timeout_add_seconds (DIAG_DUMP_TIME, id_dump, NULL);
 }
Index: test/nm-online.c
===================================================================
--- test/nm-online.c	(Revision 4333)
+++ test/nm-online.c	(Arbeitskopie)
@@ -180,7 +180,7 @@
 
 	if (timeout.value) {
 		timeout.norm = (double) timeout.value / (double) PROGRESS_STEPS;
-		g_timeout_add (1000, handle_timeout, &timeout);
+		g_timeout_add_seconds (1, handle_timeout, &timeout);
 	}
 	timeout.quiet = quiet;
 
Index: system-settings/src/main.c
===================================================================
--- system-settings/src/main.c	(Revision 4333)
+++ system-settings/src/main.c	(Arbeitskopie)
@@ -422,7 +422,7 @@
 	/* Wait for a plugin to figure out if the device should be managed or not */
 	info = g_malloc0 (sizeof (WiredDeviceInfo));
 	info->app = app;
-	info->add_id = g_timeout_add (4000, add_default_dhcp_connection, info);
+	info->add_id = g_timeout_add_seconds (4, add_default_dhcp_connection, info);
 	info->udi = g_strdup (udi);
 	g_hash_table_insert (app->wired_devices, info->udi, info);
 }
Index: callouts/nm-dispatcher-action.c
===================================================================
--- callouts/nm-dispatcher-action.c	(Revision 4333)
+++ callouts/nm-dispatcher-action.c	(Arbeitskopie)
@@ -486,7 +486,7 @@
 	if (d->quit_timeout)
 		g_source_remove (d->quit_timeout);
 	if (!d->persist)
-		d->quit_timeout = g_timeout_add (10000, quit_timeout_cb, NULL);
+		d->quit_timeout = g_timeout_add_seconds (10, quit_timeout_cb, NULL);
 
 	connection = nm_connection_new_from_hash (connection_hash, error);
 	if (connection) {
@@ -780,7 +780,7 @@
 	                                     G_OBJECT (d->handler));
 
 	if (!persist)
-		d->quit_timeout = g_timeout_add (10000, quit_timeout_cb, NULL);
+		d->quit_timeout = g_timeout_add_seconds (10, quit_timeout_cb, NULL);
 
 	g_main_loop_run (loop);
 
Index: libnm-glib/nm-vpn-plugin.c
===================================================================
--- libnm-glib/nm-vpn-plugin.c	(Revision 4333)
+++ libnm-glib/nm-vpn-plugin.c	(Arbeitskopie)
@@ -49,8 +49,8 @@
 
 #include "nm-vpn-plugin-glue.h"
 
-#define NM_VPN_PLUGIN_CONNECT_TIMER 60000
-#define NM_VPN_PLUGIN_QUIT_TIMER    20000
+#define NM_VPN_PLUGIN_CONNECT_TIMER 60
+#define NM_VPN_PLUGIN_QUIT_TIMER    20
 
 G_DEFINE_ABSTRACT_TYPE (NMVPNPlugin, nm_vpn_plugin, G_TYPE_OBJECT)
 
@@ -680,14 +680,14 @@
 		}
 
 		/* Add a timer to make sure we do not wait indefinitely for the successful connect. */
-		priv->connect_timer = g_timeout_add_full (G_PRIORITY_DEFAULT,
+		priv->connect_timer = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT,
 										  NM_VPN_PLUGIN_CONNECT_TIMER,
 										  connect_timer_expired,
 										  plugin,
 										  connect_timer_removed);
 		break;
 	case NM_VPN_SERVICE_STATE_STOPPED:
-		priv->quit_timer = g_timeout_add_full (G_PRIORITY_DEFAULT, 
+		priv->quit_timer = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, 
 									    NM_VPN_PLUGIN_QUIT_TIMER,
 									    quit_timer_expired,
 									    plugin,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]