Bug 24781 - Incorrect calculation of free dwords in ring buffer
Incorrect calculation of free dwords in ring buffer
Status: RESOLVED NOTABUG
Product: DRI
Classification: Unclassified
Component: DRM/Radeon
XOrg git
Other All
: medium normal
Assigned To: Default DRI bug account
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-10-28 17:53 UTC by Rafał Miłecki
Modified: 2009-10-28 23:31 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments
drm/radeon/kms: fix calculation of free dwords in ring (1.54 KB, patch)
2009-10-28 17:53 UTC, Rafał Miłecki
no flags Details | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Rafał Miłecki 2009-10-28 17:53:56 UTC
Created attachment 30782 [details] [review]
drm/radeon/kms: fix calculation of free dwords in ring

There are two scenarios of read/write pointers relation:

1) read lower than write
/----------------------------\
|     A B C D E F G          |
| 1 2 3 4 5 6 7 8 9 10 11 12 |
\----------------------------/
      R           W
used = w - r
free = size - used
free = size - (w - r)
free = size - w + r
free = r + size - w


2) write lower than read
/----------------------------\
| E F G           A  B  C  D |
| 1 2 3 4 5 6 7 8 9 10 11 12 |
\----------------------------/
      W           R
free = r - w


I made there ascii pictures to make it clear, as noone believed me today on IRC we have some bug there ;)

Problem is we calculate free dwords for first situation only (always). We have to detect second situation and use other calculation then.
Comment 1 Rafał Miłecki 2009-10-28 17:57:52 UTC
You can see real hitting this issue in bug #24535 (check rings dumps logs).
Comment 2 Alex Deucher 2009-10-28 23:27:00 UTC
The current code works as is since the ring size is always a power of two as per the comment in the code:

      A B C D E F G          
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
      R           W

(3 + 16 - 9) & 15 = 10

E F G                      A  B  C  D 
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
    W                      R

(12 + 16 - 2) & 15 = 10
Comment 3 Rafał Miłecki 2009-10-28 23:31:25 UTC
(In reply to comment #2)
> The current code works as is since the ring size is always a power of two as
> per the comment in the code:

It seems so... I've never played with so hackish (like for me) bit operations. Thanks for explaining.