Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 10 Jan 2025 09:58:26 -0700
From:      Warner Losh <imp@bsdimp.com>
To:        Jessica Clarke <jrtc27@freebsd.org>
Cc:        Mark Johnston <markj@freebsd.org>,  "src-committers@freebsd.org" <src-committers@freebsd.org>,  "dev-commits-src-all@freebsd.org" <dev-commits-src-all@freebsd.org>,  "dev-commits-src-main@freebsd.org" <dev-commits-src-main@freebsd.org>
Subject:   Re: git: 6b82130e6c9a - main - clock: Add a long ticks variable, ticksl
Message-ID:  <CANCZdfrt6ezJdeRKpKQzo7k5PPuznb253Ljx=w7_UVzTg7hkeQ@mail.gmail.com>
In-Reply-To: <040B6FE0-1C9F-411F-BFA9-D578462C572E@freebsd.org>
References:  <202501101600.50AG0jk6062308@gitrepo.freebsd.org> <9B1B709F-5828-489C-81B5-74ED9E4502FC@freebsd.org> <040B6FE0-1C9F-411F-BFA9-D578462C572E@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
--0000000000007d90f7062b5d015b
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Fri, Jan 10, 2025 at 9:55=E2=80=AFAM Jessica Clarke <jrtc27@freebsd.org>=
 wrote:

