Home > Community > Forums > Functional Verification > memory leak - IUS61 system verilog

Email

* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

 memory leak - IUS61 system verilog 

Last post Mon, Jul 23 2007 2:23 PM by archive. 1 replies.
Started by archive 23 Jul 2007 02:23 PM. Topic has 1 replies and 1260 views
Page 1 of 1 (2 items)
Sort Posts:
  • Mon, Jul 23 2007 2:23 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    memory leak - IUS61 system verilog Reply

    Hello,

    I have a small piece of code that uses the class and mailbox feature of system verilog.  There is a sender task which generates a transactions and puts the transaction handle in a mailbox.  The receiver task waits on a message from the mailbox and when one arrives it reads the message and print a message.  The mailbox is bounded.

    The sender and receiver tasks are forked in an initial block.

    I seem to be experiencing a memory leak since the heap continues to grow.  My understanding is system verilog handles garbage collection automatically.

    What am I doing wrong in my code.  Attached is code:


    module mem_leak ();

    /////////////////////////////////////////////////////////////////////
    // Generate clock and reset
    /////////////////////////////////////////////////////////////////////

    reg clk;

    initial
    begin
        clk = 0;
        forever #(10/2) clk = ~clk;
    end

    /////////////////////////////////////////////////////////////////////
    // Class declarations
    /////////////////////////////////////////////////////////////////////

    class CpuCmd;
        time startT;
        time stopT;
        reg [1:0] cpu_id;

        reg btype;
        rand reg wr_rdn;

        rand reg [26:0] addr;
        rand reg [ 5:0] size;
        reg [39:0] packed_cmd[1:0];
        reg [10:0] total_wd;

        extern task gen_cpu_addr;
        constraint cpucmd_constraint;
    endclass

    constraint CpuCmd::cpucmd_constraint
    {
        addr inside {[0 : 2000]};
        size inside {1, 4};
    }

    task CpuCmd::gen_cpu_addr;

        startT    = $time;
        stopT     = startT;
        cpu_id    = 0;

        btype  = 0;

        packed_cmd[0] = {btype,wr_rdn,3'h0,addr,2'h0,size};
        packed_cmd[1] = 40'h0;

        total_wd = size;

    endtask

    /////////////////////////////////////////////////////////////////////
    // Declarations
    /////////////////////////////////////////////////////////////////////

    // Command queue to hold transactions
    mailbox cmdQ;

    /////////////////////////////////////////////////////////////////////
    // Main client loop
    /////////////////////////////////////////////////////////////////////

    initial
    begin
        repeat (20) @(posedge clk);

        cmdQ  = new(4); // bounded mailbox

        repeat (20) @(posedge clk);

        fork
            begin
                $display("INFO: Fork Sender");
                sender;
            end

            begin
                $display("INFO: Fork receiver");
                receiver;
            end
        join
    end

    ///////////////////////////////////////////
    // Sender
    ///////////////////////////////////////////
    task sender;

       int val;
       CpuCmd Scmd;

       while (1)
       begin
        repeat (1000) @(posedge clk);

        Scmd = new;

        val = Scmd.randomize();
        if (val == 0)
        begin
            $display("Scmd randomization failed at %0t", $time);
            @(posedge clk);
            $finish;
        end

        Scmd.gen_cpu_addr(); // generate a command

        cmdQ.put(Scmd); // put command into mailbox
        $display("Sent message at %0t", $time);
       end
    endtask

    ///////////////////////////////////////////
    // Receiver
    ///////////////////////////////////////////

    task receiver;

       CpuCmd Rcmd;

       while (1)
       begin
               @(posedge clk);
            cmdQ.get(Rcmd); // Get a message from the mailbox
            $display("Received message at %0t", $time);
       end

    endtask

    endmodule


    Originally posted in cdnusers.org by vietnguyen
    • Post Points: 0
  • Wed, Aug 1 2007 10:00 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: memory leak - IUS61 system verilog Reply

    What exact version of IUS are you using?
    I tried running your code on IUS6.11s2 and 6.11s3, but didn't see any sign of increasing memory consumption.
    My tests ran for about 1.5h and passed hundreds of thousands of items through the mailbox.

    Maximum memory consumption was always 29.3 MB no matter how long the test ran for.


    Originally posted in cdnusers.org by stephenh
    • Post Points: 0
Page 1 of 1 (2 items)
Sort Posts:
Started by archive at 23 Jul 2007 02:23 PM. Topic has 1 replies.