# Obtaining the time spent in the ingress control block in BMv2

**URL:** <https://forum.p4.org/t/obtaining-the-time-spent-in-the-ingress-control-block-in-bmv2/1201>\
**Category:** Getting Started with P4\
**Created:** [August 29, 2024, 2:41pm UTC](https://forum.p4.org/t/obtaining-the-time-spent-in-the-ingress-control-block-in-bmv2/1201 "2024-08-29T14:41:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxpeng](https://avatars.discourse-cdn.com/v4/letter/m/c5a1d2/32.png) [@maxpeng](https://forum.p4.org/u/maxpeng)\
**Post date:** [August 29, 2024, 2:41pm UTC](https://forum.p4.org/t/obtaining-the-time-spent-in-the-ingress-control-block-in-bmv2/1201/1 "2024-08-29T14:41:08Z")

</div>

Hello everyone,  
As you may see in the title, I am trying to obtain the time spent in the ingress control block of a packet. But I am not sure what is the best way to do (approximate) this.  
What I can think of is by calculating: standard\_metadata.egress\_global\_timestamp - standard\_metadata.enq\_timestamp.  
Any idea or advice is greatly appreciated!

---

<div class="post-metadata">

**Author:** ![vgurevich](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.p4.org/vgurevich/32/23_2.png) [@vgurevich](https://forum.p4.org/u/vgurevich)\
**Post date:** [August 29, 2024, 2:46pm UTC](https://forum.p4.org/t/obtaining-the-time-spent-in-the-ingress-control-block-in-bmv2/1201/2 "2024-08-29T14:46:01Z")

</div>

Dear @maxpeng,

I would recommend you read [this post](https://forum.p4.org/t/use-these-three-magic-words-to-ask-your-p4-questions-like-a-pro/966) and edit your question accordingly, so that we can provide you with a proper answer.

Happy hacking,  
Vladimir

---

<div class="post-metadata">

**Author:** ![maxpeng](https://avatars.discourse-cdn.com/v4/letter/m/c5a1d2/32.png) [@maxpeng](https://forum.p4.org/u/maxpeng)\
**Post date:** [August 29, 2024, 3:11pm UTC](https://forum.p4.org/t/obtaining-the-time-spent-in-the-ingress-control-block-in-bmv2/1201/3 "2024-08-29T15:11:20Z")

</div>

Thank you for providing a clearer way to ask questions!  
I am doing experiments using BMv2, which uses the V1Model.  
I would like to also supply some more background information on why am I asking this question. I have implemented a sketch design that does the flow size estimation. All update or query operations are done within the ingress control block. Right now I need to know the time needed for a query operation, approximated if it’s infeasible to obtain the exact time. Since the query operation is done in the ingress control block, I believe the time of a query packet spent in the ingress control block can be regarded as the time needed for a query operation.

---

<div class="post-metadata">

**Author:** ![p4prof](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.p4.org/p4prof/32/251_2.png) [@p4prof](https://forum.p4.org/u/p4prof)\
**Post date:** [August 29, 2024, 6:30pm UTC](https://forum.p4.org/t/obtaining-the-time-spent-in-the-ingress-control-block-in-bmv2/1201/4 "2024-08-29T18:30:21Z")

</div>

@maxpeng ,

Thank you for the clarification.

In this case, the best way to measure the time it took to process the packet in the ingress pipeline would be to subtract [`standard_metadata.ingress_global_timestamp`](https://github.com/p4lang/p4c/blob/main/p4include/v1model.p4#L97) from [`standard_metadata.enq_timestamp`](https://github.com/p4lang/p4c/blob/main/p4include/v1model.p4#L86). Please, note that the former has the type `bit<48>`, whereas the latter is a `bit<32>` value, so casting will be needed.

Having said that, please be aware that due to the software nature of BMv2 and its overall architecture (that emphasizes fidelity and modularity rather than performance), that number will most probably be quite useless as will be most other performance measurements done on that target. Certainly, you can try to understand the performance of the program on the target in a given set of circumstances, but any conclusions you might draw from those numbers will probably be incorrect.

Happy hacking,  
Vladimir

---

<div class="post-metadata">

**Author:** ![maxpeng](https://avatars.discourse-cdn.com/v4/letter/m/c5a1d2/32.png) [@maxpeng](https://forum.p4.org/u/maxpeng)\
**Post date:** [August 30, 2024, 7:14am UTC](https://forum.p4.org/t/obtaining-the-time-spent-in-the-ingress-control-block-in-bmv2/1201/5 "2024-08-30T07:14:11Z")

</div>

@p4prof ,  
Thank you so much for your answer, it is quite inspiring.  
Just one more thing, does this mean that any performance test like throughput or the query time that I have mentioned ought to be carried out on hardware switches like a Tofino switch?

---

<div class="post-metadata">

**Author:** ![andyfingerhut](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.p4.org/andyfingerhut/32/17_2.png) [@andyfingerhut](https://forum.p4.org/u/andyfingerhut)\
**Post date:** [August 30, 2024, 1:52pm UTC](https://forum.p4.org/t/obtaining-the-time-spent-in-the-ingress-control-block-in-bmv2/1201/6 "2024-08-30T13:52:59Z")

</div>

Pretty much all throughput or latency tests will be specific to the target device on which you obtain them, and might not tell you much, if anything, that would help you predict performance on another different target device.

---

<div class="post-metadata">

**Author:** ![maxpeng](https://avatars.discourse-cdn.com/v4/letter/m/c5a1d2/32.png) [@maxpeng](https://forum.p4.org/u/maxpeng)\
**Post date:** [August 30, 2024, 2:51pm UTC](https://forum.p4.org/t/obtaining-the-time-spent-in-the-ingress-control-block-in-bmv2/1201/7 "2024-08-30T14:51:50Z")

</div>

@andyfingerhut ,  
I understand now. Thank you very much for this information!
