From patchwork Tue May 14 18:39:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 10943549 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7AC5092A for ; Tue, 14 May 2019 18:40:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C40328869 for ; Tue, 14 May 2019 18:40:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5FFB32887B; Tue, 14 May 2019 18:40:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E0B2F28869 for ; Tue, 14 May 2019 18:40:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mdcXx8zwj9hrnfGBjD8speZhbt3tdH985cdAIrHOcOg=; b=iTDj1c+QWy5RyP DTjTkdPqEaX/KSaDc5jiEl1yLObF2FeXDqZcEuCx/+KFi4YHVl5Lpnv8eLrefqpH7CwOOSOnE1P1f axJTJmBtnHn/vfBmu1KqFnGyVZBh5KZBuWIat/lJ740I+6vCs6adVx2dsmldTAAOeEJTgQmny58F3 ygFROmyc8Kd1VwNtx53TKRHrBSiGnzov2V8fG5HkbMAS0yVqfHtTtHUNinBm47Qnae62Vl6Kuhd8j NMGBKZreZPTzlC4FF+Sh98whgX1k1Vft6EWQWiBjs1UhSjoPNSDUERX3v2W7ZjYKhv6+K58Znu7dT gTACMuAzWA7OwfcRR8Og==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hQcLU-0008Gd-HQ; Tue, 14 May 2019 18:40:12 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hQcLQ-0008Dz-VJ for linux-rockchip@lists.infradead.org; Tue, 14 May 2019 18:40:10 +0000 Received: by mail-pg1-x541.google.com with SMTP id i21so9031912pgi.12 for ; Tue, 14 May 2019 11:40:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bCp66aV1gNxi33sE4L4kBrPzrebCfikC/mxwtWxT3pw=; b=Pg0FWMZIqRZLdiikvIImkxfeP3LRkBxXx/th6apFqSwURqdn63h23semFgSQmGJy6F lwDY5vXvHCiZV70qr4Z+Y4+b86bZf3VwvRVteFfJzUMjjLVFsEnyoqvNDPWMalvLGQ6i Os6I56KrF9GgyES0oR9JXF3o8a9b/ASyBEqzs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bCp66aV1gNxi33sE4L4kBrPzrebCfikC/mxwtWxT3pw=; b=PMs3maJjadWY3cJWRjifgq/u4cCtRsQbSrJavgCuBNaRPsgVEahMeBDrbND0a5n5EK 1ueiONmY10E9flyzv8eBuLboyALZ5TD5yfOiOrWWuvC/wfGVn5wuLyH/RxA0FBlqme6D YYkY3jF/mK7w0DSdC8j1gPQr9wdUcOmiv+K4b1ARVLtDistKMUKzB4Vz8FV1KH2ChCW+ ag/qWNkw2PQ6ix+xhxrdqP3gnkHEs8/2ps+pwqGs6i3MvcNrF3HW7883/uRakht+BsW8 32ZRm0Mjw8B+oqZ0qY3wxVx0LLkvegf14wx6rC0B7rJtDUZZ1F8koL9o6Zp7SBw+GIP8 NSeg== X-Gm-Message-State: APjAAAXzO/vV6fjkQabOWv7PVPwxNcfSA0x4Zxws9aE5yySt5AsR/RoG emy7jBenE58TPaWlMjrm2Wj1ag== X-Google-Smtp-Source: APXvYqwKFFk8VbfvQdWZ//TMaT0qP/i15b1ykYA7pmCwvZ+MflxIyOjEaHAbRIib6vZAH8JiTkSiyA== X-Received: by 2002:a63:a449:: with SMTP id c9mr3561397pgp.149.1557859208387; Tue, 14 May 2019 11:40:08 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:24fa:e766:52c9:e3b2]) by smtp.gmail.com with ESMTPSA id 19sm19182454pgz.24.2019.05.14.11.40.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 11:40:07 -0700 (PDT) From: Douglas Anderson To: Mark Brown , Benson Leung , Enric Balletbo i Serra Subject: [PATCH v3 2/3] spi: Allow SPI devices to request the pumping thread be realtime Date: Tue, 14 May 2019 11:39:34 -0700 Message-Id: <20190514183935.143463-3-dianders@chromium.org> X-Mailer: git-send-email 2.21.0.1020.gf2820cf01a-goog In-Reply-To: <20190514183935.143463-1-dianders@chromium.org> References: <20190514183935.143463-1-dianders@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190514_114009_006918_E96B9945 X-CRM114-Status: GOOD ( 20.10 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: drinkcat@chromium.org, briannorris@chromium.org, Douglas Anderson , linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, mka@chromium.org, Guenter Roeck , linux-spi@vger.kernel.org Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Right now the only way to get the SPI pumping thread bumped up to realtime priority is for the controller to request it. However it may be that the controller works fine with the normal priority but communication to a particular SPI device on the bus needs realtime priority. Let's add a way for devices to request realtime priority when they set themselves up. NOTE: this will just affect the priority of transfers that end up on the SPI core's pumping thread. In many cases transfers happen in the context of the caller so if you need realtime priority for all transfers you should ensure the calling context is also realtime priority. Signed-off-by: Douglas Anderson Reviewed-by: Guenter Roeck --- Changes in v3: - SPI core change now like patch v1 patch #2 (with name "rt"). Changes in v2: - Now only force transfers to the thread for devices that want it. - Squashed patch #1 and #2 together. - Renamed variable to "force_rt_transfers". drivers/spi/spi.c | 36 ++++++++++++++++++++++++++++++------ include/linux/spi/spi.h | 2 ++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 8eb7460dd744..466984796dd9 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1364,10 +1364,32 @@ static void spi_pump_messages(struct kthread_work *work) __spi_pump_messages(ctlr, true); } -static int spi_init_queue(struct spi_controller *ctlr) +/** + * spi_set_thread_rt - set the controller to pump at realtime priority + * @ctlr: controller to boost priority of + * + * This can be called because the controller requested realtime priority + * (by setting the ->rt value before calling spi_register_controller()) or + * because a device on the bus said that its transfers needed realtime + * priority. + * + * NOTE: at the moment if any device on a bus says it needs realtime then + * the thread will be at realtime priority for all transfers on that + * controller. If this eventually becomes a problem we may see if we can + * find a way to boost the priority only temporarily during relevant + * transfers. + */ +static void spi_set_thread_rt(struct spi_controller *ctlr) { struct sched_param param = { .sched_priority = MAX_RT_PRIO - 1 }; + dev_info(&ctlr->dev, + "will run message pump with realtime priority\n"); + sched_setscheduler(ctlr->kworker_task, SCHED_FIFO, ¶m); +} + +static int spi_init_queue(struct spi_controller *ctlr) +{ ctlr->running = false; ctlr->busy = false; @@ -1387,11 +1409,8 @@ static int spi_init_queue(struct spi_controller *ctlr) * request and the scheduling of the message pump thread. Without this * setting the message pump thread will remain at default priority. */ - if (ctlr->rt) { - dev_info(&ctlr->dev, - "will run message pump with realtime priority\n"); - sched_setscheduler(ctlr->kworker_task, SCHED_FIFO, ¶m); - } + if (ctlr->rt) + spi_set_thread_rt(ctlr); return 0; } @@ -2982,6 +3001,11 @@ int spi_setup(struct spi_device *spi) spi_set_cs(spi, false); + if (spi->rt && !spi->controller->rt) { + spi->controller->rt = true; + spi_set_thread_rt(spi->controller); + } + dev_dbg(&spi->dev, "setup mode %d, %s%s%s%s%u bits/w, %u Hz max --> %d\n", (int) (spi->mode & (SPI_CPOL | SPI_CPHA)), (spi->mode & SPI_CS_HIGH) ? "cs_high, " : "", diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 053abd22ad31..15505c2485d6 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -109,6 +109,7 @@ void spi_statistics_add_transfer_stats(struct spi_statistics *stats, * This may be changed by the device's driver, or left at the * default (0) indicating protocol words are eight bit bytes. * The spi_transfer.bits_per_word can override this for each transfer. + * @rt: Make the pump thread real time priority. * @irq: Negative, or the number passed to request_irq() to receive * interrupts from this device. * @controller_state: Controller's runtime state @@ -143,6 +144,7 @@ struct spi_device { u32 max_speed_hz; u8 chip_select; u8 bits_per_word; + bool rt; u32 mode; #define SPI_CPHA 0x01 /* clock phase */ #define SPI_CPOL 0x02 /* clock polarity */