Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp9754518rwp; Thu, 20 Jul 2023 09:11:50 -0700 (PDT) X-Google-Smtp-Source: APBJJlGHHfwY+Hn71JpKVvu/8zBPGjGNMeZpBcxiyxS2X0IalHpQhNeeHCW04S52m0buHkoY5C72 X-Received: by 2002:a17:906:591:b0:994:1eb4:6896 with SMTP id 17-20020a170906059100b009941eb46896mr5562667ejn.25.1689869509753; Thu, 20 Jul 2023 09:11:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689869509; cv=none; d=google.com; s=arc-20160816; b=yvzYgjsuud+yyaZ0mPTZibLpSB11aEsJSNmNfkR0thFirrSEj9jvkmj2ZJbOepP+nv 6hsv4u1+G63/BvtYCCvqavC4Zhw3Ci6CgWvDJl+4Trpytig1M4dkYGLnLp+BOfE1Vt4Z oKsrsbj8ppUAfDaFsIX9zMgvrZTPPvF+yn/KDvxb8J2b/0RxJ7HiSmCHquIviKDSockH /2in8JDvCewTmgqhpZwUYm22BmFyShWlKtv6J82V+KDYWmuPBZ4p8+USNBofH6eeMskI KXzkPvXsJOZX6Awv7HZcc5ryL8+Gi7hiWrc3Exs425lgnbUbfwp5orCaFA6/neVwPA/s Zkeg== 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=AzMa4g2hoWRnrtKiEBOwGs4jBTqhlAFiRuirBCpPB08=; fh=LBaDSFbQE93YBfyTmhi6Jra0AMg8othoZ8Wzqmbggco=; b=sgNHz3XLP95BqWUtM7ios5zatVhVbDkTOuU9I9utIeD+3tEqzgKgBcToGYOIKuM59N inS4nroSUaO7O7+7dInq2o1xbnOQdApv9Ni/hMGQUgsnFWvxVI+h2ew+PLSssKNnfX5Z qCFFFyqAQVe28NNcx3FHUG5tzrKgochzvlViMgu/px+B/G5PhpJtNmCufvtGmMEPcwAd WlZH72IRWN174tFiqKnrYzmHw/8EuuR4YRJytJZNtnGwk8UzmEftXCyOz4t5PT1cG/8M zckmkSyp1getLRv93Ugeqa/2OzpFUlQwbAq2fO/mZTjmRzYslhfZxRFhH7s8Sxv1lpK+ Oh2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Jd6GQ803; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g8-20020a170906198800b00992bd86ece6si839495ejd.725.2023.07.20.09.11.22; Thu, 20 Jul 2023 09:11:49 -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=@gmail.com header.s=20221208 header.b=Jd6GQ803; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232986AbjGTPtr (ORCPT + 99 others); Thu, 20 Jul 2023 11:49:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231405AbjGTPtq (ORCPT ); Thu, 20 Jul 2023 11:49:46 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 634DC134; Thu, 20 Jul 2023 08:49:44 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3fd0f000f1cso6500985e9.1; Thu, 20 Jul 2023 08:49:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689868183; x=1690472983; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=AzMa4g2hoWRnrtKiEBOwGs4jBTqhlAFiRuirBCpPB08=; b=Jd6GQ803X2qJY8axDRFBnNQApeLwHULaUnzznruB4ISc7Fu0Rc28DXZX7pfTWRBV9v BHP4I8llCRIOLAPbaK5lJe7tOkGUr6pGXgkmxdHVy79dwtdv97xuMNkaFAMQDFjC13ja A95+7C2qvajV++G0dvGk3dJptW9Tt/QLrh8dTRdGXlPwcTzUyOmTEsz0sQ02CLdprFrr nhOPxCtJ9qvrEz2Duwl3v4hihMVc64FG7mogJWqG5mNxljYradPkpUqUbyswtdNFwPv+ sYK5hlIjrUgIAInka6tK1kb3UaX5QaJj264CMF2qMxTiQBrl62HUWKwAMl5AYGOh8f2d sFEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689868183; x=1690472983; 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=AzMa4g2hoWRnrtKiEBOwGs4jBTqhlAFiRuirBCpPB08=; b=QJi9M0gW6qLoa+mBkMKTtJYOZ02DyrT/yFcsUQnHlskO4TGNrfGfsZL0TUuOaqro5T HJoKM+9topWHdUEy/NQq8OkHj6FopopVPmB4bUTJNg8lz1OcQ69DWeCMPI8Y4iU/LBYJ razprM4JH60su12rQLMHJcwXvm3uQXIVdnEddQY6vKhHKkY5csXXu2E4jTX+7AkPI3H0 Hm8bzXC1kiniO56LjNfXHce5wh1gjxRu6BPixeSIPsvZ8FcLyRP2ABTx6yUwmbKFLIBZ pdKNjlZhk/llQJkC34KcsG7Jrwa8f63BxZcEBmbrkAw4jtwxVLESprtweMIIlAPQ0ZwV JJSg== X-Gm-Message-State: ABy/qLa3jCipkPcu+lI7oQkUgpHUIWhsGwDMqh46+YiWHfcAIED6V4BQ Ba6Ypac8uZJIXFBlTcVCDv8= X-Received: by 2002:a05:600c:2290:b0:3f6:d90:3db with SMTP id 16-20020a05600c229000b003f60d9003dbmr4850758wmf.3.1689868182527; Thu, 20 Jul 2023 08:49:42 -0700 (PDT) Received: from ip-172-31-22-112.eu-west-1.compute.internal (ec2-34-244-51-157.eu-west-1.compute.amazonaws.com. [34.244.51.157]) by smtp.gmail.com with ESMTPSA id u6-20020a05600c00c600b003fbdd9c72aasm1471021wmm.21.2023.07.20.08.49.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jul 2023 08:49:42 -0700 (PDT) From: Puranjay Mohan To: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, pulehui@huawei.com, conor.dooley@microchip.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, kpsingh@kernel.org, bjorn@kernel.org, bpf@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: puranjay12@gmail.com Subject: [PATCH bpf-next 0/2] bpf, riscv: use BPF prog pack allocator in BPF JIT Date: Thu, 20 Jul 2023 15:49:39 +0000 Message-Id: <20230720154941.1504-1-puranjay12@gmail.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 BPF programs currently consume a page each on RISCV. For systems with many BPF programs, this adds significant pressure to instruction TLB. High iTLB pressure usually causes slow down for the whole system. Song Liu introduced the BPF prog pack allocator[1] to mitigate the above issue. It packs multiple BPF programs into a single huge page. It is currently only enabled for the x86_64 BPF JIT. I enabled this allocator on the ARM64 BPF JIT[2]. It is being reviewed now. This patch series enables the BPF prog pack allocator for the RISCV BPF JIT. This series needs a patch[3] from the ARM64 series to work. ====================================================== Performance Analysis of prog pack allocator on RISCV64 ====================================================== Test setup: =========== Host machine: Debian GNU/Linux 11 (bullseye) Qemu Version: QEMU emulator version 8.0.3 (Debian 1:8.0.3+dfsg-1) u-boot-qemu Version: 2023.07+dfsg-1 opensbi Version: 1.3-1 To test the performance of the BPF prog pack allocator on RV, a stresser tool[4] linked below was built. This tool loads 8 BPF programs on the system and triggers 5 of them in an infinite loop by doing system calls. The runner script starts 20 instances of the above which loads 8*20=160 BPF programs on the system, 5*20=100 of which are being constantly triggered. The script is passed a command which would be run in the above environment. The script was run with following perf command: ./run.sh "perf stat -a \ -e iTLB-load-misses \ -e dTLB-load-misses \ -e dTLB-store-misses \ -e instructions \ --timeout 60000" The output of the above command is discussed below before and after enabling the BPF prog pack allocator. The tests were run on qemu-system-riscv64 with 8 cpus, 16G memory. The rootfs was created using Bjorn's riscv-cross-builder[5] docker container linked below. Results ======= Before enabling prog pack allocator: ------------------------------------ Performance counter stats for 'system wide': 4939048 iTLB-load-misses 5468689 dTLB-load-misses 465234 dTLB-store-misses 1441082097998 instructions 60.045791200 seconds time elapsed After enabling prog pack allocator: ----------------------------------- Performance counter stats for 'system wide': 3430035 iTLB-load-misses 5008745 dTLB-load-misses 409944 dTLB-store-misses 1441535637988 instructions 60.046296600 seconds time elapsed Improvements in metrics ======================= It was expected that the iTLB-load-misses would decrease as now a single huge page is used to keep all the BPF programs compared to a single page for each program earlier. -------------------------------------------- The improvement in iTLB-load-misses: -30.5 % -------------------------------------------- I repeated this expriment more than 100 times in different setups and the improvement was always greater than 30%. This patch series is boot tested on the Starfive VisionFive 2 board[6]. The performance analysis was not done on the board because it doesn't expose iTLB-load-misses, etc. The stresser program was run on the board to test the loading and unloading of BPF programs [1] https://lore.kernel.org/bpf/20220204185742.271030-1-song@kernel.org/ [2] https://lore.kernel.org/all/20230626085811.3192402-1-puranjay12@gmail.com/ [3] https://lore.kernel.org/all/20230626085811.3192402-2-puranjay12@gmail.com/ [4] https://github.com/puranjaymohan/BPF-Allocator-Bench [5] https://github.com/bjoto/riscv-cross-builder [6] https://www.starfivetech.com/en/site/boards Puranjay Mohan (2): riscv: Extend patch_text_nosync() for multiple pages bpf, riscv: use prog pack allocator in the BPF JIT arch/riscv/kernel/patch.c | 29 ++++++-- arch/riscv/net/bpf_jit.h | 3 + arch/riscv/net/bpf_jit_comp64.c | 56 ++++++++++++--- arch/riscv/net/bpf_jit_core.c | 117 +++++++++++++++++++++++++++----- 4 files changed, 174 insertions(+), 31 deletions(-) -- 2.40.1