Skip to main content

Posts

Some Python snippets -I

Some python snippets that can be useful. I have come up with some requirements in my scripts and searched for the solutions. The working ones are kept here for reference. Counting based on condition of dictionary values. Lets say we have a dictionary with some keys and values like this: { 'a' : 'hello' , 'b' : 'world, 'c' : 'hello' , 'd' : 'junk' } Now if you want to count number of keys that has values as "hello" Here is the snippet for it count = sum ( 1 for x in dict .values() if x == 'hello' ) This will display the count as 2. Returning keys of dictionary of sorted values. Sometimes we have to sort the dictionary with values. I have to get the list of keys in sorted order of values. This snipped does exactly that: sortedKeyList = sorted ( dict ,key= dict .get, reverse= True ) the sortedKeyList is the list of keys of dictionary where the keys are sorted based o...

Linux Disk quota.. Problem of disk quota exceeded

Sometimes.. when i run some commands, I see that the command quits withe error: "Disk quota exceeded". But when i check the disk utilization using "df -h" i have pretty much space left to use. Whats the point of disk quota here. Linux administrators can set quota.. a limit for each user on how much he can fill that File system. The quota limitation if for two aspects: Total space used by user. Total number of files created by user. Lets take an example of user limits are 100GB and 10000 files.  Now for the first point, if user creates 11 files of 10 GB each, then his disk quota is exceeded.  for the second point, if user creates 12000 files of 10KB each, then total space is 120MB, but the limitation of file quota is exceeded, in this case also the disk quota is exceeded. To get user quota on different disk storages: use this command $> quota XXX.XXX.XXX.XXX:/local/------                 243220716  171798...

Waiting on clocking block signals

Its a good practice to use the clocking blocks for creating verification components. There are some scenarios, where you have to wait on change on some values. As an example, when DUT drives the valid signal, in monitor you wait for valid signal and then read other signal on next clock. Lets say the DUT drives a valid signals and in your monitor you have to wait till valid is high and wait for two clocks. Then in your montior, you do something like this: wait ( interface .cb.valid == 1'b1 ); @ interface .cb; @ interface .cb; What do you expect? when valid happens, then wait for two clock cycles. But this may not happen. the first wait and then @interface.cb may happen in same cycle. This is because the clocking block events are synchronous. The wait and the @() statement will execute in same delta. Instead, the best way is to use this: @(tif1.cb iff tif1.cb.data); In this way, you wait every clock only if the cb.data is high. Code: https://www.edaplaygroun...

Sequence Layering in UVM

What is Sequence Layering? Sequence layering is refered to as running sequences inside sequences.  So whats the big deal. There are virtual sequences we will use to run multiple sequences. A generic example of sequence layering. you have two sequences  Interrupt sequence register read write sequence. Generally when you have interrupt, we generally enter into interrupt service routine, which can be implemented as an interrupt sequence. So when you run an interrupt sequence, you might end up running register read /write sequence like polling or clearing interrupts. Well thats easy, just run one sequence in another. class top_seq extends uvm_sequence#(txn_item); //Two sequencers say.. sub sequences. sub_seq1 seq1; sub_seq2 seq2; ... task body(); seq1.start(some_seqr); seq2.start(some_seqr2); endtask endclass Killing sequences: That was great you are running nested sequences. But how to kill them when needed. UVM provides m...

Virtual Sequence and Virtual Sequencer in UVM

Virtual sequences and sequencers in UVM are just virtual containers of multiple sequences and sequencers. Using virtual sequencers and sequences can be done in these three ways: Using only virtual Sequence and handles of sequencers inside the virtual sequence. Using Virtual sequencer to hold the sequencers Same as step 2, by using uvm_declare_p_sequencer. Virtual Sequencer does not create any sequencer objects, rather it points to other physical sequencers in different agents.  Virtual Sequencer extends from uvm_sequencer. Virtual sequence will create its sequences and start them. Running sequences can be controlled by user in the body() task. virtual sequence extends from uvm_sequence. METHOD-1: In this method, we will have one base virtual sequence which will hold the handles to different sequencers. Here we dont use any virtual sequencer. We just use the nested seqeunces with handles ot sequencers inside sequence itself. //This is the base virtual se...

python process real time output

Real Time Output Issue resolved: I did encountered similar issue in Python, while capturing the real time output from c program. I added " fflush(stdout) ;" in my C code. It worked for me. Here is the snip the code << C Program >> #include <stdio.h> void main () { int count = 1 ; while ( 1 ) { printf ( " Count %d\n" , count ++); fflush ( stdout ); sleep ( 1 ); } } << Python Program >> #!/usr/bin/python import os , sys import subprocess procExe = subprocess . Popen ( ".//count" , shell = True , stdout = subprocess . PIPE , stderr = subprocess . PIPE , universal_newlines = True ) while procExe . poll () is None : line = procExe . stdout . readline () print ( "Print:" + line ) << OUTPUT>> Print: Count 1 Print: Count 2 Print: Count 3 UPDATE:: The above one has flaws as we are reading only oneline per poll iteratio...