Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp3313957rdb; Tue, 6 Feb 2024 13:50:54 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVQ1j4ucPJCDqGXzIk1xkJnsz1/PdAKyyNbxZDW9KHOin/Ue+RH0GlNtA4Pek2QltHz4O8QoLrbgT6GL1AnkfeEKr8CpJ6gnsDB/D646g== X-Google-Smtp-Source: AGHT+IEeq9S8Qp/ihJmvho6uKQyIB+jObE3n2FUzMoPIw85dLNWoudwwDIBA/zSN2WUZe9Zx/LnH X-Received: by 2002:a17:906:d93:b0:a36:c275:55e4 with SMTP id m19-20020a1709060d9300b00a36c27555e4mr4729802eji.15.1707256254242; Tue, 06 Feb 2024 13:50:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707256254; cv=pass; d=google.com; s=arc-20160816; b=gQ8Fx8jMOgQdWg9iF88ASop61nDv1VC+u2ztm9s6NgTXfRyEWKEtLQLixOfprczMG5 6r49ZtNVklnhUXCK8QR1Jtea/FM4sxWnjShFXgW+ibgttVUAX4ARbHhT4Z529gkN+UBc 2qqiTlD02ADldaO+QMyJrAsGzCASNQGiwdmboxulen6EMmrpE/edZuHKCpNiBMxQ2FEF zyazft4y/ZIDT0bkqiKDrf6tw+ASLp44sbCu8i33qbYrJ3NcEYbNSH4X034atHPYwSIu +Vy7P+dvmM5sKIM+Nhxon0l3bxFIoW2lga54uXBKFmDxYpJilZrFEHJ9BM0UvMMgfqkB hHCg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=5QwwD9KFlLch7qX+8L+lYfwlnDsJ5v9LVoktCWokEZI=; fh=5UIua33O3wrCB3415XjuJY9So6BmqMIDYg2QuUQz5yQ=; b=hUJwG4eCvy12BWPm1XEcbALVWqMtN5MKMnXjHQADbE0QBeVjpYY0lD/SM1JQhTbaw5 d/0EWh90BFV5LPtCn7lmVVUiBlkktrgoV5pZYux3/UCJmWels8TEZ/XRR2xsS3A1+WG2 V8YGLTdZuEhdZhXgAZn19gYzUL0i84CGBqgTJVIC0Wb9/rXhbpli1fa+HGUbtiIah4jh naq2ohCaULwpFG1OMIceZtjkBB7o4lnyjqww1Bl2O1NP+FqzKE9dAGnDDf2Ix+6GifF+ 7797SY1vO15XO7Dszwp2slJEPRfc4TcoCwl08pWxUIU3jTbIy3Jb9p+xW032KVChMPJ0 3VuQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=Nq9ZoVbj; arc=pass (i=1 spf=pass spfdomain=wanadoo.fr dkim=pass dkdomain=wanadoo.fr dmarc=pass fromdomain=wanadoo.fr); spf=pass (google.com: domain of linux-kernel+bounces-55656-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55656-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr X-Forwarded-Encrypted: i=1; AJvYcCVMinz6r13C9nibH0v/UlKVLhBYN2g9CsKEnTv7wHvMBH3B2edLrpmk7IC5DF+YSRp9kSpvDYOA8gK5yerCbRaC1CGyWg+rc8783JsVRA== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id b2-20020a170906d10200b00a385dd96889si217491ejz.523.2024.02.06.13.50.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 13:50:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55656-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=Nq9ZoVbj; arc=pass (i=1 spf=pass spfdomain=wanadoo.fr dkim=pass dkdomain=wanadoo.fr dmarc=pass fromdomain=wanadoo.fr); spf=pass (google.com: domain of linux-kernel+bounces-55656-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55656-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id C81981F23343 for ; Tue, 6 Feb 2024 21:50:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BE3051BC27; Tue, 6 Feb 2024 21:50:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b="Nq9ZoVbj" Received: from smtp.smtpout.orange.fr (smtp-23.smtpout.orange.fr [80.12.242.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD1C51B94C; Tue, 6 Feb 2024 21:50:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.12.242.23 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707256245; cv=none; b=eMqop/Ho22Ar0ji05qWdi3xBOTq6wlLDnXgOQk6BqIBHr/Y+DLjRDxiTrdBmTrHGdOs0YRAVgUU7ONFmCKVY4OIJ5dEUY2Q6RuUbImdGHcoZ9v52AvyoPw8qJqebCzrOalTfihm+wveki2I3cTQ8i18UNgu8m1kPhCLIiX82ISc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707256245; c=relaxed/simple; bh=vojBpdB7dXWi+U3h40tzRjjL6Zt6ey/qpX2zIWiA2Tg=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=PgS9HFQ2RcjayYqcnA5E4rignmVtGH7Qqq/lqsVVjQUapB/sDUvdIBiUROxZtXYrhbUP5UkjuC8A3nipYs7Ay8WLzUlcKj+ts3NTnlyJYrkKi3ejKGZ3m9jTYI7N8s6HyLX5mppy8aQM9N2RLZFoT64uC3vnyJdQS7pLZW8Nvjk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=wanadoo.fr; spf=pass smtp.mailfrom=wanadoo.fr; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b=Nq9ZoVbj; arc=none smtp.client-ip=80.12.242.23 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=wanadoo.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wanadoo.fr Received: from [192.168.1.18] ([92.140.202.140]) by smtp.orange.fr with ESMTPA id XTKsrOaGI3bwWXTKsrejsb; Tue, 06 Feb 2024 22:50:35 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1707256235; bh=5QwwD9KFlLch7qX+8L+lYfwlnDsJ5v9LVoktCWokEZI=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=Nq9ZoVbjiZesVvOjCn9ynvsTT0WxrmP6ZzWubssVjCcO31Dl2Q9PRiNzJmsxOl+T0 2um+M9HDFSK3bU4zGj2EHDbqtuZQq1DwyqtBubyFsc6sgjM8I56NzaoA9Yp5eltepP g4zwP9NSeHntiSYYRQZghqLmfMkiJ5nrUvP8Nx+kMFIPO1oAwbrNq8gp3/w+VybqkH sjkJMnne+Q+041pExemIRDJJ/ocyPRmcivNle9N/Vyf5uiX8GC59DwGIUI7fENcqoA l2ET6mhrwagN1/plXDL/EhPQkARVCoVGzxENnSaFozzvQMEahDu6BQ2JESC7sw0nTf 59Jv7f7DQj9WA== X-ME-Helo: [192.168.1.18] X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Tue, 06 Feb 2024 22:50:35 +0100 X-ME-IP: 92.140.202.140 Message-ID: <0158a82f-5445-43b9-9da5-8655c3a97c4d@wanadoo.fr> Date: Tue, 6 Feb 2024 22:50:34 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] spi: axi-spi-engine: remove use of ida for sync id Content-Language: en-MW To: dlechner@baylibre.com Cc: broonie@kernel.org, linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org, michael.hennerich@analog.com, nuno.sa@analog.com References: <20240206-axi-spi-engine-round-2-1-v1-0-ea6eeb60f4fb@baylibre.com> <20240206-axi-spi-engine-round-2-1-v1-1-ea6eeb60f4fb@baylibre.com> From: Christophe JAILLET In-Reply-To: <20240206-axi-spi-engine-round-2-1-v1-1-ea6eeb60f4fb@baylibre.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Le 06/02/2024 à 21:31, David Lechner a écrit : > 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... So, maybe #include can be removed as well? (untested) Also, even if unrelated to your changes, spi_engine_prepare_message() could use struct_size() in: size = sizeof(*p->instructions) * (p_dry.length + 1); p = kzalloc(sizeof(*p) + size, GFP_KERNEL); --> p = kzalloc(struct_size(p, instructions, p_dry.length + 1, GFP_KERNEL); which can be a little safer and less verbose. CJ > ...for the sync id and replaces it with a > constant value. This simplifies the driver and improves performance. > > Signed-off-by: David Lechner > --- > drivers/spi/spi-axi-spi-engine.c | 27 ++++++--------------------- > 1 file changed, 6 insertions(+), 21 deletions(-) > > diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c > index 6b0c72bf3395..9cc602075c17 100644 > --- a/drivers/spi/spi-axi-spi-engine.c > +++ b/drivers/spi/spi-axi-spi-engine.c > @@ -57,6 +57,9 @@ > #define SPI_ENGINE_TRANSFER_WRITE 0x1 > #define SPI_ENGINE_TRANSFER_READ 0x2 > > +/* Arbitrary sync ID for use by host->cur_msg */ > +#define AXI_SPI_ENGINE_CUR_MSG_SYNC_ID 0x1 > + > #define SPI_ENGINE_CMD(inst, arg1, arg2) \ > (((inst) << 12) | ((arg1) << 8) | (arg2)) > > @@ -98,8 +101,6 @@ struct spi_engine_message_state { > unsigned int rx_length; > /** @rx_buf: Bytes not yet written to the RX FIFO. */ > uint8_t *rx_buf; > - /** @sync_id: ID to correlate SYNC interrupts with this message. */ > - u8 sync_id; > }; > > struct spi_engine { > @@ -109,7 +110,6 @@ struct spi_engine { > spinlock_t lock; > > void __iomem *base; > - struct ida sync_ida; > struct timer_list watchdog_timer; > struct spi_controller *controller; > > @@ -483,9 +483,7 @@ static irqreturn_t spi_engine_irq(int irq, void *devid) > } > > if (pending & SPI_ENGINE_INT_SYNC && msg) { > - struct spi_engine_message_state *st = msg->state; > - > - if (completed_id == st->sync_id) { > + if (completed_id == AXI_SPI_ENGINE_CUR_MSG_SYNC_ID) { > if (timer_delete_sync(&spi_engine->watchdog_timer)) { > msg->status = 0; > msg->actual_length = msg->frame_length; > @@ -510,10 +508,8 @@ static int spi_engine_prepare_message(struct spi_controller *host, > struct spi_message *msg) > { > struct spi_engine_program p_dry, *p; > - struct spi_engine *spi_engine = spi_controller_get_devdata(host); > struct spi_engine_message_state *st; > size_t size; > - int ret; > > st = kzalloc(sizeof(*st), GFP_KERNEL); > if (!st) > @@ -531,18 +527,10 @@ static int spi_engine_prepare_message(struct spi_controller *host, > return -ENOMEM; > } > > - ret = ida_alloc_range(&spi_engine->sync_ida, 0, U8_MAX, GFP_KERNEL); > - if (ret < 0) { > - kfree(p); > - kfree(st); > - return ret; > - } > - > - st->sync_id = ret; > - > spi_engine_compile_message(msg, false, p); > > - spi_engine_program_add_cmd(p, false, SPI_ENGINE_CMD_SYNC(st->sync_id)); > + spi_engine_program_add_cmd(p, false, SPI_ENGINE_CMD_SYNC( > + AXI_SPI_ENGINE_CUR_MSG_SYNC_ID)); > > st->p = p; > st->cmd_buf = p->instructions; > @@ -555,10 +543,8 @@ static int spi_engine_prepare_message(struct spi_controller *host, > static int spi_engine_unprepare_message(struct spi_controller *host, > struct spi_message *msg) > { > - struct spi_engine *spi_engine = spi_controller_get_devdata(host); > struct spi_engine_message_state *st = msg->state; > > - ida_free(&spi_engine->sync_ida, st->sync_id); > kfree(st->p); > kfree(st); > > @@ -640,7 +626,6 @@ static int spi_engine_probe(struct platform_device *pdev) > spi_engine = spi_controller_get_devdata(host); > > spin_lock_init(&spi_engine->lock); > - ida_init(&spi_engine->sync_ida); > timer_setup(&spi_engine->watchdog_timer, spi_engine_timeout, TIMER_IRQSAFE); > spi_engine->controller = host; > >