Skip to content

Commit 295b6c0

Browse files
committed
drm/etnaviv: slow down FE idle polling
Currently the FE is spinning way too fast when polling for new work in the FE idleloop. As each poll fetches 16 bytes from memory, a GPU running at 1GHz with the current setting of 200 wait cycle between fetches causes 80 MB/s of memory traffic just to check for new work when the GPU is otherwise idle, which is more FE traffic than in some GPU loaded cases. Significantly increase the number of wait cycles to slow down the poll interval to ~30µs, limiting the FE idle memory traffic to 512 KB/s, while providing a max latency which should not hurt most use-cases. The FE WAIT command seems to have some unknown discrete steps in the wait cycles so we may over/undershoot the target a bit, but that should be harmless. If the GPU core base frequency is unknown keep the 200 wait cycles as a sane default. Signed-off-by: Lucas Stach <l.stach@pengutronix.de> Reviewed-by: Sui Jingfeng <suijingfeng@loongson.cn> Tested-by: Sui Jingfeng <suijingfeng@loongson.cn> Reviewed-by: Christian Gmeiner <cgmeiner@igalia.com>
1 parent 426f6e7 commit 295b6c0

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

drivers/gpu/drm/etnaviv/etnaviv_buffer.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ static inline void CMD_END(struct etnaviv_cmdbuf *buffer)
5353
OUT(buffer, VIV_FE_END_HEADER_OP_END);
5454
}
5555

56-
static inline void CMD_WAIT(struct etnaviv_cmdbuf *buffer)
56+
static inline void CMD_WAIT(struct etnaviv_cmdbuf *buffer,
57+
unsigned int waitcycles)
5758
{
5859
buffer->user_size = ALIGN(buffer->user_size, 8);
5960

60-
OUT(buffer, VIV_FE_WAIT_HEADER_OP_WAIT | 200);
61+
OUT(buffer, VIV_FE_WAIT_HEADER_OP_WAIT | waitcycles);
6162
}
6263

6364
static inline void CMD_LINK(struct etnaviv_cmdbuf *buffer,
@@ -168,7 +169,7 @@ u16 etnaviv_buffer_init(struct etnaviv_gpu *gpu)
168169
/* initialize buffer */
169170
buffer->user_size = 0;
170171

171-
CMD_WAIT(buffer);
172+
CMD_WAIT(buffer, gpu->fe_waitcycles);
172173
CMD_LINK(buffer, 2,
173174
etnaviv_cmdbuf_get_va(buffer, &gpu->mmu_context->cmdbuf_mapping)
174175
+ buffer->user_size - 4);
@@ -320,7 +321,7 @@ void etnaviv_sync_point_queue(struct etnaviv_gpu *gpu, unsigned int event)
320321
CMD_END(buffer);
321322

322323
/* Append waitlink */
323-
CMD_WAIT(buffer);
324+
CMD_WAIT(buffer, gpu->fe_waitcycles);
324325
CMD_LINK(buffer, 2,
325326
etnaviv_cmdbuf_get_va(buffer, &gpu->mmu_context->cmdbuf_mapping)
326327
+ buffer->user_size - 4);
@@ -503,7 +504,7 @@ void etnaviv_buffer_queue(struct etnaviv_gpu *gpu, u32 exec_state,
503504

504505
CMD_LOAD_STATE(buffer, VIVS_GL_EVENT, VIVS_GL_EVENT_EVENT_ID(event) |
505506
VIVS_GL_EVENT_FROM_PE);
506-
CMD_WAIT(buffer);
507+
CMD_WAIT(buffer, gpu->fe_waitcycles);
507508
CMD_LINK(buffer, 2,
508509
etnaviv_cmdbuf_get_va(buffer, &gpu->mmu_context->cmdbuf_mapping)
509510
+ buffer->user_size - 4);

drivers/gpu/drm/etnaviv/etnaviv_gpu.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,14 @@ static void etnaviv_gpu_update_clock(struct etnaviv_gpu *gpu)
493493
clock |= VIVS_HI_CLOCK_CONTROL_FSCALE_VAL(fscale);
494494
etnaviv_gpu_load_clock(gpu, clock);
495495
}
496+
497+
/*
498+
* Choose number of wait cycles to target a ~30us (1/32768) max latency
499+
* until new work is picked up by the FE when it polls in the idle loop.
500+
* If the GPU base frequency is unknown use 200 wait cycles.
501+
*/
502+
gpu->fe_waitcycles = clamp(gpu->base_rate_core >> (15 - gpu->freq_scale),
503+
200UL, 0xffffUL);
496504
}
497505

498506
static int etnaviv_hw_reset(struct etnaviv_gpu *gpu)

drivers/gpu/drm/etnaviv/etnaviv_gpu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ struct etnaviv_gpu {
150150
struct clk *clk_shader;
151151

152152
unsigned int freq_scale;
153+
unsigned int fe_waitcycles;
153154
unsigned long base_rate_core;
154155
unsigned long base_rate_shader;
155156
};

0 commit comments

Comments
 (0)