{"id":14215,"date":"2020-05-07T09:34:45","date_gmt":"2020-05-07T13:34:45","guid":{"rendered":"https:\/\/blogs.mentor.com\/verificationhorizons\/?p=14215"},"modified":"2026-03-27T08:51:04","modified_gmt":"2026-03-27T12:51:04","slug":"uvm-configuration-db-guidelines","status":"publish","type":"post","link":"https:\/\/blogs.sw.siemens.com\/verificationhorizons\/2020\/05\/07\/uvm-configuration-db-guidelines\/","title":{"rendered":"UVM Configuration DB Guidelines"},"content":{"rendered":"<h3>Introduction<\/h3>\n<p>My previous blog posts were on static and parameterized classes to get you ready for the big game \u2013 the UVM Configuration Database or uvm_config_db. When used properly, this is a great way for one component to share a value with another. If the test or environment knows the path to the agent, the DB is efficient. Used improperly and it will bring your simulation to its knees.<\/p>\n<h3>Too Many Choices<\/h3>\n<p>The DB is that it is based on an associative array with a string index. So each entry is a name-value pair. If you store 100,000 values, the DB has to search these to find the particular value. If the array index values are organized as a tree, searching may require up to 20 string comparisons. Here is the DB with 100,000 entries.<\/p>\n<p><a href=\"https:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/54\/2020\/05\/db_100k.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-14218\" src=\"https:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/54\/2020\/05\/db_100k.png\" alt=\"\" width=\"234\" height=\"83\" \/><\/a><\/p>\n<p>Since this is a parameterized class, each specialization with a different type divides the size of the database. Perhaps half your configuration values are 32-bit integers, and the other half 64-bit values. Each DB access is now looking through half as many values.<\/p>\n<p><a href=\"https:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/54\/2020\/05\/db_50-50.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-14217\" src=\"https:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/54\/2020\/05\/db_50-50-520x224.png\" alt=\"\" width=\"292\" height=\"126\" \/><\/a><\/p>\n<h3>The Wild Problem<\/h3>\n<p>The DB further organizes the name-value pairs by adding a scope to each name. The &#8220;speed&#8221; value can take a very different meaning for a memory compared to a processor.<\/p>\n<p>How does a component share values across the entire testbench? I saw a memory component that wanted to share the memory speed to EVERY component, regardless of location. So it made the following call.<\/p>\n<pre>uvm_config_db#(int)::set(null, \u201c*\u201d, \u201cmem_speed\u201d, mem_speed);<\/pre>\n<p>The problem is that when you call get() , and the DB contains entries with wildcard scopes, the DB has to perform regular expression matching, which is much less efficient than a straight string match. Worse yet, the DB can&#8217;t do a tree-search, and instead has to compare every entry. If your DB only contains a few hundred entries, no problem, but if there are hundreds of thousands, all with wildcards, the runs very slowly. How bad? These wildcard scopes for the memory speed caused the UVM build_phase() to take 24 hours, even though the rest of the simulation took less than an hour. If your testbench is getting large, keep an eye out for this problem!<\/p>\n<h3>Act Locally<\/h3>\n<p>As mentioned in the webinar, one solution is to group configuration variables together into a \u201cconfig object\u201d. For example, an agent config has its local parameters such as the active\/passive enum, various address and data values, and the virtual interface.\u00a0 If each config object holds just 10 values, the DB size drops by 10x. An agent\u2019s build_phase has a single DB call to get the handle to its config object. When the agent wants an individual value, it just uses the handle to get the value in its local object. Caching values in a config object is much faster than another DB access.<\/p>\n<h3>Think Globally<\/h3>\n<p>Another solution for the wildcard problem is a \u201cglobal scope\u201d. Remember, the scopes in the DB do NOT have to match your testbench hierarchy. The memory component could write its value in a unique name space at the top of the DB, such as \u201cmem\u201d shown here.<\/p>\n<pre>uvm_config_db#(int)::set(null, \u201cmem\u201d, \u201cspeed\u201d, memory_speed);<\/pre>\n<p>What if you have multiple memory components? In this global scope of \u201cmem\u201d, you could store a separate config object handle for each instance, assuming &#8220;speed&#8221; is a property in the mem_cfg class.<\/p>\n<pre>foreach (mem_cfg[i])\n  uvm_config_db#(mem_cfg)::set(null, \u201cmem\u201d, \n                               $sformatf(\u201cmem[%0d]\u201d, i), mem_cfgs[i]);\n<\/pre>\n<h3>More tips<\/h3>\n<p>Don&#8217;t call super.build_phase() for components directly derived from a UVM component class such as uvm_component, uvm_test, uvm_env, uvm_agent, etc. This avoids the expensive apply_config_settings().<\/p>\n<p>A wildcard at the end of a scope string, such as \u201cagt*\u201d has fewer matches and better performance than wildcards at the front, such as \u201c*\u201d.<\/p>\n<h3>Conclusion<\/h3>\n<p>A flat uvm_config_db with wildcard scopes and many entries can be a performance hog. Divide the DB into smaller domains by grouping values into config objects. You can use wildcards in the scope strings, but limit them to the end of the string to help performance.<\/p>\n<p><em>Enjoy your verification journey!<br \/>\nChris Spear<\/em><\/p>\n<p>Keep learning at <a href=\"http:\/\/mentor.com\/training\" target=\"_blank\" rel=\"noopener\">mentor.com\/training<\/a><br \/>\nQuestions or ideas? <a href=\"https:\/\/verificationacademy.com\/ask-chris-spear\" target=\"_blank\" rel=\"noopener\">verificationacademy.com\/ask-chris-spear<\/a><br \/>\nView my recent webinar on <a href=\"https:\/\/verificationacademy.com\/sessions\/uvm-coding-guidelines-tips-and-tricks-you-probably-didnt-know\" target=\"_blank\" rel=\"noopener\">UVM Coding Guidelines<\/a> and the <a href=\"https:\/\/verificationacademy.com\/sessions\/uvm-coding-guidelines-tips-and-tricks-you-probably-didnt-know\/rte\/questions--answers\" target=\"_blank\" rel=\"noopener\">Questions and Answers<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction My previous blog posts were on static and parameterized classes to get you ready for the big game \u2013&#8230;<\/p>\n","protected":false},"author":71586,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spanish_translation":"","french_translation":"","german_translation":"","italian_translation":"","polish_translation":"","japanese_translation":"","chinese_translation":"","footnotes":""},"categories":[7,1,982,10,983],"tags":[382,391,393,512,515,585,594,612,614,634,648,735,736,737,751,787,791,805,831],"industry":[],"product":[],"coauthors":[980],"class_list":["post-14215","post","type-post","status-publish","format-standard","hentry","category-learning-resources","category-news","category-systemverilog","category-tips-tricks","category-uvm","tag-class","tag-config-object","tag-configuration-object","tag-global","tag-handle","tag-member","tag-method","tag-object-oriented-programming","tag-oop","tag-performance","tag-property","tag-static","tag-static-method","tag-static-property","tag-systemverilog","tag-uvm","tag-uvm-configuration-database","tag-uvm_config_db","tag-verilog"],"_links":{"self":[{"href":"https:\/\/blogs.sw.siemens.com\/verificationhorizons\/wp-json\/wp\/v2\/posts\/14215","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.sw.siemens.com\/verificationhorizons\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.sw.siemens.com\/verificationhorizons\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/verificationhorizons\/wp-json\/wp\/v2\/users\/71586"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/verificationhorizons\/wp-json\/wp\/v2\/comments?post=14215"}],"version-history":[{"count":1,"href":"https:\/\/blogs.sw.siemens.com\/verificationhorizons\/wp-json\/wp\/v2\/posts\/14215\/revisions"}],"predecessor-version":[{"id":18194,"href":"https:\/\/blogs.sw.siemens.com\/verificationhorizons\/wp-json\/wp\/v2\/posts\/14215\/revisions\/18194"}],"wp:attachment":[{"href":"https:\/\/blogs.sw.siemens.com\/verificationhorizons\/wp-json\/wp\/v2\/media?parent=14215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/verificationhorizons\/wp-json\/wp\/v2\/categories?post=14215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/verificationhorizons\/wp-json\/wp\/v2\/tags?post=14215"},{"taxonomy":"industry","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/verificationhorizons\/wp-json\/wp\/v2\/industry?post=14215"},{"taxonomy":"product","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/verificationhorizons\/wp-json\/wp\/v2\/product?post=14215"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/verificationhorizons\/wp-json\/wp\/v2\/coauthors?post=14215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}