When it comes to data transmission, that is, the journey of data from the host to the line, the following steps are generally required:
The application program must first write the data to be sent into the memory address space of the process. Developers who are familiar with network programming must be very familiar with this link. Generally, in program development, it only requires general runtime variable assignment.
The application program sends a system call to the kernel through the system function library interface (such as send function), and the system kernel performs subsequent operations. It copies the data from the user-state memory area to a memory address space called kernel buffer maintained by the kernel. The size of this address space is usually limited. All data to be sent will enter here in the form of queues. These data may come from multiple processes. Each piece of data has a certain extra mark to mark their destination. If more data is to be sent, the system call needs to be made several times, each time copying a certain data size, which depends on the size of the network data packet and the carrying capacity of the kernel buffer. Repeated system calls are reflected in repeated call of send function at application programming level.
When the data is written into the kernel buffer, the kernel will notify the NIC controller to fetch the data while the CPU switches to other processes. After receiving the notification, the NIC controller learns the address of the corresponding kernel buffer according to the NIC driver information, and copies the data to be sent to the NIC buffer. Note that in the above series of data copying, the data is always copied according to the internal bus width of the devices connected to both ends, i.e. an integer multiple of bytes. For example, in a 32-bit bus host system, a network card using PCI-X bus interface generally uses a 32-bit bus width, so only 32-bit bit information can be copied at any time during the data copying process from the kernel buffer to the network card buffer.
The data in the network card buffer needs to be sent to the line, and the buffer is released at the same time to obtain more data to be sent. However, we know that only binary digital signals can be transmitted in the line, so data needs to be converted into bytes in place at this time. This kind of conversion is not difficult to imagine, that is, each bit of data is sent out in sequence.
When sending, the network card will use specific internal physical devices to generate various signals that can be transmitted. For example, when using copper wire, the network card will generate different electrical signals according to the changes of “0” and “1”; When using optical fiber line, the network card will generate different optical signals.