Linux-Development-Sys Digest #703, Volume #8      Tue, 8 May 01 13:13:18 EDT

Contents:
  Re: wait() and lost children (Villy Kruse)
  Re: How to get a number of processors (Greg Copeland)
  Re: losing bottom halves (Greg Copeland)
  Re: Time to read the Disk (Kaz Kylheku)
  Linux semaphore implementation (G)
  Re: Time to read the Disk (Kaz Kylheku)
  Re: wait() and lost children (Greg Copeland)
  Simulating a keystroke ("Andrew Murphy")
  kernel 2.4 with mtrr problem (Bernhard Mogens Ege)
  Checking if a pointer is valid ("Andrew Murphy")
  Re: Checking if a pointer is valid (Florian =?iso-8859-1?Q?Gro=DFe=2DCoosmann?=)
  Re: wait() and lost children ([EMAIL PROTECTED])
  Re: bind(), SO_REUSEADDR, and weird leftover states ([EMAIL PROTECTED])
  Re: losing bottom halves
  error loading a module (Ronnie Arosa Carril)
  Re: Linux, streams and the standard library ([EMAIL PROTECTED])
  What does the _REENTRANT symbol enable ? ([EMAIL PROTECTED])
  getting 'ioctl failed: Inappropriate ioctl for device' ([EMAIL PROTECTED])

----------------------------------------------------------------------------

From: [EMAIL PROTECTED] (Villy Kruse)
Subject: Re: wait() and lost children
Date: 8 May 2001 15:10:12 GMT

On 8 May 2001 13:26:28 GMT,
      [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

>
>UP.
>
>SIGCHLD is being ignored.
>

Then the kernel will remove the zombies, at least for kernel 2.2.



>What would you recommend to make sure that I get a wakeup exactly
>once for each child (assuming, for example, I wanted to know the
>status of each and every one), or else knew exactly how many did
>exit, or how many are still running?
>


What would wakeup your program is SIGCHLD is ignored?  In any case
if SIGCHLD is pending a new zombie won't arrange for an extra SIGCHLD
signal to be posted.  At most one signal can be pending at any time.


>My first inclination is to keep a list of every forked child PID,
>and after each wakeup, try to see which ones are still running.
>But this would be a fair amount of work complicated by someone
>else's program which doesn't follow the organization style I do
>my thinking in.
>

You will need to have a SIGCHLD handler and in that sighandler do a
non-blocking wait or waitpid in a loop and then for each pid that wait
returns reduce the number of running children.  Exit the waitpid
loop when it returns either 0 or -1.  If you have a list of running
children you know which one to remove from the list from the pid
that waitpid is returning.



>The idea of the server is the simple case of discovering when a
>child exits and then to start a new one to keep a certain number
>of them running.  I'm about to code up a server of my own which
>will be doing things much like this, with many child processes
>that can fairly frequently exit, so I'd like to pin this issue
>down before I finish up that design so I make sure I've taken the
>correct, or best, approach.

This is a thing that has been done quite frequently, for example
by the init process when respawning getty processes or the shell
when it keeps track of background jobs.

>
>I don't see SA_NOCLDWAIT documented in the man pages.  Looking in
>the source for 2.4.2 I find these matches which seem to hint that
>this isn't supported, yet:
>


SA_NOCLDWAIT is a flag for sigaction, but the 2.2 kernel doesn't do
anything with that flag.  You can grep for NOCLDWAIT in all .c files in
the kernel source tree to see how/where it is actualy used or not used
as the case might be.



Villy

------------------------------

Crossposted-To: comp.os.linux.development.apps
Subject: Re: How to get a number of processors
From: Greg Copeland <[EMAIL PROTECTED]>
Date: 08 May 2001 10:13:55 -0500

[EMAIL PROTECTED] (Stefaan A Eeckels) writes:

> 
> Hitting a raw nerve, eh --I apologize. You indeed spelled out why you needed
> such a function using current technology. I'm merely pointing out that you're
> doing the equivalent of having different file systems on 5.25" and 8" disks,
> as good old Flex did, at the level of processors and scheduling. When you're

I don't really understand what that means.

It's not really a raw nerve.  It was just a real world example that I
don't feel a "magic tool" existed to address the issue.  I'm really trying to
understand what would of been done differently.  In short, without knowing
the number of CPU's, we would of had to do a lot more testing to figure out
how many instances we could actually run.  Since we knew we were CPU bound,
we knew it was going to be a 1:1 ratio of instances to processes to get the
job done.  The only question was what the minimum number was to still get
the job done within the window.  We had it right on the second test run.

> faced with the reality of solving a problem using a particular set of tools,
> you might not think of fixing the tools before tackling the job, but given the
> time and cost overruns you mention, it might not have been a totally useless
> idea to consider upgrading the tools...
> 

It was not an option.  We were brought in to "do or die" on the project.  Another
consulting firm (one of the largest in the world) was not able to finish or make
the project work.  Simply put, we had to make it work with what we had because
more money on different tools specific to this project were not coming.  I am
one that does believe in the right tool for the job.  I have no problem asking
for the right tool.  In this case, I'm pretty sure anther tool wouldn't be
coming, however, I'd like to know what the "tool" would be in this case?

You make an _interesting_ argument, however I don't think I buy into it.  While
I do offer that my solution was somewhat of a hack, nothing comes into mind that
would really offer an alternate solution.  BTW, these were HP 9000 boxen (if
memory serves).

-- 
Greg Copeland, Principal Consultant
Copeland Computer Consulting
==================================================
PGP/GPG Key at http://www.keyserver.net
DE5E 6F1D 0B51 6758 A5D7  7DFE D785 A386 BD11 4FCD
==================================================

------------------------------

Subject: Re: losing bottom halves
From: Greg Copeland <[EMAIL PROTECTED]>
Date: 08 May 2001 10:28:11 -0500



You actually replied to the wrong guy, but your point is valid.  If he
needs the BH to be done now, it should be done in the TH.  At the same
time, if he still wants to use the BH, he should be prepared to handle
any and all TH events that have happened up to that point.  Just to bring
your point home, the point of the split model is to allow for low latency
TH and a potentially high latency BH.  This means that a 1:1 ratio of TH
to BH need not exist.  At least, that's my understanding, which I think
you too are saying.  I'm getting into a grey area here as I've slept since
I last read about this specific issue.  :)

