How do I find the video memory region(s) representing what's on my screen, from within the Linux kernel?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












0















About 5-20 times a day I am presented with brief visual glitches and heisenbugs caused by race conditions that only occur under high I/O load. These disappear off the screen far too quickly for me to grab a camera in time, so I am looking to find/build a screenshotting/screen-recording tool that acts/responds with the lowest possible delay after I press a hotkey/shortcut.



Critically, this tool's high-responsiveness needs to be negligibly (ideally not at all) impacted by high I/O activity, like 10-second load averages of 20-40.



A fair argument could be made about loading PREEMPT_RT and running Xorg and a homemade screenshot dæmon as realtime. This would work... except for the bit about running X realtime; I actually do want to get work done on my computer. :)



Thing is, I can confidently run any code I like in realtime on my computer, just by putting it inside the Linux kernel. So, kernel module time!! To reiterate my question,



How do I find, access and grok the memory region(s) representing the pixels on my screen, all from within a Linux kernel module?



I've found that trying to read /dev/fb0 while X is running just produces a black image, so that apparently won't work.



Unfortunately https://dri.freedesktop.org/docs/drm/gpu/index.html doesn't show anything obviously related to framebuffer read-back, but I have no experience with this API, so I don't really know what I'm looking for.



I accept that driver-specific code will likely be needed (since there's unlikely a driver-agnostic canonical spot in memory representing what's actually on screen), and this fine. I'm using an Intel-GPU-based machine at the moment, and I am happy to start specifically coding for that.



FWIW, I asked a differently-worded version of this question just under two years ago. That question only attracted one comment about HDCP and was never answered, but as I am still dealing with this problem up to 20 times a day even two years later, I'm having another go.



