select(0,NULL,NULL,NULL,&t1) used for delay

select(0,NULL,NULL,NULL,&t1) used for delay

Post by Madhu K.S » Fri, 07 Oct 2005 22:50:10


Hi all,


In many application we use select() system call for delay.

example:
select(0,NULL,NULL,NULL,&t1);


select() for delay is very inefficient. I modified sys_select() code for
efficiency .Here are the changes to fs/select.c.

Please suggest on these changes.

I know nanosleep() can be used instead of select(), but please suggest
on my changes.


file : fs/select.c
function : sys_select()




timeout += sec * (unsigned long) HZ;
}
}
-
+
+
ret = -EINVAL;
if (n < 0)
goto out_nofds;
-
+ if ( (n == 0) && (inp == NULL) && (outp == NULL) &&
(exp== NULL)){
+ printf("\n I am inside new select condition timeout
%d\n",timeout);
+ set_current_state(TASK_INTERRUPTIBLE);
+ ret = 0;
+ timeout = schedule_timeout(timeout);
+ if (signal_pending(current))
+ ret = -ERESTARTNOHAND;
+ if (tvp && !(current->personality & STICKY_TIMEOUTS)) {
+ time_t sec = 0, usec = 0;
+ if (timeout) {
+ sec = timeout / HZ;
+ usec = timeout % HZ;
+ usec *= (1000000/HZ);
+ }
+ put_user(sec, &tvp->tv_sec);
+ put_user(usec, &tvp->tv_usec);
+ }
+ current->state = TASK_RUNNING;
+ goto out_nofds;
+ }
+
/* max_fdset can increase, so grab it once to avoid race */
max_fdset = current->files->max_fdset;
if (n > max_fdset)



Thank you very much.
Thanks for your assistances.

Madhu K.S.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to XXXX@XXXXX.COM
More majordomo info at http://www.yqcomputer.com/
Please read the FAQ at http://www.yqcomputer.com/
 
 
 

select(0,NULL,NULL,NULL,&t1) used for delay

Post by Jesper Juh » Fri, 07 Oct 2005 23:30:08


A few tiny comments below.


Submitting an actual applyable patch is preferred. Makes it possible
to easily apply your changes to test the changes and then the file and
function is also part of the patch so you won't have to spell that out
explicitly.
Use diff -up

No space for the beginning parenthesis and space before the opening
bracket is preferred:
if ((n == 0) && (inp == NULL) && (outp == NULL) &&
(exp== NULL)) {


Having a printk() here certainly won't help performance.

Wouldn't it make sense to jump out at this point if there's a signal pending?
if (signal_pending(current)) {
ret = -ERESTARTNOHAND;
goto out;
}
Or am I missing something?

Small style thing: usec *= (1000000 / HZ);


[snip]

Jesper Juhl < XXXX@XXXXX.COM >
Don't top-post http://www.yqcomputer.com/ ~esr/jargon/html/T/top-post.html
Plain text mails only, please http://www.yqcomputer.com/
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to XXXX@XXXXX.COM
More majordomo info at http://www.yqcomputer.com/
Please read the FAQ at http://www.yqcomputer.com/

 
 
 

select(0,NULL,NULL,NULL,&t1) used for delay

Post by Alex Riese » Fri, 07 Oct 2005 23:30:13


Why don't you just use nanosleep(2) (or usleep)?
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to XXXX@XXXXX.COM
More majordomo info at http://www.yqcomputer.com/
Please read the FAQ at http://www.yqcomputer.com/
 
 
 

select(0,NULL,NULL,NULL,&t1) used for delay

Post by Jesper Juh » Fri, 07 Oct 2005 23:30:15


[snip]
Ohh and the parenthesis are not needed.
usec *= 1000000 / HZ;

[snip]
Jesper Juhl < XXXX@XXXXX.COM >
Don't top-post http://www.yqcomputer.com/ ~esr/jargon/html/T/top-post.html
Plain text mails only, please http://www.yqcomputer.com/
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to XXXX@XXXXX.COM
More majordomo info at http://www.yqcomputer.com/
Please read the FAQ at http://www.yqcomputer.com/
 
 
 

select(0,NULL,NULL,NULL,&t1) used for delay

Post by Christophe » Sat, 08 Oct 2005 00:30:27


I can think of one main reason...existing code. Also, nanosleep()
rounds up excessively in many kernel versions, so that a request to
sleep for less than 1 tick ends up sleeping for 2 ticks.

The select() man page explicitly mentions this usage;

"Some code calls select with all three sets empty, n zero, and a
non-null timeout as a fairly portable way to sleep with subsecond
precision."

Chris

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to XXXX@XXXXX.COM
More majordomo info at http://www.yqcomputer.com/
Please read the FAQ at http://www.yqcomputer.com/
 
 
 

select(0,NULL,NULL,NULL,&t1) used for delay

Post by Bernd Petr » Sat, 08 Oct 2005 00:51:06


And it's cooler to hack the kernel than to create and use a
portable_sleep() function and use it.

^^^^^^^

^^^^^^^^^
^^^^^^^^^

You do realize that "subsecond precision" is probably meant as
improvement to sleep(3) and surely not to nanosleep(2)?

Bernd
--
Firmix Software GmbH http://www.yqcomputer.com/
mobil: +43 664 4416156 fax: +43 1 7890849-55
Embedded Linux Development and Services

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to XXXX@XXXXX.COM
More majordomo info at http://www.yqcomputer.com/
Please read the FAQ at http://www.yqcomputer.com/
 
 
 

select(0,NULL,NULL,NULL,&t1) used for delay

Post by Bob Copela » Sat, 08 Oct 2005 02:40:47

> The select() man page explicitly mentions this usage;

Perl's documentation also notes it as one of the many ways to do a
subsecond sleep:


TMTOWTDI.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to XXXX@XXXXX.COM
More majordomo info at http://www.yqcomputer.com/
Please read the FAQ at http://www.yqcomputer.com/
 
 
 

select(0,NULL,NULL,NULL,&t1) used for delay

Post by Christophe » Sat, 08 Oct 2005 02:41:04


If there is a substantial codebase using select() for sleeping, then it
makes sense to improve the efficiency of the kernel. Fix it in one
place, make all the apps run better.


select() allows for the selection of sleep time with microsecond
precision. The mainline kernel can't sleep for that small an interval
anyway, so there's not really any difference in sleep precision between
the two.

As I mentioned earlier, select() actually sleeps more accurately than
nanosleep() on many kernels. I haven't tested the most recent to see if
this is still true though.

Chris
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to XXXX@XXXXX.COM
More majordomo info at http://www.yqcomputer.com/
Please read the FAQ at http://www.yqcomputer.com/
 
 
 

select(0,NULL,NULL,NULL,&t1) used for delay

Post by Howard Ch » Sat, 08 Oct 2005 04:10:24


Insert obligatory joke about optimizing delay loops... ?

--
-- Howard Chu
Chief Architect, Symas Corp. http://www.yqcomputer.com/
Director, Highland Sun http://www.yqcomputer.com/
OpenLDAP Core Team http://www.yqcomputer.com/

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to XXXX@XXXXX.COM
More majordomo info at http://www.yqcomputer.com/
Please read the FAQ at http://www.yqcomputer.com/
 
 
 

select(0,NULL,NULL,NULL,&t1) used for delay

Post by Christophe » Sat, 08 Oct 2005 04:50:18


It's not a delay if there's a signal pending.

Chris
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to XXXX@XXXXX.COM
More majordomo info at http://www.yqcomputer.com/
Please read the FAQ at http://www.yqcomputer.com/
 
 
 

select(0,NULL,NULL,NULL,&t1) used for delay

Post by Bill David » Wed, 12 Oct 2005 03:10:10


I think the answers here are (a) because there's an existing code base,
and (b) as long as the functionality is required it might as well be
provided optimally. If tou're going to do something at all, do it right.

--
-bill davidsen ( XXXX@XXXXX.COM )
"The secret to procrastination is to put things off until the
last possible moment - but no longer" -me
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to XXXX@XXXXX.COM
More majordomo info at http://www.yqcomputer.com/
Please read the FAQ at http://www.yqcomputer.com/