linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kamil Konieczny <k.konieczny@samsung.com>
To: k.konieczny@samsung.com
Cc: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>,
	Krzysztof Kozlowski <krzk@kernel.org>,
	Kukjin Kim <kgene@kernel.org>,
	Kyungmin Park <kyungmin.park@samsung.com>,
	linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	MyungJoo Ham <myungjoo.ham@samsung.com>
Subject: [PATCH 3/3] PM / devfreq: exynos-nocp: change load and total calculations
Date: Thu, 23 Jan 2020 15:53:13 +0100	[thread overview]
Message-ID: <20200123145313.27539-4-k.konieczny@samsung.com> (raw)
In-Reply-To: <20200123145313.27539-1-k.konieczny@samsung.com>

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


      parent reply	other threads:[~2020-01-23 14:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20200123145330eucas1p1a03da39c2381d02188a8354659a09480@eucas1p1.samsung.com>
2020-01-23 14:53 ` [PATCH 0/3] PM / devfreq: change load calc in Exynos5422 Kamil Konieczny
     [not found]   ` <CGME20200123145331eucas1p2aaf6eccd724af9edc25a547b6fde7961@eucas1p2.samsung.com>
2020-01-23 14:53     ` [PATCH 1/3] PM / devfreq: exynos-nocp: fix debug print type Kamil Konieczny
     [not found]   ` <CGME20200123145331eucas1p29464e7f22e1e775cc8c4fc1e330f8eee@eucas1p2.samsung.com>
2020-01-23 14:53     ` [PATCH 2/3] PM / devfreq: exynos-bus: prepare for change in load calc in exynos-nocp Kamil Konieczny
     [not found]   ` <CGME20200123145332eucas1p2110419ac74304cd32879bddcce0a950f@eucas1p2.samsung.com>
2020-01-23 14:53     ` Kamil Konieczny [this message]

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=20200123145313.27539-4-k.konieczny@samsung.com \
    --to=k.konieczny@samsung.com \
    --cc=b.zolnierkie@samsung.com \
    --cc=kgene@kernel.org \
    --cc=krzk@kernel.org \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=myungjoo.ham@samsung.com \
    /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;
as well as URLs for NNTP newsgroup(s).