Bug 24781

Summary: Incorrect calculation of free dwords in ring buffer
Product: DRI Reporter: Rafał Miłecki <zajec5>
Component: DRM/RadeonAssignee: Default DRI bug account <dri-devel>
Status: RESOLVED NOTABUG QA Contact:
Severity: normal    
Priority: medium    
Version: XOrg git   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:
Attachments:
Description Flags
drm/radeon/kms: fix calculation of free dwords in ring none

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.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.