nanosleep() replacement Take 2
Ben Lindstrom
mouring at etoh.eviladmin.org
Tue Mar 18 11:14:25 EST 2003
Mostly -l was designed to allow people to restrict their scp so it does
not take over their bandwidth (mainly dialup and low-end DSL). The
example was given was a long download that you don't care when it
finishes, just you don't want to choke your small pipe while doing it.
So I doubt it being 100% perfect is a major deal on some platforms.
- Ben
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.
>
> 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);
> }
>
> --
> Darren Tucker (dtucker at zip.com.au)
> GPG Fingerprint D9A3 86E9 7EEE AF4B B2D4 37C9 C982 80C7 8FF4 FA69
> Good judgement comes with experience. Unfortunately, the experience
> usually comes from bad judgement.
>
> _______________________________________________
> openssh-unix-dev mailing list
> openssh-unix-dev at mindrot.org
> http://www.mindrot.org/mailman/listinfo/openssh-unix-dev
>
More information about the openssh-unix-dev
mailing list