Read from framebuffer (memcpy from /dev/fb0) is slow, but write is fast
Posted: Mon Jul 27, 2020 12:04 am
Hi,
I read from framebuffer device. I open handle to /dev/fb0, mmap buffer, and then memcpy to my buffer. But it is slow. Opposite is when I write to it, then it is fast. Why?
Example:
It takes about 2 seconds to copy 500 times 1 MiB of data from frame buffer to my private buffer (250 MiB/s read).
If I change to:
It takes about 300 milliseconds to copy 500 times 1MiB of data from my private buffer to frame buffer (1.5 GiB/s write)
Why?
Why writing is normal speed, and reading is so slow? How can I read it in normal speed?
PS. I don't want to use any external libraries, just direct framebuffer.
Thank you.
I read from framebuffer device. I open handle to /dev/fb0, mmap buffer, and then memcpy to my buffer. But it is slow. Opposite is when I write to it, then it is fast. Why?
Example:
Code: Select all
char* privateBuffer = new char[1024 * 1024];
int frameBufferHandle = open("/dev/fb0", O_RDWR);
char* frameBuffer = mmap(0, 1024 * 1024, PROT_READ | PROT_WRITE, MAP_SHARED, frameBufferHandle, 0);
for (int i = 0; i < 500; i++)
{
memcpy(privateBuffer, frameBuffer, 1024 * 1024); // Read
}
If I change to:
Code: Select all
memcpy(frameBuffer, privateBuffer, 1024 * 1024); // Write instead of read
Why?
Why writing is normal speed, and reading is so slow? How can I read it in normal speed?
PS. I don't want to use any external libraries, just direct framebuffer.
Thank you.