Received: by 10.192.165.148 with SMTP id m20csp574490imm; Fri, 4 May 2018 15:30:59 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq2ksISBXUQqYN5IxDWV/ue7YGYm8k0VBWdBjIEI4OQhBUjow0hUL8jEAhAb2kq/8ij2Ijb X-Received: by 10.98.144.86 with SMTP id a83mr18142709pfe.186.1525473059796; Fri, 04 May 2018 15:30:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525473059; cv=none; d=google.com; s=arc-20160816; b=NLHjMPPbawnihPslGXFsPsjKhY07Yx1sH6O/WMAzngq6dFVPRMGoo2vsx7tmrkRMIN UZdKu5zXVBHE8GhnZj7EX6XxnuHUY08Z7aNSug+xlAZ4pRGsE9yv5EWhNtkNN6cG5U36 C6h34T1cqdXieHzU5Agjc2Zfhy7+F2g7UYHFxA3MExx4JqxkrgFj4/IEIwhQB3tD0T+Y mCT/rTQZujrnVwy6zQNvKvJ61IFzRlSDtCsP4FuJkACy9cWouBmcAUNPc7J46uEem/Yd i/G7TQnLRf2B3MjGBUU24kxzag8zQvmFiLA1ha+I6u0hiyGGztqTL/nCxX5Trl7BQqyP Ha9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature:arc-authentication-results; bh=0vBqUQSr/XOgnplDVdwdJT37JcOP4vgjTIWsC8ChGU4=; b=v3DFDExrNAFPUa1tB7QBbvd99Z3v9NvmTk4TeIbep/sWVPfuvArsSp638h0myRPynf i7l+U/kXfqoldvZeexpYlXan5+er2zFmWFt3n+4sW8+g8pkTBnTAwL9OKg7hgI0s2Pnr kAL93gQDwqtyF3ubut1Tg/0DE5FTvdDj79KIG742KW/IgX9kIlutwQ+RaJJvDSNXdhiK /AV2QYGnialoNgB8rII/4UdFSGsbDvVYtubzGCN8CnBhuuR/LANfNopHXZRalRMJsioi PsN5BIIqHyMcz6mfn7EyZKMZy8NxRwqAZJNcHSRWpQwJPwCYdbryWbts72ZL5HyqSgnj VHrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@netronome-com.20150623.gappssmtp.com header.s=20150623 header.b=ibT3hUkr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v5si16238639pfe.63.2018.05.04.15.30.31; Fri, 04 May 2018 15:30:59 -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; Authentication-Results: mx.google.com; dkim=pass header.i=@netronome-com.20150623.gappssmtp.com header.s=20150623 header.b=ibT3hUkr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751789AbeEDW3D (ORCPT + 99 others); Fri, 4 May 2018 18:29:03 -0400 Received: from mail-qk0-f193.google.com ([209.85.220.193]:33918 "EHLO mail-qk0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751747AbeEDW3B (ORCPT ); Fri, 4 May 2018 18:29:01 -0400 Received: by mail-qk0-f193.google.com with SMTP id p186so17856175qkd.1 for ; Fri, 04 May 2018 15:29:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :organization:mime-version:content-transfer-encoding; bh=0vBqUQSr/XOgnplDVdwdJT37JcOP4vgjTIWsC8ChGU4=; b=ibT3hUkrbqnSImnv64CY8yAwlIpNkC02WfFGFUJo/dZJBEz62XEMPe7KfgsekJGLe3 bNPoX+SFEzyW5kfwSlH7a3LBxGLroZuuuySamSlmkxeCJxec2HXl/ktX9png1rkWuvsm 0wKHLKt03bJdL63cwDw8tLwPmLwTqeyzrm+tWGoXKIF452TRkbJHJS3he39F5vtXcZT1 JEd8JCBbXHy6Tmwyxkd3QFo8GyelLqStX8LpoflfI0t4Qa4Efx7K+3kCeGUIF4097lun TFQ/w3rZ6/sBJ8mT3MbMG60sS6Gs+bok2LstjhQx0CSqpYBkNXvhEs8O2/Ya49ly2Azn Esow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:organization:mime-version:content-transfer-encoding; bh=0vBqUQSr/XOgnplDVdwdJT37JcOP4vgjTIWsC8ChGU4=; b=EcsnmmmMmWHwL04ya07SzYxeUCfS/VPwyyCD5B1EG+QBm9btRNDVedrwCdH70JgIMu q98JsAb9m7S2vgMbbzyK5HBmxNR6B10WFB0JNSOM5D34APkn6UvkFTy3DR/59GyBaVku eS93ujTYUQbNAqQHg/PuzzCpyFvCdyLSwrsjdwSg76JdZFIEEJJVbfBzDm9CtoR9Rudr GTli15Qsqg/1Y9F5AsMYfe/HxJ/75dIqLJ9nQnPJcI5uIEzyrB8jTYgTkpIPd8Wi8Whg tWpb/OKSYhmaMI/wFiSb1FctLmoQ6mR+c8ztlzqjEihJpXDxp/OiEg5CZJfCN+/bN0f/ 2Q/A== X-Gm-Message-State: ALQs6tB8TLw+18XuOJJ2aRN7r7kln/SwY20FvZ3sYzRMR7DWYbAor6BO HsbUoo2OnJnpfX9I1W9mK11u6Q== X-Received: by 10.55.204.134 with SMTP id n6mr23798279qkl.429.1525472941025; Fri, 04 May 2018 15:29:01 -0700 (PDT) Received: from cakuba.netronome.com ([75.53.12.129]) by smtp.gmail.com with ESMTPSA id o17sm14472705qki.60.2018.05.04.15.28.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 May 2018 15:29:00 -0700 (PDT) Date: Fri, 4 May 2018 15:28:57 -0700 From: Jakub Kicinski To: Alexei Starovoitov Cc: daniel@iogearbox.net, oss-drivers@netronome.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim Subject: Re: [PATCH bpf-next 09/10] tools: bpftool: add simple perf event output reader Message-ID: <20180504152857.071870b2@cakuba.netronome.com> In-Reply-To: <20180504212501.hn2rnv7t3ik563mg@ast-mbp> References: <20180504013717.29317-1-jakub.kicinski@netronome.com> <20180504013717.29317-10-jakub.kicinski@netronome.com> <20180504212501.hn2rnv7t3ik563mg@ast-mbp> Organization: Netronome Systems, Ltd. MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org CC perf folks On Fri, 4 May 2018 14:25:03 -0700, Alexei Starovoitov wrote: > > +static void > > +perf_event_read(struct event_ring_info *ring, void **buf, size_t *buf_len) > > +{ > > + volatile struct perf_event_mmap_page *header = ring->mem; > > + __u64 buffer_size = MMAP_PAGE_CNT * get_page_size(); > > + __u64 data_tail = header->data_tail; > > + __u64 data_head = header->data_head; > > + void *base, *begin, *end; > > + > > + asm volatile("" ::: "memory"); /* in real code it should be smp_rmb() */ > > + if (data_head == data_tail) > > + return; > > this function was copied several times into different places. > I think it's time to put into common lib. Like libbpf. Agreed, I think libbpf would work, although there is nothing BPF specific in this loop AFAICT now. > Would be great if you can do it in the follow up. Looking into it now, I found these: $ git grep 'data_head == data_tail' tools/bpf/bpftool/map_perf_ring.c: if (data_head == data_tail) tools/testing/selftests/bpf/trace_helpers.c: if (data_head == data_tail) Are there any other copies I should try to cater to? I have change a few things compared to the selftest, I guess others may have modified their copy too. Just trying to make sure what we put in libbpf would cater to most possible use cases. Should I also move bpf_perf_event_open()/test_bpf_perf_event() to libbpf? > for the set: > Acked-by: Alexei Starovoitov Thanks!