From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: To: 9fans@cse.psu.edu Subject: Re: [9fans] trace.c From: "Skip Tavakkolian" In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Date: Wed, 28 Jan 2004 00:13:08 -0800 Content-Transfer-Encoding: quoted-printable Topicbox-Message-UUID: c2ef6b6c-eacc-11e9-9e20-41e7f4b1d025 > (hmm, i guess the above _is_ the man page ;-)). Also realtime(3) is not there. BTW, I played with it when it first appeared (2002?) and couldn't work it right, probably due to my incorrect understanding. I was trying to write a deterministic cat for copying CD audio files to /dev/audio on a slow machine (K6-166Mhz). Regular cat results in a periodic chop, which I assumed (wild guess more like it) was buffer underrun. I think there was an example in the manpage too but a few more would have been nice. Anyhow, here is the rtcat.c which I couldn't make work. I don't remember a thing about the details now. ------------------ rtcat.c --- DOESN'T WORK ------------- #include #include char * T =3D "10s"; /* the period between releases */ char * D =3D "5s"; /* deadline before we must start (within T) */ char * C =3D "1.5s"; /* time we have to do our work */ int verbose, debug, tset, dset, cset; char *clonedev =3D "#R/realtime/clone"; /* we've got to read /dev/volume and look for speed attribute. then we read the /dev/audiostat to get the buffer size for causing DMA. Then we use this formula to calculate the period (T) for this function: Ex. 'speed 44100' would yeild: T =3D 1 =C3=B7 (($speed =C3=97 16) =C3=B7 ((1024 =C3=97 8)) OR 1 =C3=B7= (($speed =C3=97 2) =C3=B7 1024)) C =3D How long to run? D =3D T - C */ void rtcat(int f, char *s) { char buf[44100 * 2]; /* bytes: actually (44100=C3=9716)=C3=B78 */ long n; int fd; if ((fd =3D open(clonedev, ORDWR)) < 0) sysfatal("%s: %r", clonedev); if (fprint(fd, "T=3D%s D=3D%s C=3D%s procs=3D%d resources=3D admit", T,= D,C,getpid()) < 0) sysfatal("%s: admit: %r", clonedev); for (;;) { if ((n=3Dread(f, buf, (long)sizeof buf))>0) { if(write(1, buf, n)!=3Dn) sysfatal("write error copying %s: %r", s); if (fprint(fd, "yield") < 0) sysfatal("%s: yield: %r", clonedev); } else if(n < 0) { sysfatal("error reading %s: %r", s); } else { break; } } if (fprint(fd, "remove") < 0) sysfatal("%s: remove: %r", clonedev); close(fd); } static void usage(void) { fprint(2, "Usage: %s [-T period] [-D deadline] [-C cost] [-v]\n", argv0)= ; exits(nil); } void main(int argc, char *argv[]) { int f, i; /* ARGBEGIN { case 'T': T =3D EARGF(usage()); tset++; break; case 'D': D =3D EARGF(usage()); dset++; break; case 'C': C =3D EARGF(usage()); cset++; break; case 'v': verbose++; break; case 'd': debug++; break; default: usage(); } ARGEND; if (tset && !dset) D =3D T; */ argv0 =3D "rtcat"; if(argc =3D=3D 1) rtcat(0, ""); else for(i=3D1; i