Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp885810imc; Mon, 11 Mar 2019 01:24:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqzE4RaOk9LFj7hU1vrvkfVjM+S9zS9SGHR5Yl1M21tOcKtzneCpO84ycKS1sVMVMpkfYGD5 X-Received: by 2002:a63:2b82:: with SMTP id r124mr28818386pgr.214.1552292652481; Mon, 11 Mar 2019 01:24:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552292652; cv=none; d=google.com; s=arc-20160816; b=0f98Mk6JdNj4303hnaefz5NN/ggS0sEsm8AQ6RLQnAkKZIgqWZk9Nl5lO8Zqth8dbF YUFjvMU/EHIicEI9K7d/TBVaP0pZgOKltWAaMGX4nmzTGwuVq9c7+ERw70NJv308ReGQ gDz8Oe3nzHDJEx+EF2bVcdaydhm6HORmz+sUnKdbA2A1N4euoUJkidMWvV8VCBBzYQmP /AbG/r4uNzcKXFahvBOIEMFG9HWAIm3kRP4BbhCtebXLBfR/LQrJu5fi8uNSJE3bMd53 zJPBX7y7DQSenr7DZWf7qqvp0urSCqf9whrtQIUfV40a5MB9VRz5S+1nhdRCWeymCnVw ltrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=Pc1heY3mOjPU3BPmKt4DA0+vAstFl0OjDWuaP+LoJzA=; b=ZLaGviK7QIuNltANtrqXF8GOBE75stmYkIfphY2dmoQDC6dmEY6FGCrPxNRsCxg6ym omePuF8dhkgHn6sZKUG24eKsq98sgNui28dAD9HyQIWs/aV9tdQqZBW71BymzSGQQg45 dJm/o2Ep9ddWskcbzrSc+SG/JliZuC+oRKIOrVMD9gPYRxYfPGqnmh6H+9blPgLjQ+Bk iNZ3HAguy+eVZQ+wsDSLdvSfmTUGAClh9ks49KNFY/O0LTHeRyrFz9uWwfxDmQ4PbjBZ Om1K3p2o7VHznLp4cnOh5mRdD/ZPANRWuwPHOrIMBkJZdY2RcutEGhtocJIgqEg6ikLe Ci5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qAas790h; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q81si4805530pfc.42.2019.03.11.01.23.56; Mon, 11 Mar 2019 01:24:12 -0700 (PDT) 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=@gmail.com header.s=20161025 header.b=qAas790h; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726939AbfCKIXR (ORCPT + 99 others); Mon, 11 Mar 2019 04:23:17 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:41556 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726590AbfCKIXQ (ORCPT ); Mon, 11 Mar 2019 04:23:16 -0400 Received: by mail-wr1-f65.google.com with SMTP id n2so3975211wrw.8 for ; Mon, 11 Mar 2019 01:23:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Pc1heY3mOjPU3BPmKt4DA0+vAstFl0OjDWuaP+LoJzA=; b=qAas790hOFrPmLhtq74TL5kD0HbOST6wxWwvh8Z/PfJTqC7uCt5p9MF7zyt7A8qiL+ Ra2F5NdzEAgsgUJ32+y/r7d8oEx6aMpVH1DNLApRpbR8W3cQbp4BAxfuiW6eWggKr0HZ e92eK1V/ZsPO+kRIikDIcWB36YmFdEKdAxnS3x0vnu3VOpwK1dlyEf1rbQ7/LYy9tRQ1 ve0uu4iPIMYl/CHroNdv1RhzRZ5o/JRANwwitLTtfUzIPEkTuECRGTKUrskBvpGT2Vxv z4I83I5QgMACnBg3+GrhxTF7py/oPGnqa4I4yPzeuaMdJDhLGwIVV1DhT4TdQxev5tnF gjIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Pc1heY3mOjPU3BPmKt4DA0+vAstFl0OjDWuaP+LoJzA=; b=Cc+JQs6XECIxo4NGiauuY8uLI0LeMr7Bfy/F2IVy+Zg3/8XvgCVeM/PJU7H88REqCW 1ilbMr0KjwxQh7OKryu4yDeoJZ955WbYDU8TMg75Mp5HsqEuJji8vfW8yzAw+T4xspav /weF57x5IJJLlaqaJMBOaKRFPctBhP4BQDWp9Abk1zcaIWwlQRAChzHR2lchFS/jA/7+ ehnTrpp/F2plFZ0MU76DrBpMhKgAKg+ilqb7N7DZtIGRD42KEIEWmY5CMF0yBJTmK15A 9/31Ymk/mp1/TOrdhJfKRy2gn7GDnEkjy14XGbEbrCathucoxtjondfWNAmL1v/GF7fr NNWg== X-Gm-Message-State: APjAAAUzovakmvh3YT0iALU2IiOZq86jxkMy5GmoWiEkAWSsytDKLs16 sQ5Yb2Ftv2xa9Ux2jP8ZRF8= X-Received: by 2002:a5d:44c3:: with SMTP id z3mr18572931wrr.329.1552292594960; Mon, 11 Mar 2019 01:23:14 -0700 (PDT) Received: from giga-mm ([62.68.22.49]) by smtp.gmail.com with ESMTPSA id c15sm5370986wrv.69.2019.03.11.01.23.13 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 11 Mar 2019 01:23:14 -0700 (PDT) Date: Mon, 11 Mar 2019 09:23:13 +0100 From: Alexander Sverdlin To: Oleksij Rempel Cc: Greg Kroah-Hartman , Jiri Slaby , Steven Walter , Pengutronix Kernel Team , linux-kernel@vger.kernel.org Subject: Re: [PATCH v1 2/3] drivers/tty: convert tty_port to use kthread_worker Message-Id: <20190311092313.ebf38daafe4e5b0a6fcb838f@gmail.com> In-Reply-To: <20190110101232.9398-3-o.rempel@pengutronix.de> References: <20190110101232.9398-1-o.rempel@pengutronix.de> <20190110101232.9398-3-o.rempel@pengutronix.de> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-unknown-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Oleksij, On Thu, 10 Jan 2019 11:12:31 +0100 Oleksij Rempel wrote: > From: Steven Walter > > Use kthread_worker instead of workqueues. For now there is only a > single workqueue, but the intention is to bring back the "low_latency" > tty option, along with a second high-priority kthread worker. > > Even without a second worker this patch allows to give a higher priority > to tty processing by modifying the priority of the corresponding > kthread. > > Signed-off-by: Steven Walter > Tested-by: Oleksij Rempel Tested-by: Alexander Sverdlin In general I agree with Linus, that a thread with some random priority is suboptimal, and we actually should move this work into the context of the receiving thread, to properly inherit its priority. But this would be quite amount of rework. In the meanwhile this patch series restores the "low_latency" tty option. Thanks for your efforts! > --- > drivers/tty/tty_buffer.c | 21 ++++++++++++++------- > drivers/tty/tty_io.c | 1 + > include/linux/tty.h | 7 ++++--- > 3 files changed, 19 insertions(+), 10 deletions(-) > > diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c > index e0090e65d83a..18bd7f48a319 100644 > --- a/drivers/tty/tty_buffer.c > +++ b/drivers/tty/tty_buffer.c > @@ -4,6 +4,7 @@ > */ > > #include > +#include > #include > #include > #include > @@ -497,7 +498,7 @@ receive_buf(struct tty_port *port, struct tty_buffer *head, int count) > * 'consumer' > */ > > -static void flush_to_ldisc(struct work_struct *work) > +static void flush_to_ldisc(struct kthread_work *work) > { > struct tty_port *port = container_of(work, struct tty_port, buf.work); > struct tty_bufhead *buf = &port->buf; > @@ -557,10 +558,16 @@ void tty_flip_buffer_push(struct tty_port *port) > } > EXPORT_SYMBOL(tty_flip_buffer_push); > > +static DEFINE_KTHREAD_WORKER(tty_buffer_worker); > + > bool tty_buffer_queue_work(struct tty_port *port) > { > - struct tty_bufhead *buf = &port->buf; > - return schedule_work(&buf->work); > + return kthread_queue_work(&tty_buffer_worker, &port->buf.work); > +} > + > +void tty_buffer_init_kthread(void) > +{ > + kthread_run(kthread_worker_fn, &tty_buffer_worker, "tty"); > } > > /** > @@ -582,7 +589,7 @@ void tty_buffer_init(struct tty_port *port) > init_llist_head(&buf->free); > atomic_set(&buf->mem_used, 0); > atomic_set(&buf->priority, 0); > - INIT_WORK(&buf->work, flush_to_ldisc); > + kthread_init_work(&buf->work, flush_to_ldisc); > buf->mem_limit = TTYB_DEFAULT_MEM_LIMIT; > } > > @@ -614,12 +621,12 @@ bool tty_buffer_restart_work(struct tty_port *port) > return tty_buffer_queue_work(port); > } > > -bool tty_buffer_cancel_work(struct tty_port *port) > +void tty_buffer_cancel_work(struct tty_port *port) > { > - return cancel_work_sync(&port->buf.work); > + tty_buffer_flush_work(port); > } > > void tty_buffer_flush_work(struct tty_port *port) > { > - flush_work(&port->buf.work); > + kthread_flush_work(&port->buf.work); > } > diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c > index bfe9ad85b362..5fd7cecbe4e7 100644 > --- a/drivers/tty/tty_io.c > +++ b/drivers/tty/tty_io.c > @@ -3476,6 +3476,7 @@ void console_sysfs_notify(void) > */ > int __init tty_init(void) > { > + tty_buffer_init_kthread(); > cdev_init(&tty_cdev, &tty_fops); > if (cdev_add(&tty_cdev, MKDEV(TTYAUX_MAJOR, 0), 1) || > register_chrdev_region(MKDEV(TTYAUX_MAJOR, 0), 1, "/dev/tty") < 0) > diff --git a/include/linux/tty.h b/include/linux/tty.h > index 226a9eff0766..924c1093967e 100644 > --- a/include/linux/tty.h > +++ b/include/linux/tty.h > @@ -3,9 +3,9 @@ > #define _LINUX_TTY_H > > #include > +#include > #include > #include > -#include > #include > #include > #include > @@ -84,7 +84,7 @@ static inline char *flag_buf_ptr(struct tty_buffer *b, int ofs) > > struct tty_bufhead { > struct tty_buffer *head; /* Queue head */ > - struct work_struct work; > + struct kthread_work work; > struct mutex lock; > atomic_t priority; > struct tty_buffer sentinel; > @@ -510,8 +510,9 @@ extern void tty_buffer_flush(struct tty_struct *tty, struct tty_ldisc *ld); > extern bool tty_buffer_queue_work(struct tty_port *port); > extern void tty_buffer_init(struct tty_port *port); > extern void tty_buffer_set_lock_subclass(struct tty_port *port); > +extern void tty_buffer_init_kthread(void); > extern bool tty_buffer_restart_work(struct tty_port *port); > -extern bool tty_buffer_cancel_work(struct tty_port *port); > +extern void tty_buffer_cancel_work(struct tty_port *port); > extern void tty_buffer_flush_work(struct tty_port *port); > extern speed_t tty_termios_baud_rate(struct ktermios *termios); > extern speed_t tty_termios_input_baud_rate(struct ktermios *termios); -- Alexander Sverdlin.