> On 10 Jan 2025, at 16:37, Jessica Clarke <jrtc27@FreeBSD.org> wrote:
> > On 10 Jan 2025, at 16:00, Mark Johnston <markj@FreeBSD.org> wrote:
> >>
> >> The branch main has been updated by markj:
> >>
> >> URL:
> https://cgit.FreeBSD.org/src/commit/?id=3D6b82130e6c9add4a8892ca897df5a0e=
c04663ea2
> >>
> >> commit 6b82130e6c9add4a8892ca897df5a0ec04663ea2
> >> Author:     Mark Johnston <markj@FreeBSD.org>
> >> AuthorDate: 2025-01-10 15:37:07 +0000
> >> Commit:     Mark Johnston <markj@FreeBSD.org>
> >> CommitDate: 2025-01-10 15:42:59 +0000
> >>
> >>   clock: Add a long ticks variable, ticksl
> >>
> >>   For compatibility with Linux, it's useful to have a tick counter of
> >>   width sizeof(long), but our tick counter is an int.  Currently the
> >>   linuxkpi tries paper over this difference, but this cannot really be
> >>   done reliably, so it's desirable to have a wider tick counter.  This
> >>   change introduces ticksl, keeping the existing ticks variable.
> >>
> >>   Follow a suggestion from kib to avoid having to maintain two separat=
e
> >>   counters and to avoid converting existing code to use ticksl: change
> >>   hardclock() to update ticksl instead of ticks, and then use assemble=
r
> >>   directives to make ticks and ticksl overlap such that loading ticks
> >>   gives the bottom 32 bits.  This makes it possible to use ticksl in t=
he
> >>   linuxkpi without having to convert any native code, and without maki=
ng
> >>   hardclock() more complicated or expensive.  Then, the linuxkpi can b=
e
> >>   modified to use ticksl instead of ticks.
> >>
> >>   Reviewed by:    olce, kib, emaste
> >>   MFC after:      1 month
> >>   Differential Revision:  https://reviews.freebsd.org/D48383
> >> ---
> >> sys/conf/files        |  1 +
> >> sys/kern/kern_clock.c | 26 ++++++++++++++------------
> >> sys/kern/kern_tc.c    |  4 ++--
> >> sys/kern/subr_param.c |  2 +-
> >> sys/kern/subr_ticks.s | 44 +++++++++++++++++++++++++++++++++++++++++++=
+
> >> sys/sys/kernel.h      |  9 +++++++++
> >> sys/sys/timetc.h      |  2 +-
> >> 7 files changed, 72 insertions(+), 16 deletions(-)
> >>
> >> diff --git a/sys/conf/files b/sys/conf/files
> >> index d358737c5613..a630d9dd72bc 100644
> >> --- a/sys/conf/files
> >> +++ b/sys/conf/files
> >> @@ -3932,6 +3932,7 @@ kern/subr_stack.c optional ddb | stack | ktr
> >> kern/subr_stats.c optional stats
> >> kern/subr_taskqueue.c standard
> >> kern/subr_terminal.c optional vt
> >> +kern/subr_ticks.s standard
> >> kern/subr_trap.c standard
> >> kern/subr_turnstile.c standard
> >> kern/subr_uio.c standard
> >> diff --git a/sys/kern/kern_clock.c b/sys/kern/kern_clock.c
> >> index 6fa2272ed54a..b11c0d235139 100644
> >> --- a/sys/kern/kern_clock.c
> >> +++ b/sys/kern/kern_clock.c
> >> @@ -323,7 +323,7 @@ read_cpu_time(long *cp_time)
> >>
> >> #include <sys/watchdog.h>
> >>
> >> -static int watchdog_ticks;
> >> +static long watchdog_ticks;
> >> static int watchdog_enabled;
> >> static void watchdog_fire(void);
> >> static void watchdog_config(void *, u_int, int *);
> >> @@ -369,10 +369,9 @@ watchdog_attach(void)
> >> int stathz;
> >> int profhz;
> >> int profprocs;
> >> -volatile int ticks;
> >> int psratio;
> >>
> >> -DPCPU_DEFINE_STATIC(int, pcputicks); /* Per-CPU version of ticks. */
> >> +DPCPU_DEFINE_STATIC(long, pcputicks); /* Per-CPU version of ticks. */
> >> #ifdef DEVICE_POLLING
> >> static int devpoll_run =3D 0;
> >> #endif
> >> @@ -480,14 +479,14 @@ hardclock(int cnt, int usermode)
> >> struct pstats *pstats;
> >> struct thread *td =3D curthread;
> >> struct proc *p =3D td->td_proc;
> >> - int *t =3D DPCPU_PTR(pcputicks);
> >> - int global, i, newticks;
> >> + long global, newticks, *t;
> >>
> >> /*
> >> * Update per-CPU and possibly global ticks values.
> >> */
> >> + t =3D DPCPU_PTR(pcputicks);
> >> *t +=3D cnt;
> >> - global =3D ticks;
> >> + global =3D atomic_load_long(&ticksl);
> >> do {
> >> newticks =3D *t - global;
> >> if (newticks <=3D 0) {
> >> @@ -496,7 +495,7 @@ hardclock(int cnt, int usermode)
> >> newticks =3D 0;
> >> break;
> >> }
> >> - } while (!atomic_fcmpset_int(&ticks, &global, *t));
> >> + } while (!atomic_fcmpset_long(&ticksl, &global, *t));
> >>
> >> /*
> >> * Run current process's virtual and profile time, as needed.
> >> @@ -525,8 +524,10 @@ hardclock(int cnt, int usermode)
> >> }
> >> #endif /* DEVICE_POLLING */
> >> if (watchdog_enabled > 0) {
> >> - i =3D atomic_fetchadd_int(&watchdog_ticks, -newticks);
> >> - if (i > 0 && i <=3D newticks)
> >> + long left;
> >> +
> >> + left =3D atomic_fetchadd_long(&watchdog_ticks, -newticks);
> >> + if (left > 0 && left <=3D newticks)
> >> watchdog_fire();
> >> }
> >> intr_event_handle(clk_intr_event, NULL);
> >> @@ -540,11 +541,12 @@ hardclock(int cnt, int usermode)
> >> void
> >> hardclock_sync(int cpu)
> >> {
> >> - int *t;
> >> + long *t;
> >> +
> >> KASSERT(!CPU_ABSENT(cpu), ("Absent CPU %d", cpu));
> >> - t =3D DPCPU_ID_PTR(cpu, pcputicks);
> >>
> >> - *t =3D ticks;
> >> + t =3D DPCPU_ID_PTR(cpu, pcputicks);
> >> + *t =3D ticksl;
> >> }
> >>
> >> /*
> >> diff --git a/sys/kern/kern_tc.c b/sys/kern/kern_tc.c
> >> index 26f09cb60260..a797a101bf6f 100644
> >> --- a/sys/kern/kern_tc.c
> >> +++ b/sys/kern/kern_tc.c
> >> @@ -1916,9 +1916,9 @@ SYSCTL_INT(_kern_timecounter, OID_AUTO, tick,
> CTLFLAG_RD, &tc_tick, 0,
> >>    "Approximate number of hardclock ticks in a millisecond");
> >>
> >> void
> >> -tc_ticktock(int cnt)
> >> +tc_ticktock(long cnt)
> >> {
> >> - static int count;
> >> + static long count;
> >>
> >> if (mtx_trylock_spin(&tc_setclock_mtx)) {
> >> count +=3D cnt;
> >> diff --git a/sys/kern/subr_param.c b/sys/kern/subr_param.c
> >> index 19169ba63061..f4359efec466 100644
> >> --- a/sys/kern/subr_param.c
> >> +++ b/sys/kern/subr_param.c
> >> @@ -197,7 +197,7 @@ init_param1(void)
> >> * Arrange for ticks to wrap 10 minutes after boot to help catch
> >> * sign problems sooner.
> >> */
> >> - ticks =3D INT_MAX - (hz * 10 * 60);
> >> + ticksl =3D INT_MAX - (hz * 10 * 60);
> >>
> >> vn_lock_pair_pause_max =3D hz / 100;
> >> if (vn_lock_pair_pause_max =3D=3D 0)
> >> diff --git a/sys/kern/subr_ticks.s b/sys/kern/subr_ticks.s
> >> new file mode 100644
> >> index 000000000000..6565ba424137
> >> --- /dev/null
> >> +++ b/sys/kern/subr_ticks.s
> >> @@ -0,0 +1,44 @@
> >> +/*-
> >> + * SPDX-License-Identifier: BSD-2-Clause
> >> + *
> >> + * Copyright (c) 2025 Mark Johnston <markj@FreeBSD.org>
> >> + */
> >> +
> >> +/*
> >> + * Define the "ticks" and "ticksl" variables.  The former is overlaid
> onto the
> >> + * low bits of the latter.
> >> + */
> >> +
> >> +#if defined(__aarch64__)
> >> +#include <sys/elf_common.h>
> >> +#include <machine/asm.h>
> >> +
> >> +GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VA=
L)
> >> +#endif
> >> +
> >> +#ifdef _ILP32
> >> +#define SIZEOF_TICKSL 4
> >> +#define TICKSL_INIT .long 0
> >> +#else
> >> +#define SIZEOF_TICKSL 8
> >> +#define TICKSL_INIT .quad 0
> >> +#endif
> >> +
> >> +#if defined(_ILP32) || __BYTE_ORDER__ =3D=3D __ORDER_LITTLE_ENDIAN__
> >> +#define TICKS_OFFSET 0
> >> +#else
> >> +#define TICKS_OFFSET 4
> >> +#endif
> >> +
> >> + .data
> >> +
> >> + .global ticksl
> >> + .type ticksl, %object
> >> + .align SIZEOF_TICKSL
> >> +ticksl: TICKSL_INIT
> >> + .size ticksl, SIZEOF_TICKSL
> >> +
> >> + .global ticks
> >> + .type ticks, %object
> >> +ticks =3Dticksl + TICKS_OFFSET
> >> + .size ticks, 4
> >
> > This can be simplified to:
> >
> > #if __BYTE_ORDER__ =3D=3D __ORDER_LITTLE_ENDIAN__
> > #define TICKS_OFFSET 0
> > #else
> > #define TICKS_OFFSET (__SIZEOF_LONG__ - __SIZEOF_INT__)
> > #endif
> >
> > .data
> >
> > .global ticksl
> > .type ticksl, %object
> > .align __SIZEOF_LONG__
> > ticksl: .zero __SIZEOF_LONG__
> > .size ticksl, __SIZEOF_LONG__
> >
> > .global ticks
> > .type ticks, %object
> > ticks =3Dticksl + TICKS_OFFSET
> > .size ticks, __SIZEOF_INT__
> >
> > (excuse my mail client stripping the tabs...)
> >
> > No need to check the ABI beyond endianness.
> >
> > Also, shouldn=E2=80=99t these both be in .bss?
>
> And one more thing: the convention is to use .S, not .s, for assembly
> files, since the former are preprocessed[^1]. I=E2=80=99m surprised this =
even
> builds when given the lower case suffix, as bsd.suffixes.mk passes
> -x assembler for the .s.o rule.
>
> Jess
>
> [^1]: Unless you know it doesn=E2=80=99t need preprocessing and never wil=
l...
>

