Reducing the response time when transmitting data over UDP

Hello, Habr! In this article, I want to talk about solving one of the common problems that Embox handles better than GNU / Linux. This is the response time to a packet transmitted over the Ethernet protocol. As you know, the main characteristic of data transmission over a network is bandwidth, and GNU / Linux is doing fine with it. But when it comes to reducing the time it takes to receive / transmit a single network packet, problems can arise. In particular, the customer had a DE0-Nano-SoC board with Linux, and with the help of this board I wanted to control a certain object over the network. The network topology is point-to-point, there are no routers and hubs. According to the control model, the reaction time should be less than 100 ΞΌs, and on Linux based it was possible to achieve only 500 ΞΌs.


DE0 Nano SoC kit


To estimate the transmission time, we create a stand consisting of two hosts.


GNU/Linux, β€” DE0-Nano-SoC Kit Embox. FPGA HPS (Hard Processing System, .. ARM), . , UDP- :


while (1) {
    char buf[BUFLEN];

    recvfrom(s, buf, BUFLEN);    
    sendto(s, buf, BUFLEN);
}

, DE0-Nano-SoC.


, :


for (int i = 0; i < N; i++) {
    char buf_tx[BUFLEN], buf_rx[BUFLEN];
    sprintf(buf_tx, "This is packet %d\n", i);

    time_t time_begin = time_now();

    sendto(s, buf_tx, BUFLEN);
    recvfrom(s, buf_rx, BUFLEN);

    time_t time_end = time_now();

    if (memcmp(buf_tx, buf_rx, sizeof(buf))) {
            printf("%d: Buffer mismatch\n", i);
    }

    if (time_end - time_begin > TIME_LIMIT) {
            printf("Slow answer #%d: %d\n", i, time_end - time_begin);
    }
}

, .


Github.


, , :


  • UART β€” ,
  • -O2
  • - PL310 ( )

500 000 ( ) :


Avg: 4.52ms
Min: 3.12ms
Max: 12.24ms

, , β€” . , Linux . , .


, ? , .


, - , , ? β€” .


, ethernet- β€” USB-, 100/, .


1 :


Avg: 0.08ms
Min: 0.07ms
Max: 4.31ms

Linux


Linux. -: arm-linux-gnueabihf-gcc server.c -O2. ELF :


Avg: 0.77ms
Min: 0.74ms
Max: 5.31ms

, Embox "" 9 , !



, "", , .


, , , UDP- .


, UDP-.


, UDP . , . . :


int net_tx(...) {
    if (is_udp_packet()) {
        timestamp2 = timer_get();
        memcpy(packet[UDP_OFFT],
            &timestamp1,
            sizeof(timestamp1));
        memcpy(packet[UDP_OFFT + sizeof(timestamp2)],
            &timestamp2,
            sizeof(timestamp2));
        ...
    }
}

, , , Embox.



Avg: 8673
Min: 6191 
Max: 11950

, ( ) 25%, (Avg: 0.08ms Max: 4.31ms). ( , , , ), . , , 25%.


, ?




β€” Linux, .


?


, β€” :


nice -n -20 ./client


β€” , , .


β€” round robin , chrt:


chrt --rr 99 ./client


β€” . ( , .. ).



Embox , 10 . , , . , Linux, - bpfilter.


- β€” embox-devel@googlegroups.com, -, .


All Articles