Received: by 2002:ab2:6c55:0:b0:1fd:c486:4f03 with SMTP id v21csp385474lqp; Wed, 12 Jun 2024 04:53:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX9MgUba3QRwLjV+w+DN3gbFa3/1/Y1cTjFckz3ptcr0gEx+d4B37BpnqKbDE3kXle2pHS438Y035LBQ2zf4Q8qnLGXUOUKhjh2/APujQ== X-Google-Smtp-Source: AGHT+IFFMZTIH6EJCc8n+otxQlPJIWEWBvQNg/PbgxTiVQOHzsZIHMi1xy6f3uHZ0RDCOnruA0Y+ X-Received: by 2002:a05:620a:28c2:b0:795:4f8d:10e2 with SMTP id af79cd13be357-797f4db44fbmr255860785a.6.1718193207072; Wed, 12 Jun 2024 04:53:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718193207; cv=pass; d=google.com; s=arc-20160816; b=wl8x1Ns8yma1GAtAXMm4hTRd0s1mk0OMXVzY4GVFoApVtEQAVY+A7CEIX26trHeDwX JGNzqrUf1V9I/Tbb6fCGcHEWu6Lyr9KdBQnwTL3qDsv31T21lR0dfoDiJbqNMYZkloNa FIRU63TVSChqZ1W05eZB9BVZSMLSBmuyZZTNeQl8ANLNUkHEMPqtAMUGKe0CRkpZnNl4 WIkMT2TlzuaGjWNpt+BNCPc06heu3gYZPgTSOd54TreDJ03rP36qc2LtoM7taTwRdyTn fjSsNqYwgBKPMUv5dLZIyUR8tVGN0HoVSsIw3Xoobrge/xM60r6zZWV0uTH7FJD+73aI qe6A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:in-reply-to:subject:cc:to:date:from :dkim-signature; bh=whHryiAPBJgTX0UmNKd94bkWR6VTp+XXxTkE2EV+Beo=; fh=l61EwgxHJmcu5CE9WXK4WZvo2BIkFCTiDYRvCno8cEI=; b=xUGxXdW5Pukx4Vcs+yZSdr+bqtQlqiqZ7LdJChLExeZSlp++MdHayk7EHOnZ2XPyOs iSp3gQm8fdtuuFSMh1rGCBAMu6RcGjQqWG4L46DlRGc8iiX7n/JiyFXqNoq3zYrfDk6D ZoN/NGcUlv96F2kbS8HZ1Gjm9yvsI9ucslxCfKYowmEyL7Pnp2NGrpw5KaBzYmdllMfw LGuTitjba66eBiypE2mfhghX+a1XlOd08PSw7Xgv/vTQTyGgJ+FoG0SejoYsZFNBmGzd 3RuxCJttJrVF88H/nyWqXDoBert0QJroxNi0g30hSjUEwImHcJOWKofGQS2W64tlSXFe FSWw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aSto2ezH; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-211083-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-211083-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-441579dc973si19568061cf.537.2024.06.12.04.53.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 04:53:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-211083-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aSto2ezH; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-211083-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-211083-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (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 ny.mirrors.kernel.org (Postfix) with ESMTPS id C214B1C23FE7 for ; Wed, 12 Jun 2024 07:38:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B047D16C451; Wed, 12 Jun 2024 07:38:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="aSto2ezH" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (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 61AC512DD9B; Wed, 12 Jun 2024 07:38:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.19 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718177900; cv=none; b=lF+t42HP0DOlioMhRxmD7gb8oSrdHrjeRdKpHMZOHiCxSjD2nHboxJ9vdkwJfJn4oq2T2ebAFG7T4RjTFD1ljmCrAQAZHJH57OGLaF0cu1FnAWmfcQDsdU1Y28wnJHHcaOvoMtvFlR0H855aQLMKiD8xj4+0acCv1iFE2VjGRIM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718177900; c=relaxed/simple; bh=SRTOkK8vWEME9QApRo3c7TilPvpi/6OLtqm8jG7e20U=; h=From:Date:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=QET8JN3FlBRdE9wEy/uOHAkO8DroNxJLDawW4UaTUZxIfTWKKQiXYBvxLPd8Zh002uVTI8aIcHlYJH2HFuCZknBkQ4vVtFbjKTaMmueW7zuuei2+XDhheFdi1YwxSK5QuA7eD41NEJuRpfCcUjVhxbVpFKlM4SxPcwiloRya9/A= 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=aSto2ezH; arc=none smtp.client-ip=192.198.163.19 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=1718177899; x=1749713899; h=from:date:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=SRTOkK8vWEME9QApRo3c7TilPvpi/6OLtqm8jG7e20U=; b=aSto2ezHJhiXo79H5hJvdCyUhW7CahukGD+HLTFKaQ0BwUjq/mHmbIfm bqemET3RDrurjinEqhX2Y7AjeDlJDLq/VZUFo053l6CX0hDSpJ/KR1Lj1 N3V1rAut0sjCBWZrrfMLPEHZi433Y+HeAcUlbTzYc4xO+yKLtP9OuwPp+ rAcTsofDJ5vl4eLK/3O13fN9g7pFxFl+Xt3WiDzs0bn1qpFApgZ32TljY N9KS/8E1nGRKsgCBeTliI+CmMng0Vzv4YoWKRQzSaLSjzHOR7bkXd0NBW eM8ThICQV1VdrxquD2zvcRfgNJ3N6FByapU5caYr4p9k0MrHONL+5xi5J g==; X-CSE-ConnectionGUID: P0gk9DqfQuWUnsqNRJ6fsw== X-CSE-MsgGUID: cF8tf6jcRNC/wPn6PzhmYQ== X-IronPort-AV: E=McAfee;i="6600,9927,11100"; a="14722439" X-IronPort-AV: E=Sophos;i="6.08,232,1712646000"; d="scan'208";a="14722439" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jun 2024 00:38:18 -0700 X-CSE-ConnectionGUID: sIJBPyJiQk2LWkQF+l5nXg== X-CSE-MsgGUID: XzBC8xt2QZeDhWU8YfCBRQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,232,1712646000"; d="scan'208";a="44096445" Received: from unknown (HELO localhost) ([10.245.247.204]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jun 2024 00:38:14 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Date: Wed, 12 Jun 2024 10:38:08 +0300 (EEST) To: Douglas Anderson cc: Greg Kroah-Hartman , Jiri Slaby , Yicong Yang , Tony Lindgren , Andy Shevchenko , Johan Hovold , John Ogness , linux-arm-msm@vger.kernel.org, Bjorn Andersson , Konrad Dybcio , Stephen Boyd , linux-serial , LKML , =?ISO-8859-15?Q?Uwe_Kleine-K=F6nig?= Subject: Re: [PATCH v4 2/8] tty: serial: Add uart_fifo_timeout_ms() In-Reply-To: <20240610152420.v4.2.I65a6430ab75f74d20c28b5c5f819dd5b8455933d@changeid> Message-ID: <0bb414fa-851b-40cf-ede9-fc6252c6b173@linux.intel.com> References: <20240610222515.3023730-1-dianders@chromium.org> <20240610152420.v4.2.I65a6430ab75f74d20c28b5c5f819dd5b8455933d@changeid> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="8323328-260151195-1718177888=:1312" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323328-260151195-1718177888=:1312 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE On Mon, 10 Jun 2024, Douglas Anderson wrote: > The current uart_fifo_timeout() returns jiffies, which is not always > the most convenient for callers. Add a variant uart_fifo_timeout_ms() > that returns the timeout in milliseconds. >=20 > NOTES: > - msecs_to_jiffies() rounds up, unlike nsecs_to_jiffies(). This is > because msecs_to_jiffies() is actually intended for device drivers > to calculate timeout value. This means we don't need to take the max > of the timeout and "1" since the timeout will always be > 0 ms (we > add 20 ms of slop). > - uart_fifo_timeout_ms() returns "unsigned int" but we leave > uart_fifo_timeout() returning "unsigned long". This matches the > types of msecs_to_jiffies(). >=20 > Suggested-by: Ilpo J=C3=A4rvinen > Signed-off-by: Douglas Anderson > --- >=20 > Changes in v4: > - New >=20 > include/linux/serial_core.h | 15 +++++++++++---- > 1 file changed, 11 insertions(+), 4 deletions(-) >=20 > diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h > index 8cb65f50e830..97968acfd564 100644 > --- a/include/linux/serial_core.h > +++ b/include/linux/serial_core.h > @@ -889,14 +889,21 @@ unsigned int uart_get_divisor(struct uart_port *por= t, unsigned int baud); > /* > * Calculates FIFO drain time. > */ > -static inline unsigned long uart_fifo_timeout(struct uart_port *port) > +static inline unsigned int uart_fifo_timeout_ms(struct uart_port *port) > { > =09u64 fifo_timeout =3D (u64)READ_ONCE(port->frame_time) * port->fifosiz= e; > +=09unsigned int fifo_timeout_ms =3D div_u64(fifo_timeout, NSEC_PER_MSEC)= ; > =20 > -=09/* Add .02 seconds of slop */ > -=09fifo_timeout +=3D 20 * NSEC_PER_MSEC; > +=09/* > +=09 * Add .02 seconds of slop. This also helps account for the fact that > +=09 * when we converted from ns to ms that we didn't round up. > +=09 */ > +=09return fifo_timeout_ms + 20; > +} > =20 > -=09return max(nsecs_to_jiffies(fifo_timeout), 1UL); > +static inline unsigned long uart_fifo_timeout(struct uart_port *port) > +{ > +=09return msecs_to_jiffies(uart_fifo_timeout_ms(port)); > } Hi, This is definitely towards the right direction! However, it now does=20 double conversion, first div_u64() and then msecs_to_jiffies(). Perhaps it= =20 would be better to retain the nsecs version (maybe rename it to _ns for=20 consistency) and add _ms variant that does the nsec -> msec conversion. --=20 i. --8323328-260151195-1718177888=:1312--