I had this same comment in a review, but was busy and didn't get to make it=
.

We *NEVER* have .s except for weird things we might generate, by convention=
.
We spent a lot of time fixing this a few months ago.

Warner

--0000000000007d90f7062b5d015b
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div class=3D"gmail_quote g=
mail_quote_container"><div dir=3D"ltr" class=3D"gmail_attr">On Fri, Jan 10,=
 2025 at 9:55=E2=80=AFAM Jessica Clarke &lt;<a href=3D"mailto:jrtc27@freebs=
d.org">jrtc27@freebsd.org</a>&gt; wrote:<br></div><blockquote class=3D"gmai=
l_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,20=
4,204);padding-left:1ex">On 10 Jan 2025, at 16:37, Jessica Clarke &lt;jrtc2=
7@FreeBSD.org&gt; wrote:<br>
&gt; On 10 Jan 2025, at 16:00, Mark Johnston &lt;markj@FreeBSD.org&gt; wrot=
e:<br>
&gt;&gt; <br>
&gt;&gt; The branch main has been updated by markj:<br>
&gt;&gt; <br>
&gt;&gt; URL: <a href=3D"https://cgit.FreeBSD.org/src/commit/?id=3D6b82130e=
6c9add4a8892ca897df5a0ec04663ea2" rel=3D"noreferrer" target=3D"_blank">http=
s://cgit.FreeBSD.org/src/commit/?id=3D6b82130e6c9add4a8892ca897df5a0ec04663=
ea2</a><br>
&gt;&gt; <br>
&gt;&gt; commit 6b82130e6c9add4a8892ca897df5a0ec04663ea2<br>
&gt;&gt; Author:=C2=A0 =C2=A0 =C2=A0Mark Johnston &lt;markj@FreeBSD.org&gt;=
<br>
&gt;&gt; AuthorDate: 2025-01-10 15:37:07 +0000<br>
&gt;&gt; Commit:=C2=A0 =C2=A0 =C2=A0Mark Johnston &lt;markj@FreeBSD.org&gt;=
<br>
&gt;&gt; CommitDate: 2025-01-10 15:42:59 +0000<br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0clock: Add a long ticks variable, ticksl<br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0For compatibility with Linux, it&#39;s useful to have =
a tick counter of<br>
&gt;&gt;=C2=A0 =C2=A0width sizeof(long), but our tick counter is an int.=C2=
=A0 Currently the<br>
&gt;&gt;=C2=A0 =C2=A0linuxkpi tries paper over this difference, but this ca=
nnot really be<br>
&gt;&gt;=C2=A0 =C2=A0done reliably, so it&#39;s desirable to have a wider t=
ick counter.=C2=A0 This<br>
&gt;&gt;=C2=A0 =C2=A0change introduces ticksl, keeping the existing ticks v=
ariable.<br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0Follow a suggestion from kib to avoid having to mainta=
in two separate<br>
&gt;&gt;=C2=A0 =C2=A0counters and to avoid converting existing code to use =
ticksl: change<br>
&gt;&gt;=C2=A0 =C2=A0hardclock() to update ticksl instead of ticks, and the=
n use assembler<br>
&gt;&gt;=C2=A0 =C2=A0directives to make ticks and ticksl overlap such that =
loading ticks<br>
&gt;&gt;=C2=A0 =C2=A0gives the bottom 32 bits.=C2=A0 This makes it possible=
 to use ticksl in the<br>