Let me know if you disagree: I/O is available which was triggered via an
interrupt.  The BH is scheduled.  Prior to the BH being called, another
IRQ occurs and is handled in the TH, again flagging the BH.  The BH finally
runs which handles both TH events.  Work for you?

Greg

[EMAIL PROTECTED] () writes:

> In article <[EMAIL PROTECTED]>,
> Greg Copeland  <[EMAIL PROTECTED]> wrote:
> 
> >I didn't take that mean that it is flawed, but I do believe that it is a
> >true statement.  After all, wasn't that one of the primary reasons for the
> >split irq handlers that Linux uses?  Fast top half called on the IRQ, slower?
> >bottom half to be called when able.
> 
> But why should anything prevent an interrupt happening before the bh
> is executed?  The idea was allow some processing to be done outside of
> the interrupt handler.  But that doesn't mean it'll happen before anything
> else.  All that marking the bh to run does is mean it will run sometime
> in the future.  When your bh runs it should insure that it does all the
> work that is ready to be done and not assume that only one interrupt
> has happened.  If you can't do that, why bother with a bh at all?


-- 
Greg Copeland, Principal Consultant
Copeland Computer Consulting
==================================================
PGP/GPG Key at http://www.keyserver.net
DE5E 6F1D 0B51 6758 A5D7  7DFE D785 A386 BD11 4FCD
==================================================

------------------------------

From: [EMAIL PROTECTED] (Kaz Kylheku)
Crossposted-To: comp.os.linux.development.apps
Subject: Re: Time to read the Disk
Reply-To: [EMAIL PROTECTED]
Date: Tue, 08 May 2001 15:32:14 GMT

On Tue, 08 May 2001 18:12:05 +0800, Chan Shing Hong <[EMAIL PROTECTED]>
wrote:
>I have bind a SCSI disk to a raw device at /dev/raw/raw1
>
>When I try to read 128KB from the disk, I found that the time is about
>the same as TWO reads where each read reads 64KB.
>
>However, I think reading 128KB at a time should be faster than reading
>64KB twice since it may save time on the rotation latency.

Except that modern drives have buffers that store the entire contents of a
cylinder. So the only time rotation latency enters into the equation is when
you move the head from cylinder to cylinder in a linear read of consecutive
blocks. Then latency matters, because depending on where the first block of the
next cylinder starts, it may come under the head in a timely way.

>tell me what's going on?  Is the 128KB request broken up into two
>requests???

It's likely broken up into small requests which correspond to the transfer size
between the drive controller and the buffer.  Unless you suppose that your
drive has 64 kilobyte sectors. ;)

------------------------------

From: G <[EMAIL PROTECTED]>
Subject: Linux semaphore implementation
Date: Tue, 8 May 2001 20:59:30 +0530

Hey, can anyone tell me why the semaphore counter does not reflect the no 
of processes sleeping on the semaphore?? 
Say if i initialise the semaphore counter to 0 and then do a couple of 
downs in a  couple of tasks, the tasks doing the down shud typically sleep 
and the semaphore counter shud be -2, but in linux it stays at -1.  Any 
historical reasons?? and why hold a global spinlock to protect a per sema 
"sleepers" variable?? y need the sleepers variable at all?? how is this 
implementation better than the classical semaphore implementation?? 
performance??? historical reasons???  
TIA
G

------------------------------

From: [EMAIL PROTECTED] (Kaz Kylheku)
Crossposted-To: comp.os.linux.development.apps
Subject: Re: Time to read the Disk
Reply-To: [EMAIL PROTECTED]
Date: Tue, 08 May 2001 15:33:11 GMT

On 8 May 2001 14:52:27 GMT, Villy Kruse <[EMAIL PROTECTED]>
wrote:
>disk blocks.  Before the disk driver sees your request it is broken up into
>page size blocks, so the contigous disk access is what realy matters here.

Note that he said he was using a raw device, not a block device.

------------------------------

Subject: Re: wait() and lost children
From: Greg Copeland <[EMAIL PROTECTED]>
Date: 08 May 2001 10:35:58 -0500

[EMAIL PROTECTED] writes:

> On Tue, 08 May 2001 11:59:11 +0000 Kasper Dupont <[EMAIL PROTECTED]> wrote:
> | [EMAIL PROTECTED] wrote:
> |> 
> |> I'm debugging a server program I did not write which has a loop
> |> which involves doing a wait(NULL) call if it has reached its
> |> maximum number of children.  What seems to be happening is that
> |> if 2 or more children have exit status at the same time, the
> |> number of wakeups is less than the number of such children, and
> |> may even be as few as 1.  This is on Linux 2.4.  Is wait() allowed
> |> to behave this way?  

I personally like to keep a list of pids and use waitpid() if possible and
signal the intent to exit to the parent.  Are you sure that all of your
children are really exiting and not hanging in a race condition or skipped
past your _exit() in an unexpected turn of logic?  In other words, are you
sure that each and every child is really in a state whereby wait() will 
really be doing what you expect it to be doing?

Greg


-- 
Greg Copeland, Principal Consultant
Copeland Computer Consulting
==================================================
PGP/GPG Key at http://www.keyserver.net
DE5E 6F1D 0B51 6758 A5D7  7DFE D785 A386 BD11 4FCD
==================================================

------------------------------

From: "Andrew Murphy" <[EMAIL PROTECTED]>
Subject: Simulating a keystroke
Date: Tue, 8 May 2001 16:24:58 +0100

Hi,
      Can you simulate a key stroke in Linux so that a subsequent read from
the keyboard will pick up the key. I tried to write to the keyboard and
although it gave a good return code the next read did not pick up the key.
Thanks
Andy



------------------------------

From: Bernhard Mogens Ege <[EMAIL PROTECTED]>
Subject: kernel 2.4 with mtrr problem
Date: 08 May 2001 17:47:02 +0200

I am not sure where to post this but here it is:

I have installed Redhat 7.1 and that means the 2.4 kernel is
installed. It sort of work fine. It doesn't crash more than 2.2.16
used to. When I write it like that, I mean that AGP still doesn't work 
and now mtrr is also defective.

I am using the nvidia driver for xfree86 4.0.3 and opengl works as it
should (accelerated that is). Two problems remain:

