Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/1238832/?format=api
{ "id": 1238832, "url": "http://patchwork.ozlabs.org/api/patches/1238832/?format=api", "web_url": "http://patchwork.ozlabs.org/project/netdev/patch/20200216193005.144157-17-jolsa@kernel.org/", "project": { "id": 7, "url": "http://patchwork.ozlabs.org/api/projects/7/?format=api", "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, "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20200216193005.144157-17-jolsa@kernel.org>", "list_archive_url": null, "date": "2020-02-16T19:30:03", "name": "[16/18] perf tools: Synthesize bpf_trampoline/dispatcher ksymbol event", "commit_ref": null, "pull_url": null, "state": "changes-requested", "archived": false, "hash": "181b4261aa43267c2934c466c83d5182d8185f3d", "submitter": { "id": 73687, "url": "http://patchwork.ozlabs.org/api/people/73687/?format=api", "name": "Jiri Olsa", "email": "jolsa@kernel.org" }, "delegate": { "id": 77147, "url": "http://patchwork.ozlabs.org/api/users/77147/?format=api", "username": "bpf", "first_name": "BPF", "last_name": "Maintainers", "email": "bpf@iogearbox.net" }, "mbox": "http://patchwork.ozlabs.org/project/netdev/patch/20200216193005.144157-17-jolsa@kernel.org/mbox/", "series": [ { "id": 158829, "url": "http://patchwork.ozlabs.org/api/series/158829/?format=api", "web_url": "http://patchwork.ozlabs.org/project/netdev/list/?series=158829", "date": "2020-02-16T19:29:47", "name": "bpf: Add trampoline and dispatcher to /proc/kallsyms", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/158829/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/1238832/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/1238832/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<bpf-owner@vger.kernel.org>", "X-Original-To": "incoming-bpf@patchwork.ozlabs.org", "Delivered-To": "patchwork-incoming-bpf@bilbo.ozlabs.org", "Authentication-Results": [ "ozlabs.org; spf=none (no SPF record)\n\tsmtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67;\n\thelo=vger.kernel.org; envelope-from=bpf-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)", "ozlabs.org;\n\tdmarc=fail (p=none dis=none) header.from=kernel.org" ], "Received": [ "from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 48LHLM1FPQz9sP7\n\tfor <incoming-bpf@patchwork.ozlabs.org>;\n\tMon, 17 Feb 2020 06:31:55 +1100 (AEDT)", "(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1726037AbgBPTby convert rfc822-to-8bit (ORCPT\n\t<rfc822;incoming-bpf@patchwork.ozlabs.org>);\n\tSun, 16 Feb 2020 14:31:54 -0500", "from us-smtp-2.mimecast.com ([207.211.31.81]:30654 \"EHLO\n\tus-smtp-delivery-1.mimecast.com\" rhost-flags-OK-OK-OK-FAIL)\n\tby vger.kernel.org with ESMTP id S1726656AbgBPTby (ORCPT\n\t<rfc822;bpf@vger.kernel.org>); Sun, 16 Feb 2020 14:31:54 -0500", "from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com\n\t[209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id\n\tus-mta-307-7nDvYxAmN4exEtzLaotL_Q-1; Sun, 16 Feb 2020 14:31:45 -0500", "from smtp.corp.redhat.com\n\t(int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mimecast-mx01.redhat.com (Postfix) with ESMTPS id D10801005516;\n\tSun, 16 Feb 2020 19:31:42 +0000 (UTC)", "from krava.redhat.com (ovpn-204-28.brq.redhat.com [10.40.204.28])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id 8C6318AC5B;\n\tSun, 16 Feb 2020 19:31:39 +0000 (UTC)" ], "From": "Jiri Olsa <jolsa@kernel.org>", "To": "Alexei Starovoitov <ast@kernel.org>,\n\tDaniel Borkmann <daniel@iogearbox.net>", "Cc": "netdev@vger.kernel.org, bpf@vger.kernel.org, Andrii Nakryiko\n\t<andriin@fb.com>, Yonghong Song <yhs@fb.com>, Song Liu\n\t<songliubraving@fb.com>, Martin KaFai Lau <kafai@fb.com>,\n\tJakub Kicinski <kuba@kernel.org>, David Miller <davem@redhat.com>,\n\t=?utf-8?b?QmrDtnJuIFTDtnBlbA==?= <bjorn.topel@intel.com>,\n\tJohn Fastabend <john.fastabend@gmail.com>, Jesper Dangaard Brouer\n\t<hawk@kernel.org>, Arnaldo Carvalho de Melo <acme@redhat.com>", "Subject": "[PATCH 16/18] perf tools: Synthesize bpf_trampoline/dispatcher\n\tksymbol event", "Date": "Sun, 16 Feb 2020 20:30:03 +0100", "Message-Id": "<20200216193005.144157-17-jolsa@kernel.org>", "In-Reply-To": "<20200216193005.144157-1-jolsa@kernel.org>", "References": "<20200216193005.144157-1-jolsa@kernel.org>", "MIME-Version": "1.0", "X-Scanned-By": "MIMEDefang 2.79 on 10.5.11.11", "X-MC-Unique": "7nDvYxAmN4exEtzLaotL_Q-1", "X-Mimecast-Spam-Score": "0", "X-Mimecast-Originator": "kernel.org", "Content-Type": "text/plain; charset=WINDOWS-1252", "Content-Transfer-Encoding": "8BIT", "Sender": "bpf-owner@vger.kernel.org", "Precedence": "bulk", "List-ID": "<bpf.vger.kernel.org>", "X-Mailing-List": "bpf@vger.kernel.org" }, "content": "Synthesize bpf images (trampolines/dispatchers) on start,\nas ksymbol events from /proc/kallsyms. Having this perf\ncan recognize samples from those images and perf report\nand top shows them correctly.\n\nThe rest of the ksymbol handling is already in place from\nfor the bpf programs monitoring, so only the initial state\nwas needed.\n\nperf report output:\n\n # Overhead Command Shared Object Symbol\n\n 12.37% test_progs [kernel.vmlinux] [k] entry_SYSCALL_64\n 11.80% test_progs [kernel.vmlinux] [k] syscall_return_via_sysret\n 9.63% test_progs bpf_prog_bcf7977d3b93787c_prog2 [k] bpf_prog_bcf7977d3b93787c_prog2\n 6.90% test_progs bpf_trampoline_24456 [k] bpf_trampoline_24456\n 6.36% test_progs [kernel.vmlinux] [k] memcpy_erms\n\nSigned-off-by: Jiri Olsa <jolsa@kernel.org>\n---\n tools/perf/util/bpf-event.c | 98 +++++++++++++++++++++++++++++++++++++\n 1 file changed, 98 insertions(+)", "diff": "diff --git a/tools/perf/util/bpf-event.c b/tools/perf/util/bpf-event.c\nindex a3207d900339..120ec547ae75 100644\n--- a/tools/perf/util/bpf-event.c\n+++ b/tools/perf/util/bpf-event.c\n@@ -6,6 +6,9 @@\n #include <bpf/libbpf.h>\n #include <linux/btf.h>\n #include <linux/err.h>\n+#include <linux/string.h>\n+#include <internal/lib.h>\n+#include <symbol/kallsyms.h>\n #include \"bpf-event.h\"\n #include \"debug.h\"\n #include \"dso.h\"\n@@ -290,11 +293,87 @@ static int perf_event__synthesize_one_bpf_prog(struct perf_session *session,\n \treturn err ? -1 : 0;\n }\n \n+struct kallsyms_parse {\n+\tunion perf_event\t*event;\n+\tperf_event__handler_t\t process;\n+\tstruct machine\t\t*machine;\n+\tstruct perf_tool\t*tool;\n+};\n+\n+static int\n+process_bpf_image(char *name, u64 addr, struct kallsyms_parse *data)\n+{\n+\tstruct machine *machine = data->machine;\n+\tunion perf_event *event = data->event;\n+\tstruct perf_record_ksymbol *ksymbol;\n+\tu32 size;\n+\n+\tksymbol = &event->ksymbol;\n+\n+\t/*\n+\t * The bpf image (trampoline/dispatcher) size is aligned to\n+\t * page, while it starts little bit after the page boundary.\n+\t */\n+\tsize = page_size - (addr - PERF_ALIGN(addr, page_size));\n+\n+\t*ksymbol = (struct perf_record_ksymbol) {\n+\t\t.header = {\n+\t\t\t.type = PERF_RECORD_KSYMBOL,\n+\t\t\t.size = offsetof(struct perf_record_ksymbol, name),\n+\t\t},\n+\t\t.addr = addr,\n+\t\t.len = size,\n+\t\t.ksym_type = PERF_RECORD_KSYMBOL_TYPE_BPF,\n+\t\t.flags = 0,\n+\t};\n+\n+\tstrncpy(ksymbol->name, name, KSYM_NAME_LEN);\n+\tksymbol->header.size += PERF_ALIGN(strlen(name) + 1, sizeof(u64));\n+\tmemset((void *) event + event->header.size, 0, machine->id_hdr_size);\n+\tevent->header.size += machine->id_hdr_size;\n+\n+\treturn perf_tool__process_synth_event(data->tool, event, machine,\n+\t\t\t\t\t data->process);\n+}\n+\n+static int\n+kallsyms_process_symbol(void *data, const char *_name,\n+\t\t\tchar type __maybe_unused, u64 start)\n+{\n+\tchar *module, *name;\n+\tunsigned long id;\n+\tint err = 0;\n+\n+\tmodule = strchr(_name, '\\t');\n+\tif (!module)\n+\t\treturn 0;\n+\n+\t/* We are going after [bpf] module ... */\n+\tif (strcmp(module + 1, \"[bpf]\"))\n+\t\treturn 0;\n+\n+\tname = memdup(_name, (module - _name) + 1);\n+\tif (!name)\n+\t\treturn -ENOMEM;\n+\n+\tname[module - _name] = 0;\n+\n+\t/* .. and only for trampolines and dispatchers */\n+\tif ((sscanf(name, \"bpf_trampoline_%lu\", &id) == 1) ||\n+\t (sscanf(name, \"bpf_dispatcher_%lu\", &id) == 1))\n+\t\terr = process_bpf_image(name, start, data);\n+\n+\tfree(name);\n+\treturn err;\n+}\n+\n int perf_event__synthesize_bpf_events(struct perf_session *session,\n \t\t\t\t perf_event__handler_t process,\n \t\t\t\t struct machine *machine,\n \t\t\t\t struct record_opts *opts)\n {\n+\tconst char *kallsyms_filename = \"/proc/kallsyms\";\n+\tstruct kallsyms_parse arg;\n \tunion perf_event *event;\n \t__u32 id = 0;\n \tint err;\n@@ -303,6 +382,8 @@ int perf_event__synthesize_bpf_events(struct perf_session *session,\n \tevent = malloc(sizeof(event->bpf) + KSYM_NAME_LEN + machine->id_hdr_size);\n \tif (!event)\n \t\treturn -1;\n+\n+\t/* Synthesize all the bpf programs in system. */\n \twhile (true) {\n \t\terr = bpf_prog_get_next_id(id, &id);\n \t\tif (err) {\n@@ -335,6 +416,23 @@ int perf_event__synthesize_bpf_events(struct perf_session *session,\n \t\t\tbreak;\n \t\t}\n \t}\n+\n+\t/* Synthesize all the bpf images - trampolines/dispatchers. */\n+\tif (symbol_conf.kallsyms_name != NULL)\n+\t\tkallsyms_filename = symbol_conf.kallsyms_name;\n+\n+\targ = (struct kallsyms_parse) {\n+\t\t.event = event,\n+\t\t.process = process,\n+\t\t.machine = machine,\n+\t\t.tool = session->tool,\n+\t};\n+\n+\tif (kallsyms__parse(kallsyms_filename, &arg, kallsyms_process_symbol)) {\n+\t\tpr_err(\"%s: failed to synthesize bpf images: %s\\n\",\n+\t\t __func__, strerror(errno));\n+\t}\n+\n \tfree(event);\n \treturn err;\n }\n", "prefixes": [ "16/18" ] }