Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 03 Jul 2026 15:33:17 +0000
From:      Olivier Certner <olce@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: c3c8f4d9e662 - main - cpu: New cpu_get_pcpuid(), retrieves internal CPU ID
Message-ID:  <6a47d63d.46209.5445b6f0@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch main has been updated by olce:

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

commit c3c8f4d9e66287b24af2b3881c528236b836f2f1
Author:     Olivier Certner <olce@FreeBSD.org>
AuthorDate: 2026-06-26 22:17:35 +0000
Commit:     Olivier Certner <olce@FreeBSD.org>
CommitDate: 2026-07-03 15:32:25 +0000

    cpu: New cpu_get_pcpuid(), retrieves internal CPU ID
    
    It is a handy shortcut that will be used extensively in
    hwpstate_intel(4) and hwpstate_amd(4).
    
    Warn users that it panics if the parent bus does not provide the
    CPU_IVAR_PCPU instance variable.  That condition should be tested by
    callers (doing so once is enough).  Suggest to do that in driver's
    attach method.
    
    Reviewed by:    jhb (code)
    Event:          Halifax Hackathon 202606
    Location:       Seat 36K in AC667, waiting for a gate at Montréal-Trudeau
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D57897
---
 sys/sys/cpu.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/sys/sys/cpu.h b/sys/sys/cpu.h
index 21e79e6db6a4..9156fa9f723d 100644
--- a/sys/sys/cpu.h
+++ b/sys/sys/cpu.h
@@ -51,6 +51,17 @@ cpu_get_pcpu(device_t dev)
 	return ((struct pcpu *)v);
 }
 
+/*
+ * Assumes the parent bus sets the CPU_IVAR_PCPU instance variable, which most
+ * CPU buses do.  A panic will ensure if not the case.  Calling devices should
+ * check for that condition (most probably in their attach function).
+ */
+static __inline u_int
+cpu_get_pcpuid(device_t dev)
+{
+	return (cpu_get_pcpu(dev)->pc_cpuid);
+}
+
 static __inline int32_t
 cpu_get_nominal_mhz(device_t dev)
 {


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6a47d63d.46209.5445b6f0>