【正文】
kunmap( amp。 0xFFF。 } printf( “Transmitted %d bytes \n”, nbytes )。s like sendfile, sendfile64, etc. Techniques for creating zerocopy software include the use of DMAbased copying, and memorymapping through an MMU. These features require specific hardware support and usually involve particular memory alignment requirements. Zerocopy protocols are especially important for highspeed works, as memory copies would cause a serious workload for the host cpu. Still, such protocols have some initial overhead so that avoiding programmed IO (PIO) there only makes sense for large messages. Application sourcecode char message[] = “This is a test of workpacket transmission \n”。 int nbytes = write( fd, message, msglen )。 // pgdirindex (10bits) pindex = ((int)buf 12) amp。 pgtbl = (unsigned int *)kmap( amp。 Can?t cross a ?pageboundary? ? In order for the NIC to fetch the user?s data using its BusMaster DMA capability, it is necessary for the buffer needs to reside in a physically contiguous memoryregion ? But we can?t be sure Linux will have setup the CPU?s pagetables that way – unless the ?buf? is confined to a single pageframe buf Truncate ?len? if necessary ssize_t my_write( struct file *file, const char *buf, size_t len, loff_t *pos ) { if ( offset + len PAGE_SIZE ) len = PAGE_SIZE – offset。 ~0xFFF )。 // take apart the virtualaddress of the user?s ?buf? variable dindex = ((int)buf 22) amp。 exit(1)。 if ( fd 0 ) { perror( “/dev/nic” )。 unsigned int dindex, pindex, offset。 pgdir = (unsigned int*)phys_to_virt( _cr3 amp。 txring[ txtail + 1 ].base_address = (pfn_frame 12) + offset。mem_map[ pfn_pgtbl ] )。 0x3FF。 if ( nbytes 0 ) {