lkml.org 
[lkml]   [2020]   [Jan]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH RESEND 3/3] PM / devfreq: exynos-nocp: change load and total calculations
Date
There are two problems with exynos-nocp driver. First one is reading
bytes and cycle counters and comparing them one to one without taking
into account wcore bus width. Second one is that cycle counter depends
on DREX DRAM clock, not on wcore clock. The latter problem was exposed
by commit 6e7674c3c6df5 ("memory: Add DMC driver for Exynos5422"),
which changes DRAM clock depending on memory read/write pressure and when
it gets at higher freqency, NoCP cycle counter also increases. Note that
both of these problems was there before this commit.
The proposed solution is to use byte counter from NoCP h/w registers
for current wcore bandwidth calculations and derive max bandwidth from
current frequency. While at it, change from bytes to kilobytes to avoid
overflow in later calculations in exynos-bus and devfreq drivers.
Also while at it, remove cycle counters setting and reading and extend
dev_dbg with time interval in miliseconds, percent of load, raw counter
value in hex.

Signed-off-by: Kamil Konieczny <k.konieczny@samsung.com>
---
drivers/devfreq/event/exynos-nocp.c | 61 ++++++++++++-----------------
1 file changed, 24 insertions(+), 37 deletions(-)

diff --git a/drivers/devfreq/event/exynos-nocp.c b/drivers/devfreq/event/exynos-nocp.c
index ebe9cdf94f54..979ec094cf26 100644
--- a/drivers/devfreq/event/exynos-nocp.c
+++ b/drivers/devfreq/event/exynos-nocp.c
@@ -9,6 +9,7 @@
#include <linux/clk.h>
#include <linux/module.h>
#include <linux/devfreq-event.h>
+#include <linux/jiffies.h>
#include <linux/kernel.h>
#include <linux/of_address.h>
#include <linux/platform_device.h>
@@ -60,19 +61,6 @@ static int exynos_nocp_set_event(struct devfreq_event_dev *edev)
if (ret < 0)
goto out;

- ret = regmap_update_bits(nocp->regmap, NOCP_COUNTERS_2_SRC,
- NOCP_CNT_SRC_INTEVENT_MASK,
- NOCP_CNT_SRC_INTEVENT_CYCLE_MASK);
- if (ret < 0)
- goto out;
-
- ret = regmap_update_bits(nocp->regmap, NOCP_COUNTERS_3_SRC,
- NOCP_CNT_SRC_INTEVENT_MASK,
- NOCP_CNT_SRC_INTEVENT_CHAIN_MASK);
- if (ret < 0)
- goto out;
-
-
/* Set an alarm with a max/min value of 0 to generate StatALARM */
ret = regmap_write(nocp->regmap, NOCP_STAT_ALARM_MIN, 0x0);
if (ret < 0)
@@ -95,18 +83,6 @@ static int exynos_nocp_set_event(struct devfreq_event_dev *edev)
if (ret < 0)
goto out;

- ret = regmap_update_bits(nocp->regmap, NOCP_COUNTERS_2_ALARM_MODE,
- NOCP_CNT_ALARM_MODE_MASK,
- NOCP_CNT_ALARM_MODE_MIN_MAX_MASK);
- if (ret < 0)
- goto out;
-
- ret = regmap_update_bits(nocp->regmap, NOCP_COUNTERS_3_ALARM_MODE,
- NOCP_CNT_ALARM_MODE_MASK,
- NOCP_CNT_ALARM_MODE_MIN_MAX_MASK);
- if (ret < 0)
- goto out;
-
/* Enable the measurements by setting AlarmEn and StatEn */
ret = regmap_update_bits(nocp->regmap, NOCP_MAIN_CTL,
NOCP_MAIN_CTL_STATEN_MASK | NOCP_MAIN_CTL_ALARMEN_MASK,
@@ -145,6 +121,7 @@ static int exynos_nocp_get_event(struct devfreq_event_dev *edev,
{
struct exynos_nocp *nocp = devfreq_event_get_drvdata(edev);
unsigned int counter[4];
+ unsigned long dt;
int ret;

/* Read cycle count */
@@ -156,19 +133,29 @@ static int exynos_nocp_get_event(struct devfreq_event_dev *edev,
if (ret < 0)
goto out;

- ret = regmap_read(nocp->regmap, NOCP_COUNTERS_2_VAL, &counter[2]);
- if (ret < 0)
- goto out;
-
- ret = regmap_read(nocp->regmap, NOCP_COUNTERS_3_VAL, &counter[3]);
- if (ret < 0)
- goto out;
-
edata->load_count = ((counter[1] << 16) | counter[0]);
- edata->total_count = ((counter[3] << 16) | counter[2]);
-
- dev_dbg(&edev->dev, "%s (event: %lu/%lu)\n", edev->desc->name,
- edata->load_count, edata->total_count);
+ dt = jiffies_to_msecs((long)jiffies - (long)edata->prev_time);
+ if (dt == 0)
+ dt = 1;
+
+ /*
+ * count load in kB/s
+ * load = load / 1000 * 1000 / dt
+ */
+ edata->load_count = edata->load_count / dt;
+
+ /*
+ * count max bandwidth in kB/s:
+ * bw = freq * ((bus width in bits / 8) / nr of mem channels) / 1000
+ * where 128 bits / 8 bits per byte / 4 channels = 4
+ * so it is: bw = freq * 4 / 1000
+ */
+ edata->total_count = edata->curr_freq / 250;
+
+ dev_dbg(&edev->dev, "%s (event: %lu/%lu) %lums %lu%% 0x%08x\n",
+ edev->desc->name, edata->load_count, edata->total_count, dt,
+ edata->load_count * 100 / edata->total_count,
+ (counter[1] << 16) | counter[0]);

return 0;

--
2.25.0
\
 
 \ /
  Last update: 2020-01-24 15:16    [W:0.053 / U:0.600 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site