(My current approach (scrot launched by i3's hotkey binder) very often takes up to 20 (!!) seconds to take a single screenshot on systems experiencing high I/O load.)










share|improve this question
























  • It may depend on what video driver and kernel sub-system you are using. Running X.org 2D or 3D acceleration or simple frame buffer? Places like /dev/dri /dev/fbx /dev/mem /dev/nvidia0 and others.

    – jc__
    Feb 12 at 16:03











  • @jc__: I'm using the intel driver - as I noted - and presume this provides 2D and basic 3D accel. I've already had a look at the DRI docs. I noted that /dev/fb0 produced a black image when X is running. I am genuinely curious, do you think /dev/mem might include VRAM? (That would be awesome.) I don't have an Nvidia GPU.

    – i336_
    Feb 12 at 22:48











  • @jc__: Genuinely appreciate the assistance

    – i336_
    Feb 12 at 22:48















0















About 5-20 times a day I am presented with brief visual glitches and heisenbugs caused by race conditions that only occur under high I/O load. These disappear off the screen far too quickly for me to grab a camera in time, so I am looking to find/build a screenshotting/screen-recording tool that acts/responds with the lowest possible delay after I press a hotkey/shortcut.



Critically, this tool's high-responsiveness needs to be negligibly (ideally not at all) impacted by high I/O activity, like 10-second load averages of 20-40.



A fair argument could be made about loading PREEMPT_RT and running Xorg and a homemade screenshot dæmon as realtime. This would work... except for the bit about running X realtime; I actually do want to get work done on my computer. :)



Thing is, I can confidently run any code I like in realtime on my computer, just by putting it inside the Linux kernel. So, kernel module time!! To reiterate my question,



How do I find, access and grok the memory region(s) representing the pixels on my screen, all from within a Linux kernel module?



I've found that trying to read /dev/fb0 while X is running just produces a black image, so that apparently won't work.



Unfortunately https://dri.freedesktop.org/docs/drm/gpu/index.html doesn't show anything obviously related to framebuffer read-back, but I have no experience with this API, so I don't really know what I'm looking for.



I accept that driver-specific code will likely be needed (since there's unlikely a driver-agnostic canonical spot in memory representing what's actually on screen), and this fine. I'm using an Intel-GPU-based machine at the moment, and I am happy to start specifically coding for that.



FWIW, I asked a differently-worded version of this question just under two years ago. That question only attracted one comment about HDCP and was never answered, but as I am still dealing with this problem up to 20 times a day even two years later, I'm having another go.



(My current approach (scrot launched by i3's hotkey binder) very often takes up to 20 (!!) seconds to take a single screenshot on systems experiencing high I/O load.)










share|improve this question
























  • It may depend on what video driver and kernel sub-system you are using. Running X.org 2D or 3D acceleration or simple frame buffer? Places like /dev/dri /dev/fbx /dev/mem /dev/nvidia0 and others.

    – jc__
    Feb 12 at 16:03











  • @jc__: I'm using the intel driver - as I noted - and presume this provides 2D and basic 3D accel. I've already had a look at the DRI docs. I noted that /dev/fb0 produced a black image when X is running. I am genuinely curious, do you think /dev/mem might include VRAM? (That would be awesome.) I don't have an Nvidia GPU.

    – i336_
    Feb 12 at 22:48











  • @jc__: Genuinely appreciate the assistance

    – i336_
    Feb 12 at 22:48













0












0








0








About 5-20 times a day I am presented with brief visual glitches and heisenbugs caused by race conditions that only occur under high I/O load. These disappear off the screen far too quickly for me to grab a camera in time, so I am looking to find/build a screenshotting/screen-recording tool that acts/responds with the lowest possible delay after I press a hotkey/shortcut.



Critically, this tool's high-responsiveness needs to be negligibly (ideally not at all) impacted by high I/O activity, like 10-second load averages of 20-40.



A fair argument could be made about loading PREEMPT_RT and running Xorg and a homemade screenshot dæmon as realtime. This would work... except for the bit about running X realtime; I actually do want to get work done on my computer. :)



Thing is, I can confidently run any code I like in realtime on my computer, just by putting it inside the Linux kernel. So, kernel module time!! To reiterate my question,



How do I find, access and grok the memory region(s) representing the pixels on my screen, all from within a Linux kernel module?



I've found that trying to read /dev/fb0 while X is running just produces a black image, so that apparently won't work.



Unfortunately https://dri.freedesktop.org/docs/drm/gpu/index.html doesn't show anything obviously related to framebuffer read-back, but I have no experience with this API, so I don't really know what I'm looking for.



I accept that driver-specific code will likely be needed (since there's unlikely a driver-agnostic canonical spot in memory representing what's actually on screen), and this fine. I'm using an Intel-GPU-based machine at the moment, and I am happy to start specifically coding for that.



FWIW, I asked a differently-worded version of this question just under two years ago. That question only attracted one comment about HDCP and was never answered, but as I am still dealing with this problem up to 20 times a day even two years later, I'm having another go.



(My current approach (scrot launched by i3's hotkey binder) very often takes up to 20 (!!) seconds to take a single screenshot on systems experiencing high I/O load.)










share|improve this question
















About 5-20 times a day I am presented with brief visual glitches and heisenbugs caused by race conditions that only occur under high I/O load. These disappear off the screen far too quickly for me to grab a camera in time, so I am looking to find/build a screenshotting/screen-recording tool that acts/responds with the lowest possible delay after I press a hotkey/shortcut.



Critically, this tool's high-responsiveness needs to be negligibly (ideally not at all) impacted by high I/O activity, like 10-second load averages of 20-40.



A fair argument could be made about loading PREEMPT_RT and running Xorg and a homemade screenshot dæmon as realtime. This would work... except for the bit about running X realtime; I actually do want to get work done on my computer. :)



Thing is, I can confidently run any code I like in realtime on my computer, just by putting it inside the Linux kernel. So, kernel module time!! To reiterate my question,



How do I find, access and grok the memory region(s) representing the pixels on my screen, all from within a Linux kernel module?



I've found that trying to read /dev/fb0 while X is running just produces a black image, so that apparently won't work.



Unfortunately https://dri.freedesktop.org/docs/drm/gpu/index.html doesn't show anything obviously related to framebuffer read-back, but I have no experience with this API, so I don't really know what I'm looking for.



I accept that driver-specific code will likely be needed (since there's unlikely a driver-agnostic canonical spot in memory representing what's actually on screen), and this fine. I'm using an Intel-GPU-based machine at the moment, and I am happy to start specifically coding for that.



FWIW, I asked a differently-worded version of this question just under two years ago. That question only attracted one comment about HDCP and was never answered, but as I am still dealing with this problem up to 20 times a day even two years later, I'm having another go.



(My current approach (scrot launched by i3's hotkey binder) very often takes up to 20 (!!) seconds to take a single screenshot on systems experiencing high I/O load.)







linux xorg screenshot drm kms






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 12 at 13:01









Rui F Ribeiro

41.2k1481139




41.2k1481139










asked Feb 12 at 12:53









i336_i336_

351317




351317












  • It may depend on what video driver and kernel sub-system you are using. Running X.org 2D or 3D acceleration or simple frame buffer? Places like /dev/dri /dev/fbx /dev/mem /dev/nvidia0 and others.

    – jc__
    Feb 12 at 16:03











  • @jc__: I'm using the intel driver - as I noted - and presume this provides 2D and basic 3D accel. I've already had a look at the DRI docs. I noted that /dev/fb0 produced a black image when X is running. I am genuinely curious, do you think /dev/mem might include VRAM? (That would be awesome.) I don't have an Nvidia GPU.

    – i336_
    Feb 12 at 22:48











  • @jc__: Genuinely appreciate the assistance

    – i336_
    Feb 12 at 22:48

















  • It may depend on what video driver and kernel sub-system you are using. Running X.org 2D or 3D acceleration or simple frame buffer? Places like /dev/dri /dev/fbx /dev/mem /dev/nvidia0 and others.

    – jc__
    Feb 12 at 16:03











  • @jc__: I'm using the intel driver - as I noted - and presume this provides 2D and basic 3D accel. I've already had a look at the DRI docs. I noted that /dev/fb0 produced a black image when X is running. I am genuinely curious, do you think /dev/mem might include VRAM? (That would be awesome.) I don't have an Nvidia GPU.

    – i336_
    Feb 12 at 22:48











  • @jc__: Genuinely appreciate the assistance

    – i336_
    Feb 12 at 22:48
















It may depend on what video driver and kernel sub-system you are using. Running X.org 2D or 3D acceleration or simple frame buffer? Places like /dev/dri /dev/fbx /dev/mem /dev/nvidia0 and others.

– jc__
Feb 12 at 16:03





It may depend on what video driver and kernel sub-system you are using. Running X.org 2D or 3D acceleration or simple frame buffer? Places like /dev/dri /dev/fbx /dev/mem /dev/nvidia0 and others.

– jc__
Feb 12 at 16:03













@jc__: I'm using the intel driver - as I noted - and presume this provides 2D and basic 3D accel. I've already had a look at the DRI docs. I noted that /dev/fb0 produced a black image when X is running. I am genuinely curious, do you think /dev/mem might include VRAM? (That would be awesome.) I don't have an Nvidia GPU.

– i336_
Feb 12 at 22:48





@jc__: I'm using the intel driver - as I noted - and presume this provides 2D and basic 3D accel. I've already had a look at the DRI docs. I noted that /dev/fb0 produced a black image when X is running. I am genuinely curious, do you think /dev/mem might include VRAM? (That would be awesome.) I don't have an Nvidia GPU.

– i336_
Feb 12 at 22:48













@jc__: Genuinely appreciate the assistance

– i336_
Feb 12 at 22:48





@jc__: Genuinely appreciate the assistance

– i336_
Feb 12 at 22:48










0






active

oldest

votes











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f500167%2fhow-do-i-find-the-video-memory-regions-representing-whats-on-my-screen-from%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f500167%2fhow-do-i-find-the-video-memory-regions-representing-whats-on-my-screen-from%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown






Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay