Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp3029328rdb; Tue, 6 Feb 2024 05:21:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IFShfDc4x3Efb8Gu2r7zirBwM2Pt1GxX/KC/1jUmGL3bpARgNUAePtoZALz0CQfIZH3xDKh X-Received: by 2002:a05:6359:4118:b0:178:ba22:3cfd with SMTP id kh24-20020a056359411800b00178ba223cfdmr1967098rwc.17.1707225682247; Tue, 06 Feb 2024 05:21:22 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCU5TDFSEYB8OOkHR/hB4+fhXEpDg7+/r0KZ4T34FG/g9dmJHxOnMalmGEoWr0rG18oHp6tVfLfs+n7fe1LqVG3QVapalqYlR61QA80pRA== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id r9-20020a63fc49000000b005d8b44e7961si1580937pgk.599.2024.02.06.05.21.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 05:21:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54994-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b="VTUAN+O/"; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-54994-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54994-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 45EFDB254CB for ; Tue, 6 Feb 2024 13:09:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3D820130E32; Tue, 6 Feb 2024 13:09:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=intel.com header.i=@intel.com header.b="VTUAN+O/" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 92176130E2C; Tue, 6 Feb 2024 13:09:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.21 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707224981; cv=none; b=sQDI3cKotZZnmwHozdDR+LN4rtyvNDPuDrlBO4kXESK8flpgjEU1yBwv1hCb3NAPIylYFoeBeLx26qr/h3ANwu+ViLZX+m7cjygQNWX/VU3FY5ahU5kxsuQUIUqGk+vcp0GEE6RjBnwcy43hBF/W4NvWJCBWBNQ0SlMNzvoSyg0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707224981; c=relaxed/simple; bh=EIi8PsNJVlYI6YE+gaDW03VVmxtdFg+rlTNVZ23mC8I=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UkDOw8exO28WbZio0MQYBVvo0+rgx2MD8P0aCgnDko1/zryp1i2tyMMLpvq0pW+uQh+QpfeTAoVpPwwMJ8Q17CHv2c9qZq+Pi2eS65aZro7e5Lly/IZyZ1sHpQroq1T6vHBvT2zkaOfWMznDNkxBh+BxB8RP4OmgeJlWHg1uPbg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=VTUAN+O/; arc=none smtp.client-ip=198.175.65.21 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707224979; x=1738760979; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=EIi8PsNJVlYI6YE+gaDW03VVmxtdFg+rlTNVZ23mC8I=; b=VTUAN+O/SqqrCACwYQ1bZ0iVSO3olxxfgvg3Aoc3l232YVMzTfjplGOc uSVsm0UM7M4FfOFr8cq4li1R8OE47Hxnmd0MTokOF2V9IETd/qZJvbqiC lLiXVSAeHwYa58jmn6+59eNPahayaYx5T3/2LfvNhcsfcemSYMb2+rXLe /ksYX+pDzca/Wcpgp1ccEWqCK0WwYuqfzLH3BQmO57GfxBlVzuyOtnidd fjklqKmkvpyfnjyfw8ltt3ltyAZ6JX1F/W+IjlrU3QH3yZ6JBwmJaT36n kDOhJVZnXRpXQXO3WVpZIZ/je3/aQ+zzGuY6A3PY5hnjXVnJtZlfBojGp g==; X-IronPort-AV: E=McAfee;i="6600,9927,10975"; a="654227" X-IronPort-AV: E=Sophos;i="6.05,247,1701158400"; d="scan'208";a="654227" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2024 05:09:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10975"; a="824176965" X-IronPort-AV: E=Sophos;i="6.05,247,1701158400"; d="scan'208";a="824176965" Received: from smile.fi.intel.com ([10.237.72.54]) by orsmga001.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2024 05:09:35 -0800 Received: from andy by smile.fi.intel.com with local (Exim 4.97) (envelope-from ) id 1rXLCe-00000002LVL-1AyX; Tue, 06 Feb 2024 15:09:32 +0200 Date: Tue, 6 Feb 2024 15:09:32 +0200 From: Andy Shevchenko To: Yicong Yang Cc: gregkh@linuxfoundation.org, jirislaby@kernel.org, tony@atomide.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, john.ogness@linutronix.de, tglx@linutronix.de, yangyicong@hisilicon.com, linuxarm@huawei.com, prime.zeng@hisilicon.com, jonathan.cameron@huawei.com, fanghao11@huawei.com Subject: Re: [PATCH v2] serial: port: Don't suspend if the port is still busy Message-ID: References: <20240206073322.5560-1-yangyicong@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240206073322.5560-1-yangyicong@huawei.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo On Tue, Feb 06, 2024 at 03:33:22PM +0800, Yicong Yang wrote: > From: Yicong Yang > > We accidently met the issue that the bash prompt is not shown after the > previous command done and until the next input if there's only one CPU > (In our issue other CPUs are isolated by isolcpus=). Further analysis > shows it's because the port entering runtime suspend even if there's > still pending chars in the buffer and the pending chars will only be > processed in next device resuming. We are using amba-pl011 and the > problematic flow is like below: > > Bash                                         kworker > tty_write() >   file_tty_write() >     n_tty_write() >       uart_write() >         __uart_start() >           pm_runtime_get() // wakeup waker >             queue_work() >                                     pm_runtime_work() >                                                rpm_resume() >                                                 status = RPM_RESUMING >                                                 serial_port_runtime_resume() >                                                   port->ops->start_tx() >                                                     pl011_tx_chars() >                                                       uart_write_wakeup() >         […] >         __uart_start() >           pm_runtime_get() < 0 // because runtime status = RPM_RESUMING >                                // later data are not commit to the port driver >                                                 status = RPM_ACTIVE >                                                 rpm_idle() -> rpm_suspend() > > This patch tries to fix this by checking the port busy before entering > runtime suspending. A runtime_suspend callback is added for the port > driver. When entering runtime suspend the callback is invoked, if there's > still pending chars in the buffer then flush the buffer. .. > +static int serial_port_runtime_suspend(struct device *dev) > +{ > + struct serial_port_device *port_dev = to_serial_base_port_device(dev); > + struct uart_port *port; > + unsigned long flags; > + int ret = 0; > + > + port = port_dev->port; > + > + if (port->flags & UPF_DEAD) > + return ret; > + > + uart_port_lock_irqsave(port, &flags); > + if (__serial_port_busy(port)) { > + port->ops->start_tx(port); > + pm_runtime_mark_last_busy(dev); Do you think we need to call this under a lock? > + ret = -EBUSY; > + } > + uart_port_unlock_irqrestore(port, flags); > + > + return ret; > +} With the above I would rather write it as static int __serial_port_busy(struct uart_port *port) { if (uart_tx_stopped(port)) return 0; if (uart_circ_chars_pending(&port->state->xmit) return -EBUSY; return 0; } static int serial_port_runtime_suspend(struct device *dev) { int ret; ... uart_port_lock_irqsave(port, &flags); ret = __serial_port_busy(port); if (ret) port->ops->start_tx(port); uart_port_unlock_irqrestore(port, flags); if (ret) pm_runtime_mark_last_busy(dev); return ret; } It also seems aligned with the resume implementation above. .. For the consistency's sake the resume can be refactored as static int serial_port_runtime_resume(struct device *dev) { ... int ret; ... ret = __serial_port_busy(port); if (ret) ... } but this can be done later. -- With Best Regards, Andy Shevchenko