Re: [PATCH v3 01/12] serial: Store character timing information to uart_port

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Apr 11, 2022 at 01:56:24PM +0300, Andy Shevchenko wrote:
> On Mon, Apr 11, 2022 at 01:52:18PM +0300, Andy Shevchenko wrote:
> > On Mon, Apr 11, 2022 at 11:33:10AM +0300, Ilpo Järvinen wrote:
> > > Struct uart_port currently stores FIFO timeout. Having character
> > > timing information readily available is useful. Even serial core
> > > itself determines char_time from port->timeout using inverse
> > > calculation.
> > > 
> > > Store frame_time directly into uart_port. Character time is stored
> > > in nanoseconds to have reasonable precision with high rates.
> > > To avoid overflow, 64-bit math is necessary.
> > > 
> > > It might be possible to determine timeout from frame_time by
> > > multiplying it with fifosize as needed but only part of the
> > > users seem to be protected by a lock. Thus, this patch does
> > > not pursue storing only frame_time in uart_port.
> 
> ...
> 
> > > -	char_time = (port->timeout - HZ/50) / port->fifosize;
> > > -	char_time = char_time / 5;
> > > -	if (char_time == 0)
> > > -		char_time = 1;
> > > +	char_time = max(nsecs_to_jiffies(port->frame_time / 5), 1UL);
> > > +
> > >  	if (timeout && timeout < char_time)
> > >  		char_time = timeout;
> > 
> > Seems it can be packed to something like
> > 
> > 	char_time = min_not_zero(nsecs_to_jiffies(port->frame_time / 5), timeout);
> > 
> > ?
> 
> Actually:
> 
> 	char_time = min_not_zero(timeout, nsecs_to_jiffies(port->frame_time / 5));
> 
> Ah, either way it would still miss the case when both == 0. So, we need
> something like minmax3_not_zero, where 1UL is implied argument. Probably
> a suggesting for the future, since here it doesn't make much sense to
> introduce.

In case somebody goes for it:

#define minmax_not_zero(x, y)	(min_not_zero(x, y) ?: 1)

-- 
With Best Regards,
Andy Shevchenko





[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux PPP]     [Linux FS]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Linmodem]     [Device Mapper]     [Linux Kernel for ARM]

  Powered by Linux