From patchwork Mon May 6 23:50:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Cross X-Patchwork-Id: 2529291 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 716DCDF230 for ; Mon, 6 May 2013 23:57:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758263Ab3EFX5V (ORCPT ); Mon, 6 May 2013 19:57:21 -0400 Received: from mail-gg0-f202.google.com ([209.85.161.202]:65156 "EHLO mail-gg0-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758762Ab3EFX45 (ORCPT ); Mon, 6 May 2013 19:56:57 -0400 Received: by mail-gg0-f202.google.com with SMTP id 4so425503ggm.3 for ; Mon, 06 May 2013 16:56:56 -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=uz4PsJHVLrO0ia17+oEKB09UwU7o52IglgBsKXJme3Q=; b=HLD7shDaqiMxRLixwgolZkDGuHtdwS7Hq9Y8aZPbFmv0ofZK/3F/WxFBjitnTnO6zM +J/lDgAruF2gCCj3I2BnMCGGEFGZjWsqD2g3lrEmx1k/ouS1WC/0Zc3joooum/XHj4dw QUz+40ydceRkzRrQaIJUrs2+67O07X3SCJLX15jQ9HKF2hT5z30BjhNvI+q049p9zc9P xqJA/dg7JQ8KMnG4b8v7sH1BF1S6qwm7j56sqy8H+I6mMRJ4fyIrzFBqt7wON1LChBV5 7z7WZXBpdTNPeLWwV/9KkRj+Ikf1XEE3Qw5UxHgg32wi+Y9fkjCmC3wWebN+4e2Sb6qH Dyzg== X-Received: by 10.236.61.42 with SMTP id v30mr17560533yhc.15.1367884227698; Mon, 06 May 2013 16:50:27 -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 s48si2637508yhe.6.2013.05.06.16.50.27 for (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Mon, 06 May 2013 16:50:27 -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 8576731C078; Mon, 6 May 2013 16:50:27 -0700 (PDT) Received: by walnut.mtv.corp.google.com (Postfix, from userid 99897) id 3B79C1613FF; Mon, 6 May 2013 16:50:27 -0700 (PDT) From: Colin Cross To: linux-kernel@vger.kernel.org Cc: Pavel Machek , "Rafael J. Wysocki" , Peter Zijlstra , Ingo Molnar , Andrew Morton , Mandeep Singh Baines , Colin Cross , Oleg Nesterov , linux-nfs@vger.kernel.org, linux-pm@vger.kernel.org, netdev@vger.kernel.org, Linus Torvalds , Tejun Heo , Len Brown Subject: [PATCH v3 05/16] freezer: shorten freezer sleep time using exponential backoff Date: Mon, 6 May 2013 16:50:10 -0700 Message-Id: <1367884221-20462-6-git-send-email-ccross@android.com> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1367884221-20462-1-git-send-email-ccross@android.com> References: <1367884221-20462-1-git-send-email-ccross@android.com> X-Gm-Message-State: ALoCoQlqIEe0sLWqZL+vfwEERL//WE4gU4v3HCIG2Oh+K2tQNUk8AACxO/FidYNO8P+/Q2T+ax72UkAnFo87/d9IqTmALqC1BORteB27M/Jbkvy1Z4PlxL/vdPOWFuDSYqZlsHu24OaA/9JeSkvVmrrtcv4kP9O9bMmfJq43yAUFKU/Yo6heOLyY/0nEIeLDory8qyAH/2gH 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. Acked-by: Pavel Machek Acked-by: Tejun Heo Signed-off-by: Colin Cross --- kernel/power/process.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/kernel/power/process.c b/kernel/power/process.c index 98088e0..fc0df84 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); @@ -68,22 +69,25 @@ 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. + * time to enter the refrigerator. Start with an initial + * 1 ms sleep followed by exponential backoff until 8 ms. */ - 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 +100,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;