Skip to content

Setting sync-offset and sync-size has no effect. #129

@Jeason-Hu

Description

@Jeason-Hu

Hi ikwzm,

I encountered a problem where I cannot set the sync-offset and sync-size. The PL writes data cyclically to the physical address range from 0x87B000000 to 0x87F000000, and the address space is split into 16 parts. The device tree is defined as follows:

reserved-memory {  
		#address-cells= <2>;  
		#size-cells= <2>;  
		ranges;  
		run_buffer: run_buffer@0 {  
			compatible = "shared-dma-pool";  
			reusable;  
			reg = <0x00000008 0x7B00000000 0x00000000 0x04000000>;
			label = "run_buffer";  
		}
};
udmabuf@0x00 {
		compatible = "ikwzm,u-dma-buf";
		device-name = "runlength";
		size = <0x04000000>;
		dma-mask = <40>;				// 40bits dma addr
		sync-mode = <2>;				// 
		//sync-offset = <0x00000000>;
		//sync-size = <0x04000000>;
		sync-direction = <2>;			// from device
		quirk-mmap-auto;
		memory-region = <&run_buffer>;	// use cma memory
};

When I directly use system("echo 1 > /sys/class/u-dma-buf/runlength/sync_for_cpu"); to synchronize the entire block of memory, there is no cache consistency problem, but the synchronization time is relatively long.
When I change to calling the previously set sync-offset and sync-size, I encounter cache consistency problems.

		int fd;
		if ((fd = open("/dev/runlength", O_RDWR)) != -1) {
			// sync_size is slice buffer size, frameIdx is slice buffer index
			unsigned long sync_offset    		= frameIdx*RUN_V3_MAX_NUM*sizeof(tRUN_V3);
			unsigned long sync_size      		= RUN_V3_MAX_NUM*sizeof(tRUN_V3);
			unsigned int sync_direction 		= 2;
	        uint64_t sync_for_cpu   = ((uint64_t)(sync_offset    & 0xFFFFFFFF) << 32) |
		                                ((uint64_t)(sync_size      & 0xFFFFFFF0) <<  0) |
										((uint64_t)(sync_direction & 0x00000003) <<  2) |
										0x00000001;

	        ioctl(fd, U_DMA_BUF_IOCTL_SET_SYNC_FOR_CPU, &sync_for_cpu);
	        close(fd);
        }

The same problem occurs when I switch to other interfaces:

	    unsigned int sync_offset    = frameIdx*RUN_V3_MAX_NUM*sizeof(tRUN_V3);
	    unsigned int sync_size      = RUN_V3_MAX_NUM*sizeof(tRUN_V3);
	    unsigned int sync_direction = 2;
	    unsigned int sync_for_cpu = 1;
	    if ((fd  = open("/sys/class/u-dma-buf/runlength/sync_for_cpu", O_WRONLY)) != -1) {
	    	sprintf(attr, "0x%08X%08X", (sync_offset & 0xFFFFFFFF), (sync_size & 0xFFFFFFF0) | (sync_direction << 2) | sync_for_cpu);
	        write(fd, attr, strlen(attr));
	        close(fd);
	    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions