From patchwork Tue May 19 18:56:35 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 27409 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@bilbo.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ozlabs.org (ozlabs.org [203.10.76.45]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mx.ozlabs.org", Issuer "CA Cert Signing Authority" (verified OK)) by bilbo.ozlabs.org (Postfix) with ESMTPS id 770C8B6F56 for ; Wed, 20 May 2009 04:56:46 +1000 (EST) Received: by ozlabs.org (Postfix) id 06167DE0BA; Wed, 20 May 2009 04:56:46 +1000 (EST) Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by ozlabs.org (Postfix) with ESMTP id 39741DE089 for ; Wed, 20 May 2009 04:56:45 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753366AbZESS4h (ORCPT ); Tue, 19 May 2009 14:56:37 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753337AbZESS4h (ORCPT ); Tue, 19 May 2009 14:56:37 -0400 Received: from gw1.cosmosbay.com ([212.99.114.194]:59969 "EHLO gw1.cosmosbay.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753324AbZESS4h convert rfc822-to-8bit (ORCPT ); Tue, 19 May 2009 14:56:37 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) by gw1.cosmosbay.com (8.13.7/8.13.7) with ESMTP id n4JIuYkg013607; Tue, 19 May 2009 20:56:35 +0200 Message-ID: <4A1300E3.1000809@cosmosbay.com> Date: Tue, 19 May 2009 20:56:35 +0200 From: Eric Dumazet User-Agent: Thunderbird 2.0.0.21 (Windows/20090302) MIME-Version: 1.0 CC: "Tero.Kristo@nokia.com" , netdev@vger.kernel.org Subject: [PATCH] net: use a deferred timer in rt_check_expire References: <1F18D6510CF0474A8C9500565A7E41A20544D923FF@NOK-EUMSG-02.mgdnok.nokia.com> <4A127608.5020109@cosmosbay.com> <1F18D6510CF0474A8C9500565A7E41A20544D9255A@NOK-EUMSG-02.mgdnok.nokia.com> In-Reply-To: <1F18D6510CF0474A8C9500565A7E41A20544D9255A@NOK-EUMSG-02.mgdnok.nokia.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-1.6 (gw1.cosmosbay.com [0.0.0.0]); Tue, 19 May 2009 20:56:35 +0200 (CEST) To: unlisted-recipients:; (no To-header on input) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Tero.Kristo@nokia.com a écrit : > > >> -----Original Message----- >> From: ext Eric Dumazet [mailto:dada1@cosmosbay.com] >> Sent: 19 May, 2009 12:04 >> To: Kristo Tero (Nokia-D/Tampere) >> Cc: netdev@vger.kernel.org >> Subject: Re: Network stack timer hacks for power saving >> >> Tero.Kristo@nokia.com a écrit : >>> Hi, >>> >>> I have been looking at network stack timer optimization for power >>> saving in embedded ARM environment, basically trying to >> avoid as many >>> wakeups as possible. I have changed several timers in the network >>> stack into deferred ones, i.e. they do not wake up the >> device from low >>> power modes but instead they are deferred until next wakeup >>from some >>> other source, like another (non-deferred) timer or some I/O. >> Attached >>> a patch about the changes I've done, is something like this safe to >>> do? >>> >>> -Tero Here is the patch I cooked and tested on a machine where ip_rt_gc_interval is set to minimal value (1 second), where equilibrium depends on garbage collection done in time. I found that delayed timers could be *really* delayed so I think we must take into account the elapsed time (in jiffies) between two rt_check_expire() calls, to "guarantee" a full scan of rt cache in a ip_rt_gc_timeout period. Not for inclusion, as undergoing work is happening in this function for a bug correction. I'll redo the patch later once stabilized. [PATCH] net: use a deferred timer in rt_check_expire For the sake of power saver lovers, use a deferrable timer to fire rt_check_expire() As some big routers cache equilibrium depends on garbage collection done in time, we take into account elapsed time between two rt_check_expire() invocations to adjust the amount of slots we have to check. Based on an initial idea and patch from Tero Kristo Signed-off-by: Eric Dumazet Signed-off-by: Tero Kristo --- net/ipv4/route.c | 11 ++++++++--- 1 files changed, 8 insertions(+), 3 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/net/ipv4/route.c b/net/ipv4/route.c index c4c60e9..b2c6793 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -131,8 +131,8 @@ static int ip_rt_min_advmss __read_mostly = 256; static int ip_rt_secret_interval __read_mostly = 10 * 60 * HZ; static int rt_chain_length_max __read_mostly = 20; -static void rt_worker_func(struct work_struct *work); -static DECLARE_DELAYED_WORK(expires_work, rt_worker_func); +static struct delayed_work expires_work; +static unsigned long expires_ljiffies; /* * Interface to generic destination cache. @@ -787,9 +787,12 @@ static void rt_check_expire(void) struct rtable *rth, **rthp; unsigned long length = 0, samples = 0; unsigned long sum = 0, sum2 = 0; + unsigned long delta; u64 mult; - mult = ((u64)ip_rt_gc_interval) << rt_hash_log; + delta = jiffies - expires_ljiffies; + expires_ljiffies = jiffies; + mult = ((u64)delta) << rt_hash_log; if (ip_rt_gc_timeout > 1) do_div(mult, ip_rt_gc_timeout); goal = (unsigned int)mult; @@ -3410,6 +3413,8 @@ int __init ip_rt_init(void) /* All the timers, started at system startup tend to synchronize. Perturb it a bit. */ + INIT_DELAYED_WORK_DEFERRABLE(&expires_work, rt_worker_func); + expires_ljiffies = jiffies; schedule_delayed_work(&expires_work, net_random() % ip_rt_gc_interval + ip_rt_gc_interval);