bandwidth: add min bandwidth read in usage_stat [1/1]
authorTao Zeng <tao.zeng@amlogic.com>
Tue, 30 Apr 2019 02:56:18 +0000 (10:56 +0800)
committerJianxin Pan <jianxin.pan@amlogic.com>
Tue, 30 Apr 2019 08:30:28 +0000 (01:30 -0700)
PD#SWPL-7960

Problem:
There is no min ddr bandwidth data

Solution:
Add this value in sysfs

Verify:
p212

Change-Id: I9d90476d30c0ca7789046d8d205f0802de2b4acf
Signed-off-by: Tao Zeng <tao.zeng@amlogic.com>
drivers/amlogic/ddr_tool/ddr_bandwidth.c
include/linux/amlogic/aml_ddr_bandwidth.h

index 0eaea45..f468c30 100644 (file)
@@ -104,6 +104,11 @@ static void cal_ddr_usage(struct ddr_bandwidth *db, struct ddr_grant *dg)
                memcpy(&db->max_sample, &db->cur_sample,
                       sizeof(struct ddr_bandwidth_sample));
        }
+       /* update min sample */
+       if (db->cur_sample.total_bandwidth < db->min_sample.total_bandwidth) {
+               memcpy(&db->min_sample, &db->cur_sample,
+                      sizeof(struct ddr_bandwidth_sample));
+       }
        /* update usage statistics */
        db->usage_stat[db->cur_sample.total_usage / 1000]++;
 
@@ -340,8 +345,10 @@ static ssize_t usage_stat_store(struct class *cla,
        /* clear flag and start statistics */
        spin_lock_irqsave(&aml_db->lock, flags);
        memset(&aml_db->max_sample, 0, sizeof(struct ddr_bandwidth_sample));
+       memset(&aml_db->min_sample, 0, sizeof(struct ddr_bandwidth_sample));
        memset(aml_db->usage_stat, 0, 10 * sizeof(int));
        memset(&aml_db->avg, 0, sizeof(struct ddr_avg_bandwidth));
+       aml_db->min_sample.total_bandwidth = 0xffffffff;
        spin_unlock_irqrestore(&aml_db->lock, flags);
        return count;
 }
@@ -355,6 +362,7 @@ static ssize_t usage_stat_show(struct class *cla,
        unsigned long total_count = 0;
        struct ddr_avg_bandwidth tmp;
 #define MAX_PREFIX "MAX bandwidth: %8d KB/s, usage: %2d.%02d%%"
+#define MIN_PREFIX "MIN bandwidth: %8d KB/s, usage: %2d.%02d%%"
 #define AVG_PREFIX "AVG bandwidth: %8lld KB/s, usage: %2d.%02d%%"
 
        if (aml_db->mode != MODE_ENABLE)
@@ -374,6 +382,20 @@ static ssize_t usage_stat_show(struct class *cla,
                             aml_db->max_sample.bandwidth[i]);
        }
 
+       /* show for min bandwidth */
+       percent = aml_db->min_sample.total_usage / 100;
+       rem     = aml_db->min_sample.total_usage % 100;
+       tick    = aml_db->min_sample.tick;
+       do_div(tick, 1000);
+       s      += sprintf(buf + s, MIN_PREFIX", tick:%lld us\n",
+                         aml_db->min_sample.total_bandwidth,
+                         percent, rem, tick);
+       for (i = 0; i < aml_db->channels; i++) {
+               s += sprintf(buf + s, "ch:%d port:%16llx: %8d KB/s\n",
+                            i, aml_db->port[i],
+                            aml_db->min_sample.bandwidth[i]);
+       }
+
        /* show for average bandwidth */
        if (aml_db->avg.sample_count) {
                memcpy(&tmp, &aml_db->avg, sizeof(tmp));
@@ -654,6 +676,7 @@ static int __init ddr_bandwidth_probe(struct platform_device *pdev)
        if (!aml_db)
                return -ENOMEM;
 
+       aml_db->min_sample.total_bandwidth = 0xffffffff;
        aml_db->cpu_type = get_meson_cpu_version(0);
        pr_info("chip type:0x%x\n", aml_db->cpu_type);
        if (aml_db->cpu_type < MESON_CPU_MAJOR_ID_M8B) {
index ba0057d..d6e47c9 100644 (file)
@@ -160,6 +160,7 @@ struct ddr_bandwidth {
        spinlock_t lock;
        struct ddr_bandwidth_sample cur_sample;
        struct ddr_bandwidth_sample max_sample;
+       struct ddr_bandwidth_sample min_sample;
        struct ddr_avg_bandwidth    avg;
        u64          port[MAX_CHANNEL];
        void __iomem *ddr_reg;