From nobody Wed May 15 04:03:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1644484242; cv=none; d=zohomail.com; s=zohoarc; b=Ll2cL7zxpb1ITKh5KCADgczd8hLvNMLRZZnPgld4pXBgsFD6M8ht0d7iajG+dGJx4dUfWuc7tdyE7xqwtIFz1xXzmAu5Hv1PzJ5CzqPnrRn2YWNz/erCj0uwHCfU0gFWhJSKDr8ggCQdlDklUi9X38YAu4jh+Tj81VLwvYtNPyk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644484242; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=banDBLdJhTWH0Mj8nyMjS7yxWEtL7ATHjJMD5UuJA/0=; b=KOzM3WbYILBQ+51ttbhxFn/V2hu028fFJn7wIdr5VdUypZ/Cv7YhBrf8bjh5nN867Gx+9HuYOJ++9iyErz6IcJ7G1cZO3VnRXqZk4Al8ved38BwBX11xUe9e+aEW9+o+Eh2wNRfsEdDMVG2M4ORzRwU9XkrxqFVSvciEn0hnLv4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1644484242855348.8534075497996; Thu, 10 Feb 2022 01:10:42 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-30-MpGEz40nPJqDCyUzqCeODQ-1; Thu, 10 Feb 2022 04:10:39 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 31B391B2C984; Thu, 10 Feb 2022 09:10:34 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7D3D2783AA; Thu, 10 Feb 2022 09:10:32 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 262C91809CBA; Thu, 10 Feb 2022 09:10:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21A98mRJ006264 for ; Thu, 10 Feb 2022 04:08:48 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9FF5D7A22B; Thu, 10 Feb 2022 09:08:48 +0000 (UTC) Received: from harajuku.usersys.redhat.com.homenet.telecomitalia.it (unknown [10.40.194.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 01BAD7AB71; Thu, 10 Feb 2022 09:08:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644484241; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=banDBLdJhTWH0Mj8nyMjS7yxWEtL7ATHjJMD5UuJA/0=; b=TcOrqUK2F64d/QHWrEiWlcQT+HksUPS5V/IXXWVyBls7IUQnroyF5lk1TUHmpFKdgKoamJ Ehb2wavG7YfbxqYwR0IRABunu/D7b/9LGPFYS/tcpODi8nYCCIUFEKTnrdt4AdvYFRFLKI Hk3o1gvTYBQcLt4ScZJFKvDI+eeXsAQ= X-MC-Unique: MpGEz40nPJqDCyUzqCeODQ-1 From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH] util: Fix getting CPU frequency on Apple Silicon Date: Thu, 10 Feb 2022 10:08:42 +0100 Message-Id: <20220210090842.99280-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: huanghaorui301@gmail.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644484243597100001 Content-Type: text/plain; charset="utf-8" The hw.cpufrequency sysctl, which we use to obtain the CPU frequency on macOS, is not available when running on Apple Silicon, and as a consequence we currently report an error whenever such information is requested. The virNodeInfo.mhz field, where the CPU frequency gets stored, is documented as being zero when the information could not be obtained, and we already do that for Linux on aarch64. Extend this behavior to macOS on Apple Silicon. Signed-off-by: Andrea Bolognani Reviewed-by: Michal Privoznik --- src/util/virhostcpu.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c index a07c00a0e9..011ef8a153 100644 --- a/src/util/virhostcpu.c +++ b/src/util/virhostcpu.c @@ -928,8 +928,14 @@ virHostCPUGetInfo(virArch hostarch G_GNUC_UNUSED, *mhz =3D cpu_freq; # else if (sysctlbyname("hw.cpufrequency", &cpu_freq, &cpu_freq_len, NULL, 0)= < 0) { - virReportSystemError(errno, "%s", _("cannot obtain CPU freq")); - return -1; + if (errno =3D=3D ENOENT) { + /* The hw.cpufrequency sysctl is not implemented on Apple Sili= con. + * In that case, we report 0 instead of erroring out */ + cpu_freq =3D 0; + } else { + virReportSystemError(errno, "%s", _("cannot obtain CPU freq")); + return -1; + } } =20 *mhz =3D cpu_freq / 1000000; --=20 2.34.1