Subject: Linux-Development Digest #917
From: Digestifier <Linux-Development-Request@senator-bedfellow.MIT.EDU>
To: Linux-Development@senator-bedfellow.MIT.EDU
Reply-To: Linux-Development@senator-bedfellow.MIT.EDU
Date:     Fri, 15 Jul 94 10:13:10 EDT

Linux-Development Digest #917, Volume #1         Fri, 15 Jul 94 10:13:10 EDT

Contents:
  Re: Returning free'd memory (Rob Janssen)
  Re: 1.1.28: SCSI disks inverted ! (Rob Janssen)
  Re: Linux Performance Enhance ? (Rob Janssen)
  GnuChess and Linux (Thomas Heiling)
  Patch Linux lp drivers to support off-line printers (Yan Zhou)
  Why no AFS? ("Theodore Ts'o")
  Linux Performance Enhance ? ("Theodore Ts'o")
  Re: mstats.o missing in libc.a (Mitchum DSouza)
  S: Solution for NCR 810 and INTA (HIGGINS@DELBOX.ZER.DE)

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

From: rob@pe1chl.ampr.org (Rob Janssen)
Subject: Re: Returning free'd memory
Reply-To: pe1chl@rabo.nl
Date: Fri, 15 Jul 1994 06:35:07 GMT

In <304kr8$ain@csnews.cs.Colorado.EDU> drew@kinglear.cs.colorado.edu (Drew Eckhardt) writes:

>In article <CsyA71.8Fo@pe1chl.ampr.org>, Rob Janssen <pe1chl@rabo.nl> wrote:
>>In <graphix.774209621@spiff.cc.iastate.edu> graphix@iastate.edu (Kent A Vander Velden) writes:
>>
>>>Are there any planed changes to the Linux kernel to actually completely give 
>>>the memory back to the system which was free'd by the program before the 
>>>program exits?
>>
>>There are no changes needed in the Linux kernel for this.  It is a function
>>(not) performed by the C libraries.

>This isn't entirely accurate.  While it is definately possible for 
>the user libraries to sbrk() and reduce the size of the data segment,
>you can end up with things like

>    a = malloc (20 * 1024 * 1024);
>    b = malloc (16);
>    free(a);

>and your program will still be holding down an extra 20M.  In real life,
>this would be starting a bunch of X applications which caused resources 
>to be allocated in the X server which are essentially transient, another
>which stayed on your desktop, and the transient applications terminating
>after the permamant application started.

This is very true.  However, you will find that whatever method you design
to handle memory allocation, there will always be a scenario that will make
it perform badly.

E.g.: the current malloc() function in the C library seems to be
designed to be fast and to reduce internal fragmentation.  However, it
is extremely wasteful of memory when many small blocks are allocated.

>To deal with the situation optimally, you need to have some 
>amount of malloc()/free() implemented in the kernel although
>you want to avoid system call overhead for Many Small malloc()s.

>I'd suggest implementing a general user alloc region(s) / free region(s)
>call in the kernel.

It already exists in some form: mmap of /dev/zero

The malloc in the C library could be modified to use this technique when
large blocks of memory are allocated, and to use the sbrk() method for
small blocks.  Optimally, there could be functions to manipulate the behaviour
by programs that know about it.

It would be simple to add system calls to allocate and release memory in
units of a page (4K) but it would impact portability (of the library code
in this case) to other systems.

Rob
-- 
=========================================================================
| Rob Janssen                | AMPRnet:   rob@pe1chl.ampr.org           |
| e-mail: pe1chl@rabo.nl     | AX.25 BBS: PE1CHL@PI8UTR.#UTR.NLD.EU     |
=========================================================================

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

From: rob@pe1chl.ampr.org (Rob Janssen)
Subject: Re: 1.1.28: SCSI disks inverted !
Reply-To: pe1chl@rabo.nl
Date: Fri, 15 Jul 1994 07:47:49 GMT

In <1994Jul14.221420.20160@rosevax.rosemount.com> grante@reddwarf.rosemount.com () writes:

>Chris Adams (racerx@vespucci.iquest.com) wrote:

>: If you are using LILO, then you can always have a "stable" kernel handy
>: right on your hard disk!  Just add another entry when you have a new
>: kernel to test out, specify it when booting, and, if it works, you can
>: make it the default.  If it doesn't work, just boot up the old kernel.
>: No need for floppies.

>Definitely.  My LILO configuration has three kernels configured:

>  "old" is the one from before the one called "linux".
>  "linux" is the one I'm using now.
>  "new" is the one that I'm building/testing.

>After testing "new" for a while, I shift em' all over one.

>Always, always, always, have a kernel that you _know_ works.

>I broke that rule once, and sweated for a day and a half before I got
>back up and running again.

>The easiest way to screw yourself is to move the kernel files around
>and then forget to the LILO config, so that then next time you boot,
>it tries to load Aunt Sally's recipe for peanut butter cookies.  I
>usually add the LILO config command to the /usr/src/Linux Makefile.

Just use "make zlilo" with the Makefile as distributed by Linus.
It will move "vmlinuz" to "vmlinuz.old", install the new "vmlinuz" and
run lilo.

When you make entries in the LILO config for "vmlinuz", "vmlinuz.old" and
optionally a 3rd version which you overwrite only after really testing
the new version, you should be safe.

Rob
-- 
=========================================================================
| Rob Janssen                | AMPRnet:   rob@pe1chl.ampr.org           |
| e-mail: pe1chl@rabo.nl     | AX.25 BBS: PE1CHL@PI8UTR.#UTR.NLD.EU     |
=========================================================================

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

From: rob@pe1chl.ampr.org (Rob Janssen)
Subject: Re: Linux Performance Enhance ?
Reply-To: pe1chl@rabo.nl
Date: Fri, 15 Jul 1994 07:49:51 GMT

In <304lpj$90i@wombat.cssc-syd.tansu.com.au> chrisb@cssc-syd.tansu.com.au (Chris Bitmead) writes:

>Can anyone confirm if this is really portable C? And if it is what does it
>mean? 

It is.
It means control transfers to the case label determined by the value of
'what', and continues from there on as usual.

>How is this:

