bill.connelly
Posts: 6
Joined: Wed Jan 29, 2014 12:20 pm

Unpredictable timing with ioctl - mailboxes and double buffering

Fri Aug 16, 2019 5:38 am

To flip the frame buffer, I am updating the mailbox virtual offset with a function like this:

Code: Select all

int flip_buffer(int buffer_num, fb_config fb0){
        int fd = open("/dev/vcio",0);
        if(fd == -1){
                perror("VCIO OPEN ERROR: ");
                return 1;
        }

        volatile uint32_t property[32] __attribute__((aligned(16))) =
        {
        0x00000000,//Buffer size in bytes
        0x00000000,//Request / Response code
        0x48009, //TAG: set vir offset
        8,
        8,
        0,//x offset
        0,//y offset
        0
        };
        property[0] = 8*sizeof(property[0]);
        if(buffer_num != 0){
                property[6] = fb0.height;
        }
        //send request via property interface using ioctl

        if(ioctl(fd, _IOWR(100, 0, char *), property) == -1){
                perror("BUFFER FLIP IOCTL ERROR");
        }

        close(fd);
        return 0
}
In order to synchronize with vsync I have tried

Code: Select all

flip_buffer(buffer, fb0);
ioctl(fb0.framebuffer, FBIO_WAITFORVSYNC, &dummy);
or in the opposite order

Code: Select all

ioctl(fb0.framebuffer, FBIO_WAITFORVSYNC, &dummy);
flip_buffer(buffer, fb0);
However, I have found that when I perform the second of those two (FBIO wait for vsync then flip bluffer) the behaviour of the this line

Code: Select all

        if(ioctl(fd, _IOWR(100, 0, char *), property) == -1){
         
Is odd. Sometimes it executes in a few microseconds, sometmes taking several milliseconds, and screwing up the timings.

I've tried going through the code for ioctl but I can't understand it. Any reason why the order of the operations, re FBIO_WAITFORVSYNC and updating the mailbox should cause one function to hang for so long?

Return to “C/C++”