ddr: fix bandwidth read result 0 on 32bit OS [1/1]
authortao zeng <tao.zeng@amlogic.com>
Mon, 29 Oct 2018 04:11:18 +0000 (12:11 +0800)
committerJianxin Pan <jianxin.pan@amlogic.com>
Tue, 30 Oct 2018 01:42:53 +0000 (18:42 -0700)
PD#SWPL-960

Problem:
Reading bandwidth of DDR from sysfs get all 0 result on 32
bit kernel

Solution:
Fix overflow when calculating bandwidth.

Verify:
P212

Change-Id: I35837db653bdc2d97ced98689546a9ffc0db21c7
Signed-off-by: tao zeng <tao.zeng@amlogic.com>
drivers/amlogic/ddr_tool/ddr_bandwidth.c

index 132773c..fb49fe8 100644 (file)
@@ -40,17 +40,23 @@ static void cal_ddr_usage(struct ddr_bandwidth *db, struct ddr_grant *dg)
 
        if (db->ops && db->ops->get_freq)
                freq = db->ops->get_freq(db);
-       mul  = (dg->all_grant * 10000ULL) / 16; /* scale up to keep precision*/
+       mul  = dg->all_grant;
+       mul *= 10000ULL;
+       mul /= 16;
        cnt  = db->clock_count;
        do_div(mul, cnt);
        db->total_usage = mul;
        if (freq) {
                /* calculate in KB */
-               mul = (dg->all_grant * freq) / 1024;
+               mul  = dg->all_grant;
+               mul *= freq;
+               mul /= 1024;
                do_div(mul, cnt);
                db->total_bandwidth = mul;
                for (i = 0; i < db->channels; i++) {
-                       mul = (dg->channel_grant[i] * freq) / 1024;
+                       mul  = dg->channel_grant[i];
+                       mul *= freq;
+                       mul /= 1024;
                        do_div(mul, cnt);
                        db->bandwidth[i] = mul;
                }