Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 28 Oct 2021 10:52:59 +0200
From:      Sebastian Huber <sebastian.huber@embedded-brains.de>
To:        freebsd-hackers@freebsd.org
Subject:   Dynamic timecounter changes
Message-ID:  <ca05516f-8162-0906-1631-43f208751cb7@embedded-brains.de>

next in thread | raw e-mail | index | archive | help
Hello,

there was a recent change which protected timecounter changes with a mute=
x:

https://github.com/freebsd/freebsd-src/commit/621fd9dcb2d83daab477c130bc9=
9b905f6fc27dc

If the timecounter can change dynamically, could tc_windup() see=20
different timercounter here:

	/*
	 * Capture a timecounter delta on the current timecounter and if
	 * changing timecounters, a counter value from the new timecounter.
	 * Update the offset fields accordingly.
	 */
	delta =3D tc_delta(th);
	if (th->th_counter !=3D timecounter)
		ncount =3D timecounter->tc_get_timecount(timecounter);
	else
		ncount =3D 0;

and here:

	/* Now is a good time to change timecounters. */
	if (th->th_counter !=3D timecounter) {
#ifndef __arm__
		if ((timecounter->tc_flags & TC_FLAGS_C2STOP) !=3D 0)
			cpu_disable_c2_sleep++;
		if ((th->th_counter->tc_flags & TC_FLAGS_C2STOP) !=3D 0)
			cpu_disable_c2_sleep--;
#endif
		th->th_counter =3D timecounter;
		th->th_offset_count =3D ncount;
		tc_min_ticktock_freq =3D max(1, timecounter->tc_frequency /
		    (((uint64_t)timecounter->tc_counter_mask + 1) / 3));
		recalculate_scaling_factor_and_large_delta(th);
#ifdef FFCLOCK
		ffclock_change_tc(th);
#endif
	}

An ncount value from two different timecounter would be used in this=20
case.  Maybe the "timecounter" global variable should be just read once=20
into a local variable.

--=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/



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?ca05516f-8162-0906-1631-43f208751cb7>