drm/amdgpu: throttle buffer migrations at CS using a fixed MBps limit (v2)
Subsystems (2)
PATCH 1/1 drm/amdgpu: throttle buffer migrations at CS using a fixed MBps limit (v2)
From: Marek Olšák <[email protected]>
The old mechanism used a per-submission limit that didn't take previous submissions within the same time frame into account. It also filled VRAM slowly when VRAM usage dropped due to a big eviction or buffer deallocation.
This new method establishes a configurable MBps limit that is obeyed when VRAM usage is very high. When VRAM usage is not very high, it gives the driver the freedom to fill it quickly. The result is more consistent performance.
It can't keep the BO move rate low if lots of evictions are happening due to VRAM fragmentation, or if a big buffer is being migrated.
The amdgpu.moverate parameter can be used to set a non-default limit. Measurements can be done to find out which amdgpu.moverate setting gives the best results.
Mainly APUs and cards with small VRAM will benefit from this. For F1 2015, anything with 2 GB VRAM or less will benefit.
Some benchmark results - F1 2015 (Tonga 2GB):
Limit MinFPS AvgFPS Old code: 14 32.6 128 MB/s: 28 41 64 MB/s: 15.5 43 32 MB/s: 28.7 43.4 8 MB/s: 27.8 44.4 8 MB/s: 21.9 42.8 (different run)
Random drops in Min FPS can still occur (due to fragmented VRAM?), but the average FPS is much better. 8 MB/s is probably a good limit for this game & the current VRAM management. The random FPS drops are still to be tackled.
v2: use a spinlock
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 9 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 152 ++++++++++++++++++++--------- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 10 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 4 + 4 files changed, 127 insertions(+), 48 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +9 -0
@@ -58,20 +58,21 @@#include "amd_powerplay.h" #include "gpu_scheduler.h" /* * Modules parameters. */ extern int amdgpu_modeset;extern int amdgpu_vram_limit;extern int amdgpu_gart_size; +extern int amdgpu_moverate;extern int amdgpu_benchmarking;extern int amdgpu_testing;extern int amdgpu_audio;extern int amdgpu_disp_priority;extern int amdgpu_hw_i2c;extern int amdgpu_pcie_gen2;extern int amdgpu_msi;extern int amdgpu_lockup_timeout;extern int amdgpu_dpm;extern int amdgpu_smc_load_fw;
@@ -2029,20 +2030,28 @@ struct amdgpu_device {struct amdgpu_mman mman;struct amdgpu_vram_scratch vram_scratch;struct amdgpu_wb wb;atomic64_t vram_usage;atomic64_t vram_vis_usage;atomic64_t gtt_usage;atomic64_t num_bytes_moved;atomic64_t num_evictions;atomic_t gpu_reset_counter; +/* data for buffer migration throttling */ +struct { +spinlock_t lock; +s64 last_update_us; +s64 accum_us;/* accumulated microseconds */ +u32 log2_max_MBps; + } mm_stats; +/* display */ bool enable_virtual_display;struct amdgpu_mode_info mode_info;/* For pre-DCE11. DCE11 and later are in "struct amdgpu_device->dm" */ struct work_struct hotplug_work;struct amdgpu_irq_src crtc_irq;struct amdgpu_irq_src pageflip_irq;struct amdgpu_irq_src hpd_irq;/* rings */
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +104 -48
215 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +10 -0
@@ -1521,20 +1521,21 @@ static bool amdgpu_device_is_virtual(void)* Returns 0 for success or an error on failure. * Called at driver startup. */ int amdgpu_device_init (struct amdgpu_device *adev,struct drm_device *ddev,struct pci_dev *pdev,uint32_t flags) {int r, i;bool runtime = false; +u32 max_MBps; adev->shutdown = false; adev->dev = &pdev->dev; adev->ddev = ddev; adev->pdev = pdev; adev->flags = flags; adev->asic_type = flags &AMD_ASIC_MASK ; adev->is_atom_bios = false; adev->usec_timeout =AMDGPU_MAX_USEC_TIMEOUT ; adev->mc.gtt_size =512 *1024 *1024 ;
@@ -1580,20 +1581,21 @@ int amdgpu_device_init(struct amdgpu_device *adev,/* Registers mapping */ /* TODO: block userspace mapping of io register */ spin_lock_init (&adev->mmio_idx_lock);spin_lock_init (&adev->smc_idx_lock);spin_lock_init (&adev->pcie_idx_lock);spin_lock_init (&adev->uvd_ctx_idx_lock);spin_lock_init (&adev->didt_idx_lock);spin_lock_init (&adev->gc_cac_idx_lock);spin_lock_init (&adev->audio_endpt_idx_lock); +spin_lock_init (&adev->mm_stats.lock);INIT_LIST_HEAD (&adev->shadow_list);mutex_init (&adev->shadow_list_lock); adev->rmmio_base =pci_resource_start (adev->pdev,5 ); adev->rmmio_size =pci_resource_len (adev->pdev,5 ); adev->rmmio =ioremap (adev->rmmio_base, adev->rmmio_size);if (adev->rmmio ==NULL ) {return -ENOMEM ; }
@@ -1693,20 +1695,28 @@ int amdgpu_device_init(struct amdgpu_device *adev, r =amdgpu_init (adev);if (r) {dev_err (adev->dev,"amdgpu_init failed\n" );amdgpu_fini (adev); goto failed; } adev->accel_working = true; +/* Initialize the buffer migration limit. */ +if (amdgpu_moverate >=0 ) + max_MBps = amdgpu_moverate; +else + max_MBps =8 ;/* Allow 8 MB/s. */ +/* Get a log2 for easy divisions. */ + adev->mm_stats.log2_max_MBps =ilog2 (max (1u , max_MBps)); +amdgpu_fbdev_init (adev); r =amdgpu_ib_pool_init (adev);if (r) {dev_err (adev->dev,"IB initialization failed (%d).\n" , r); goto failed; } r =amdgpu_ib_ring_tests (adev);if (r)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +4 -0
@@ -54,20 +54,21 @@* at the end of IBs. * - 3.3.0 - Add VM support for UVD on supported hardware. * - 3.4.0 - Add AMDGPU_INFO_NUM_EVICTIONS. */ #define KMS_DRIVER_MAJOR 3#define KMS_DRIVER_MINOR 4#define KMS_DRIVER_PATCHLEVEL 0int amdgpu_vram_limit =0 ;int amdgpu_gart_size =-1 ;/* auto */ +int amdgpu_moverate =-1 ;/* auto */ int amdgpu_benchmarking =0 ;int amdgpu_testing =0 ;int amdgpu_audio =-1 ;int amdgpu_disp_priority =0 ;int amdgpu_hw_i2c =0 ;int amdgpu_pcie_gen2 =-1 ;int amdgpu_msi =-1 ;int amdgpu_lockup_timeout =0 ;int amdgpu_dpm =-1 ;int amdgpu_smc_load_fw =1 ;
@@ -92,20 +93,23 @@ unsigned amdgpu_pcie_lane_cap = 0;unsigned amdgpu_cg_mask =0xffffffff ;unsigned amdgpu_pg_mask =0xffffffff ;char *amdgpu_virtual_display =NULL ;MODULE_PARM_DESC (vramlimit,"Restrict VRAM for testing, in megabytes" );module_param_named (vramlimit, amdgpu_vram_limit, int,0600 );MODULE_PARM_DESC (gartsize,"Size of PCIE/IGP gart to setup in megabytes (32, 64, etc., -1 = auto)" );module_param_named (gartsize, amdgpu_gart_size, int,0600 ); +MODULE_PARM_DESC (moverate,"Maximum buffer migration rate in MB/s. (32, 64, etc., -1=auto, 0=1=disabled)" ); +module_param_named (moverate, amdgpu_moverate, int,0600 ); +MODULE_PARM_DESC (benchmark,"Run benchmark" );module_param_named (benchmark, amdgpu_benchmarking, int,0444 );MODULE_PARM_DESC (test,"Run tests" );module_param_named (test, amdgpu_testing, int,0444 );MODULE_PARM_DESC (audio,"Audio enable (-1 = auto, 0 = disable, 1 = enable)" );module_param_named (audio, amdgpu_audio, int,0444 );MODULE_PARM_DESC (disp_priority,"Display Priority (0 = auto, 1 = normal, 2 = high)" );
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx