PCIe Geschwindigkeit einstellen / Set PCIe Speed

Hallo,

ich will hier auf meinem Testrechner etwas Ausprobieren,
dazu will ich die PCIe Geschwindigkeit meiner RTX 3050 (siehe unten)
manuell einstellen. Das geht mit setpci.
Ich bekomme das aber mit der Syntax nicht hin.
Ich blicke da nicht durch, das ist sehr kompliziert.
Einstellen will ich Gen1, Gen2, Gen3 oder Gen4.
(Aktuell : “LnkSta: Speed 2.5GT/s (downgraded)”, also Gen1 hier automatisch eingestellt)

setpci -s 01:00.0 ...

Soweit ist alles klar, aber was danach kommt, da bin ich raus.
Da bräuchte ich Hilfe.

Kann man sowas auch gleich beim Booten einstellen,
z.b. über einen GRUB Parameter ?
Wenn nicht, was muss man machen,
das es gleich beim Systemstart eingestellt wird ?

Danke im voraus.

01:00.0 VGA compatible controller [0300]: NVIDIA Corporation GA106 [Geforce RTX 3050] [10de:2507] (rev a1) (prog-if 00 [VGA controller])
	Subsystem: ASUSTeK Computer Inc. Device [1043:887c]
	Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx+
	Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
	Latency: 0
	Interrupt: pin A routed to IRQ 179
	IOMMU group: 13
	Region 0: Memory at db000000 (32-bit, non-prefetchable) [size=16M]
	Region 1: Memory at fa00000000 (64-bit, prefetchable) [size=8G]
	Region 3: Memory at fc00000000 (64-bit, prefetchable) [size=32M]
	Region 5: I/O ports at f000 [size=128]
	Expansion ROM at dc000000 [virtual] [disabled] [size=512K]
	Capabilities: [60] Power Management version 3
		Flags: PMEClk- DSI- D1- D2- AuxCurrent=0mA PME(D0+,D1-,D2-,D3hot+,D3cold-)
		Status: D0 NoSoftRst+ PME-Enable- DSel=0 DScale=0 PME-
	Capabilities: [68] MSI: Enable+ Count=1/1 Maskable- 64bit+
		Address: 00000000fee00000  Data: 0000
	Capabilities: [78] Express (v2) Legacy Endpoint, IntMsgNum 0
		DevCap:	MaxPayload 256 bytes, PhantFunc 0, Latency L0s unlimited, L1 <64us
			ExtTag+ AttnBtn- AttnInd- PwrInd- RBE+ FLReset+ TEE-IO-
		DevCtl:	CorrErr+ NonFatalErr+ FatalErr+ UnsupReq+
			RlxdOrd+ ExtTag+ PhantFunc- AuxPwr- NoSnoop+ FLReset-
			MaxPayload 256 bytes, MaxReadReq 512 bytes
		DevSta:	CorrErr- NonFatalErr- FatalErr- UnsupReq- AuxPwr- TransPend-
		LnkCap:	Port #0, Speed 16GT/s, Width x16, ASPM L0s L1, Exit Latency L0s <512ns, L1 <16us
			ClockPM+ Surprise- LLActRep- BwNot- ASPMOptComp+
		LnkCtl:	ASPM L1 Enabled; RCB 64 bytes, LnkDisable- CommClk+
			ExtSynch- ClockPM+ AutWidDis- BWInt- AutBWInt-
		LnkSta:	Speed 2.5GT/s (downgraded), Width x8 (downgraded)
			TrErr- Train- SlotClk+ DLActive- BWMgmt- ABWMgmt-
		DevCap2: Completion Timeout: Range AB, TimeoutDis+ NROPrPrP- LTR+
			 10BitTagComp+ 10BitTagReq+ OBFF Via message, ExtFmt- EETLPPrefix-
			 EmergencyPowerReduction Not Supported, EmergencyPowerReductionInit-
			 FRS-
			 AtomicOpsCap: 32bit- 64bit- 128bitCAS-
		DevCtl2: Completion Timeout: 50us to 50ms, TimeoutDis-
			 AtomicOpsCtl: ReqEn-
			 IDOReq- IDOCompl- LTR+ EmergencyPowerReductionReq-
			 10BitTagReq+ OBFF Disabled, EETLPPrefixBlk-
		LnkCap2: Supported Link Speeds: 2.5-16GT/s, Crosslink- Retimer+ 2Retimers+ DRS-
		LnkCtl2: Target Link Speed: 16GT/s, EnterCompliance- SpeedDis-
			 Transmit Margin: Normal Operating Range, EnterModifiedCompliance- ComplianceSOS-
			 Compliance Preset/De-emphasis: -6dB de-emphasis, 0dB preshoot
		LnkSta2: Current De-emphasis Level: -3.5dB, EqualizationComplete+ EqualizationPhase1+
			 EqualizationPhase2+ EqualizationPhase3+ LinkEqualizationRequest-
			 Retimer- 2Retimers- CrosslinkRes: unsupported
	Capabilities: [b4] Vendor Specific Information: Len=14 <?>
	Capabilities: [100 v1] Virtual Channel
		Caps:	LPEVC=0 RefClk=100ns PATEntryBits=1
		Arb:	Fixed- WRR32- WRR64- WRR128-
		Ctrl:	ArbSelect=Fixed
		Status:	InProgress-
		VC0:	Caps:	PATOffset=00 MaxTimeSlots=1 RejSnoopTrans-
			Arb:	Fixed- WRR32- WRR64- WRR128- TWRR128- WRR256-
			Ctrl:	Enable+ ID=0 ArbSelect=Fixed TC/VC=01
			Status:	NegoPending- InProgress-
	Capabilities: [250 v1] Latency Tolerance Reporting
		Max snoop latency: 34326183936ns
		Max no snoop latency: 34326183936ns
	Capabilities: [258 v1] L1 PM Substates
		L1SubCap: PCI-PM_L1.2+ PCI-PM_L1.1+ ASPM_L1.2+ ASPM_L1.1+ L1_PM_Substates+
			  PortCommonModeRestoreTime=255us PortTPowerOnTime=10us
		L1SubCtl1: PCI-PM_L1.2- PCI-PM_L1.1- ASPM_L1.2- ASPM_L1.1-
			   T_CommonMode=0us LTR1.2_Threshold=32768ns
		L1SubCtl2: T_PwrOn=10us
	Capabilities: [128 v1] Power Budgeting <?>
	Capabilities: [420 v2] Advanced Error Reporting
		UESta:	DLP- SDES- TLP- FCP- CmpltTO- CmpltAbrt- UnxCmplt- RxOF- MalfTLP-
			ECRC- UnsupReq- ACSViol- UncorrIntErr- BlockedTLP- AtomicOpBlocked- TLPBlockedErr-
			PoisonTLPBlocked- DMWrReqBlocked- IDECheck- MisIDETLP- PCRC_CHECK- TLPXlatBlocked-
		UEMsk:	DLP- SDES- TLP- FCP- CmpltTO- CmpltAbrt- UnxCmplt- RxOF- MalfTLP-
			ECRC- UnsupReq- ACSViol- UncorrIntErr- BlockedTLP- AtomicOpBlocked- TLPBlockedErr-
			PoisonTLPBlocked- DMWrReqBlocked- IDECheck- MisIDETLP- PCRC_CHECK- TLPXlatBlocked-
		UESvrt:	DLP+ SDES+ TLP- FCP+ CmpltTO- CmpltAbrt- UnxCmplt- RxOF+ MalfTLP+
			ECRC- UnsupReq- ACSViol- UncorrIntErr+ BlockedTLP- AtomicOpBlocked- TLPBlockedErr-
			PoisonTLPBlocked- DMWrReqBlocked- IDECheck- MisIDETLP- PCRC_CHECK- TLPXlatBlocked-
		CESta:	RxErr- BadTLP- BadDLLP- Rollover- Timeout- AdvNonFatalErr- CorrIntErr- HeaderOF-
		CEMsk:	RxErr- BadTLP- BadDLLP- Rollover- Timeout- AdvNonFatalErr+ CorrIntErr- HeaderOF+
		AERCap:	First Error Pointer: 00, ECRCGenCap- ECRCGenEn- ECRCChkCap- ECRCChkEn-
			MultHdrRecCap- MultHdrRecEn- TLPPfxPres- HdrLogCap-
		HeaderLog: 00000000 00000000 00000000 00000000
	Capabilities: [600 v1] Vendor Specific Information: ID=0001 Rev=1 Len=024 <?>
	Capabilities: [900 v1] Secondary PCI Express
		LnkCtl3: LnkEquIntrruptEn- PerformEqu-
		LaneErrStat: 0
	Capabilities: [bb0 v1] Physical Resizable BAR
		BAR 0: current size: 16MB, supported: 16MB
		BAR 1: current size: 8GB, supported: 64MB 128MB 256MB 512MB 1GB 2GB 4GB 8GB
		BAR 3: current size: 32MB, supported: 32MB
	Capabilities: [c1c v1] Physical Layer 16.0 GT/s <?>
	Capabilities: [d00 v1] Lane Margining at the Receiver
		PortCap: Uses Driver+
		PortSta: MargReady+ MargSoftReady+
	Capabilities: [e00 v1] Data Link Feature <?>
	Kernel driver in use: nvidia
	Kernel modules: nouveau, nvidia_drm, nvidia
