OpenQNX :: The QNX Community Portal

May 13, 2008 - 10:46 AM
Google
  Web openqnx.com   
     Create an account Home · Submit News · QNX Forums · QNX Download · Search   
_
Main Menu
Who's Online
There are 59 unlogged users and 0 registered users online.

You can log-in or register for a user account here.

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
xuyong
Post subject: how to improve the efficiency?  PostPosted: May 08, 2008 - 06:34 AM
Senior Member


Joined: Mar 02, 2003
Posts: 277

the structure of my socket programme is below:
while(1)
{
recv(...);
send(...);
usleep(10);
}
the purpose of it is "send" and "receive" data by special period,I found the occupancy of CPU is very HIGH when I use sleep function,Can I change it to improve the efficiency?how to do
 
 View user's profile Send private message  
Reply with quote Back to top
mario
Post subject: RE: how to improve the efficiency?  PostPosted: May 08, 2008 - 01:26 PM
QNX Master


Joined: Sep 01, 2002
Posts: 2667

More info is needed to provide an alternate solution. If the socket is not set to non blocking, this should not take a lot of CPU, unless the functions are returning error code and you aren't checking for them.

The usleep(10) may not do what you thing it's doing. usleep cannot be more precise then the system clock period which is set a 1ms by defaults. A request of 10us will give you in fact 1 ms maybe 2ms.
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
xuyong
Post subject: RE: how to improve the efficiency?  PostPosted: May 09, 2008 - 12:24 AM
Senior Member


Joined: Mar 02, 2003
Posts: 277

yes,I have set the socket to non blocking,because I don't want it blocked when it can't receice or send anything
 
 View user's profile Send private message  
Reply with quote Back to top
mario
Post subject: RE: how to improve the efficiency?  PostPosted: May 09, 2008 - 11:42 AM
QNX Master


Joined: Sep 01, 2002
Posts: 2667

Thinking about it, still should not take that much CPU. Unless there is something in your real code that doesn't show in your pseudo code. A good rule of thumb is never do polling Wink

For tcpip stuff I like to go with a thread and leave the socket in block mode, that way I don't have to use select/ionotify which in my opinion adds a significant overhead compare to a simple recv loop
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2007 The PNphpBB Group
Credits
All logos and trademarks in this site are property of their respective owners. The comments are property of their posters.
Powered by OpenQNX: The QNX Community Portal Site
QNX and the QNX logo are registered trademarks of QNX Software Systems.