>switch (what)
>    {
>        while (i--)
>        {
>        case 0:

>different to this:

>while (i--)
>    {
>    switch (what)
>        {
>        case 0:

You must be kidding?

Rob
-- 
=========================================================================
| Rob Janssen                | AMPRnet:   rob@pe1chl.ampr.org           |
| e-mail: pe1chl@rabo.nl     | AX.25 BBS: PE1CHL@PI8UTR.#UTR.NLD.EU     |
=========================================================================

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

From: tom@wpzd07.pzlc.uni-wuerzburg.de (Thomas Heiling)
Crossposted-To: gnu.chess,rec.games.chess
Subject: GnuChess and Linux
Date: 15 Jul 1994 12:11:36 GMT

Hello !

Has anyone out tried gnuchess on a Linux box ? 
There is an annoying bug in either the Linux
libc or in gnuchess.
This is for all versions since 4.0 pl xx (I don't know, when
I started to try this - could be 1 1/2 years )
up to patchlevel 70 with many patches from this group.
If you do a "make test" ( eg: cat ../test/testall|gnuchessr )
the first positions won't  be solved. ( For me it looks like
a problem in stdio - The first 1024 bytes coming to fast ?? )

You got something like this :
Time Target : 0 Total Time 300 and then in the stats line
gnuchess searches only about 15 moves and goes to the next
position.
Last night I played with gdb and it looks like a Problem in
InputPrompt() in the lines with (void) gets(sx) and afterwards.
But the routine looks o.k. to me, if you step over to
EvaluatePosition() /* From memory - it was the routine where the
alpha beta search begins */ gnuchess returns immediately with a
move and XCmoves is {40,0,0}.

Has anyone the same problems on other machines or does anyone
know how to fix this ?

Thanks for your help
Thomas

===================================================
Thomas Heiling Pharmacist & Doctorate at 
Pharmazeutisches Institut Uni Wuerzburg - Germany 
Email phar006@rzbox.uni-wuerzburg.de (HP-UX)
      tom@wpzd07.pzlc.uni-wuerzburg.de (Linux)
or phar006@vax.rz.uni-wuerzburg.de ( VAX )
===================================================

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

From: yanz@staff.cs.su.oz.au (Yan Zhou)
Subject: Patch Linux lp drivers to support off-line printers
Date: 15 Jul 1994 07:22:09 GMT

This is a patch to linux/drivers/char/lp.c, to support off-line
printers.  Lpd works great with the patched drivers.

Cheers,
Yan

---BEGIN---CUT-HERE---
*** linux/drivers/char/lp.c.old Tue Mar 22 00:26:07 1994
--- linux/drivers/char/lp.c     Fri Jul 15 11:21:57 1994
***************
*** 24,29 ****
--- 24,81 ----
  
  #undef LP_DEBUG
  
+ /*
+  * LP OFFLINE SUPPORT (for the polling and interrupt lp drivers)
+  * Patched by Yan ZHOU (yanz@staff.cs.su.oz.au), July 1994
+  *
+  * Why this patch?  Because :-)
+  * "if a printer (/dev/lp?) is off-line, then it acts like /dev/null"
+  *
+  * Guidelines to support off-line (powered-off) printers:
+  *
+  *  o lp_open()  fails if the printer is off-line.
+  *    `lpd' relies on this to check if a printer is available.
+  *
+  *  o lp_write() fails if the printer is off-line (even if LP_ABORT is off).
+  *    Off-line error is treated differently from other kinds of errors,
+  *    (such as `out of paper'), as most print jobs cannot continue and 
+  *    have to abort.
+  *    `lpd' restarts a print job from beginning if the job is aborted.
+  *
+  *  o Data transfer only happens when 
+  *      THERE IS NO ERROR and THE PRINTER IS ONLINE and THE PRINTER IS NOT BUSY
+  *    The ACKLNG signal (LP_PACK) is no longer checked, for 2 reasons:
+  *      1. ACKLNG is some kind of `pulse', while BUSY is a `state'
+  *      2. ACKLNG is unstable during printer power on/off.
+  *    When a printer is off-line, data transfer (thus) will never happen,
+  *    so no data will be lost.
+  */
+ 
+ /* Enable LP OFFLINE SUPPORT  */
+ #define LP_OFFLINE_SUPPORT
+ #ifdef LP_OFFLINE_SUPPORT
+ 
+ /*
+  * Allow first n lp_open() to be successful,
+  * even if the printer is off-line.  So that
+  * `tunelp(8)' can have a chance to do its
+  * job during startup (in /etc/rc.*), even if
+  * the printers are off-line.
+  * 
+  * (n = LP_NO seems to be a good value.)
+  */
+ #define LP_OFFLINE_SUPPORT_OPEN_N_ALLOW               LP_NO
+ 
+ /*
+  * Some macros for printer status testing
+  */
+ #define LP_SERROR(x) (!((x) & LP_PERRORP))            /* Error        */
+ #define LP_SBUSY(x) (!((x) & LP_PBUSY))                       /* Busy         */
+ #define LP_SOFFLINE(x) (!((x) & LP_PSELECD))          /* Off-line     */
+ #define LP_SREADY(x)  (!LP_SERROR((x)) && !LP_SOFFLINE((x)) && !LP_SBUSY((x)))
+ 
+ #endif        /* LP_OFFLINE_SUPPORT   */
+ 
  static int lp_reset(int minor)
  {
        int testvalue;
***************
*** 53,59 ****
--- 105,115 ----
                count ++;
                if(need_resched)
                        schedule();
+ #ifdef LP_OFFLINE_SUPPORT
+       } while(!LP_SREADY(status) && count < LP_CHAR(minor));
+ #else
        } while(!(status & LP_PBUSY) && count < LP_CHAR(minor));
+ #endif
  
        if (count == LP_CHAR(minor)) {
                return 0;
***************
*** 84,93 ****
        unsigned char status;
  
  
        if (!((status = LP_S(minor)) & LP_PACK) || (status & LP_PBUSY)
        || !((status = LP_S(minor)) & LP_PACK) || (status & LP_PBUSY)
        || !((status = LP_S(minor)) & LP_PACK) || (status & LP_PBUSY)) {
! 
                outb_p(lpchar, LP_B(minor));
                /* must wait before taking strobe high, and after taking strobe
                   low, according spec.  Some printers need it, others don't. */
--- 140,155 ----
        unsigned char status;
  
  
+ #ifdef LP_OFFLINE_SUPPORT
+       status = LP_S(minor);
+       if (!LP_SREADY(status)) status = LP_S(minor);
+       if (!LP_SREADY(status)) status = LP_S(minor);
+       if ( LP_SREADY(status)) {
+ #else
        if (!((status = LP_S(minor)) & LP_PACK) || (status & LP_PBUSY)
        || !((status = LP_S(minor)) & LP_PACK) || (status & LP_PBUSY)
        || !((status = LP_S(minor)) & LP_PACK) || (status & LP_PBUSY)) {
! #endif
                outb_p(lpchar, LP_B(minor));
                /* must wait before taking strobe high, and after taking strobe
                   low, according spec.  Some printers need it, others don't. */
***************
*** 140,146 ****
--- 202,213 ----
                                --copy_size;
                                ++bytes_written;
                        } else {
+ #ifdef LP_OFFLINE_SUPPORT
+                                 status = LP_S(minor);
+                                 if (LP_SERROR(status)) {
+ #else
                                if (!((status = LP_S(minor)) & LP_PERRORP)) {
+ #endif
                                        int rc = total_bytes_written + bytes_written;
  
                                        if ((status & LP_POUTPA)) {
***************
*** 156,168 ****
--- 223,243 ----
                                                if (!rc)
                                                        rc = -EIO;
                                        }
+ 
                                        if(LP_F(minor) & LP_ABORT)
                                                return rc;
+ #ifdef LP_OFFLINE_SUPPORT
+                                         if (LP_SOFFLINE(status)) return rc;
+ #endif
                                }
                                cli();
                                outb_p((LP_PSELECP|LP_PINITP|LP_PINTEN), (LP_C(minor)));
                                status = LP_S(minor);
+ #ifdef LP_OFFLINE_SUPPORT
+                                 if (LP_SREADY(status)) {
+ #else
                                if (!(status & LP_PACK) || (status & LP_PBUSY)) {
+ #endif
                                        outb_p((LP_PSELECP|LP_PINITP), (LP_C(minor)));
                                        sti();
                                        continue;
***************
*** 227,233 ****
--- 302,310 ----
                        } else
                        if (!(status & LP_PSELECD)) {
                                printk("lp%d off-line\n", minor);
+ #ifndef LP_OFFLINE_SUPPORT
                                if(LP_F(minor) & LP_ABORT)
+ #endif
                                        return temp-buf?temp-buf:-EIO;
                                current->state = TASK_INTERRUPTIBLE;
                                current->timeout = jiffies + LP_TIMEOUT_POLLED;
***************
*** 291,296 ****
--- 368,388 ----
        if (LP_F(minor) & LP_BUSY)
                return -EBUSY;
  
+ #ifdef LP_OFFLINE_SUPPORT
+         /*
+          * Off-line ?
+          *   But the first several open requests are allowed anyway,
+          *   so that `tunelp' can have a chance to run, even if the
+          *   printers are off-line.
+          */
+         {
+           static int openCounter = 0;
+           if (openCounter >= LP_OFFLINE_SUPPORT_OPEN_N_ALLOW) {
+             if (LP_SOFFLINE(LP_S(minor))) return -EIO;
+           } else openCounter ++;
+         }
+ #endif
+ 
        if ((irq = LP_IRQ(minor))) {
                lp_table[minor].lp_buffer = (char *) kmalloc(LP_BUFFER_SIZE, GFP_KERNEL);
                if (!lp_table[minor].lp_buffer)
***************
*** 458,462 ****
--- 550,559 ----
        }
        if (count == 0)
                printk("lp_init: no lp devices found\n");
+ 
+ #ifdef LP_OFFLINE_SUPPORT
+       printk("lp driver: off-line support enabled.\n");
+ #endif
+ 
        return kmem_start;
  }
-- 
--
Yan ZHOU (Room G87A, Madsen)

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

From: "Theodore Ts'o" <tytso@MIT.EDU>
Subject: Why no AFS?
Date: 15 Jul 1994 09:24:16 -0400
Reply-To: tytso@MIT.EDU

   From: cfuchs@athena.mit.edu (Christopher A Fuchs)
   Date: 13 Jul 1994 05:09:28 GMT

   Hi, I don't know too much about the Linux development effort, but I
   was wondering why Linux does not have AFS support?  I've read
   a million times that it doesn't, but nowhere does it mention _why_.
   Also, is there any development effort going on to change this?

Yes, there is work (funded and managed by MIT Information Systems) going
on to make AFS happen under linux, and will hopefully bear fruit soon.
Have patience.

There are a lot of problems with making AFS under Linux happen, both
legal and technical.  Both are being worked, and I'm confident that
we'll have something which we can distribute (within MIT, anyway) by
sometime this Fall.  I'm hopeful for distribution outside of MIT, but
that's not entirely under our control.

                                                - Ted

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

From: "Theodore Ts'o" <tytso@MIT.EDU>
Subject: Linux Performance Enhance ?
Date: 15 Jul 1994 09:26:28 -0400
Reply-To: tytso@MIT.EDU

   From: andy@eng.kvaerner.no (Andrew Walker)
   Date: 14 Jul 1994 03:22:28 -0400
   Reply-To: andy@eng.kvaerner.no (Andrew Walker)

   Check out the while(i) statement that encloses the switch cases -
   the code jumps into a while loop. To be honest I can't even be bothered
   to check the legality of this in K&R (I think its totally non-intuitive,
   and thus "BAD CODE", but I'd defend it in the kernel if it really
   generates better code).

This is legal, and is called "Duff's device".  It's generally used to
unroll loops for performance reasons.  It's particularily ugly, but it
is legal.  :-)

                                                - Ted

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

From: Mitchum DSouza <m.dsouza@mrc-apu.cam.ac.uk>
Subject: Re: mstats.o missing in libc.a
Date: 15 Jul 1994 09:46:56 -0400
Reply-To: m.dsouza@mrc-apu.cam.ac.uk

Hansel Kwok writes:
| I just found a curious problem in my Slackware 1.2.0 distribution.
| 
| I was writing some code that and I wanted to monitor it the memory
| usage by malloc at various stage. So I used the mstats routine defined
| in malloc.h as:
|                         extern struct mstats mstats __P ((void));
| When I complied the program, I had the message that mstats was not 
| defined.
| 
| So I looked in the libs. using nm, and couldn't find this routine.
| But I know this routine does exist in libc.a as I complied gcc
| at college:
|                 >nm libc.a | grep mstats
|                 mstats.o:
|                 00000000 T _mstats
| Was it a bug in the distribution? And how can I fix the problem
| without recompiling/reinstalling gcc on my linux box? (i.e. are
| there any files that I can grep and just compile the missing links
| and then add to the lib libc.a?)
| 

Hal N. Brooks posted a description of malloc debigging under linux a while
ago. I meant to put this in the GCC-FAQ, but never got round to it.

If you like a copy of his original posting please email me.

Mitch

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

From: HIGGINS@DELBOX.ZER.DE
Subject: S: Solution for NCR 810 and INTA
Date: Thu, 14 Jul 1994 15:27:00 +0200

Frank Westheider         Linux Support Group Paderborn
higgins@uni-paderborn.de     higgins@delbox.zer
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Hi NCR-Folks !

I just got a Elitegroup-PCI-Board with onboard NCR810 chip.
Booting with the ncr boot disk the bootstrap complains about

" You have to set INTA ..."

How can i do this. In the Bios-Setup is only support for INT3 upto INT15 !


Ciao
  Higgins

--
You can escape the gates of hell, say DOG and WINDOG,

         USE LINUX   :-)     !
## CrossPoint v3.0 ##

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


** 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: Linux-Development-Request@NEWS-DIGESTS.MIT.EDU

You can send mail to the entire list (and comp.os.linux.development) via:

    Internet: Linux-Development@NEWS-DIGESTS.MIT.EDU

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

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