From patchwork Wed Sep 16 06:45:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11779129 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3BB4E59D for ; Wed, 16 Sep 2020 06:45:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 18F8520770 for ; Wed, 16 Sep 2020 06:45:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="n+szBhQ/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726210AbgIPGps (ORCPT ); Wed, 16 Sep 2020 02:45:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726189AbgIPGpr (ORCPT ); Wed, 16 Sep 2020 02:45:47 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0E77C061788 for ; Tue, 15 Sep 2020 23:45:46 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id mm21so1056811pjb.4 for ; Tue, 15 Sep 2020 23:45:46 -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=eVoj/Y7hhEmWcOFF7SkEdYZfa2skHwatr+eS0o7Q9yk=; b=n+szBhQ/7hLOh3i8vQAg7nmEUOn/cXc5TXnyfxzZEitj/nyEyJyEP2jCyGxE9Sv5T9 e2VmbDKzMs3liv8Pzc4XkUsF0OeCJVb3Y/5B8R0dziN8MQYeXPpqhVg4M7EfcOSwWoKV qcWblFbTv/eHecb9sRu5TILzCukoXdEgQEGRNWprxAbSNY66jt3zVPb9klsM1kf7zyJq t40SyHfHQUrHpCk1XWtdyhlqmgUNYDtvLWs4eMPV+q1PQtHSG8VhwcEk6XFIYLynN/U9 06tOy+rbumit3iRseFtPFjE/xE5jwLK4fYnchCliiPJ0eXDibtSt/bUMLXl8uj7SXYLG GLNw== 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=eVoj/Y7hhEmWcOFF7SkEdYZfa2skHwatr+eS0o7Q9yk=; b=TFHhzB6GgAePgbPN3SUW+nLiqBe8j+0dXUE5rp1Ln4JvV0wxXdBDyQDTQ+TbjqIshT xgJODhZt4ZCtEvpds/I1k8gdgZiyIOZZyLWq4uFO3B+mPhj2aA5uE8e9CuHmepvOIZwR 7rJtcxpsc6lYMtzssjkwLMrrH6eB5Jhc3USDXSXAUKcZB2A7hLJdlziwGRkYJ+TD+CLm Wu6I1CdDW6E3lYQXBWqOZCDhehelbN+1z9LNSrr5EuAXtWqnN8lahgYil2y7ZMypl/IN 6NarUihql6Litymf6J8rJOx8w6AW5FhUSG+N3GIsbKaAR9DGDLNJ4vuGNy2pK1GdG117 ZVJg== X-Gm-Message-State: AOAM532wip+hNFM+c1jUj7KO82Jmg46YNUoDXeMUHxnv2shoH9d/m2h+ OsjQg40eVrCxrvYyu0YjeAwE8Q== X-Google-Smtp-Source: ABdhPJwYSxPJhKE9AWiA5IBejWBYN+GiAYyaL9vZu/cmrDJZ8jZfy5LbHajV2rLB7DeIWFauGzxbhg== X-Received: by 2002:a17:90a:f117:: with SMTP id cc23mr2627310pjb.155.1600238746495; Tue, 15 Sep 2020 23:45:46 -0700 (PDT) Received: from localhost ([122.181.54.133]) by smtp.gmail.com with ESMTPSA id a27sm15586944pfk.52.2020.09.15.23.45.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Sep 2020 23:45:45 -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 V2 1/4] cpufreq: stats: Defer stats update to cpufreq_stats_record_transition() Date: Wed, 16 Sep 2020 12:15:28 +0530 Message-Id: <31999d801bfb4d8063dc1ceec1234b6b80b4ae68.1600238586.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(-) diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c index 94d959a8e954..3e7eee29ee86 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 */ + unsigned int 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 */ + WRITE_ONCE(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 (READ_ONCE(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 = READ_ONCE(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. + */ + WRITE_ONCE(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 = READ_ONCE(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 (READ_ONCE(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 16 06:45:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11779131 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 45FD559D for ; Wed, 16 Sep 2020 06:46:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2720320936 for ; Wed, 16 Sep 2020 06:46:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="n2XHtFO9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726321AbgIPGp7 (ORCPT ); Wed, 16 Sep 2020 02:45:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726100AbgIPGpv (ORCPT ); Wed, 16 Sep 2020 02:45:51 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5703C06174A for ; Tue, 15 Sep 2020 23:45:49 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id v14so1026018pjd.4 for ; Tue, 15 Sep 2020 23:45:49 -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=hZYCz5nzNahLD9wsdHTKADWsrq22uAWjN70xaMi6z60=; b=n2XHtFO9+VtbH/rlGPlB4k4m2Tlk1t+XAlgn/+W/9KolZcZ/wbfFx+FBCfDYKoM8Y+ QqvBTdFfFTBwWFY3p8C7N0gKWAycS8Ov0T1gK8rdXYolO34yYi5JtrFssFI/welnC+p5 l4/XLfLa7BRm/V0TgL3v6++Mp/ViknUGx90pUVo+odHSeXoNdXcKFytsQMC7q97op0PA 9DP5qLVUVMUnvCMaQtikQOagPILRRsi/CCdKQfxgGnjd8s/HO3uJtQRJLGsBbL07GMpp fzcHCFQ0hR4LT8/iV8qx3s/RTtzmXbUKphL+31S9rpot7mgKZzfHK06n0oor9bJzUB8s R1og== 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=hZYCz5nzNahLD9wsdHTKADWsrq22uAWjN70xaMi6z60=; b=YUEsvpnfvp8G6wxllPMMjRR8tZ8bPbMr+4QaDQuUvY/Da92mYPYZ5HzCoSl/DqhmxN janUNwPegSC/hb+0N2f8YDAb8QfgoYlhEzmuxTgpCJP4FsWoe5LfnQ29Vx8BbBYh/klo O7fBD4zHFmPe7GgPs5JEssr/1Gfeh01dFXP6FI9xJxPJ5+c0Eh0dyJUSac8qwQqS3tfe 9i/Up8rY0u1mII6wwMCamIFyATu1M8QfYWdW8UxwA1FOZmakT4+2AVU0Y5R+u0xYR7vS qhASK7gJzXocXfwLuWp1RvPgE0hgbUib/4onxuWeqzl4OHZpp5MGgWvqKur8DSDRLtis /ntg== X-Gm-Message-State: AOAM530bIegkqoCRjRCagb6/bPZJylDiZJhfSYyT4aQfbhsUT5uvN1mm GY2mhPi9TE+0ey5JtCtD88ZHjQ== X-Google-Smtp-Source: ABdhPJxB8nLngvmMpf3Pyv7Pfp2yrzRvcH3mr/M62gU4ciHkgNYxsRm3TMFyh056FAcIMRiQ1AiqqA== X-Received: by 2002:a17:902:aa49:b029:d0:cbe1:e7b3 with SMTP id c9-20020a170902aa49b02900d0cbe1e7b3mr23073632plr.36.1600238749479; Tue, 15 Sep 2020 23:45:49 -0700 (PDT) Received: from localhost ([122.181.54.133]) by smtp.gmail.com with ESMTPSA id x3sm15458102pfq.49.2020.09.15.23.45.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Sep 2020 23:45:48 -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 V2 2/4] cpufreq: stats: Remove locking Date: Wed, 16 Sep 2020 12:15:29 +0530 Message-Id: <2b378277fe1acfd2567a3a639cc4d9b0292b99f7.1600238586.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 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(-) diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c index 3e7eee29ee86..314fa1d506d0 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 */ WRITE_ONCE(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 16 06:45:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11779133 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8C24D618 for ; Wed, 16 Sep 2020 06:46:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6B413221F0 for ; Wed, 16 Sep 2020 06:46:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="pv86wScJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726343AbgIPGqE (ORCPT ); Wed, 16 Sep 2020 02:46:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726307AbgIPGpx (ORCPT ); Wed, 16 Sep 2020 02:45:53 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08B7FC06178A for ; Tue, 15 Sep 2020 23:45:53 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id y6so2662771plt.9 for ; Tue, 15 Sep 2020 23:45:53 -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=McEf55q90LKX19rNTKkq9dZfRHRoQFlPTj7IjRPXpZk=; b=pv86wScJOEde8s9UC/74KhTAK9uJRxO43Wb7FdGsoH3TnuDTgoaCaNqNDjAVwRTtx/ kidu/cjHQUNSr0xC0VzVnBZ7vqAYETM5LD0AScTJS6TvdBGmhulR8RjnItFwH8eFfV0M KwRU1TVHtyDI5XnOnzToeXbju9xjxkRc3Eth7s0LkrFFF/q6HsOsZPbYhqlfI2bWT3ec Zykx9TF4yv5sRm30HAs7H+w3Zg51/7on3JvJyimXGOBq+zerFIYkEmrGzHSZLu6nT1qL z7QBTzmi14cEr6MkJ57c0TcscE/iX7NsvoTia6w+Q0YKcf36EX+UUSGUmq4H+UJCdioL Ksfg== 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=McEf55q90LKX19rNTKkq9dZfRHRoQFlPTj7IjRPXpZk=; b=ICfvPgFrsGtKIc7V2rebLmLQfxs1PmuMoTCSQFk6VWU2or+3c5/jK6a0+Z5XxDX5CH Bf5jFytAYmVMtoW/XQE3cKWUKR73mmV91pYOvocw5bF6/OVyRvrVveG5zxjfAiXLZAoc CamTGzWnG3VVjFdxUWt74uM9sXnbAE4ffCxP+u0CEyVmQTsokGylQ3Y9fIyQesjo9Msp 7XYUnDnOWAqECKlk7mYP7vKnKF+FBtLy8eAlaAO+WSHveYAPQEWi4JPMAa/t9aXtTPwf U20nkuggBOMaR1cIQhAS7/m9UXuXNDe+qE1Bs9Vc6MDbyaxyEGWvW+iRtxh3T4XOAkD5 yx4Q== X-Gm-Message-State: AOAM530A+yfWqUEEM+si1ssyPwM/nwOVMqRjzTqoNc7ITHiA9KAJBby/ um4Ffbip36rUlAlhznOKrdzqMw== X-Google-Smtp-Source: ABdhPJwAJfZFG7omNOVziytcj6Q6FgpVIo7pPO6hbQwG7kQBV4JaLfoZt743eQVXAJYsxTrFpNERjg== X-Received: by 2002:a17:902:e9d3:b029:d1:f370:1e90 with SMTP id 19-20020a170902e9d3b02900d1f3701e90mr157085plk.76.1600238752568; Tue, 15 Sep 2020 23:45:52 -0700 (PDT) Received: from localhost ([122.181.54.133]) by smtp.gmail.com with ESMTPSA id ml20sm1452102pjb.20.2020.09.15.23.45.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Sep 2020 23:45:51 -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 V2 3/4] cpufreq: stats: Enable stats for fast-switch as well Date: Wed, 16 Sep 2020 12:15:30 +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 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(-) 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 314fa1d506d0..daea17f0c36c 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 16 06:45:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11779135 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A040F618 for ; Wed, 16 Sep 2020 06:46:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8266E20936 for ; Wed, 16 Sep 2020 06:46:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="uRZlRFdF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726359AbgIPGqI (ORCPT ); Wed, 16 Sep 2020 02:46:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726320AbgIPGp5 (ORCPT ); Wed, 16 Sep 2020 02:45:57 -0400 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62581C061797 for ; Tue, 15 Sep 2020 23:45:56 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id j34so3338030pgi.7 for ; Tue, 15 Sep 2020 23:45:56 -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=uRZlRFdFIqJ1hKepe6TwTT1ejfn2sNcY6FUbnxA60wp4fHk8d8BMKOGYFiKtliEDU7 nYTypBc7qrLNtqkCMI5Z2uC/fYXMqw9JwIc/ZGtKT6Jr2g6BzWabwwv05AJGDL75/z4G jdeMhtb9vgaumuOQlCfMAj/HHO0euaF6sNXj1azlUmDyirVJf6ZshZdrv5KkDVor80cX o9tucm5tMCET1BAjVyTBZEmjXfbG96qvgsxMxXCbzM/oM9C9ZobC3F3z4UeAABqjTPUf qCk3Lh8YBaiPeG3B5tIp2q6lovw5DshTPexPdgJqkzsyijV2X7LEb2OU6DcJepFIKOs9 6GcA== 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=ncwozEgf9XrM9M7/hK/+YODeiZL0WZP3c3s0jlqBQknrq5/siaF0VVE51cAPdpJ5Dl WfT5UC+fR/VSYE9FD0dnD9ANSrMZMD5NVUVRig79X7ww604RO37zEnMrApO7XGRyTgJ3 YGLTGzNDDHdqEcXAE03/bBq40E7QUxv+sfCevXrvjF+5i67bXeDDW4XGDBlPCrOmM535 JxgOuXtMZmcsi7ypbJ4fvsruCn6eoTpqnLDbNwDaI1E/r2Dd7J84/mlESF+c5+V9KTzP yOnED3vRFeikJ6GKgG+guyTa6INqx2CBBPtKI7uEl2cClMoW7qqaPh3vdjNNAs2PEP8/ WuBg== X-Gm-Message-State: AOAM530SEIL1gwkXTkAAiOn+tFvSdxoI1AEIE4daM2VGPfyboLRqjJOs Vn/hHZcMYtxXkq+amQxPu1kVtg== X-Google-Smtp-Source: ABdhPJwVMC2jV/RcJgnKKvnmqAu/+6fc/ErIlkFTDy2DRiHDhLQKMYj8C8Fvlw3g0vYlro33ZEceNQ== X-Received: by 2002:a63:e741:: with SMTP id j1mr17532251pgk.422.1600238755679; Tue, 15 Sep 2020 23:45:55 -0700 (PDT) Received: from localhost ([122.181.54.133]) by smtp.gmail.com with ESMTPSA id 143sm15783270pfc.66.2020.09.15.23.45.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Sep 2020 23:45:55 -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 V2 4/4] cpufreq: Move traces and update to policy->cur to cpufreq core Date: Wed, 16 Sep 2020 12:15:31 +0530 Message-Id: <875fc2c8d800f075c2faf925b04461b85362887a.1600238586.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(-) 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,