do_select() improvement ...
This patch can improve do_select() ==> select() performance due :
1) the load from the fd bitmap is done every __NFDBITS instead of every bit. If You look at the BITS() macro You'll see that it's not cheap in terms of memory operations
2) if a sequential hole of __NFDBITS is found it'll be skipped without doing a bit by bit check
*** select.orig.c Thu Jun 21 08:52:04 2001
--- select.c Thu Jun 21 12:09:25 2001
***************
*** 164,171 ****
--- 164,172 ----
{
poll_table table, *wait;
int retval, i, off;
long __timeout = *timeout;+ unsigned long bits;
read_lock(¤t->files->file_lock);
retval = max_select_fd(n, fds);
read_unlock(¤t->files->file_lock);
***************
*** 186,194 ****
unsigned long mask;
struct file *file;
off = i / __NFDBITS;
! if (!(bit & BITS(fds, off)))
continue;
file = fget(i);
mask = POLLNVAL;
if (file) {
--- 187,202 ----
unsigned long mask;
struct file *file;
off = i / __NFDBITS;! if (!(i & (__NFDBITS - 1))) {
! bits = BITS(fds, off);
! if (!bits) {
! i += __NFDBITS;
! continue;
! }
! }
! if (!(bit & bits))
continue;
file = fget(i);
mask = POLLNVAL;
if (file) {- Davide
*** select.orig.c Thu Jun 21 08:52:04 2001
--- select.c Thu Jun 21 12:09:25 2001
***************
*** 164,171 ****
--- 164,172 ----
{
poll_table table, *wait;
int retval, i, off;
long __timeout = *timeout;
+ unsigned long bits;
read_lock(¤t->files->file_lock);
retval = max_select_fd(n, fds);
read_unlock(¤t->files->file_lock);
***************
*** 186,194 ****
unsigned long mask;
struct file *file;
off = i / __NFDBITS;
! if (!(bit & BITS(fds, off)))
continue;
file = fget(i);
mask = POLLNVAL;
if (file) {
--- 187,202 ----
unsigned long mask;
struct file *file;
off = i / __NFDBITS;
! if (!(i & (__NFDBITS - 1))) {
! bits = BITS(fds, off);
! if (!bits) {
! i += __NFDBITS;
! continue;
! }
! }
! if (!(bit & bits))
continue;
file = fget(i);
mask = POLLNVAL;
if (file) {
Quoted 7 lines · On 21-Jun-2001 Davide Libenzi wrote:
off = i / __NFDBITS;! if (!(i & (
__NFDBITS- 1))) {
! bits =BITS(fds, off);
! if (!bits) {
! i +=__NFDBITS;
! continue;
! }
This is wrong.
Quoted 7 lines
off = i / __NFDBITS;! if (!(i & (
__NFDBITS- 1))) {
! bits =BITS(fds, off);
! if (!bits) {
! i +=__NFDBITS- 1;
! continue;
! }
This is right.
- Davide
select.c renamed from select.orig.c +9 -1
@@ -165,6 +165,7 @@poll_table table, *wait;int retval, i, off;long __timeout = *timeout; +unsigned long bits;read_lock (¤t->files->file_lock); retval =max_select_fd (n, fds);
@@ -187,7 +188,14 @@struct file *file; off = i / __NFDBITS; -if (!(bit &BITS (fds, off))) +if (!(i & (__NFDBITS -1 ))) { + bits =BITS (fds, off); +if (!bits) { + i += __NFDBITS -1 ; +continue ; + } + } +if (!(bit & bits))continue ; file =fget (i); mask =POLLNVAL ;