From patchwork Mon Apr 29 21:45:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Cross X-Patchwork-Id: 2502681 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 52CDFDF25A for ; Mon, 29 Apr 2013 21:47:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932613Ab3D2VqC (ORCPT ); Mon, 29 Apr 2013 17:46:02 -0400 Received: from mail-qe0-f74.google.com ([209.85.128.74]:61819 "EHLO mail-qe0-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932468Ab3D2Vp4 (ORCPT ); Mon, 29 Apr 2013 17:45:56 -0400 Received: by mail-qe0-f74.google.com with SMTP id a11so145770qen.5 for ; Mon, 29 Apr 2013 14:45:55 -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=Mrov1mg7vAXzrbM9w+A3HFGqK3KPT51VSoX/b1F3Lw1stN27gNlIoJjrHj9lck2fgs TzvEk2CPWRU5BX4nFHEYxekwPimssebomCRHQgyfBYmH5HpoF6jhn+aCKcUIUNwJt/Em iorNnxe2+aaMH3QYl7gtbLiRd+BuIVqpbxFQBnkLlWR9u/pX+0UED/PFwjfoQzB5TSCc mbfnI3R8i2ExbezkKvs9x9Q2R7N5ZFIxs+HCkumG5ZTPbOTRuNvl/2d1YP4Pdiuwy/PF Dptdhx37SIiEiXvRfaChCnc+SHwBHgwpOTOVXqnbTsmyojkmfoteKAjX+QC/qg+wyR++ r7rw== X-Received: by 10.236.189.241 with SMTP id c77mr5049480yhn.17.1367271954390; Mon, 29 Apr 2013 14:45:54 -0700 (PDT) Received: from corp2gmr1-2.hot.corp.google.com (corp2gmr1-2.hot.corp.google.com [172.24.189.93]) by gmr-mx.google.com with ESMTPS id u58si1362141yhe.2.2013.04.29.14.45.54 for (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Mon, 29 Apr 2013 14:45:54 -0700 (PDT) Received: from walnut.mtv.corp.google.com (walnut.mtv.corp.google.com [172.18.105.48]) by corp2gmr1-2.hot.corp.google.com (Postfix) with ESMTP id 3D9165A4034; Mon, 29 Apr 2013 14:45:54 -0700 (PDT) Received: by walnut.mtv.corp.google.com (Postfix, from userid 99897) id D93C7160552; Mon, 29 Apr 2013 14:45:48 -0700 (PDT) From: Colin Cross To: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, "Rafael J. Wysocki" , arve@android.com, Colin Cross , Len Brown , Pavel Machek Subject: [PATCH 01/10] freezer: shorten freezer sleep time using exponential backoff Date: Mon, 29 Apr 2013 14:45:37 -0700 Message-Id: <1367271946-7239-2-git-send-email-ccross@android.com> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1367271946-7239-1-git-send-email-ccross@android.com> References: <1367271946-7239-1-git-send-email-ccross@android.com> X-Gm-Message-State: ALoCoQmFJtjFHe/yRb3AtxsfjDYNtL3Tu7ImUUsvhHEAKHek24mN9/QXmaqpHQzfnRDikOW/nW69akuRgxcpFqlqXisuoGfyF0xcKu19SQToGaJsU+Jr/nzdH99mTFbOif9PYRNW6/W40BfcBW5J5lFDlmAEy7qd7Sxd0PND6SKS9NzX3YzoLmG/ZFr1nBDZPEv73PD0k/3d 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: Pavel Machek --- 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;