From nobody Sat Nov 30 10:36:42 2024 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 037A2191F88; Tue, 10 Sep 2024 12:29:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725971358; cv=none; b=paVvA37X+t0/Zz+4ZdiOya941wu4IQC5rkmJux+i/VWL5/K+8iDdcCX7MN7H+Ka2kbffkauIIjW8j/V7ow7Prq1+LszLLIMuhctn0dTCXE62m4GK3yIHg7YoNTS6Y1/sGUu3rQJhA5XHkvTzODXIslgL+Aie/9aL7lBiGKZKv2Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725971358; c=relaxed/simple; bh=PBJjWRoqAxx/V736ktmFavFSdpR0jTSelW8gIZc2KlQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=JPn+E4QvI6HfYrS/gM1uu55N7k3yoLXElhaDITUfoXYzzljGa/IN7WHaorUIRY0LAelbs52PhXI/t7ltkx+GUj5JEU14Y6kcxv85oQxFtBLfMjioeXOzg4kCahzWcs/ci82q+qQrXYWV03LgSqbTbML0HVyjRywor+T333OrXp0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=YGqc37aW; arc=none smtp.client-ip=192.198.163.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="YGqc37aW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1725971356; x=1757507356; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PBJjWRoqAxx/V736ktmFavFSdpR0jTSelW8gIZc2KlQ=; b=YGqc37aW/YuTb2mGdpTIeyBuvX7gX02PxTnzy4ebARZYd9jNREPNnpS4 nsmIwpENPSFa1Es1+3rRKrWgR6Asgk2pHB9XxiHuecn6EqM/s6dNjyiBu dIVNiv4dtOZORlzabDg/BWYEA7ZJm/qVoSXnyONsUvJttqMpjga8wvlhC nvMBruGmuKMiyJtsnVBHxOb0nf13PTff/30aUO3fo5znuYzElpLFbNvjh I7H/BN2dsFCRFKu3lNpZ8EJ3dfIqqX8pmZQ+LFFL/3mes3joln+v2HurB YEirzOP2AR3/1kYDqbA4DXBPOOAqLwlDZuTJhDJUww+Nb3UqYbBFEPnbH g==; X-CSE-ConnectionGUID: TwEJONQGTJi1BuMFacXTSQ== X-CSE-MsgGUID: X1orFKy/T8iO+TWZbOYJ0w== X-IronPort-AV: E=McAfee;i="6700,10204,11190"; a="24257224" X-IronPort-AV: E=Sophos;i="6.10,217,1719903600"; d="scan'208";a="24257224" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 05:29:15 -0700 X-CSE-ConnectionGUID: PtY63CttSpCsyit5dQ7H3g== X-CSE-MsgGUID: 4fq+/sfzSd6T1DFGXU1F6Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,217,1719903600"; d="scan'208";a="104483233" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.245.245.224]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 05:29:07 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Rob Herring , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , "Maciej W. Rozycki" , Jonathan Cameron , Lukas Wunner , Alexandru Gagniuc , Krishna chaitanya chundru , Srinivas Pandruvada , "Rafael J. Wysocki" , linux-pm@vger.kernel.org, Smita Koralahalli , Shuah Khan , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: Daniel Lezcano , Amit Kucheria , Zhang Rui , Christophe JAILLET Subject: [PATCH v7 8/8] selftests/pcie_bwctrl: Create selftests Date: Tue, 10 Sep 2024 15:27:05 +0300 Message-Id: <20240910122705.4068-9-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240910122705.4068-1-ilpo.jarvinen@linux.intel.com> References: <20240910122705.4068-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Create selftests for PCIe BW control through the PCIe cooling device sysfs interface. First, the BW control selftest finds the PCIe Port to test with. By default, the PCIe Port with the highest Link Speed is selected but another PCIe Port can be provided with -d parameter. The actual test steps the cur_state of the cooling device one-by-one from max_state to what the cur_state was initially. The speed change is confirmed by observing the current_link_speed for the corresponding PCIe Port. Signed-off-by: Ilpo J=C3=A4rvinen --- MAINTAINERS | 1 + tools/testing/selftests/Makefile | 1 + tools/testing/selftests/pcie_bwctrl/Makefile | 2 + .../pcie_bwctrl/set_pcie_cooling_state.sh | 122 ++++++++++++++++++ .../selftests/pcie_bwctrl/set_pcie_speed.sh | 67 ++++++++++ 5 files changed, 193 insertions(+) create mode 100644 tools/testing/selftests/pcie_bwctrl/Makefile create mode 100755 tools/testing/selftests/pcie_bwctrl/set_pcie_cooling_st= ate.sh create mode 100755 tools/testing/selftests/pcie_bwctrl/set_pcie_speed.sh diff --git a/MAINTAINERS b/MAINTAINERS index 47542dcb9259..dc601dcab8c6 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -17676,6 +17676,7 @@ S: Supported F: drivers/pci/pcie/bwctrl.c F: drivers/thermal/pcie_cooling.c F: include/linux/pci-bwctrl.h +F: tools/testing/selftests/pcie_bwctrl/ =20 PCIE DRIVER FOR AMAZON ANNAPURNA LABS M: Jonathan Chocron diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Mak= efile index bc8fe9e8f7f2..086af950930c 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -69,6 +69,7 @@ TARGETS +=3D net/openvswitch TARGETS +=3D net/tcp_ao TARGETS +=3D net/netfilter TARGETS +=3D nsfs +TARGETS +=3D pcie_bwctrl TARGETS +=3D perf_events TARGETS +=3D pidfd TARGETS +=3D pid_namespace diff --git a/tools/testing/selftests/pcie_bwctrl/Makefile b/tools/testing/s= elftests/pcie_bwctrl/Makefile new file mode 100644 index 000000000000..3e84e26341d1 --- /dev/null +++ b/tools/testing/selftests/pcie_bwctrl/Makefile @@ -0,0 +1,2 @@ +TEST_PROGS =3D set_pcie_cooling_state.sh +include ../lib.mk diff --git a/tools/testing/selftests/pcie_bwctrl/set_pcie_cooling_state.sh = b/tools/testing/selftests/pcie_bwctrl/set_pcie_cooling_state.sh new file mode 100755 index 000000000000..9df606552af3 --- /dev/null +++ b/tools/testing/selftests/pcie_bwctrl/set_pcie_cooling_state.sh @@ -0,0 +1,122 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-or-later + +SYSFS=3D +# Kselftest framework requirement - SKIP code is 4. +ksft_skip=3D4 +retval=3D0 +skipmsg=3D"skip all tests:" + +PCIEPORTTYPE=3D"PCIe_Port_Link_Speed" + +prerequisite() +{ + local ports + + if [ $UID !=3D 0 ]; then + echo $skipmsg must be run as root >&2 + exit $ksft_skip + fi + + SYSFS=3D`mount -t sysfs | head -1 | awk '{ print $3 }'` + + if [ ! -d "$SYSFS" ]; then + echo $skipmsg sysfs is not mounted >&2 + exit $ksft_skip + fi + + if ! ls $SYSFS/class/thermal/cooling_device* > /dev/null 2>&1; then + echo $skipmsg thermal cooling devices missing >&2 + exit $ksft_skip + fi + + ports=3D`grep -e "^$PCIEPORTTYPE" $SYSFS/class/thermal/cooling_device*/ty= pe | wc -l` + if [ $ports -eq 0 ]; then + echo $skipmsg pcie cooling devices missing >&2 + exit $ksft_skip + fi +} + +testport=3D +find_pcie_port() +{ + local patt=3D"$1" + local pcieports + local max + local cur + local delta + local bestdelta=3D-1 + + pcieports=3D`grep -l -F -e "$patt" /sys/class/thermal/cooling_device*/typ= e` + if [ -z "$pcieports" ]; then + return + fi + pcieports=3D${pcieports//\/type/} + # Find the port with the highest PCIe Link Speed + for port in $pcieports; do + max=3D`cat $port/max_state` + cur=3D`cat $port/cur_state` + delta=3D$((max-cur)) + if [ $delta -gt $bestdelta ]; then + testport=3D"$port" + bestdelta=3D$delta + fi + done +} + +sysfspcidev=3D +find_sysfs_pci_dev() +{ + local typefile=3D"$1/type" + local pcidir + + pcidir=3D"$SYSFS/bus/pci/devices/`sed -e "s|^${PCIEPORTTYPE}_||g" $typefi= le`" + + if [ -r "$pcidir/current_link_speed" ]; then + sysfspcidev=3D"$pcidir/current_link_speed" + fi +} + +usage() +{ + echo "Usage $0 [ -d dev ]" + echo -e "\t-d: PCIe port BDF string (e.g., 0000:00:04.0)" +} + +pattern=3D"$PCIEPORTTYPE" +parse_arguments() +{ + while getopts d:h opt; do + case $opt in + h) + usage "$0" + exit 0 + ;; + d) + pattern=3D"$PCIEPORTTYPE_$OPTARG" + ;; + *) + usage "$0" + exit 0 + ;; + esac + done +} + +parse_arguments "$@" +prerequisite +find_pcie_port "$pattern" +if [ -z "$testport" ]; then + echo $skipmsg "pcie cooling device not found from sysfs" >&2 + exit $ksft_skip +fi +find_sysfs_pci_dev "$testport" +if [ -z "$sysfspcidev" ]; then + echo $skipmsg "PCIe port device not found from sysfs" >&2 + exit $ksft_skip +fi + +./set_pcie_speed.sh "$testport" "$sysfspcidev" +retval=3D$? + +exit $retval diff --git a/tools/testing/selftests/pcie_bwctrl/set_pcie_speed.sh b/tools/= testing/selftests/pcie_bwctrl/set_pcie_speed.sh new file mode 100755 index 000000000000..584596949312 --- /dev/null +++ b/tools/testing/selftests/pcie_bwctrl/set_pcie_speed.sh @@ -0,0 +1,67 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-or-later + +set -e + +TESTNAME=3Dset_pcie_speed + +declare -a PCIELINKSPEED=3D( + "2.5 GT/s PCIe" + "5.0 GT/s PCIe" + "8.0 GT/s PCIe" + "16.0 GT/s PCIe" + "32.0 GT/s PCIe" + "64.0 GT/s PCIe" +) + +# Kselftest framework requirement - SKIP code is 4. +ksft_skip=3D4 +retval=3D0 + +coolingdev=3D"$1" +statefile=3D"$coolingdev/cur_state" +maxfile=3D"$coolingdev/max_state" +linkspeedfile=3D"$2" + +oldstate=3D`cat $statefile` +maxstate=3D`cat $maxfile` + +set_state() +{ + local state=3D$1 + local linkspeed + local expected_linkspeed + + echo $state > $statefile + + sleep 1 + + linkspeed=3D"`cat $linkspeedfile`" + expected_linkspeed=3D$((maxstate-state)) + expected_str=3D"${PCIELINKSPEED[$expected_linkspeed]}" + if [ ! "${expected_str}" =3D "${linkspeed}" ]; then + echo "$TESTNAME failed: expected: ${expected_str}; got ${linkspeed}" + retval=3D1 + fi +} + +cleanup_skip () +{ + set_state $oldstate + exit $ksft_skip +} + +trap cleanup_skip EXIT + +echo "$TESTNAME: testing states $maxstate .. $oldstate with $coolingdev" +for i in $(seq $maxstate -1 $oldstate); do + set_state "$i" +done + +trap EXIT +if [ $retval -eq 0 ]; then + echo "$TESTNAME [PASS]" +else + echo "$TESTNAME [FAIL]" +fi +exit $retval --=20 2.39.2