From: Chanwoo Choi <cw00.choi@samsung.com>
To: Viresh Kumar <viresh.kumar@linaro.org>
Cc: rjw@sisk.pl, linux-kernel@vger.kernel.org,
linux-pm@vger.kernel.org, cpufreq@vger.kernel.org,
kyungmin.park@samsung.com, myungjoo.ham@samsung.com
Subject: Re: [PATCH 2/3 v6] cpufreq: stats: Add 'load_table' debugfs file to show accumulated data of CPUs
Date: Wed, 24 Jul 2013 10:56:36 +0900 [thread overview]
Message-ID: <51EF3454.50807@samsung.com> (raw)
In-Reply-To: <CAKohponVEJv9e9V5qz+iugSMzu1zp1BeFf58W8m0qAV3_m6U1w@mail.gmail.com>
Hi Viresh,
On 07/22/2013 08:05 PM, Viresh Kumar wrote:
> On 18 July 2013 16:47, Chanwoo Choi <cw00.choi@samsung.com> wrote:
>> diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
>
>> +static int cpufreq_stats_reset_debugfs(struct cpufreq_policy *policy)
>> +{
>> + struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, policy->cpu);
>> + int size;
>> +
>> + if (!stat)
>> + return -EINVAL;
>> +
>> + if (stat->load_table)
>> + kfree(stat->load_table);
>> + stat->load_last_index = 0;
>> +
>> + size = sizeof(*stat->load_table) * stat->load_max_index;
>> + stat->load_table = kzalloc(size, GFP_KERNEL);
>> + if (!stat->load_table)
>> + return -ENOMEM;
>
> Why are you freeing memory and allocating it again ??
This purpose is reseting the data of stat->load_table.
If you don't agree this, I'll initizliae stat->load_table array as zero(0) with loop statement.
>
>> + return 0;
>> +}
>> +
>> +static int cpufreq_stats_create_debugfs(struct cpufreq_policy *policy)
>> +{
>> + struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, policy->cpu);
>> + unsigned int idx, size;
>> + int ret = 0;
>> +
>> + if (!stat)
>> + return -EINVAL;
>> +
>> + if (!policy->cpu_debugfs)
>> + return -EINVAL;
>> +
>> + stat->load_last_index = 0;
>> + stat->load_max_index = CONFIG_NR_CPU_LOAD_STORAGE;
>> +
>> + /* Allocate memory for storage of CPUs load */
>> + size = sizeof(*stat->load_table) * stat->load_max_index;
>> + stat->load_table = kzalloc(size, GFP_KERNEL);
>> + if (!stat->load_table)
>> + return -ENOMEM;
>> +
>> + /* Create debugfs directory and file for cpufreq */
>> + idx = cpumask_weight(policy->cpus) > 1 ? policy->cpu : 0;
>
> idx is broken again..
OK, I'll fix it.
>
>> + stat->debugfs_load_table = debugfs_create_file("load_table", S_IWUSR,
>> + policy->cpu_debugfs[idx],
>> + policy, &load_table_fops);
>> + if (!stat->debugfs_load_table) {
>> + ret = -ENOMEM;
>> + goto err;
>> + }
>> +
>> + pr_debug("Creating debugfs file for CPU%d \n", policy->cpu);
>
> s/Creating/Created
OK, I'll fixt it.
>
>> +
>> + return 0;
>> +err:
>> + kfree(stat->load_table);
>> + return ret;
>> +}
>> +
>> +/* should be called late in the CPU removal sequence so that the stats
>> + * memory is still available in case someone tries to use it.
>> + */
>
> Please write multiline comment correctly..
OK.
>
>> +static void cpufreq_stats_free_load_table(unsigned int cpu)
>> +{
>> + struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, cpu);
>> +
>> + if (stat) {
>> + pr_debug("Free memory of load_table\n");
>> + kfree(stat->load_table);
>> + }
>> +}
>> +
>> +/* must be called early in the CPU removal sequence (before
>> + * cpufreq_remove_dev) so that policy is still valid.
>> + */
>> +static void cpufreq_stats_free_debugfs(unsigned int cpu)
>> +{
>> + struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, cpu);
>> +
>> + if (stat) {
>> + pr_debug("Remove load_table debugfs file\n");
>> + debugfs_remove(stat->debugfs_load_table);
>> + }
>> +}
>> +
>> +static void cpufreq_stats_store_load_table(struct cpufreq_freqs *freq,
>> + unsigned long val)
>> +{
>> + struct cpufreq_stats *stat;
>> + int cpu, last_idx;
>> +
>> + stat = per_cpu(cpufreq_stats_table, freq->cpu);
>> + if (!stat)
>> + return;
>> +
>> + spin_lock(&cpufreq_stats_lock);
>> +
>> + switch (val) {
>> + case CPUFREQ_POSTCHANGE:
>> + if (!stat->load_last_index)
>> + last_idx = stat->load_max_index;
>> + else
>> + last_idx = stat->load_last_index - 1;
>> +
>> + stat->load_table[last_idx].new = freq->new;
>> + break;
>> + case CPUFREQ_LOADCHECK:
>> + last_idx = stat->load_last_index;
>> +
>> + stat->load_table[last_idx].time = freq->time;
>> + stat->load_table[last_idx].old = freq->old;
>> + stat->load_table[last_idx].new = freq->old;
>> + for_each_present_cpu(cpu)
>> + stat->load_table[last_idx].load[cpu] = freq->load[cpu];
>> +
>> + if (++stat->load_last_index == stat->load_max_index)
>> + stat->load_last_index = 0;
>> + break;
>> + }
>> +
>> + spin_unlock(&cpufreq_stats_lock);
>> +}
>> +
>> static int freq_table_get_index(struct cpufreq_stats *stat, unsigned int freq)
>> {
>> int index;
>> @@ -204,7 +386,7 @@ static int cpufreq_stats_create_table(struct cpufreq_policy *policy,
>> unsigned int alloc_size;
>> unsigned int cpu = policy->cpu;
>> if (per_cpu(cpufreq_stats_table, cpu))
>> - return -EBUSY;
>> + return 0;
>> stat = kzalloc(sizeof(struct cpufreq_stats), GFP_KERNEL);
>> if ((stat) == NULL)
>> return -ENOMEM;
>> @@ -257,6 +439,14 @@ static int cpufreq_stats_create_table(struct cpufreq_policy *policy,
>> spin_lock(&cpufreq_stats_lock);
>> stat->last_time = get_jiffies_64();
>> stat->last_index = freq_table_get_index(stat, policy->cur);
>> +
>> + ret = cpufreq_stats_create_debugfs(data);
>> + if (ret < 0) {
>> + spin_unlock(&cpufreq_stats_lock);
>> + ret = -EINVAL;
>> + goto error_out;
>> + }
>> +
>> spin_unlock(&cpufreq_stats_lock);
>> cpufreq_cpu_put(data);
>> return 0;
>> @@ -297,11 +487,18 @@ static int cpufreq_stat_notifier_policy(struct notifier_block *nb,
>> if (val != CPUFREQ_NOTIFY)
>> return 0;
>> table = cpufreq_frequency_get_table(cpu);
>> - if (!table)
>> - return 0;
>> - ret = cpufreq_stats_create_table(policy, table);
>> - if (ret)
>> + if (table) {
>> + ret = cpufreq_stats_create_table(policy, table);
>> + if (ret)
>> + return ret;
>> + }
>> +
>> + ret = cpufreq_stats_reset_debugfs(policy);
>
> Why?
When cpufreq governor is changed, always reset stats->load_table for performance/powersave/userspace governor.
-sh-4.1# cat /sys/kernel/debug/cpufreq/cpu0/load_table
Time(ms) Old Freq(Hz) New Freq(Hz) CPU0 CPU1 CPU3
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
>
>> + if (ret < 0) {
>> + pr_debug("Failed to reset CPUs data of debugfs\n");
>> return ret;
>> + }
>> +
>> return 0;
>> }
>
Thanks for your comment.
Best Regards,
Chanwoo Choi
next prev parent reply other threads:[~2013-07-24 1:56 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-18 11:17 [PATCH 0/3 v6] cpufreq: Add 'load_table' debugfs file to show colleced CPUs load Chanwoo Choi
2013-07-18 11:17 ` [PATCH 1/3 v6] cpufreq: Add debugfs directory for cpufreq Chanwoo Choi
2013-07-22 10:11 ` Viresh Kumar
2013-07-24 1:25 ` Chanwoo Choi
2013-07-24 5:05 ` Viresh Kumar
2013-07-24 7:43 ` Chanwoo Choi
2013-07-24 7:51 ` Viresh Kumar
2013-07-24 8:01 ` Chanwoo Choi
2013-07-24 8:07 ` Viresh Kumar
2013-07-24 8:46 ` Chanwoo Choi
2013-07-24 8:51 ` Viresh Kumar
2013-07-24 9:05 ` Chanwoo Choi
2013-07-24 9:09 ` Viresh Kumar
2013-07-24 9:14 ` Chanwoo Choi
2013-07-24 6:14 ` Chanwoo Choi
2013-07-24 6:16 ` Viresh Kumar
2013-07-18 11:17 ` [PATCH 2/3 v6] cpufreq: stats: Add 'load_table' debugfs file to show accumulated data of CPUs Chanwoo Choi
2013-07-22 11:05 ` Viresh Kumar
2013-07-24 1:56 ` Chanwoo Choi [this message]
2013-07-18 11:17 ` [PATCH 3/3 v6] Documentation: cpufreq: load_table: Update load_table debugfs file documentation Chanwoo Choi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=51EF3454.50807@samsung.com \
--to=cw00.choi@samsung.com \
--cc=cpufreq@vger.kernel.org \
--cc=kyungmin.park@samsung.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=myungjoo.ham@samsung.com \
--cc=rjw@sisk.pl \
--cc=viresh.kumar@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox