|
http://lkml.org/lkml/1998/7/29/45 FPU benchmark: #include <stdio.h> #include <sys/types.h> #include <signal.h> int pipe1[2]; int pipe2[2]; int *my_input, *my_output; int parent_fp = 0; int child_fp = 0;
static void
context_switch(void) {
char buf;
if (read(*my_input, &buf, 1) != 1) {
perror("read");
exit(1);
}
if (write(*my_output, &buf, 1) != 1) {
perror("write");
exit(1);
}
}
void
child_process(void) {
float tmp;
if (child_fp) tmp = 1.0;
my_input = &pipe1[0];
my_output = &pipe2[1];
printf("child_fp = %d.\n", child_fp);
fflush(stdout);
for(;;) {
if (child_fp) {
tmp = tmp * 1.00001;
}
context_switch( );
}
if (child_fp) printf ("child tmp = %f.\n", tmp);
fflush(stdout);
}
int
parent_process(int child, int count) {
float tmp;
if (parent_fp) tmp = 1.0;
my_input = &pipe2[0];
my_output = &pipe1[1];
printf("parent_fp = %d.\n", parent_fp);
fflush(stdout);
if (write (*my_output, "x", 1) < 0) { /* prevent deadlock */
perror ("initial write");
exit(1);
}
while(count-- > 0) {
if (parent_fp) {
tmp = tmp * 1.00001;
}
context_switch();
}
if (parent_fp) printf ("parent tmp = %f\n", tmp);
kill(child, SIGKILL);
return 0;
}
int
main( int argc, char **argv) {
int count;
int pid;
if (argc < 2) {
fprintf (stderr, "Usage: benchmark [--child-fp] [--parent-fp] iteration_count\n");
exit(1);
}
if (pipe(&pipe1) < 0 || pipe(&pipe2) < 0) {
perror("pipe");
return 1;
}
if (strncmp(argv[1], "--child-fp") == 0) {
argc--;
argv++;
child_fp = 1;
}
if (strncmp(argv[1], "--parent-fp") == 0) {
argc--;
argv++;
parent_fp = 1;
}
count = argc == 2 ? atoi(argv[1]) : 10000;
switch(pid = fork()) {
case 0:
child_process();
exit(0);
/*NOTREACHED*/
case -1:
perror("fork");
exit(1);
/*NOTREACHED*/
default:
return parent_process(pid,count);
}
}
|
