From patchwork Thu Mar 23 21:03:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Pitre X-Patchwork-Id: 95917 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp943370qgd; Thu, 23 Mar 2017 14:18:19 -0700 (PDT) X-Received: by 10.98.194.157 with SMTP id w29mr5322997pfk.192.1490303899116; Thu, 23 Mar 2017 14:18:19 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g79si62553pfg.307.2017.03.23.14.18.18; Thu, 23 Mar 2017 14:18:19 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965088AbdCWVSS (ORCPT + 16 others); Thu, 23 Mar 2017 17:18:18 -0400 Received: from alt42.smtp-out.videotron.ca ([23.233.128.29]:62221 "EHLO alt42.smtp-out.videotron.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932142AbdCWVSQ (ORCPT ); Thu, 23 Mar 2017 17:18:16 -0400 X-Greylist: delayed 900 seconds by postgrey-1.27 at vger.kernel.org; Thu, 23 Mar 2017 17:18:16 EDT Received: from yoda.home ([96.23.157.65]) by Videotron with SMTP id r9sxcoZCW6cTKr9sycapMC; Thu, 23 Mar 2017 17:03:09 -0400 X-Authority-Analysis: v=2.1 cv=TfA2zUkh c=1 sm=1 tr=0 a=keA3yYpnlypCNW5BNWqu+w==:117 a=keA3yYpnlypCNW5BNWqu+w==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=6Iz7jQTuP9IA:10 a=EPRR6sFaZmFumjIzl6IA:9 Received: from xanadu.home (xanadu.home [192.168.2.2]) by yoda.home (Postfix) with ESMTP id DEAC92DA03BA; Thu, 23 Mar 2017 17:03:06 -0400 (EDT) From: Nicolas Pitre To: Greg Kroah-Hartman , Jiri Slaby Cc: Russell King , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 0/3] minitty: a minimal TTY layer alternative for embedded systems Date: Thu, 23 Mar 2017 17:03:01 -0400 Message-Id: <20170323210304.2181-1-nicolas.pitre@linaro.org> X-Mailer: git-send-email 2.9.3 X-CMAE-Envelope: MS4wfOZ0AzVapveuFGtT+vYBSa+MRPUQAc0UN3ZkKStbA26TcqUOgOWWLUtNiYW2NNKdQIFfNMECgOnUwJjTXlJg/lpQS6rJhgUpC/H+tchlQTk7DX8U+qDp 0X1Y3SGLxsbqL5+hoCDCeKP/qeE92DMfOGEkZb6i/dFrpsm9ZQE+B/p9/TxPOP/ysG50CQ8LmWFsHh5kIkWX1Rw+5sdV0a7CpxDt26Q/MoLuBeCnnqwLUCoD oSdHgLjHaKBgDzdTFQ278s6BQdOCZPgRJ60f+SGafpLoAcSwbHJLYS7Dpg3UwXNkm3xfdKWZ9JlFu6YST7IQ4n5j65gG+faSS/AJObG4EuI= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Many embedded systems don't need the full TTY layer support. Most of the time, the TTY layer is only a conduit for outputting debugging messages over a serial port. The TTY layer also implements many features that are very unlikely to ever be used in such a setup. There is great potential for both code and dynamic memory size reduction on small systems. This is what this patch series is achieving. The existing TTY code is quite large and complex. Trying to shrink it is rather risky as the potential for breakage is non negligeable. Therefore, the approach used here consists in the creation of the minimal code that interface with the existing UART drivers and provide TTY-like character devices to user space. When the regular TTY layer is disabled, then the minitty layer replacement is proposed by Kconfig. Of course, making it "mini" means there are limitations to what it does: - This supports serial ports only. No VT's, no PTY's. - The default n_tty line discipline is hardcoded and no other line discipline are supported. - The line discipline features are not all implemented. Notably, XON/XOFF is currently not implemented (although this might not require a lot of code to do it). - Hung-up state is not implemented. - No error handling on RX bytes other than counting them. - Behavior in the presence of overflows is most likely different from the full TTY code. - Job control is currently not supported (this may change in the future and be configurable). But again, most small embedded systems simply don't need those things. Here's some numbers using a minimal ARM config. When CONFIG_TTY=y, the following files are linked into the kernel: text data bss dec hex filename 8796 128 0 8924 22dc drivers/tty/n_tty.o 12846 276 44 13166 336e drivers/tty/serial/serial_core.o 4852 489 49 5390 150e drivers/tty/sysrq.o 1376 0 0 1376 560 drivers/tty/tty_buffer.o 13571 172 132 13875 3633 drivers/tty/tty_io.o 3072 0 0 3072 c00 drivers/tty/tty_ioctl.o 2457 2 120 2579 a13 drivers/tty/tty_ldisc.o 1328 0 0 1328 530 drivers/tty/tty_ldsem.o 316 0 0 316 13c drivers/tty/tty_mutex.o 2516 0 0 2516 9d4 drivers/tty/tty_port.o 51130 1067 345 52542 cd3e (TOTALS) With CONFIG_TTY=n and CONFIG_MINITTY_SERIAL=y, the above is replaced by: text data bss dec hex filename 8776 8 108 8892 22bc drivers/tty/serial/minitty_serial.o That's it! And the runtime buffer usage is much less as well. Overall diffstat: drivers/tty/Kconfig | 10 +- drivers/tty/Makefile | 3 +- drivers/tty/serial/Kconfig | 12 +- drivers/tty/serial/Makefile | 3 + .../serial/{serial_core.c => fulltty_serial.c} | 0 drivers/tty/serial/minitty_serial.c | 2091 +++++++++++++++++ drivers/tty/tty_baudrate.c | 232 ++ drivers/tty/tty_io.c | 24 - drivers/tty/tty_ioctl.c | 222 -- include/linux/console.h | 2 + include/linux/tty.h | 7 +- include/linux/tty_flip.h | 4 + init/main.c | 2 +- kernel/printk/printk.c | 24 + 14 files changed, 2380 insertions(+), 256 deletions(-)