From patchwork Mon Oct 12 09:02:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kaixu Xia X-Patchwork-Id: 54749 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by patches.linaro.org (Postfix) with ESMTPS id 67C5E23001 for ; Mon, 12 Oct 2015 09:03:28 +0000 (UTC) Received: by wibzt1 with SMTP id zt1sf11951968wib.0 for ; Mon, 12 Oct 2015 02:03:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-type:sender:precedence :list-id:x-original-sender:x-original-authentication-results :mailing-list:list-post:list-help:list-archive:list-unsubscribe; bh=k5JZ8f7T7njX7801eoSniZaqG1iMj90qCnvTYdcxFPg=; b=EX0F/DQ5k9uAA6275o++TYeaD3qzZcVW6KCX1db8I5mCp8thTIiApGwSUsNL/fIFEX T+BGgP/IMZzQ5rKcvAGpXwUO3S+1GRMRhh6W0spnT86pXjHsx6Arla/UUm4o9JwBFvW7 88PJZGgStYWir8qSE2sq4rgrTJeQ+6KqeAItt3ET8f2GIImynQ9zNDw6IMS10zIOF6/k lq87Ydo3yaeLd17oyXFfx1EdEQHHkt+jTlWORBVOSTmpYSEUG40KzyetPm9iXybTCTz/ ED/5x4VGc86Sf6J4zcWZfjb+qmWZL6c1BXN9TblGVGR97L05n6vAZvpL0mamTdLJ+GSI S+Dw== X-Gm-Message-State: ALoCoQng60YzHFHtdREg/UN0c5uCCCrTIAuJcp6+EQNeqA8wlal3jjHt6Owu++BlTYuyeTnxiAgi X-Received: by 10.180.10.202 with SMTP id k10mr2598229wib.2.1444640607733; Mon, 12 Oct 2015 02:03:27 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.15.147 with SMTP id 19ls49629lfp.5.gmail; Mon, 12 Oct 2015 02:03:27 -0700 (PDT) X-Received: by 10.112.135.136 with SMTP id ps8mr11771507lbb.38.1444640607548; Mon, 12 Oct 2015 02:03:27 -0700 (PDT) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com. [209.85.217.169]) by mx.google.com with ESMTPS id vn6si10502138lbb.74.2015.10.12.02.03.27 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Oct 2015 02:03:27 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) client-ip=209.85.217.169; Received: by lbbk10 with SMTP id k10so23994575lbb.0 for ; Mon, 12 Oct 2015 02:03:27 -0700 (PDT) X-Received: by 10.112.64.72 with SMTP id m8mr11570655lbs.41.1444640607330; Mon, 12 Oct 2015 02:03:27 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp1430542lbq; Mon, 12 Oct 2015 02:03:26 -0700 (PDT) X-Received: by 10.107.137.144 with SMTP id t16mr26914171ioi.102.1444640606267; Mon, 12 Oct 2015 02:03:26 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l17si11140629ioe.73.2015.10.12.02.03.25; Mon, 12 Oct 2015 02:03:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752048AbbJLJDR (ORCPT + 30 others); Mon, 12 Oct 2015 05:03:17 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:15526 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751346AbbJLJDO (ORCPT ); Mon, 12 Oct 2015 05:03:14 -0400 Received: from 172.24.1.48 (EHLO szxeml422-hub.china.huawei.com) ([172.24.1.48]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id BOT26930; Mon, 12 Oct 2015 17:03:04 +0800 (CST) Received: from euler.hulk-profiling (10.107.193.250) by szxeml422-hub.china.huawei.com (10.82.67.152) with Microsoft SMTP Server id 14.3.235.1; Mon, 12 Oct 2015 17:02:49 +0800 From: Kaixu Xia To: , , , , , , , CC: , , , , , Subject: [RFC PATCH 1/2] perf: Add the flag sample_disable not to output data on samples Date: Mon, 12 Oct 2015 09:02:42 +0000 Message-ID: <1444640563-159175-2-git-send-email-xiakaixu@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1444640563-159175-1-git-send-email-xiakaixu@huawei.com> References: <1444640563-159175-1-git-send-email-xiakaixu@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.107.193.250] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020203.561B7749.00D2, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 788daf7ccdbb4800c79b962b8fc546a1 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: xiakaixu@huawei.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , In some scenarios we don't want to output trace data when sampling to reduce overhead. This patch adds the flag sample_disable to implement this function. By setting this flag and integrating with ebpf, we can control the data output process and get the samples we are most interested in. Signed-off-by: Kaixu Xia --- include/linux/bpf.h | 1 + include/linux/perf_event.h | 2 ++ kernel/bpf/arraymap.c | 5 +++++ kernel/events/core.c | 3 +++ 4 files changed, 11 insertions(+) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index f57d7fe..25e073d 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -39,6 +39,7 @@ struct bpf_map { u32 max_entries; const struct bpf_map_ops *ops; struct work_struct work; + atomic_t perf_sample_disable; }; struct bpf_map_type_list { diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 092a0e8..0606d1d 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -483,6 +483,8 @@ struct perf_event { perf_overflow_handler_t overflow_handler; void *overflow_handler_context; + atomic_t *sample_disable; + #ifdef CONFIG_EVENT_TRACING struct trace_event_call *tp_event; struct event_filter *filter; diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c index 29ace10..4ae82c9 100644 --- a/kernel/bpf/arraymap.c +++ b/kernel/bpf/arraymap.c @@ -51,6 +51,9 @@ static struct bpf_map *array_map_alloc(union bpf_attr *attr) array->elem_size = elem_size; + if (attr->map_type == BPF_MAP_TYPE_PERF_EVENT_ARRAY) + atomic_set(&array->map.perf_sample_disable, 1); + return &array->map; } @@ -298,6 +301,8 @@ static void *perf_event_fd_array_get_ptr(struct bpf_map *map, int fd) perf_event_release_kernel(event); return ERR_PTR(-EINVAL); } + + event->sample_disable = &map->perf_sample_disable; return event; } diff --git a/kernel/events/core.c b/kernel/events/core.c index b11756f..f6ef45c 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -6337,6 +6337,9 @@ static int __perf_event_overflow(struct perf_event *event, irq_work_queue(&event->pending); } + if ((event->sample_disable) && atomic_read(event->sample_disable)) + return ret; + if (event->overflow_handler) event->overflow_handler(event, data, regs); else