Why are nanosleep () and usleep () too slow?

I have a program that generates packets to send to the receiver. I need an effective method of introducing a slight delay between sending each packet so as not to intercept the receiver. I tried usleep () and nanosleep (), but they seem too slow. I implemented a closed wait loop and had more success, but this is not the most efficient method I know. I am interested in any experience in trying to do what I do. Do others find usleep () and nanosleep () to work well for this type of application?

Thank,

Danny Llewaln

+3
source share
5 answers

.

"" ​​(CONFIG_NO_HZ) , , , .

. (CONFIG_HZ) - , 10 , 4 , 3,3 1 .

+8

. , , . , , .

, , , () .

+2

, , , , / NOP- .

A NOP , , _NOP() , , nops.

regTX = 0xFF;  // Transmit FF on special register

// Wait three clock cycles
_NOP();
_NOP();
_NOP();

regTX = 0x00; // Transmit 00
+2

Solaris , . 10 , , usleep. , hires_tick = 1 (1 ) hires_hz = /etc/system, .

0

, , , . TCP ? TCP , .

If you have already invested a lot in the packetized approach, you can always use a layer on top of TCP to extract the original data packets from the TCP stream and transfer them to existing functions.

-1
source

Source: https://habr.com/ru/post/1747371/


All Articles