From nobody Tue Oct 07 14:26:43 2025 X-Original-To: dev-commits-src-main@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 4cgz3S1X76z6BNtJ; Tue, 07 Oct 2025 14:26:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cgz3R6wksz3QqS; Tue, 07 Oct 2025 14:26:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1759847204; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Lm2PN0SDpNkbNOZc4W4D6Z71GLysQUIYTYgyFv0qjzY=; b=ZdE6X4XPqrIpOrluLcvyjTgv2q1IN4RwUc09o3ifhNGkbczb9Fw2TkzeA42QdmSMAamWSR NOJp6EhnPI8SJEnLd/kZC6G06UUg2qg6ojJVAWLCxTaXJR7e1yZUQZJyu+fBCaVQ1g0BYy oSmvH4FjcpztsEscpYmNwPc83RJeMrrFQYW6PEgT4KQoxIxeFmrVTf0QEfnXLEIwn15k4K WOlpSi3KZLC8KmQmFtUXUs7Ew/jMnoMT8r76gS0RMAwylPJPgV4WQI9u4Pf09ZMDpZhUXU ma0X2FQxKQqIJNpnOGvnFVvnrL8HxqaKganv+SnUH53HEeBdNKYByVQwQL7EKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1759847204; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Lm2PN0SDpNkbNOZc4W4D6Z71GLysQUIYTYgyFv0qjzY=; b=LFf6DfAVQjvoBpZqe1op9AvZXN6WOlr+PKuKl7p2DfV5DShRHxuafM4GqDSJTKX85WuevI I/Smi3/rw1GOYltDywgCpwG61R5ikDaISfUQPX7ZzZnolEy2CkXzsvWFO5u4J7WjWt3+IM zM4ROhAEpxHwby2ewKSFHDN+sa9hAnx24TnDWuGtUQ1v78iMCvOcocgu2QmDi8qslouwHC 4go4Ifc2FzQcmn8cBCGQ98F2selqZ9+QPFIZlPFHedKZN3XVibw3Wc9mDzD6pONR6l669T fKbp+ApTGEqqmORKh1Vfdvhz6PywbKM6iv7OZjKHwVIE6lB71gnM7LXe/K253Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1759847204; a=rsa-sha256; cv=none; b=g8NrKllAxr/hc0C7g4GV041RMGiJpVpJqHqzNLfDSmXwi/vfIHnIYlnKHnsSXSE9qXZ+UI R1z29sN7MR/jVy+mpULflEKEbZL7+rOrytRsUV0PyiSNOy4kwJ6HQUI1igCWae9N/+gONA kMldL9i6F/DY8EAwfkoSRtwMMNniiB4w71OaVI/iSri06JDdu/VfB+V+b44ZHgGsicEbQx ZpA5l9/okiWBg1JOo2/5bsXWTQzaVlnjvvvqrlhHywnkAMWdwfcR14ok2cxnC8SYK+M4TG ENbf7Kenhq/P5EwcymPevFv9OIDeYqRmvkLHGgBDvAY2fVRBIGw+amzswXV8DQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4cgz3R646szq1G; Tue, 07 Oct 2025 14:26:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 597EQhfo050880; Tue, 7 Oct 2025 14:26:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 597EQh3K050877; Tue, 7 Oct 2025 14:26:43 GMT (envelope-from git) Date: Tue, 7 Oct 2025 14:26:43 GMT Message-Id: <202510071426.597EQh3K050877@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Jonathan T. Looney" Subject: git: e770e32aa3a0 - main - x86: Reduce amount of time the MCA lock is held while emitting records List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jtl X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e770e32aa3a017b35fcf24e7c6f14fc2a209bad5 Auto-Submitted: auto-generated The branch main has been updated by jtl: URL: https://cgit.FreeBSD.org/src/commit/?id=e770e32aa3a017b35fcf24e7c6f14fc2a209bad5 commit e770e32aa3a017b35fcf24e7c6f14fc2a209bad5 Author: Jonathan T. Looney AuthorDate: 2025-10-06 15:07:33 +0000 Commit: Jonathan T. Looney CommitDate: 2025-10-07 14:20:12 +0000 x86: Reduce amount of time the MCA lock is held while emitting records The MCA spin lock is acquired in the hardware interrupt context to record MCA messages. It is also acquired by a task handler to emit those messages. Reduce the amount of time the task handler holds the lock to reduce the maximum amount of time the hardware interrupt handler may need to spin on the lock. Reviewed by: glebius, markj MFC after: 2 weeks Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D52938 --- sys/x86/x86/mca.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/sys/x86/x86/mca.c b/sys/x86/x86/mca.c index e43c88b3a27b..7ee22895e0a7 100644 --- a/sys/x86/x86/mca.c +++ b/sys/x86/x86/mca.c @@ -796,9 +796,9 @@ mca_record_entry(enum scan_mode mode, const struct mca_record *record) mtx_lock_spin(&mca_lock); rec = STAILQ_FIRST(&mca_freelist); if (rec == NULL) { + mtx_unlock_spin(&mca_lock); printf("MCA: Unable to allocate space for an event.\n"); mca_log(record); - mtx_unlock_spin(&mca_lock); return; } STAILQ_REMOVE_HEAD(&mca_freelist, link); @@ -1017,6 +1017,7 @@ static void mca_process_records(enum scan_mode mode) { struct mca_internal *mca; + STAILQ_HEAD(, mca_internal) tmplist; /* * If in an interrupt context, defer the post-scan activities to a @@ -1028,10 +1029,21 @@ mca_process_records(enum scan_mode mode) return; } + /* + * Copy the pending list to the stack so we can drop the spin lock + * while we are emitting logs. + */ + STAILQ_INIT(&tmplist); mtx_lock_spin(&mca_lock); - while ((mca = STAILQ_FIRST(&mca_pending)) != NULL) { - STAILQ_REMOVE_HEAD(&mca_pending, link); + STAILQ_SWAP(&mca_pending, &tmplist, mca_internal); + mtx_unlock_spin(&mca_lock); + + STAILQ_FOREACH(mca, &tmplist, link) mca_log(&mca->rec); + + mtx_lock_spin(&mca_lock); + while ((mca = STAILQ_FIRST(&tmplist)) != NULL) { + STAILQ_REMOVE_HEAD(&tmplist, link); mca_store_record(mca); } mtx_unlock_spin(&mca_lock);