* Boundary calculation
@ 2018-07-16 19:25 Ricardo Biehl Pasquali
2018-07-17 6:43 ` Clemens Ladisch
0 siblings, 1 reply; 5+ messages in thread
From: Ricardo Biehl Pasquali @ 2018-07-16 19:25 UTC (permalink / raw)
To: alsa-devel
Hello.
I can't get the tricky boundary calculation. Perhaps I'm
missing some obvious thing, or maybe it's really some
circumvent for a specific case that was not commented.
The current calculation for boundary is:
boundary = buffer_size;
while (boundary * 2 <= LONG_MAX - buffer_size)
boundary *= 2;
I've checked out some repositories, specially alsa-driver
in ALSA git, and I realized this calculation exists at
least since 2001. I guess it was Jaroslav who wrote.
Visualization of the calculation (B = buffer_size):
LONG_MAX
-------------------------------
\______________/ \__/
B * 4 B
\______/
B * 2
\__/
B
Why isn't a simpler calculation used instead? e.g.:
/* closest multiple of buffer size less or equal LONG_MAX */
boundary = LONG_MAX - LONG_MAX % buffer_size;
LONG_MAX
-------------------------------
\__________________________/
B * 6
Cheers!
pasquali
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Boundary calculation
2018-07-16 19:25 Ricardo Biehl Pasquali
@ 2018-07-17 6:43 ` Clemens Ladisch
2018-07-17 7:41 ` Takashi Iwai
0 siblings, 1 reply; 5+ messages in thread
From: Clemens Ladisch @ 2018-07-17 6:43 UTC (permalink / raw)
To: alsa-devel
Ricardo Biehl Pasquali wrote:
> The current calculation for boundary is:
>
> boundary = buffer_size;
> while (boundary * 2 <= LONG_MAX - buffer_size)
> boundary *= 2;
>
> Why isn't a simpler calculation used instead? e.g.:
>
> /* closest multiple of buffer size less or equal LONG_MAX */
> boundary = LONG_MAX - LONG_MAX % buffer_size;
To ensure that the factor is a power of two.
Originally, that was not really necessary, but the algorithm is
now part of the kernel/userspace interface.
Regards,
Clemens
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Boundary calculation
2018-07-17 6:43 ` Clemens Ladisch
@ 2018-07-17 7:41 ` Takashi Iwai
0 siblings, 0 replies; 5+ messages in thread
From: Takashi Iwai @ 2018-07-17 7:41 UTC (permalink / raw)
To: Clemens Ladisch; +Cc: alsa-devel
On Tue, 17 Jul 2018 08:43:27 +0200,
Clemens Ladisch wrote:
>
> Ricardo Biehl Pasquali wrote:
> > The current calculation for boundary is:
> >
> > boundary = buffer_size;
> > while (boundary * 2 <= LONG_MAX - buffer_size)
> > boundary *= 2;
> >
> > Why isn't a simpler calculation used instead? e.g.:
> >
> > /* closest multiple of buffer size less or equal LONG_MAX */
> > boundary = LONG_MAX - LONG_MAX % buffer_size;
>
> To ensure that the factor is a power of two.
>
> Originally, that was not really necessary, but the algorithm is
> now part of the kernel/userspace interface.
Right.
I don't think we have strictly ABI issue even if relaxing this, but I
also don't think it would give so much benefit, either.
thanks,
Takashi
^ permalink raw reply [flat|nested] 5+ messages in thread
* Boundary calculation
@ 2018-07-17 13:13 Ricardo Biehl Pasquali
2018-07-17 15:33 ` Clemens Ladisch
0 siblings, 1 reply; 5+ messages in thread
From: Ricardo Biehl Pasquali @ 2018-07-17 13:13 UTC (permalink / raw)
To: clemens; +Cc: alsa-devel
Have you addressed your reply to pasqualirb at gmail.com?
I have not received in my mail neither yours nor Takashi's
reply. I had to copy manually the headers and the message.
Thanks!
Clemens Ladisch wrote:
> To ensure that the factor is a power of two.
Ok, but why LONG_MAX - buffer_size?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Boundary calculation
2018-07-17 13:13 Boundary calculation Ricardo Biehl Pasquali
@ 2018-07-17 15:33 ` Clemens Ladisch
0 siblings, 0 replies; 5+ messages in thread
From: Clemens Ladisch @ 2018-07-17 15:33 UTC (permalink / raw)
To: alsa-devel; +Cc: Ricardo Biehl Pasquali
Ricardo Biehl Pasquali wrote:
> Clemens Ladisch wrote:
>> To ensure that the factor is a power of two.
>
> Ok, but why LONG_MAX - buffer_size?
To ensure that adding the position in the buffer to the current pointer
will not overflow.
Regards,
Clemens
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-07-17 15:34 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-17 13:13 Boundary calculation Ricardo Biehl Pasquali
2018-07-17 15:33 ` Clemens Ladisch
-- strict thread matches above, loose matches on Subject: below --
2018-07-16 19:25 Ricardo Biehl Pasquali
2018-07-17 6:43 ` Clemens Ladisch
2018-07-17 7:41 ` Takashi Iwai
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.