mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v4 1/8] input: virtio: poll from poller, not bthread
Date: Tue, 22 Jun 2021 10:26:10 +0200	[thread overview]
Message-ID: <20210622082617.18011-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20210622082617.18011-1-a.fatoum@pengutronix.de>

With the upcoming move of bthreads to be scheduled only in command
context, long running tasks (i.e. bareDOOM) may no longer process
VirtIO input in a timely manner. Move the input polling into a poller,
so input can once again be processed between frames.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/input/Kconfig        |  3 ++-
 drivers/input/virtio_input.c | 45 ++++++++++++++++--------------------
 2 files changed, 22 insertions(+), 26 deletions(-)

diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig
index ff3e9d33f6d7..ba9fa25a3dec 100644
--- a/drivers/input/Kconfig
+++ b/drivers/input/Kconfig
@@ -73,7 +73,8 @@ config INPUT_SPECIALKEYS
 
 config VIRTIO_INPUT
 	bool "Virtio input driver"
-	depends on VIRTIO && BTHREAD
+	depends on VIRTIO
+	select POLLER
 	select INPUT
 	help
 	 This driver supports virtio keyboard input devices.
diff --git a/drivers/input/virtio_input.c b/drivers/input/virtio_input.c
index 9c2e4d923f8d..b354933209fc 100644
--- a/drivers/input/virtio_input.c
+++ b/drivers/input/virtio_input.c
@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
 
 #include <common.h>
-#include <bthread.h>
+#include <poller.h>
 #include <linux/virtio.h>
 #include <linux/virtio_config.h>
 #include <linux/virtio_ring.h>
@@ -17,7 +17,7 @@ struct virtio_input {
 	struct virtio_device       *vdev;
 	struct virtqueue           *evt, *sts;
 	struct virtio_input_event  evts[64];
-	struct bthread             *bthread;
+	struct poller_struct       poller;
 	struct sound_card          beeper;
 	unsigned long              sndbit[BITS_TO_LONGS(SND_CNT)];
 };
@@ -100,21 +100,17 @@ static int virtinput_recv_status(struct virtio_input *vi)
 	return i;
 }
 
-static int virtinput_poll_vqs(void *_vi)
+static void virtinput_poll_vqs(struct poller_struct *poller)
 {
-	struct virtio_input *vi = _vi;
+	struct virtio_input *vi = container_of(poller, struct virtio_input, poller);
 
-	while (!bthread_should_stop()) {
-		int bufs = 0;
+	int bufs = 0;
 
-		bufs += virtinput_recv_events(vi);
-		bufs += virtinput_recv_status(vi);
+	bufs += virtinput_recv_events(vi);
+	bufs += virtinput_recv_status(vi);
 
-		if (bufs)
-			virtqueue_kick(vi->evt);
-	}
-
-	return 0;
+	if (bufs)
+		virtqueue_kick(vi->evt);
 }
 
 static u8 virtinput_cfg_select(struct virtio_input *vi,
@@ -213,6 +209,8 @@ static int virtinput_probe(struct virtio_device *vdev)
 			   name, min(size, sizeof(name)));
 	name[size] = '\0';
 
+	dev_info(&vdev->dev, "'%s' detected\n", name);
+
 	virtinput_cfg_bits(vi, VIRTIO_INPUT_CFG_EV_BITS, EV_SND,
 			   vi->sndbit, SND_CNT);
 
@@ -224,12 +222,12 @@ static int virtinput_probe(struct virtio_device *vdev)
 
 	virtinput_fill_evt(vi);
 
-	vi->bthread = bthread_run(virtinput_poll_vqs, vi,
-				  "%s/input0", dev_name(&vdev->dev));
-	if (!vi->bthread) {
-		err = -ENOMEM;
-		goto err_bthread_run;
-	}
+	vi->poller.func = virtinput_poll_vqs;
+	snprintf(name, sizeof(name), "%s/input0", dev_name(&vdev->dev));
+
+	err = poller_register(&vi->poller, name);
+	if (err)
+		goto err_poller_register;
 
 	if (IS_ENABLED(CONFIG_SOUND) &&
 	    (vi->sndbit[0] & (BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE)))) {
@@ -246,12 +244,10 @@ static int virtinput_probe(struct virtio_device *vdev)
 			dev_info(&vdev->dev, "bell registered\n");
 	}
 
-	dev_info(&vdev->dev, "'%s' probed\n", name);
-
 	return 0;
 
-err_bthread_run:
-	bthread_free(vi->bthread);
+err_poller_register:
+	input_device_unregister(&vi->idev);
 err_input_register:
 	vdev->config->del_vqs(vdev);
 err_init_vq:
@@ -263,8 +259,7 @@ static void virtinput_remove(struct virtio_device *vdev)
 {
 	struct virtio_input *vi = vdev->priv;
 
-	bthread_stop(vi->bthread);
-	bthread_free(vi->bthread);
+	poller_unregister(&vi->poller);
 
 	vdev->config->reset(vdev);
 	vdev->config->del_vqs(vdev);
-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  reply	other threads:[~2021-06-22  8:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-22  8:26 [PATCH v4 0/8] usbgadget: add support for USB mass storage gadget Ahmad Fatoum
2021-06-22  8:26 ` Ahmad Fatoum [this message]
2021-06-22  8:26 ` [PATCH v4 2/8] bthread: add debug print for scheduler context switches Ahmad Fatoum
2021-06-22  8:26 ` [PATCH v4 3/8] common: move workqueue handling from poller_call() to sched() Ahmad Fatoum
2021-06-22  8:26 ` [PATCH v4 4/8] common: bthread: schedule only in command context Ahmad Fatoum
2021-06-22  9:08   ` Ahmad Fatoum
2021-06-22  8:26 ` [PATCH v4 5/8] bthread: implement basic Linux-like completion API Ahmad Fatoum
2021-06-22  8:26 ` [PATCH v4 6/8] Documentation: devel: background-execution: update bthread docs Ahmad Fatoum
2021-06-22  8:26 ` [PATCH v4 7/8] usbgadget: refactor usbgadget_register to accept array Ahmad Fatoum
2021-06-22  8:26 ` [PATCH v4 8/8] usbgadget: add support for USB mass storage gadget Ahmad Fatoum
2021-06-25  7:34 ` [PATCH v4 0/8] " Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210622082617.18011-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox