From patchwork Fri Sep 13 12:59:39 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 20054 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f199.google.com (mail-ve0-f199.google.com [209.85.128.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id ADDE8202E6 for ; Fri, 13 Sep 2013 13:00:03 +0000 (UTC) Received: by mail-ve0-f199.google.com with SMTP id db12sf1207492veb.10 for ; Fri, 13 Sep 2013 06:00:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=yS1466VvDScjFPKhUSBMMpQNRlNy0VfCUq20cRyF/9A=; b=MOuS+apiVTUb0p+lkSjXNbT8qLKc2MLK+cLAqnMBGNvsZWkQ1fWlfFCKwwTWJwp5Sw uZkzmOPowpDHTDLNnZyCQBeBsx5sAwY22XbUBvKAeMczFv/U3yZmxP3ZYYZ6VJQY3SqZ AJOwJqJe3H6+6hYn6CKW+miLl5knqnCebmPFTzt5eSRs6Er0MbyNO9AvwLAGdvPOfhyF ZiE582fzzm1cRGDbhk1Qd6H7Jr/lSBgYbw6VCdHLE+eJkrXjLgWWMcSjQEb93pBM2cl5 XWMTCKE2TZXVVYPS+Wm9SoyyQMfyf72wMqkGGQYQC5Eqp8Y7RhTjbNEinxQTj6vWgT+W BbpQ== X-Gm-Message-State: ALoCoQln5Pf3wEwf5qsKVW50TM9hiOHCjkyUr2PUBZA5LHQWnUMOswF8oWUZD5ei0ca9gNaI3mh5 X-Received: by 10.236.125.232 with SMTP id z68mr341515yhh.56.1379077203284; Fri, 13 Sep 2013 06:00:03 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.97.66 with SMTP id dy2ls1234538qeb.85.gmail; Fri, 13 Sep 2013 06:00:03 -0700 (PDT) X-Received: by 10.220.13.20 with SMTP id z20mr11946745vcz.0.1379077203040; Fri, 13 Sep 2013 06:00:03 -0700 (PDT) Received: from mail-ve0-f170.google.com (mail-ve0-f170.google.com [209.85.128.170]) by mx.google.com with ESMTPS id b5si3095002vcf.54.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Sep 2013 06:00:03 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.170 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.170; Received: by mail-ve0-f170.google.com with SMTP id c14so959919vea.1 for ; Fri, 13 Sep 2013 06:00:03 -0700 (PDT) X-Received: by 10.220.181.136 with SMTP id by8mr12115956vcb.11.1379077202929; Fri, 13 Sep 2013 06:00:02 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp79229vcz; Fri, 13 Sep 2013 06:00:02 -0700 (PDT) X-Received: by 10.68.229.2 with SMTP id sm2mr13292952pbc.68.1379077201874; Fri, 13 Sep 2013 06:00:01 -0700 (PDT) Received: from mail-pa0-f45.google.com (mail-pa0-f45.google.com [209.85.220.45]) by mx.google.com with ESMTPS id z1si11113210pab.247.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Sep 2013 06:00:01 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.45 is neither permitted nor denied by best guess record for domain of viresh.kumar@linaro.org) client-ip=209.85.220.45; Received: by mail-pa0-f45.google.com with SMTP id bg4so2475758pad.32 for ; Fri, 13 Sep 2013 06:00:01 -0700 (PDT) X-Received: by 10.68.218.163 with SMTP id ph3mr13333579pbc.19.1379077201234; Fri, 13 Sep 2013 06:00:01 -0700 (PDT) Received: from localhost ([122.167.78.148]) by mx.google.com with ESMTPSA id mr3sm11616804pbb.27.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 13 Sep 2013 06:00:00 -0700 (PDT) From: Viresh Kumar To: rjw@sisk.pl 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/2] cpufreq: powernow-k8: mark freq transition complete on error cases Date: Fri, 13 Sep 2013 18:29:39 +0530 Message-Id: <68dc892ac44a619e3bb8a69ec8314c59f19c514a.1379062834.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 1.7.12.rc2.18.g61b472e In-Reply-To: References: In-Reply-To: References: X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.170 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Following patch "cpufreq: make sure frequency transitions are serialized" guarantees that we don't have any races while changing cpu frequency or sending notifications. It handled a special case with CPUFREQ_ASYNC_NOTIFICATION flag for drivers that don't complete their freq change from ->target() and exynos5440 driver is well adopted to it as well.. There is one more driver powernow-k8 that has similar implementation, schedules a work for doing transitions. All is good if that work function does notifications on every call to it and so the transition_ongoing count stays stable. But there are chances that the work function may return without actually doing the notifications, in which case transition_ongoing count will not be set to zero and so no transitions would be possible after that. This patch fixes powernow-k8 driver to get transition_ongoing count stable. It does following to ensure proper working of this driver: - return -EINPROGRESS from ->target() so that core doesn't mark transfer over at the end of ->target(). - mark cpufreq_driver->flags with CPUFREQ_ASYNC_NOTIFICATION, so that core knows that driver would terminate its transition. - call cpufreq_transition_complete() whenever we are returning before sending notifications Hopefully things will work well after this patch, only compiled tested at my end. Signed-off-by: Viresh Kumar --- drivers/cpufreq/powernow-k8.c | 47 +++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/drivers/cpufreq/powernow-k8.c b/drivers/cpufreq/powernow-k8.c index 2344a9e..8215bbc 100644 --- a/drivers/cpufreq/powernow-k8.c +++ b/drivers/cpufreq/powernow-k8.c @@ -952,7 +952,7 @@ static int transition_frequency_fidvid(struct powernow_k8_data *data, if ((data->currvid == vid) && (data->currfid == fid)) { pr_debug("target matches current values (fid 0x%x, vid 0x%x)\n", fid, vid); - return 0; + return -EALREADY; } pr_debug("cpu %d, changing to fid 0x%x, vid 0x%x\n", @@ -993,22 +993,27 @@ static long powernowk8_target_fn(void *arg) unsigned int newstate; int ret; - if (!data) - return -EINVAL; + if (!data) { + ret = -EINVAL; + goto transition_complete; + } checkfid = data->currfid; checkvid = data->currvid; if (pending_bit_stuck()) { printk(KERN_ERR PFX "failing targ, change pending bit set\n"); - return -EIO; + ret = -EIO; + goto transition_complete; } pr_debug("targ: cpu %d, %d kHz, min %d, max %d, relation %d\n", pol->cpu, targfreq, pol->min, pol->max, relation); - if (query_current_values_with_pending_wait(data)) - return -EIO; + if (query_current_values_with_pending_wait(data)) { + ret = -EIO; + goto transition_complete; + } pr_debug("targ: curr fid 0x%x, vid 0x%x\n", data->currfid, data->currvid); @@ -1022,25 +1027,36 @@ static long powernowk8_target_fn(void *arg) } if (cpufreq_frequency_table_target(pol, data->powernow_table, - targfreq, relation, &newstate)) - return -EIO; + targfreq, relation, &newstate)) { + ret = -EIO; + goto transition_complete; + } mutex_lock(&fidvid_mutex); powernow_k8_acpi_pst_values(data, newstate); ret = transition_frequency_fidvid(data, newstate); + mutex_unlock(&fidvid_mutex); if (ret) { - printk(KERN_ERR PFX "transition frequency failed\n"); - mutex_unlock(&fidvid_mutex); - return 1; + /* Not a error case, just need to mark transition complete */ + if (ret == -EALREADY) { + ret = 0; + } else { + printk(KERN_ERR PFX "transition frequency failed\n"); + ret = 1; + } + goto transition_complete; } - mutex_unlock(&fidvid_mutex); pol->cur = find_khz_freq_from_fid(data->currfid); return 0; + +transition_complete: + cpufreq_transition_complete(pol); + return ret; } /* Driver entry point to switch to the target frequency */ @@ -1049,8 +1065,12 @@ static int powernowk8_target(struct cpufreq_policy *pol, { struct powernowk8_target_arg pta = { .pol = pol, .targfreq = targfreq, .relation = relation }; + int ret; - return work_on_cpu(pol->cpu, powernowk8_target_fn, &pta); + ret = work_on_cpu(pol->cpu, powernowk8_target_fn, &pta); + if (!ret) + ret = -EINPROGRESS; /* Mark transition as In-progress */ + return ret; } /* Driver entry point to verify the policy and range of frequencies */ @@ -1233,6 +1253,7 @@ static struct freq_attr *powernow_k8_attr[] = { }; static struct cpufreq_driver cpufreq_amd64_driver = { + .flags = CPUFREQ_ASYNC_NOTIFICATION, .verify = powernowk8_verify, .target = powernowk8_target, .bios_limit = acpi_processor_get_bios_limit,