From patchwork Mon May 13 20:18:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 10941749 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 30FCE15AB for ; Mon, 13 May 2019 20:21:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2181E284D2 for ; Mon, 13 May 2019 20:21:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1592328474; Mon, 13 May 2019 20:21:10 +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=unavailable 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 8AB36284CE for ; Mon, 13 May 2019 20:21:09 +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=t7PBr7LjoCQOqHfgQEXyqz20FjVbLujCLmi2BUk0bOc=; b=mO8mZioKPXVcZt sW7pJBasWO1OcuW8f6JQLaYb5QXZUo1cmBdQeK4ryAPeptb+KqXK25U0oYfLs0MEIcWOEk54xwf1z EMgdctJNz6K93Tz525jJzv5IHwXEdg0TSzvO9u20FNaFV+UMOg9Cm/tY7bNvD0jKoUrKmAGIWu/4U Pc8P28NgUPnOOqdspA2fL1hrws8tOqo+wODmVX+1CvHAJBijwlvEe28HdjozjVwAx+DjZxkGAvQVc SAqNOKt4nCpXCIQ/aIh40lnRbjzYAYCRo0dMRhtc1u0BMAHm2ugKQEUPFY2EmOHlwc/XCJNIR+KAG 1H5oO6EnvgQQKVOXbSdQ==; 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 1hQHRZ-000852-MP; Mon, 13 May 2019 20:21:05 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hQHRP-00080c-90 for linux-rockchip@lists.infradead.org; Mon, 13 May 2019 20:21:01 +0000 Received: by mail-pg1-x544.google.com with SMTP id c13so7352878pgt.1 for ; Mon, 13 May 2019 13:20:54 -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=leVujDMTj0xRtIjTHni2T68vyCo9/+ZtwUA9W0h1xvg=; b=TzBw3rm5Uzlf1eQN4ygDogRI9eCgK0tH/HrGQrbnDeENT/b5X7psVKXbzu/NIJ+8g5 43PEzYY9vLu/EPZL/Z3ZabchH0iW6ta9Tt4KwRgLtphg7iYzuTtKPNIxP2kcE5ct1buU BL9zOBIYSrYI6/b1IdlQWPKdroztStJquwXjY= 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=leVujDMTj0xRtIjTHni2T68vyCo9/+ZtwUA9W0h1xvg=; b=PG51MpPGeBjoNAt44FuHr4zSwucakHtx5NY7NnV4/nT6GmELoAsamIh4wCOlt82Ui3 VaZMlMCLWOiivgOpr3hNP2JwdoEGsZLjV+nIdc8Z29N8L65rxHS2izeUNHhW/4C8DLXS ay+RLHdItPNtiMwibeVQrmNuDiIzInVMxZeY+b+9m3/Ei2Tv02XqU52YGEIGRoeiW1MF dIPFzUuijxWOZTD95xHD9Q5AaEx5rGK7QZbSO0z9pQQaW2/l8hJySSqE68RsLmMq5WTP p2TNUsao6K3+OA2obFJ61JuGBCCRThjYtBwwj5WM1R0tOStFZmPaoiTUe8RZcSG5fnvf pOJA== X-Gm-Message-State: APjAAAWOCxiagDHtD8ELf58bkMkve3KHh38em5cx9cJ8ck6YeBMN8qcg 4vqIikJ0oDFeDJSct3OcvKOrMQ== X-Google-Smtp-Source: APXvYqypJfXRNBxFLFxlzzTNfhkd2BXv4vnyAkeLtglsBBqPuWU48fMWCiBiLWtiHvH8KpQxfCUl3w== X-Received: by 2002:a62:38cc:: with SMTP id f195mr36507159pfa.15.1557778853924; Mon, 13 May 2019 13:20:53 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:24fa:e766:52c9:e3b2]) by smtp.gmail.com with ESMTPSA id s198sm26356597pfs.34.2019.05.13.13.20.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 May 2019 13:20:53 -0700 (PDT) From: Douglas Anderson To: Mark Brown , Benson Leung , Enric Balletbo i Serra Subject: [PATCH v2 1/3] spi: Allow SPI devices to force transfers on a realtime thread Date: Mon, 13 May 2019 13:18:23 -0700 Message-Id: <20190513201825.166969-2-dianders@chromium.org> X-Mailer: git-send-email 2.21.0.1020.gf2820cf01a-goog In-Reply-To: <20190513201825.166969-1-dianders@chromium.org> References: <20190513201825.166969-1-dianders@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190513_132058_639032_E3AAF41B X-CRM114-Status: GOOD ( 27.41 ) 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 For communication with some SPI devices it may be necessary (for correctness) not to get interrupted during a transfer. One example is the EC (Embedded Controller) on Chromebooks. The Chrome OS EC will drop a transfer if more than ~8ms passes between the chip select being asserted and the transfer finishing. The best way to make transfers to devices like this succeed is to run the transfers at realtime priority. ...but, since there is no easy way in the kernel to just temporarily bump the priority of the current thread the current best way to do this is to schedule work on another thread and give that thread a boosted priority. The SPI framework already has another thread and, in fact, that other thread is already made realtime priority in some cases. Let's add an ability for a SPI device driver to request that this thread always be used and that it's realtime priority. NOTE: Forcing all transfers to the message pumping thread will add extra overhead to each transfer. On some systems this may lower your overall bus throughput and may increase CPU utilization. You only want to use this feature when it's important that a transfer not get interrupt once started. Signed-off-by: Douglas Anderson --- Another option is to change this patch to allow a SPI device driver to request that the pumping thread be realtime but not to _force_ all messages onto that thread. In the case of cros_ec this means a bunch of code duplication (we need to create a thread to do basically the same thing as the SPI core) but that would make sense if the SPI framework doesn't expect other use cases like this and doesn't want to carry the baggage in the SPI core. 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 | 49 +++++++++++++++++++++++++++++++++-------- include/linux/spi/spi.h | 5 +++++ 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 8eb7460dd744..911961bb230d 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1217,6 +1217,7 @@ EXPORT_SYMBOL_GPL(spi_finalize_current_transfer); */ static void __spi_pump_messages(struct spi_controller *ctlr, bool in_kthread) { + struct spi_message *msg; unsigned long flags; bool was_busy = false; int ret; @@ -1276,10 +1277,16 @@ static void __spi_pump_messages(struct spi_controller *ctlr, bool in_kthread) return; } - /* Extract head of queue */ - ctlr->cur_msg = - list_first_entry(&ctlr->queue, struct spi_message, queue); + /* If device for this message needs a realtime thread; queue it */ + msg = list_first_entry(&ctlr->queue, struct spi_message, queue); + if (msg->spi->force_rt_transfers & !in_kthread) { + kthread_queue_work(&ctlr->kworker, &ctlr->pump_messages); + spin_unlock_irqrestore(&ctlr->queue_lock, flags); + return; + } + /* Extract head of queue */ + ctlr->cur_msg = msg; list_del_init(&ctlr->cur_msg->queue); if (ctlr->busy) was_busy = true; @@ -1364,10 +1371,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 +1416,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 +3008,11 @@ int spi_setup(struct spi_device *spi) spi_set_cs(spi, false); + if (spi->force_rt_transfers && !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..4d6ea3366480 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -109,6 +109,10 @@ 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. + * @force_rt_transfers: Transfers for this device should always be done + * at realtime priority. NOTE that this might add some latency in + * starting the transfer (since we may need to context switch) but + * once the transfer starts it will be done at high priority. * @irq: Negative, or the number passed to request_irq() to receive * interrupts from this device. * @controller_state: Controller's runtime state @@ -143,6 +147,7 @@ struct spi_device { u32 max_speed_hz; u8 chip_select; u8 bits_per_word; + bool force_rt_transfers; u32 mode; #define SPI_CPHA 0x01 /* clock phase */ #define SPI_CPOL 0x02 /* clock polarity */ From patchwork Mon May 13 20:18:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 10941743 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 6B728933 for ; Mon, 13 May 2019 20:21:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C5CC283A2 for ; Mon, 13 May 2019 20:21:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 50BC8284E4; Mon, 13 May 2019 20:21:06 +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.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 E0820284CE for ; Mon, 13 May 2019 20:21:05 +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=NB3rgs358Gmodz1Zp+zfzeCLn/cTSsQ9xLWutYE6D9s=; b=B3jlVaPByb36hv pGnBiDBu1MbrKzZ9R1c6VoJT7AP0ZSbeG1YW3ISnsR57AZyz3G/8/EMxoKIMXHrTmsmQXDDIvYBaz Zjem605Lg8/blB2xo4SOT9sbPNCYo2RiY6jhec5AnQ2gJVhI9ZygKVn5SgJhv4M3bw9YHfaVLbzhM J/55+Vm78VXTr4mHc97yVroG7+2ZG8oe8UUzN8ajHJDTjh+Q4LsXAz/dPfDZLp3olHBmqY7zKakXu gtYDbkgMTLZu/jESLIMJ49n63a6RNkZinxDFgl5xxYxTD2mu4kzKTPGzjh3BQrt8jlLIn1OmzslIq 3EPoXhKg2v1tkzkFZQ7Q==; 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 1hQHRV-00082T-Nq; Mon, 13 May 2019 20:21:01 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hQHRQ-00080d-3L for linux-rockchip@lists.infradead.org; Mon, 13 May 2019 20:20:59 +0000 Received: by mail-pl1-x644.google.com with SMTP id f12so5010002plt.8 for ; Mon, 13 May 2019 13:20:55 -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=A0hIvZUUUL3EyRykGBdB7l1SOet5HjIbFD3tZy1lwZw=; b=lP34r2NWD/uZoRd0AmHrnPVr3Iay5m0VNeOUlwc4hniFrGufSZMjFpfwGXk+W85GBs NfDq9Njm4nXNu8kRznt9FC3BI+msSj8YszwBXIYYOhHJZFeJJqMuE8f0NIPFLskYUPGo xPrwdOGYOlGlnFbS4SFxOBOcejh3pG8VoKSnw= 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=A0hIvZUUUL3EyRykGBdB7l1SOet5HjIbFD3tZy1lwZw=; b=sDyGuEkzA00MeUl6v0HamJcjmwOofVySG+kU5gzGRF2hYXXzU/dy92cHUzVUuP8xuu 2FSuZkWlFUz6z3TUdPzR/h1+nsvk4/l+2nqg7yY5TVKF7dyHu43V1KyejH3nLf7ICN26 38FlJvHygjDCgUFmDgSmXI/J+kvVZ5H+mjATOoXTjT2L3MXsz/W8YljPf5rE5uGRpRLR hBDo7RiDcIq2qeUq8MVfmrhzGtoQ3b+ampu0cbN/Qxjz0yso2Jd2Wec7k80i8Y4FL9XF iRJLmX5amiex3temZJcgDEG3kJTAzBIbyFTMo13YV+rQfEpR7j2I2YfULzrV+XVhWKVR XYbw== X-Gm-Message-State: APjAAAW53dz3JfTEWlwUeGkN0W53x42eCVqxhVCGr6Ij/hk7y1TK6znh vH27HiIWPyqCPoN0O4Pih3ofiw== X-Google-Smtp-Source: APXvYqycX98I9RrS0+2PLISochd9e1uNzSdWwjsBuwDbWsmLVvAd8DTtC/KuAkigAeIT07A+gaSOGA== X-Received: by 2002:a17:902:7b8f:: with SMTP id w15mr33608247pll.314.1557778854816; Mon, 13 May 2019 13:20:54 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:24fa:e766:52c9:e3b2]) by smtp.gmail.com with ESMTPSA id s198sm26356597pfs.34.2019.05.13.13.20.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 May 2019 13:20:54 -0700 (PDT) From: Douglas Anderson To: Mark Brown , Benson Leung , Enric Balletbo i Serra Subject: [PATCH v2 2/3] platform/chrome: cros_ec_spi: Force transfers to realtime priority Date: Mon, 13 May 2019 13:18:24 -0700 Message-Id: <20190513201825.166969-3-dianders@chromium.org> X-Mailer: git-send-email 2.21.0.1020.gf2820cf01a-goog In-Reply-To: <20190513201825.166969-1-dianders@chromium.org> References: <20190513201825.166969-1-dianders@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190513_132058_635464_B51B8995 X-CRM114-Status: GOOD ( 10.90 ) 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 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP All currently known ECs in the wild are very sensitive to timing. Specifically the ECs are known to drop a transfer if more than 8 ms passes from the assertion of the chip select until the transfer finishes. Let's use the new feature introduced in the patch ("spi: Allow SPI devices to force transfers on a realtime thread") to specify this and increase the success rate of our transfers. NOTE: if future Chrome OS ECs ever fix themselves to be less sensitive then we could consider adding a property (or compatible string) to not set this property. For now we need it across the board. With this change we can revert the commit 37a186225a0c ("platform/chrome: cros_ec_spi: Transfer messages at high priority"). ...and, in fact, transfers are _even more_ reliable than they were with that commit since the SPI framework will use a higher priority (realtime) and we no longer lose our priority when we get shunted over to the message pumping thread (because we now always get shunted and the thread is high priority). Signed-off-by: Douglas Anderson Reviewed-by: Guenter Roeck --- Changes in v2: - Renamed variable to "force_rt_transfers". drivers/platform/chrome/cros_ec_spi.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/platform/chrome/cros_ec_spi.c b/drivers/platform/chrome/cros_ec_spi.c index 8e9451720e73..a2959365a870 100644 --- a/drivers/platform/chrome/cros_ec_spi.c +++ b/drivers/platform/chrome/cros_ec_spi.c @@ -703,6 +703,7 @@ static int cros_ec_spi_probe(struct spi_device *spi) spi->bits_per_word = 8; spi->mode = SPI_MODE_0; + spi->force_rt_transfers = true; err = spi_setup(spi); if (err < 0) return err; From patchwork Mon May 13 20:18:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 10941747 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 9B4F0912 for ; Mon, 13 May 2019 20:21:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8AA0D284C9 for ; Mon, 13 May 2019 20:21:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7EDCE284B9; Mon, 13 May 2019 20:21:08 +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 0F4A2284C9 for ; Mon, 13 May 2019 20:21:08 +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=UsFNjw7usSOMVTpVOTT4vW/B6ST3/QxogJKKVxf2fzk=; b=amk7asocRqE0ZU 8b3jWvAI3A1/wsv1Zy/wBMzfFwxQkRwEKfgaG5DD3BACzQIEAFz1l9Tf5+PKXr1vwJzoO+vNVbzCZ lSHVu8LphdINvYR2KJr6YdnKTtBsOBfjAhhy1UORzNg+tAIVGjlASaaweyFpP0AVk4y3SCr1QiIqU u8F3bRnf2bCOl19GmNKIT4EWHbmok8pOTaHwIcorMf2WC3gWOrAiOj86eL6b6Lker2Xbm0FLlZapD PU+a7ca+xU04FV+2CNuQWQ2TtPU5lji58zo8iQw5in+oj4AXf1LLXujcu1Vu9nDlP6MxxGSDYjmBy iCZYdS4aTIeTBqAekc6A==; 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 1hQHRY-00083q-RE; Mon, 13 May 2019 20:21:04 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hQHRR-00080h-CY for linux-rockchip@lists.infradead.org; Mon, 13 May 2019 20:21:01 +0000 Received: by mail-pl1-x643.google.com with SMTP id p15so7028666pll.4 for ; Mon, 13 May 2019 13:20:57 -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=lnf9X1JzNr0p/o4q+Qg8KxiBFNUwbq0BM3Xh4UH0r7k=; b=bCGz4J8ppGdokDgODI+0By4RzdTs4uc+h8HuDat4mmDuu17yR0T+GnYtO3lDNPy82H wEif10+dwhAiTiS7e82OhpE1ddg4BGq+ixxRvPKhAClYImqsqNDhtVsrN1xXa2wUKad+ osLIDfAY+jE4KhX0I++jdUsrXi50hLxQ1ZsAg= 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=lnf9X1JzNr0p/o4q+Qg8KxiBFNUwbq0BM3Xh4UH0r7k=; b=TAOs8m/rnr6xislO+2AG0BnhWGwFRNP9+wVUwUgu9FkKST4sT8eLAJPLH5KuVGpVgZ K8lvAUGnD2YcGZeBsSU/0M7boqQVT03ds3HDRsleqggOWYzFjiVHdVWPH+r59GwpngdW e3MZPx9nNQIE6Mt3PJ0yDEca0aRt+uzBBrx1uOpfgIOZ5RvZr+C1bci934CVM5JP6Yt/ 0uY+EDj2RKuX7Hw2+n2jV+/6hp145DV4sr1zwc+2U6lVb8XBNMxon8i/GDTh0CQVBVu1 8KLcmz3RmJ56z68IV3mRrL9UGHNg4eUkoBnbL1m3CqYOUKtVB0gKQNg2paFaKrwOwPdb W+gw== X-Gm-Message-State: APjAAAUlr44HmbfG1Qc02yAF8dKq8bXn/UtIUfDyAkQo29+wG6KBd2A3 L19+G/jTquMvC5Is2SjfrTrLYA== X-Google-Smtp-Source: APXvYqy5wGuT5CZ/TaXPeEZeoV8ZznOBT7/f/8i18U3AePnUU+33PWms/FxG3zRylr0ySkmVt8Ra/Q== X-Received: by 2002:a17:902:6948:: with SMTP id k8mr33923439plt.81.1557778856650; Mon, 13 May 2019 13:20:56 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:24fa:e766:52c9:e3b2]) by smtp.gmail.com with ESMTPSA id s198sm26356597pfs.34.2019.05.13.13.20.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 May 2019 13:20:55 -0700 (PDT) From: Douglas Anderson To: Mark Brown , Benson Leung , Enric Balletbo i Serra Subject: [PATCH v2 3/3] Revert "platform/chrome: cros_ec_spi: Transfer messages at high priority" Date: Mon, 13 May 2019 13:18:25 -0700 Message-Id: <20190513201825.166969-4-dianders@chromium.org> X-Mailer: git-send-email 2.21.0.1020.gf2820cf01a-goog In-Reply-To: <20190513201825.166969-1-dianders@chromium.org> References: <20190513201825.166969-1-dianders@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190513_132058_637675_D3D8F07B X-CRM114-Status: GOOD ( 14.31 ) 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 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This reverts commit 37a186225a0c020516bafad2727fdcdfc039a1e4. We have a better solution in the patch ("platform/chrome: cros_ec_spi: Force transfers to realtime priority"). Let's revert the uglier and less reliable solution. Signed-off-by: Douglas Anderson Reviewed-by: Guenter Roeck --- Changes in v2: None drivers/platform/chrome/cros_ec_spi.c | 80 ++------------------------- 1 file changed, 6 insertions(+), 74 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_spi.c b/drivers/platform/chrome/cros_ec_spi.c index a2959365a870..7adaf534eb8b 100644 --- a/drivers/platform/chrome/cros_ec_spi.c +++ b/drivers/platform/chrome/cros_ec_spi.c @@ -75,27 +75,6 @@ struct cros_ec_spi { unsigned int end_of_msg_delay; }; -typedef int (*cros_ec_xfer_fn_t) (struct cros_ec_device *ec_dev, - struct cros_ec_command *ec_msg); - -/** - * struct cros_ec_xfer_work_params - params for our high priority workers - * - * @work: The work_struct needed to queue work - * @fn: The function to use to transfer - * @ec_dev: ChromeOS EC device - * @ec_msg: Message to transfer - * @ret: The return value of the function - */ - -struct cros_ec_xfer_work_params { - struct work_struct work; - cros_ec_xfer_fn_t fn; - struct cros_ec_device *ec_dev; - struct cros_ec_command *ec_msg; - int ret; -}; - static void debug_packet(struct device *dev, const char *name, u8 *ptr, int len) { @@ -371,13 +350,13 @@ static int cros_ec_spi_receive_response(struct cros_ec_device *ec_dev, } /** - * do_cros_ec_pkt_xfer_spi - Transfer a packet over SPI and receive the reply + * cros_ec_pkt_xfer_spi - Transfer a packet over SPI and receive the reply * * @ec_dev: ChromeOS EC device * @ec_msg: Message to transfer */ -static int do_cros_ec_pkt_xfer_spi(struct cros_ec_device *ec_dev, - struct cros_ec_command *ec_msg) +static int cros_ec_pkt_xfer_spi(struct cros_ec_device *ec_dev, + struct cros_ec_command *ec_msg) { struct ec_host_response *response; struct cros_ec_spi *ec_spi = ec_dev->priv; @@ -514,13 +493,13 @@ static int do_cros_ec_pkt_xfer_spi(struct cros_ec_device *ec_dev, } /** - * do_cros_ec_cmd_xfer_spi - Transfer a message over SPI and receive the reply + * cros_ec_cmd_xfer_spi - Transfer a message over SPI and receive the reply * * @ec_dev: ChromeOS EC device * @ec_msg: Message to transfer */ -static int do_cros_ec_cmd_xfer_spi(struct cros_ec_device *ec_dev, - struct cros_ec_command *ec_msg) +static int cros_ec_cmd_xfer_spi(struct cros_ec_device *ec_dev, + struct cros_ec_command *ec_msg) { struct cros_ec_spi *ec_spi = ec_dev->priv; struct spi_transfer trans; @@ -632,53 +611,6 @@ static int do_cros_ec_cmd_xfer_spi(struct cros_ec_device *ec_dev, return ret; } -static void cros_ec_xfer_high_pri_work(struct work_struct *work) -{ - struct cros_ec_xfer_work_params *params; - - params = container_of(work, struct cros_ec_xfer_work_params, work); - params->ret = params->fn(params->ec_dev, params->ec_msg); -} - -static int cros_ec_xfer_high_pri(struct cros_ec_device *ec_dev, - struct cros_ec_command *ec_msg, - cros_ec_xfer_fn_t fn) -{ - struct cros_ec_xfer_work_params params; - - INIT_WORK_ONSTACK(¶ms.work, cros_ec_xfer_high_pri_work); - params.ec_dev = ec_dev; - params.ec_msg = ec_msg; - params.fn = fn; - - /* - * This looks a bit ridiculous. Why do the work on a - * different thread if we're just going to block waiting for - * the thread to finish? The key here is that the thread is - * running at high priority but the calling context might not - * be. We need to be at high priority to avoid getting - * context switched out for too long and the EC giving up on - * the transfer. - */ - queue_work(system_highpri_wq, ¶ms.work); - flush_work(¶ms.work); - destroy_work_on_stack(¶ms.work); - - return params.ret; -} - -static int cros_ec_pkt_xfer_spi(struct cros_ec_device *ec_dev, - struct cros_ec_command *ec_msg) -{ - return cros_ec_xfer_high_pri(ec_dev, ec_msg, do_cros_ec_pkt_xfer_spi); -} - -static int cros_ec_cmd_xfer_spi(struct cros_ec_device *ec_dev, - struct cros_ec_command *ec_msg) -{ - return cros_ec_xfer_high_pri(ec_dev, ec_msg, do_cros_ec_cmd_xfer_spi); -} - static void cros_ec_spi_dt_probe(struct cros_ec_spi *ec_spi, struct device *dev) { struct device_node *np = dev->of_node;