<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.freebsd.org/bugzilla/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.freebsd.org/bugzilla/"
          
          maintainer="bugmeister@FreeBSD.org"
>

    <bug>
          <bug_id>295043</bug_id>
          
          <creation_ts>2026-05-06 01:34:48 +0000</creation_ts>
          <short_desc>pf: per-packet microuptime() calls from 0493260115db cause major throughput regression with expensive timecounters</short_desc>
          <delta_ts>2026-07-18 19:04:10 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>Base System</product>
          <component>kern</component>
          <version>15.0-RELEASE</version>
          <rep_platform>amd64</rep_platform>
          <op_sys>Any</op_sys>
          <bug_status>In Progress</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>regression</keywords>
          <priority>---</priority>
          <bug_severity>Affects Some People</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Justin Worrell">jworrell</reporter>
          <assigned_to name="Kristof Provost">kp</assigned_to>
          <cc>emaste</cc>
    
    <cc>jworrell</cc>
    
    <cc>kp</cc>
    
    <cc>mike</cc>
    
    <cc>quentin.thebault</cc>
          

      

      

      <flag name="mfc-stable14"
          id="100107"
          type_id="11"
          status="?"
          setter="linimon"
    />

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1421608</commentid>
    <comment_count>0</comment_count>
    <who name="Justin Worrell">jworrell</who>
    <bug_when>2026-05-06 01:34:48 +0000</bug_when>
    <thetext>Commit 0493260115db (&quot;pf: store state creation/expiration timestamps
with millisecond precision&quot;) replaced time_uptime reads with
microuptime() calls via pf_get_uptime() in pf&apos;s per-packet state expire
update path. On systems using HPET (common in KVM guests without ITSC),
this is extremely expensive.
 
https://github.com/freebsd/freebsd-src/commit/0493260115db10164246762d6d4923880575e529
 
Measurements (FreeBSD/KVM guest, iperf3, pf enabled with stateful rules):
 
  vtnet,  HPET:     ~2.3 Gbit/s
  vtnet,  TSC-low:  ~9   Gbit/s
  ixl passthrough + VLANs, HPET:    &lt;1   Gbit/s
  ixl passthrough + VLANs, TSC-low: ~9   Gbit/s
  pf disabled, any timecounter:     ~9   Gbit/s
 
  kern.timecounter.choice: TSC-low(-100) i8254(0) ACPI-fast(900) HPET(950) dummy(-1000000)
 
TSC-low is distrusted because the hypervisor doesn&apos;t expose ITSC to the
guest, which is common in many KVM configurations.
 
How to reproduce:
 
In a VM with pf enabled and stateful rules:
 
  sysctl kern.timecounter.hardware=HPET
  iperf3 -c &lt;target&gt;    # observe reduced throughput
  sysctl kern.timecounter.hardware=TSC-low
  iperf3 -c &lt;target&gt;    # throughput restored
 
Possible approaches:
 
The millisecond precision is primarily needed by pflow(4) at export
time, not per packet. Defaulting pf_get_uptime() to
(uint64_t)time_uptime * 1000 would preserve the data model changes
while eliminating the per-packet timecounter read. The precise
microuptime() path could be gated behind a sysctl for pflow users who
need it.
 
Alternatively, the patch could use getmicrouptime() instead of
microuptime(). The former returns a cached value without querying the
hardware timecounter, which is what the man page recommends when
execution time matters more than precision.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1424948</commentid>
    <comment_count>1</comment_count>
    <who name="">commit-hook</who>
    <bug_when>2026-05-21 21:20:10 +0000</bug_when>
    <thetext>A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=e4130ac13d2fe9c17b8f8e86d39a7b5223fe7b79

commit e4130ac13d2fe9c17b8f8e86d39a7b5223fe7b79
Author:     Kristof Provost &lt;kp@FreeBSD.org&gt;
AuthorDate: 2026-05-21 11:31:11 +0000
Commit:     Kristof Provost &lt;kp@FreeBSD.org&gt;
CommitDate: 2026-05-21 21:19:50 +0000

    pf: switch to getmicro(up)time()

    It is reported that micro(up)time() performs poorly in certain
    virtualisation scenarios. Absolute accuracy isn&apos;t required here, so
    switch to the slightly less accurate (as per the man page) get-variants.

    PR:             295043
    MFC after:      3 weeks
    Sponsored by:   Rubicon Communications, LLC (&quot;Netgate&quot;)

 sys/net/pfvar.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1428763</commentid>
    <comment_count>2</comment_count>
    <who name="">commit-hook</who>
    <bug_when>2026-06-11 20:29:15 +0000</bug_when>
    <thetext>A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=a9ebef44a473b1262abad53a22855317c9406948

commit a9ebef44a473b1262abad53a22855317c9406948
Author:     Kristof Provost &lt;kp@FreeBSD.org&gt;
AuthorDate: 2026-05-21 11:31:11 +0000
Commit:     Kristof Provost &lt;kp@FreeBSD.org&gt;
CommitDate: 2026-06-11 20:21:57 +0000

    pf: switch to getmicro(up)time()

    It is reported that micro(up)time() performs poorly in certain
    virtualisation scenarios. Absolute accuracy isn&apos;t required here, so
    switch to the slightly less accurate (as per the man page) get-variants.

    PR:             295043
    MFC after:      3 weeks
    Sponsored by:   Rubicon Communications, LLC (&quot;Netgate&quot;)

    (cherry picked from commit e4130ac13d2fe9c17b8f8e86d39a7b5223fe7b79)

 sys/net/pfvar.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>