From patchwork Wed Apr 29 03:58:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 220350 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E369C83003 for ; Wed, 29 Apr 2020 03:58:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 289102072A for ; Wed, 29 Apr 2020 03:58:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="kwSWqOks" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726634AbgD2D6u (ORCPT ); Tue, 28 Apr 2020 23:58:50 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:23496 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726755AbgD2D6t (ORCPT ); Tue, 28 Apr 2020 23:58:49 -0400 Received: from pps.filterd (m0109331.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 03T3rwGE028630 for ; Tue, 28 Apr 2020 20:58:48 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=facebook; bh=nW1dAchKtYHXH0E5cc5HRNgJkJCkI944GZCwY6z2qYk=; b=kwSWqOkskbh4agSmsibVjkTSjhsWa1NpygMRBQxpGkEPwTocE6FvDN2q6mpfwq1ElsKS H4cxDSumx+awVRoQRPkFqWWwTQsj5xdJ3eB9BTDUucX777soDiLnb1BPtmhhDjkBQu/L ABdRN7FJdf76fFMB36OG3UrVR4YE91hGB1A= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 30mk1grb90-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 28 Apr 2020 20:58:48 -0700 Received: from intmgw004.03.ash8.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1847.3; Tue, 28 Apr 2020 20:58:47 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id 57B0362E4BEF; Tue, 28 Apr 2020 20:58:43 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Song Liu Smtp-Origin-Hostname: devbig006.ftw2.facebook.com To: , CC: , , , Song Liu Smtp-Origin-Cluster: ftw2c04 Subject: [PATCH v7 bpf-next 0/3] bpf: sharing bpf runtime stats with Date: Tue, 28 Apr 2020 20:58:38 -0700 Message-ID: <20200429035841.3959159-1-songliubraving@fb.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.676 definitions=2020-04-28_15:2020-04-28,2020-04-28 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 impostorscore=0 suspectscore=8 mlxlogscore=999 priorityscore=1501 lowpriorityscore=0 mlxscore=0 malwarescore=0 bulkscore=0 spamscore=0 adultscore=0 clxscore=1015 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2004290028 X-FB-Internal: deliver Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org run_time_ns is a useful stats for BPF programs. However, it is gated by sysctl kernel.bpf_stats_enabled. When multiple user space tools are toggling kernl.bpf_stats_enabled at the same time, they may confuse each other. Solve this problem with a new BPF command BPF_ENABLE_STATS. Changes v6 => v7: 1. Add test to verify run_cnt matches count measured by the program. Changes v5 => v6: 1. Simplify test program (Yonghong). 2. Rebase (with some conflicts). Changes v4 => v5: 1. Use memset to zero bpf_attr in bpf_enable_stats() (Andrii). Changes v3 => v4: 1. Add libbpf support and selftest; 2. Avoid cleaning trailing space. Changes v2 => v3: 1. Rename the command to BPF_ENABLE_STATS, and make it extendible. 2. fix commit log; 3. remove unnecessary headers. Song Liu (3): bpf: sharing bpf runtime stats with BPF_ENABLE_STATS libbpf: add support for command BPF_ENABLE_STATS bpf: add selftest for BPF_ENABLE_STATS include/linux/bpf.h | 1 + include/uapi/linux/bpf.h | 11 ++++ kernel/bpf/syscall.c | 50 ++++++++++++++++ kernel/sysctl.c | 37 +++++++++++- tools/include/uapi/linux/bpf.h | 11 ++++ tools/lib/bpf/bpf.c | 10 ++++ tools/lib/bpf/bpf.h | 1 + tools/lib/bpf/libbpf.map | 5 ++ .../selftests/bpf/prog_tests/enable_stats.c | 58 +++++++++++++++++++ .../selftests/bpf/progs/test_enable_stats.c | 18 ++++++ 10 files changed, 200 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/enable_stats.c create mode 100644 tools/testing/selftests/bpf/progs/test_enable_stats.c --- 2.24.1