drm/i915/pmu: Micro-optimize sampling loop
Subsystems (2)
Tvrtko Ursulin
maintainerRFC 1/1 drm/i915/pmu: Micro-optimize sampling loop
From: Tvrtko Ursulin <[email protected]>
By carefully chosing slightly unsynchronized values for timer frequency and period, we can remove the multiplications from the sampling loop and replace them with shifts only.
Downside is that the counter read callback now has to do a divide with a non-power-of-two, but the rationale is that sampling loop which runs at ~200 Hz, multiplied by number of engines, is more important than less frequent counter read-out. Furthermore, the divide in counter read-out seems to be optimized by the compiler to some shifts and multiply.
We can only do all this at the expense of introducing a systematic error to the sampling counters to the amount of 0.18%. At the same time we are increasing the sampling rate from 200 to 238 Hz which may cancel some of this out.
---
Motivated by Chris' insisting to use power-of-two scale factor in the engine queue depth PMU series. I was actually reluctant to give in there so this is even more questionable. :)
I have no idea if it is cheaper to run the sampling timer at 200Hz with some multiplies, or run it at 238Hz with only shifts.
FWIW 0.18% systematic error at least doesn't sound like a big deal when sampling counters are concerned.
--- drivers/gpu/drm/i915/i915_pmu.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/i915_pmu.c +13 -3
@@ -29,9 +29,19 @@#include "i915_pmu.h" #include "intel_ringbuffer.h" -/* Frequency for the sampling timer for events which need it. */ -#define FREQUENCY 200 -#define PERIOD max_t(u64, 10000, NSEC_PER_SEC / FREQUENCY) +/* +* Frequency for the sampling timer for events which need it. +* +* The relationship between frequency and period is: +* PERIOD(ns) = 1e9 / FREQUENCY(Hz) +* +* We set the period to a power-of-two value 0x400000 for simpler computations +* inside the sampling timer, at the expense of introducting a systematic error +* of 0.18%. This is caused by frequency (using as divisor for reading out +* certain counters) being rounded to 238, while 1e9 / 0x400000 = 238.418579102. +*/ +#define FREQUENCY 238 +#define PERIOD 0x400000#define ENGINE_SAMPLE_MASK \ (BIT(I915_SAMPLE_BUSY) | \
Signature · 6 lines
2.14.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoting Tvrtko Ursulin (2018-01-31 16:02:38)
Quoted 19 lines
From: Tvrtko Ursulin <[email protected]>
By carefully chosing slightly unsynchronized values for timer frequency and period, we can remove the multiplications from the sampling loop and replace them with shifts only.
Downside is that the counter read callback now has to do a divide with a non-power-of-two, but the rationale is that sampling loop which runs at ~200 Hz, multiplied by number of engines, is more important than less frequent counter read-out. Furthermore, the divide in counter read-out seems to be optimized by the compiler to some shifts and multiply.
We can only do all this at the expense of introducing a systematic error to the sampling counters to the amount of 0.18%. At the same time we are increasing the sampling rate from 200 to 238 Hz which may cancel some of this out.
Signed-off-by Tvrtko Ursulin <[email protected]>Cc Chris Wilson <[email protected]>
Quoted 7 lines
---
Motivated by Chris' insisting to use power-of-two scale factor in the engine queue depth PMU series. I was actually reluctant to give in there so this is even more questionable. :)I have no idea if it is cheaper to run the sampling timer at 200Hz with some multiplies, or run it at 238Hz with only shifts.
I can't say I have any insight into the timer wheel or hrtimer either. Let's watch.
Quoted 2 lines
FWIW 0.18% systematic error at least doesn't sound like a big deal when sampling counters are concerned.
Yeah, since even pinning it down to a 5% systematic error is hard, but we'll see if this 0.18% is the straw that breaks CI back! -Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI✓ Fi.CI.BAT: success for drm/i915/pmu: Micro-optimize sampling loop
In reply to Tvrtko Ursulin== Series Details ==
== Series Details ==
Series: drm/i915/pmu: Micro-optimize sampling loop
URL : https://patchwork.freedesktop.org/series/37420/
State : success
== Summary ==
Series 37420v1 drm/i915/pmu: Micro-optimize sampling loop
https://patchwork.freedesktop.org/api/1.0/series/37420/revisions/1/mbox/
Test debugfs_test:
Subgroup read_all_entries:
dmesg-warn -> DMESG-FAIL (fi-elk-e7500) fdo#103989
Test kms_pipe_crc_basic:
Subgroup suspend-read-crc-pipe-b:
incomplete -> PASS (fi-snb-2520m) fdo#103713fdo#103989 https://bugs.freedesktop.org/show_bug.cgi?id=103989
fdo#103713 https://bugs.freedesktop.org/show_bug.cgi?id=103713
fi-bdw-5557u total:288 pass:267 dwarn:0 dfail:0 fail:0 skip:21 time:419s fi-bdw-gvtdvm total:288 pass:264 dwarn:0 dfail:0 fail:0 skip:24 time:430s fi-blb-e6850 total:288 pass:223 dwarn:1 dfail:0 fail:0 skip:64 time:371s fi-bsw-n3050 total:288 pass:242 dwarn:0 dfail:0 fail:0 skip:46 time:483s fi-bwr-2160 total:288 pass:183 dwarn:0 dfail:0 fail:0 skip:105 time:281s fi-bxt-dsi total:288 pass:258 dwarn:0 dfail:0 fail:0 skip:30 time:484s fi-bxt-j4205 total:288 pass:259 dwarn:0 dfail:0 fail:0 skip:29 time:482s fi-byt-j1900 total:288 pass:253 dwarn:0 dfail:0 fail:0 skip:35 time:463s fi-byt-n2820 total:288 pass:249 dwarn:0 dfail:0 fail:0 skip:39 time:450s fi-cfl-s2 total:288 pass:262 dwarn:0 dfail:0 fail:0 skip:26 time:563s fi-elk-e7500 total:224 pass:168 dwarn:9 dfail:1 fail:0 skip:45 fi-gdg-551 total:288 pass:179 dwarn:0 dfail:0 fail:1 skip:108 time:281s fi-glk-1 total:288 pass:260 dwarn:0 dfail:0 fail:0 skip:28 time:510s fi-hsw-4770 total:288 pass:261 dwarn:0 dfail:0 fail:0 skip:27 time:388s fi-hsw-4770r total:288 pass:261 dwarn:0 dfail:0 fail:0 skip:27 time:398s fi-ilk-650 total:288 pass:228 dwarn:0 dfail:0 fail:0 skip:60 time:415s fi-ivb-3520m total:288 pass:259 dwarn:0 dfail:0 fail:0 skip:29 time:446s fi-ivb-3770 total:288 pass:255 dwarn:0 dfail:0 fail:0 skip:33 time:411s fi-kbl-7500u total:288 pass:263 dwarn:1 dfail:0 fail:0 skip:24 time:455s fi-kbl-7560u total:288 pass:269 dwarn:0 dfail:0 fail:0 skip:19 time:498s fi-kbl-7567u total:288 pass:268 dwarn:0 dfail:0 fail:0 skip:20 time:451s fi-kbl-r total:288 pass:261 dwarn:0 dfail:0 fail:0 skip:27 time:499s fi-pnv-d510 total:288 pass:222 dwarn:1 dfail:0 fail:0 skip:65 time:579s fi-skl-6260u total:288 pass:268 dwarn:0 dfail:0 fail:0 skip:20 time:429s fi-skl-6600u total:288 pass:261 dwarn:0 dfail:0 fail:0 skip:27 time:508s fi-skl-6700hq total:288 pass:262 dwarn:0 dfail:0 fail:0 skip:26 time:523s fi-skl-6700k2 total:288 pass:264 dwarn:0 dfail:0 fail:0 skip:24 time:487s fi-skl-6770hq total:288 pass:268 dwarn:0 dfail:0 fail:0 skip:20 time:482s fi-skl-guc total:288 pass:260 dwarn:0 dfail:0 fail:0 skip:28 time:415s fi-skl-gvtdvm total:288 pass:265 dwarn:0 dfail:0 fail:0 skip:23 time:433s fi-snb-2520m total:288 pass:248 dwarn:0 dfail:0 fail:0 skip:40 time:520s fi-snb-2600 total:288 pass:248 dwarn:0 dfail:0 fail:0 skip:40 time:393s
Blacklisted hosts:
fi-glk-dsi total:288 pass:258 dwarn:0 dfail:0 fail:0 skip:30 time:468s
badc0398a06018a07f6f50a1ff5a5fd8a30b9944 drm-tip: 2018y-01m-31d-12h-17m-12s UTC integration manifest ef8f136b87be drm/i915/pmu: Micro-optimize sampling loop
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_7840/issues.html
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI✗ Fi.CI.IGT: warning for drm/i915/pmu: Micro-optimize sampling loop
In reply to Tvrtko Ursulin== Series Details ==
== Series Details ==
Series: drm/i915/pmu: Micro-optimize sampling loop
URL : https://patchwork.freedesktop.org/series/37420/
State : warning
== Summary ==
Test kms_flip:
Subgroup 2x-plain-flip-fb-recreate:
pass -> FAIL (shard-hsw) fdo#100368
Test kms_cursor_legacy:
Subgroup flip-vs-cursor-legacy:
pass -> FAIL (shard-hsw) fdo#102670
Test kms_sysfs_edid_timing:
pass -> WARN (shard-apl) fdo#100047
Test kms_atomic_interruptible:
Subgroup legacy-cursor:
pass -> SKIP (shard-snb)
Test kms_frontbuffer_tracking:
Subgroup fbc-1p-offscren-pri-shrfb-draw-mmap-cpu:
pass -> SKIP (shard-snb) fdo#101623
Test drv_suspend:
Subgroup sysfs-reader-hibernate:
fail -> SKIP (shard-hsw) fdo#103375
Test perf_pmu:
Subgroup semaphore-wait-bcs0:
fail -> PASS (shard-apl) fdo#104829fdo#100368 https://bugs.freedesktop.org/show_bug.cgi?id=100368
fdo#102670 https://bugs.freedesktop.org/show_bug.cgi?id=102670
fdo#100047 https://bugs.freedesktop.org/show_bug.cgi?id=100047
fdo#101623 https://bugs.freedesktop.org/show_bug.cgi?id=101623
fdo#103375 https://bugs.freedesktop.org/show_bug.cgi?id=103375
fdo#104829 https://bugs.freedesktop.org/show_bug.cgi?id=104829
shard-apl total:2838 pass:1748 dwarn:2 dfail:0 fail:23 skip:1064 time:12578s shard-hsw total:2838 pass:1734 dwarn:1 dfail:0 fail:11 skip:1091 time:11946s shard-snb total:2838 pass:1328 dwarn:1 dfail:0 fail:10 skip:1499 time:6614s
Blacklisted hosts:
shard-kbl total:2838 pass:1870 dwarn:4 dfail:0 fail:22 skip:942 time:9731s
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_7840/shards.html
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 25 lines · Chris Wilson
Quoting Tvrtko Ursulin (2018-01-31 16:02:38)
Quoted 24 lines
From: Tvrtko Ursulin <[email protected]>
By carefully chosing slightly unsynchronized values for timer frequency and period, we can remove the multiplications from the sampling loop and replace them with shifts only.
Downside is that the counter read callback now has to do a divide with a non-power-of-two, but the rationale is that sampling loop which runs at ~200 Hz, multiplied by number of engines, is more important than less frequent counter read-out. Furthermore, the divide in counter read-out seems to be optimized by the compiler to some shifts and multiply.
We can only do all this at the expense of introducing a systematic error to the sampling counters to the amount of 0.18%. At the same time we are increasing the sampling rate from 200 to 238 Hz which may cancel some of this out.
Signed-off-by Tvrtko Ursulin <[email protected]>Cc Chris Wilson <[email protected]>---
Motivated by Chris' insisting to use power-of-two scale factor in the engine queue depth PMU series. I was actually reluctant to give in there so this is even more questionable. :)
Quoted 5 lines
Quoted 2 lines
I have no idea if it is cheaper to run the sampling timer at 200Hz with some multiplies, or run it at 238Hz with only shifts.
I can't say I have any insight into the timer wheel or hrtimer either. Let's watch.
I got 0.35% vs 0.19% CPU usage for i915_sample, tip vs this patch. But in general it seems to fluctuate a lot so I don't really believe those numbers.
Quoted 5 lines
Quoted 2 lines
FWIW 0.18% systematic error at least doesn't sound like a big deal when sampling counters are concerned.
Yeah, since even pinning it down to a 5% systematic error is hard, but we'll see if this 0.18% is the straw that breaks CI back!
It passed but I don't think we should be tempted, unless someone can prove it is really worth it. I'll just forget about it for time being.
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx