How to time a system call
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. 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 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 calls. Is there any easy way to time a system call (perhaps with minor modifications of the kernel)? Any help is appreciated. -Zhihui To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
putting FreeBSD in an extended partition
I am wondering whether there is a good reason for not putting FreeBSD in a DOS extended partition. I have installed four O.S.es on my laptop and know that could be a limitation if FreeBSD can not be put into a DOS extended partition. I do not see any limitations in the boot loader or kernel that prevent this. Thanks for any enlightment. -Zhihui To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: putting FreeBSD in an extended partition
On Mon, 25 Sep 2000, Doug White wrote: > On Sat, 23 Sep 2000, Zhiui Zhang wrote: > > > > > I am wondering whether there is a good reason for not putting FreeBSD in a > > DOS extended partition. > > Good luck booting it. Do you mean as long as I can boot it, the kernel itself has no problem with being putting into a DOS extended partition? First of all, it seems to me that there is no way to put FreeBSD in an extended partition without modifying /stand/sysintall. -Zhihui To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: putting FreeBSD in an extended partition
On Tue, 26 Sep 2000, Mike Smith wrote: > I am wondering whether there is a good reason for not putting FreeBSD in a > DOS extended partition. > >>> > >>> Good luck booting it. > >> > >> Do you mean as long as I can boot it, the kernel itself has no problem > >> with being putting into a DOS extended partition? > > > > Loader(8) can't grok it and the kernel can't mount it as root. > > Actually, that's not entirely true. > > The problem with booting is that you cannot mark an extended partition > entry as 'active' (without some nasty, nonstandard hacks). > > If that were possible, it would be trivial to improve the loader to deal > with that case. The kernel most certainly can mount an extended partition > as root, however. I know this is a minor subject. But Why Linux can be put in an extended partition while FreeBSD cannot? I can not find anywhere (e.g. kern/subr_diskslice.c) in the kernel that prevents this and I know LILO can boot FreeBSD. If it is the problem of booteasy, then we can use other boot loader. -Zhihui To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
system hangs with BUS Reset
I am debugging a program that does a lot of disk I/O and the system hangs briefly with the some repeated messages that looks like: (da0:ahc0:0:0:0): SCB 0x0 - Timed out in Data-in phase, SEQADDR==0x88 (da0:ahc0:0:0:0): BDR message in message buffer (da0:ahc0:0:0:0): SCB 0x0 - Timed out in Data-in phase, SEQADDR==0x89 (da0:ahc0:0:0:0): no longer in timeout, status= 34b ahc0: Issued Channel A Bus Reset. 2SCBs aborted. What should I do now? The following is my dmesg output: Copyright (c) 1992-2000 The FreeBSD Project. Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994 The Regents of the University of California. All rights reserved. FreeBSD 4.1-RELEASE #0: Tue Sep 26 01:34:11 GMT 2000 [EMAIL PROTECTED]:/usr/src/sys/compile/SUNYFS Timecounter "i8254" frequency 1193182 Hz CPU: Pentium III/Pentium III Xeon/Celeron (501.14-MHz 686-class CPU) Origin = "GenuineIntel" Id = 0x673 Stepping = 3 Features=0x383fbff real memory = 134205440 (131060K bytes) avail memory = 126341120 (123380K bytes) Preloaded elf kernel "kernel" at 0xc0419000. Pentium Pro MTRR support enabled md0: Malloc disk npx0: on motherboard npx0: INT 16 interface pcib0: on motherboard pci0: on pcib0 pcib1: at device 1.0 on pci0 pci1: on pcib1 isab0: at device 4.0 on pci0 isa0: on isab0 atapci0: port 0xd800-0xd80f at device 4.1 on pci0 ata0: at 0x1f0 irq 14 on atapci0 uhci0: port 0xd400-0xd41f irq 10 at device 4.2 on pci0 usb0: on uhci0 usb0: USB revision 1.0 uhub0: Intel UHCI root hub, class 9/0, rev 1.00/1.00, addr 1 uhub0: 2 ports with 2 removable, self powered uhub0: port 1 power on failed, IOERROR uhub0: port 2 power on failed, IOERROR chip1: port 0xe800-0xe80f at device 4.3 on pci0 ahc0: port 0xd000-0xd0ff mem 0xe300-0xe3000fff irq 10 at device 6.0 on pci0 ahc0: aic7890/91 Wide Channel A, SCSI Id=7, 16/255 SCBs dc0: port 0xb800-0xb8ff mem 0xe280-0xe28000ff irq 11 at device 10.0 on pci0 dc0: Ethernet address: 00:a0:cc:e4:b7:14 miibus0: on dc0 dcphy0: on miibus0 dcphy0: 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, auto fdc0: at port 0x3f0-0x3f5,0x3f7 irq 6 drq 2 on isa0 fdc0: FIFO enabled, 8 bytes threshold fd0: <1440-KB 3.5" drive> on fdc0 drive 0 atkbdc0: at port 0x60,0x64 on isa0 atkbd0: flags 0x1 irq 1 on atkbdc0 kbd0 at atkbd0 vga0: at port 0x3c0-0x3df iomem 0xa-0xb on isa0 sc0: at flags 0x100 on isa0 sc0: VGA <16 virtual consoles, flags=0x300> sio0 at port 0x3f8-0x3ff irq 4 flags 0x10 on isa0 sio0: type 16550A sio1 at port 0x2f8-0x2ff irq 3 on isa0 sio1: type 16550A ppc0: at port 0x378-0x37f irq 7 on isa0 ppc0: SMC-like chipset (ECP/EPP/PS2/NIBBLE) in COMPATIBLE mode ppc0: FIFO with 16/16/9 bytes threshold ppi0: on ppbus0 lpt0: on ppbus0 lpt0: Interrupt-driven port plip0: on ppbus0 ata0-slave: ata_command: timeout waiting for intr ata0-slave: identify failed acd0: CDROM at ata0-master using PIO4 Waiting 15 seconds for SCSI devices to settle Mounting root from ufs:/dev/da0s1a da0 at ahc0 bus 0 target 0 lun 0 da0: Fixed Direct Access SCSI-2 device da0: 80.000MB/s transfers (40.000MHz, offset 15, 16bit), Tagged Queueing Enabled da0: 8683MB (17783240 512 byte sectors: 255H 63S/T 1106C) WARNING: / was not properly dismounted Any help is appreciated. -Zhihui To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
process scheduling quantum
Suppose a process is scheduled to run, will it run until its quantum ends unless it calls tsleep() on his own? In other words, is it possible for a process to give up its quantum earlier without having it to do so voluntarily? Thanks. -Zhihui To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
RE: process scheduling quantum
On Tue, 3 Oct 2000, John Baldwin wrote: > > On 02-Oct-00 Zhiui Zhang wrote: > > > > Suppose a process is scheduled to run, will it run until its quantum ends > > unless it calls tsleep() on his own? In other words, is it possible for a > > process to give up its quantum earlier without having it to do so > > voluntarily? Thanks. > > If an interrupt occurs and puts a thread on the run queue (which will have > higher priority than the currently running proceess) then the current > process will be stopped so that the interrupt thread can run. Thanks. But I guess that you are talking about the new SMP threads. For FreeBSD 4.1-Release, I am not sure this can happen. I am wondering any time taken by interrupts (hardware or software) will be accounted to the current process. If so, the process's quantum is stolen away and nothing useful for that process is done. I wrote program the other day. It read the number of context switches done so far in a loop. If the number changes, then the process exits. In between, it calls getpid(). I just want to see how many system calls can be done between context switch. It turns out sometimes the number of calls to getpid() is zero. That is why I am asking the above question. -Zhihui To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
granularity of gettimeofday()
The manual says the granularity of gettimeofday() is hardware dependent. The time may be updated continuously or in clock ticks. Can anyone explain for me the two different ways of updating the time? What kind of hardware can help? Thanks for your help. -Zhihui To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: granularity of gettimeofday()
On Fri, 3 Nov 2000, Poul-Henning Kamp wrote: > In message <Pine.SOL.4.21.0011031156050.29568-10@jade>, Zhiui Zhang writes: > > > >The manual says the granularity of gettimeofday() is hardware dependent. > >The time may be updated continuously or in clock ticks. Can anyone > >explain for me the two different ways of updating the time? What kind of > >hardware can help? > > You probably need to tell me what you need first... This is actually a question from the book "Kernel Project for Linux" and I am a TA for an operating system course that uses this textbook. I know a little bit of NTP and Intel Time stamp counter. I need an authoritive answer for this question because I do not have the time to go through the FreeBSD code to find out myself in a short time. My impression is that if the time is updated by an interrupt handler per tick, it can not get a microsecond granularity. -Zhihui To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Protect a VFS buffer from VM - how
I understand that memory belonged to a buffer will not be paged out by VM daemon. Now I want protect that memory from being cleaned by VM daemon as well. Should I use vfs_busy_pages() or just assume that since my pages are on the active queue, VM daemon will not touch it (it only cleans pages on the inactive queue). In short, I not only want to wire the page, but also want exclusive access to it by the filesystem code. How to do this correctly? Please clarify this subject for me. Any help is appreciated. -Zhihui To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
simple lock and the lost wakeup problem
I am new to SMP subject and have some questions to ask: Is the simplelock() really needed since FreeBSD is using the big giant lock and the kernel is non preemptive? Or has FreeBSD changed the big giant lock and made kernel thread preemptive? Uresha Vahalia talks about Lost Wakeup Problem (page 196), the test of the resource and sleep() has to be done atomically. Which correct mechanism should I use on FreeBSD to achieve this (avoid the lost-wakeup problem)? Any help is appreciated. -Zhihui To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
ptrace(PT_GETDBREGS) message in remote debugging
I tried remote debugging on FreeBSD 4.2 this morning. Everything was fine, except that I saw the following messages: (gdb) step ptrace(PT_GETDBREGS) failed: No such process ptrace(PT_GETDBREGS) failed: No such process ptrace(PT_GETDBREGS) failed: No such process 201 cred = p ? p->p_ucred : NOCRED; This ptrace stuff never appear before. Is this a new feature or was I doing something wrong? Any help is appreciated. -Zhihui To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: ptrace(PT_GETDBREGS) message in remote debugging
Thanks. I tried this on FreeBSD 4.2-Release (because I do not have a stable or current), but I failed: # make Warning: Object directory not changed from original /usr/src/gnu/usr.bin/binutils/gdb cc: ../libbfd/libbfd.a: No such file or directory cc: ../libopcodes/libopcodes.a: No such file or directory cc: ../libiberty/libiberty.a: No such file or directory *** Error code 1 Stop in /usr/src/gnu/usr.bin/binutils/gdb. What should I do? -Zhihui On Wed, 6 Dec 2000, Brian Dean wrote: > Index: freebsd-nat.c > === > RCS file: >/usr00/FreeBSD/mirror/ncvs/src/gnu/usr.bin/binutils/gdb/i386/freebsd-nat.c,v > retrieving revision 1.21.4.2 > diff -u -r1.21.4.2 freebsd-nat.c > --- freebsd-nat.c 2000/08/22 12:28:19 1.21.4.2 > +++ freebsd-nat.c 2000/12/07 00:31:52 > @@ -478,14 +478,16 @@ > { >struct dbreg dbr; >extern int inferior_pid; > - > + >if (inferior_pid != 0 && core_bfd == NULL) > { >int pid = inferior_pid & ((1 << 17) - 1); /* XXX extract pid from tid */ > - > + >if (ptrace(PT_GETDBREGS, pid, (caddr_t)&dbr, 0) == -1) > { > - perror("ptrace(PT_GETDBREGS) failed"); > + /* don't complain on ESRCH, assume we are debugging a remote target */ > + if (errno != ESRCH) > + perror("ptrace(PT_GETDBREGS) failed"); > return 0; > } > #if WATCHPOINT_DEBUG > 1 > @@ -520,7 +522,10 @@ > >if (ptrace(PT_GETDBREGS, pid, (caddr_t)&dbr, 0) == -1) > { > - perror("ptrace(PT_GETDBREGS) failed"); > + /* don't complain on ESRCH, assume we are debugging a remote target */ > + if (errno != ESRCH) > + perror("ptrace(PT_GETDBREGS) failed"); > + > return 0; > } > > @@ -615,7 +620,9 @@ > >if (ptrace(PT_GETDBREGS, pid, (caddr_t)&dbr, 0) == -1) > { > - perror("ptrace(PT_GETDBREGS) failed"); > + /* don't complain on ESRCH, assume we are debugging a remote target */ > + if (errno != ESRCH) > + perror("ptrace(PT_GETDBREGS) failed"); > return 0; > } > To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: ptrace(PT_GETDBREGS) message in remote debugging
Your patch works for me on FreeBSD 4.2-Release. Thanks. -Zhihui On Thu, 7 Dec 2000, Brian Dean wrote: > On Thu, Dec 07, 2000 at 03:30:51PM -0500, Zhiui Zhang wrote: > > Thanks. I tried this on FreeBSD 4.2-Release (because I do not have a > > stable or current), but I failed: > > > > # make > > > > Warning: Object directory not changed from original > > /usr/src/gnu/usr.bin/binutils/gdb > > > > > > cc: ../libbfd/libbfd.a: No such file or directory > > cc: ../libopcodes/libopcodes.a: No such file or directory > > cc: ../libiberty/libiberty.a: No such file or directory > > *** Error code 1 > > > > Stop in /usr/src/gnu/usr.bin/binutils/gdb. > > > > What should I do? > > Hmmm, looks like you haven't built world on this machine. No worries, > just do this: > > % cd /usr/src/gnu/usr.bin/binutils > % (cd libbfd && make) > % (cd libopcodes && make) > % (cd libiberty && make) > % (cd gdb && make && make install) > > This should build the missing libs and then gdb should link correctly. To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
kernel debugging suggestion needed
I have written a KLD and am debugging it. The program often hangs after runs for a while (I guess it enters into some dead loop). Is there a way to attach to the process and somehow find out which code it is executing (with remote debugging or ddb)? Thanks for your help. -Zhihui To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: kernel debugging suggestion needed
On Tue, 2 Jan 2001, Doug White wrote: > On Tue, 2 Jan 2001, Zhiui Zhang wrote: > > > > > I have written a KLD and am debugging it. The program often hangs after > > runs for a while (I guess it enters into some dead loop). Is there a way > > to attach to the process and somehow find out which code it is executing > > (with remote debugging or ddb)? > > kld debugging is a bit tricky. Take a look at the debugging macros and > bits that Greg Lehey put together for vinum for a starting point. You have > to calculate the appropriate offset to get to the KLD code in gdb. I already did this. I hope that I can find a way to know which process is running which part of the KLD code endlessly. -Zhihui To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Process virtual memory question
Although the 4.4 BSD design and implementation book says the text part of a process starts from 0x,, it actually starts from some place around 0x800, (or 0x8048000 to be exact). What's in the area between 0 - 0x800,? Why do we not use it if it is left empty as shown by /proc/pid/map? How is the magic number 0x8048000 determined? Thanks. -Zhihui To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: Process virtual memory question
Thanks. It just occurs to me that Linux kernel used to have something like this in routine BUG(): * ((char *) 0) = 0; It is called when there is a kernel bug. So address 0 should not be mapped writable, otherwise all C statements " char * p = NULL; * p = value; " would be legal. The book "Unix Internals - A Practical Approach" by S.D. Pate has a figure showing in ELF format, the stack lies BELOW the code segment and grows downwards. This might have something to do with code starting from 0x8048000. -Zhihui On Thu, 11 Jan 2001, John Polstra wrote: > In article <Pine.SOL.4.21.010008490.22923-10@jade>, Zhiui > Zhang <[EMAIL PROTECTED]> wrote: > > > Although the 4.4 BSD design and implementation book says the text > > part of a process starts from 0x,, it actually starts from > > some place around 0x800, (or 0x8048000 to be exact). What's in > > the area between 0 - 0x800,? Why do we not use it if it is left > > empty as shown by /proc/pid/map? How is the magic number 0x8048000 > > determined? Thanks. > > Processes used to be mapped at address 0 when we used the a.out object > file format. We changed the starting address to 0x8048000 when we > switched to the ELF format. That magic address came from SVR4, the > first system to use ELF. > > I am not 100% sure why the SVR4 developers chose that address. I > think it may have been so that they could map libc and the dynamic > linker at the fixed address 0, thereby avoiding the need to do any > run-time relocations on them. > > In any case, all ELF-based systems on the x86 architecture seem to > use this same address. On other architecutures such as the Alpha > it is entirely different, of course. > To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
kernel debugging help
I am debugging a kernel. Since a kernel is consisted of many files, how can I load a specific file into gdb, browse it, and set a break point at some line within that file? Right now, I can only view the file whose statements are being executed. Thanks. -Zhihui To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
buffer headers in FreeBSD & Linux
I am wondering why FreeBSD has fixed number of buffer headers (nbuf) while Linux can grow the number of buffer headers on the fly. In FreeBSD, we have a lofreebuffers count. I think this is a reserve for avoiding deadlock when the buffer headers are low. But Linux does not seem to have such a counter. How do they solve this problems? What's the pros and cons of these two different schemes? Any help is appreciated! -Zhihui To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
specify a different kernel to boot
Is there a way to specify a kernel other than /kernel to boot from? I do not want to do this manually, I want to put it into some configuration file. Thanks, -Zhihui To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Obtain a list of active vnodes
I tried to obtain a list of vnodes in the system. The command pstat -v no longer works. Is there any way to achieve this or hack the code a little bit to achieve this? Thanks. -Zhihui To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
No-passwd account and reboot records
Is it possible to create a no-password account? Is it possible to record in a file the times of each reboots? If so, how to do this? Thanks. -Zhihui To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Linux kiobuf stuff...
While looking at Linux 2.4 code, I see the kiobuf stuff. They implement it because Linux 2.2 lacks raw device support. I am wondering whether FreeBSD has a similar mechanism already in place. My reasonings: (1) FreeBSD's buffer is variable sized while Linux's buffer is fixed sized. So in the case of FreeBSD, a buffer can easily be associated with many pages. The kiobuf in Linux seems to limit the max I/O to 64KB. (2) We have physical buffers, they can be used separately (like in physio() and swapping) or they can be built on top of regular buffers (like in clustering I/O). Thanks for any enlightment. -Zhihui To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message