Re: [PATCH] Microoptimization of lib/poll.c

2008-08-06 Thread Paolo Bonzini
3) access to thread-local errno is slow, it's also better to cache it. Pheww! That is micro-optimization indeed. Well, thread-local errno might involve a function call on some systems. If the function call is not CSE'd by the compiler, it means half a dozen function calls. Do you have

Re: [PATCH] Microoptimization of lib/poll.c

2008-08-06 Thread Bruno Haible
Paolo Bonzini wrote: > I actually noticed these in a profile! What tool do you use for doing profiling on a per-line or per-instruction basis? The Google profiler? > 3) access to thread-local errno is slow, it's also better to cache it. Pheww! That is micro-optimization indeed. Do you have an o

Re: [PATCH] Microoptimization of lib/poll.c

2008-08-06 Thread Paolo Bonzini
#ifdef _SC_OPEN_MAX - if (nfd > sysconf (_SC_OPEN_MAX)) + static int sc_open_max = -1; + + if (nfd < 0 + || (nfd > sc_open_max + && (sc_open_max != -1 + || nfd > (sc_open_max = sysconf (_SC_OPEN_MAX) Doesn't this make poll non-reentrant? Are there systems wher

Re: [PATCH] Microoptimization of lib/poll.c

2008-08-06 Thread Ralf Wildenhues
Hi Paolo, * Paolo Bonzini wrote on Wed, Aug 06, 2008 at 10:28:00AM CEST: > --- a/lib/poll.c > +++ b/lib/poll.c > #ifdef _SC_OPEN_MAX > - if (nfd > sysconf (_SC_OPEN_MAX)) > + static int sc_open_max = -1; > + > + if (nfd < 0 > + || (nfd > sc_open_max > + && (sc_open_max != -1 > +

[PATCH] Microoptimization of lib/poll.c

2008-08-06 Thread Paolo Bonzini
I actually noticed these in a profile! 1) sysconf (_SC_OPEN_MAX) is slow, it's better to cache it. 2) division by 1000 is slow, and in my code the timeout was always 0. 3) access to thread-local errno is slow, it's also better to cache it. Ciao, Paolo 2008-08-06 Paolo Bonzini <[EMAIL PROTEC