From patchwork Wed Sep 2 07:24:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 248960 Delivered-To: patch@linaro.org Received: by 2002:a92:5b9c:0:0:0:0:0 with SMTP id c28csp190900ilg; Wed, 2 Sep 2020 00:25:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRQY8Ry69aYoREz9HB2FyK3HW+rbVmCNu55AjvPzn5x2ZFMC5Vw+bh3v8w31ltnJ9AMGv1 X-Received: by 2002:a05:6402:3193:: with SMTP id di19mr3833572edb.211.1599031507020; Wed, 02 Sep 2020 00:25:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599031507; cv=none; d=google.com; s=arc-20160816; b=Zx8qeyOORFg2S73gPvuUrZAM7GLfLuQ1xt86W5o/Emhslp0dzT4Fupesxdu+3AbNsC Pvi+TOi951nMT9F4B8Nc7cqA3RBi5mX3YzUu7DqS4iPG9xlaZQM6AeO16jHhQgtP3HKq ruxbyGYMu1kcj0jz8VcXb0igwcNCaaRBC26HK5LwgHM7wmZMhmC9ME/imWBqftwfOQsE b0RuN6r7k6ckyooqmEHSEzdCMyI7z5eNRP7rRrNn0zRvferDu3J/eNkouKQj1fvnn+0u mkYWl4PYxr1aqxMXb5I/MTTMyGt5zbErQaAyzFmTWo0zQrCXlvK6FZR820VWISf0mBIs dQEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ABESP1WCpoqEOc5UMRR48HLj5tlVp8CRML1h3CxuOlI=; b=EgjSIa06ioOC25HyNWjMDCOW+ObGy8YalGN9ybApJyPP+pdAYhuru6s5+tz8JWRRGI HBOzww9qZfTpKvu0n88/IPg/h/UAyi2m9cRoYWyfr07alzjgNvsjPJmjFnjYbgbaaaUz mOKKVuqzgpkM/c/1WTYE+dPfOB5BmtFU7qtMWId+XCrrwk4f3OocAsBOd/zoj9hVEKKK bXN09XZrmnlZsxpEnjz8FsvFHv6Q0Jr7+lSI+EjWmyzkzxzLO+w0ZrqWVpitCblyvGC4 PzvNv3DwmcL3m8QdZmmvgaElt+XQVQYWvh2gdF6rkXY+zYZXKuUcxmaIkk9OQCW1sQZR TFQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wGxNf6Vs; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-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. [23.128.96.18]) by mx.google.com with ESMTP id d3si2053372edo.152.2020.09.02.00.25.06; Wed, 02 Sep 2020 00:25:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wGxNf6Vs; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-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 S1727800AbgIBHZF (ORCPT + 10 others); Wed, 2 Sep 2020 03:25:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726130AbgIBHZC (ORCPT ); Wed, 2 Sep 2020 03:25:02 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AA33C061244 for ; Wed, 2 Sep 2020 00:25:02 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id a8so1887748plm.2 for ; Wed, 02 Sep 2020 00:25:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ABESP1WCpoqEOc5UMRR48HLj5tlVp8CRML1h3CxuOlI=; b=wGxNf6Vsr62NPWa9sSB8S86EkWPBNSXgc+Mq4pYSYwOjt+pAPY1oLH3kvydFsr1iJ6 NfKN7CUnj5um2Nd6UCMKbfQwnuxsCjYK5MFbMlqfy4mJdIjJm9M80Dtzu9KEzyBlfSNx Q3BrUEzI+6/FF1cKf1HLvjrBSWlEGXv/tCyDRsGSxYmtjssLlqitl3emPTWxv4dGWpp6 jLjT2KT+A+hFx9POyyZQjeDo+h3Q7Wdg2wAVF+FbKFms/BzkVmBglDx+zLbLTcHhbUta 0vElNjHI6rFORD19g0oO4hX+AvtkwB+AVoGsi1h7Yj6zXCDyol0yaT5ZwWqJowyD9mZX TvDw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=ABESP1WCpoqEOc5UMRR48HLj5tlVp8CRML1h3CxuOlI=; b=PGgiwhsJ+xafJP8b5pF5lnrwKW3/k5qiYUl2RbXJwevgYYSo6hQldSRLWkX0gweqt0 qncMKtuL+EzfnnNuv6oRM1Jw7YlVBEr2Qtq0E7p3rA5nSY7hRmnmI3w24v/yEWXv0x9v Ebdg46YUMvzMmvQgoyMdLaaFnkg0Mwuops7qfPB01ALVSsAfyxCTANad6aTvmDQnp6M8 XCsziqf2q5/2ApqSKlq0C5I2GBfyYBUs18PoQZJVCJUCX5GVFJKQ6Vjok3qhgh6Hoyoj /edruWXLnvAq5CVgKsAGXQ+Sg0N9iw3EWyef9OfBNKkoAZ88Rn7PhBxrrk28FyX8MgjQ UMmQ== X-Gm-Message-State: AOAM532jXY1VqTITSRzuA0pi6xYWIxFBnGfah0gTn0IFa+MBQcLR8R3E mufqRbmTOAO8cLw3kuA9xi1kVQ== X-Received: by 2002:a17:902:758d:: with SMTP id j13mr1016597pll.174.1599031501559; Wed, 02 Sep 2020 00:25:01 -0700 (PDT) Received: from localhost ([122.167.135.199]) by smtp.gmail.com with ESMTPSA id e12sm3534433pjd.55.2020.09.02.00.25.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Sep 2020 00:25:00 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Viresh Kumar Cc: linux-pm@vger.kernel.org, Vincent Guittot , Lukasz Luba , cristian.marussi@arm.com, sudeep.holla@arm.com, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] cpufreq: stats: Defer stats update to cpufreq_stats_record_transition() Date: Wed, 2 Sep 2020 12:54:41 +0530 Message-Id: <973bd0536c4957d03f36447398498cfacb2393d9.1599031227.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org In order to prepare for lock-less stats update, add support to defer any updates to it until cpufreq_stats_record_transition() is called. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq_stats.c | 75 ++++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 19 deletions(-) -- 2.25.0.rc1.19.g042ed3e048af diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c index 94d959a8e954..fdf9e8556a49 100644 --- a/drivers/cpufreq/cpufreq_stats.c +++ b/drivers/cpufreq/cpufreq_stats.c @@ -22,17 +22,22 @@ struct cpufreq_stats { spinlock_t lock; unsigned int *freq_table; unsigned int *trans_table; + + /* Deferred reset */ + atomic_t reset_pending; + unsigned long long reset_time; }; -static void cpufreq_stats_update(struct cpufreq_stats *stats) +static void cpufreq_stats_update(struct cpufreq_stats *stats, + unsigned long long time) { unsigned long long cur_time = get_jiffies_64(); - stats->time_in_state[stats->last_index] += cur_time - stats->last_time; + stats->time_in_state[stats->last_index] += cur_time - time; stats->last_time = cur_time; } -static void cpufreq_stats_clear_table(struct cpufreq_stats *stats) +static void cpufreq_stats_reset_table(struct cpufreq_stats *stats) { unsigned int count = stats->max_state; @@ -41,42 +46,67 @@ static void cpufreq_stats_clear_table(struct cpufreq_stats *stats) memset(stats->trans_table, 0, count * count * sizeof(int)); stats->last_time = get_jiffies_64(); stats->total_trans = 0; + + /* Adjust for the time elapsed since reset was requested */ + atomic_set(&stats->reset_pending, 0); + cpufreq_stats_update(stats, stats->reset_time); spin_unlock(&stats->lock); } static ssize_t show_total_trans(struct cpufreq_policy *policy, char *buf) { - return sprintf(buf, "%d\n", policy->stats->total_trans); + struct cpufreq_stats *stats = policy->stats; + + if (atomic_read(&stats->reset_pending)) + return sprintf(buf, "%d\n", 0); + else + return sprintf(buf, "%d\n", stats->total_trans); } cpufreq_freq_attr_ro(total_trans); static ssize_t show_time_in_state(struct cpufreq_policy *policy, char *buf) { struct cpufreq_stats *stats = policy->stats; + bool pending = atomic_read(&stats->reset_pending); + unsigned long long time; ssize_t len = 0; int i; if (policy->fast_switch_enabled) return 0; - spin_lock(&stats->lock); - cpufreq_stats_update(stats); - spin_unlock(&stats->lock); - for (i = 0; i < stats->state_num; i++) { + if (pending) { + if (i == stats->last_index) + time = get_jiffies_64() - stats->reset_time; + else + time = 0; + } else { + time = stats->time_in_state[i]; + if (i == stats->last_index) + time += get_jiffies_64() - stats->last_time; + } + len += sprintf(buf + len, "%u %llu\n", stats->freq_table[i], - (unsigned long long) - jiffies_64_to_clock_t(stats->time_in_state[i])); + jiffies_64_to_clock_t(time)); } return len; } cpufreq_freq_attr_ro(time_in_state); +/* We don't care what is written to the attribute */ static ssize_t store_reset(struct cpufreq_policy *policy, const char *buf, size_t count) { - /* We don't care what is written to the attribute. */ - cpufreq_stats_clear_table(policy->stats); + struct cpufreq_stats *stats = policy->stats; + + /* + * Defer resetting of stats to cpufreq_stats_record_transition() to + * avoid races. + */ + atomic_set(&stats->reset_pending, 1); + stats->reset_time = get_jiffies_64(); + return count; } cpufreq_freq_attr_wo(reset); @@ -84,8 +114,9 @@ cpufreq_freq_attr_wo(reset); static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf) { struct cpufreq_stats *stats = policy->stats; + bool pending = atomic_read(&stats->reset_pending); ssize_t len = 0; - int i, j; + int i, j, count; if (policy->fast_switch_enabled) return 0; @@ -113,8 +144,13 @@ static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf) for (j = 0; j < stats->state_num; j++) { if (len >= PAGE_SIZE) break; - len += scnprintf(buf + len, PAGE_SIZE - len, "%9u ", - stats->trans_table[i*stats->max_state+j]); + + if (pending) + count = 0; + else + count = stats->trans_table[i * stats->max_state + j]; + + len += scnprintf(buf + len, PAGE_SIZE - len, "%9u ", count); } if (len >= PAGE_SIZE) break; @@ -228,10 +264,11 @@ void cpufreq_stats_record_transition(struct cpufreq_policy *policy, struct cpufreq_stats *stats = policy->stats; int old_index, new_index; - if (!stats) { - pr_debug("%s: No stats found\n", __func__); + if (!stats) return; - } + + if (atomic_read(&stats->reset_pending)) + cpufreq_stats_reset_table(stats); old_index = stats->last_index; new_index = freq_table_get_index(stats, new_freq); @@ -241,7 +278,7 @@ void cpufreq_stats_record_transition(struct cpufreq_policy *policy, return; spin_lock(&stats->lock); - cpufreq_stats_update(stats); + cpufreq_stats_update(stats, stats->last_time); stats->last_index = new_index; stats->trans_table[old_index * stats->max_state + new_index]++; From patchwork Wed Sep 2 07:24:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 248963 Delivered-To: patch@linaro.org Received: by 2002:a92:5b9c:0:0:0:0:0 with SMTP id c28csp191220ilg; Wed, 2 Sep 2020 00:25:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyC6p9VVsJnctZaucCG0o3jjOAKZnC8RAUL6gJoZihQCm8rd4a75golScHAAhsmZVHn84aX X-Received: by 2002:a05:6402:1b9a:: with SMTP id cc26mr3688606edb.30.1599031547168; Wed, 02 Sep 2020 00:25:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599031547; cv=none; d=google.com; s=arc-20160816; b=rX1efVZEH4e2g6tnW9/syXwIcn6nVIK1eZFPgyWohgkPE0KxQhPnWkTijcI4egmh1J D26s8yo3H0Gc0fhZPN9mhcFsPvmqLZxkQUypoqkiiI22L0Svd4hFrG3hva5keQKO246U q/gmiyqWu4PSXmfMcJ+/BUziR0Gr31EJimn5DZvW2UZJ5qtEr4c7WhSFfRGoM0Mj/937 FWDJeLS+wJ3T/nSxxAJtskncunKoweAIP+FL+zPF2fT2CxL6EpVdLNB6IgyIv4vqxqBo UfiTVXb4Wqbep/SWbSjIKMvjJSVoKzLxlOdh7hgJtWGa2aiB3SR6f+HD9FUtMok+Bhm3 J7FQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+tJBzI8lB5wRp0GmHPQXlUe4WhX44ejADtz0Zhvnig4=; b=VqiJULGPhVZiv88blZMXuanZryUd/3gBsZsO7G/J3qQTg/PUjcEyrEtvjgPYqfcI7Z QoyPuaEg8K7j6OJEfpD2YjlWFPpQIJAU/fCmPYDzD39bF8J789HH7tAMvaxT4FxUT5UU j8gUv2I/mdaTLCAQs1/OX7kzTVmJmdAl0/xMlQ6XqVWP3L/7Zha43YffoGlkG6wlKwIn F3VW3VEY8a/efi/jkm33btogoWzH+G4A+Fdo9jlcyegHSNkx2JEfV5MrKcYbmy49Cw3E HhxuLb7b8cDI6njQ00HZmUMo/NbLOgKcpjDa/A2DATqLZG2nSVBEn50EXM0HdTzKMWnW f2Uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aWhkyKDW; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-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. [23.128.96.18]) by mx.google.com with ESMTP id u1si1925801eda.219.2020.09.02.00.25.47; Wed, 02 Sep 2020 00:25:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aWhkyKDW; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-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 S1727801AbgIBHZG (ORCPT + 10 others); Wed, 2 Sep 2020 03:25:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726247AbgIBHZF (ORCPT ); Wed, 2 Sep 2020 03:25:05 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04672C061246 for ; Wed, 2 Sep 2020 00:25:05 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id ds1so1953445pjb.1 for ; Wed, 02 Sep 2020 00:25:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+tJBzI8lB5wRp0GmHPQXlUe4WhX44ejADtz0Zhvnig4=; b=aWhkyKDWAf5betm7xqDa2cSgBjrX/ykPr83ItMwjnU8aSuoXBr6L5cgQA2wfKMApbI kw6gED2PvEapoNJZ5BuBEykbjCWuQVICq/DMqc9hIa3OSwLAOaTaa5GOiwPaoA4Lb3PP CT2A1RTX68yyGQtdLtMZBJUSgLmMs0jz2zo6bjcSIXqAnbk/LTUtwuA8UMskxth+Am+0 8orfpjeS8IeUv2Dxfxy3FxWqrxMYFukMWwuBF96mREo+fRklhDq/As1WbMpBJscIG3SD AIqPjjmMpZFmNZlVK5tf6Lr1TVOR/ynpstIrM7IQKckzLhg4Ot8zqA/EHZ93B2YMxY9z BBIA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=+tJBzI8lB5wRp0GmHPQXlUe4WhX44ejADtz0Zhvnig4=; b=me1SWiYA6rLizbMYX20zB2GvUu8AtWx/BKmGJ17znfaxnxDtDXMYCGrcgF7h2ROLMM BV+qZq1rFcYkbMD5WOfZznolV30iSdQW5JycBmgphMd8mE9HiC5XINxuAXr4RJEjFZ9z /x3YZzhmPmEE5KWphuVUgiMHmeWS7o/YO4QSXZFFj5XKGKAX/ZC+vFhQt+0MJi3Rsj8z Q01YqJ11jgo3Tm9mcitkRhGPAbjKUWNrsSISOqd/rsLx5bPfYgimwPDRoyxXTHKGMxiD kM5E2h032Yjs4+L560VX27w6ZwQauW43JnbIir5JVCWqeBae+x/gM1R3Tami7SD+nMSH 6Kcg== X-Gm-Message-State: AOAM531+cRlt4CSBP9A0uRqiE2zNQF+eQ6TgDjEwgewskPc0vIW8PhhK 4qS/eLQi6A33yA0biml0MJAHYoUlfdUk2Q== X-Received: by 2002:a17:902:a50e:: with SMTP id s14mr1053168plq.164.1599031504547; Wed, 02 Sep 2020 00:25:04 -0700 (PDT) Received: from localhost ([122.167.135.199]) by smtp.gmail.com with ESMTPSA id h11sm4240987pgm.79.2020.09.02.00.25.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Sep 2020 00:25:03 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Viresh Kumar Cc: linux-pm@vger.kernel.org, Vincent Guittot , Lukasz Luba , cristian.marussi@arm.com, sudeep.holla@arm.com, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] cpufreq: stats: Remove locking Date: Wed, 2 Sep 2020 12:54:42 +0530 Message-Id: X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The locking isn't required anymore as stats can get updated only from one place at a time. Remove it. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq_stats.c | 6 ------ 1 file changed, 6 deletions(-) -- 2.25.0.rc1.19.g042ed3e048af diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c index fdf9e8556a49..d86ea9744649 100644 --- a/drivers/cpufreq/cpufreq_stats.c +++ b/drivers/cpufreq/cpufreq_stats.c @@ -19,7 +19,6 @@ struct cpufreq_stats { unsigned int state_num; unsigned int last_index; u64 *time_in_state; - spinlock_t lock; unsigned int *freq_table; unsigned int *trans_table; @@ -41,7 +40,6 @@ static void cpufreq_stats_reset_table(struct cpufreq_stats *stats) { unsigned int count = stats->max_state; - spin_lock(&stats->lock); memset(stats->time_in_state, 0, count * sizeof(u64)); memset(stats->trans_table, 0, count * count * sizeof(int)); stats->last_time = get_jiffies_64(); @@ -50,7 +48,6 @@ static void cpufreq_stats_reset_table(struct cpufreq_stats *stats) /* Adjust for the time elapsed since reset was requested */ atomic_set(&stats->reset_pending, 0); cpufreq_stats_update(stats, stats->reset_time); - spin_unlock(&stats->lock); } static ssize_t show_total_trans(struct cpufreq_policy *policy, char *buf) @@ -244,7 +241,6 @@ void cpufreq_stats_create_table(struct cpufreq_policy *policy) stats->state_num = i; stats->last_time = get_jiffies_64(); stats->last_index = freq_table_get_index(stats, policy->cur); - spin_lock_init(&stats->lock); policy->stats = stats; ret = sysfs_create_group(&policy->kobj, &stats_attr_group); @@ -277,11 +273,9 @@ void cpufreq_stats_record_transition(struct cpufreq_policy *policy, if (old_index == -1 || new_index == -1 || old_index == new_index) return; - spin_lock(&stats->lock); cpufreq_stats_update(stats, stats->last_time); stats->last_index = new_index; stats->trans_table[old_index * stats->max_state + new_index]++; stats->total_trans++; - spin_unlock(&stats->lock); } From patchwork Wed Sep 2 07:24:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 248962 Delivered-To: patch@linaro.org Received: by 2002:a92:5b9c:0:0:0:0:0 with SMTP id c28csp191206ilg; Wed, 2 Sep 2020 00:25:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrYnaDPLQyBxbBa67PUWtjMYiSmZNy59VIvJDnX8CKoQamr7LXnkGza4IHarXXh5USiYgf X-Received: by 2002:a17:906:1ed4:: with SMTP id m20mr5182862ejj.460.1599031545156; Wed, 02 Sep 2020 00:25:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599031545; cv=none; d=google.com; s=arc-20160816; b=UvbCqvU0fNSl6nqYWaGOg7X6fOCRUp4z3LkJsJ2Zwrb0QgZWYreQ3tybOyOebl7c0S vapDxS0G3Ino5+cKPlmMyFrFf+hDoioXrwheCFjUtkF6RhEfsxsNe7GPc2slYXb6zY47 m0gl+uwzwL+OeYXY3+o8q/ya4s7EG2OwaTFbcBTysR1ZB64Vk3FdXa02ay8p+WZZ2eRL vO3awAnODeQYzoGsw1vP4CYyVI9bQRfhbjgqpkPEjTcjp3z29NqSbKofK8gyW/vrFJPy JTvelU+CD4qSGhUXJLDaNhDQRfoD1fh3T3WkSu8YCwYHkyq7DdJtI5ECBENy5ZsIwwQC CORA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QakrURdUkg4E7FIP/CypxAR9NETwtzt47NN+BbaWNug=; b=lEU09DaH79EwWnPVywwP46yPQeBbnLQVoVmF6qBNG46jwWVX2pKRSAB/V4NiQ03oRI +b/YCIeZta8Y55HsY7ZXmJTASD0ApOo/Yl3OLHsudBgAr3YnfnmMIdZuoxS8vA7LLGtg 51pYURWr6AO0TVSqbOjoCs9SbZT0Q5hMOe/ISaJ6Zgsyez36iDFZ93XhEiq8f969NuGK OkPxxeQKmZK5UZdJdwOLQZp05QD4XmaY+IXX15WjKn33du94ABLDxlrN67+3JXLBBIYb lUWnfcW74rIRy4HSqkm5JJbFW1YKQMNcCsb0vYFZQ20KCg3ZZ0vbQVCs4Cgl52nTokaP Ykxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RWPSGWqX; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-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. [23.128.96.18]) by mx.google.com with ESMTP id u1si1925801eda.219.2020.09.02.00.25.44; Wed, 02 Sep 2020 00:25:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RWPSGWqX; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-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 S1726312AbgIBHZm (ORCPT + 10 others); Wed, 2 Sep 2020 03:25:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727822AbgIBHZJ (ORCPT ); Wed, 2 Sep 2020 03:25:09 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31120C061245 for ; Wed, 2 Sep 2020 00:25:08 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id f18so2350462pfa.10 for ; Wed, 02 Sep 2020 00:25:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QakrURdUkg4E7FIP/CypxAR9NETwtzt47NN+BbaWNug=; b=RWPSGWqX08GKXFj5iHZkTa+y4XaDiqWxfL0yK70eGkiIQN/S+3ikTN0IFRwKKzRIyd Ej9S4ynaTJ8vNfXb1YWWnbA3UTwhzXnj0zsmh4prkdWZFzYo0tPp9PWLbx33SVHDDTaK hnL/GS/yLVwSq7nixL0qoJPEOxAbKkRI37eZTn//vbrdPQM5eIPVB67m4BQ5azV4JvmP /MP14dCT6xZe3lW9hFQJRu6dmVgpI2yqe1PBG9cLmX+jmK+RIMV/IXgNBQQ+SYJpcdRy h4a8vAsrw+ByO0Bi346aRy9Kkhcut78cS0bAtFECh5KYUSzsMjr5oQWOa1OXVY2fhD5t dcRw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=QakrURdUkg4E7FIP/CypxAR9NETwtzt47NN+BbaWNug=; b=tV5bZpaKMS3BIanQvxPrNDxIDK+6SjEwoK67QFJCuZ5aEaRWQDe+RsIXfONk0iow0H EsYghrNDHbhyByRFZeV8XQAWAhLnmQ5xR0M2ScegRtRnVMfr2ch60dP8UWrWHmemRw/q L5iCYF0jfxQP/G0QCckYIvtHmDp4AVeND+81FAwFbMRQnRtdRPydCNVy6Q5qBlHKmVgc ZW9RStPJVwicbKMJK5FGMmVbjTWpN00aztV8qiemADBubvHpw2wobkWiCy6OHF6C6z7X YPLSt1PsJI1tK0QNH4bt57G9xPeTQQaGhYV9ddbViyXPddhgcuxwgnCZX6u/8CWaTIv/ C0ZQ== X-Gm-Message-State: AOAM5335eaDxW8vPwnrGC66p0slqpgeEYb1UyVE7BSCuPAa6ECdMDeSc 58cwxqaVBNbwdZA1Dw9HxrcWKg== X-Received: by 2002:aa7:8646:: with SMTP id a6mr2054058pfo.54.1599031507740; Wed, 02 Sep 2020 00:25:07 -0700 (PDT) Received: from localhost ([122.167.135.199]) by smtp.gmail.com with ESMTPSA id k5sm3656831pjq.5.2020.09.02.00.25.06 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Sep 2020 00:25:07 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Viresh Kumar Cc: linux-pm@vger.kernel.org, Vincent Guittot , Lukasz Luba , cristian.marussi@arm.com, sudeep.holla@arm.com, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] cpufreq: stats: Enable stats for fast-switch as well Date: Wed, 2 Sep 2020 12:54:43 +0530 Message-Id: <6a25f7c9c96dc25bb2acf26b4ab58ed954113965.1599031227.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Now that all the blockers are gone for enabling stats in fast-switching case, enable it. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 6 +++++- drivers/cpufreq/cpufreq_stats.c | 6 ------ 2 files changed, 5 insertions(+), 7 deletions(-) -- 2.25.0.rc1.19.g042ed3e048af diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 47aa90f9a7c2..d5fe64e96be9 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -2057,8 +2057,12 @@ unsigned int cpufreq_driver_fast_switch(struct cpufreq_policy *policy, unsigned int target_freq) { target_freq = clamp_val(target_freq, policy->min, policy->max); + target_freq = cpufreq_driver->fast_switch(policy, target_freq); - return cpufreq_driver->fast_switch(policy, target_freq); + if (target_freq) + cpufreq_stats_record_transition(policy, target_freq); + + return target_freq; } EXPORT_SYMBOL_GPL(cpufreq_driver_fast_switch); diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c index d86ea9744649..06b5ee12f3b2 100644 --- a/drivers/cpufreq/cpufreq_stats.c +++ b/drivers/cpufreq/cpufreq_stats.c @@ -69,9 +69,6 @@ static ssize_t show_time_in_state(struct cpufreq_policy *policy, char *buf) ssize_t len = 0; int i; - if (policy->fast_switch_enabled) - return 0; - for (i = 0; i < stats->state_num; i++) { if (pending) { if (i == stats->last_index) @@ -115,9 +112,6 @@ static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf) ssize_t len = 0; int i, j, count; - if (policy->fast_switch_enabled) - return 0; - len += scnprintf(buf + len, PAGE_SIZE - len, " From : To\n"); len += scnprintf(buf + len, PAGE_SIZE - len, " : "); for (i = 0; i < stats->state_num; i++) { From patchwork Wed Sep 2 07:24:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 248961 Delivered-To: patch@linaro.org Received: by 2002:a92:5b9c:0:0:0:0:0 with SMTP id c28csp190958ilg; Wed, 2 Sep 2020 00:25:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwDmA0RGTTUk6d1MtdGH7FuT817MzUgFhKV/i2BOZtxaOMl52ZT2C1CNO0m0MrrxQ2/w/2W X-Received: by 2002:a50:f081:: with SMTP id v1mr5447167edl.161.1599031514544; Wed, 02 Sep 2020 00:25:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599031514; cv=none; d=google.com; s=arc-20160816; b=XccCrm92KPJcHF11skeZcdU/LNrPOS2gs0RXIJM1Sl01gBPizJ57l8eMSt32DtN8oJ KH/y7oRYS0ZuHGaAbYRFjAXx0qhiuPoXst2p5oDXv15QEUXueKyZ260TFMTuC+Jwem9L HEgKWJLlLaGMlGS4GrdGzTYwBhh8RlL6yED9RzR+1ZPK9B8Hl9NT5Bwrsx3wMqhKxrpf VzamJEJ/R2/8uH1RZfjPnTN9cwWLw6XNvAerdpV7sbA837vsV4kyzfM5AjiYRMlyihB2 G4ndktI3bGLKhXHzMyN6LrCzQ/vSqetVg+a1Q/0XRzghrvo19LH91zAO1Yqx/wD6vcy9 Pt3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=j9iUKTmxDCnsjI9D2FE0HYnpMw3U8pIfYBDaFqDjR3Y=; b=Cd5oWUWrdpz8HtaUECTZJ2v0w9plkm3F5Lcxb4R9A6yWto3iru8rlv0eAb8wmAHsj7 fHVrUBMN5OVi9lSImhGQejowpRQQzE2+AP+2qqcX8Gee0KpXQkkip4N4sr45RK73L5HN Nz8CUfGxFtavQNgIUPAgw4I5DLClAAa5Kwe4fmshL218z8nLsVqcqUx2CK764IWG3+Fz q9LsFw1rqTgvxMTh8Kw52lw77iOv1F/EX0/hMrTdSFhfB4KpYz9S5d3n859+La2iYPho PSF5WkziO5ILgXYbH7evYdQ7TVGjuDQkQdyW1hI9UDGmgMq7ppey6Nkce3woHjpuqLOU loHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kQt3TjnH; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-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. [23.128.96.18]) by mx.google.com with ESMTP id d3si2053372edo.152.2020.09.02.00.25.14; Wed, 02 Sep 2020 00:25:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kQt3TjnH; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-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 S1727845AbgIBHZN (ORCPT + 10 others); Wed, 2 Sep 2020 03:25:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727824AbgIBHZL (ORCPT ); Wed, 2 Sep 2020 03:25:11 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D41EC061244 for ; Wed, 2 Sep 2020 00:25:11 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id z15so1879198plo.7 for ; Wed, 02 Sep 2020 00:25:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=j9iUKTmxDCnsjI9D2FE0HYnpMw3U8pIfYBDaFqDjR3Y=; b=kQt3TjnH53yJTlq71MyV9vFyJS84thyJs1LOMPFhAgnL+ipFolq38cRsvGI+ZjULq6 5RnEoMl2TA4mjX6LGAcMMZ+xeaxxju8XuJTzD1CGCxCqkU8arjVrqUbyNv4iIXIjJJ4L V+T0vFkFUw5dr65LdX/ot8oYoZp3hP4nYxIDStJr0Hs5q7Gp0k/IBsa7LwX3qI1pMVNd B3Z7lbgLwLX2twOpkdBrUkV7SrkZs8sSIOb55vdq/CCvueQrqpomorSlFMJKqnKx8no5 rNlggaim9Pl0tkHcjliy+/zKU1KXD7FA2zpKIJuydPc3iUtlMKCdKiKGEkrI9yP57VB0 cGNA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=j9iUKTmxDCnsjI9D2FE0HYnpMw3U8pIfYBDaFqDjR3Y=; b=Eq2N+Ls3JlFypw8XOU5fv67j9U/Lu0VVKjBv2rwcTMRoH7uOkgr6BOzRUb97zPswL4 Y8kVeqA7512qG5m7eMK7pCG4FedHEGKf1gMEud5FgO/q1UkgBIYF2MhugVprflWjuqfN hVUCGc1DClMLZz/bhEZu+6Dg5ucUyFIZkRvYJtTQ6yqPh8/E2W3JBqULn8xIz+lgqDk/ 8eKwiFxct1qXHzAn1qyTun7s9CfACvt1jH+hPlaiYPjdkrcNTBC4fCjHEWjyyatAipk5 6hDaO8aE/p444VmmXptQxr4qatEkpJHEByBh86Z9oN2/pmAeAEaajGCFJeduQl5l8ces GFbQ== X-Gm-Message-State: AOAM532r7gEfzLTQqSvCJz/I/CoC5Pe5NkFdJIn5S/DBZ/q0Lj68Q+1P nDHmAwAw4cr4svXVJQ3SZlBaYg== X-Received: by 2002:a17:90a:d594:: with SMTP id v20mr1148478pju.227.1599031510786; Wed, 02 Sep 2020 00:25:10 -0700 (PDT) Received: from localhost ([122.167.135.199]) by smtp.gmail.com with ESMTPSA id y1sm4287781pgr.3.2020.09.02.00.25.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Sep 2020 00:25:10 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Viresh Kumar , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman Cc: linux-pm@vger.kernel.org, Lukasz Luba , cristian.marussi@arm.com, sudeep.holla@arm.com, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] cpufreq: Move traces and update to policy->cur to cpufreq core Date: Wed, 2 Sep 2020 12:54:44 +0530 Message-Id: <3f76b8bb243d522be5d858cbdf7f676b0e1f9e96.1599031227.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The cpufreq core handles the updates to policy->cur and recording of cpufreq trace events for all the governors except schedutil's fast switch case. Move that as well to cpufreq core for consistency and readability. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 14 ++++++++++++-- kernel/sched/cpufreq_schedutil.c | 12 +----------- 2 files changed, 13 insertions(+), 13 deletions(-) -- 2.25.0.rc1.19.g042ed3e048af diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index d5fe64e96be9..bc930f6ecff6 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -2056,11 +2056,21 @@ EXPORT_SYMBOL(cpufreq_unregister_notifier); unsigned int cpufreq_driver_fast_switch(struct cpufreq_policy *policy, unsigned int target_freq) { + int cpu; + target_freq = clamp_val(target_freq, policy->min, policy->max); target_freq = cpufreq_driver->fast_switch(policy, target_freq); - if (target_freq) - cpufreq_stats_record_transition(policy, target_freq); + if (!target_freq) + return 0; + + policy->cur = target_freq; + cpufreq_stats_record_transition(policy, target_freq); + + if (trace_cpu_frequency_enabled()) { + for_each_cpu(cpu, policy->cpus) + trace_cpu_frequency(target_freq, cpu); + } return target_freq; } diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index e39008242cf4..28f6d1ad608b 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -115,21 +115,11 @@ static void sugov_fast_switch(struct sugov_policy *sg_policy, u64 time, unsigned int next_freq) { struct cpufreq_policy *policy = sg_policy->policy; - int cpu; if (!sugov_update_next_freq(sg_policy, time, next_freq)) return; - next_freq = cpufreq_driver_fast_switch(policy, next_freq); - if (!next_freq) - return; - - policy->cur = next_freq; - - if (trace_cpu_frequency_enabled()) { - for_each_cpu(cpu, policy->cpus) - trace_cpu_frequency(next_freq, cpu); - } + cpufreq_driver_fast_switch(policy, next_freq); } static void sugov_deferred_update(struct sugov_policy *sg_policy, u64 time,