From: "Skip Tavakkolian" <fst@centurytel.net>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] trace.c
Date: Wed, 28 Jan 2004 00:13:08 -0800 [thread overview]
Message-ID: <b09f0f2486775560c2ec37ad9213e0bb@centurytel.net> (raw)
In-Reply-To: <d43d860f1c84bd4a71dada98076fa2d4@plan9.bell-labs.com>
> (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 <u.h>
#include <libc.h>
char * T = "10s"; /* the period between releases */
char * D = "5s"; /* deadline before we must start (within T) */
char * C = "1.5s"; /* time we have to do our work */
int verbose, debug, tset, dset, cset;
char *clonedev = "#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 = 1 ÷ (($speed × 16) ÷ ((1024 × 8)) OR 1 ÷ (($speed × 2) ÷ 1024))
C = How long to run?
D = T - C
*/
void
rtcat(int f, char *s)
{
char buf[44100 * 2]; /* bytes: actually (44100×16)÷8 */
long n;
int fd;
if ((fd = open(clonedev, ORDWR)) < 0)
sysfatal("%s: %r", clonedev);
if (fprint(fd, "T=%s D=%s C=%s procs=%d resources= admit", T,D,C,getpid()) < 0)
sysfatal("%s: admit: %r", clonedev);
for (;;) {
if ((n=read(f, buf, (long)sizeof buf))>0) {
if(write(1, buf, n)!=n)
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 = EARGF(usage());
tset++;
break;
case 'D':
D = EARGF(usage());
dset++;
break;
case 'C':
C = EARGF(usage());
cset++;
break;
case 'v':
verbose++;
break;
case 'd':
debug++;
break;
default:
usage();
}
ARGEND;
if (tset && !dset) D = T;
*/
argv0 = "rtcat";
if(argc == 1)
rtcat(0, "<stdin>");
else for(i=1; i<argc; i++) {
f = open(argv[i], OREAD);
if(f < 0)
sysfatal("can't open %s: %r", argv[i]);
else{
rtcat(f, argv[i]);
close(f);
}
}
exits(0);
}
next prev parent reply other threads:[~2004-01-28 8:13 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-01-27 19:48 mirtchov
2004-01-27 19:58 ` Peter Bosch
2004-01-28 8:13 ` Skip Tavakkolian [this message]
2004-01-28 10:46 ` Bruce Ellis
2004-01-28 13:06 ` boyd, rounin
2004-01-28 13:00 ` Sape Mullender
2004-01-28 15:52 ` Rob Pike
2004-01-28 16:21 ` Sape Mullender
2004-01-29 1:48 ` Geoff Collyer
2004-01-29 1:56 ` Peter Bosch
2004-01-29 2:34 ` Geoff Collyer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b09f0f2486775560c2ec37ad9213e0bb@centurytel.net \
--to=fst@centurytel.net \
--cc=9fans@cse.psu.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).