From nobody Sat Sep 16 07:46:38 2023 X-Original-To: hackers@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 4Rnjn51psgz4tftl for ; Sat, 16 Sep 2023 07:46:49 +0000 (UTC) (envelope-from sebastian.huber@embedded-brains.de) Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4Rnjn42Kkgz4H8s for ; Sat, 16 Sep 2023 07:46:48 +0000 (UTC) (envelope-from sebastian.huber@embedded-brains.de) Authentication-Results: mx1.freebsd.org; dkim=none; spf=pass (mx1.freebsd.org: domain of sebastian.huber@embedded-brains.de designates 85.10.215.148 as permitted sender) smtp.mailfrom=sebastian.huber@embedded-brains.de; dmarc=none Received: from sslproxy05.your-server.de ([78.46.172.2]) by dedi548.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qhQ0l-000E7J-Nv for hackers@freebsd.org; Sat, 16 Sep 2023 09:46:40 +0200 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy05.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qhQ0l-000EFr-KF for hackers@freebsd.org; Sat, 16 Sep 2023 09:46:39 +0200 Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 4EEFC480155 for ; Sat, 16 Sep 2023 09:46:39 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavis, port 10032) with ESMTP id ftlM0O81MwQK for ; Sat, 16 Sep 2023 09:46:39 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id EE2CA4801D8 for ; Sat, 16 Sep 2023 09:46:38 +0200 (CEST) X-Virus-Scanned: amavis at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavis, port 10026) with ESMTP id AnUlMxQPqJYy for ; Sat, 16 Sep 2023 09:46:38 +0200 (CEST) Received: from [10.10.171.34] (unknown [10.10.171.34]) by mail.embedded-brains.de (Postfix) with ESMTPSA id C7860480155 for ; Sat, 16 Sep 2023 09:46:38 +0200 (CEST) Message-ID: Date: Sat, 16 Sep 2023 09:46:38 +0200 List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@freebsd.org MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: hackers@freebsd.org Content-Language: en-US From: Sebastian Huber Subject: Remove timecounter tc_counter_mask member? Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Authenticated-Sender: smtp-embedded@poldi-networks.de X-Virus-Scanned: Clear (ClamAV 0.103.10/27032/Fri Sep 15 09:38:51 2023) X-Spamd-Bar: + X-Spamd-Result: default: False [1.41 / 15.00]; SUBJECT_ENDS_QUESTION(1.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-0.999]; NEURAL_SPAM_LONG(0.98)[0.978]; NEURAL_SPAM_SHORT(0.73)[0.725]; R_SPF_ALLOW(-0.20)[+ip4:85.10.215.148]; MIME_GOOD(-0.10)[text/plain]; XM_UA_NO_VERSION(0.01)[]; DMARC_NA(0.00)[embedded-brains.de]; ARC_NA(0.00)[]; MLMMJ_DEST(0.00)[hackers@freebsd.org]; ASN(0.00)[asn:24940, ipnet:85.10.192.0/18, country:DE]; R_DKIM_NA(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_SEVEN(0.00)[7]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_TLS_LAST(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[hackers@freebsd.org]; RCPT_COUNT_ONE(0.00)[1]; HAS_X_AS(0.00)[] X-Rspamd-Queue-Id: 4Rnjn42Kkgz4H8s Hello, the timecounter structure contains a tc_counter_mask which enables=20 support for time counters implementing less than 32-bits: struct timecounter { timecounter_get_t *tc_get_timecount; #ifndef __rtems__ /* * This function reads the counter. It is not required to * mask any unimplemented bits out, as long as they are * constant. */ uint32_t tc_counter_mask; /* This mask should mask off any unimplemented bits. */ [...] }; In the FreeBSD main branch sys/x86/x86/tsc.c: .tc_counter_mask =3D ~0u, sys/x86/x86/pvclock.c: pvc->tc.tc_counter_mask =3D ~0U; sys/x86/isa/clock.c: sc->tc.tc_counter_mask =3D 0xffff; sys/arm/ti/am335x/am335x_dmtimer.c: sc->func.tc.tc_counter_mask =3D= ~0u; sys/arm/ti/am335x/am335x_dmtpps.c: sc->tc.tc_counter_mask =3D ~0u; sys/arm/allwinner/a10_timer.c: .tc_counter_mask =3D ~0u, sys/arm/allwinner/a10_timer.c: .tc_counter_mask =3D ~0u, sys/arm/arm/generic_timer.c: .tc_counter_mask =3D ~0u, sys/arm/arm/sp804.c: sc->tc.tc_counter_mask =3D ~0u; sys/arm/arm/mpcore_timer.c: .tc_counter_mask =3D ~0u, sys/arm/broadcom/bcm2835/bcm2835_systimer.c: .tc_counter_mask =3D ~0= u, sys/arm/mv/timer.c: .tc_counter_mask =3D ~0u, sys/arm/freescale/imx/imx_gpt.c: .tc_counter_mask =3D ~0u, sys/arm/freescale/imx/imx_epit.c: sc->tc.tc_counter_mask =3D=20 0xffffffff; sys/powerpc/powerpc/clock.c: .tc_counter_mask =3D ~0u, sys/dev/acpica/acpi_hpet.c: sc->tc.tc_counter_mask =3D ~0u, sys/dev/acpica/acpi_timer.c: acpi_timer_timecounter.tc_counter_mask =3D= =20 0xffffffff; sys/dev/acpica/acpi_timer.c: acpi_timer_timecounter.tc_counter_mask =3D= =20 0x00ffffff; sys/dev/xen/timer/xen_timer.c: sc->tc.tc_counter_mask =3D ~0u; sys/dev/hyperv/vmbus/amd64/hyperv_machdep.c: .tc_counter_mask=20 =3D 0xffffffff, sys/dev/hyperv/vmbus/x86/hyperv_x86.c: .tc_counter_mask =3D 0xffffffff, sys/riscv/riscv/timer.c: .tc_counter_mask =3D ~0u, only two timecounters use a mask other than 0xffffffff. These are sys/x86/isa/clock.c: sc->tc.tc_counter_mask =3D 0xffff; and sys/dev/acpica/acpi_timer.c- if (AcpiGbl_FADT.Flags &=20 ACPI_FADT_32BIT_TIMER) sys/dev/acpica/acpi_timer.c: acpi_timer_timecounter.tc_counter_mask =3D= =20 0xffffffff; sys/dev/acpica/acpi_timer.c- else sys/dev/acpica/acpi_timer.c: acpi_timer_timecounter.tc_counter_mask =3D= =20 0x00ffffff; Is the sys/x86/isa/clock.c still used? Are there chips on the market=20 with 24-bit ACPI timers? Instead of using the mask, we could instead left shift the frequency and=20 the returned count by 16 (sys/x86/isa/clock.c) or 8=20 (sys/dev/acpica/acpi_timer.c). Then we could remove the tc_counter_mask=20 member to simplify some calculations such as: /* * Return the difference between the timehands' counter value now and wh= at * was when we copied it to the timehands' offset_count. */ static __inline uint32_t tc_delta(struct timehands *th) { struct timecounter *tc; tc =3D th->th_counter; return ((tc->tc_get_timecount(tc) - th->th_offset_count) & tc->tc_counter_mask); } Would such a change be acceptable for FreeBSD? Kind regards, Sebastian --=20 embedded brains GmbH Herr Sebastian HUBER Dornierstr. 4 82178 Puchheim Germany email: sebastian.huber@embedded-brains.de phone: +49-89-18 94 741 - 16 fax: +49-89-18 94 741 - 08 Registergericht: Amtsgericht M=C3=BCnchen Registernummer: HRB 157899 Vertretungsberechtigte Gesch=C3=A4ftsf=C3=BChrer: Peter Rasmussen, Thomas= D=C3=B6rfler Unsere Datenschutzerkl=C3=A4rung finden Sie hier: https://embedded-brains.de/datenschutzerklaerung/