First is AGP support. Using the agpgart module, my machine locks up
soon after starting the X server. nvidia agp cannot enable agp. (using 
Geforve 2MX agp card). This was the same with the 2.2.16 kernel.

The new problem that occured with the 2.4 kernel is that mtrr support
is faulty. This is what /proc/mtrr says:

reg00: base=0x00000000 (   0MB), size=16711936MB: write-back, count=1

This really doesn't look right. I believe the size should be equal to
my main memory size (256Mb mem). I tried to change it, but it always
ended up with the range being about 167xxxxxMb. I issued these commands:

echo "disable=reg00" > /proc/mtrr
echo "base=0x00000000 size=0x10000000 type=write-back" > /proc/mtrr

/proc/mtrr has this to say:

reg00: base=0x00000000 (   0MB), size=16773376MB: write-back, count=1

After the disable command, /proc/mtrr was empty (this I did
expect). With mtrr empty, the machine is extremely slow.

I am unable to add further entries to mtrr, probably because of the
faulty readback.

What could the problem be?

Here is what lspci says about my system (for better insight in my
setup):

00:00.0 Host bridge: Advanced Micro Devices [AMD] AMD-751 [Irongate] System Controller 
(rev 23)
00:01.0 PCI bridge: Advanced Micro Devices [AMD] AMD-751 [Irongate] AGP Bridge (rev 01)
00:07.0 ISA bridge: Advanced Micro Devices [AMD] AMD-756 [Viper] ISA (rev 01)
00:07.1 IDE interface: Advanced Micro Devices [AMD] AMD-756 [Viper] IDE (rev 
03)00:07.3 Bridge: Advanced Micro Devices [AMD] AMD-756 [Viper] ACPI (rev 03)
00:08.0 Multimedia audio controller: Yamaha Corporation YMF-724F [DS-1 Audio 
Controller] (rev 03)
00:0a.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL-8139 (rev 10)
01:05.0 VGA compatible controller: nVidia Corporation NV11 (rev a1)

This is the MSI 6167 mainboard.

dmesg says this about mtrr (during bios initialisation):

mtrr: v1.37 (20001109) Richard Gooch ([EMAIL PROTECTED])
mtrr: detected mtrr type: Intel

dmesg has this to says about the later mtrr changes:

mtrr: type mismatch for d8000000,400000 old: write-back new: write-combining
NVRM: loading NVIDIA kernel module version 1.0-769
mtrr: type mismatch for d8000000,2000000 old: write-back new: write-combining

These two mtrr changes are the ones the nvidia kernel module issues
(the obviously fail).

This affects my desktop speed much, so I would like to have it solved.

Any ideas?

regards,

Bernhard Ege

------------------------------

From: "Andrew Murphy" <[EMAIL PROTECTED]>
Subject: Checking if a pointer is valid
Date: Tue, 8 May 2001 16:32:17 +0100

Hi,
    Does any one know how to check if a pointer is valid in Linux C. I am
trying to simulate the windows IsBadReadPtr and  IsBadWritePtr functions.
Any help appreciated.
Thanks
Andy




------------------------------

From: Florian =?iso-8859-1?Q?Gro=DFe=2DCoosmann?= <[EMAIL PROTECTED]>
Subject: Re: Checking if a pointer is valid
Date: Tue, 08 May 2001 17:54:25 +0200

Andrew Murphy wrote:
> 
> Hi,
>     Does any one know how to check if a pointer is valid in Linux C. I am
> trying to simulate the windows IsBadReadPtr and  IsBadWritePtr functions.
> Any help appreciated.
> Thanks
> Andy

Try to parse /proc/<getpid()>/maps, have a look at "man 5 proc".

Cheers, Florian

------------------------------

From: [EMAIL PROTECTED]
Subject: Re: wait() and lost children
Date: 8 May 2001 15:22:13 GMT

