Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 21 Sep 2000 12:13:59 -0400 (EDT)
From:      Song Li <sl5b@cs.virginia.edu>
To:        freebsd-hackers@FreeBSD.ORG
Subject:   Re: How to time a system call
Message-ID:  <Pine.GSO.4.21.0009211155490.1062-100000@viper.cs.Virginia.EDU>
In-Reply-To: <Pine.SOL.4.21.0009181425060.6901-100000@jade>

next in thread | previous in thread | raw e-mail | index | archive | help
> 
> A friend asks me what will happen if more than one process trying to read
> the stdin at the same time. There is no way to guarantee that any
> particular keyboard input will be accepted by a particular process.
how about using several psudo terminal?

> Since a system call is atomic, this makes me wonder how long it takes to
> do a system call, like read(), on a 500Mhz PC? How to time it?  I later
Usually 50us to several hundrends us, as what I remember.

> write a program that forks.  So that two processes tries to read the stdin
> at the same time. I use read() to read one character at a time.  Each
> process read 1000 characters and write what they read to a file. I use I/O
> redirect to let them read from the same file instead of keyboard. I find
> out that one process always call 1000 read()s before the second has a
> chance to call read().
> 
> I hope someone can give me a clue on how this is happening. Maybe the
> scheduling quantum (100ms?) is just enough for doing 1000 read() system
I guess so, unless the read cannot return instantly and cause the
volunteer context switch.

> calls. Is there any easy way to time a system call (perhaps with minor
> modifications of the kernel)?
You may set the ktrace flag when the program was forked or execve-ed. You
should also provide the file to which the output will be written when
setting the flag. Then you can go to the file
/usr/src/sys/kern/kern_ktrace.c and modify the function ktrsyscall(),
ktrsysret(), ktrwrite(), etc to decide what kind of information and the format 
to write. If you want to exclude the idle time of the process, you also
need to modify the mi_switch() in file /usr/src/sys/kern_synch.c so that
the switch time stamps can be recorded and excluded later.

That's what I did before. Probably there is simpler method.

> 
> Any help is appreciated.
> 
> -Zhihui
> 
> 
> 
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-hackers" in the body of the message
> 



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.GSO.4.21.0009211155490.1062-100000>