Coverage Sampling Race condition

Hi,

Could you please let me know if there is anything wrong with below code.
I am getting race condition e.g
CLK 1 : At the posedge of clk1 req,x,y and z goes high so rose edge of “req” is getting sampled at next clk2 as expected
CLK 2 : At posedge of this clk Property is evaluated as true as $rose sampled is true and it calls sample function ,simultaneously at the same posedge z,y,z and req changes to 0.At this point value of x,y and z is sampled 0 inside covergroup not 1 as I was expecting.
I used $sampled function for debug it shows expected sampled valued 1 for x,y,z when property is evaluated to true. but covergoup is taking current value of x,y,z.

module(input logic x, input logic y, input logic z,input logic req,input logic reset)

covergroup xyz with function sample();
  
   x_cp     : coverpoint x ;
   y_cp     : coverpoint y;
   z_cp     : coverpoint z;

endgroup

property xyz_sample
@(posedge clk) disable iff(reset) $rose(req) ##0 (1,xyz_inst.sample());
endproperty :xyz_sample

 xyz_prop :cover property (xyz_sample)
 $display ("Sampled  values :X %d, Y=%d, Z=%d",$sampled(x),$sampled(y),$sampled(z));

Thanks

That is the correct behavior. The coverpoint expressions evaluate upon calling the sample method using the current values of all identifiers. Only the identifier that appear withing the scope of the property are implicitly sampled. That is why you had to use $sample() in the action block of the cover statement to get the sampled values of x, y, and z. Otherwise you would have $display’ed the current values.

So you can

  1. Change the way you initiate the call to sample()
  2. Change the coverpoint expressions to use sampled values either by calling $sample, or using clocking block sampled input varaibles
  3. Change the covergroup function sample() to include arguments
covergroup xyz with function sample(logic cx,cy,xz));
x_cp     : coverpoint cx ;
y_cp     : coverpoint cy;
z_cp     : coverpoint cz;
endgroup
property xyz_sample
@(posedge clk) disable iff(reset) $rose(req) ##0 (1,xyz_inst.sample(x,y,z));
endproperty :xyz_sample

Now the x,y,z in the call to the sample method uses the sampled values because it is within the scope of the property.

BTW, in your original example, the with function sample() is superfluous because it has no arguments, so it does nothing to override the default sample behavior.

In reply to dave_59:

Hi Dave,

Thanks for response.It works.
In my actual scenario I need to sample the coverage only after satisfying some complex temporal sequences and then I need to pass many signals in port list.
Could you suggest any other method without passing arguments.Would it work if I call sample function in always block as it works in active region .

Thanks,
Gagan