&gt;&gt;=C2=A0 =C2=A0linuxkpi without having to convert any native code, an=
d without making<br>
&gt;&gt;=C2=A0 =C2=A0hardclock() more complicated or expensive.=C2=A0 Then,=
 the linuxkpi can be<br>
&gt;&gt;=C2=A0 =C2=A0modified to use ticksl instead of ticks.<br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0Reviewed by:=C2=A0 =C2=A0 olce, kib, emaste<br>
&gt;&gt;=C2=A0 =C2=A0MFC after:=C2=A0 =C2=A0 =C2=A0 1 month<br>
&gt;&gt;=C2=A0 =C2=A0Differential Revision:=C2=A0 <a href=3D"https://review=
s.freebsd.org/D48383" rel=3D"noreferrer" target=3D"_blank">https://reviews.=
freebsd.org/D48383</a><br>
&gt;&gt; ---<br>
&gt;&gt; sys/conf/files=C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0 1 +<br>
&gt;&gt; sys/kern/kern_clock.c | 26 ++++++++++++++------------<br>
&gt;&gt; sys/kern/kern_tc.c=C2=A0 =C2=A0 |=C2=A0 4 ++--<br>
&gt;&gt; sys/kern/subr_param.c |=C2=A0 2 +-<br>
&gt;&gt; sys/kern/subr_ticks.s | 44 +++++++++++++++++++++++++++++++++++++++=
+++++<br>
&gt;&gt; sys/sys/kernel.h=C2=A0 =C2=A0 =C2=A0 |=C2=A0 9 +++++++++<br>
&gt;&gt; sys/sys/timetc.h=C2=A0 =C2=A0 =C2=A0 |=C2=A0 2 +-<br>
&gt;&gt; 7 files changed, 72 insertions(+), 16 deletions(-)<br>
&gt;&gt; <br>
&gt;&gt; diff --git a/sys/conf/files b/sys/conf/files<br>
&gt;&gt; index d358737c5613..a630d9dd72bc 100644<br>
&gt;&gt; --- a/sys/conf/files<br>
&gt;&gt; +++ b/sys/conf/files<br>
&gt;&gt; @@ -3932,6 +3932,7 @@ kern/subr_stack.c optional ddb | stack | ktr=
<br>
&gt;&gt; kern/subr_stats.c optional stats<br>
&gt;&gt; kern/subr_taskqueue.c standard<br>
&gt;&gt; kern/subr_terminal.c optional vt<br>
&gt;&gt; +kern/subr_ticks.s standard<br>
&gt;&gt; kern/subr_trap.c standard<br>
&gt;&gt; kern/subr_turnstile.c standard<br>
&gt;&gt; kern/subr_uio.c standard<br>
&gt;&gt; diff --git a/sys/kern/kern_clock.c b/sys/kern/kern_clock.c<br>
&gt;&gt; index 6fa2272ed54a..b11c0d235139 100644<br>
&gt;&gt; --- a/sys/kern/kern_clock.c<br>
&gt;&gt; +++ b/sys/kern/kern_clock.c<br>
&gt;&gt; @@ -323,7 +323,7 @@ read_cpu_time(long *cp_time)<br>
&gt;&gt; <br>
&gt;&gt; #include &lt;sys/watchdog.h&gt;<br>
&gt;&gt; <br>
&gt;&gt; -static int watchdog_ticks;<br>
&gt;&gt; +static long watchdog_ticks;<br>
&gt;&gt; static int watchdog_enabled;<br>
&gt;&gt; static void watchdog_fire(void);<br>
&gt;&gt; static void watchdog_config(void *, u_int, int *);<br>
&gt;&gt; @@ -369,10 +369,9 @@ watchdog_attach(void)<br>
&gt;&gt; int stathz;<br>
&gt;&gt; int profhz;<br>
&gt;&gt; int profprocs;<br>
&gt;&gt; -volatile int ticks;<br>
&gt;&gt; int psratio;<br>
&gt;&gt; <br>
&gt;&gt; -DPCPU_DEFINE_STATIC(int, pcputicks); /* Per-CPU version of ticks.=
 */<br>
