From patchwork Mon Jan 29 07:21:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 126152 Delivered-To: patch@linaro.org Received: by 10.46.84.92 with SMTP id y28csp2208000ljd; Sun, 28 Jan 2018 23:22:12 -0800 (PST) X-Google-Smtp-Source: AH8x227blmhfXdY7Y5TcET+J8FUOn0H7s81MTft0+zpx0Cy6fM9SITXibRwfzksIUpnL3RLglMzb X-Received: by 10.98.62.69 with SMTP id l66mr26286028pfa.20.1517210532270; Sun, 28 Jan 2018 23:22:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517210532; cv=none; d=google.com; s=arc-20160816; b=fD3WuaSakXhKEcy7r7kp/ZVFaM0LOD/8G+p3DKwTOGtpuWD81AznRrj2wqdzrtDCDl l0Cpb3OSNBy9i+g0hM/BJ5EcXWf3wZUUuAmiGTtOhYNM8qWPJAw2rDgCFsn7bv3Irko6 c8cioh9vRRNdoO9RMX0Eeu+XNHOYoMk19rZDGYbPD+Ej3Xxu1VLmRjRYSG/dVUs72x9e iuzl/hcS1HlJucHITHH4Z/zEvvwH6d0nu7/AymnIJoHxvhIjtKz2Np0HpJfnbL5DWi84 CoXTOvokkt1l1xM+p/Dh0luP9nlU2uWxUnJmKMA+KcLi8RmjHASBb+cb/2/6DuR0Lw25 xQ9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=m8aM8GLfHnbGfYI0PTC4m/7pTDQOTdnOvKt/bWoX/88=; b=dNEzkVQQQBzTKwdGojbMOAoiqxR3MarRzPbMGgbIqqo4Eiq4X5Sd03HfzuTZ1pvrCS MBfQfA7bUutB1Hf9s+xLH+EWHgZTtziqmBju9SJf7pgPM31/aZbgq6eEXB9f5ZEZTzPR phjFZvkIevAZHXoBceqeEB54CQgANt3hjXYUiOsR+ihv3ketOFYBe9xy57jt2ut6jOVj VoffN3+J9Tefw60KFbI5Gqk96kZeJMKEJZ+HVmTBeEikS7e0QC9OY3U2sPb74OWnIpJf QzR+LsaWuoyS6PqKNWAWCeVOqyv+cyFH1a45MofbEcGwS12l0EKdv+4VyabE4DJATY4v QaVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cE/XYT3v; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e65si11389265pfg.255.2018.01.28.23.22.11; Sun, 28 Jan 2018 23:22:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cE/XYT3v; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751355AbeA2HWL (ORCPT + 10 others); Mon, 29 Jan 2018 02:22:11 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:35570 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751127AbeA2HWK (ORCPT ); Mon, 29 Jan 2018 02:22:10 -0500 Received: by mail-pg0-f67.google.com with SMTP id o13so3778255pgs.2 for ; Sun, 28 Jan 2018 23:22:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=m8aM8GLfHnbGfYI0PTC4m/7pTDQOTdnOvKt/bWoX/88=; b=cE/XYT3vCJ8QI1D4QeSkCcNpOsbW1PphfW3WlTiiM+0gHBNID9cGKCa97dmDta1gLU K7JLESjCx5j+yyH0rT9BOQ0tj8yUPiG9OHIq0kfinlGS6o0t4TDRf4vCWpmV138KjjbF 6EqnO9wVBqewCu1MrSdwJGGfeD5iaLpRWM2qE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=m8aM8GLfHnbGfYI0PTC4m/7pTDQOTdnOvKt/bWoX/88=; b=qaYSZaFjkGKS5H5FIqCqhPRFCl1YPnF1eQxCx1yCtTv/SxpEET2DANn2Bk/LLaQEA/ lpoJazXutWko6nCJzUz3yJiVn02uDdgqoVxylHdgir1aOSqnCif65QeZ8i6RySA4PTOM RGl6+04IO2eiB89Uye6DYIUM2EtK+QbIVRRDgAcdvjGZWCx4FO/MvryGFoR6Cztb6U1G c0YCiaIcKX5zveil8YJPHF688GQcavBhpItddv7gYtocwl81G/31/+pRTUlgqaQ0M5aW dRcjzrJEdwneDMNuNNDND/itaPJNwOQkLVdLbf9aNoW3FnvUzTLkKa2PHoyFuJV4kI8X sRpg== X-Gm-Message-State: AKwxytf9N6+nfzOQ/kO/k/6RvV9kmwp586nvEk5muEv1XPvbbKLu4jDS SnwGIFAyE6O+5YHLi7n5vJhbBTnAPSw= X-Received: by 2002:a17:902:8f95:: with SMTP id z21-v6mr21943105plo.104.1517210528990; Sun, 28 Jan 2018 23:22:08 -0800 (PST) Received: from localhost ([122.167.234.121]) by smtp.gmail.com with ESMTPSA id l64sm20914656pfg.62.2018.01.28.23.22.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Jan 2018 23:22:07 -0800 (PST) From: Viresh Kumar To: stable@vger.kernel.org Cc: Viresh Kumar , Rafael Wysocki , linux-pm@vger.kernel.org Subject: [PATCH] cpufreq: governor: Ensure sufficiently large sampling intervals Date: Mon, 29 Jan 2018 12:51:23 +0530 Message-Id: <5c514d244ce5b3f7f94d8675fcd64c58fba09417.1517210263.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.15.0.194.g9af6a3dea062 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: "Rafael J. Wysocki" [ Upstream commit 56026645e2b6f11ede34a5e6ab69d3eb56f9c8fc ] After commit aa7519af450d (cpufreq: Use transition_delay_us for legacy governors as well) the sampling_rate field of struct dbs_data may be less than the tick period which causes dbs_update() to produce incorrect results, so make the code ensure that the value of that field will always be sufficiently large. Cc: 4.14 # 4.14 Fixes: aa7519af450d (cpufreq: Use transition_delay_us for legacy governors as well) Reported-by: Andy Tang Reported-by: Doug Smythies Tested-by: Andy Tang Signed-off-by: Rafael J. Wysocki Acked-by: Viresh Kumar --- drivers/cpufreq/cpufreq_governor.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) -- 2.15.0.194.g9af6a3dea062 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c index 58d4f4e1ad6a..ca38229b045a 100644 --- a/drivers/cpufreq/cpufreq_governor.c +++ b/drivers/cpufreq/cpufreq_governor.c @@ -22,6 +22,8 @@ #include "cpufreq_governor.h" +#define CPUFREQ_DBS_MIN_SAMPLING_INTERVAL (2 * TICK_NSEC / NSEC_PER_USEC) + static DEFINE_PER_CPU(struct cpu_dbs_info, cpu_dbs); static DEFINE_MUTEX(gov_dbs_data_mutex); @@ -47,11 +49,15 @@ ssize_t store_sampling_rate(struct gov_attr_set *attr_set, const char *buf, { struct dbs_data *dbs_data = to_dbs_data(attr_set); struct policy_dbs_info *policy_dbs; + unsigned int sampling_interval; int ret; - ret = sscanf(buf, "%u", &dbs_data->sampling_rate); - if (ret != 1) + + ret = sscanf(buf, "%u", &sampling_interval); + if (ret != 1 || sampling_interval < CPUFREQ_DBS_MIN_SAMPLING_INTERVAL) return -EINVAL; + dbs_data->sampling_rate = sampling_interval; + /* * We are operating under dbs_data->mutex and so the list and its * entries can't be freed concurrently. @@ -430,7 +436,14 @@ int cpufreq_dbs_governor_init(struct cpufreq_policy *policy) if (ret) goto free_policy_dbs_info; - dbs_data->sampling_rate = cpufreq_policy_transition_delay_us(policy); + /* + * The sampling interval should not be less than the transition latency + * of the CPU and it also cannot be too small for dbs_update() to work + * correctly. + */ + dbs_data->sampling_rate = max_t(unsigned int, + CPUFREQ_DBS_MIN_SAMPLING_INTERVAL, + cpufreq_policy_transition_delay_us(policy)); if (!have_governor_per_policy()) gov->gdbs_data = dbs_data;