From: Kamil Konieczny <k.konieczny@samsung.com> To: k.konieczny@samsung.com Cc: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>, Chanwoo Choi <cw00.choi@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, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, Marek Szyprowski <m.szyprowski@samsung.com>, MyungJoo Ham <myungjoo.ham@samsung.com> Subject: [PATCH RESEND 3/3] PM / devfreq: exynos-nocp: change load and total calculations Date: Fri, 24 Jan 2020 15:14:49 +0100 [thread overview] Message-ID: <20200124141449.19844-4-k.konieczny@samsung.com> (raw) In-Reply-To: <20200124141449.19844-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
WARNING: multiple messages have this Message-ID (diff)
From: Kamil Konieczny <k.konieczny@samsung.com> To: k.konieczny@samsung.com Cc: linux-samsung-soc@vger.kernel.org, Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Krzysztof Kozlowski <krzk@kernel.org>, Chanwoo Choi <cw00.choi@samsung.com>, Kyungmin Park <kyungmin.park@samsung.com>, Kukjin Kim <kgene@kernel.org>, MyungJoo Ham <myungjoo.ham@samsung.com>, linux-arm-kernel@lists.infradead.org, Marek Szyprowski <m.szyprowski@samsung.com> Subject: [PATCH RESEND 3/3] PM / devfreq: exynos-nocp: change load and total calculations Date: Fri, 24 Jan 2020 15:14:49 +0100 [thread overview] Message-ID: <20200124141449.19844-4-k.konieczny@samsung.com> (raw) In-Reply-To: <20200124141449.19844-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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2020-01-24 14:15 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top [not found] <CGME20200124141505eucas1p21ab7071b808c4ac6ef10c0d13adab49d@eucas1p2.samsung.com> 2020-01-24 14:14 ` [PATCH RESEND 0/3] PM / devfreq: change load calc in Exynos5422 Kamil Konieczny 2020-01-24 14:14 ` Kamil Konieczny [not found] ` <CGME20200124141506eucas1p2da00cf4424a6b5e5e6d3e245eda586a5@eucas1p2.samsung.com> 2020-01-24 14:14 ` [PATCH RESEND 1/3] PM / devfreq: exynos-nocp: fix debug print type Kamil Konieczny 2020-01-24 14:14 ` Kamil Konieczny [not found] ` <CGME20200124141506eucas1p1d2fdb3b5d26d123272cafeddecd5708a@eucas1p1.samsung.com> 2020-01-24 14:14 ` [PATCH RESEND 2/3] PM / devfreq: exynos-bus: prepare for change in load calc in exynos-nocp Kamil Konieczny 2020-01-24 14:14 ` Kamil Konieczny [not found] ` <CGME20200124141507eucas1p115e87fdd6eda4a5f320d5145f5960889@eucas1p1.samsung.com> 2020-01-24 14:14 ` Kamil Konieczny [this message] 2020-01-24 14:14 ` [PATCH RESEND 3/3] PM / devfreq: exynos-nocp: change load and total calculations Kamil Konieczny 2020-03-02 14:59 ` [PATCH RESEND 0/3] PM / devfreq: change load calc in Exynos5422 Bartlomiej Zolnierkiewicz 2020-03-02 14:59 ` Bartlomiej Zolnierkiewicz
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=20200124141449.19844-4-k.konieczny@samsung.com \ --to=k.konieczny@samsung.com \ --cc=b.zolnierkie@samsung.com \ --cc=cw00.choi@samsung.com \ --cc=kgene@kernel.org \ --cc=krzk@kernel.org \ --cc=kyungmin.park@samsung.com \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-pm@vger.kernel.org \ --cc=linux-samsung-soc@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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.