{"id":809047,"url":"http://patchwork.ozlabs.org/api/1.0/patches/809047/?format=json","project":{"id":7,"url":"http://patchwork.ozlabs.org/api/1.0/projects/7/?format=json","name":"Linux network development","link_name":"netdev","list_id":"netdev.vger.kernel.org","list_email":"netdev@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null},"msgid":"<20170902054824.371962-5-yhs@fb.com>","date":"2017-09-02T05:48:24","name":"[v2,net-next,4/4] bpf: add a test case for helper bpf_perf_prog_read_time","commit_ref":null,"pull_url":null,"state":"changes-requested","archived":true,"hash":"0bc61b1b457d1811a34ed9a6faa832d39f39d609","submitter":{"id":71628,"url":"http://patchwork.ozlabs.org/api/1.0/people/71628/?format=json","name":"Yonghong Song","email":"yhs@fb.com"},"delegate":{"id":34,"url":"http://patchwork.ozlabs.org/api/1.0/users/34/?format=json","username":"davem","first_name":"David","last_name":"Miller","email":"davem@davemloft.net"},"mbox":"http://patchwork.ozlabs.org/project/netdev/patch/20170902054824.371962-5-yhs@fb.com/mbox/","series":[{"id":1139,"url":"http://patchwork.ozlabs.org/api/1.0/series/1139/?format=json","date":"2017-09-02T05:48:21","name":"bpf: add two helpers to read perf event enabled/running time","version":2,"mbox":"http://patchwork.ozlabs.org/series/1139/mbox/"}],"check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/809047/checks/","tags":{},"headers":{"Return-Path":"<netdev-owner@vger.kernel.org>","X-Original-To":"patchwork-incoming@ozlabs.org","Delivered-To":"patchwork-incoming@ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=netdev-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=fb.com header.i=@fb.com header.b=\"YBU017hU\";\n\tdkim-atps=neutral"],"Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xklXd0wQ1z9s76\n\tfor <patchwork-incoming@ozlabs.org>;\n\tSat,  2 Sep 2017 15:48:49 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1751989AbdIBFsi (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tSat, 2 Sep 2017 01:48:38 -0400","from mx0b-00082601.pphosted.com ([67.231.153.30]:35591 \"EHLO\n\tmx0a-00082601.pphosted.com\" rhost-flags-OK-OK-OK-FAIL)\n\tby vger.kernel.org with ESMTP id S1750997AbdIBFs1 (ORCPT\n\t<rfc822;netdev@vger.kernel.org>); Sat, 2 Sep 2017 01:48:27 -0400","from pps.filterd (m0089730.ppops.net [127.0.0.1])\n\tby m0089730.ppops.net (8.16.0.21/8.16.0.21) with SMTP id\n\tv8254KDF031068\n\tfor <netdev@vger.kernel.org>; Fri, 1 Sep 2017 22:48:25 -0700","from mail.thefacebook.com ([199.201.64.23])\n\tby m0089730.ppops.net with ESMTP id 2cqhbp8jjj-2\n\t(version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT)\n\tfor <netdev@vger.kernel.org>; Fri, 01 Sep 2017 22:48:25 -0700","from mx-out.facebook.com (192.168.52.123) by\n\tPRN-CHUB12.TheFacebook.com (192.168.16.22) with Microsoft SMTP Server\n\tid 14.3.319.2; Fri, 1 Sep 2017 22:48:25 -0700","by devbig474.prn1.facebook.com (Postfix, from userid 128203)  id\n\tA36F146E047A; Fri,  1 Sep 2017 22:48:24 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com;\n\th=from : to : cc : subject\n\t: date : message-id : in-reply-to : references : mime-version :\n\tcontent-type; s=facebook;\n\tbh=GfUdr9KXq7rAd0cgRZKn/GW8bWjLYOewZdwF9TNAmSc=; \n\tb=YBU017hUSSfjx2k6IvpsP3g+L3vfHt++wYpj/0UeXfuUxOkJgIthYL4cfoAg1syGRLmg\n\tq1twzujWaNqOgJBjECnsjXbf3NbYEYmYpdzs2kiUK9xWO+N61zK3ydi4QCPF8Em+GX10\n\tKcut4+LjMm7nJoahfwwX5rRztmfcbLMUGwQ= ","X-ThriftRelayHost":"devbig474.prn1.facebook.com","Smtp-Origin-Hostprefix":"devbig","From":"Yonghong Song <yhs@fb.com>","Smtp-Origin-Hostname":"devbig474.prn1.facebook.com","To":"<peterz@infradead.org>, <rostedt@goodmis.org>, <ast@fb.com>,\n\t<daniel@iogearbox.net>, <netdev@vger.kernel.org>","CC":"<kernel-team@fb.com>","Smtp-Origin-Cluster":"prn1c29","Subject":"[PATCH v2 net-next 4/4] bpf: add a test case for helper\n\tbpf_perf_prog_read_time","Date":"Fri, 1 Sep 2017 22:48:24 -0700","Message-ID":"<20170902054824.371962-5-yhs@fb.com>","X-Mailer":"git-send-email 2.9.5","In-Reply-To":"<20170902054824.371962-1-yhs@fb.com>","References":"<20170902054824.371962-1-yhs@fb.com>","X-FB-Internal":["Safe","Safe"],"MIME-Version":"1.0","Content-Type":"text/plain","X-Proofpoint-Spam-Reason":"safe","X-Proofpoint-Virus-Version":"vendor=fsecure engine=2.50.10432:, ,\n\tdefinitions=2017-09-02_01:, , signatures=0","Sender":"netdev-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<netdev.vger.kernel.org>","X-Mailing-List":"netdev@vger.kernel.org"},"content":"The bpf sample program trace_event is enhanced to use the new\nhelper to print out enabled/running time.\n\nSigned-off-by: Yonghong Song <yhs@fb.com>\n---\n samples/bpf/trace_event_kern.c            | 10 ++++++++++\n samples/bpf/trace_event_user.c            | 13 ++++++++-----\n tools/testing/selftests/bpf/bpf_helpers.h |  3 +++\n 3 files changed, 21 insertions(+), 5 deletions(-)","diff":"diff --git a/samples/bpf/trace_event_kern.c b/samples/bpf/trace_event_kern.c\nindex 41b6115..e93c8b1 100644\n--- a/samples/bpf/trace_event_kern.c\n+++ b/samples/bpf/trace_event_kern.c\n@@ -37,10 +37,14 @@ struct bpf_map_def SEC(\"maps\") stackmap = {\n SEC(\"perf_event\")\n int bpf_prog1(struct bpf_perf_event_data *ctx)\n {\n+\tchar time_fmt1[] = \"Time Enabled: %llu, Time Running: %llu\";\n+\tchar time_fmt2[] = \"Get Time Failed, ErrCode: %d\";\n \tchar fmt[] = \"CPU-%d period %lld ip %llx\";\n \tu32 cpu = bpf_get_smp_processor_id();\n+\tstruct bpf_perf_time time_buf;\n \tstruct key_t key;\n \tu64 *val, one = 1;\n+\tint ret;\n \n \tif (ctx->sample_period < 10000)\n \t\t/* ignore warmup */\n@@ -54,6 +58,12 @@ int bpf_prog1(struct bpf_perf_event_data *ctx)\n \t\treturn 0;\n \t}\n \n+\tret = bpf_perf_prog_read_time(ctx, (void *)&time_buf, sizeof(struct bpf_perf_time));\n+\tif (!ret)\n+\t  bpf_trace_printk(time_fmt1, sizeof(time_fmt1), time_buf.enabled, time_buf.running);\n+\telse\n+\t  bpf_trace_printk(time_fmt2, sizeof(time_fmt2), ret);\n+\n \tval = bpf_map_lookup_elem(&counts, &key);\n \tif (val)\n \t\t(*val)++;\ndiff --git a/samples/bpf/trace_event_user.c b/samples/bpf/trace_event_user.c\nindex 7bd827b..bf4f1b6 100644\n--- a/samples/bpf/trace_event_user.c\n+++ b/samples/bpf/trace_event_user.c\n@@ -127,6 +127,9 @@ static void test_perf_event_all_cpu(struct perf_event_attr *attr)\n \tint *pmu_fd = malloc(nr_cpus * sizeof(int));\n \tint i, error = 0;\n \n+\t/* system wide perf event, no need to inherit */\n+\tattr->inherit = 0;\n+\n \t/* open perf_event on all cpus */\n \tfor (i = 0; i < nr_cpus; i++) {\n \t\tpmu_fd[i] = sys_perf_event_open(attr, -1, i, -1, 0);\n@@ -154,6 +157,11 @@ static void test_perf_event_task(struct perf_event_attr *attr)\n {\n \tint pmu_fd;\n \n+\t/* per task perf event, enable inherit so the \"dd ...\" command can be traced properly.\n+\t * Enabling inherit will cause bpf_perf_prog_read_time helper failure.\n+\t */\n+\tattr->inherit = 1;\n+\n \t/* open task bound event */\n \tpmu_fd = sys_perf_event_open(attr, 0, -1, -1, 0);\n \tif (pmu_fd < 0) {\n@@ -175,14 +183,12 @@ static void test_bpf_perf_event(void)\n \t\t.freq = 1,\n \t\t.type = PERF_TYPE_HARDWARE,\n \t\t.config = PERF_COUNT_HW_CPU_CYCLES,\n-\t\t.inherit = 1,\n \t};\n \tstruct perf_event_attr attr_type_sw = {\n \t\t.sample_freq = SAMPLE_FREQ,\n \t\t.freq = 1,\n \t\t.type = PERF_TYPE_SOFTWARE,\n \t\t.config = PERF_COUNT_SW_CPU_CLOCK,\n-\t\t.inherit = 1,\n \t};\n \tstruct perf_event_attr attr_hw_cache_l1d = {\n \t\t.sample_freq = SAMPLE_FREQ,\n@@ -192,7 +198,6 @@ static void test_bpf_perf_event(void)\n \t\t\tPERF_COUNT_HW_CACHE_L1D |\n \t\t\t(PERF_COUNT_HW_CACHE_OP_READ << 8) |\n \t\t\t(PERF_COUNT_HW_CACHE_RESULT_ACCESS << 16),\n-\t\t.inherit = 1,\n \t};\n \tstruct perf_event_attr attr_hw_cache_branch_miss = {\n \t\t.sample_freq = SAMPLE_FREQ,\n@@ -202,7 +207,6 @@ static void test_bpf_perf_event(void)\n \t\t\tPERF_COUNT_HW_CACHE_BPU |\n \t\t\t(PERF_COUNT_HW_CACHE_OP_READ << 8) |\n \t\t\t(PERF_COUNT_HW_CACHE_RESULT_MISS << 16),\n-\t\t.inherit = 1,\n \t};\n \tstruct perf_event_attr attr_type_raw = {\n \t\t.sample_freq = SAMPLE_FREQ,\n@@ -210,7 +214,6 @@ static void test_bpf_perf_event(void)\n \t\t.type = PERF_TYPE_RAW,\n \t\t/* Intel Instruction Retired */\n \t\t.config = 0xc0,\n-\t\t.inherit = 1,\n \t};\n \n \tprintf(\"Test HW_CPU_CYCLES\\n\");\ndiff --git a/tools/testing/selftests/bpf/bpf_helpers.h b/tools/testing/selftests/bpf/bpf_helpers.h\nindex fe41852..ddad690 100644\n--- a/tools/testing/selftests/bpf/bpf_helpers.h\n+++ b/tools/testing/selftests/bpf/bpf_helpers.h\n@@ -74,6 +74,9 @@ static int (*bpf_perf_read_counter_time)(void *map, unsigned long long flags,\n \t\t\t\t       void *counter_time_buf,\n \t\t\t\t       unsigned int buf_size) =\n \t(void *) BPF_FUNC_perf_read_counter_time;\n+static int (*bpf_perf_prog_read_time)(void *ctx, void *time_buf,\n+\t\t\t\t      unsigned int size) =\n+\t(void *) BPF_FUNC_perf_prog_read_time;\n \n \n /* llvm builtin functions that eBPF C program may use to\n","prefixes":["v2","net-next","4/4"]}