new lsub nix patch: nsec

7 views
Skip to first unread message

Fco. J. Ballesteros

unread,
Apr 15, 2012, 6:07:03 AM4/15/12
to nix...@googlegroups.com, ne...@lsub.org
http://lsub.org/magic/webls?dir=/nixpatch/nsec


cleanup nsec not to cache anything.
files:
/sys/src/libc/9sys/nsec.c nsec.c
removed:

/sys/src/libc/9sys/nsec.c:
nsec.c.orig:19,24 d nsec.c:18
< static int fd = -1;
< static struct {
< int pid;
< int fd;
< } fds[64];
<
nsec.c.orig:30 c nsec.c:24
< int pid, i, f, tries;
---
> int f;
nsec.c.orig:32,74 c nsec.c:26,33
< /*
< * Threaded programs may have multiple procs
< * with different fd tables, so we may need to open
< * /dev/bintime on a per-pid basis
< */
<
< /* First, look if we've opened it for this particular pid */
< pid = _tos->pid;
< do{
< f = -1;
< for(i = 0; i < nelem(fds); i++)
< if(fds[i].pid == pid){
< f = fds[i].fd;
< break;
< }
< tries = 0;
< if(f < 0){
< /* If it's not open for this pid, try the global pid */
< if(fd >= 0)
< f = fd;
< else{
< /* must open */
< if((f = open("/dev/bintime", OREAD|OCEXEC)) < 0)
< return 0;
< fd = f;
< for(i = 0; i < nelem(fds); i++)
< if(fds[i].pid == pid || fds[i].pid == 0){
< fds[i].pid = pid;
< fds[i].fd = f;
< break;
< }
< }
< }
< if(pread(f, b, sizeof b, 0) == sizeof b){
< be2vlong(&t, b);
< return t;
< }
< close(f);
< if(i < nelem(fds))
< fds[i].fd = -1;
< }while(tries++ == 0); /* retry once */
< USED(tries);
< return 0;
---
> f = open("/dev/bintime", OREAD);
> if(f < 0)
> return 0;
> t = 0;
> if(pread(f, b, sizeof b, 0) == sizeof b)
> be2vlong(&t, b);
> close(f);
> return t;

erik quanstrom

unread,
Apr 15, 2012, 1:02:42 PM4/15/12
to nix...@googlegroups.com
lgtm.

also there was a lot of back-and-forth about timing
and time bases. i'd like to gather up something concrete
that allows for
- arch independent interface
- nanosecond resolution timing
- known precision.
- unspecified units & post division.
- maximum range ~ ±2 years.

perhaps
vlong tsprec()
vlong ts(void);
vlong tstonsec();

i realize the cool thing to do these days is to parameterize everything,
but i just spent a few days suffering a set of bugs that was caused by changing
the parameterized type in a non-obvious way, and with no easy way to
revert, it was a real mess. i don't see why vlong can't be good enough.

- erik

Nemo

unread,
Apr 15, 2012, 1:07:06 PM4/15/12
to nix...@googlegroups.com
yes. I think I agree.


;; patch/Apply nsec
applying to /n/src/nix...
/dist/patch/nsec
merge...backup...copy...
cpfile nsec.c /n/dist/sys/src/libc/9sys/nsec.c
done

Charles Forsyth

unread,
Apr 15, 2012, 1:11:15 PM4/15/12
to nix...@googlegroups.com
It isn't just cool, it's because having to wade through years later working out
just how big each and every ulong needs to be (or what it really represents)
remains as tedious as it was going from 6th to 7th Edition  (in a smaller source).

erik quanstrom

unread,
Apr 15, 2012, 1:15:07 PM4/15/12
to charles...@gmail.com, nix...@googlegroups.com
On Sun Apr 15 13:11:36 EDT 2012, charles...@gmail.com wrote:

> It isn't just cool, it's because having to wade through years later working
> out
> just how big each and every ulong needs to be (or what it really represents)
> remains as tedious as it was going from 6th to 7th Edition (in a smaller
> source).

i wasn't alluding to anything in the plan 9 or nix kernel, but
rather some recent mistakes in ken's kernel such as Timet ticks
(Timet is long) replacing ulong ticks.

- erik

Reply all
Reply to author
Forward
0 new messages