Skip to contentSkip to conversation

CRTC video scanout position for high precision vblank timestamping?

DISCUSSION Mario Kleiner 4 participants 8 messages Dec 29, 2010 5 messages not in the archive

lore
Share & tools
lore
#0 lore raw

Hello all,

i have recently implemented some patches to the drm core and to the intel and radeon kms drivers to provide high precision timestamping of vblank intervals and for timestamping of pageflip bufferswap completion. This is needed to properly implement the DRI2 sync & swap bits and their support for the oml_sync_control extension.

The patches are in drm-next and will hopefully land in the 2.6.38 merge window. Now i'd like to add support for the nouveau kms driver as well.

I had a look at the current nouveau code in drm-next. Implementing the patches shouldn't be a problem, it is mostly copy & paste from radeon/intel kms + a little bit of adjustments and then testing.

Problem: The code needs to query the current video scanout position of a given crtc. My missing bit of information is the location and format of the MMIO registers which presumably exist on nvidia gpu's to provide this information. I know the gpu's support this, because the NVidia proprietary drivers on both MS-Windows and MacOS/X provide a function to query this info from userspace (Windows DirectDraw-7 GetScanline() function, OS/X CGDisplayBeamposition() function). Unfortunately the nvidia blob on Linux (and Linux/X11 itself) to my knowledge doesn't support such an api, so i can't simply mmio-trace the blob to find the relevant register. Also afaik the rules-ng database and the current driver source code don't document the location of such a register.

I've already made friendship with renouveau and hacked it a bit for my purpose, but playing with it for an hour on a Geforce 8800 and staring at dumps didn't get me lucky that easily.

I thought i'd ask if any of you have by accident stumbled across such a register or would have any good hints how i could narrow down the search. Otherwise i'll hack up renouveau to do a bit of pattern matching, searching for characteristic patterns in the brute force way and praying to the gods of computing that this won't take forever. To my surprise I already had to learn that apparently just reading the wrong registers can cause display corruption and crash the whole machine.

Any helpful comments highly appreciated.

Thanks,
-mario

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 39 lines · Mario Kleiner

Hello all,

i have recently implemented some patches to the drm core and to the intel and radeon kms drivers to provide high precision timestamping of vblank intervals and for timestamping of pageflip bufferswap completion. This is needed to properly implement the DRI2 sync & swap bits and their support for the oml_sync_control extension.

The patches are in drm-next and will hopefully land in the 2.6.38 merge window. Now i'd like to add support for the nouveau kms driver as well.

I had a look at the current nouveau code in drm-next. Implementing the patches shouldn't be a problem, it is mostly copy & paste from radeon/intel kms + a little bit of adjustments and then testing.

Problem: The code needs to query the current video scanout position of a given crtc. My missing bit of information is the location and format of the MMIO registers which presumably exist on nvidia gpu's to provide this information. I know the gpu's support this, because the NVidia proprietary drivers on both MS-Windows and MacOS/X provide a function to query this info from userspace (Windows DirectDraw-7 GetScanline() function, OS/X CGDisplayBeamposition() function). Unfortunately the nvidia blob on Linux (and Linux/X11 itself) to my knowledge doesn't support such an api, so i can't simply mmio-trace the blob to find the relevant register. Also afaik the rules-ng database and the current driver source code don't document the location of such a register.

I've already made friendship with renouveau and hacked it a bit for my purpose, but playing with it for an hour on a Geforce 8800 and staring at dumps didn't get me lucky that easily.

I thought i'd ask if any of you have by accident stumbled across such a register or would have any good hints how i could narrow down the search. Otherwise i'll hack up renouveau to do a bit of pattern matching, searching for characteristic patterns in the brute force way and praying to the gods of computing that this won't take forever. To my surprise I already had to learn that apparently just reading the wrong registers can cause display corruption and crash the whole machine.

Quoted 9 lines

Any helpful comments highly appreciated.

Thanks,
-mario
_______________________________________________
Nouveau mailing list [email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau

If you promise to (get someone to) document them i'll tell you the ones for my NV96 (probably the same registers on all geforce 8 and upwards) :-)

0x616340: CRTC0 vertical scanline (lower 16 bits, upper 16 bits empty) 0x616344: CRTC0 horizontal scanline (lower 16 bits, upper 16 bits is a counter that increments every display cycle)

0x616B40: CRTC1 vertical scanline
0x616B44: CRTC1 horizontal scanline

I found these by simply dumping the entire range modesetting related registers. At the time they didn't help me (the issue of swapbuffers remains unsolved on this generation of hardware, it didn't interest me *that* much). I don't know what exactly you are doing, but a lot of stuff is done through pushbuffers (even modesetting) so there are no "instant" registers that i know of.

