Received: by 10.223.185.116 with SMTP id b49csp4009073wrg; Tue, 13 Feb 2018 11:11:42 -0800 (PST) X-Google-Smtp-Source: AH8x224A/bCKRszCU8tXu0NMYZFz2uAcouZLNAidjzWkf1JC1TALpLlxrk05k2hd6NfD1c/Hsa8+ X-Received: by 10.98.181.14 with SMTP id y14mr2231855pfe.220.1518549102717; Tue, 13 Feb 2018 11:11:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518549102; cv=none; d=google.com; s=arc-20160816; b=F8rFWMzU4c6YyZO4drOBdWCHgUN1M33x3DwdpvzmMw4IEjhtwrYxA6g3gYtSKTqQ9e g5Xwb6aKrikb3VHZNN21CKDKDc/T0N9462wQnY1bZd8DzlOLITCVFwaTW4ghwl6aPKpq tD/w52LuxkwNSgesM1rFRFtLs7lSMogJgqD4pt7Vj2E0dnwyRmraKAkgnGeIMCbnFyNu +FsR/o22sL9T6bqATm8v1FrpULKD8e6pH2BqrmWc+KTEELEw/mUJVd68R6fookw3Evsc yVwHtHy7V9CCQ5Fx5+9rmHcYmw8A1uEkp/tzVQRG9GqzUCkFP8LUPXyseKREJi0VWtct VcMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=O8xXWGRRalWR9ldNKooYC7fkxNzO24HiEhMCBis1piA=; b=TGbO7cWppOab8Vb6uChxBKPV9ZgAR+ckLXhEi7YBC3h/0hcmedl7Y3PLni63JRTKb9 OVkfJApIqIAkUcu+4JV9hLbQgEqKJ6LExmk+S+mmSykGRTodKKkjO+9ePIxgG5gGk6kW LnM6aOZJMu5uxymK/jZgkG05fL3jsaoebA2H2IcMZE5eb9AisIZPyJzGyL4qaBeElXMD TkiEQUz0+hVYaJYtzQFaBSV66t8v/0bPloxKzKoS1jhLFVJcX7MXbnparE7oLQVFG01t g64GDb3vBBa+vFBfoNhVO9NrsBxnQ8d2z+jtz2a1V8IBcak6wBfYzd2qASCztaNJoTXM 7eUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hUcgmbzA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k33-v6si60483pld.303.2018.02.13.11.11.23; Tue, 13 Feb 2018 11:11:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hUcgmbzA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754208AbeBMTKN (ORCPT + 99 others); Tue, 13 Feb 2018 14:10:13 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:37006 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753260AbeBMTKK (ORCPT ); Tue, 13 Feb 2018 14:10:10 -0500 Received: by mail-pg0-f68.google.com with SMTP id o1so519603pgn.4 for ; Tue, 13 Feb 2018 11:10:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=O8xXWGRRalWR9ldNKooYC7fkxNzO24HiEhMCBis1piA=; b=hUcgmbzAoZ5iozzHdkLdzRyvk378Evlu2k8WUjcXI1CcqwFK7XsuzpxND+zxXxMsqU d2G2AYAssFVhmK8zRSQ7iIoQs5KY1MfsQeiukFYWO3NhTEosLyPhY6ulvK4Idyoq39Qw BiBtqnZrLuRohfzGB5Ad4MzrdIi21hegJoVgU= 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; bh=O8xXWGRRalWR9ldNKooYC7fkxNzO24HiEhMCBis1piA=; b=aePd+uMJ5kzplwJst98Mn8IajmP/dpw1Qb9F3XqHSgMVzl6LwnZypjD8M+8HD3j1/p OQJTqN6toid25uqrpLyJbrhXmgrBSYWSG69lOxYi3gr5K+ih7BSmNbxhJsIMzbIYJ67J 5Us3J4/EpJnvrcYVT5KwRFbekYkS0FCsNc89YeYO42Q0WEAWqnAIBM4PkyLc7zgVRrGt PHDpx13HTwbro06Qtd4Zsn4s6qIPjHZCulDOiMMP20EbVSWjheqPcfxdGLHJbGzuuwWF bh1X+Hdw2GLVUuc9C4+SjeHBKMHa6Km0cKIiQfv1y0ldIJK2rBiXfnGxaQj77Ye5WTBE fddw== X-Gm-Message-State: APf1xPDK+UvWmwcs6uE4RLR6VX/uW9B01uEqMjzBcDlRhQCRKOCves8F 6ZRAQY28JCurWp0/AIr3euIeAA== X-Received: by 10.167.129.195 with SMTP id c3mr2020270pfn.14.1518548647712; Tue, 13 Feb 2018 11:04:07 -0800 (PST) Received: from localhost.localdomain (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id y4sm15478765pfm.16.2018.02.13.11.04.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Feb 2018 11:04:06 -0800 (PST) From: Bjorn Andersson To: Ohad Ben-Cohen , Bjorn Andersson , Chris Lew , Arun Kumar Neelakantam , Srini Kandagatla Cc: linux-remoteproc@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] rpmsg: glink: Use spinlock in tx path Date: Tue, 13 Feb 2018 11:04:04 -0800 Message-Id: <20180213190404.25026-1-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.15.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Switch the tx_lock to a spinlock we allow clients to use rpmsg_trysend() from atomic context. In order to allow clients to sleep while waiting for space in the FIFO we release the lock temporarily around the delay; which should be replaced by sending a READ_NOTIF and waiting for the remote to signal us that space has been made available. Signed-off-by: Bjorn Andersson --- drivers/rpmsg/qcom_glink_native.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/rpmsg/qcom_glink_native.c b/drivers/rpmsg/qcom_glink_native.c index e0f31ed096a5..6e950e9afa82 100644 --- a/drivers/rpmsg/qcom_glink_native.c +++ b/drivers/rpmsg/qcom_glink_native.c @@ -113,7 +113,7 @@ struct qcom_glink { spinlock_t rx_lock; struct list_head rx_queue; - struct mutex tx_lock; + spinlock_t tx_lock; spinlock_t idr_lock; struct idr lcids; @@ -288,15 +288,14 @@ static int qcom_glink_tx(struct qcom_glink *glink, const void *data, size_t dlen, bool wait) { unsigned int tlen = hlen + dlen; + unsigned long flags; int ret; /* Reject packets that are too big */ if (tlen >= glink->tx_pipe->length) return -EINVAL; - ret = mutex_lock_interruptible(&glink->tx_lock); - if (ret) - return ret; + spin_lock_irqsave(&glink->tx_lock, flags); while (qcom_glink_tx_avail(glink) < tlen) { if (!wait) { @@ -304,7 +303,12 @@ static int qcom_glink_tx(struct qcom_glink *glink, goto out; } + /* Wait without holding the tx_lock */ + spin_unlock_irqrestore(&glink->tx_lock, flags); + usleep_range(10000, 15000); + + spin_lock_irqsave(&glink->tx_lock, flags); } qcom_glink_tx_write(glink, hdr, hlen, data, dlen); @@ -313,7 +317,7 @@ static int qcom_glink_tx(struct qcom_glink *glink, mbox_client_txdone(glink->mbox_chan, 0); out: - mutex_unlock(&glink->tx_lock); + spin_unlock_irqrestore(&glink->tx_lock, flags); return ret; } @@ -1567,7 +1571,7 @@ struct qcom_glink *qcom_glink_native_probe(struct device *dev, glink->features = features; glink->intentless = intentless; - mutex_init(&glink->tx_lock); + spin_lock_init(&glink->tx_lock); spin_lock_init(&glink->rx_lock); INIT_LIST_HEAD(&glink->rx_queue); INIT_WORK(&glink->rx_work, qcom_glink_work); -- 2.15.0