00: de 10 07 25 07 04 10 00 a1 00 00 03 00 00 80 00
10: 00 00 00 db 0c 00 00 00 fa 00 00 00 0c 00 00 00
20: fc 00 00 00 01 f0 00 00 00 00 00 00 43 10 7c 88
30: 00 00 00 00 60 00 00 00 00 00 00 00 ff 01 00 00
40: 43 10 7c 88 00 00 00 00 00 00 00 00 00 00 00 00
50: 00 00 00 00 01 00 00 00 ce d6 23 00 00 00 00 00
60: 01 68 03 48 08 00 00 00 05 78 81 00 00 00 e0 fe
70: 00 00 00 00 00 00 00 00 10 b4 12 00 e1 8d 2c 11
80: 3f 29 00 00 04 3d 46 00 42 01 81 10 00 00 00 00
90: 00 00 00 00 00 00 00 00 00 00 00 00 13 08 07 00
a0: 00 14 00 00 1e 00 80 01 04 00 1f 00 00 00 00 00
b0: 00 00 00 00 09 00 14 01 01 00 13 0b 80 00 00 00
c0: ba f3 33 fb 00 00 00 00 11 00 05 00 00 00 b9 00
d0: 00 00 ba 00 00 00 00 00 00 00 00 00 00 00 00 00
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Hallo KTM2k22,
hier PCIe Force Gen 2 [Alex Forencich]
gibt es ein Skript, dass vielleicht deine Wünsche erfüllt. Wenn nicht, könnte es zumindest als Grundlage zur Anpassung dienen.
Aber für Details müsstest Du dich an an den Schöpfer dieses Skriptes wenden.

