• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Functional Verification
  3. memory leak - IUS61 system verilog

Stats

  • Locked Locked
  • Replies 1
  • Subscribers 64
  • Views 1912
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

memory leak - IUS61 system verilog

archive
archive over 18 years ago

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
  • Cancel
Parents
  • archive
    archive over 18 years ago

    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
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • archive
    archive over 18 years ago

    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
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information