From patchwork Mon Oct 5 07:56:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 286854 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25A4AC4363A for ; Mon, 5 Oct 2020 07:56:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D45AF20756 for ; Mon, 5 Oct 2020 07:56:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="knhU6mtR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725942AbgJEH4h (ORCPT ); Mon, 5 Oct 2020 03:56:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725931AbgJEH4f (ORCPT ); Mon, 5 Oct 2020 03:56:35 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C293BC0613A6 for ; Mon, 5 Oct 2020 00:56:35 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id e10so5736772pfj.1 for ; Mon, 05 Oct 2020 00:56:35 -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=rXevW3gspEqrbAGRsrOKhUql5m0Aoc1FPHPDeVmOGB0=; b=knhU6mtRL+hMoixoMeE5z6HzTd6SQof8JiUtyCx1XosRHhlL0c5Fz2lzDh4WpWsrk+ hhechBFPkwZa5oUoTuNCk4fDbEHOhfApb1sM5HdWmiR7WGcpEyve7xw+xthFrHWpIlWY 7jwFPjZUBz5WLZSHSrHVghSOzeVDsrEKwfCuPC5qzZqJPuoUJVUWy2w+nNP/v9XUjMEO 3xMoRn2/2M4RImjukHEzwRRkIpyDFlL3aRcNBwskrq1PY2KtAOq23EWSlOxHVtiIU/EU K/Xz4W1P5xE6xOiVB40EnelI92yZl5YTdr8EcgYb5R6xSYQRBmhejpJT/V3cBs02XCVT BGZg== 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=rXevW3gspEqrbAGRsrOKhUql5m0Aoc1FPHPDeVmOGB0=; b=ZuZkURbMj/9aomxuk67JYYRgkxjgJWoGW4W97jhHZ00PexAAmvqS0LQEx8FEWHctqI cNELlYZ6YLeDQCO/VsFRwYUACMKhkCQQD8tPv/VMxXNig47xPhtVLXVm6nFMDAWvtcas BOfkylI1P0U33UJGZcHluARJz+ZgwGbR4ycEyFehPSkbwBG7OOA+r/GBNELyaDLctvUC 5BQCmvq8ycRwOHhln20gCISuCmxZIN4L2Ej+/0iGecGr6d9GNdqpijvDfGBOAg7NDA4e 7jMKjF/t8hAk62TcBr5W/fsTBLkroqjcXgGbJrsrZjzCpp84taZE7I2jgy2yj7wsbYGd qnLA== X-Gm-Message-State: AOAM530kj84CSJV5LAMfyOfWU/2VIqXfs0HlE3xd8rNHjfeiIfklF8Vj JiBeuiEzSyO/gBcq1b6QkcT/bAxFK27hDQ== X-Google-Smtp-Source: ABdhPJwGFoxTy7Ia4fihc+xAupy9E8rnHjAwhi5e5qj8gagwC1Dgw39Rp2LpAkYqkyC7bKzW4NjPPA== X-Received: by 2002:a63:d841:: with SMTP id k1mr13588737pgj.59.1601884595204; Mon, 05 Oct 2020 00:56:35 -0700 (PDT) Received: from localhost ([122.181.54.133]) by smtp.gmail.com with ESMTPSA id x12sm3497294pfr.156.2020.10.05.00.56.34 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Oct 2020 00:56:34 -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 V3 1/5] cpufreq: stats: Defer stats update to cpufreq_stats_record_transition() Date: Mon, 5 Oct 2020 13:26:01 +0530 Message-Id: <2570daf8931feeecd3ae94463f736e813c993fc0.1601884370.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: MIME-Version: 1.0 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. The stats were updated from two places earlier: - show_time_in_state(): This can be easily deferred, all we need is to calculate the delta duration again in this routine to show the current state's time-in-state. - store_reset(): This is a bit tricky as we need to clear the stats here and avoid races with simultaneous call to cpufreq_stats_record_transition(). This patch fixes it by deferring the reset of the stats (within the code) to the next call to cpufreq_stats_record_transition(), but since we need to keep showing the right stats until that time, we capture the reset time and account for the time since last time reset was called until the time cpufreq_stats_record_transition() update the stats. Userspace will continue seeing the stats correctly, everything will be 0 after the stats are reset, apart from the time-in-state of the current state, until the time a frequency switch happens. 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..498d962ba224 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, READ_ONCE(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() - READ_ONCE(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_time, get_jiffies_64()); + WRITE_ONCE(stats->reset_pending, 1); + 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 (unlikely(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 Mon Oct 5 07:56:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 267488 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B378C4363A for ; Mon, 5 Oct 2020 07:56:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BA7592075A for ; Mon, 5 Oct 2020 07:56:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="glhwHwWo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725972AbgJEH4m (ORCPT ); Mon, 5 Oct 2020 03:56:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725967AbgJEH4i (ORCPT ); Mon, 5 Oct 2020 03:56:38 -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 C0E58C0613A6 for ; Mon, 5 Oct 2020 00:56:38 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id g10so3049788pfc.8 for ; Mon, 05 Oct 2020 00:56:38 -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=J4qdGO1JzbarEAt5kXWVquFeUU4w8XJCRXx1wssOX40=; b=glhwHwWoSPB7vbpkNltzCZuIRGmvdyF6aRXSvux7O0gh5RDnah9YJzBYE9y2Xx44M/ zwHQJY+Fgh/LqIs5bqvnnxpiqx+pExQIHmT9Ll7y7kKqV3fxk+NcEsv3N9BSma9+eGWD o5wweXxZMJEBbpXKu2pV65Wxdz4yxYUEO69GSmfju/ZuaoSjSIcrjz+e4FJXifMSIgqH NaJ6vLSkY4c9IhJDFdQylXKYC+thaP7DlFZp24MQSrmulZs4IcJbkMdhLQF61BielJOS Uu6OnbbC2DfMp9xXIZtc+U3yAPJqZng/TqzzsONmA86UFq0l9i8i68hfRgzXA+eZz5SA TI3A== 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=J4qdGO1JzbarEAt5kXWVquFeUU4w8XJCRXx1wssOX40=; b=Zfmz1d7IvDVgY1jCCgs0sJtup5atj5974lFr0oIVQOYzzzwr52kplPPl2gxoRJ1V7Z OAYTN9w4OrM/hQULvEFgP7t7PyJEz5eKKhHdMCCtwrBlLBX0V7WtZtcMP9cRScXGN/nt BSOFgGcCKXcr7yjj4mcz77i02B0R4wb1TAhWi/0+ccPJXlBdftmS491ZrpkydqTJXhpx sqp4hs4MroFkCIW26fgW/DsLzRqeLEF3LUaPHEaGJjsDWoT987xIhiYwXSW18VhtgDPM l8P0BsW8bB+I6RRZ+3vohefY1z32ImU6m3AGGI0ptG1iM1DfinIOEsd231hN4FtYPtla CXwQ== X-Gm-Message-State: AOAM5323YqioWahIcfwpz/2tZEBsA02hUwhGy42XWrzTxxBkFnTiWcJz kISUOuyVMdvnllx3qmLQmNthwA== X-Google-Smtp-Source: ABdhPJxAPv4l/65ZQQxBev3hTwT1tahpTGcKOaCmgb9omR+AFrSB6szG8y8TZQb+6Qc7oC6P5QWnqg== X-Received: by 2002:a63:c547:: with SMTP id g7mr13254623pgd.234.1601884598314; Mon, 05 Oct 2020 00:56:38 -0700 (PDT) Received: from localhost ([122.181.54.133]) by smtp.gmail.com with ESMTPSA id n8sm9215326pff.188.2020.10.05.00.56.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Oct 2020 00:56:37 -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 V3 2/5] cpufreq: stats: Remove locking Date: Mon, 5 Oct 2020 13:26:02 +0530 Message-Id: X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: MIME-Version: 1.0 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 498d962ba224..45a067855367 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, READ_ONCE(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 Mon Oct 5 07:56:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 286853 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E23FEC4363A for ; Mon, 5 Oct 2020 07:56:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9D2FF20756 for ; Mon, 5 Oct 2020 07:56:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="hLbJsgCZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725977AbgJEH4m (ORCPT ); Mon, 5 Oct 2020 03:56:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725969AbgJEH4m (ORCPT ); Mon, 5 Oct 2020 03:56:42 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2C47C0613A8 for ; Mon, 5 Oct 2020 00:56:41 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id 34so5464612pgo.13 for ; Mon, 05 Oct 2020 00:56:41 -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=nYf6GPt1wRUI8w200qpKr/LuqlJa9al57JJ7Q+opvEQ=; b=hLbJsgCZapLKk39/1FZQk05+VxQTPVQ/ckuhiTIxrxmFV/QyEuRSE6lK3Dcjw/Ttqn UnlrYEshMpTMNfxszZk+OBg5SQaP5abwxlOFb/T6t7L/xK41J4YazhiL79Q+YMlhX84V G8Wl/cIdDjF7siv0rrPvJgBO7mesydHLLiVy7TW6baA2NcTX4n7eJSDnzj5pJjLqzyua dGCSv5KhJEzt6IGyXiXM/jfob8zu8oc3j2bqMuLMjrs8L6Y8z3h0R0SZkM+0iz8bankW Tx0yPYJENsA4Kd35xc7sbludoQlQecrIYmcqEhyCKGS0X21HN+ej37A1gZOskLRjIJaO bX3A== 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=nYf6GPt1wRUI8w200qpKr/LuqlJa9al57JJ7Q+opvEQ=; b=REphwcweFEJbzLFK3IUZoK9BnmG5eQ0zYkcfgwP1vG8Vx3kXyCNon/jzrsOOKqxJtI xgxiEsx9pCkG0MIkv0t3PHEtZ6r+cvEi+Du6hCupcKQ9Bli44L4jVY9eBvMmbg306CDI fnJwHHxad/jySPkp5j/AS6Kq63tQKoB3CNbUZghpOXRgMqoVr7NZPEnnSjwICXXu1P3J QA6/hGgRTvBFenFK6d2l/9wZfjHDLgByeWddHbZNRWZr1xEBG5vGMTs6hr/l2OfjBhmV KCZBz4MtoFNWBu2Yy0bzwNwCYmTOlxXjYi5nIkR9EpNY/kPnA4XMyX513bCLvwnYSP1F 9ksg== X-Gm-Message-State: AOAM53069x72EUOQx94e7cuo42nTVS42s8ywnPLe4/y0ycOzcEbqjgFg wXnluMENkPnpuiF0EkdOyU9Zjg== X-Google-Smtp-Source: ABdhPJy2AkqRQJNbK0grU2beG+3LdlZf199gBlJg2TQ13yIuW3jlQ2yx9MrZj/I0egK7qZw1Lg9X/Q== X-Received: by 2002:aa7:8e43:0:b029:151:3e50:afa6 with SMTP id d3-20020aa78e430000b02901513e50afa6mr6668641pfr.59.1601884601412; Mon, 05 Oct 2020 00:56:41 -0700 (PDT) Received: from localhost ([122.181.54.133]) by smtp.gmail.com with ESMTPSA id z1sm9798018pgu.80.2020.10.05.00.56.40 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Oct 2020 00:56:40 -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 V3 3/5] cpufreq: stats: Mark few conditionals with unlikely() Date: Mon, 5 Oct 2020 13:26:03 +0530 Message-Id: X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Since this will be part of scheduler's hotpath in some cases, use unlikely() for few of the obvious conditionals. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq_stats.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c index 45a067855367..bba04da3a278 100644 --- a/drivers/cpufreq/cpufreq_stats.c +++ b/drivers/cpufreq/cpufreq_stats.c @@ -260,7 +260,7 @@ void cpufreq_stats_record_transition(struct cpufreq_policy *policy, struct cpufreq_stats *stats = policy->stats; int old_index, new_index; - if (!stats) + if (unlikely(!stats)) return; if (unlikely(READ_ONCE(stats->reset_pending))) @@ -270,7 +270,7 @@ void cpufreq_stats_record_transition(struct cpufreq_policy *policy, new_index = freq_table_get_index(stats, new_freq); /* We can't do stats->time_in_state[-1]= .. */ - if (old_index == -1 || new_index == -1 || old_index == new_index) + if (unlikely(old_index == -1 || new_index == -1 || old_index == new_index)) return; cpufreq_stats_update(stats, stats->last_time); From patchwork Mon Oct 5 07:56:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 286852 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A4BBC4727D for ; Mon, 5 Oct 2020 07:56:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6246B20756 for ; Mon, 5 Oct 2020 07:56:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="mbbRT7rB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725997AbgJEH4r (ORCPT ); Mon, 5 Oct 2020 03:56:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725914AbgJEH4p (ORCPT ); Mon, 5 Oct 2020 03:56:45 -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 5149AC0613CE for ; Mon, 5 Oct 2020 00:56:45 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id gm14so5534675pjb.2 for ; Mon, 05 Oct 2020 00:56:45 -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=jct6+w41xsh8CGOaC++VC9dJ8A2Tl3u2I+mZjVCHvk8=; b=mbbRT7rBAgV6ecbWTKavQBOpoE061Jv30DV4WDRfOKAEwqdwF2OmQOEmOaDICv1BJT +Gvz93OLc6VYyBmQg5LXqc7llRYR/YvUBFRKZHn2iAwyv1edkhWl9T2ExRO68EliXHVW O4958C1O5gJs2OMZJ8GnFeOltptVtvQAeCzh3WI+BzOafBdWckIt+bpnvAsFNAWljAI7 p4oRUsDPTQm6Dc5ImYfWwLdqLCL4d57nMeaZieNC3j7Dwlggj1824G2i/Gdfx334VWt/ r4WWaZIMZivJQtTTdqSan9qOjgLnPKfpUd+Aowb8+fzZJvN9n5hB85M50jGDEtlz/Ndl XypQ== 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=jct6+w41xsh8CGOaC++VC9dJ8A2Tl3u2I+mZjVCHvk8=; b=jwCerBAEJRGBSxeVHlGC6/SLGXPaoiPCHt+8kB9d8ut9yzflAbfdtUlMfdtoyCpVN/ JiK0ZaipO1v2benLILP1AOTutpUcUGlIEfYO+zU92xXeRNjSfDWkWB/twGDsW0/exswb 4f4ZvDFgpK+LuPf1b09bNtR5pdgIbbvtoDkquFIpHNJn1H/AdAhZaHreWIJ9JUoyZugh Gq5eUPEVxbEtjZ2bOSNrN1cwgynAtk4XP0lS3/wY3nb0wldz4XqXGyCETLTotARM6Ny1 5e2RqaUnSMAD8vuWRq9oinplrk+8neToN/UHMfN8XvAixdC84b9RYtzpj4D/YF+1WbPn 614A== X-Gm-Message-State: AOAM533zNYrbDVstkALPOdhpxgjj2dbd0o2AWQF/Bu0R2x6PS9MA05G6 mFPr4/e+gLXQ5ABHFWBJXHiOyg== X-Google-Smtp-Source: ABdhPJwKZw+tKzueEcGgKMntoiwcfsTBTbjXiDNLJVhPXK9CMi28XfybBWUwf7tDphMpOuDMzYDZOw== X-Received: by 2002:a17:90b:1902:: with SMTP id mp2mr16335709pjb.176.1601884604738; Mon, 05 Oct 2020 00:56:44 -0700 (PDT) Received: from localhost ([122.181.54.133]) by smtp.gmail.com with ESMTPSA id j12sm9792366pjd.36.2020.10.05.00.56.43 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Oct 2020 00:56:44 -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 V3 4/5] cpufreq: stats: Enable stats for fast-switch as well Date: Mon, 5 Oct 2020 13:26:04 +0530 Message-Id: <2773c97ebdbd86b58b5577f6d060110a21b23e29.1601884370.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: MIME-Version: 1.0 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 | 4 ++++ drivers/cpufreq/cpufreq_stats.c | 6 ------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 2ea245a6c0c0..2d0e2e464b14 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -2072,8 +2072,12 @@ unsigned int cpufreq_driver_fast_switch(struct cpufreq_policy *policy, target_freq = clamp_val(target_freq, policy->min, policy->max); freq = cpufreq_driver->fast_switch(policy, target_freq); + if (!freq) + return 0; + arch_set_freq_scale(policy->related_cpus, freq, policy->cpuinfo.max_freq); + cpufreq_stats_record_transition(policy, freq); return freq; } diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c index bba04da3a278..8e7d64f34041 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 Mon Oct 5 07:56:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 267487 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3106C4363A for ; Mon, 5 Oct 2020 07:56:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7E67E20756 for ; Mon, 5 Oct 2020 07:56:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="IJH3N+4V" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726013AbgJEH4t (ORCPT ); Mon, 5 Oct 2020 03:56:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725995AbgJEH4t (ORCPT ); Mon, 5 Oct 2020 03:56:49 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47A9CC0613A6 for ; Mon, 5 Oct 2020 00:56:48 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id t14so5477506pgl.10 for ; Mon, 05 Oct 2020 00:56:48 -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=V24nFqUoLW4E3Th0MpyhsidyzVGENaV4KzeBs2bcktI=; b=IJH3N+4VTgKq/7yzzSibeAML3izyYdLrGuWTH3WTmV9f4KVaPgK8ma8n0pyl32oisR LMGx6FLS0wyiX4qm6cTxKwT1cEmZ6cyrhq2RrzcEfeg6ylmpwHzID2PoVLqdoMYO2OPW twbGV0dEeluBWu14lxxj9WinZIhNq6UsYMtnjb3+H7hAV5f+Xi/bkdqIgawWvQIhYERz sYTz1v8O1C1CbfV1FpUHhV1EzKttxLFjbybYVklM+p2jC8SxsrYSpI7X1ckPlnEaxxxi VbO2ogMSk//2i8lbwjBh4DQ+O9AQ0KcvXUy7I2RPyUDipux0iz0UX+PicwXWzxaYdyhu BK+g== 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=V24nFqUoLW4E3Th0MpyhsidyzVGENaV4KzeBs2bcktI=; b=gMX1l9pKomL0cSHWG9m07o69iqoHd/gww/CQMKykNPGTYTQcKMP6/nmV8ey8r4oLrp 1cfZlCQIVoIqxo8nnLWBJGPaZKT71tReDfLZn4nCw5dJerWUb1RihcSKs3nG1MRT5+iE aadxjM0wTorduXMI+hdLSravAezFPTMu/jTllmNRxXwz11TF/6CHiJHV+zqwC+nhKJrH qwrPdT4Zl8Od6CzrukxOCsUXk6v+Fy9yR5NiJhwtdB/PRDGI743uThFrx4hdxY8Ex7b2 OOtRcERi42HzymVxTHb3TRx+hcPDvR7Q9DhktTcHvtY+nYoWDpmPs7bgLq8ivtUXlsT+ tkRg== X-Gm-Message-State: AOAM53005YwBWruVGF3oBqFR1ZQDSYLJxfDw76B6GB8qpvBDeBF+Jmos FRzr6szpMOaLWcwHHktbG293lQ== X-Google-Smtp-Source: ABdhPJzEDI0+5SGijxUigKS4MKnFVsdoYLdCe5Hmr2YYhueCd/nXgFjF0qwlFmKyHaC0U8qepooiWQ== X-Received: by 2002:a65:60d0:: with SMTP id r16mr13871777pgv.348.1601884607804; Mon, 05 Oct 2020 00:56:47 -0700 (PDT) Received: from localhost ([122.181.54.133]) by smtp.gmail.com with ESMTPSA id z20sm9480873pjq.1.2020.10.05.00.56.46 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Oct 2020 00:56:47 -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 V3 5/5] cpufreq: Move traces and update to policy->cur to cpufreq core Date: Mon, 5 Oct 2020 13:26:05 +0530 Message-Id: X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: References: MIME-Version: 1.0 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 | 7 +++++++ kernel/sched/cpufreq_schedutil.c | 12 +----------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 2d0e2e464b14..db00693a586a 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -2068,6 +2068,7 @@ unsigned int cpufreq_driver_fast_switch(struct cpufreq_policy *policy, unsigned int target_freq) { unsigned int freq; + int cpu; target_freq = clamp_val(target_freq, policy->min, policy->max); freq = cpufreq_driver->fast_switch(policy, target_freq); @@ -2075,10 +2076,16 @@ unsigned int cpufreq_driver_fast_switch(struct cpufreq_policy *policy, if (!freq) return 0; + policy->cur = freq; arch_set_freq_scale(policy->related_cpus, freq, policy->cpuinfo.max_freq); cpufreq_stats_record_transition(policy, freq); + if (trace_cpu_frequency_enabled()) { + for_each_cpu(cpu, policy->cpus) + trace_cpu_frequency(freq, cpu); + } + return freq; } EXPORT_SYMBOL_GPL(cpufreq_driver_fast_switch); 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,