viele Grüsse gosia

Hallo,

danke für den Link !

Falls das noch jemand mal brauchen sollte,
gelöst habe ich es jetzt so :

Zuerst alle PCIe Geräte anzeigen lassen :

lspci

Genaue Infos über ein bestimmtes PCIe-Gerät herausfinden.
Die Grafikkarte ist auf 01:00.0 hier in meinem Fall :

sudo lspci -s 01:00.0 -nnvvxxx | less

Nützlich sind hier die Parameter
LnkCap: Port #0, Speed … die Maximale Geschwindigkeit des PCIe Geräts
und
LnkSta: Speed … die aktuelle Geschwindigkeit.

Das Script mit Rootrechten erstellen :

sudo nano /usr/bin/pcie_set_speed.sh
#! /bin/bash
#
# Original Script by Alex Forencich :
# https://www.alexforencich.com/wiki/en/pcie/set-speed

# Bei Aufruf ohne systemctl, die beiden # entfernen
# und bei dem Block - Hier ändern - setzen.
# dev=$1
# speed=$2

#  - Hier ändern -
# Für Meine Grafikkarte auf Gen1 fest eingestellt.
dev="01:00.0"
speed="1"
#  ------------------------------

if [ -z "$dev" ]; then
    echo "Error: no device specified"
    exit 1
