From patchwork Sun May 15 17:11:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Lepiller X-Patchwork-Id: 39377 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id B29B927BBEA; Sun, 15 May 2022 18:13:36 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 083B027BBE9 for ; Sun, 15 May 2022 18:13:36 +0100 (BST) Received: from localhost ([::1]:59760 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nqHoE-0006mS-Hd for patchwork@mira.cbaines.net; Sun, 15 May 2022 13:13:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60386) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nqHni-0006mF-6A for guix-patches@gnu.org; Sun, 15 May 2022 13:13:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:56670) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nqHnh-0000r0-U1 for guix-patches@gnu.org; Sun, 15 May 2022 13:13:01 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nqHnh-0004SL-Q1 for guix-patches@gnu.org; Sun, 15 May 2022 13:13:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#55431] [PATCH] guix: cpu: recognize other architectures. Resent-From: Julien Lepiller Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 15 May 2022 17:13:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 55431 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 55431@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.165263473217071 (code B ref -1); Sun, 15 May 2022 17:13:01 +0000 Received: (at submit) by debbugs.gnu.org; 15 May 2022 17:12:12 +0000 Received: from localhost ([127.0.0.1]:50567 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nqHmt-0004RH-Q3 for submit@debbugs.gnu.org; Sun, 15 May 2022 13:12:12 -0400 Received: from lists.gnu.org ([209.51.188.17]:40518) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nqHms-0004R9-Bp for submit@debbugs.gnu.org; Sun, 15 May 2022 13:12:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60276) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nqHmr-0006go-TB for guix-patches@gnu.org; Sun, 15 May 2022 13:12:10 -0400 Received: from lepiller.eu ([2a00:5884:8208::1]:54284) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nqHmp-0000it-OI for guix-patches@gnu.org; Sun, 15 May 2022 13:12:09 -0400 Received: from lepiller.eu (localhost [127.0.0.1]) by lepiller.eu (OpenSMTPD) with ESMTP id d1c6996c for ; Sun, 15 May 2022 17:12:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=lepiller.eu; h=date:from :to:subject:message-id:mime-version:content-type; s=dkim; bh=N6a yDETuXb2TovcWRXIBcBy+AvJtyKGKkV+Tp9Vtxas=; b=TEkOqfBuJJpAP9d0jQK j3XVdBAs89pi5jSRrqXHP/5hVUfDJ/KQQwabJldcfStkLSh2nvRbcGOhtYeOpwdV KclxK0m0VrTOuU4gewfqzvL1JfJTlkfNrqYKPAxaKboCEzbEICkqln+v6Dki9HqZ SCwjyrJ3yIOXnLkO3ZpWr4QZR2wdUSUflGjWKjXmGSYUFcm50yIkW3NQGeG1SP4u S/lGSNYewYqXlmZYFc5BHdJR0+7B0xcLFY4jrhzaOmRZ0a97bKcZaVxNicxVPZYe +oqeIodEP0zZzf7GAQdNxWfQbjUhO1aWK+QDfva4VTfo+r/fjP4wrgKor6evFDlj RwQ== Received: by lepiller.eu (OpenSMTPD) with ESMTPSA id 5220eecf (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO) for ; Sun, 15 May 2022 17:12:00 +0000 (UTC) Date: Sun, 15 May 2022 19:11:32 +0200 From: Julien Lepiller Message-ID: <20220515191132.288dc60d@sybil.lepiller.eu> X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:5884:8208::1; envelope-from=julien@lepiller.eu; helo=lepiller.eu X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches Hi Guix! The attached patch lets (guix cpu) recognize other architectures. The code of (current-cpu) is based on the content of /proc/cpuinfo which can be pretty different on non-intel architectures. For instance, here's a sample from an armhf machine: processor : 0 model name : ARMv7 Processor rev 4 (v7l) BogoMIPS : 45.47 Features : half thumb fastmult vfp edsp thumbee neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm CPU implementer : 0x41 CPU architecture: 7 CPU variant : 0x0 CPU part : 0xc07 CPU revision : 4 In particular, there's no flags entry, so (current-cpu) doesn't stop until eof, and returns #f. It's an issue because a test uses this code, for testing manifests with --tune. If no cpu is returned, the test crashes: In guix/transformations.scm: 864:25 1 (_ _ _ _ ((package ad-hoc-package "gcc-toolchain") (<80>) <80>)) In guix/cpu.scm: 94:2 0 (cpu->gcc-architecture #f) Since the test fails, the "guix" package doesn't build, and I can't reconfigure on armhf or aarch64. (well armhf has other issues right now...) The attached patch changes the logic of the code to read all lines, find information about the CPU even if it's an ARM CPU, and returns always something (to prevent the crash) when it reads eof. This means that it will return architecture information about the last CPU, instead of the first. I don't think that's an issue because this code is used for --tune which really only works on intel where you don't have multiple CPUs with too different features. WDYT? From 32ebfc93f838eba74c1f1188f7d23363f32ee94b Mon Sep 17 00:00:00 2001 From: Julien Lepiller Date: Sun, 15 May 2022 19:01:37 +0200 Subject: [PATCH] guix: cpu: Recognize other architectures. * guix/cpu.scm (current-cpu): Recognize aarch64. --- guix/cpu.scm | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/guix/cpu.scm b/guix/cpu.scm index a44cd082f1..7e25fcb9cf 100644 --- a/guix/cpu.scm +++ b/guix/cpu.scm @@ -62,31 +62,48 @@ (define (prefix? prefix) (lambda (port) (let loop ((vendor #f) (family #f) - (model #f)) + (model #f) + (flags '())) (match (read-line port) ((? eof-object?) - #f) + (cpu (utsname:machine (uname)) + vendor family model (list->set flags))) ((? (prefix? "vendor_id") str) (match (string-tokenize str) (("vendor_id" ":" vendor) - (loop vendor family model)))) + (loop vendor family model flags)))) + ((? (prefix? "CPU implementer") str) + (match (string-tokenize str) + (("CPU" "implementer" ":" vendor) + (loop vendor family model flags)))) ((? (prefix? "cpu family") str) (match (string-tokenize str) (("cpu" "family" ":" family) - (loop vendor (string->number family) model)))) + (loop vendor (string->number family) model flags)))) + ((? (prefix? "CPU architecture") str) + (match (string-tokenize str) + (("CPU" "architecture:" family) + (loop vendor family model flags)))) ((? (prefix? "model") str) (match (string-tokenize str) (("model" ":" model) - (loop vendor family (string->number model))) + (loop vendor family (string->number model) flags)) (_ - (loop vendor family model)))) + (loop vendor family model flags)))) + ((? (prefix? "CPU part") str) + (match (string-tokenize str) + (("CPU" "part" ":" model) + (loop vendor family (string->number (substring model 2) 16) flags)))) ((? (prefix? "flags") str) (match (string-tokenize str) (("flags" ":" flags ...) - (cpu (utsname:machine (uname)) - vendor family model (list->set flags))))) + (loop vendor family model flags)))) + ((? (prefix? "Features") str) + (match (string-tokenize str) + (("Features" ":" flags ...) + (loop vendor family model flags)))) (_ - (loop vendor family model)))))))) + (loop vendor family model flags)))))))) (define (cpu->gcc-architecture cpu) "Return the architecture name, suitable for GCC's '-march' flag, that -- 2.35.1