nanosleep() replacement Take 2
Tim Rice
tim at multitalents.net
Tue Mar 18 10:58:53 EST 2003
On Tue, 18 Mar 2003, Darren Tucker wrote:
> Gert Doering wrote:
> > Tested on SCO OSR 3.0. openssh-current (as of right now) with your
> > appended patch. Configures, compiles, and "scp -l <number>" seems to
> > do things that correlate with the specified number (I assume it's
> > kbit/second and the progress bar is Kbyte/second).
>
> Yes that's the case.
>
> > -l is fairly unprecise, but this is likely due to a fairly slow machine,
> > select()/scheduler granularity, and other things eating CPU.
>
> I saw that too with Tim's function but I was able to get pretty good
> results (5% variance or less from specified bandwidth) on a somewhat
> loaded 170 MHz SPARC.
>
> I suspect there's some cases it doesn't handle correctly (I'm trying to
> find an example).
>
> Would you mind trying the following function for comparison?
>
> -Daz.
Something isn't quite right with this version.
When I try this I get
...
scp -l 512 openssh/sshd.o uw711:/tmp
sshd.o 100% 84KB 84.1KB/s 00:01
scp -l 256 openssh/sshd.o uw711:/tmp
sshd.o 100% 84KB 42.0KB/s 00:02
scp -l 128 openssh/sshd.o uw711:/tmp
sshd.o 100% 84KB 42.0KB/s 00:02
scp -l 64 openssh/sshd.o uw711:/tmp
sshd.o 100% 84KB 42.0KB/s 00:02
scp -l 8 openssh/sshd.o uw711:/tmp
sshd.o 100% 84KB 42.0KB/s 00:02
scp -l 1 openssh/sshd.o uw711:/tmp
sshd.o 100% 84KB 42.0KB/s 00:02
...
>
> int nanosleep(const struct timespec *req, struct timespec *rem)
> {
> int rc;
> extern int errno;
> int saverrno;
> struct timeval tstart, tstop, tremain, time2wait;
>
> TIMESPEC_TO_TIMEVAL(&time2wait, req)
>
> gettimeofday(&tstart, NULL);
> rc = select(0, NULL, NULL, NULL, &time2wait);
> saverrno = errno;
> gettimeofday (&tstop, NULL);
>
> tremain.tv_sec = tstop.tv_sec - tstart.tv_sec - time2wait.tv_sec;
> tremain.tv_usec = tstop.tv_usec - tstart.tv_usec -
> time2wait.tv_usec;
> tremain.tv_sec += tremain.tv_usec / 1000000L;
> tremain.tv_usec %= 1000000L;
> TIMEVAL_TO_TIMESPEC(&tremain, rem)
>
> if (rc < 0) {
> rc = -1;
> errno = saverrno;
> }
> return(rc);
> }
>
>
--
Tim Rice Multitalents (707) 887-1469
tim at multitalents.net
More information about the openssh-unix-dev
mailing list