From patchwork Fri Sep 1 16:53:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yonghong Song X-Patchwork-Id: 808823 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=fb.com header.i=@fb.com header.b="NT01hZOm"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xkQLf5vXGz9t2x for ; Sat, 2 Sep 2017 02:54:02 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752319AbdIAQyB (ORCPT ); Fri, 1 Sep 2017 12:54:01 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:60444 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752284AbdIAQx7 (ORCPT ); Fri, 1 Sep 2017 12:53:59 -0400 Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v81GrcV7014146 for ; Fri, 1 Sep 2017 09:53:58 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=facebook; bh=lxRgg/FIlbxt+ZAUeI3uijGHDu0DwvHg0Yv7EhxpWek=; b=NT01hZOmz0bwpttzDIw5PRm8vmuLqfbJ9yqIzVQ/Ps61IKIcSgvBe4WHidweMyyxYDyI mhP4RtRuvJS1t7HdLrGrv10knRHaUkXVx9A3lLNvvT7eU/7eX44oUBmwLwhNpVDgDfg0 FOF2jMtylh61n8hohemfpoz6sXgR1akluOM= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2cq7xp945j-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Fri, 01 Sep 2017 09:53:58 -0700 Received: from mx-out.facebook.com (192.168.52.123) by PRN-CHUB12.TheFacebook.com (192.168.16.22) with Microsoft SMTP Server id 14.3.319.2; Fri, 1 Sep 2017 09:53:58 -0700 X-ThriftRelayHost: devbig474.prn1.facebook.com Received: by devbig474.prn1.facebook.com (Postfix, from userid 128203) id C048E46E035D; Fri, 1 Sep 2017 09:53:57 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Yonghong Song Smtp-Origin-Hostname: devbig474.prn1.facebook.com To: , , , , CC: Smtp-Origin-Cluster: prn1c29 Subject: [PATCH net-next 0/4] bpf: add two helpers to read perf event enabled/running time Date: Fri, 1 Sep 2017 09:53:53 -0700 Message-ID: <20170901165357.465121-1-yhs@fb.com> X-Mailer: git-send-email 2.9.5 X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-09-01_04:, , signatures=0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Hardware pmu counters are limited resources. When there are more pmu based perf events opened than available counters, kernel will multiplex these events so each event gets certain percentage (but not 100%) of the pmu time. In case that multiplexing happens, the number of samples or counter value will not reflect the case compared to no multiplexing. This makes comparison between different runs difficult. Typically, the number of samples or counter value should be normalized before comparing to other experiments. The typical normalization is done like: normalized_num_samples = num_samples * time_enabled / time_running normalized_counter_value = counter_value * time_enabled / time_running where time_enabled is the time enabled for event and time_running is the time running for event since last normalization. This patch set implements two helper functions. The helper bpf_perf_read_counter_time reads counter/time_enabled/time_running for perf event array map. The helper bpf_perf_prog_read_time read time_enabled/time_running for bpf prog with type BPF_PROG_TYPE_PERF_EVENT. Yonghong Song (4): bpf: add helper bpf_perf_read_counter_time for perf event array map bpf: add a test case for helper bpf_perf_read_counter_time bpf: add helper bpf_perf_prog_read_time bpf: add a test case for helper bpf_perf_prog_read_time include/linux/perf_event.h | 3 ++ include/uapi/linux/bpf.h | 29 +++++++++++- kernel/bpf/verifier.c | 4 +- kernel/events/core.c | 3 +- kernel/trace/bpf_trace.c | 73 +++++++++++++++++++++++++++++-- samples/bpf/trace_event_kern.c | 5 +++ samples/bpf/tracex6_kern.c | 26 +++++++++++ samples/bpf/tracex6_user.c | 13 +++++- tools/testing/selftests/bpf/bpf_helpers.h | 7 +++ 9 files changed, 155 insertions(+), 8 deletions(-)