From owner-freebsd-hackers Thu Sep 21 9:14: 4 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from ares.cs.Virginia.EDU (ares.cs.Virginia.EDU [128.143.137.19]) by hub.freebsd.org (Postfix) with ESMTP id E3B3037B422 for ; Thu, 21 Sep 2000 09:14:01 -0700 (PDT) Received: from viper.cs.Virginia.EDU (viper.cs.Virginia.EDU [128.143.137.17]) by ares.cs.Virginia.EDU (8.9.2/8.9.2/UVACS-2000040300) with ESMTP id MAA28855 for ; Thu, 21 Sep 2000 12:14:00 -0400 (EDT) Received: from localhost (sl5b@localhost) by viper.cs.Virginia.EDU (8.9.2/8.9.2) with ESMTP id MAA02043 for ; Thu, 21 Sep 2000 12:13:59 -0400 (EDT) X-Authentication-Warning: viper.cs.Virginia.EDU: sl5b owned process doing -bs Date: Thu, 21 Sep 2000 12:13:59 -0400 (EDT) From: Song Li To: freebsd-hackers@FreeBSD.ORG Subject: Re: How to time a system call In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > > 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