drm/i915: use static const array for PICK macro
Subsystems (2)
PATCH v2 1/1 drm/i915: use static const array for PICK macro
The varargs macro trick in _PIPE3/_PHY3/_PORT3 was meant as an optimization to shrink the i915 kernel module by around 1000 bytes. However, the downside is a size regression with CONFIG_KASAN, as I found from stack size warnings with gcc-7.0.1:
before:drivers/gpu/drm/i915/intel_dpll_mgr.c: In function 'bxt_ddi_pll_get_hw_state':drivers/gpu/drm/i915/intel_dpll_mgr.c:1644:1: error: the frame size of 176 bytes is larger than 100 bytes [-Werror=frame-larger-than=] drivers/gpu/drm/i915/intel_dpll_mgr.c: In function 'bxt_ddi_pll_enable':drivers/gpu/drm/i915/intel_dpll_mgr.c:1548:1: error: the frame size of 224 bytes is larger than 100 bytes [-Werror=frame-larger-than=]
after:drivers/gpu/drm/i915/intel_dpll_mgr.c: In function 'bxt_ddi_pll_get_hw_state':drivers/gpu/drm/i915/intel_dpll_mgr.c:1644:1: error: the frame size of 1016 bytes is larger than 1000 bytes [-Werror=frame-larger-than=] drivers/gpu/drm/i915/intel_dpll_mgr.c: In function 'bxt_ddi_pll_enable':drivers/gpu/drm/i915/intel_dpll_mgr.c:1548:1: error: the frame size of 1960 bytes is larger than 1000 bytes [-Werror=frame-larger-than=]
I also checked the module sizes and got with gcc-7.0.1
original:
text data bss dec hex filename
2380830 1155436 4448 3540714 3606ea drivers/gpu/drm/i915/i915-kasan.o
1298054 543692 2884 1844630 1c2596 drivers/gpu/drm/i915/i915-nokasan.o
after ce64645d86ac:
text data bss dec hex filename
2389515 1154476 4448 3548439 362517 drivers/gpu/drm/i915/i915-kasan.o
1299639 543692 2884 1846215 1c2bc7 drivers/gpu/drm/i915/i915-nokasan.o
with this patch:
text data bss dec hex filename
2381275 1163884 4448 3549607 3629a7 drivers/gpu/drm/i915/i915-kasan.o
1296038 543692 2884 1842614 1c1db6 drivers/gpu/drm/i915/i915-nokasan.o
Actually showing a code size growth in .text both with and without kasan, and my version gets most of it back at the expense of larger .data when kasan is enabled.
---
v2: rebased after a1986f4174a4 ("drm/i915: Remove unnecessary PORT3 definition.")
--- drivers/gpu/drm/i915/i915_reg.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/gpu/drm/i915/i915_reg.h +9 -9
@@ -139,7 +139,7 @@ static inline bool i915_mmio_reg_valid(i915_reg_t reg)return !i915_mmio_reg_equal (reg,INVALID_MMIO_REG ); } -#define _PICK (__index, ...) (((const u32 []){ __VA_ARGS__ })[__index]) +#define _PICK (__index, ...) ({static const u32 __arr[] = { __VA_ARGS__ }; __arr[__index];})#define _PIPE (pipe, a, b) ((a) + (pipe)*((b)-(a)))#define _MMIO_PIPE (pipe, a, b) _MMIO(_PIPE(pipe, a, b))
@@ -3097,10 +3097,10 @@ enum i915_power_well_id {/* * Clock control & power management */ -#define _DPLL_A (dev_priv->info.display_mmio_offset + 0x6014) -#define _DPLL_B (dev_priv->info.display_mmio_offset + 0x6018) -#define _CHV_DPLL_C (dev_priv->info.display_mmio_offset + 0x6030) -#define DPLL (pipe) _MMIO_PIPE3((pipe), _DPLL_A, _DPLL_B, _CHV_DPLL_C) +#define _DPLL_A 0x6014 +#define _DPLL_B 0x6018 +#define _CHV_DPLL_C 0x6030 +#define DPLL (pipe) _MMIO(dev_priv->info.display_mmio_offset + _PICK((pipe), _DPLL_A, _DPLL_B, _CHV_DPLL_C))#define VGA0 _MMIO(0x6000)#define VGA1 _MMIO(0x6004)
@@ -3196,10 +3196,10 @@ enum i915_power_well_id {#define SDVO_MULTIPLIER_SHIFT_HIRES 4#define SDVO_MULTIPLIER_SHIFT_VGA 0 -#define _DPLL_A_MD (dev_priv->info.display_mmio_offset + 0x601c) -#define _DPLL_B_MD (dev_priv->info.display_mmio_offset + 0x6020) -#define _CHV_DPLL_C_MD (dev_priv->info.display_mmio_offset + 0x603c) -#define DPLL_MD (pipe) _MMIO_PIPE3((pipe), _DPLL_A_MD, _DPLL_B_MD, _CHV_DPLL_C_MD) +#define _DPLL_A_MD 0x601c +#define _DPLL_B_MD 0x6020 +#define _CHV_DPLL_C_MD 0x603c +#define DPLL_MD (pipe) _MMIO(dev_priv->info.display_mmio_offset + _PICK((pipe), _DPLL_A_MD, _DPLL_B_MD, _CHV_DPLL_C_MD))/* * UDI pixel divider, controlling how many pixels are stuffed into a packet.
Signature · 6 lines
2.9.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Patchwork
CI✓ Fi.CI.BAT: success for drm/i915: use static const array for PICK macro (rev3)
== Series Details ==
== Series Details ==
Series: drm/i915: use static const array for PICK macro (rev3)
URL : https://patchwork.freedesktop.org/series/21561/
State : success
== Summary ==
Series 21561v3 drm/i915: use static const array for PICK macro
https://patchwork.freedesktop.org/api/1.0/series/21561/revisions/3/mbox/
Test debugfs_test:
Subgroup read_all_entries:
dmesg-fail -> DMESG-WARN (fi-elk-e7500) fdo#103989fdo#103989 https://bugs.freedesktop.org/show_bug.cgi?id=103989
fi-bdw-5557u total:288 pass:267 dwarn:0 dfail:0 fail:0 skip:21 time:438s fi-bdw-gvtdvm total:288 pass:264 dwarn:0 dfail:0 fail:0 skip:24 time:442s fi-blb-e6850 total:288 pass:223 dwarn:1 dfail:0 fail:0 skip:64 time:385s fi-bsw-n3050 total:288 pass:242 dwarn:0 dfail:0 fail:0 skip:46 time:519s fi-bwr-2160 total:288 pass:183 dwarn:0 dfail:0 fail:0 skip:105 time:280s fi-bxt-dsi total:288 pass:258 dwarn:0 dfail:0 fail:0 skip:30 time:505s fi-bxt-j4205 total:288 pass:259 dwarn:0 dfail:0 fail:0 skip:29 time:511s fi-byt-j1900 total:288 pass:253 dwarn:0 dfail:0 fail:0 skip:35 time:482s fi-byt-n2820 total:288 pass:249 dwarn:0 dfail:0 fail:0 skip:39 time:473s fi-elk-e7500 total:224 pass:163 dwarn:15 dfail:0 fail:0 skip:45 fi-gdg-551 total:288 pass:178 dwarn:1 dfail:0 fail:1 skip:108 time:267s fi-glk-1 total:288 pass:260 dwarn:0 dfail:0 fail:0 skip:28 time:536s fi-hsw-4770 total:288 pass:261 dwarn:0 dfail:0 fail:0 skip:27 time:373s fi-hsw-4770r total:288 pass:224 dwarn:0 dfail:0 fail:0 skip:64 time:260s fi-ilk-650 total:288 pass:228 dwarn:0 dfail:0 fail:0 skip:60 time:399s fi-ivb-3770 total:288 pass:259 dwarn:0 dfail:0 fail:0 skip:29 time:447s fi-kbl-7500u total:288 pass:263 dwarn:1 dfail:0 fail:0 skip:24 time:483s fi-kbl-7560u total:288 pass:269 dwarn:0 dfail:0 fail:0 skip:19 time:526s fi-kbl-7567u total:288 pass:268 dwarn:0 dfail:0 fail:0 skip:20 time:470s fi-pnv-d510 total:288 pass:222 dwarn:1 dfail:0 fail:0 skip:65 time:585s fi-skl-6600u total:288 pass:261 dwarn:0 dfail:0 fail:0 skip:27 time:544s fi-skl-6700hq total:288 pass:262 dwarn:0 dfail:0 fail:0 skip:26 time:565s fi-skl-6700k total:288 pass:264 dwarn:0 dfail:0 fail:0 skip:24 time:522s fi-skl-6770hq total:288 pass:268 dwarn:0 dfail:0 fail:0 skip:20 time:497s fi-skl-gvtdvm total:288 pass:265 dwarn:0 dfail:0 fail:0 skip:23 time:443s fi-snb-2520m total:288 pass:249 dwarn:0 dfail:0 fail:0 skip:39 time:548s fi-snb-2600 total:288 pass:248 dwarn:0 dfail:0 fail:0 skip:40 time:414s Blacklisted hosts: fi-cfl-s2 total:288 pass:262 dwarn:0 dfail:0 fail:0 skip:26 time:595s fi-cnl-y total:288 pass:262 dwarn:0 dfail:0 fail:0 skip:26 time:624s fi-glk-dsi total:288 pass:190 dwarn:1 dfail:4 fail:0 skip:93 time:431s
bb55ba9311dea38dcf8fb1a6c447505dc635f54f drm-tip: 2017y-12m-11d-11h-51m-11s UTC integration manifest 2ff9e2cfcb9b drm/i915: use static const array for PICK macro
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_7466/issues.html
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoting Chris Wilson (2017-12-11 12:51:42)
Quoted 62 lines
Quoting Arnd Bergmann (2017-12-11 12:46:22)
Quoted 54 lines
The varargs macro trick in _PIPE3/_PHY3/_PORT3 was meant as an optimization to shrink the i915 kernel module by around 1000 bytes. However, the downside is a size regression with
CONFIG_KASAN, as I found from stack size warnings with gcc-7.0.1:before:
drivers/gpu/drm/i915/intel_dpll_mgr.c: In function 'bxt_ddi_pll_get_hw_state':drivers/gpu/drm/i915/intel_dpll_mgr.c:1644:1: error: the frame size of 176 bytes is larger than 100 bytes [-Werror=frame-larger-than=]drivers/gpu/drm/i915/intel_dpll_mgr.c: In function 'bxt_ddi_pll_enable':drivers/gpu/drm/i915/intel_dpll_mgr.c:1548:1: error: the frame size of 224 bytes is larger than 100 bytes [-Werror=frame-larger-than=]after:
drivers/gpu/drm/i915/intel_dpll_mgr.c: In function 'bxt_ddi_pll_get_hw_state':drivers/gpu/drm/i915/intel_dpll_mgr.c:1644:1: error: the frame size of 1016 bytes is larger than 1000 bytes [-Werror=frame-larger-than=]drivers/gpu/drm/i915/intel_dpll_mgr.c: In function 'bxt_ddi_pll_enable':drivers/gpu/drm/i915/intel_dpll_mgr.c:1548:1: error: the frame size of 1960 bytes is larger than 1000 bytes [-Werror=frame-larger-than=]I also checked the module sizes and got with gcc-7.0.1
original:
text data bss dec hex filename2380830 1155436 4448 3540714 3606ea drivers/gpu/drm/i915/i915-kasan.o 1298054 543692 2884 1844630 1c2596 drivers/gpu/drm/i915/i915-nokasan.oafter
ce64645d86ac:
text data bss dec hex filename2389515 1154476 4448 3548439 362517 drivers/gpu/drm/i915/i915-kasan.o 1299639 543692 2884 1846215 1c2bc7 drivers/gpu/drm/i915/i915-nokasan.owith this patch:
text data bss dec hex filename2381275 1163884 4448 3549607 3629a7 drivers/gpu/drm/i915/i915-kasan.o 1296038 543692 2884 1842614 1c1db6 drivers/gpu/drm/i915/i915-nokasan.oActually showing a code size growth in .text both with and without kasan, and my version gets most of it back at the expense of larger .data when kasan is enabled.
Fixes ce64645d86ac ("drm/i915: use variadic macros and arrays to choose port/pipe based registers")Cc Jani Nikula <[email protected]>Signed-off-by Arnd Bergmann <[email protected]>---
v2: rebased aftera1986f4174a4("drm/i915: Remove unnecessary PORT3 definition.")--- drivers/gpu/drm/i915/i915_reg.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)drivers/gpu/drm/i915/i915_reg.h +0
-0drivers/gpu/drm/i915/i915_reg.h static inline bool i915_mmio_reg_valid(i915_reg_t reg) · line 142
Quoted 5 lines
drivers/gpu/drm/i915/i915_reg.h +1
-1@@ -139,7 +139,7 @@ static inline bool i915_mmio_reg_valid(i915_reg_t reg)return !i915_mmio_reg_equal (reg,INVALID_MMIO_REG ); } -#define _PICK (__index, ...) (((const u32 []){ __VA_ARGS__ })[__index]) +#define _PICK (__index, ...) ({static const u32 __arr[] = { __VA_ARGS__ }; __arr[__index];})Is gcc smart enough for
Quoted 7 lines
if (__builtin_context_p(__index)) { ((const u32 []){ __VA_ARGS__ })[__index]; } else { static const u32 __arr[] = { __VA_ARGS__ }; __arr[__index]; }?
Not really, we don't have enough constants for it to make a substantial difference:
add/remove: 1/0 grow/shrink: 3/5 up/down: 617/-604 (13)
Function old new delta cnl_ddi_vswing_program.isra - 574 +574 bxt_ddi_phy_is_enabled 220 241 +21 bxt_ddi_phy_set_signal_level 537 556 +19 i9xx_get_pipe_config 1474 1477 +3 bxt_ddi_phy_verify_state 411 408 -3 _bxt_ddi_phy_init 956 950 -6 vlv_display_power_well_init 470 461 -9
bxt_ddi_pll_get_hw_state 774 762 -12cnl_ddi_vswing_sequence 1166 592 -574
Total: Before=13461532, After=13461545, chg +0.00%
Of particular note the size of __arr[] is not reduced, so gcc is already eliminating the static[] for constant index, or not eliminating the redundant branch here.
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 39 lines · Chris Wilson
Quoting Chris Wilson (2017-12-11 12:51:42)
Quoted 18 lines
Quoting Arnd Bergmann (2017-12-11 12:46:22)
Quoted 10 lines
v2: rebased after
a1986f4174a4("drm/i915: Remove unnecessary PORT3 definition.")--- drivers/gpu/drm/i915/i915_reg.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)drivers/gpu/drm/i915/i915_reg.h +0
-0drivers/gpu/drm/i915/i915_reg.h static inline bool i915_mmio_reg_valid(i915_reg_t reg) · line 142
Quoted 5 lines
drivers/gpu/drm/i915/i915_reg.h +1
-1@@ -139,7 +139,7 @@ static inline bool i915_mmio_reg_valid(i915_reg_t reg)return !i915_mmio_reg_equal (reg,INVALID_MMIO_REG ); } -#define _PICK (__index, ...) (((const u32 []){ __VA_ARGS__ })[__index]) +#define _PICK (__index, ...) ({static const u32 __arr[] = { __VA_ARGS__ }; __arr[__index];})Is gcc smart enough for
Quoted 7 lines
if (__builtin_context_p(__index)) { ((const u32 []){ __VA_ARGS__ })[__index]; } else { static const u32 __arr[] = { __VA_ARGS__ }; __arr[__index]; }?
Not really, we don't have enough constants for it to make a substantial difference:
add/remove: 1/0 grow/shrink: 3/5 up/down: 617/-604 (13)
Function old new delta cnl_ddi_vswing_program.isra - 574 +574 bxt_ddi_phy_is_enabled 220 241 +21 bxt_ddi_phy_set_signal_level 537 556 +19 i9xx_get_pipe_config 1474 1477 +3 bxt_ddi_phy_verify_state 411 408 -3 _bxt_ddi_phy_init 956 950 -6 vlv_display_power_well_init 470 461 -9
Quoted 7 lines
bxt_ddi_pll_get_hw_state774 762 -12cnl_ddi_vswing_sequence1166 592 -574
Total: Before=13461532, After=13461545, chg +0.00%Of particular note the size of __arr[] is not reduced, so gcc is already eliminating the static[] for constant index, or not eliminating the redundant branch here.
I noticed we never concluded here. Did you see anything wrong with my workaround in the end or could we just apply it to avoid the stack size regression?
Arnd
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx