From patchwork Thu May 2 01:34:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Cross X-Patchwork-Id: 2509581 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 78D263FC5A for ; Thu, 2 May 2013 01:35:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758868Ab3EBBfS (ORCPT ); Wed, 1 May 2013 21:35:18 -0400 Received: from mail-qa0-f74.google.com ([209.85.216.74]:59180 "EHLO mail-qa0-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758176Ab3EBBfQ (ORCPT ); Wed, 1 May 2013 21:35:16 -0400 Received: by mail-qa0-f74.google.com with SMTP id i13so14423qae.5 for ; Wed, 01 May 2013 18:35:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=RzKIFVJavxGp0Wd811Y093Of/7BibL45qkgY74ksI+c=; b=cQ0rvfSCp0s2fWimhyaSEuETicr2ap0jwEIHUYA5wHObbKjWVflseufXAlfED/GStK ddia+A1u7xfcuhwEI/SGn+I/tdBYA8KCoQi0c9pzzhnJHzfCQtkTrR7Nlz00vLR+qekr Gm9XpaCYmHsG7774a43jJBmgkBvMUqUuAnMxU42JS9sRooSxMVqALR/RK0EWu7AHAzar inE6kspzi5Tp4EV+QRG1ZlcjviQy2Ghj+CGfPkpFKdVh24lV0wpvWDB5ZW7QrKpOwLLG hP0rAbu1J1oX9wWX4dae7bt0doOEKxqYHyeQZWyqlCLckU3VavZm39qgRIzY4xrkEkS0 KWUw== X-Received: by 10.236.81.115 with SMTP id l79mr3691768yhe.20.1367458515203; Wed, 01 May 2013 18:35:15 -0700 (PDT) Received: from corp2gmr1-1.hot.corp.google.com (corp2gmr1-1.hot.corp.google.com [172.24.189.92]) by gmr-mx.google.com with ESMTPS id q46si398253yhh.4.2013.05.01.18.35.15 for (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Wed, 01 May 2013 18:35:15 -0700 (PDT) Received: from walnut.mtv.corp.google.com (walnut.mtv.corp.google.com [172.18.105.48]) by corp2gmr1-1.hot.corp.google.com (Postfix) with ESMTP id 0E01D31C042; Wed, 1 May 2013 18:35:15 -0700 (PDT) Received: by walnut.mtv.corp.google.com (Postfix, from userid 99897) id B58E7160A66; Wed, 1 May 2013 18:35:14 -0700 (PDT) From: Colin Cross To: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, "Rafael J. Wysocki" , arve@android.com, Tejun Heo , Oleg Nesterov , Colin Cross , Len Brown , Pavel Machek Subject: [PATCH v2 01/10] freezer: shorten freezer sleep time using exponential backoff Date: Wed, 1 May 2013 18:34:59 -0700 Message-Id: <1367458508-9133-2-git-send-email-ccross@android.com> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1367458508-9133-1-git-send-email-ccross@android.com> References: <1367458508-9133-1-git-send-email-ccross@android.com> X-Gm-Message-State: ALoCoQl2P3zYswATJg1Xg5pB7K1tatSG69souhBBpFdAhnWkMjAwQhFhbvXBOj6S06cII7x6B2nHV0j9mwT739790gGavln0Z4a5WsWSTog8kD0lBz/sQyPAJIKjuDPTSrBcYDpi2UazKHipoTJ4soDyTupoV1TOxs6urCpSMyEZQTW9fHYk3pQTjuJnuy/yYFWww1qm0rNF Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org All tasks can easily be frozen in under 10 ms, switch to using an initial 1 ms sleep followed by exponential backoff until 8 ms. Also convert the printed time to ms instead of centiseconds. Signed-off-by: Colin Cross Acked-by: Tejun Heo --- kernel/power/process.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/kernel/power/process.c b/kernel/power/process.c index 98088e0..eb7e6c1 100644 --- a/kernel/power/process.c +++ b/kernel/power/process.c @@ -30,9 +30,10 @@ static int try_to_freeze_tasks(bool user_only) unsigned int todo; bool wq_busy = false; struct timeval start, end; - u64 elapsed_csecs64; - unsigned int elapsed_csecs; + u64 elapsed_msecs64; + unsigned int elapsed_msecs; bool wakeup = false; + int sleep_usecs = USEC_PER_MSEC; do_gettimeofday(&start); @@ -70,20 +71,22 @@ static int try_to_freeze_tasks(bool user_only) * We need to retry, but first give the freezing tasks some * time to enter the refrigerator. */ - msleep(10); + usleep_range(sleep_usecs / 2, sleep_usecs); + if (sleep_usecs < 8 * USEC_PER_MSEC) + sleep_usecs *= 2; } do_gettimeofday(&end); - elapsed_csecs64 = timeval_to_ns(&end) - timeval_to_ns(&start); - do_div(elapsed_csecs64, NSEC_PER_SEC / 100); - elapsed_csecs = elapsed_csecs64; + elapsed_msecs64 = timeval_to_ns(&end) - timeval_to_ns(&start); + do_div(elapsed_msecs64, NSEC_PER_MSEC); + elapsed_msecs = elapsed_msecs64; if (todo) { printk("\n"); - printk(KERN_ERR "Freezing of tasks %s after %d.%02d seconds " + printk(KERN_ERR "Freezing of tasks %s after %d.%03d seconds " "(%d tasks refusing to freeze, wq_busy=%d):\n", wakeup ? "aborted" : "failed", - elapsed_csecs / 100, elapsed_csecs % 100, + elapsed_msecs / 1000, elapsed_msecs % 1000, todo - wq_busy, wq_busy); if (!wakeup) { @@ -96,8 +99,8 @@ static int try_to_freeze_tasks(bool user_only) read_unlock(&tasklist_lock); } } else { - printk("(elapsed %d.%02d seconds) ", elapsed_csecs / 100, - elapsed_csecs % 100); + printk("(elapsed %d.%03d seconds) ", elapsed_msecs / 1000, + elapsed_msecs % 1000); } return todo ? -EBUSY : 0;