From patchwork Sat Nov 30 15:56:20 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 3260741 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D45BA9F376 for ; Sat, 30 Nov 2013 15:57:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0634820439 for ; Sat, 30 Nov 2013 15:57:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2A4FD2028D for ; Sat, 30 Nov 2013 15:57:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752675Ab3K3P4n (ORCPT ); Sat, 30 Nov 2013 10:56:43 -0500 Received: from mail-pb0-f51.google.com ([209.85.160.51]:63574 "EHLO mail-pb0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752403Ab3K3P4j (ORCPT ); Sat, 30 Nov 2013 10:56:39 -0500 Received: by mail-pb0-f51.google.com with SMTP id up15so16017091pbc.24 for ; Sat, 30 Nov 2013 07:56:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=dCArDE9W1vugDD9pKmi1lhmmUO4w1JnimpV4pdoVkFA=; b=X3fIfVUJlApETLEeHm14LVhJzgq/rQu8254I0WkleyZAIj2Qa2X2JIqrR1p6ZAM5J9 baKXxqUOPZ96lfOFztCnVgrhL+w696f1HyY7+dNpiiiata9Jrj+gQ+2oZZAWgRBBnpXt O0Rmizht6L9x1P2AHz6MH1spAJTVvLQCZm5K40wtyx7gt1RyRGyaXBnquphcV+AFHJgu dV3/u1SJ94YEGwnZp+aXUeN1uFAQpRfa0Y/7SUeILVXVYU8MfKy4jKhpfDtDs1CSA/Ry Ezf5ojjQQvQPslMExV5azDhBrEStwlklY9ps3haG4e4AYfd/dH1PC21JQ/acZGXt4N3w J0Aw== X-Gm-Message-State: ALoCoQkEhy+w5xl806JotYedGAHUDakZX7jmQKMeM9B0guB5VZCDwzOJfzRiK1RdoaXBf6DV5O7z X-Received: by 10.66.253.169 with SMTP id ab9mr2032700pad.156.1385826998464; Sat, 30 Nov 2013 07:56:38 -0800 (PST) Received: from localhost ([122.167.133.207]) by mx.google.com with ESMTPSA id fk4sm124598390pab.23.2013.11.30.07.56.35 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 30 Nov 2013 07:56:37 -0800 (PST) From: Viresh Kumar To: rjw@rjwysocki.net Cc: linaro-kernel@lists.linaro.org, patches@linaro.org, cpufreq@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Viresh Kumar Subject: [PATCH 2/5] cpufreq: send new set of notification for transition failures Date: Sat, 30 Nov 2013 21:26:20 +0530 Message-Id: <4834ba7f5ae3838515f7b85102987cc3ec066627.1385826776.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 1.7.12.rc2.18.g61b472e In-Reply-To: <0d635c6701654a75f6d25dd435705dc1ede3e19c.1385826776.git.viresh.kumar@linaro.org> References: <0d635c6701654a75f6d25dd435705dc1ede3e19c.1385826776.git.viresh.kumar@linaro.org> In-Reply-To: <0d635c6701654a75f6d25dd435705dc1ede3e19c.1385826776.git.viresh.kumar@linaro.org> References: <0d635c6701654a75f6d25dd435705dc1ede3e19c.1385826776.git.viresh.kumar@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In the current code, if we fail during a frequency transition we simply send the POSTCHANGE notification with old frequency. This isn't enough. One of the core user of these notifications is the code responsible for keeping loops_per_jiffy aligned with frequency change. And mostly it is written as: if ((val == CPUFREQ_PRECHANGE && freq->old < freq->new) || (val == CPUFREQ_POSTCHANGE && freq->old > freq->new)) { update-loops-per-jiffy... } So, suppose we are changing to a higher frequency and failed during transition, then following will happen: - CPUFREQ_PRECHANGE notification with freq-new > freq-old - CPUFREQ_POSTCHANGE notification with freq-new == freq-old The first one will update loops_per_jiffy and second one will do nothing. Even if we send the 2nd notification by exchanging values of freq-new and old, some users of these notifications might get unstable. This can be fixed by simply calling cpufreq_notify_post_transition() with error code and this routine will take care of sending notifications in correct order. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index a862aa9..557bb49 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1764,17 +1764,8 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy, pr_err("%s: Failed to change cpu frequency: %d\n", __func__, retval); - if (notify) { - /* - * Notify with old freq in case we failed to change - * frequency - */ - if (retval) - freqs.new = freqs.old; - - cpufreq_notify_transition(policy, &freqs, - CPUFREQ_POSTCHANGE); - } + if (notify) + cpufreq_notify_post_transition(policy, &freqs, retval); } out: