Buffer flush after 'writeline' 
Author Message
 Buffer flush after 'writeline'

Hello,

the VHDL function "writeline( fp, line )" seems to use buffered I/O
on Unix platforms (at least Mentor quickhdl). Does anybody know how
to force a buffer flush after a writeline() ?

Thanks in advance for any answer.

Hans-Juergen Heinrichs



Sat, 01 Apr 2000 03:00:00 GMT  
 Buffer flush after 'writeline'


Quote:

>the VHDL function "writeline( fp, line )" seems to use buffered I/O
>on Unix platforms (at least Mentor quickhdl). Does anybody know how
>to force a buffer flush after a writeline() ?

The procedure WRITELINE is often written in C by the simulator vendor.
MTI provides the following code as representative code for the procedure.  
The deallocate of the line follows the write of the line to the file or to
the output (screen).    See procedure below.   FOr a specific deallocate,
just add the deallocate procedure as shown below:
 Deallocate(L);  -- where is is the varaiable of type line.
Again, this SHOULD NOT BE NECESSARY AFTER the WRITELINE.   If you
simulator exhibits a memory leak because it does not automatically provide
the deallocate, then you should contact that vendor, and he should fix his
code.  
\---
    procedure WRITELINE(file f : TEXT; L : inout LINE)
    --procedure WRITELINE(f : out TEXT; L : inout LINE)
    is
    begin
        if L /= null then
            write(f, L.all & LF);
            Deallocate(L);
        else
            -- Write a blank line
            write(f, (1 => LF));
        end if;
    end;
--=============================================
-- Ben Cohen, Hughes Aircraft Co,  RE- R1/B507
-- ** "VHDL Coding Styles and Methodologies",
--     ISBN 0-7923-9598-0  Kluwer Academic Publishers, 1995.
-- ** "VHDL Answers to Frequently Asked Questions"  
--     ISBN 0-7923-9791-6 Kluwer Academic Publishers, 1996.
-- FTP site:   users.aol.com       /vhdlcohen/vhdl
-- Web page:   http://members.aol.com/vhdlcohen/vhdl
-- (310) 334-7389,      fax: (310) 334-1749
--=============================================


Sun, 02 Apr 2000 03:00:00 GMT  
 Buffer flush after 'writeline'

This is a multi-part message in MIME format.

--------------2A956D596E60
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Quote:

> Hello,

> the VHDL function "writeline( fp, line )" seems to use buffered I/O
> on Unix platforms (at least Mentor quickhdl). Does anybody know how
> to force a buffer flush after a writeline() ?

> Thanks in advance for any answer.

> Hans-Juergen Heinrichs


        Hi,

I'm not aware of any VHDL way of flushing such a buffer. The problem
is that an implementation will call most probably some fprintf()
library function on Unix.

Now fprintf() is normally line buffered for stdout (screen output) and
fully buffered for files. This means that for screen output the
implicit newline in writeline will cause the flushing of the buffer.
For files, flushing is only done on a full buffer, a file close or
an explicit flush() call. This is however not possible in VHDL.

On the other side exists unix library calls to change this default
buffering.

I think your only chance is a simulator option that changes this
default buffering behaviour. In CADENCE leapfrog, f.i., there's
a switch -UNBUFFERED which solves this problem.

Hope it helps anyway ...

--------------2A956D596E60

Content-Transfer-Encoding: 7bit

=== Expressed opinions are not necessarily those of Alcatel ===

     \\\|///      ir. Jos De Laender
     ( 0 0 )      Alcatel - SSD (Switching Systems Division)
   oo0-(_)-0oo    ASIC design - VH14                
  _\   ' `   /_
  \ \ALCATEL/ /   F. Wellesplein 1, B-2018 Antwerp, Belgium
   \ \     / /                                

     \ \ / /                                                                
     o0 Y 0o      Alcatel Bell    : http://www.bel.alcatel.be
       \|/        Alcatel Telecom : http://www.alcatelecom.be
        *         Phone           : (32)(0) 3 240 74 61
                  Fax             : (32)(0) 3 240 99 47

--------------2A956D596E60--



Sun, 02 Apr 2000 03:00:00 GMT  
 Buffer flush after 'writeline'

Quote:



> >the VHDL function "writeline( fp, line )" seems to use buffered I/O
> >on Unix platforms (at least Mentor quickhdl). Does anybody know how
> >to force a buffer flush after a writeline() ?

> The procedure WRITELINE is often written in C by the simulator vendor.
> MTI provides the following code as representative code for the procedure.
> The deallocate of the line follows the write of the line to the file or to
> the output (screen).    See procedure below.   FOr a specific deallocate,
> just add the deallocate procedure as shown below:
>  Deallocate(L);  -- where is is the varaiable of type line.
> Again, this SHOULD NOT BE NECESSARY AFTER the WRITELINE.   If you
> simulator exhibits a memory leak because it does not automatically provide
> the deallocate, then you should contact that vendor, and he should fix his
> code.

Hmm, Ben, I think you missed the point here.  The original post was
wanting
to see the ouput of the write statement; he wasn't concerned with
recovering
the memory.

In all but 1 of the cases that I have tried it; an easy solution is to
declare
the FILE inside a procedure.  The file is then opened whenever the
procedure
is called and is closed (thereby flushing the buffers) whenever the
procedure exits.  There was a problem with this approach in one version
of the Viewlogic simulator 3 or 4 years ago as it opened the file for
writing at the _TOP_ rather than at the bottom; thus you had a file that
contained only the last line written to it.

--

Efficient Networks, Inc                 'ATM for the Desktop'
4201 Spring Valley, Suite 1200          http://www.efficient.com/
Dallas,  TX  75244                      (972) 991-3884



Mon, 03 Apr 2000 03:00:00 GMT  
 Buffer flush after 'writeline'

Quote:


> > the VHDL function "writeline( fp, line )" seems to use buffered I/O
> > on Unix platforms (at least Mentor quickhdl). Does anybody know how
> > to force a buffer flush after a writeline() ?

> I'm not aware of any VHDL way of flushing such a buffer. The problem
> is that an implementation will call most probably some fprintf()
> library function on Unix.

For the truly brave-hearted, you could try and bootstrap the
library routines. I guess the best one to choose is fopen().
You could turn off buffering for all files, or be clever and
see which file is being opened in the fopen() call.

One thing you could do is replace your libc.so with the GNU
C library with the fopen() call modified appropriately.

Alternatively, you can bootstrap a single routine using
the LD_PRELOAD environment variable.
--
"To YOU I'm an atheist; to God, I'm the Loyal Opposition."
    -- Woody Allen


WWW    : http://homepages.munich.netsurf.de/Jonathan.Connell/
Fax    : +49 89 636-82692      |     Tel : +49 89 636-82687



Tue, 04 Apr 2000 03:00:00 GMT  
 Buffer flush after 'writeline'


Quote:

>Hmm, Ben, I think you missed the point here.  The original post was
>wanting to see the ouput of the write statement; he wasn't concerned with
>recovering the memory.

Charles,
I may have missed the point. I felt that the question was anbiguous.  My
response came from the point of view that the simulator may not have
deallocated the line after the writeline, thus causing a memory leak
problem.    I have seen a similar leak in the READLINE procedure from
Leapfrog simulator. We were reading a long file containing compare data
generated from a C program.  After 2 hours of simulator, the simulator
{*filter*}because of lack of system resourses on a Sun workstation with 1.6 BB
of virtual memory.  This was the release prior to 97A.  
I don't know if that vendor has fixed the problem in his latest release.
We passed the info to Cadence.  
Cheers,

--=============================================
-- Ben Cohen, Hughes Aircraft Co,  RE- R1/B507
-- ** "VHDL Coding Styles and Methodologies",
--     ISBN 0-7923-9598-0  Kluwer Academic Publishers, 1995.
-- ** "VHDL Answers to Frequently Asked Questions"  
--     ISBN 0-7923-9791-6 Kluwer Academic Publishers, 1996.
-- FTP site:   users.aol.com       /vhdlcohen/vhdl
-- Web page:   http://www.*-*-*.com/
-- (310) 334-7389,      fax: (310) 334-1749
--=============================================



Tue, 04 Apr 2000 03:00:00 GMT  
 Buffer flush after 'writeline'



Quote:


> > > the VHDL function "writeline( fp, line )" seems to use buffered I/O
> > > on Unix platforms (at least Mentor quickhdl). Does anybody know how
> > > to force a buffer flush after a writeline() ?

> > I'm not aware of any VHDL way of flushing such a buffer. The problem
> > is that an implementation will call most probably some fprintf()
> > library function on Unix.

> For the truly brave-hearted, you could try and bootstrap the
> library routines. I guess the best one to choose is fopen().
> You could turn off buffering for all files, or be clever and
> see which file is being opened in the fopen() call.

> One thing you could do is replace your libc.so with the GNU
> C library with the fopen() call modified appropriately.

> Alternatively, you can bootstrap a single routine using
> the LD_PRELOAD environment variable.

I have this same problem using Model Technologies V-System under windoze
95.
When my simulation finishes, I have to then select the "end simulation"
menu item or exit the simulator in order to see the last few lines of my
log files, which is a shame, because it's usually the last few lines that
are the most interesting.

I don't think the library replacement trick works in windoze.

Allan.



Sun, 09 Apr 2000 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. 'flush' and efficiency

2. buffer size with 'read'

3. flushing buffers when closing a file with STATUS='DELETE'

4. Can't get stderr to flush

5. flush of Sun Fotran doesn't work?

6. flush doesn't work with dec3100 f77 compiler

7. expect: Can't flush.

8. Flushing a file buffer in awk.

9. Optimising Browse Load with Buffering using STREAM and FLUSH

10. Flushing buffer to disk

11. How do I flush the serial port buffer?

12. Best word to flush output buffer

 

 
Powered by phpBB® Forum Software