With respect to older cards, i think the VGA spec should offer some help. That data has been duplicated into normally accessible registers. If you're lucky Francisco Jerez will reply, he might know the exact registers.

I wish you much fun and happiness.

Sincerely,

Maarten.

Signature · 2 lines
Far away from the primal instinct, the song seems to fade away, the
river get wider between your thoughts and the things we do and say.

A message that is not in the archive (sent off-list or not yet received): AANLkTi=9FagJJYP148Zsc26mm+BCvRCNTqD4jsLT7os6-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#4 lore raw
Quoted 76 lines · Maarten Maathuis
Quoted 39 lines · Mario Kleiner

Hello all,

i have recently implemented some patches to the drm core and to the intel and radeon kms drivers to provide high precision timestamping of vblank intervals and for timestamping of pageflip bufferswap completion. This is needed to properly implement the DRI2 sync & swap bits and their support for the oml_sync_control extension.

The patches are in drm-next and will hopefully land in the 2.6.38 merge window. Now i'd like to add support for the nouveau kms driver as well.

I had a look at the current nouveau code in drm-next. Implementing the patches shouldn't be a problem, it is mostly copy & paste from radeon/intel kms + a little bit of adjustments and then testing.

Problem: The code needs to query the current video scanout position of a given crtc. My missing bit of information is the location and format of the MMIO registers which presumably exist on nvidia gpu's to provide this information. I know the gpu's support this, because the NVidia proprietary drivers on both MS-Windows and MacOS/X provide a function to query this info from userspace (Windows DirectDraw-7 GetScanline() function, OS/X CGDisplayBeamposition() function). Unfortunately the nvidia blob on Linux (and Linux/X11 itself) to my knowledge doesn't support such an api, so i can't simply mmio-trace the blob to find the relevant register. Also afaik the rules-ng database and the current driver source code don't document the location of such a register.

I've already made friendship with renouveau and hacked it a bit for my purpose, but playing with it for an hour on a Geforce 8800 and staring at dumps didn't get me lucky that easily.

I thought i'd ask if any of you have by accident stumbled across such a register or would have any good hints how i could narrow down the search. Otherwise i'll hack up renouveau to do a bit of pattern matching, searching for characteristic patterns in the brute force way and praying to the gods of computing that this won't take forever. To my surprise I already had to learn that apparently just reading the wrong registers can cause display corruption and crash the whole machine.

Quoted 9 lines

Any helpful comments highly appreciated.

Thanks,
-mario
_______________________________________________
Nouveau mailing list [email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau

If you promise to (get someone to) document them i'll tell you the ones for my NV96 (probably the same registers on all geforce 8 and upwards) :-)

0x616340: CRTC0 vertical scanline (lower 16 bits, upper 16 bits empty) 0x616344: CRTC0 horizontal scanline (lower 16 bits, upper 16 bits is a counter that increments every display cycle)

0x616B40: CRTC1 vertical scanline
0x616B44: CRTC1 horizontal scanline

I found these by simply dumping the entire range modesetting related registers. At the time they didn't help me (the issue of swapbuffers remains unsolved on this generation of hardware, it didn't interest me *that* much). I don't know what exactly you are doing, but a lot of stuff is done through pushbuffers (even modesetting) so there are no "instant" registers that i know of.

With respect to older cards, i think the VGA spec should offer some help. That data has been duplicated into normally accessible registers. If you're lucky Francisco Jerez will reply, he might know the exact registers.

I wish you much fun and happiness.

Quoted 8 lines

Sincerely,

Maarten.

--
Far away from the primal instinct, the song seems to fade away, the river get wider between your thoughts and the things we do and say.

In my infinite wisdom i swapped the vertical and horizontal regs, these are the right ones:

0x616340: CRTC0 horizontal scanline (lower 16 bits, upper 16 bits is a counter that increments every display cycle)
0x616344: CRTC0 vertical scanline (lower 16 bits, upper 16 bits empty)

0x616B40: CRTC1 horizontal scanline
0x616B44: CRTC1 vertical scanline

Signature · 2 lines
Far away from the primal instinct, the song seems to fade away, the
river get wider between your thoughts and the things we do and say.

A message that is not in the archive (sent off-list or not yet received): AANLkTimBropE8C8uxnwkuQKdM-yNByY2a=EQQfGZNVCf-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#6 lore raw
Quoted 89 lines · Maarten Maathuis
Quoted 76 lines · Maarten Maathuis
Quoted 39 lines · Mario Kleiner