&gt;&gt; +DPCPU_DEFINE_STATIC(long, pcputicks); /* Per-CPU version of ticks=
. */<br>
&gt;&gt; #ifdef DEVICE_POLLING<br>
&gt;&gt; static int devpoll_run =3D 0;<br>
&gt;&gt; #endif<br>
&gt;&gt; @@ -480,14 +479,14 @@ hardclock(int cnt, int usermode)<br>
&gt;&gt; struct pstats *pstats;<br>
&gt;&gt; struct thread *td =3D curthread;<br>
&gt;&gt; struct proc *p =3D td-&gt;td_proc;<br>
&gt;&gt; - int *t =3D DPCPU_PTR(pcputicks);<br>
&gt;&gt; - int global, i, newticks;<br>
&gt;&gt; + long global, newticks, *t;<br>
&gt;&gt; <br>
&gt;&gt; /*<br>
&gt;&gt; * Update per-CPU and possibly global ticks values.<br>
&gt;&gt; */<br>
&gt;&gt; + t =3D DPCPU_PTR(pcputicks);<br>
&gt;&gt; *t +=3D cnt;<br>
&gt;&gt; - global =3D ticks;<br>
&gt;&gt; + global =3D atomic_load_long(&amp;ticksl);<br>
&gt;&gt; do {<br>
&gt;&gt; newticks =3D *t - global;<br>
&gt;&gt; if (newticks &lt;=3D 0) {<br>
&gt;&gt; @@ -496,7 +495,7 @@ hardclock(int cnt, int usermode)<br>
&gt;&gt; newticks =3D 0;<br>
&gt;&gt; break;<br>
&gt;&gt; }<br>
&gt;&gt; - } while (!atomic_fcmpset_int(&amp;ticks, &amp;global, *t));<br>
&gt;&gt; + } while (!atomic_fcmpset_long(&amp;ticksl, &amp;global, *t));<br=
>
&gt;&gt; <br>
&gt;&gt; /*<br>
&gt;&gt; * Run current process&#39;s virtual and profile time, as needed.<b=
r>
&gt;&gt; @@ -525,8 +524,10 @@ hardclock(int cnt, int usermode)<br>
&gt;&gt; }<br>
&gt;&gt; #endif /* DEVICE_POLLING */<br>
&gt;&gt; if (watchdog_enabled &gt; 0) {<br>
&gt;&gt; - i =3D atomic_fetchadd_int(&amp;watchdog_ticks, -newticks);<br>
&gt;&gt; - if (i &gt; 0 &amp;&amp; i &lt;=3D newticks)<br>
&gt;&gt; + long left;<br>
&gt;&gt; +<br>
&gt;&gt; + left =3D atomic_fetchadd_long(&amp;watchdog_ticks, -newticks);<b=
r>
&gt;&gt; + if (left &gt; 0 &amp;&amp; left &lt;=3D newticks)<br>
&gt;&gt; watchdog_fire();<br>
&gt;&gt; }<br>
&gt;&gt; intr_event_handle(clk_intr_event, NULL);<br>
&gt;&gt; @@ -540,11 +541,12 @@ hardclock(int cnt, int usermode)<br>
&gt;&gt; void<br>
&gt;&gt; hardclock_sync(int cpu)<br>
&gt;&gt; {<br>
&gt;&gt; - int *t;<br>
&gt;&gt; + long *t;<br>
&gt;&gt; +<br>
&gt;&gt; KASSERT(!CPU_ABSENT(cpu), (&quot;Absent CPU %d&quot;, cpu));<br>
&gt;&gt; - t =3D DPCPU_ID_PTR(cpu, pcputicks);<br>
&gt;&gt; <br>
&gt;&gt; - *t =3D ticks;<br>
&gt;&gt; + t =3D DPCPU_ID_PTR(cpu, pcputicks);<br>
&gt;&gt; + *t =3D ticksl;<br>
&gt;&gt; }<br>
&gt;&gt; <br>
&gt;&gt; /*<br>
&gt;&gt; diff --git a/sys/kern/kern_tc.c b/sys/kern/kern_tc.c<br>
&gt;&gt; index 26f09cb60260..a797a101bf6f 100644<br>
&gt;&gt; --- a/sys/kern/kern_tc.c<br>
&gt;&gt; +++ b/sys/kern/kern_tc.c<br>
&gt;&gt; @@ -1916,9 +1916,9 @@ SYSCTL_INT(_kern_timecounter, OID_AUTO, tick=
, CTLFLAG_RD, &amp;tc_tick, 0,<br>
&gt;&gt;=C2=A0 =C2=A0 &quot;Approximate number of hardclock ticks in a mill=
isecond&quot;);<br>
&gt;&gt; <br>
&gt;&gt; void<br>
&gt;&gt; -tc_ticktock(int cnt)<br>
&gt;&gt; +tc_ticktock(long cnt)<br>
&gt;&gt; {<br>
&gt;&gt; - static int count;<br>
&gt;&gt; + static long count;<br>
&gt;&gt; <br>
&gt;&gt; if (mtx_trylock_spin(&amp;tc_setclock_mtx)) {<br>
&gt;&gt; count +=3D cnt;<br>
&gt;&gt; diff --git a/sys/kern/subr_param.c b/sys/kern/subr_param.c<br>
&gt;&gt; index 19169ba63061..f4359efec466 100644<br>
&gt;&gt; --- a/sys/kern/subr_param.c<br>
&gt;&gt; +++ b/sys/kern/subr_param.c<br>
&gt;&gt; @@ -197,7 +197,7 @@ init_param1(void)<br>
&gt;&gt; * Arrange for ticks to wrap 10 minutes after boot to help catch<br=
>
&gt;&gt; * sign problems sooner.<br>
&gt;&gt; */<br>
&gt;&gt; - ticks =3D INT_MAX - (hz * 10 * 60);<br>
&gt;&gt; + ticksl =3D INT_MAX - (hz * 10 * 60);<br>
&gt;&gt; <br>
&gt;&gt; vn_lock_pair_pause_max =3D hz / 100;<br>
&gt;&gt; if (vn_lock_pair_pause_max =3D=3D 0)<br>
&gt;&gt; diff --git a/sys/kern/subr_ticks.s b/sys/kern/subr_ticks.s<br>
&gt;&gt; new file mode 100644<br>
&gt;&gt; index 000000000000..6565ba424137<br>
&gt;&gt; --- /dev/null<br>
&gt;&gt; +++ b/sys/kern/subr_ticks.s<br>
&gt;&gt; @@ -0,0 +1,44 @@<br>
&gt;&gt; +/*-<br>
&gt;&gt; + * SPDX-License-Identifier: BSD-2-Clause<br>
&gt;&gt; + *<br>
&gt;&gt; + * Copyright (c) 2025 Mark Johnston &lt;markj@FreeBSD.org&gt;<br>
&gt;&gt; + */<br>
&gt;&gt; +<br>
&gt;&gt; +/*<br>
&gt;&gt; + * Define the &quot;ticks&quot; and &quot;ticksl&quot; variables.=
=C2=A0 The former is overlaid onto the<br>
&gt;&gt; + * low bits of the latter.<br>
&gt;&gt; + */<br>
&gt;&gt; +<br>
&gt;&gt; +#if defined(__aarch64__)<br>
&gt;&gt; +#include &lt;sys/elf_common.h&gt;<br>
&gt;&gt; +#include &lt;machine/asm.h&gt;<br>
&gt;&gt; +<br>
&gt;&gt; +GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_=
1_VAL)<br>
&gt;&gt; +#endif<br>
&gt;&gt; +<br>
&gt;&gt; +#ifdef _ILP32<br>
&gt;&gt; +#define SIZEOF_TICKSL 4<br>
&gt;&gt; +#define TICKSL_INIT .long 0<br>
&gt;&gt; +#else<br>
&gt;&gt; +#define SIZEOF_TICKSL 8<br>
&gt;&gt; +#define TICKSL_INIT .quad 0<br>
&gt;&gt; +#endif<br>
&gt;&gt; +<br>
&gt;&gt; +#if defined(_ILP32) || __BYTE_ORDER__ =3D=3D __ORDER_LITTLE_ENDIA=
N__<br>
&gt;&gt; +#define TICKS_OFFSET 0<br>
&gt;&gt; +#else<br>
&gt;&gt; +#define TICKS_OFFSET 4<br>
&gt;&gt; +#endif<br>
&gt;&gt; +<br>
&gt;&gt; + .data<br>
&gt;&gt; +<br>
&gt;&gt; + .global ticksl<br>
&gt;&gt; + .type ticksl, %object<br>
&gt;&gt; + .align SIZEOF_TICKSL<br>
&gt;&gt; +ticksl: TICKSL_INIT<br>
&gt;&gt; + .size ticksl, SIZEOF_TICKSL<br>
&gt;&gt; +<br>
&gt;&gt; + .global ticks<br>
&gt;&gt; + .type ticks, %object<br>
&gt;&gt; +ticks =3Dticksl + TICKS_OFFSET<br>
&gt;&gt; + .size ticks, 4<br>
&gt; <br>
&gt; This can be simplified to:<br>
&gt; <br>
&gt; #if __BYTE_ORDER__ =3D=3D __ORDER_LITTLE_ENDIAN__<br>
&gt; #define TICKS_OFFSET 0<br>
&gt; #else<br>
&gt; #define TICKS_OFFSET (__SIZEOF_LONG__ - __SIZEOF_INT__)<br>
&gt; #endif<br>
&gt; <br>
&gt; .data<br>
&gt; <br>
&gt; .global ticksl<br>
&gt; .type ticksl, %object<br>
&gt; .align __SIZEOF_LONG__<br>
&gt; ticksl: .zero __SIZEOF_LONG__<br>
&gt; .size ticksl, __SIZEOF_LONG__<br>
&gt; <br>
&gt; .global ticks<br>
&gt; .type ticks, %object<br>
&gt; ticks =3Dticksl + TICKS_OFFSET<br>
&gt; .size ticks, __SIZEOF_INT__<br>
&gt; <br>
&gt; (excuse my mail client stripping the tabs...)<br>
&gt; <br>
&gt; No need to check the ABI beyond endianness.<br>
&gt; <br>
&gt; Also, shouldn=E2=80=99t these both be in .bss?<br>
<br>
And one more thing: the convention is to use .S, not .s, for assembly<br>
files, since the former are preprocessed[^1]. I=E2=80=99m surprised this ev=
en<br>
builds when given the lower case suffix, as <a href=3D"http://bsd.suffixes.=
mk" rel=3D"noreferrer" target=3D"_blank">bsd.suffixes.mk</a> passes<br>
-x assembler for the .s.o rule.<br>
<br>
Jess<br>
<br>
[^1]: Unless you know it doesn=E2=80=99t need preprocessing and never will.=
..<br></blockquote><div><br></div><div>I had this same comment in a review,=
 but was busy and didn&#39;t get to make it.</div><div><br></div><div>We *N=
EVER* have .s except for weird things we might generate, by convention.</di=
v><div>We spent a lot of time fixing this a few months ago.</div><div><br><=
/div><div>Warner=C2=A0</div></div></div>

--0000000000007d90f7062b5d015b--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CANCZdfrt6ezJdeRKpKQzo7k5PPuznb253Ljx=w7_UVzTg7hkeQ>