{"id":809045,"url":"http://patchwork.ozlabs.org/api/1.0/patches/809045/?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-3-yhs@fb.com>","date":"2017-09-02T05:48:22","name":"[v2,net-next,2/4] bpf: add a test case to read enabled/running time for perf array","commit_ref":null,"pull_url":null,"state":"changes-requested","archived":true,"hash":"ca7cd2cc61f2a2fe2908dd16e467eb2137d4ff85","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-3-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/809045/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=\"GYhlHA4w\";\n\tdkim-atps=neutral"],"Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xklXb6MqFz9s76\n\tfor <patchwork-incoming@ozlabs.org>;\n\tSat,  2 Sep 2017 15:48:47 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1751539AbdIBFs3 (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tSat, 2 Sep 2017 01:48:29 -0400","from mx0b-00082601.pphosted.com ([67.231.153.30]:56705 \"EHLO\n\tmx0a-00082601.pphosted.com\" rhost-flags-OK-OK-OK-FAIL)\n\tby vger.kernel.org with ESMTP id S1751095AbdIBFs1 (ORCPT\n\t<rfc822;netdev@vger.kernel.org>); Sat, 2 Sep 2017 01:48:27 -0400","from pps.filterd (m0001255.ppops.net [127.0.0.1])\n\tby mx0b-00082601.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id\n\tv8258Hqw002578\n\tfor <netdev@vger.kernel.org>; Fri, 1 Sep 2017 22:48:25 -0700","from mail.thefacebook.com ([199.201.64.23])\n\tby mx0b-00082601.pphosted.com with ESMTP id 2cqe04h6yc-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-CHUB11.TheFacebook.com (192.168.16.21) with Microsoft SMTP Server\n\tid 14.3.319.2; Fri, 1 Sep 2017 22:48:24 -0700","by devbig474.prn1.facebook.com (Postfix, from userid 128203)  id\n\t82A5546E0481; 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=rsN5LLl+aduGR+8vqSTKsyHb5Tap9djV0PSBjtvuVAw=; \n\tb=GYhlHA4woRACc0SxuCYC7OSFg796FsWM61wXtq+6Zya5tOlzXAczZ2Pu3g6FKclHMUxy\n\taj6UVcydL+pFOCZyqZMZuymwRDLJIYpQ34+OKh0B/ozG1wfbhuS/tLxMj5j0mTzM7qzh\n\toiWk//7C/CVidnCO4KbiVUvYixB71gu+Kzo= ","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 2/4] bpf: add a test case to read\n\tenabled/running time for perf array","Date":"Fri, 1 Sep 2017 22:48:22 -0700","Message-ID":"<20170902054824.371962-3-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 tracex6 is enhanced to use the new\nhelper to read enabled/running time as well.\n\nSigned-off-by: Yonghong Song <yhs@fb.com>\n---\n samples/bpf/tracex6_kern.c                | 26 ++++++++++++++++++++++++++\n samples/bpf/tracex6_user.c                | 13 ++++++++++++-\n tools/testing/selftests/bpf/bpf_helpers.h |  4 ++++\n 3 files changed, 42 insertions(+), 1 deletion(-)","diff":"diff --git a/samples/bpf/tracex6_kern.c b/samples/bpf/tracex6_kern.c\nindex e7d1803..46acfef 100644\n--- a/samples/bpf/tracex6_kern.c\n+++ b/samples/bpf/tracex6_kern.c\n@@ -15,6 +15,12 @@ struct bpf_map_def SEC(\"maps\") values = {\n \t.value_size = sizeof(u64),\n \t.max_entries = 64,\n };\n+struct bpf_map_def SEC(\"maps\") values2 = {\n+\t.type = BPF_MAP_TYPE_HASH,\n+\t.key_size = sizeof(int),\n+\t.value_size = sizeof(struct bpf_perf_counter_time),\n+\t.max_entries = 64,\n+};\n \n SEC(\"kprobe/htab_map_get_next_key\")\n int bpf_prog1(struct pt_regs *ctx)\n@@ -37,5 +43,25 @@ int bpf_prog1(struct pt_regs *ctx)\n \treturn 0;\n }\n \n+SEC(\"kprobe/htab_map_lookup_elem\")\n+int bpf_prog2(struct pt_regs *ctx)\n+{\n+\tu32 key = bpf_get_smp_processor_id();\n+\tstruct bpf_perf_counter_time *val, buf;\n+\tint error;\n+\n+\terror = bpf_perf_read_counter_time(&counters, key, &buf, sizeof(buf));\n+\tif (error)\n+\t\treturn 0;\n+\n+\tval = bpf_map_lookup_elem(&values2, &key);\n+\tif (val)\n+\t\t*val = buf;\n+\telse\n+\t\tbpf_map_update_elem(&values2, &key, &buf, BPF_NOEXIST);\n+\n+\treturn 0;\n+}\n+\n char _license[] SEC(\"license\") = \"GPL\";\n u32 _version SEC(\"version\") = LINUX_VERSION_CODE;\ndiff --git a/samples/bpf/tracex6_user.c b/samples/bpf/tracex6_user.c\nindex a05a99a..2a0c5d8 100644\n--- a/samples/bpf/tracex6_user.c\n+++ b/samples/bpf/tracex6_user.c\n@@ -22,6 +22,7 @@\n \n static void check_on_cpu(int cpu, struct perf_event_attr *attr)\n {\n+\tstruct bpf_perf_counter_time value2;\n \tint pmu_fd, error = 0;\n \tcpu_set_t set;\n \t__u64 value;\n@@ -46,8 +47,18 @@ static void check_on_cpu(int cpu, struct perf_event_attr *attr)\n \t\tfprintf(stderr, \"Value missing for CPU %d\\n\", cpu);\n \t\terror = 1;\n \t\tgoto on_exit;\n+\t} else {\n+\t\tfprintf(stderr, \"CPU %d: %llu\\n\", cpu, value);\n+\t}\n+\t/* The above bpf_map_lookup_elem should trigger the second kprobe */\n+\tif (bpf_map_lookup_elem(map_fd[2], &cpu, &value2)) {\n+\t\tfprintf(stderr, \"Value2 missing for CPU %d\\n\", cpu);\n+\t\terror = 1;\n+\t\tgoto on_exit;\n+\t} else {\n+\t\tfprintf(stderr, \"CPU %d: counter: %llu, enabled: %llu, running: %llu\\n\", cpu,\n+\t\t\tvalue2.counter, value2.time.enabled, value2.time.running);\n \t}\n-\tfprintf(stderr, \"CPU %d: %llu\\n\", cpu, value);\n \n on_exit:\n \tassert(bpf_map_delete_elem(map_fd[0], &cpu) == 0 || error);\ndiff --git a/tools/testing/selftests/bpf/bpf_helpers.h b/tools/testing/selftests/bpf/bpf_helpers.h\nindex 36fb916..fe41852 100644\n--- a/tools/testing/selftests/bpf/bpf_helpers.h\n+++ b/tools/testing/selftests/bpf/bpf_helpers.h\n@@ -70,6 +70,10 @@ static int (*bpf_sk_redirect_map)(void *map, int key, int flags) =\n static int (*bpf_sock_map_update)(void *map, void *key, void *value,\n \t\t\t\t  unsigned long long flags) =\n \t(void *) BPF_FUNC_sock_map_update;\n+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 \n \n /* llvm builtin functions that eBPF C program may use to\n","prefixes":["v2","net-next","2/4"]}