Hello all,

i have recently implemented some patches to the drm core and to the intel and radeon kms drivers to provide high precision timestamping of vblank intervals and for timestamping of pageflip bufferswap completion. This is needed to properly implement the DRI2 sync & swap bits and their support for the oml_sync_control extension.

The patches are in drm-next and will hopefully land in the 2.6.38 merge window. Now i'd like to add support for the nouveau kms driver as well.

I had a look at the current nouveau code in drm-next. Implementing the patches shouldn't be a problem, it is mostly copy & paste from radeon/intel kms + a little bit of adjustments and then testing.

Problem: The code needs to query the current video scanout position of a given crtc. My missing bit of information is the location and format of the MMIO registers which presumably exist on nvidia gpu's to provide this information. I know the gpu's support this, because the NVidia proprietary drivers on both MS-Windows and MacOS/X provide a function to query this info from userspace (Windows DirectDraw-7 GetScanline() function, OS/X CGDisplayBeamposition() function). Unfortunately the nvidia blob on Linux (and Linux/X11 itself) to my knowledge doesn't support such an api, so i can't simply mmio-trace the blob to find the relevant register. Also afaik the rules-ng database and the current driver source code don't document the location of such a register.

I've already made friendship with renouveau and hacked it a bit for my purpose, but playing with it for an hour on a Geforce 8800 and staring at dumps didn't get me lucky that easily.

I thought i'd ask if any of you have by accident stumbled across such a register or would have any good hints how i could narrow down the search. Otherwise i'll hack up renouveau to do a bit of pattern matching, searching for characteristic patterns in the brute force way and praying to the gods of computing that this won't take forever. To my surprise I already had to learn that apparently just reading the wrong registers can cause display corruption and crash the whole machine.

Quoted 9 lines

Any helpful comments highly appreciated.

Thanks,
-mario
_______________________________________________
Nouveau mailing list [email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau

If you promise to (get someone to) document them i'll tell you the ones for my NV96 (probably the same registers on all geforce 8 and upwards) :-)

0x616340: CRTC0 vertical scanline (lower 16 bits, upper 16 bits empty) 0x616344: CRTC0 horizontal scanline (lower 16 bits, upper 16 bits is a counter that increments every display cycle)

0x616B40: CRTC1 vertical scanline
0x616B44: CRTC1 horizontal scanline

I found these by simply dumping the entire range modesetting related registers. At the time they didn't help me (the issue of swapbuffers remains unsolved on this generation of hardware, it didn't interest me *that* much). I don't know what exactly you are doing, but a lot of stuff is done through pushbuffers (even modesetting) so there are no "instant" registers that i know of.

With respect to older cards, i think the VGA spec should offer some help. That data has been duplicated into normally accessible registers. If you're lucky Francisco Jerez will reply, he might know the exact registers.

I wish you much fun and happiness.

Quoted 8 lines

Sincerely,

Maarten.

--
Far away from the primal instinct, the song seems to fade away, the river get wider between your thoughts and the things we do and say.

In my infinite wisdom i swapped the vertical and horizontal regs, these are the right ones:

Quoted 6 lines

0x616340: CRTC0 horizontal scanline (lower 16 bits, upper 16 bits is a counter that increments every display cycle)
0x616344: CRTC0 vertical scanline (lower 16 bits, upper 16 bits empty)

0x616B40: CRTC1 horizontal scanline
0x616B44: CRTC1 vertical scanline

Ah, I should've waited 10 minutes before doing the same here. Ah well, I can confirm at least on NV84, I can't imagine it differs at all on any nv50+ board either.

Ben.

Quoted 1 line
#7 lore raw
Quoted 94 lines · Ben Skeggs
Quoted 93 lines · Maarten Maathuis
Quoted 76 lines · Maarten Maathuis
Quoted 39 lines · Mario Kleiner

Hello all,

i have recently implemented some patches to the drm core and to the intel and radeon kms drivers to provide high precision timestamping of vblank intervals and for timestamping of pageflip bufferswap completion. This is needed to properly implement the DRI2 sync& swap bits and their support for the oml_sync_control extension.

The patches are in drm-next and will hopefully land in the 2.6.38 merge window. Now i'd like to add support for the nouveau kms driver as well.

I had a look at the current nouveau code in drm-next. Implementing the patches shouldn't be a problem, it is mostly copy& paste from radeon/intel kms + a little bit of adjustments and then testing.

