Skip to content

Commit

Permalink
[skip ci]fix linux
Browse files Browse the repository at this point in the history
  • Loading branch information
SekaiMoe committed Jul 2, 2024
1 parent 2ec03b2 commit 0406026
Show file tree
Hide file tree
Showing 35 changed files with 16,526 additions and 0 deletions.
11,818 changes: 11,818 additions & 0 deletions linux-g14/asus_defconfig

Large diffs are not rendered by default.

142 changes: 142 additions & 0 deletions linux-g14/choose-gcc-optimization.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#!/usr/bin/env bash

set -e

. /usr/share/makepkg/util/message.sh
[[ -t 1 ]] && colorize

Detect_CPU=$(gcc -c -Q -march=native --help=target | grep march | awk '{print $2}' | head -1)

msg "Detected CPU architecture: $Detect_CPU"

cat << EOF
Available CPU microarchitectures:
1) AMD K6/K6-II/K6-III
2) AMD Athlon/Duron/K7
3) AMD Opteron/Athlon64/Hammer/K8
4) AMD Opteron/Athlon64/Hammer/K8 with SSE3
5) AMD 61xx/7x50/PhenomX3/X4/II/K10
6) AMD Family 10h (Barcelona)
7) AMD Family 14h (Bobcat)
8) AMD Family 16h (Jaguar)
9) AMD Family 15h (Bulldozer)
10) AMD Family 15h (Piledriver)
11) AMD Family 15h (Steamroller)
12) AMD Family 15h (Excavator)
13) AMD Family 17h (Zen)
14) AMD Family 17h (Zen 2)
15) AMD Family 19h Zen 3 processors (Zen 3)
16) Transmeta Crusoe
17) Transmeta Efficeon
18) IDT Winchip C6
19) Winchip-2/Winchip-2A/Winchip-3
20) AMD Elan
21) Geode GX1 (Cyrix MediaGX)
22) AMD Geode GX and LX
23) Cyrix III or C3
24) VIA C3 "Nehemiah"
25) VIA C7
26) Intel Pentium 4, Pentium D and older Nocona/Dempsey Xeon CPUs with Intel 64bit
27) Intel Atom
28) Intel Core 2 and newer Core 2 Xeons (Xeon 51xx and 53xx)
29) Intel 1st Gen Core i3/i5/i7-family (Nehalem)
30) Intel 1.5 Gen Core i3/i5/i7-family (Westmere)
31) Intel Silvermont
32) Intel Goldmont (Apollo Lake and Denverton)
33) Intel Goldmont Plus (Gemini Lake)
34) Intel 2nd Gen Core i3/i5/i7-family (Sandybridge)
35) Intel 3rd Gen Core i3/i5/i7-family (Ivybridge)
36) Intel 4th Gen Core i3/i5/i7-family (Haswell)
37) Intel 5th Gen Core i3/i5/i7-family (Broadwell)
38) Intel 6th Gen Core i3/i5/i7-family (Skylake)
39) Intel 6th Gen Core i7/i9-family (Skylake X)
40) Intel 8th Gen Core i3/i5/i7-family (Cannon Lake)
41) Intel 8th Gen Core i7/i9-family (Ice Lake)
42) Xeon processors in the Cascade Lake family
43) Intel Xeon (Cooper Lake)
44) Intel 3rd Gen 10nm++ i3/i5/i7/i9-family (Tiger Lake)
45) Intel Sapphire Rapids
46) Intel Rocket Lake
47) Intel Alder Lake
92) Generic-x86-64-v2 (Nehalem and newer)
93) Generic-x86-64-v3 (Haswell and newer)
94) Generic-x86-64-v4 (AVX512 CPUs)
98) Intel-Native optimizations autodetected by GCC
99) AMD-Native optimizations autodetected by GCC
0) Generic (default)
EOF

sleep 1
answer=$1

