{"id":808825,"url":"http://patchwork.ozlabs.org/api/1.0/patches/808825/?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":"<20170901165357.465121-3-yhs@fb.com>","date":"2017-09-01T16:53:55","name":"[net-next,2/4] bpf: add a test case for helper bpf_perf_read_counter_time","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/20170901165357.465121-3-yhs@fb.com/mbox/","series":[{"id":1077,"url":"http://patchwork.ozlabs.org/api/1.0/series/1077/?format=json","date":"2017-09-01T16:53:53","name":"bpf: add two helpers to read perf event enabled/running time","version":1,"mbox":"http://patchwork.ozlabs.org/series/1077/mbox/"}],"check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/808825/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=\"atzpbO9X\";\n\tdkim-atps=neutral"],"Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xkQLp14YDz9t2x\n\tfor <patchwork-incoming@ozlabs.org>;\n\tSat,  2 Sep 2017 02:54:09 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1752355AbdIAQyH (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tFri, 1 Sep 2017 12:54:07 -0400","from mx0b-00082601.pphosted.com ([67.231.153.30]:53991 \"EHLO\n\tmx0a-00082601.pphosted.com\" rhost-flags-OK-OK-OK-FAIL)\n\tby vger.kernel.org with ESMTP id S1752297AbdIAQyA (ORCPT\n\t<rfc822;netdev@vger.kernel.org>); Fri, 1 Sep 2017 12:54:00 -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\tv81GptJJ021070\n\tfor <netdev@vger.kernel.org>; Fri, 1 Sep 2017 09:53:59 -0700","from mail.thefacebook.com ([199.201.64.23])\n\tby mx0b-00082601.pphosted.com with ESMTP id 2cq176jkjp-2\n\t(version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT)\n\tfor <netdev@vger.kernel.org>; Fri, 01 Sep 2017 09:53:59 -0700","from PRN-CHUB02.TheFacebook.com (2620:10d:c081:35::11) by\n\tPRN-CHUB15.TheFacebook.com (2620:10d:c081:35::27) with Microsoft SMTP\n\tServer (TLS) id 14.3.319.2; Fri, 1 Sep 2017 09:53:59 -0700","from mx-out.facebook.com (192.168.52.123) by\n\tPRN-CHUB02.TheFacebook.com (192.168.16.12) with Microsoft SMTP Server\n\tid 14.3.319.2; Fri, 1 Sep 2017 09:53:57 -0700","by devbig474.prn1.facebook.com (Postfix, from userid 128203)  id\n\tCF0A246E02C5; Fri,  1 Sep 2017 09:53:57 -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=miNs/7WzN6OZmm0qMKI/CqJ5DVgO67yJD1CyeTTDw5w=; \n\tb=atzpbO9XSVlXXZ4dyk1FFquZoiU+E3o+zj2FD2CDjN510aPc8e5n1YRMhLIRwNOQgGdd\n\t8CTWcxUSQabYFkeaIMGK5Ku7Uzw4Ue+T03vn0hL5GB22gEYnBgdtg3RXqj8a4J3oPrXN\n\tZTK1gX7h3DhNr+vv9Y8IUQpOOoibdvhVp+Y= ","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 net-next 2/4] bpf: add a test case for helper\n\tbpf_perf_read_counter_time","Date":"Fri, 1 Sep 2017 09:53:55 -0700","Message-ID":"<20170901165357.465121-3-yhs@fb.com>","X-Mailer":"git-send-email 2.9.5","In-Reply-To":"<20170901165357.465121-1-yhs@fb.com>","References":"<20170901165357.465121-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-01_04:, , 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.\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":["net-next","2/4"]}