Problem: The code needs to query the current video scanout position of a given crtc. My missing bit of information is the location and format of the MMIO registers which presumably exist on nvidia gpu's to provide this information. I know the gpu's support this, because the NVidia proprietary drivers on both MS-Windows and MacOS/X provide a function to query this info from userspace (Windows DirectDraw-7 GetScanline() function, OS/X CGDisplayBeamposition() function). Unfortunately the nvidia blob on Linux (and Linux/X11 itself) to my knowledge doesn't support such an api, so i can't simply mmio-trace the blob to find the relevant register. Also afaik the rules-ng database and the current driver source code don't document the location of such a register.

I've already made friendship with renouveau and hacked it a bit for my purpose, but playing with it for an hour on a Geforce 8800 and staring at dumps didn't get me lucky that easily.

I thought i'd ask if any of you have by accident stumbled across such a register or would have any good hints how i could narrow down the search. Otherwise i'll hack up renouveau to do a bit of pattern matching, searching for characteristic patterns in the brute force way and praying to the gods of computing that this won't take forever. To my surprise I already had to learn that apparently just reading the wrong registers can cause display corruption and crash the whole machine.

Quoted 9 lines

Any helpful comments highly appreciated.

Thanks,
-mario
_______________________________________________
Nouveau mailing list [email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau

If you promise to (get someone to) document them i'll tell you the ones for my NV96 (probably the same registers on all geforce 8 and upwards) :-)

0x616340: CRTC0 vertical scanline (lower 16 bits, upper 16 bits empty) 0x616344: CRTC0 horizontal scanline (lower 16 bits, upper 16 bits is a counter that increments every display cycle)

0x616B40: CRTC1 vertical scanline
0x616B44: CRTC1 horizontal scanline

I found these by simply dumping the entire range modesetting related registers. At the time they didn't help me (the issue of swapbuffers remains unsolved on this generation of hardware, it didn't interest me *that* much). I don't know what exactly you are doing, but a lot of stuff is done through pushbuffers (even modesetting) so there are no "instant" registers that i know of.

With respect to older cards, i think the VGA spec should offer some help. That data has been duplicated into normally accessible registers. If you're lucky Francisco Jerez will reply, he might know the exact registers.

I wish you much fun and happiness.

Quoted 8 lines

Sincerely,

Maarten.

--
Far away from the primal instinct, the song seems to fade away, the river get wider between your thoughts and the things we do and say.

In my infinite wisdom i swapped the vertical and horizontal regs, these are the right ones:

0x616340: CRTC0 horizontal scanline (lower 16 bits, upper 16 bits is a counter that increments every display cycle)
0x616344: CRTC0 vertical scanline (lower 16 bits, upper 16 bits empty)

Quoted 8 lines
Quoted 2 lines

0x616B40: CRTC1 horizontal scanline
0x616B44: CRTC1 vertical scanline

Ah, I should've waited 10 minutes before doing the same here. Ah well, I can confirm at least on NV84, I can't imagine it differs at all on any nv50+ board either.

Ben.

Quoted 1 line

Wow, that was fast! Thanks! I'll get some good sleep now and then give it a try on my GF-8800. This is probably also useful to implement the .get_vblank_counter() hook properly. Currently it hooks up to drm_vblank_count() which is problematic, as .get_vblank_counter() is meant to query the hardware for the purpose of reinitializing drm_vblank_count() after a long vblank irq off period.

I'll let you know how it goes, hopefully with some nice patches asap.

If somebody knows about similar NV40 and earlier registers, keep it coming :-)

Is the range from NV_PCRTC0_OFFSET to NV_PCRTC0_OFFSET + NV_PCRTC0_SIZE a good starting point for a search on NV40 and earlier?

thanks,
-mario

A message that is not in the archive (sent off-list or not yet received): [email protected]

#9 lore raw
Quoted 11 lines · Mario Kleiner
Quoted 10 lines · Ben Skeggs

On Wed, 2010-12-29 at 10:37 +0100, Maarten Maathuis wrote:
[...]

Quoted 8 lines

In my infinite wisdom i swapped the vertical and horizontal regs, these are the right ones:

0x616340: CRTC0 horizontal scanline (lower 16 bits, upper 16 bits is a counter that increments every display cycle)
0x616344: CRTC0 vertical scanline (lower 16 bits, upper 16 bits empty)

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

0x616B40: CRTC1 horizontal scanline
0x616B44: CRTC1 vertical scanline

Ah, I should've waited 10 minutes before doing the same here. Ah well, I can confirm at least on NV84, I can't imagine it differs at all on any nv50+ board either.

I can confirm those registers are still there on NVA8.

