From nobody Wed Nov 03 13:15:35 2021 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 141CE183410A; Wed, 3 Nov 2021 13:15:38 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HknMF36Vzz4d1s; Wed, 3 Nov 2021 13:15:35 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 7D14B193EE; Wed, 3 Nov 2021 13:15:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1A3DFZ2D055424; Wed, 3 Nov 2021 13:15:35 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1A3DFZb9055423; Wed, 3 Nov 2021 13:15:35 GMT (envelope-from git) Date: Wed, 3 Nov 2021 13:15:35 GMT Message-Id: <202111031315.1A3DFZb9055423@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 009b4d719039 - stable/13 - vlapic: Schedule callouts on the local CPU 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 009b4d7190397032d21a7470ddf0cc93482297e2 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=009b4d7190397032d21a7470ddf0cc93482297e2 commit 009b4d7190397032d21a7470ddf0cc93482297e2 Author: Mark Johnston AuthorDate: 2021-10-20 00:50:06 +0000 Commit: Mark Johnston CommitDate: 2021-11-03 13:15:18 +0000 vlapic: Schedule callouts on the local CPU The virtual LAPIC driver uses callouts to implement the LAPIC timer. Callouts are armed using callout_reset_sbt(), which currently puts everything on CPU 0. On systems running many bhyve VMs this results in a large amount of contention for CPU 0's callout lock. Modify vlapic to schedule callouts on the local CPU instead. This allows timer interrupts to be scheduled more evenly among CPUs where bhyve is running. Reviewed by: grehan, jhb Sponsored by: The FreeBSD Foundation (cherry picked from commit 4c812fe61b7ce2f297a381950ff7bd87fd51f698) --- sys/amd64/vmm/io/vlapic.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/sys/amd64/vmm/io/vlapic.c b/sys/amd64/vmm/io/vlapic.c index 4e7ddbafd447..940e45cce458 100644 --- a/sys/amd64/vmm/io/vlapic.c +++ b/sys/amd64/vmm/io/vlapic.c @@ -83,6 +83,7 @@ __FBSDID("$FreeBSD$"); #define VLAPIC_BUS_FREQ (128 * 1024 * 1024) static void vlapic_set_error(struct vlapic *, uint32_t, bool); +static void vlapic_callout_handler(void *arg); static __inline uint32_t vlapic_get_id(struct vlapic *vlapic) @@ -710,6 +711,13 @@ vlapic_trigger_lvt(struct vlapic *vlapic, int vector) return (0); } +static void +vlapic_callout_reset(struct vlapic *vlapic, sbintime_t t) +{ + callout_reset_sbt_curcpu(&vlapic->callout, t, 0, + vlapic_callout_handler, vlapic, 0); +} + static void vlapic_callout_handler(void *arg) { @@ -765,8 +773,7 @@ vlapic_callout_handler(void *arg) } bintime_add(&vlapic->timer_fire_bt, &vlapic->timer_period_bt); - callout_reset_sbt(&vlapic->callout, rem_sbt, 0, - vlapic_callout_handler, vlapic, 0); + vlapic_callout_reset(vlapic, rem_sbt); } done: VLAPIC_TIMER_UNLOCK(vlapic); @@ -792,8 +799,7 @@ vlapic_icrtmr_write_handler(struct vlapic *vlapic) bintime_add(&vlapic->timer_fire_bt, &vlapic->timer_period_bt); sbt = bttosbt(vlapic->timer_period_bt); - callout_reset_sbt(&vlapic->callout, sbt, 0, - vlapic_callout_handler, vlapic, 0); + vlapic_callout_reset(vlapic, sbt); } else callout_stop(&vlapic->callout); @@ -1667,8 +1673,7 @@ vlapic_reset_callout(struct vlapic *vlapic, uint32_t ccr) bintime_add(&vlapic->timer_fire_bt, &bt); sbt = bttosbt(bt); - callout_reset_sbt(&vlapic->callout, sbt, 0, - vlapic_callout_handler, vlapic, 0); + vlapic_callout_reset(vlapic, sbt); } else { /* even if the CCR was 0, periodic timers should be reset */ if (vlapic_periodic_timer(vlapic)) { @@ -1678,8 +1683,7 @@ vlapic_reset_callout(struct vlapic *vlapic, uint32_t ccr) sbt = bttosbt(vlapic->timer_period_bt); callout_stop(&vlapic->callout); - callout_reset_sbt(&vlapic->callout, sbt, 0, - vlapic_callout_handler, vlapic, 0); + vlapic_callout_reset(vlapic, sbt); } }