Linux-Development-Apps Digest #421, Volume #7    Mon, 21 May 01 18:13:14 EDT

Contents:
  Re: Can't get a "Hello World" to compile!  Help please... 
(=?iso-8859-1?Q?Andr=E9_P=F6nitz?=)
  Re: gui for linux (Grant Edwards)
  Re: asynchronous io (Michel Bardiaux)
  Floating point performence problems due to poor stack alignment (Daniel Spangberg)
  Re: Send a short message (SMS) within a classic modem (Martin Bertilsson Haagen)
  Re: Floating point performence problems due to poor stack alignment (Daniel 
Spangberg)
  Re: Faster than strstr (CBFalconer)
  Re: asynchronous io ("D. Stimits")
  Re: [Q]What is frame buffer??... Help (Matan Ziv-Av)
  Re: asynchronous io (Philip Armstrong)
  Re: Running an app with a different libc so than the system default? ("Paul D. 
Smith")
  How to get rid of 'tempnam is dangerous' warning? (Grant Edwards)

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

From: =?iso-8859-1?Q?Andr=E9_P=F6nitz?= <[EMAIL PROTECTED]>
Subject: Re: Can't get a "Hello World" to compile!  Help please...
Date: 21 May 2001 14:16:00 GMT

IncaOfJersey <[EMAIL PROTECTED]> wrote:
> this is my test.cc file
> #include <iostream.h>
> int main()
> {
>   cout << "hello world";
>   return 0;
> }

The canonical C++ "hello world" program nowadays looks like

#include <iostream>

int main()
{
  std::cout << "hello world\n";
  return 0;
}

(or "using std::cout;" or "using namespace std;" before main or "std::endl"
instead of "\n")

However, your real problem seems to be invoking GCC as C compiler (gcc),
not as C++ compiler (g++). If you do so, you are responsible for linking in
libstdc++ yourself. Using g++ directly is of course simpler...

Andre'

-- 
André Pönitz ............................................. [EMAIL PROTECTED]

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

From: [EMAIL PROTECTED] (Grant Edwards)
Subject: Re: gui for linux
Date: Mon, 21 May 2001 14:17:02 GMT

In article <[EMAIL PROTECTED]>, Nils O. Selåsdal wrote:

>> > i want to programm a very simple GUI for my programm under linux.
>> > but i don't want to use gnome, kde and such thinks because they need too
>> > much resources.
>> >
>> > do anyone know how to programm the grafics-controller under this os?
>> >
>> > cu torsten
>> You could program your gui using Tcl/TK, or plain GTK (without
>> gnome). There is also FLTK (fast light tool kit) which may do
>> what you want.
>
>Or why not use the X libraries directly ?

I don't know if you've done xlib programming, but it's pretty
brutal.  I've no idea why somebody would use xlib directly
rather than something like gtk.

-- 
Grant Edwards                   grante             Yow!  I'll take ROAST BEEF
                                  at               if you're out of LAMB!!
                               visi.com            

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

From: Michel Bardiaux <[EMAIL PROTECTED]>
Subject: Re: asynchronous io
Date: Mon, 21 May 2001 16:39:42 GMT

[EMAIL PROTECTED] wrote:
> 
> In article <[EMAIL PROTECTED]>,
> D. Stimits <[EMAIL PROTECTED]> wrote:
> 
> >I'm trying to find out if the aio_read is available, and if so,
> >approximately what kernel version it is available from?
> 
> Set O_ASYNC and handle SIGIO.
> 
> --
> http://www.spinics.net/linux

O_ASYNC on what? 

Anyway I doubt any of the ioctl, fcntl or whatever, provide asynchronous
IO on ***DISK*** files. Only aio can do that. So, back to the original
question: is aio available on Linux?

-- 
Michel Bardiaux
Peaktime Belgium S.A.  Rue Margot, 37  B-1457 Nil St Vincent
Tel : +32 10 65.44.15  Fax : +32 10 65.44.10
Cc Email of replies welcome

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

Subject: Floating point performence problems due to poor stack alignment
From: Daniel Spangberg <[EMAIL PROTECTED]>
Date: 21 May 2001 19:35:32 +0200

Hi!

I recently got some floating point performance problems when running a
rather large scientific code on a 1 GHz Athlon Thunderbird. This code
is carefully cache-blocked to run most of the time from L1 cache.

This code had no performance problems when compiled on some older
machines running SuSE 6.1 and 6.3 but got problems on SuSE 7.0 and
7.1. The same version of gcc, 2.95.2, was used on all machines
however. 

The problem turned out to be due to poor stack alignment. All
calculations are done in double precision and those variables should
really be aligned on eight byte boundaries for optimal
performance. There is an option to recent gcc's that should align the
stack (-mpreferred-stack-boundary=3) but it does not work.  It
actually seems like the stack is not properly aligned when main is
called, so there is not much gcc can do to ensure a stricter
alignment.

I googled around for a while but could not find any recent
solutions. I finally created a very ugly hack to align the stack in
main before calling the rest of the code.

The difference in performance when doing optimal cache blocking is
rather large. Without the hack I get a little more than 500 MFlops.
With the hack I get more than 800 MFlops.

I have extracted a part of the problematic code below and run it at
different data set sizes. The results at different memory sizes is
available at
http://www.teoroo.mkem.uu.se/daniels/pics/emicro.gif

There are two memory buffers, scratch and buf, in the program
below. In the original code the memory access patterns of the two
buffers are quite different. The scratch buffer changes occasionally
and is rather small (enough to easily keep it in the L1 cache). The
buf buffer is large and prefetches are needed to hide the latency when
accessing it. However in the code below, for simplicity, they are
accessed in a similar fashion and optional prefetches can be inserted
for both buffers.

Fastest code is obtained by compiling at the -O1 level. 
To include the hack compile it with 
gcc -O1 -DUSE_X86_ALIGN_HACK
To also include the prefetches (3dnow!) compile with
gcc -O1 -DUSE_X86_ALIGN_HACK -DUSE_PREFETCH_3DNOW

Finally for the question(s): Does anyone know where the alignment
problem occurs? Should the stack be aligned by gcc startup code
or elsewhere? I saw some old comments from gcc people who thought
that they shouldn't have to do this in the gcc startup code since the
OS should be clever enough to not provide an unaligned stack. I am
trying to understand when and/or if I can get rid of my ugly hack
somewhere in the future. Also, does anyone know if there is some
better/cleverer way to handle this problem?


#include <stdio.h>
#include <stdlib.h>

#if 1
#include <sys/times.h>
#include <time.h>

double mytime()
{
  struct tms t;
  times(&t);
  return (t.tms_utime+t.tms_stime)/(double)CLK_TCK;
}
#endif

/* Some global variables to prevent optimization
   from removing the code. */
int s0,s1,s2,s3,s4,s5,s6,s7;


/* This type is used to cast between pointers and ints,
   to make sure memory buffers are aligned. */
typedef unsigned long ptrint_t;
#define MALIGN 16

#define BLOCKMAX 1000000
#define EXTRAREPEAT 10*BLOCKMAX

void bench()
{
    int i,j;
    double sum0=0.;
    double sum1=0.;
    double sum2=0.;
    double sum3=0.;
    double sum4=0.;
    double sum5=0.;
    double sum6=0.;
    double sum7=0.;

    double efac=1.;
                      
    int block=16;
    printf("Memory MFlops samples\n");

    while (block<BLOCKMAX)
    {
        int extrarepeat;
        double *bufm=malloc(block*2*sizeof *bufm+MALIGN);
        double *scratchm=malloc(block*4*sizeof *scratchm+MALIGN);
        ptrint_t cnv;
        double *buf,*scratch,*bufptr,*scratchptr;
        double measure;
        double numlaps;

        /* Align buffers. */
        cnv=(ptrint_t)bufm;
        cnv/=MALIGN;
        cnv*=MALIGN;
        cnv+=MALIGN;
        buf=(double*)cnv;
        cnv=(ptrint_t)scratchm;
        cnv/=MALIGN;
        cnv*=MALIGN;
        cnv+=MALIGN;
        scratch=(double*)cnv;
  
        for (i=0; i<block; i++)
        {
            buf[i*2]=1.1;
            buf[i*2+1]=1.2;
            scratch[i*4]=1.3;
            scratch[i*4+1]=1.4;
            scratch[i*4+2]=1.5;
            scratch[i*4+3]=1.6;
        }


        extrarepeat=EXTRAREPEAT/block;
        if (extrarepeat<2)
            extrarepeat=2;
      
        measure=mytime();
        numlaps=block*extrarepeat;
      
        for (j=0; j<extrarepeat; j++)
        {

            bufptr=buf;
            scratchptr=scratch;

            for (i=0; i<block; i++)
            {
                double ch_sinkr=*bufptr;
                double ch_coskr=*(bufptr+1);
      
                double sicjpcisj=*scratchptr;
                double sicjncisj=*(scratchptr+1);

                double cicjpsisj=*(scratchptr+2);
                double cicjnsisj=*(scratchptr+3);

                double qcksicjpcisj,qcksicjncisj;
                double qsksicjpcisj,qsksicjncisj;
                double qckcicjpsisj,qckcicjnsisj;
                double qskcicjpsisj,qskcicjnsisj;


#ifdef USE_PREFETCH_3DNOW
              __asm__ __volatile__ ("prefetch %0" : : "m" (*(bufptr+8)));
              __asm__ __volatile__ ("prefetch %0" : : "m" (*(scratchptr+16)));
#endif  


                qcksicjpcisj=ch_coskr*sicjpcisj;
                qskcicjnsisj=ch_sinkr*cicjnsisj;

                sum0+=qcksicjpcisj+qskcicjnsisj;
                sum6+=qskcicjnsisj-qcksicjpcisj;

                bufptr+=2;

                qckcicjnsisj=ch_coskr*cicjnsisj;
                qsksicjpcisj=ch_sinkr*sicjpcisj;

                sum1+=qckcicjnsisj-qsksicjpcisj;
                sum7+=qckcicjnsisj+qsksicjpcisj;

                scratchptr+=4;                  

                qcksicjncisj=ch_coskr*sicjncisj;
                qskcicjpsisj=ch_sinkr*cicjpsisj;

                sum2+=qcksicjncisj+qskcicjpsisj;
                sum4+=qskcicjpsisj-qcksicjncisj;

                qckcicjpsisj=ch_coskr*cicjpsisj;
                qsksicjncisj=ch_sinkr*sicjncisj;

                sum3+=qckcicjpsisj-qsksicjncisj;
                sum5+=qckcicjpsisj+qsksicjncisj;
            }

            s0=sum0;
            s1=sum1;
            s2=sum2;
            s3=sum3;
            s4=sum4;
            s5=sum5;
            s6=sum6;
            s7=sum7;

        }
        measure=mytime()-measure;
        printf("%d %f %d\n",block*6*8,
               24./(1e6*((double) measure/(double)numlaps)),extrarepeat);
        fflush(stdout);

        free(bufm);
        free(scratchm);

        block*=1.5;
    }

}

int main()
{
#ifdef USE_X86_ALIGN_HACK
    void *p;
    __asm__ __volatile__ (" movl %%esp,%0" : "=m" (p) : );
    if (((unsigned long)p) & 0x7)
    {  
        __asm__ __volatile__ (" subl $4,%%esp " : :);  
        printf("Aligned stack.\n");
    } 
#endif
    bench();
    return 0;
}

Final note: The original code does contain proper comments. :-)

-- 
Daniel Spångberg                         
http://www.teoroo.mkem.uu.se/daniels/    
Linux user #47682. http://counter.li.org

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

From: Martin Bertilsson Haagen <[EMAIL PROTECTED]>
Subject: Re: Send a short message (SMS) within a classic modem
Date: Mon, 21 May 2001 19:36:08 +0200



On Mon, 21 May 2001, TF wrote:

> Thank you for youe message,
> 
> I would like to developp an application, sometimes I have to send a SMS
> through this program, I need an example of the communication protocol , to
> insert it in my program
> Thanks,
> TF
> E-mail [EMAIL PROTECTED]

You use an extended AT-commandset to send sms. Check your modem manual,
siemens has a great manual on their site for their phones.

/Martin


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

Subject: Re: Floating point performence problems due to poor stack alignment
From: Daniel Spangberg <[EMAIL PROTECTED]>
Date: 21 May 2001 19:44:02 +0200

Sorry about the invalid mail address. The proper one is
[EMAIL PROTECTED]
-- 
Daniel Spångberg                         
http://www.teoroo.mkem.uu.se/daniels/    
Linux user #47682. http://counter.li.org

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

Subject: Re: Faster than strstr
From: CBFalconer <[EMAIL PROTECTED]>
Reply-To: [EMAIL PROTECTED]
Crossposted-To: comp.lang.c.moderated,comp.lang.c
Date: 21 May 2001 18:42:38 GMT

Ben Pfaff wrote:
> 
> CBFalconer <[EMAIL PROTECTED]> writes:
> 
> > mmf wrote:
> > >
> > > In article <[EMAIL PROTECTED]>, DB <[EMAIL PROTECTED]> wrote:
> > >
> > > >My current project for SPI Dynamics made extensive use of the strstr()
> > > >function to detect malicious activity in web server log files. The
> > > >performance of that search routine was quite a bottleneck while LogAlert
> > > >was detecting exploit strings. The strstr() function seemed to be part
> > > >of the problem, I had to find a way to speed things up.
> > >
> > > why not move laterally? instead of a faster way to repeatedly scan text
> > > why not find a way to scan text once
> >
> > A technique used in ID2ID (to replace id strings in multiple
> > source files in one pass) inputs the candidate strings and forms a
> > binary tree.  It uses an AVL tree to avoid imbalance, but could
> > also use red-black trees. [...]
> 
> If the table of candidate strings does not change during a
> program run, then there's a good chance that a balanced tree is a
> waste of time and too complicated to boot.  I would probably use
> qsort() followed by bsearch() for simplicity or a hand-coded
> binary search for speed, or maybe a hash table or trie, myself.
> 
> Though AVL and red-black trees are pretty, there's an even
> prettier algorithm for giving an ordinary binary tree perfect
> balance in O(n) time and O(1) space.  If you really want to use a
> binary tree, then, for a tree with static content, you can't beat
> this.  Just build a tree that's unbalanced any which way and run
> it through the balancer.

That runs the risk that the initial build can run into evil
conditions, such as a linked list on sorted input.  The tree
builder can then use excessive space for its own recursion.  An
intrinsically balanced entry mechanism avoids all this, and is
relatively impervious to peculiar input sets.

-- 
Chuck F ([EMAIL PROTECTED]) ([EMAIL PROTECTED])
http://www.qwikpages.com/backstreets/cbfalconer :=(down for now)
   (Remove "NOSPAM." from reply address. my-deja works unmodified)
   mailto:[EMAIL PROTECTED]  (for spambots to harvest)
-- 
comp.lang.c.moderated - moderation address: [EMAIL PROTECTED]

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

Date: Mon, 21 May 2001 13:13:40 -0600
From: "D. Stimits" <[EMAIL PROTECTED]>
Reply-To: [EMAIL PROTECTED]
Subject: Re: asynchronous io

Michel Bardiaux wrote:
> 
> [EMAIL PROTECTED] wrote:
> >
> > In article <[EMAIL PROTECTED]>,
> > D. Stimits <[EMAIL PROTECTED]> wrote:
> >
> > >I'm trying to find out if the aio_read is available, and if so,
> > >approximately what kernel version it is available from?
> >
> > Set O_ASYNC and handle SIGIO.
> >
> > --
> > http://www.spinics.net/linux
> 
> O_ASYNC on what?
> 
> Anyway I doubt any of the ioctl, fcntl or whatever, provide asynchronous
> IO on ***DISK*** files. Only aio can do that. So, back to the original
> question: is aio available on Linux?
> 
> --
> Michel Bardiaux
> Peaktime Belgium S.A.  Rue Margot, 37  B-1457 Nil St Vincent
> Tel : +32 10 65.44.15  Fax : +32 10 65.44.10
> Cc Email of replies welcome

In my case, if this helps to narrow things down, I am wanting to use
asynchronous I/O with network sockets.

D. Stimits, [EMAIL PROTECTED]

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

From: [EMAIL PROTECTED] (Matan Ziv-Av)
Subject: Re: [Q]What is frame buffer??... Help
Reply-To: [EMAIL PROTECTED]
Date: Mon, 21 May 2001 17:47:52 GMT

On 18 May 2001 08:55:29 +0400, Victor Wagner wrote:
> Zoran Cutura <[EMAIL PROTECTED]> wrote:
> 
> : I wouldn't recommend framebuffer programming to a newbie. :-(
> 
> : svgalib may be the better alternative.
> 
> No, svgalib is worse. It requires special privilegies to access
> hardware and may hang system, becouse it interfaces hardware on
> to lower level, bypassing some kernel protections.

Accessing the framebuffer requires special privileges, and 
framebuffer may hang the system, becouse it interfaces hardware 
on to lower level.

> BTW, svgalib is inherently non-portable, and there are more chances
> that framebuffer would work on some kind of embedded device.

Svgalib is working on freebsd, while framebuffer is linux specific.



-- 
Matan Ziv-Av.                         [EMAIL PROTECTED]


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

From: [EMAIL PROTECTED] (Philip Armstrong)
Subject: Re: asynchronous io
Date: 21 May 2001 19:01:41 +0100

In article <[EMAIL PROTECTED]>,
Michel Bardiaux  <[EMAIL PROTECTED]> wrote:
>[EMAIL PROTECTED] wrote:
>> In article <[EMAIL PROTECTED]>,
>> D. Stimits <[EMAIL PROTECTED]> wrote:
>> >I'm trying to find out if the aio_read is available, and if so,
>> >approximately what kernel version it is available from?
>> Set O_ASYNC and handle SIGIO.
>O_ASYNC on what? 

The file?

>Anyway I doubt any of the ioctl, fcntl or whatever, provide asynchronous
>IO on ***DISK*** files. Only aio can do that. So, back to the original
>question: is aio available on Linux?

Yes. But it's implemented in the libc, with a thread to handle the
oustanding io (all of which is transparent to the user of the aio
functions). SGI have written a kernel-based implementation of aio
which may or may not find its way into the mainstream kernel at some
point in the future. See http://oss.sgi.com/ for details.

do 

$ info libc

and search for aio for details of the libc implementation.

Phil


-- 
http://www.kantaka.co.uk/ .oOo. public key: http://www.kantaka.co.uk/gpg.txt


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

From: "Paul D. Smith" <[EMAIL PROTECTED]>
Subject: Re: Running an app with a different libc so than the system default?
Date: 21 May 2001 17:25:19 -0400
Reply-To: [EMAIL PROTECTED]

%% Wolfram Gloger <[EMAIL PROTECTED]> writes:

  wg> The _original_ glibc-2.2.3 is known to have problems with certain
  wg> nss_... modules, maybe you're seeing those.  I suspect the latest
  wg> Debian package already has the well known fixes, though.

I think so as well; I'm using testing, not unstable, but I checked and
there's no new glibc in the pipeline in unstable either.

  >> I tried the simple approach of setting LD_LIBRARY_PATH to the directory
  >> with the old stuff, but I get this error:

  wg> Yes, that is not enough, because /lib/ld-linux.so.2 is hardcoded in
  wg> the application's binary.

I figured, from the man page :).

  >> Is there anything else I can do (assuming that something like chroot is
  >> not going to work, as the daemon needs access to the regular system) to
  >> get this working?

  wg> You can use:

  wg> % /opt/wherever/lib/ld-linux.so.2 --library-path /opt/wherever/lib \
  wg>  /foo/bin/app

  wg> to make use of the library installation in /opt/wherever/lib.

Aha!

Awesom!  Would be nice if this were mentioned in the ld-linux.so man
pages or anywhere else :(; I had looked there but no joy.

Are there other cool options to ld.so?  I tried ld-linux.so.2 --help but
it just barked.

Anyway, it actually took a bit of doing because this package has a large
number of apps, in reality, so I wrote a generic shell script to exec
its arguments with the above ld-linux.so.2, then moved the apps and
replaced them with symlinks to this script.

There was a little back and forth, but so far it seems to be working
great!  For a few minutes and about 5 commands so far, but... :)

Thanks!

-- 
===============================================================================
 Paul D. Smith <[EMAIL PROTECTED]>    HASMAT--HA Software Methods & Tools
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist
===============================================================================
   These are my opinions---Nortel Networks takes no responsibility for them.

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

From: [EMAIL PROTECTED] (Grant Edwards)
Subject: How to get rid of 'tempnam is dangerous' warning?
Date: Mon, 21 May 2001 21:52:15 GMT

How do I get rid of the 'tempnam is dangerous' warning?  

Is there a pragma I can use to turn off that warning?

The man pages (and the fcc warning message) all say to use
mkstmp() instead of tempnam(), but the mkstemp()'s semantics
aren't the same, so I can't use it.

I'd really like to have a clean compile with -Wall before
shipping the product, and the tempnam warning is the last
one...

-- 
Grant Edwards                   grante             Yow!  .. my NOSE is NUMB!
                                  at               
                               visi.com            

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


** 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.apps 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-Apps Digest
******************************

Reply via email to