AnsweredAssumed Answered

when using mmap,consume too much cpu resources

Question asked by sensarliar on Sep 26, 2016
Latest reply on Sep 26, 2016 by larsc

when we add a mwipcore in our fpga code, add linux driver (device tree ) in image in Picozed.

we start to access this mwipcore very frequently,just to read one register bit, to check the fifo flag is full or not,

so we get the code, to access the register. just like  below.

when we use this function frequently, the CPU usage is very high(>100%).  add some receiving data is lost.

How to reslove it ?

 

      int uio_rd(const char *dev, unsigned int reg_addr, unsigned int* reg_val)
{
    int uio_fd;
    void *uio_addr;
 
    uio_fd = open(dev, O_RDWR);
    if(uio_fd < 1)
    {
        printf("error: invalid uio_fd\n\r");
        return -1;
    }
 
    uio_addr = mmap(NULL, 0x1000, PROT_READ|PROT_WRITE, MAP_SHARED, uio_fd, 0);
 
    *reg_val = *((unsigned *) (uio_addr + reg_addr));
    //printf("r: reg[0x%x] = 0x%x\n\r", reg_addr, *reg_val);
 
    munmap(uio_addr, 0x1000);
    close(uio_fd);
 
    return 0;
}

Outcomes