case $answer in
1) Microarchitecture=CONFIG_MK6 ;;
2) Microarchitecture=CONFIG_MK7 ;;
3) Microarchitecture=CONFIG_MK8 ;;
4) Microarchitecture=CONFIG_MK8SSE3 ;;
5) Microarchitecture=CONFIG_MK10 ;;
6) Microarchitecture=CONFIG_MBARCELONA ;;
7) Microarchitecture=CONFIG_MBOBCAT ;;
8) Microarchitecture=CONFIG_MJAGUAR ;;
9) Microarchitecture=CONFIG_MBULLDOZER ;;
10) Microarchitecture=CONFIG_MPILEDRIVER ;;
11) Microarchitecture=CONFIG_MSTEAMROLLER ;;
12) Microarchitecture=CONFIG_MEXCAVATOR ;;
13) Microarchitecture=CONFIG_MZEN ;;
14) Microarchitecture=CONFIG_MZEN2 ;;
15) Microarchitecture=CONFIG_MZEN3 ;;
16) Microarchitecture=CONFIG_MCRUSOE ;;
17) Microarchitecture=CONFIG_MEFFICEON ;;
18) Microarchitecture=CONFIG_MWINCHIPC6 ;;
19) Microarchitecture=CONFIG_MWINCHIP3D ;;
20) Microarchitecture=CONFIG_MELAN ;;
21) Microarchitecture=CONFIG_MGEODEGX1 ;;
22) Microarchitecture=CONFIG_MGEODE_LX ;;
23) Microarchitecture=CONFIG_MCYRIXIII ;;
24) Microarchitecture=CONFIG_MVIAC3_2 ;;
25) Microarchitecture=CONFIG_MVIAC7 ;;
26) Microarchitecture=CONFIG_MPSC ;;
27) Microarchitecture=CONFIG_MATOM ;;
28) Microarchitecture=CONFIG_MCORE2 ;;
29) Microarchitecture=CONFIG_MNEHALEM ;;
30) Microarchitecture=CONFIG_MWESTMERE ;;
31) Microarchitecture=CONFIG_MSILVERMONT ;;
32) Microarchitecture=CONFIG_MGOLDMONT ;;
33) Microarchitecture=CONFIG_MGOLDMONTPLUS ;;
34) Microarchitecture=CONFIG_MSANDYBRIDGE ;;
35) Microarchitecture=CONFIG_MIVYBRIDGE ;;
36) Microarchitecture=CONFIG_MHASWELL ;;
37) Microarchitecture=CONFIG_MBROADWELL ;;
38) Microarchitecture=CONFIG_MSKYLAKE ;;
39) Microarchitecture=CONFIG_MSKYLAKEX ;;
40) Microarchitecture=CONFIG_MCANNONLAKE ;;
41) Microarchitecture=CONFIG_MICELAKE ;;
42) Microarchitecture=CONFIG_MCASCADELAKE ;;
43) Microarchitecture=CONFIG_MCOOPERLAKE ;;
44) Microarchitecture=CONFIG_MTIGERLAKE ;;
45) Microarchitecture=CONFIG_MSAPPHIRERAPIDS ;;
46) Microarchitecture=CONFIG_MROCKETLAKE ;;
47) Microarchitecture=CONFIG_MALDERLAKE ;;
92) Microarchitecture=CONFIG_GENERIC_CPU2 ;;
93) Microarchitecture=CONFIG_GENERIC_CPU3 ;;
94) Microarchitecture=CONFIG_GENERIC_CPU4 ;;
98) Microarchitecture=CONFIG_MNATIVE_INTEL ;;
99) Microarchitecture=CONFIG_MNATIVE_AMD ;;
*) default=CONFIG_GENERIC_CPU ;;
esac

warning "According to PKGBUILD variable _microarchitecture, your choice is $answer"
msg "Building this package for microarchitecture: $Microarchitecture$default"
sleep 5

sed -e 's|^CONFIG_GENERIC_CPU=y|# CONFIG_GENERIC_CPU is not set|g' -i .config
sed -e 's|^CONFIG_GENERIC_CPU2=y|# CONFIG_GENERIC_CPU2 is not set|g' -i .config
sed -e "s|^# $Microarchitecture is not set|$Microarchitecture=y|g" -i .config

echo
38 changes: 38 additions & 0 deletions linux-g14/patch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

set -e

scripts/config --disable CONFIG_INFINIBAND \
--disable CONFIG_DRM_NOUVEAU \
--disable CONFIG_DRM_RADEON \
--disable CONFIG_IIO \
--disable CONFIG_CAN_DEV \
--disable CONFIG_PCMCIA_WL3501 \
--disable CONFIG_PCMCIA_RAYCS \
--disable CONFIG_IWL3945 \
--disable CONFIG_IWL4965 \
--disable CONFIG_IPW2200 \
--disable CONFIG_IPW2100 \
--disable CONFIG_FB_NVIDIA \
--disable CONFIG_SENSORS_ASUS_EC \
--disable CONFIG_SENSORS_ASUS_WMI_EC