Quoted 10 lines
Quoted 2 lines

Ben.

Quoted 1 line

Wow, that was fast! Thanks! I'll get some good sleep now and then give it a try on my GF-8800. This is probably also useful to implement the .get_vblank_counter() hook properly. Currently it hooks up to drm_vblank_count() which is problematic, as .get_vblank_counter() is meant to query the hardware for the purpose of reinitializing drm_vblank_count() after a long vblank irq off period.

Quoted 5 lines

I'll let you know how it goes, hopefully with some nice patches asap.

If somebody knows about similar NV40 and earlier registers, keep it coming :-)

On nv04-nv4x class hardware there's a scanline counter in the lower 12 bits of 0x600808 (0x602808 for the second CRTC), bit 16 lights up during the vblank period.

I don't think I've ever seen a hardware frame counter there, but they might have one. Tracing what the nvidia blob does for SGI_video_sync and friends would be your best bet I guess.

Quoted 9 lines

Is the range from NV_PCRTC0_OFFSET to NV_PCRTC0_OFFSET + NV_PCRTC0_SIZE a good starting point for a search on NV40 and earlier?

thanks,
-mario
_______________________________________________
Nouveau mailing list [email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau

_______________________________________________
Nouveau mailing list [email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau

A message that is not in the archive (sent off-list or not yet received): [email protected]

#11 lore raw

Sorry for the top-posting. Also confirmed on fermi (nvc0).

Ben.

Sent from my iPhone

Quoted 54 lines · Francisco Jerez
Quoted 11 lines · Mario Kleiner
Quoted 10 lines · Ben Skeggs

On Wed, 2010-12-29 at 10:37 +0100, Maarten Maathuis wrote:
[...]

Quoted 8 lines

In my infinite wisdom i swapped the vertical and horizontal regs, these are the right ones:

0x616340: CRTC0 horizontal scanline (lower 16 bits, upper 16 bits is a counter that increments every display cycle)
0x616344: CRTC0 vertical scanline (lower 16 bits, upper 16 bits empty)

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

0x616B40: CRTC1 horizontal scanline
0x616B44: CRTC1 vertical scanline

Ah, I should've waited 10 minutes before doing the same here. Ah well, I can confirm at least on NV84, I can't imagine it differs at all on any nv50+ board either.

I can confirm those registers are still there on NVA8.

Quoted 10 lines
Quoted 2 lines

Ben.

Quoted 1 line

Wow, that was fast! Thanks! I'll get some good sleep now and then give it a try on my GF-8800. This is probably also useful to implement the .get_vblank_counter() hook properly. Currently it hooks up to drm_vblank_count() which is problematic, as .get_vblank_counter() is meant to query the hardware for the purpose of reinitializing drm_vblank_count() after a long vblank irq off period.

Quoted 5 lines

I'll let you know how it goes, hopefully with some nice patches asap.

If somebody knows about similar NV40 and earlier registers, keep it coming :-)

On nv04-nv4x class hardware there's a scanline counter in the lower 12 bits of 0x600808 (0x602808 for the second CRTC), bit 16 lights up during the vblank period.

I don't think I've ever seen a hardware frame counter there, but they might have one. Tracing what the nvidia blob does for SGI_video_sync and friends would be your best bet I guess.

Quoted 9 lines

Is the range from NV_PCRTC0_OFFSET to NV_PCRTC0_OFFSET + NV_PCRTC0_SIZE a good starting point for a search on NV40 and earlier?

thanks,
-mario
_______________________________________________
Nouveau mailing list [email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau

#12 lore raw
In reply to a message not in the archive
Quoted 7 lines · Maarten Maathuis

I found these by simply dumping the entire range modesetting related registers. At the time they didn't help me (the issue of swapbuffers remains unsolved on this generation of hardware, it didn't interest me *that* much). I don't know what exactly you are doing, but a lot of stuff is done through pushbuffers (even modesetting) so there are no "instant" registers that i know of.

Oh, it's about precisely timestamping when a scanout starts (at end of vblank) and when exactly a bufferswap completed - when the post-swap frontbuffer starts to scan out. This commit gives the background info:

<http://git.kernel.org/?p=linux/kernel/git/airlied/drm-2.6.git;a=commit;h=27641c3f003e7f3b6585c01d8a788883603eb262>

This is what it looks like in the i915 kms, to be implemented very similar in nouveau kms:

<http://git.kernel.org/?p=linux/kernel/git/airlied/drm-2.6.git;a=commit;h=0af7e4dff50454905092d468e91c1ef92e10e6b4>

-mario