From patchwork Fri Jul 7 10:56:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dimitri John Ledkov X-Patchwork-Id: 117095 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp3181895vqx; Fri, 7 Jul 2023 04:06:01 -0700 (PDT) X-Google-Smtp-Source: APBJJlGHOCGufcTIPUr1LWyXB93kasg0vD7oV9CjwcgEtsYz9THPF4F9L5mRDEQT6D0uCT7BrNxB X-Received: by 2002:a05:6358:918e:b0:134:5667:a16c with SMTP id j14-20020a056358918e00b001345667a16cmr5852296rwa.32.1688727960737; Fri, 07 Jul 2023 04:06:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688727960; cv=none; d=google.com; s=arc-20160816; b=yWZRHzSYad2Giav9HILE0+HlughlcH1wLkjmmaL7i8m+S0FbdCGbB/xYV8OaFOVwbk X5z8Vh8Z7yV/SaBanM4X/8+MbpA4Lrad9HCU4LmI6BY91zjVVL0LfzUhwRFJaT9ZVcBf Ry6jS4VJ3W8Yc2S69cNDC/Pd2tkvdZ4ZFbVubaW/eG2D841eSCaeTCWNdCaxEJ6AcQ5D vvTLUiEjXfjx0gP1nDBOULYRy1R/r8jh1BygbVagjtr8NMyBAscOQph8m2btFyZYwniW 9d8UPZI1AcaN9ttI1/hSRHeFH/l3ERfkFeHy4/LdIaWH524TxLsjf0h85C/x3Jvx5Ki2 sQwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=QIqxOuEMfymVjnTNBLkJVxXaeMv8lGdAOtu8dboON2E=; fh=QeKJyzMFxPxB4oesbWy/RTOkYWPpIlUB3zC7Bb8Pqnk=; b=PrzFZWYnpBsa6izrqcMtjOgio6tYnXvRFmEPkjmKsjQT9Pd/KQ/5l+nk5Cw7n/TW3C ADAvO1myI1PPgEkQISyfjfCCZTMlhgp4EX7TFpl8cBY+xPUSo6G0KAY1sEY0ZFnX80ms lq1eMbSqIh/EIW6qGoqTlnYseHJAQOdWNngVwZ9kJTpfoYr+FN0UbW7G6UwACRtsPDqW KUPIvP9mql4efxzinNqof8iPpJSMzhMPr70PI6h5+95UwoWWT+hsNGEx128ioLP883/D /VuHERqYxALyl794cfOlSV5nPp9NYKew9x2Tr2xmbMwkuVU8Vy8ZrgyHTyyo9foOIZjk AoJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=sz8hLHD0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u195-20020a6379cc000000b00543a881db0fsi3586865pgc.283.2023.07.07.04.05.45; Fri, 07 Jul 2023 04:06:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=sz8hLHD0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232808AbjGGK4f (ORCPT + 99 others); Fri, 7 Jul 2023 06:56:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232853AbjGGK40 (ORCPT ); Fri, 7 Jul 2023 06:56:26 -0400 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0EA6211E for ; Fri, 7 Jul 2023 03:56:23 -0700 (PDT) Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id BD98A3F363 for ; Fri, 7 Jul 2023 10:56:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1688727381; bh=QIqxOuEMfymVjnTNBLkJVxXaeMv8lGdAOtu8dboON2E=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=sz8hLHD0IpVzIkrrdjuERdG1JnV6tigT6HxaYKj3+/6kdc74yV1KyhJAKejy0Kz3P lRezd4QOteLNspAr7ygOR6+277iELvTRhWIaR6Il9fDrMOiUv6mlJEsIOCd5GaUqr2 B0c7ORbo8s/rodjXMfFsnQ6w6HU9BQLxcQM3yDhNyWl43jYshL3F1Bx+IpA0IwJol1 iG+1l+38JIXlRKvKbAXy5mL/ciAIhdfqhXip5XrTfU9KWmySIv3p07NcClY1UP3P7t 7GM4kXkI/+SZ1O0zjYKfsGXDu20OFkg2TWC5tmQPsGlKu7QOrT1GARdh1I0sUCVPF6 90z1mQFAQYzuQ== Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-31273e0507dso955527f8f.3 for ; Fri, 07 Jul 2023 03:56:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688727381; x=1691319381; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=QIqxOuEMfymVjnTNBLkJVxXaeMv8lGdAOtu8dboON2E=; b=CWRMTLij2X11E6XU33DvJ0zn8UT6c4qm5HM9GDtZ6Ah1g6hZit3cv9I4BDGiJB3LpT UDhqZAw1H4H5qiKF7txztG3WIt628SdSHz7J7KP17XvZj948rDeQZAo4eXu1IFhVAd18 IWOxCFtYgqL9ZpftDAZnUj08IZy7jbWBKX2kkRQjq/GmdrGncnxTuFDo2OvGTxPrqoBN ECDhTMAXv1zhxMGg3NFgwAzHqMDuKkKpb8dg0+VRUxE/YpGaFFJCEvmREbfRpSiA8Ij9 wFIhajquzVNpIoDLH7HczuwqLi2QHPihFVnbCKwFHlDSp4/gjkqgFG3eQkYOtn2/BUrK UtPw== X-Gm-Message-State: ABy/qLaYBqpuNdMW3sn5X7N5HO+6u9LmEYb//Lm3FGmM1t6UQVNWm6q2 nAIvC+eFIlv0vJxQ8GZO3bvYrljXeOjC+gD1Zd5J/At+ayjWZ7Nb7aYfWudHeisbWeAl9ykRx78 JLcyl+r1dsGbks3NQ+keEj1PnO8cZinbT/NxCNJ6srA== X-Received: by 2002:a5d:58c9:0:b0:315:8a86:cf7f with SMTP id o9-20020a5d58c9000000b003158a86cf7fmr367722wrf.70.1688727381178; Fri, 07 Jul 2023 03:56:21 -0700 (PDT) X-Received: by 2002:a5d:58c9:0:b0:315:8a86:cf7f with SMTP id o9-20020a5d58c9000000b003158a86cf7fmr367704wrf.70.1688727380897; Fri, 07 Jul 2023 03:56:20 -0700 (PDT) Received: from localhost ([137.220.91.195]) by smtp.gmail.com with ESMTPSA id f18-20020adff992000000b003143c532431sm4164228wrr.27.2023.07.07.03.56.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 03:56:20 -0700 (PDT) From: Dimitri John Ledkov To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Cc: linux-kernel@vger.kernel.org Subject: [PATCH] x86/cpu: Add support for modern x86-64-v* march Date: Fri, 7 Jul 2023 11:56:00 +0100 Message-Id: <20230707105601.133221-1-dimitri.ledkov@canonical.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770759610457075776?= X-GMAIL-MSGID: =?utf-8?q?1770759610457075776?= Add support for setting march to x86-64-v2, x86-64-v3, x86-64-v4 with tuning set to an early family of CPUs that support such instruction levels. By default gcc sets generic tuning for x86-64-v*, which is suboptimal for all brands of CPUs with such instruction set support. Signed-off-by: Dimitri John Ledkov --- arch/x86/Kconfig.cpu | 23 ++++++++++++++++++++++- arch/x86/Makefile | 11 +++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu index 00468adf18..70e70b4733 100644 --- a/arch/x86/Kconfig.cpu +++ b/arch/x86/Kconfig.cpu @@ -294,6 +294,27 @@ config GENERIC_CPU Generic x86-64 CPU. Run equally well on all x86-64 CPUs. +config X86_64_V2 + bool "x86-64-v2" + depends on X86_64 + help + x86-64-v2 CPU. + Run well on x86-64-v2 capable CPUs. + +config X86_64_V3 + bool "x86-64-v3" + depends on X86_64 + help + x86-64-v3 CPU. + Run well on x86-64-v3 capable CPUs. + +config X86_64_V4 + bool "x86-64-v4" + depends on X86_64 + help + x86-64-v4 CPU. + Run well on x86-64-v4 capable CPUs. + endchoice config X86_GENERIC @@ -318,7 +339,7 @@ config X86_INTERNODE_CACHE_SHIFT config X86_L1_CACHE_SHIFT int default "7" if MPENTIUM4 || MPSC - default "6" if MK7 || MK8 || MPENTIUMM || MCORE2 || MATOM || MVIAC7 || X86_GENERIC || GENERIC_CPU + default "6" if MK7 || MK8 || MPENTIUMM || MCORE2 || MATOM || MVIAC7 || X86_GENERIC || GENERIC_CPU || X86_64_V2 || X86_64_V3 || X86_64_V4 default "4" if MELAN || M486SX || M486 || MGEODEGX1 default "5" if MWINCHIP3D || MWINCHIPC6 || MCRUSOE || MEFFICEON || MCYRIXIII || MK6 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || MVIAC3_2 || MGEODE_LX diff --git a/arch/x86/Makefile b/arch/x86/Makefile index fdc2e3abd6..ee97501970 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -154,6 +154,14 @@ else cflags-$(CONFIG_MCORE2) += -march=core2 cflags-$(CONFIG_MATOM) += -march=atom cflags-$(CONFIG_GENERIC_CPU) += -mtune=generic + # Note gcc for -march=x86-64-v* sets genetic tuning only, + # rather than something sensible / minimum tuning from the + # same family. Set mtune to early family of CPUs that support + # such instructions, which works better across all CPU brands. + cflags-$(CONFIG_X86_64_V2) += -march=x86-64-v2 -mtune=nehalem + cflags-$(CONFIG_X86_64_V3) += -march=x86-64-v3 -mtune=skylake + cflags-$(CONFIG_X86_64_V4) += -march=x86-64-v4 -mtune=skylake-avx512 + KBUILD_CFLAGS += $(cflags-y) rustflags-$(CONFIG_MK8) += -Ctarget-cpu=k8 @@ -161,6 +169,9 @@ else rustflags-$(CONFIG_MCORE2) += -Ctarget-cpu=core2 rustflags-$(CONFIG_MATOM) += -Ctarget-cpu=atom rustflags-$(CONFIG_GENERIC_CPU) += -Ztune-cpu=generic + rustflags-$(CONFIG_X86_64_V2) += -Ctarget-cpu=x86-64-v2 + rustflags-$(CONFIG_X86_64_V3) += -Ctarget-cpu=x86-64-v3 + rustflags-$(CONFIG_X86_64_V4) += -Ctarget-cpu=x86-64-v4 KBUILD_RUSTFLAGS += $(rustflags-y) KBUILD_CFLAGS += -mno-red-zone