# select slightly more sane block device driver options; NVMe really should be built in
scripts/config --disable CONFIG_RAPIDIO \
--module CONFIG_CDROM \
--disable CONFIG_PARIDE \

# bake in s0ix debugging parameters so we get useful problem reports re: suspend
scripts/config --enable CONFIG_CMDLINE_BOOL \
--set-str CONFIG_CMDLINE "makepkgplaceholderyolo" \
--disable CMDLINE_OVERRIDE

# enable back EFI_HANDOVER_PROTOCOL and EFI_STUB
scripts/config --enable CONFIG_EFI_HANDOVER_PROTOCOL \
--enable CONFIG_EFI_STUB

# try to fix stuttering on some ROG laptops
scripts/config --disable CONFIG_HW_RANDOM_TPM

# enable SCHED_CLASS_EXT
scripts/config --enable CONFIG_SCHED_CLASS_EXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
From cfadb2992e771f8b5bdbdbfe6c2fdd2fd964de1d Mon Sep 17 00:00:00 2001
From: hqp1203 <hqp1203hqp@163.com>
Date: Tue, 14 Mar 2023 22:30:57 +0800
Subject: [PATCH 01/11] ACPI: resource: Skip IRQ override on ASUS TUF Gaming
A15
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

On that Linux kernel, my laptop's built-in keyboard isn't working. It is
suspected that the architecture of higher vresion of AMD's chip(the spec
ific CPU model is 7735h)conflicts with IRQ of the current Linux Kernel.
The solution is to add my laptop model number under drivers/acpi/resourc-
e.c to skip IRQ overrides. After modification, it was found that the key-
board worked properly.
My laptop model is the ASUS TUF Gaming A15, specifically FA507NV.

Signed-off-by: hqp1203 <hqp1203hqp@163.com>

要提交的变更:
修改: drivers/acpi/resource.c
---
drivers/acpi/resource.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/drivers/acpi/resource.c b/drivers/acpi/resource.c
index 0800a9d77558..cefc3b24a845 100644
--- a/drivers/acpi/resource.c
+++ b/drivers/acpi/resource.c
@@ -467,6 +467,13 @@ static const struct dmi_system_id asus_laptop[] = {
DMI_MATCH(DMI_BOARD_NAME, "B2502CBA"),
},
},
+ {
+ .ident = "Asus TUF Gaming A15 FA507NV",
+ .matches = {
+ DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
+ DMI_MATCH(DMI_BOARD_NAME, "FA507NV"),
+ },
+ },
{ }
};

--
2.40.1

