Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752091AbbKQDGb (ORCPT ); Mon, 16 Nov 2015 22:06:31 -0500 Received: from szxga02-in.huawei.com ([119.145.14.65]:58856 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751577AbbKQDGa (ORCPT ); Mon, 16 Nov 2015 22:06:30 -0500 Message-ID: <564A9985.20404@huawei.com> Date: Tue, 17 Nov 2015 11:05:41 +0800 From: "Wangnan (F)" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: , , CC: , , , Arnaldo Carvalho de Melo Subject: Re: [PATCH 13/13] perf tools: Use same BPF program if arguments are identical References: <1447675815-166222-1-git-send-email-wangnan0@huawei.com> <1447675815-166222-14-git-send-email-wangnan0@huawei.com> In-Reply-To: <1447675815-166222-14-git-send-email-wangnan0@huawei.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.111.66.109] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090202.564A99A9.000B,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 6a5d1c76b7f913bea54b54afc3e66975 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2368 Lines: 77 On 2015/11/16 20:10, Wang Nan wrote: > This patch allows creating only one BPF program for different > 'probe_trace_event'(tev) generated by one 'perf_probe_event'(pev), if > their prologues are identical. > > This is done by comparing argument list of different tev, and maps type > of prologue and tev using a mapping array. This patch utilizes qsort to > sort tevs. After sorting, tevs with identical argument list will be > grouped together. > > Test result: > > Sample BPF program: > > SEC("inlines=no\n" > "func=SyS_dup? oldfd") > int func(void *ctx) > { > return 1; > } > > It would probe at SyS_dup2 and SyS_dup3, extracts oldfd as its argument. > > Following cmdline shows BPF program loaded into kernel by perf: > > # ./perf record -e ./test_bpf_arg.c sleep 4 & sleep 1 && ls /proc/$!/fd/ -l | grep bpf-prog > > Before this patch: > > # ./perf record -e ./test_bpf_arg.c sleep 4 & sleep 1 && ls /proc/$!/fd/ -l | grep bpf-prog > [1] 24858 > lrwx------ 1 root root 64 Nov 14 04:09 3 -> anon_inode:bpf-prog > lrwx------ 1 root root 64 Nov 14 04:09 4 -> anon_inode:bpf-prog > ... > > After this patch: > > # ./perf record -e ./test_bpf_arg.c sleep 4 & sleep 1 && ls /proc/$!/fd/ -l | grep bpf-prog > [1] 25699 > lrwx------ 1 root root 64 Nov 14 04:10 3 -> anon_inode:bpf-prog > ... > > Signed-off-by: Wang Nan > Cc: Alexei Starovoitov > Cc: Arnaldo Carvalho de Melo > Cc: Masami Hiramatsu > Cc: Zefan Li > Cc: pi3orama@163.com > --- [SNIP] > @@ -462,7 +570,19 @@ static int hook_load_preprocessor(struct bpf_program *prog) > return -ENOMEM; > } > > - err = bpf_program__set_prep(prog, pev->ntevs, > + priv->type_mapping = malloc(sizeof(int) * pev->ntevs); > + if (!priv->type_mapping) { > + pr_debug("No enough memory: alloc type_mapping failed\n"); > + return -ENOMEM; > + } > + memset(priv->type_mapping, 0xff, > + sizeof(int) * pev->ntevs); > + We can change 0xff to -1 like previous patches. Will do it by resending. Thank you. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/