From nobody Fri Jan 10 16:55:28 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4YV77z2Rlgz5kf7J for ; Fri, 10 Jan 2025 16:55:43 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "WR4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YV77y0Gyjz44Fr for ; Fri, 10 Jan 2025 16:55:42 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Authentication-Results: mx1.freebsd.org; dkim=none; spf=pass (mx1.freebsd.org: domain of jrtc27@jrtc27.com designates 209.85.128.44 as permitted sender) smtp.mailfrom=jrtc27@jrtc27.com; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=freebsd.org (policy=none) Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-436202dd730so17008085e9.2 for ; Fri, 10 Jan 2025 08:55:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736528139; x=1737132939; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HS0gN5uM/oadHMSzgk+7umsSNj9vDYR8s8Qjzr1iYd4=; b=OdhNPsj570JD/zQpEIBA2ARDD68W9REmyjAyPT/XimpohOYYoKHyJlmdbbX81bTAl1 U8y9/3ajEgdglZu5qVZp5RW8tzHXw/kBTncfJ0uwbnsQBk9klL4L+ZgwrCCpL/+4Uhzb ihzYrKbSHOoUpOKSnTVRcrqTfdu5mLkG+4hreXXlUZ6yEWf0qe5MyrP3COj+QX8sRQ2W DhrMKIvN7EuivKjDbiyRvBvgoiBFMzrsPHSG//7qY7xml+wmSOuEWzO4UkVfGbnkyZ75 Zrm2XLXr/zOLe4ew38KXd5nl7cNr3CPcu7wiVpokHmGGy3SMQ/shAIeCU/5jUK1wNYOf eUzg== X-Forwarded-Encrypted: i=1; AJvYcCUotuKZGv225rT5adyBD+4OX3Ep98+l0zfKm1c5dQHRFMbZv4fxM1jec6QcFMhklde9Z+4Uv6AfHms3gSJRV2MRevSQ@freebsd.org X-Gm-Message-State: AOJu0YyeLA/5ruUxSQ+WVaFHBE+3phtD27VAU9K5fDIRhJ8ikynX/sDm P5a+H7DF+DOAB+ICn0sXqSeWDfZxNPb20pG1p4CZWrpmfGlYMpPGa6/pT02b7TM= X-Gm-Gg: ASbGncshKGgyZkcqSTyaxfAalUnYqiiKWs6JGegoEbkSk6nEJ3gnoqEabnkVLhT/Hbn o6jrgBLX8x6ldZ8xdahuCXVXXNV7PFNa64oUHZqYacMUd7BBlZVgP6yW3a4tA0NSUVyh6U62EU7 jzlrCams5PpIzgczwRAAQVo2uzOsFZ1i5AN8Uk8+Qc4P5QRm+HSf0Qa5V6ZO+UtcxXUVF9WgnQo LTHzUglFbKJ8sUml+OaOX5cP1v8q4DAjbc1vQGS/XD1SK9wD5EgFYqxWaclc2X1FprvM0I= X-Google-Smtp-Source: AGHT+IGCkXxd7WO8j1b2/2wytxmfGzm38cb8FX6UkL6I5FFiTlzDfbvrJtDqgufsPfUg9phh0eaxug== X-Received: by 2002:a05:600c:4449:b0:435:192:63ca with SMTP id 5b1f17b1804b1-436e26f481dmr7775575e9.21.1736528139286; Fri, 10 Jan 2025 08:55:39 -0800 (PST) Received: from smtpclient.apple ([131.111.5.201]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-436e2da66e6sm92887815e9.4.2025.01.10.08.55.38 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Jan 2025 08:55:38 -0800 (PST) Content-Type: text/plain; charset=utf-8 List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.300.87.4.3\)) Subject: Re: git: 6b82130e6c9a - main - clock: Add a long ticks variable, ticksl From: Jessica Clarke In-Reply-To: <9B1B709F-5828-489C-81B5-74ED9E4502FC@freebsd.org> Date: Fri, 10 Jan 2025 16:55:28 +0000 Cc: "src-committers@freebsd.org" , "dev-commits-src-all@freebsd.org" , "dev-commits-src-main@freebsd.org" Content-Transfer-Encoding: quoted-printable Message-Id: <040B6FE0-1C9F-411F-BFA9-D578462C572E@freebsd.org> References: <202501101600.50AG0jk6062308@gitrepo.freebsd.org> <9B1B709F-5828-489C-81B5-74ED9E4502FC@freebsd.org> To: Mark Johnston X-Mailer: Apple Mail (2.3826.300.87.4.3) X-Rspamd-Queue-Id: 4YV77y0Gyjz44Fr X-Spamd-Bar: -- X-Spamd-Result: default: False [-2.40 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-0.999]; MV_CASE(0.50)[]; FORGED_SENDER(0.30)[jrtc27@freebsd.org,jrtc27@jrtc27.com]; R_SPF_ALLOW(-0.20)[+ip4:209.85.128.0/17]; MIME_GOOD(-0.10)[text/plain]; DMARC_POLICY_SOFTFAIL(0.10)[freebsd.org : SPF not aligned (relaxed), No valid DKIM,none]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; TO_DN_EQ_ADDR_SOME(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; RCVD_TLS_LAST(0.00)[]; ARC_NA(0.00)[]; FREEFALL_USER(0.00)[jrtc27]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US]; FROM_HAS_DN(0.00)[]; RWL_MAILSPIKE_POSSIBLE(0.00)[209.85.128.44:from]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_NEQ_ENVFROM(0.00)[jrtc27@freebsd.org,jrtc27@jrtc27.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[dev-commits-src-all@freebsd.org]; R_DKIM_NA(0.00)[]; MLMMJ_DEST(0.00)[dev-commits-src-all@freebsd.org]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[209.85.128.44:from] On 10 Jan 2025, at 16:37, Jessica Clarke wrote: > On 10 Jan 2025, at 16:00, Mark Johnston wrote: >>=20 >> The branch main has been updated by markj: >>=20 >> URL: = https://cgit.FreeBSD.org/src/commit/?id=3D6b82130e6c9add4a8892ca897df5a0ec= 04663ea2 >>=20 >> commit 6b82130e6c9add4a8892ca897df5a0ec04663ea2 >> Author: Mark Johnston >> AuthorDate: 2025-01-10 15:37:07 +0000 >> Commit: Mark Johnston >> CommitDate: 2025-01-10 15:42:59 +0000 >>=20 >> clock: Add a long ticks variable, ticksl >>=20 >> 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. >>=20 >> Follow a suggestion from kib to avoid having to maintain two = separate >> counters and to avoid converting existing code to use ticksl: = change >> hardclock() to update ticksl instead of ticks, and then use = assembler >> directives to make ticks and ticksl overlap such that loading ticks >> gives the bottom 32 bits. This makes it possible to use ticksl in = the >> linuxkpi without having to convert any native code, and without = making >> hardclock() more complicated or expensive. Then, the linuxkpi can = be >> modified to use ticksl instead of ticks. >>=20 >> 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(-) >>=20 >> 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) >>=20 >> #include >>=20 >> -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; >>=20 >> -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; >>=20 >> /* >> * 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)); >>=20 >> /* >> * 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); >>=20 >> - *t =3D ticks; >> + t =3D DPCPU_ID_PTR(cpu, pcputicks); >> + *t =3D ticksl; >> } >>=20 >> /* >> 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"); >>=20 >> void >> -tc_ticktock(int cnt) >> +tc_ticktock(long cnt) >> { >> - static int count; >> + static long count; >>=20 >> 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); >>=20 >> 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 >> + */ >> + >> +/* >> + * Define the "ticks" and "ticksl" variables. The former is = overlaid onto the >> + * low bits of the latter. >> + */ >> + >> +#if defined(__aarch64__) >> +#include >> +#include >> + >> = +GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL) >> +#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 >=20 > This can be simplified to: >=20 > #if __BYTE_ORDER__ =3D=3D __ORDER_LITTLE_ENDIAN__ > #define TICKS_OFFSET 0 > #else > #define TICKS_OFFSET (__SIZEOF_LONG__ - __SIZEOF_INT__) > #endif >=20 > .data >=20 > .global ticksl > .type ticksl, %object > .align __SIZEOF_LONG__ > ticksl: .zero __SIZEOF_LONG__ > .size ticksl, __SIZEOF_LONG__ >=20 > .global ticks > .type ticks, %object > ticks =3Dticksl + TICKS_OFFSET > .size ticks, __SIZEOF_INT__ >=20 > (excuse my mail client stripping the tabs...) >=20 > No need to check the ABI beyond endianness. >=20 > 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 = will...