adi_v5_jtag: avoid RAM exhaustion by limiting jtag queue size

Issue has been found when I tried to read 64 MiB QSPI flash bank.
Bank is memory mapped, default_flash_read() is used for 'flash read_bank'
command. OpenOCD consumed as much as 6.8 GiB of RAM during this
process. Investigation showed that this happens because JTAG queue
is not limited in any way. OpenOCD queues 16 millions of AP reads
allocating all corresponding data structures.

Most of this memory is allocated in:
cmd_queue_alloc (commands.c) - 4.2 GiB
dap_cmd_new (adi_v5_jtag.c) - 2.25GiB

This patch implements a pool of "struct dap_cmd" objects using
linked list. Objects are taken from a pool in "dap_cmd_new()" and
returned to the pool when they are not needed. Size of the pool
is limited to 64K of objects, JTAG queue is forcibly executed
when this limit is reached.

Checked with Valgrind and Clang analyzer - no new warnings.

Change-Id: I5aaaecce5ed71414f7965a2598f49742f6a6b2b5
Signed-off-by: Bohdan Tymkiv <bhdt@cypress.com>
Reviewed-on: http://openocd.zylin.com/4948
Tested-by: jenkins
Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de>
This commit is contained in:
Bohdan Tymkiv
2019-02-26 11:45:40 +02:00
committed by Andreas Fritiofson
parent 03beb01239
commit 5f42124a40
3 changed files with 97 additions and 25 deletions

View File

@@ -234,6 +234,12 @@ struct adiv5_dap {
/* dap transaction list for WAIT support */
struct list_head cmd_journal;
/* pool for dap_cmd objects */
struct list_head cmd_pool;
/* number of dap_cmd objects in the pool */
size_t cmd_pool_size;
struct jtag_tap *tap;
/* Control config */
uint32_t dp_ctrl_stat;