Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

spi: axi-spi-engine: remove use of ida for sync id

Profiling has shown that ida_alloc_range() accounts for about 10% of the
time spent in spi_sync() when using the AXI SPI Engine controller. This
call is used to create a unique id for each SPI message to match to an
IRQ when the message is complete.

Since the core SPI code serializes messages in a message queue, we can
only have one message in flight at a time, namely host->cur_msg. This
means that we can use a fixed value instead of a unique id for each
message since there can never be more than one message pending at a
time.

This patch removes the use of ida for the sync id and replaces it with a
constant value. This simplifies the driver and improves performance.

Reviewed-by: Nuno Sa <nuno.sa@analog.com>
Signed-off-by: David Lechner <dlechner@baylibre.com>
Link: https://lore.kernel.org/r/20240207-axi-spi-engine-round-2-1-v2-1-40c0b4e85352@baylibre.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

David Lechner and committed by
Mark Brown
531860e1 c0c0293c

+6 -22
+6 -22
drivers/spi/spi-axi-spi-engine.c
··· 7 7 8 8 #include <linux/clk.h> 9 9 #include <linux/fpga/adi-axi-common.h> 10 - #include <linux/idr.h> 11 10 #include <linux/interrupt.h> 12 11 #include <linux/io.h> 13 12 #include <linux/of.h> ··· 56 57 #define SPI_ENGINE_TRANSFER_WRITE 0x1 57 58 #define SPI_ENGINE_TRANSFER_READ 0x2 58 59 60 + /* Arbitrary sync ID for use by host->cur_msg */ 61 + #define AXI_SPI_ENGINE_CUR_MSG_SYNC_ID 0x1 62 + 59 63 #define SPI_ENGINE_CMD(inst, arg1, arg2) \ 60 64 (((inst) << 12) | ((arg1) << 8) | (arg2)) 61 65 ··· 100 98 unsigned int rx_length; 101 99 /** @rx_buf: Bytes not yet written to the RX FIFO. */ 102 100 uint8_t *rx_buf; 103 - /** @sync_id: ID to correlate SYNC interrupts with this message. */ 104 - u8 sync_id; 105 101 }; 106 102 107 103 struct spi_engine { ··· 109 109 spinlock_t lock; 110 110 111 111 void __iomem *base; 112 - struct ida sync_ida; 113 112 struct timer_list watchdog_timer; 114 113 struct spi_controller *controller; 115 114 ··· 482 483 } 483 484 484 485 if (pending & SPI_ENGINE_INT_SYNC && msg) { 485 - struct spi_engine_message_state *st = msg->state; 486 - 487 - if (completed_id == st->sync_id) { 486 + if (completed_id == AXI_SPI_ENGINE_CUR_MSG_SYNC_ID) { 488 487 if (timer_delete_sync(&spi_engine->watchdog_timer)) { 489 488 msg->status = 0; 490 489 msg->actual_length = msg->frame_length; ··· 507 510 struct spi_message *msg) 508 511 { 509 512 struct spi_engine_program p_dry, *p; 510 - struct spi_engine *spi_engine = spi_controller_get_devdata(host); 511 513 struct spi_engine_message_state *st; 512 514 size_t size; 513 - int ret; 514 515 515 516 st = kzalloc(sizeof(*st), GFP_KERNEL); 516 517 if (!st) ··· 526 531 return -ENOMEM; 527 532 } 528 533 529 - ret = ida_alloc_range(&spi_engine->sync_ida, 0, U8_MAX, GFP_KERNEL); 530 - if (ret < 0) { 531 - kfree(p); 532 - kfree(st); 533 - return ret; 534 - } 535 - 536 - st->sync_id = ret; 537 - 538 534 spi_engine_compile_message(msg, false, p); 539 535 540 - spi_engine_program_add_cmd(p, false, SPI_ENGINE_CMD_SYNC(st->sync_id)); 536 + spi_engine_program_add_cmd(p, false, SPI_ENGINE_CMD_SYNC( 537 + AXI_SPI_ENGINE_CUR_MSG_SYNC_ID)); 541 538 542 539 st->p = p; 543 540 st->cmd_buf = p->instructions; ··· 542 555 static int spi_engine_unprepare_message(struct spi_controller *host, 543 556 struct spi_message *msg) 544 557 { 545 - struct spi_engine *spi_engine = spi_controller_get_devdata(host); 546 558 struct spi_engine_message_state *st = msg->state; 547 559 548 - ida_free(&spi_engine->sync_ida, st->sync_id); 549 560 kfree(st->p); 550 561 kfree(st); 551 562 ··· 625 640 spi_engine = spi_controller_get_devdata(host); 626 641 627 642 spin_lock_init(&spi_engine->lock); 628 - ida_init(&spi_engine->sync_ida); 629 643 timer_setup(&spi_engine->watchdog_timer, spi_engine_timeout, TIMER_IRQSAFE); 630 644 spi_engine->controller = host; 631 645