From patchwork Mon Dec 11 14:16:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 10105259 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9965E602B3 for ; Mon, 11 Dec 2017 14:16:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF0C9295F6 for ; Mon, 11 Dec 2017 14:16:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B3BCC2960F; Mon, 11 Dec 2017 14:16:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 05DC0295F6 for ; Mon, 11 Dec 2017 14:16:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753263AbdLKOQY (ORCPT ); Mon, 11 Dec 2017 09:16:24 -0500 Received: from mail-by2nam01on0071.outbound.protection.outlook.com ([104.47.34.71]:27392 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751956AbdLKOQT (ORCPT ); Mon, 11 Dec 2017 09:16:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=nwpl6K3hO6MumZ7BOVPkEPozdNQTLD225qAyQSKxNkw=; b=JMY1hc0nVtSBomk7ed8nXdSA3OP1RmgWEfHN0qX7jT+Oouu/l1ypP1qQj/0UooUtCsXo5+f99wO+dV5CcpEEfPsCqK8yPMxxCMrPLlRFw7h+RoYFUi2173/MKEtAznabbaJhWlG9voaPtmy00c8wG4V+jSvlthahYbONM56neFE= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Yuri.Norov@cavium.com; Received: from localhost (50.233.148.156) by DM5PR0701MB3831.namprd07.prod.outlook.com (2603:10b6:4:7f::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.302.9; Mon, 11 Dec 2017 14:16:16 +0000 From: Yury Norov To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Yury Norov , Andrew Morton , Ashish Kalra , Christoffer Dall , Geert Uytterhoeven , Linu Cherian , Sunil Goutham Subject: [PATCH] IPI performance benchmark Date: Mon, 11 Dec 2017 17:16:00 +0300 Message-Id: <20171211141600.24401-1-ynorov@caviumnetworks.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 X-Originating-IP: [50.233.148.156] X-ClientProxiedBy: DB3PR0202CA0003.eurprd02.prod.outlook.com (2603:10a6:8:1::16) To DM5PR0701MB3831.namprd07.prod.outlook.com (2603:10b6:4:7f::29) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5917cfa7-441e-48f4-649c-08d540a1beb3 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(5600026)(4604075)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(2017052603307); SRVR:DM5PR0701MB3831; X-Microsoft-Exchange-Diagnostics: 1; DM5PR0701MB3831; 3:8ATK5iN3yoyLTIKXL0Fu0x6mhBJjE3hEJ+wn3N9xPcaZAS6kajqk39yptRAdkNkxCNn7jqxXIJUuM7a47NVLgpleJNw3wCueJRENAYfzNd9913mjXOS12ua7iFoq02HVpD6bH+mti4CRPvasEe3FRiNk43+ElufCJDrgmGTNVbz7or1dEldd55x3AlJKPufKPsQ89y7/1XObVDtcQXCBtE7lfGVgd87itq+gz8OCsS0sgMDX6mWZiZmL8S9JQT8y; 25:ILfzvuFGEaOIe5S6YmqUqI8tFoS+dik+LNKpg/yanUiNp0kXmtRDlqgRTL/WR9vejjyxX9atPtlHp4XkYhkVbqq3xN7tKv4HVcOgPEddyXVnG2rilywX6LI253+/ua5ntJ3US7BlYoidVYPm7qXsK5gB4TgexER5iqrD5zydRaVrgki539eAR0AQFb1hiUvXAvubhaCYNiN0CIALE6dul4gxzW2DgfZE8tCJVAQnn0qozbCWo/aW+/Toz9tQAAlGixWdy3jXDOVf1MsiSymHauywg2/VadVmxRoy96tVBtY845RKkCxwrNQT8thP9Vj4uRRbhM1LPRSp2xrZvneO2A==; 31:3mKRqCpEgBPAlDyd54zM2kf3JJCNJS8LqimpJJhmsx59jmClVQkUbRlsJXM/qCMb75ZSO4gWgTQR9z6rbYagNAy6GLLfEExohUIc06JXdre0PkvSvxv202ElZwPpZXbBZlefaG5SFeUdq3C/XSeMoD1wHCrb5Ugc21b8KZQCOF6vCpgqZVAsuuqnwaMPGu9YsVvz2WiIdln2xnl7Hqbd5+7A8O/UVhUgH36np9XZ2Eo= X-MS-TrafficTypeDiagnostic: DM5PR0701MB3831: X-Microsoft-Exchange-Diagnostics: 1; DM5PR0701MB3831; 20:Rhhiu4eJAphiWq01xR2WHsqFlJR3meQnyAAQLf71937IBYYQViIF7uw4pCdV+V54uHFfMrw9hmVIcfv1yT0Onls0MpkW5w0ySpQSk9bfJbOXaXkgvNEVFBCz6jlvadw6St8RltaC9ciSOODXxCN74eUHnWQZJbCJ7EWGBHmgkD++XgvPHjuW5TK8XCbxVTC7eFNwhvllGrkKF8UnHX7MMiCdRGRwi9nSoKNSt9kRsUOPFEBBfY1N3h4+idQEBVenUX3Tb+L9qqHHQaI0hBzZeqtlscPCPvXgWjZqOX8MsKbY+y//FenNrl6cspV1Hz6IHERP3ByUZ/1piYbE0NdQDLa1oM/zJINIy2bQxZLwMSub3N5My3YoQdOGQO2UGMGDtosVTGjJG2o7gWnV6Dqgf4KXvhoukiNyaBwYZdIaQ//NCbio3WI5KfXxGaOPQajiclKV7NpdM1iwcJU4iM/Qe/mwY0l0jsLpAOx+QVdUbRt3TaRwdBTAHjhSCal2UOMVr3F7evjTHp7G+YntComyZDAS5RluOZK4++lF4pUrAboL1JJVtINK8RxxGmiu3FWr1CIeEPXVl7afRkmUfO6fdDiI/QqWbHxgHhIXP6FpkuY=; 4:vS0wipPROKDhH3a4tQws1eAMcWciJRB2twXVN30j4Rsl9u6I04inQe14M8V7Lr+uYITr/2b8Lt8LgUkFzNq4qwNhAfuMp0nFN4D4L1xiCJc4wwL/qYIJ2qRdv+UyPp0CkALgMiRqYzWH6v6bGwScRhGFdpl9EhvIgyIIBbyCIrNauoCVQdj2X00G/mx104SV7t5d2N6quc3+ui5+a2rzOTPdhnuy1DWyU98w7FHvzOPdD/AOvoC4gwotZ1YGPWfO0hkLbnLMYOKJX66bTQdeE3kyNyQ6qAVCPjvCrB/WrSM2gzQyTI9ftHC1 hGn5PYvR X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(209352067349851); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(2401047)(8121501046)(5005006)(93006095)(3002001)(10201501046)(3231022)(6041248)(20161123562025)(20161123564025)(20161123560025)(20161123555025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:DM5PR0701MB3831; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:DM5PR0701MB3831; X-Forefront-PRVS: 0518EEFB48 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6069001)(366004)(346002)(376002)(189003)(199004)(53936002)(6306002)(16526018)(4326008)(50226002)(8936002)(66066001)(25786009)(54906003)(42882006)(6496006)(47776003)(16586007)(316002)(6666003)(107886003)(52116002)(2906002)(7736002)(6486002)(6116002)(575784001)(3846002)(76506005)(81156014)(81166006)(5660300001)(51416003)(1076002)(97736004)(68736007)(305945005)(478600001)(966005)(105586002)(33646002)(72206003)(59450400001)(8676002)(50466002)(48376002)(36756003)(106356001)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR0701MB3831; H:localhost; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM5PR0701MB3831; 23:zq804L3nsO02UodLOZNJaKpUTJDaaaULLjWbEDg?= =?us-ascii?Q?YsuIXJqx8yX4R3bBc++wFDr2fdYTGwHwdMkfMv+ter3BEEHxf54oN+Kj0Ari?= =?us-ascii?Q?zfhvClmHqsK2aJmAK6aasUZLrkZfuJxJeHU04FuAbzkDiUbDiSwB2Dj/HhPQ?= =?us-ascii?Q?d6jdWIN5TzqspW2tK5Q3O7y1R8T9M42M6Z37AWfXU2Iz5U4KOTLygi33RzBd?= =?us-ascii?Q?abLOkafiPCsttS2K0TDBkDDLSWmyoCzW46B8ytEPXPV0iHIZGrsT5z7T+gyy?= =?us-ascii?Q?5bf0fNu1/LAJjlc7BCMB09q/GEK3XXHSuYM4qwhRJW1cDBoizkbbN3ylOIU/?= =?us-ascii?Q?7ony6bQqEjODsLwGIWPevjWKP91bJfNu7XiznTLQkrUfEfEN4LKNlmi8plvR?= =?us-ascii?Q?J1ltHOI7s+rhxWgARWQ+Lrv3d2EQhqzwWfHuAuCz2rLN1VEndnMii3OjvID8?= =?us-ascii?Q?3UUVyBwS86OjIA++t8sZ+fS6pE3A1sTsRvVP4/YSASqOaP8fAQNc4V3ka9iy?= =?us-ascii?Q?rRWiHs/upW2vovT4C6AtYztzxlTIUAip7NwMkjRwoTs+J5zv29PNc1yXDzZu?= =?us-ascii?Q?1Hodfagy0aGr1WFJMS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iLFoHO2sojj4S819DFtA=; 5:qbbc0lzK94AAjA/rLcOWLS7hcKDY405b/sbLKOBO6Iug81a7zizywzRm7s+nwppvC+Vd0Zby1fhKJdra49kl3IWiy+8WQCRZ9smjv22i1TvLO/ue1cCPhNYjh/ZbsSr4fnNOkiLTc54LQUu4g5tvBUnl7dJ8oMr2gOio7S09uN0=; 24:wrGACz1iYwP5wn99kn0DNuMzGSyhf0N7AeIapW31nUVOhlY1pvlVG+dGvQEg+nNk1ZT/sqd8FcqO+QCaG5gT+simGqpaYDH53vXLvL1hl3U=; 7:NbBPNnft15UMLys+YsTMCWencYmxF/lxTRo1Q7OY/AHFrHaAkdS13C+Dn/1H5tuoBulr8H/QCA4qniHdozPZ2EzCBObNcdaYa/CFJ5pGwff0j6bPxhfsO8OFkYkDRDkcef9Xd+C6zgnWT1M2Kym8yDGnKfroeusvC0rIOCV2EcpdA4z0JTvfhBjoTKNRo6NSCc/uMACXsTh+4YkD/pxNYGiK+fAO0CfvtCMRxGMrUgLBKtsqtL+u//cMNKvr4oFy SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2017 14:16:16.4570 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5917cfa7-441e-48f4-649c-08d540a1beb3 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR0701MB3831 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This benchmark sends many IPIs in different modes and measures time for IPI delivery (first column), and total time, ie including time to acknowledge the receive by sender (second column). The scenarios are: Dry-run: do everything except actually sending IPI. Useful to estimate system overhead. Self-IPI: Send IPI to self CPU. Normal IPI: Send IPI to some other CPU. Broadcast IPI: Send broadcast IPI to all online CPUs. For virtualized guests, sending and reveiving IPIs causes guest exit. I used this test to measure performance impact on KVM subsystem of Christoffer Dall's series "Optimize KVM/ARM for VHE systems". https://www.spinics.net/lists/kvm/msg156755.html Test machine is ThunderX2, 112 online CPUs. Below the results normalized to host dry-run time. Smaller - better. Host, v4.14: Dry-run: 0 1 Self-IPI: 9 18 Normal IPI: 81 110 Broadcast IPI: 0 2106 Guest, v4.14: Dry-run: 0 1 Self-IPI: 10 18 Normal IPI: 305 525 Broadcast IPI: 0 9729 Guest, v4.14 + VHE: Dry-run: 0 1 Self-IPI: 9 18 Normal IPI: 176 343 Broadcast IPI: 0 9885 CC: Andrew Morton CC: Ashish Kalra CC: Christoffer Dall CC: Geert Uytterhoeven CC: Linu Cherian CC: Sunil Goutham Signed-off-by: Yury Norov --- arch/Kconfig | 10 ++++ kernel/Makefile | 1 + kernel/ipi_benchmark.c | 134 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 145 insertions(+) create mode 100644 kernel/ipi_benchmark.c diff --git a/arch/Kconfig b/arch/Kconfig index 057370a0ac4e..80d6ef439199 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -82,6 +82,16 @@ config JUMP_LABEL ( On 32-bit x86, the necessary options added to the compiler flags may increase the size of the kernel slightly. ) +config IPI_BENCHMARK + tristate "Test IPI performance on SMP systems" + depends on SMP + help + Test IPI performance on SMP systems. If system has only one online + CPU, sending IPI to other CPU is obviously not possible, and ENOENT + is returned for corresponding test. + + If unsure, say N. + config STATIC_KEYS_SELFTEST bool "Static key selftest" depends on JUMP_LABEL diff --git a/kernel/Makefile b/kernel/Makefile index 172d151d429c..04e550e1990c 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -101,6 +101,7 @@ obj-$(CONFIG_TRACEPOINTS) += trace/ obj-$(CONFIG_IRQ_WORK) += irq_work.o obj-$(CONFIG_CPU_PM) += cpu_pm.o obj-$(CONFIG_BPF) += bpf/ +obj-$(CONFIG_IPI_BENCHMARK) += ipi_benchmark.o obj-$(CONFIG_PERF_EVENTS) += events/ diff --git a/kernel/ipi_benchmark.c b/kernel/ipi_benchmark.c new file mode 100644 index 000000000000..35f1f7598c36 --- /dev/null +++ b/kernel/ipi_benchmark.c @@ -0,0 +1,134 @@ +/* + * Performance test for IPI on SMP machines. + * + * Copyright (c) 2017 Cavium Networks. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + */ + +#include +#include +#include +#include + +#define NTIMES 100000 + +#define POKE_ANY 0 +#define DRY_RUN 1 +#define POKE_SELF 2 +#define POKE_ALL 3 + +static void __init handle_ipi(void *t) +{ + ktime_t *time = (ktime_t *) t; + + if (time) + *time = ktime_get() - *time; +} + +static ktime_t __init send_ipi(int flags) +{ + ktime_t time; + unsigned int cpu = get_cpu(); + + switch (flags) { + case POKE_ALL: + /* If broadcasting, don't force all CPUs to update time. */ + smp_call_function_many(cpu_online_mask, handle_ipi, NULL, 1); + /* Fall thru */ + case DRY_RUN: + /* Do everything except actually sending IPI. */ + time = 0; + break; + case POKE_ANY: + cpu = cpumask_any_but(cpu_online_mask, cpu); + if (cpu >= nr_cpu_ids) { + time = -ENOENT; + break; + } + /* Fall thru */ + case POKE_SELF: + time = ktime_get(); + smp_call_function_single(cpu, handle_ipi, &time, 1); + break; + default: + time = -EINVAL; + } + + put_cpu(); + return time; +} + +static int __init __bench_ipi(unsigned long i, ktime_t *time, int flags) +{ + ktime_t t; + + *time = 0; + while (i--) { + t = send_ipi(flags); + if ((int) t < 0) + return (int) t; + + *time += t; + } + + return 0; +} + +static int __init bench_ipi(unsigned long times, int flags, + ktime_t *ipi, ktime_t *total) +{ + int ret; + + *total = ktime_get(); + ret = __bench_ipi(times, ipi, flags); + if (unlikely(ret)) + return ret; + + *total = ktime_get() - *total; + + return 0; +} + +static int __init init_bench_ipi(void) +{ + ktime_t ipi, total; + int ret; + + ret = bench_ipi(NTIMES, DRY_RUN, &ipi, &total); + if (ret) + pr_err("Dry-run FAILED: %d\n", ret); + else + pr_err("Dry-run: %18llu, %18llu ns\n", ipi, total); + + ret = bench_ipi(NTIMES, POKE_SELF, &ipi, &total); + if (ret) + pr_err("Self-IPI FAILED: %d\n", ret); + else + pr_err("Self-IPI: %18llu, %18llu ns\n", ipi, total); + + ret = bench_ipi(NTIMES, POKE_ANY, &ipi, &total); + if (ret) + pr_err("Normal IPI FAILED: %d\n", ret); + else + pr_err("Normal IPI: %18llu, %18llu ns\n", ipi, total); + + ret = bench_ipi(NTIMES, POKE_ALL, &ipi, &total); + if (ret) + pr_err("Broadcast IPI FAILED: %d\n", ret); + else + pr_err("Broadcast IPI: %18llu, %18llu ns\n", ipi, total); + + /* Return error to avoid annoying rmmod. */ + return -EINVAL; +} +module_init(init_bench_ipi); + +MODULE_LICENSE("GPL");