lkml.org 
[lkml]   [2023]   [Aug]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH v2 0/6] Introduce __mt_dup() to improve the performance of fork()
From
See the attachment for the slightly modified benchmark./*******************************************************************************
* The BYTE UNIX Benchmarks - Release 3
* Module: spawn.c SID: 3.3 5/15/91 19:30:20
*
*******************************************************************************
* Bug reports, patches, comments, suggestions should be sent to:
*
* Ben Smith, Rick Grehan or Tom Yagerat BYTE Magazine
* ben@bytepb.byte.com rick_g@bytepb.byte.com tyager@bytepb.byte.com
*
*******************************************************************************
* Modification Log:
* $Header: spawn.c,v 3.4 87/06/22 14:32:48 kjmcdonell Beta $
* August 29, 1990 - Modified timing routines (ty)
* October 22, 1997 - code cleanup to remove ANSI C compiler warnings
* Andy Kahn <kahn@zk3.dec.com>
*
******************************************************************************/
char SCCSid[] = "@(#) @(#)spawn.c:3.3 -- 5/15/91 19:30:20";
/*
* Process creation
*
*/

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/mman.h>

volatile int stop;
unsigned long iter;

void wake_me(int seconds, void (*func)())
{
/* set up the signal handler */
signal(SIGALRM, func);
/* get the clock running */
alarm(seconds);
}

void report()
{
fprintf(stderr,"COUNT: %lu\n", iter);
iter = 0;
stop = 1;
}

void spawn()
{
int status, slave;

while (!stop) {
if ((slave = fork()) == 0) {
/* slave .. boring */
exit(0);
} else if (slave < 0) {
/* woops ... */
fprintf(stderr,"Fork failed at iteration %lu\n", iter);
perror("Reason");
exit(2);
} else
/* master */
wait(&status);
if (status != 0) {
fprintf(stderr,"Bad wait status: 0x%x\n", status);
exit(2);
}
iter++;
}
}

int main(int argc, char *argv[])
{
int duration, nr_vmas = 0;
size_t size;
void *addr;

if (argc != 2) {
fprintf(stderr,"Usage: %s duration \n", argv[0]);
exit(1);
}
duration = atoi(argv[1]);

size = 10 * getpagesize();
for (int i = 0; i <= 7000; ++i) {
if (i == nr_vmas) {
stop = 0;
fprintf(stderr,"VMAs: %d\n", i);
wake_me(duration, report);
spawn();
if (nr_vmas == 0)
nr_vmas = 100;
else nr_vmas *= 2;
}
addr = mmap(NULL, size, i & 1 ? PROT_READ : PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);

if (addr == MAP_FAILED) {
perror("mmap");
exit(2);
}
}
}
\
 
 \ /
  Last update: 2023-08-30 21:31    [W:0.251 / U:0.332 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site