On 8 May 2001 15:10:12 GMT Villy Kruse <[EMAIL PROTECTED]> wrote:
| On 8 May 2001 13:26:28 GMT,
|       [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
|
|>
|>UP.
|>
|>SIGCHLD is being ignored.
|>
|
| Then the kernel will remove the zombies, at least for kernel 2.2.

Even though the parent is in a wait loop to restart children?

This is from gnu-pop3d 0.9.8:

  while (1)
    {
      if (children < maxchildren)
        {
          if (!fork ())
            {
              sock2 = accept (sock, &client, &socksize);
              pop3_mainloop (sock2, sock2);
              close (sock2);
              exit (OK);
            }
          else
            {
              /* wait (NULL); */
              children++;
            }
        }
      else
        {
          wait (NULL);
          children--;
        }
    }



| What would wakeup your program is SIGCHLD is ignored?  In any case
| if SIGCHLD is pending a new zombie won't arrange for an extra SIGCHLD
| signal to be posted.  At most one signal can be pending at any time.

Which is why the wait loop.  I think.  If it hadn't had a NULL as
the status pointer, it should be able to reveal the status for each
child.  Just on the chance the NULL pointer made the kernel think
it was OK to "batch" the children, I changed it to point to a dummy
status.  It was still having problems.


| You will need to have a SIGCHLD handler and in that sighandler do a
| non-blocking wait or waitpid in a loop and then for each pid that wait
| returns reduce the number of running children.  Exit the waitpid
| loop when it returns either 0 or -1.  If you have a list of running
| children you know which one to remove from the list from the pid
| that waitpid is returning.

The above wait loop won't do the job (outside of a signal handler)?


|>The idea of the server is the simple case of discovering when a
|>child exits and then to start a new one to keep a certain number
|>of them running.  I'm about to code up a server of my own which
|>will be doing things much like this, with many child processes
|>that can fairly frequently exit, so I'd like to pin this issue
|>down before I finish up that design so I make sure I've taken the
|>correct, or best, approach.
|
| This is a thing that has been done quite frequently, for example
| by the init process when respawning getty processes or the shell
| when it keeps track of background jobs.

But I'm curious why the need to do it in the signal handler.  I thought
if you did one of the wait() calls, you'd get the status of the next
child in the list, until no more.


| SA_NOCLDWAIT is a flag for sigaction, but the 2.2 kernel doesn't do
| anything with that flag.  You can grep for NOCLDWAIT in all .c files in
| the kernel source tree to see how/where it is actualy used or not used
| as the case might be.

I didn't find any NOCLDWAIT that wasn't also matching SA_NOCLDWAIT.

-- 
=================================================================
| Phil Howard - KA9WGN |   Dallas   | http://linuxhomepage.com/ |
| [EMAIL PROTECTED] | Texas, USA | http://phil.ipal.org/     |
=================================================================

------------------------------

From: [EMAIL PROTECTED]
Subject: Re: bind(), SO_REUSEADDR, and weird leftover states
Date: 8 May 2001 15:24:50 GMT

On 8 May 2001 14:55:35 GMT Villy Kruse <[EMAIL PROTECTED]> wrote:
| On 8 May 2001 10:36:58 GMT,
|        [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:


|>I've modified the gnu-pop3d server to set SO_REUSEADDR on the sockets
|>in daemon mode.  Yet I am finding that when there are leftover
|>connection states after killing all the processes, I cannot get the
|>daemon to restart, until after all the leftover states clear out.
|>
|
|
| You do that on the listen socket before binding the address and port number
| to that socket?

I did it everywhere.  I haven't seen any documentation that says
when in the state-life of a socket this is appropriate.  And I
don't know that the accept() socket inherits it from the listen()
socket, so I do it there as well.

Is that overdoing it to the point of breaking it?

-- 
=================================================================
| Phil Howard - KA9WGN |   Dallas   | http://linuxhomepage.com/ |
| [EMAIL PROTECTED] | Texas, USA | http://phil.ipal.org/     |
=================================================================

------------------------------

From: [EMAIL PROTECTED] ()
Subject: Re: losing bottom halves
Date: Tue, 08 May 2001 16:29:42 -0000

In article <[EMAIL PROTECTED]>,
Greg Copeland  <[EMAIL PROTECTED]> wrote:

>Let me know if you disagree: I/O is available which was triggered via an
>interrupt.  The BH is scheduled.  Prior to the BH being called, another
>IRQ occurs and is handled in the TH, again flagging the BH.  The BH finally
>runs which handles both TH events.  Work for you?

That's how I see it. 

--
http://www.spinics.net/linux

------------------------------

From: Ronnie Arosa Carril <[EMAIL PROTECTED]>
Subject: error loading a module
Date: Tue, 08 May 2001 18:13:50 +0200

I've tried to load a module with the insmod command and I've got this
error: "couldn't found kernel version the module was compile for". Why?
How should I load the module? I have kernel 2.4 and I've just recompiled
my kernel.

Thanks in advance.


------------------------------

Subject: Re: Linux, streams and the standard library
From: [EMAIL PROTECTED]
Date: 08 May 2001 12:49:26 -0500

>>>>> "DK" == David Konerding <[EMAIL PROTECTED]> writes:
    DK> THat's why I responded earlier saying "I'm going to save you a
    DK> lot of time" because 2.95.3 + STLport-4.0 is really stable &
    DK> solid.  I did spend a couple weeks chasing a really tricky bug
    DK> which we were certain was STLport-4.0 but actually turned out to
    DK> be a problem with the run time linker (if you make a C app that
    DK> dlopen()s two shared object files, each of which is linked
    DK> dynamically gainst STLport shared library, you get crashes in
    DK> IOStreams, because the run-time linker doesn't resolve symbols
    DK> properly when it loads the second .so.  The main C app (python)
    DK> specifically does not like havig RTLD_GLOBAL set when it
    DK> dlopen()s the .so's, so it's not surprising we have this
    DK> behavior (what's surprising is that IRIX and Tru64 don't have
    DK> this "problem".  We had to work around it using LD_PRELOAD--
    DK> yecch).  But C++ dlls that get loaded into C programs are fairly
    DK> esoteric, hopefully not an issue for most programmers.

David,

I have experienced a problem (maybe similar to the one you describe
above), when using STLport-4.0 and g++-2.95 and shared C++ DLLs.

What happens is that if I define the _REENTRANT preprocessor symbol for
shared, dynamically loadable libraries (DLLs) written using C++ and that
link against stlport_gcc_stldebug (STLport-4.0), I get segmentation
faults from within STLport.

What exactly does _REENTRANT symbol enable that might be causing this
problem ?

System details:

Reading specs from /usr/lib/gcc-lib/i386-linux/2.95.4/specs
gcc version 2.95.4 20010506 (Debian prerelease)
Linux kernel-2.4.4
libc6-2.2.2-4
Debian GNU/Linux sid (unstable)

Thanks.

-- 
Salman Ahmed

To reply, remove "nospam." from my email address

ssahmed AT pathcom DOT com

------------------------------

Subject: What does the _REENTRANT symbol enable ?
From: [EMAIL PROTECTED]
Date: 08 May 2001 12:58:43 -0500


I was reading in John Goerzen's "Linux Programming Bible" that shared,
dynamic libraries should be built with the _REENTRANT symbols defined
for all source files that are compiled into it.

What exactly does the _REENTRANT symbol enable in the system (ie libc)
headers and elsewhere ?

Thanks.

-- 
Salman Ahmed

To reply, remove "nospam." from my email address

ssahmed AT pathcom DOT com

------------------------------

From: [EMAIL PROTECTED]
Subject: getting 'ioctl failed: Inappropriate ioctl for device'
Date: Tue, 08 May 2001 17:02:01 GMT

I have /sbin/insmod my driver and it is successful. I also executed 'mknod' so
that my device is in /dev directory. Now, from the user space, I opened this
device and it is successful. But when I try to send an ioctl, I get 'ioctl
failed: Inappropriate ioctl for device' message. Also, I see none of the other
calls like open in my fops are getting called either. I know this because, I
have printks in my fops--open call and I don't see it in the /var/log/messages.
I thought that this should be called when I do - an open on this device from the
User Space. Is my assumption wrong. Any thoughts ...

thanx,
k



------------------------------


** FOR YOUR REFERENCE **

The service address, to which questions about the list itself and requests
to be added to or deleted from it should be directed, is:

    Internet: [EMAIL PROTECTED]

You can send mail to the entire list by posting to the
comp.os.linux.development.system newsgroup.

Linux may be obtained via one of these FTP sites:
    ftp.funet.fi                                pub/Linux
    tsx-11.mit.edu                              pub/linux
    sunsite.unc.edu                             pub/Linux

End of Linux-Development-System Digest
******************************

Reply via email to