From nobody Fri Jul 24 04:35:12 2026 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 4h5wC46jbXz6lsWc for ; Fri, 24 Jul 2026 04:35:12 +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 "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4h5wC42rt8z3ZVR for ; Fri, 24 Jul 2026 04:35:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1784867712; 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=PbT2ako4bpYbPK92jnqaxf5EyXx2yjvY3TelzfYC3ZY=; b=cAEmKk2wobLez37rJBoHJQjT1d9xc5vHhRRxGusrwE/LtiYXRPWzb/FUjIN+QXSnYCIbmc vrEZX4O4MevIYjMAPZeybPgeatKqFKkuWHd9K4ce8zoQG4u1FMG1G5d4VZ0voYibGlzKog TyYTKjJZmFpfh4jvtPaC760hGeFVXFCue/VMKB8TjyCPYaksAXZQTLbZYkkGvk4nCrWvve 0ITgcRs1NMVXRkm2YX71rFbQCKMQL04R8nNwhaDlqgx0Q0pFzC8wXObXB2yLGPdRmHormv oG+R/3tc0LJK2kOAm8GzFg9sxCX8716zNYXENuIQDMwG5BuRA14ffXEzydxbFA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1784867712; a=rsa-sha256; cv=none; b=v9o0mVT5pdiJwGtlKVMifwAQwSyjTATpPMUDp4HGOV+tnbFwQ71nhv3YeoozKtxFxzBgh6 ht1G6zNLBktv9393EIxzf6p7gprO4XjDW6j6msOQ87f2u3IhJVw5HAQnCosfL+diduNqjN dXu2oZ+4jWOC3IxS8lDxckhtqMT5U1cr8soEX3EISnMiSOWfM6v7ydRkf5fT62sJIAzi3J +Rksota1s67BU4OY8yGMb1qPgFYbOUmHCYwQhec4g7U3gOMmdjJ67BspNubgnClvuh9FcL XpNqEzn6na/I774yqq2byKzGMZ30qw6I97ezJ+6G7BTIqKScoTGeWtOKcF05bw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1784867712; 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=PbT2ako4bpYbPK92jnqaxf5EyXx2yjvY3TelzfYC3ZY=; b=RfOkf0f7KW5yLnXe2mZsVte2C/H1wBv2vc20uvqLz64aljpft0vpehssWdyWi6slUrwlIO t80SceilfosxGa2IaH4CNdnV/z1LQNULooxRo0bQ93WyudSW/+gclVjDrOG/DT3lzhwa4V pure8FoyIXL6HnLdEgt2oya92x5fs7TPnjMS4GwdferF2jhs1m0bESBi1pHLq5FxBtY5WO eZZl7O7vklNDLUnjjYm5+2zoiM8ikxCFBrjtFlZKI1G4J1GR/5bi/OdJhE6Lpu+cEhOEX9 N7d3ZVfoIeCFU0wwX/J73MCyCxLGKJjCHc3Vbbc+RUFtG65zeeUt5+B4tRAQ4Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4h5wC41pTGzcBQ for ; Fri, 24 Jul 2026 04:35:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 385dd by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 24 Jul 2026 04:35:12 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Olivier Certner Subject: git: 93dbde154260 - stable/15 - x86/local_apic.c: Factor out version read and max LVT slot computation 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: olce X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 93dbde1542606eda4eb601caf715241869f47966 Auto-Submitted: auto-generated Date: Fri, 24 Jul 2026 04:35:12 +0000 Message-Id: <6a62eb80.385dd.6f25ea5d@gitrepo.freebsd.org> The branch stable/15 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=93dbde1542606eda4eb601caf715241869f47966 commit 93dbde1542606eda4eb601caf715241869f47966 Author: Olivier Certner AuthorDate: 2026-07-08 12:59:28 +0000 Commit: Olivier Certner CommitDate: 2026-07-24 04:33:38 +0000 x86/local_apic.c: Factor out version read and max LVT slot computation This makes the code slightly more compact and easier to read. No functional change intended. Reviewed by: bnovkov MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D58110 (cherry picked from commit 060ecf296664fd150328ac6dcdc24764a427bc3a) --- sys/x86/x86/local_apic.c | 72 ++++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/sys/x86/x86/local_apic.c b/sys/x86/x86/local_apic.c index 1c0132d81bff..821b17358448 100644 --- a/sys/x86/x86/local_apic.c +++ b/sys/x86/x86/local_apic.c @@ -333,16 +333,6 @@ SYSCTL_INT(_hw_apic, OID_AUTO, ds_idle_timeout, CTLFLAG_RWTUN, static void lapic_calibrate_initcount(struct lapic *la); -/* - * Calculate the max index of the present LVT entry from the value of - * the LAPIC version register. - */ -static int -lapic_maxlvt(uint32_t version) -{ - return ((version & APIC_VER_MAXLVT) >> MAXLVTSHIFT); -} - /* * Use __nosanitizethread to exempt the LAPIC I/O accessors from KCSan * instrumentation. Otherwise, if x2APIC is not available, use of the global @@ -390,6 +380,28 @@ lapic_write32_nofence(enum LAPIC_REGISTERS reg, uint32_t val) } } +static inline uint32_t __pure2 +lapic_version(void) +{ + return (lapic_read32(LAPIC_VERSION)); +} + +/* + * Calculate the max index of the present LVT entry from the value of + * the LAPIC version register. + */ +static inline int __pure2 +lapic_version_maxlvt(uint32_t version) +{ + return ((version & APIC_VER_MAXLVT) >> MAXLVTSHIFT); +} + +static inline int __pure2 +lapic_maxlvt(void) +{ + return (lapic_version_maxlvt(lapic_version())); +} + #ifdef SMP static uint64_t lapic_read_icr_lo(void) @@ -645,7 +657,7 @@ lapic_init(vm_paddr_t addr) * It seems that at least some KVM versions report * EOI_SUPPRESSION bit, but auto-EOI does not work. */ - ver = lapic_read32(LAPIC_VERSION); + ver = lapic_version(); if ((ver & APIC_VER_EOI_SUPPRESSION) != 0) { lapic_eoi_suppression = 1; if (vm_guest == VM_GUEST_KVM) { @@ -752,7 +764,7 @@ amd_read_ext_features(void) if (cpu_vendor_id != CPU_VENDOR_AMD && cpu_vendor_id != CPU_VENDOR_HYGON) return (0); - version = lapic_read32(LAPIC_VERSION); + version = lapic_version(); if ((version & APIC_VER_AMD_EXT_SPACE) != 0) return (lapic_read32(LAPIC_EXT_FEATURES)); else @@ -777,14 +789,12 @@ amd_read_elvt_count(void) void lapic_dump(const char* str) { - uint32_t version; - uint32_t maxlvt; + const uint32_t version = lapic_version(); + const int maxlvt = lapic_version_maxlvt(version); uint32_t extf; int elvt_count; int i; - version = lapic_read32(LAPIC_VERSION); - maxlvt = lapic_maxlvt(version); printf("cpu%d %s:\n", PCPU_GET(cpuid), str); printf(" ID: 0x%08x VER: 0x%08x LDR: 0x%08x DFR: 0x%08x", lapic_read32(LAPIC_ID), version, @@ -841,10 +851,8 @@ static void lapic_early_mask_vecs(void) { int elvt_count, lvts_count, i; - uint32_t version; - version = lapic_read32(LAPIC_VERSION); - lvts_count = min(nitems(lvts), lapic_maxlvt(version) + 1); + lvts_count = min(nitems(lvts), lapic_maxlvt() + 1); for (i = 0; i < lvts_count; i++) lapic_early_mask_vec(&lvts[i]); @@ -856,9 +864,9 @@ lapic_early_mask_vecs(void) void lapic_setup(int boot) { + const uint32_t version = lapic_version(); + const uint32_t maxlvt = lapic_version_maxlvt(version); struct lapic *la; - uint32_t version; - uint32_t maxlvt; register_t saveintr; int elvt_count; int i; @@ -867,8 +875,6 @@ lapic_setup(int boot) la = &lapics[lapic_id()]; KASSERT(la->la_present, ("missing APIC structure")); - version = lapic_read32(LAPIC_VERSION); - maxlvt = lapic_maxlvt(version); /* Initialize the TPR to allow all interrupts. */ lapic_set_tpr(0); @@ -1017,8 +1023,6 @@ lapic_calibrate_timer(void) int lapic_enable_pcint(void) { - u_int32_t maxlvt; - #ifdef DEV_ATPIC /* Fail if the local APIC is not present. */ if (!x2apic_mode && lapic_map == NULL) @@ -1026,8 +1030,7 @@ lapic_enable_pcint(void) #endif /* Fail if the PMC LVT is not present. */ - maxlvt = lapic_maxlvt(lapic_read32(LAPIC_VERSION)); - if (maxlvt < APIC_LVT_PMC) + if (lapic_maxlvt() < APIC_LVT_PMC) return (0); if (refcount_acquire(&pcint_refcnt) > 0) return (1); @@ -1041,8 +1044,6 @@ lapic_enable_pcint(void) void lapic_disable_pcint(void) { - u_int32_t maxlvt; - #ifdef DEV_ATPIC /* Fail if the local APIC is not present. */ if (!x2apic_mode && lapic_map == NULL) @@ -1050,8 +1051,7 @@ lapic_disable_pcint(void) #endif /* Fail if the PMC LVT is not present. */ - maxlvt = lapic_maxlvt(lapic_read32(LAPIC_VERSION)); - if (maxlvt < APIC_LVT_PMC) + if (lapic_maxlvt() < APIC_LVT_PMC) return; if (!refcount_release(&pcint_refcnt)) return; @@ -1968,19 +1968,19 @@ DB_SHOW_COMMAND_FLAGS(lapic, db_show_lapic, DB_CMD_MEMSAFE) { const struct lvt *l; int elvt_count, lvts_count, i; - uint32_t v, vr; + const uint32_t v = lapic_version(); + const int maxlvt = lapic_version_maxlvt(v); + const uint32_t vr = lapic_read32(LAPIC_SVR); db_printf("lapic ID = %d\n", lapic_id()); - v = lapic_read32(LAPIC_VERSION); db_printf("version = %d.%d (%#x) \n", (v & APIC_VER_VERSION) >> 4, v & 0xf, v); - db_printf("max LVT = %d\n", lapic_maxlvt(v)); - vr = lapic_read32(LAPIC_SVR); + db_printf("max LVT = %d\n", maxlvt); db_printf("SVR = %02x (%s)\n", vr & APIC_SVR_VECTOR, vr & APIC_SVR_ENABLE ? "enabled" : "disabled"); db_printf("TPR = %02x\n", lapic_read32(LAPIC_TPR)); - lvts_count = min(nitems(lvts), lapic_maxlvt(v) + 1); + lvts_count = min(nitems(lvts), maxlvt + 1); for (i = 0; i < lvts_count; i++) { l = &lvts[i]; db_printf("LVT%d (reg %#x %-5s) = %#010x\n", i, l->lvt_reg,