125 changes: 125 additions & 0 deletions linux-g14/patches/0001-acpi-proc-idle-skip-dummy-wait.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
Processors based on the Zen microarchitecture support IOPORT based deeper
C-states. The idle driver reads the acpi_gbl_FADT.xpm_timer_block.address
in the IOPORT based C-state exit path which is claimed to be a
"Dummy wait op" and has been around since ACPI introduction to Linux
dating back to Andy Grover's Mar 14, 2002 posting [1].
The comment above the dummy operation was elaborated by Andreas Mohr back
in 2006 in commit b488f02156d3d ("ACPI: restore comment justifying 'extra'
P_LVLx access") [2] where the commit log claims:
"this dummy read was about: STPCLK# doesn't get asserted in time on
(some) chipsets, which is why we need to have a dummy I/O read to delay
further instruction processing until the CPU is fully stopped."

However, sampling certain workloads with IBS on AMD Zen3 system shows
that a significant amount of time is spent in the dummy op, which
incorrectly gets accounted as C-State residency. A large C-State
residency value can prime the cpuidle governor to recommend a deeper
C-State during the subsequent idle instances, starting a vicious cycle,
leading to performance degradation on workloads that rapidly switch
between busy and idle phases.

One such workload is tbench where a massive performance degradation can
be observed during certain runs. Following are some statistics gathered
by running tbench with 128 clients, on a dual socket (2 x 64C/128T) Zen3
system with the baseline kernel, baseline kernel keeping C2 disabled,
and baseline kernel with this patch applied keeping C2 enabled:

baseline kernel was tip:sched/core at
commit f3dd3f674555 ("sched: Remove the limitation of WF_ON_CPU on
wakelist if wakee cpu is idle")

Kernel : baseline baseline + C2 disabled baseline + patch

Min (MB/s) : 2215.06 33072.10 (+1393.05%) 33016.10 (+1390.52%)
Max (MB/s) : 32938.80 34399.10 34774.50
Median (MB/s) : 32191.80 33476.60 33805.70
AMean (MB/s) : 22448.55 33649.27 (+49.89%) 33865.43 (+50.85%)
AMean Stddev : 17526.70 680.14 880.72
AMean CoefVar : 78.07% 2.02% 2.60%

The data shows there are edge cases that can cause massive regressions
in case of tbench. Profiling the bad runs with IBS shows a significant
amount of time being spent in acpi_idle_do_entry method:

Overhead Command Shared Object Symbol
74.76% swapper [kernel.kallsyms] [k] acpi_idle_do_entry
0.71% tbench [kernel.kallsyms] [k] update_sd_lb_stats.constprop.0
0.69% tbench_srv [kernel.kallsyms] [k] update_sd_lb_stats.constprop.0
0.49% swapper [kernel.kallsyms] [k] psi_group_change
...

Annotation of acpi_idle_do_entry method reveals almost all the time in
acpi_idle_do_entry is spent on the port I/O in wait_for_freeze():

0.14 │ in (%dx),%al # <------ First "in" corresponding to inb(cx->address)
0.51 │ mov 0x144d64d(%rip),%rax
0.00 │ test $0x80000000,%eax
│ ↓ jne 62 # <------ Skip if running in guest
0.00 │ mov 0x19800c3(%rip),%rdx
99.33 │ in (%dx),%eax # <------ Second "in" corresponding to inl(acpi_gbl_FADT.xpm_timer_block.address)
0.00 │62: mov -0x8(%rbp),%r12
0.00 │ leave
0.00 │ ← ret

This overhead is reflected in the C2 residency on the test system where
C2 is an IOPORT based C-State. The total C-state residency reported by
"cpupower idle-info" on CPU0 for good and bad case over the 80s tbench
run is as follows (all numbers are in microseconds):

Good Run Bad Run
(Baseline)

POLL: 43338 6231 (-85.62%)
C1 (MWAIT Based): 23576156 363861 (-98.45%)
C2 (IOPORT Based): 10781218 77027280 (+614.45%)

The larger residency value in bad case leads to the system recommending
C2 state again for subsequent idle instances. The pattern lasts till the
end of the tbench run. Following is the breakdown of "entry_method"
passed to acpi_idle_do_entry during good run and bad run:

Good Run Bad Run
(Baseline)

Number of times acpi_idle_do_entry was called: 6149573 6149050 (-0.01%)
|-> Number of times entry_method was "ACPI_CSTATE_FFH": 6141494 88144 (-98.56%)
|-> Number of times entry_method was "ACPI_CSTATE_HALT": 0 0 (+0.00%)
|-> Number of times entry_method was "ACPI_CSTATE_SYSTEMIO": 8079 6060906 (+74920.49%)

For processors based on the Zen microarchitecture, this dummy wait op is
unnecessary and can be skipped when choosing IOPORT based C-States to
avoid polluting the C-state residency information.

Link: https://git.kernel.org/pub/scm/linux/kernel/git/mpe/linux-fullhistory.git/commit/?id=972c16130d9dc182cedcdd408408d9eacc7d6a2d [1]
Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=b488f02156d3deb08f5ad7816d565c370a8cc6f1 [2]

Suggested-by: Calvin Ong <calvin.ong@amd.com>
Cc: stable@vger.kernel.org
Cc: regressions@lists.linux.dev
Signed-off-by: K Prateek Nayak <kprateek.nayak@amd.com>
---
drivers/acpi/processor_idle.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index 16a1663d02d4..18850aa2b79b 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -527,9 +527,11 @@
static void wait_for_freeze(void)
{
#ifdef CONFIG_X86
- /* No delay is needed if we are in guest */
- if (boot_cpu_has(X86_FEATURE_HYPERVISOR))
- return;
+ /*
+ * No delay is needed if we are in guest or on a processor
+ * based on the Zen microarchitecture.
+ */
+ if (boot_cpu_has(X86_FEATURE_HYPERVISOR) || boot_cpu_has(X86_FEATURE_ZEN))
/*
* Modern (>=Nehalem) Intel systems use ACPI via intel_idle,
* not this code. Assume that any Intel systems using this

--
2.25.1
Loading

0 comments on commit 0406026

Please sign in to comment.