fi

if [ ! -e "/sys/bus/pci/devices/$dev" ]; then
    dev="0000:$dev"
fi

if [ ! -e "/sys/bus/pci/devices/$dev" ]; then
    echo "Error: device $dev not found"
    exit 1
fi

pciec=$(setpci -s $dev CAP_EXP+02.W)
pt=$((("0x$pciec" & 0xF0) >> 4))

port=$(basename $(dirname $(readlink "/sys/bus/pci/devices/$dev")))

if (($pt == 0)) || (($pt == 1)) || (($pt == 5)); then
    dev=$port
fi

lc=$(setpci -s $dev CAP_EXP+0c.L)
ls=$(setpci -s $dev CAP_EXP+12.W)

max_speed=$(("0x$lc" & 0xF))

echo "Link capabilities:" $lc
echo "Max link speed:" $max_speed
echo "Link status:" $ls
echo "Current link speed:" $(("0x$ls" & 0xF))

if [ -z "$speed" ]; then
    speed=$max_speed
fi

if (($speed > $max_speed)); then
    speed=$max_speed
fi

echo "Configuring $dev..."

lc2=$(setpci -s $dev CAP_EXP+30.L)

echo "Original link control 2:" $lc2
echo "Original link target speed:" $(("0x$lc2" & 0xF))

lc2n=$(printf "%08x" $((("0x$lc2" & 0xFFFFFFF0) | $speed)))

echo "New target link speed:" $speed
echo "New link control 2:" $lc2n

setpci -s $dev CAP_EXP+30.L=$lc2n

echo "Triggering link retraining..."

lc=$(setpci -s $dev CAP_EXP+10.L)

echo "Original link control:" $lc

lcn=$(printf "%08x" $(("0x$lc" | 0x20)))

echo "New link control:" $lcn

setpci -s $dev CAP_EXP+10.L=$lcn

sleep 0.1

ls=$(setpci -s $dev CAP_EXP+12.W)

echo "Link status:" $ls
echo "Current link speed:" $(("0x$ls" & 0xF))

Das Script noch Ausführbar machen :

sudo chmod +x /usr/bin/pcie_set_speed.sh

Als System Service beim Start einrichten :

sudo systemctl --force --full edit pcie_set_speed.service

→ Falls man wie ich mit vi/vim nicht klarkommt,
den Editor nano als Systemeditor
in die /etc/environment eintragen :
Die Zeile

EDITOR=nano

hinzufügen und neu starten.
Dann wird er zukünftig hier verwendet anstatt vi/vim.

Die Servicedatei mit diesen Parametern erstellen :

[Unit]
Description=PCIe Geschwindigkeit Manuell einstellen und Fixieren.
Before=basic.target
After=local-fs.target sysinit.target
DefaultDependencies=no

[Service]
Type=oneshot
ExecStart=/usr/bin/pcie_set_speed.sh

[Install]
WantedBy=sysinit.target

System Services aktualisieren :

sudo systemctl daemon-reload

System Service ab nächstem Neustart aktivieren :

sudo systemctl enable pcie_set_speed

Rechner neu Starten :

sudo reboot

Wenn alles funktioniert hat,
sollte das PCIe-Gerät jetzt fest auf
den im Script angegebenen Wert eingestellt sein.

Wenn man die PCIe Geschwindigkeit bei laufendem System ändern will,
einfach die /usr/bin/pcie_set_speed.sh mit Rootrechten
Editieren, danach noch

sudo systemctl start pcie_set_speed

ausführen.

Um die Manuelle Einstellung der PCIe Geschwindigkeit
wieder zu deaktivieren, einfach den Service deaktivieren :

sudo systemctl disable pcie_set_speed

und
sudo reboot