Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754027AbbGBSCn (ORCPT ); Thu, 2 Jul 2015 14:02:43 -0400 Received: from mail-pa0-f49.google.com ([209.85.220.49]:33270 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753543AbbGBSCa (ORCPT ); Thu, 2 Jul 2015 14:02:30 -0400 Message-ID: <55957CB4.3010803@plumgrid.com> Date: Thu, 02 Jul 2015 11:02:28 -0700 From: Alexei Starovoitov User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: "Wangnan (F)" , He Kuang , rostedt@goodmis.org, masami.hiramatsu.pt@hitachi.com, mingo@redhat.com, acme@redhat.com, a.p.zijlstra@chello.nl, jolsa@kernel.org, namhyung@kernel.org CC: linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 1/5] bpf: Put perf_events check ahead of bpf prog References: <1435719455-91155-1-git-send-email-hekuang@huawei.com> <1435719455-91155-2-git-send-email-hekuang@huawei.com> <5594B50A.3010705@plumgrid.com> <5594D1AA.9040803@huawei.com> In-Reply-To: <5594D1AA.9040803@huawei.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1167 Lines: 24 On 7/1/15 10:52 PM, Wangnan (F) wrote: > I'd like to discuss with you about the correctness of our > understanding. Do you have any strong reason to put BPF filters at such > an early stage? the obvious reason is performance. It is so much faster to run generated 'if (bpf_get_current_pid() != expected_pid) return' instead of going through __get_data_size, perf_trace_buf_prepare, store_trace_args, perf_trace_buf_submit->perf_tp_event_match->filter_match_preds. bpf is the fastest way to filter out things, so it should be first. I would argue that even for regular samples (cycle counts and so on), we should be using this tiny bpf prog to filter by pid. It's around 5 or so instructions that perf can always use instead of doing 'common_pid != expected_pid' > filter. Disturbance to the whole kernel will be much lower. Obviously there are no hooks for bpf programs in regular samples, but I think it's worth doing. -- 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/