git: 686b143f37c5 - stable/13 - timecounter: Initialize tc_lock earlier

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Mon, 22 Nov 2021 13:46:23 UTC
The branch stable/13 has been updated by markj:

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

commit 686b143f37c501c79c0ddbbcb55ce852cc0bc846
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2021-11-19 22:29:28 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2021-11-22 13:44:49 +0000

    timecounter: Initialize tc_lock earlier
    
    Hyper-V wants to register its MSR-based timecounter during
    SI_SUB_HYPERVISOR, before SI_SUB_LOCK, since an emulated 8254 may not be
    available for DELAY().  So we cannot use MTX_SYSINIT to initialize the
    timecounter lock.
    
    PR:             259878
    Reviewed by:    kib
    Sponsored by:   The FreeBSD Foundation
    
    (cherry picked from commit 3339950117bedb5f880f6c08982dcc5dd43f9c34)
---
 sys/kern/kern_tc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sys/kern/kern_tc.c b/sys/kern/kern_tc.c
index 135279d48a22..989457b82434 100644
--- a/sys/kern/kern_tc.c
+++ b/sys/kern/kern_tc.c
@@ -100,7 +100,6 @@ static struct timecounter *timecounters = &dummy_timecounter;
 
 /* Mutex to protect the timecounter list. */
 static struct mtx tc_lock;
-MTX_SYSINIT(tc_lock, &tc_lock, "tc", MTX_DEF);
 
 int tc_min_ticktock_freq = 1;
 
@@ -1982,6 +1981,8 @@ inittimehands(void *dummy)
 
 	TUNABLE_STR_FETCH("kern.timecounter.hardware", tc_from_tunable,
 	    sizeof(tc_from_tunable));
+
+	mtx_init(&tc_lock, "tc", NULL, MTX_DEF);
 }
 SYSINIT(timehands, SI_SUB_TUNABLES, SI_ORDER_ANY, inittimehands, NULL);