Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp177921imj; Fri, 15 Feb 2019 21:03:07 -0800 (PST) X-Google-Smtp-Source: AHgI3IbmUaB8ZbMtf7w55OfcfDNTS8RKqEy4N1CbDP8ipk5cMFCXOIBa0OTYQF/aWP3DlMNO6skK X-Received: by 2002:a63:5343:: with SMTP id t3mr8585075pgl.415.1550293387354; Fri, 15 Feb 2019 21:03:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550293387; cv=none; d=google.com; s=arc-20160816; b=yCA4+PZRfY9mpNM6THN0yV3H2Vd7ljBeQexm0V9NQCPgWZz3/FC8CA9aQ5AipX3rta BEdDYpwS+qbQeW1tCNglLsk/zjZkmQPNGn0BUD3Nmvjm/+8FptG4rFxwPvfQ69uavaXs w3Tkrl5wv1pJn0rg97Zu4H1Xqfw5hnWvg9Uld9lxOAPyY/mJmiASs2bErf8Loof8QMpB YrDqXKxwA8AVuOuXjxWNud0+4ZsGoEsOBXnX+6GNqO925c4y6KzZUxnZbgwstl9eAd7w RiHznL9RBbQqBuVJnWJDIZszx6ywAluMbSYyonU1iky3i7BTphjDc1fv7BGmZFZoKttR VBdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=xfx+LJ3Z0e8hufOtlFRlTSU7bB+k0mlrJgHWe4Q5AyM=; b=kHx7wuNhKWABU4d29s5XidNP5A4Gnrayy1lgoPVEvo74qRszRbB/85xEDuaILwbM+7 +fWjo0GCsIwP32FtJ8SvjMk6NBpVSFrANTQ21tno4RVwxXo2go0D+HRg+YjIVWySp0+E Yu0FXe9xkJGOFzncJVQl4D4uzbzFc7wwJ27+HNsJg/c0uVMQzVjGW76o2W0sVu4oA2S6 7QxwgudEZWuobzo5LHiBmXDRcwg0I4AoIGyGnSmIYAr/GR7mG+F3IBnyv6tDFnE7l9q5 tFdAM+vfMBeHPbSrtc+b3v6hZiGvkk/JYhdsjp2s6jDrd5z7Y6VAAn4dQp2ss7hmh9Fr TWnA== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d17si6627061pgp.274.2019.02.15.21.02.51; Fri, 15 Feb 2019 21:03:07 -0800 (PST) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388398AbfBOSJW (ORCPT + 99 others); Fri, 15 Feb 2019 13:09:22 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33116 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387853AbfBOSJW (ORCPT ); Fri, 15 Feb 2019 13:09:22 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8B0DD1219DB; Fri, 15 Feb 2019 18:09:21 +0000 (UTC) Received: from sandy.ghostprotocols.net (ovpn-112-20.phx2.redhat.com [10.3.112.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 795395D6A9; Fri, 15 Feb 2019 18:09:20 +0000 (UTC) Received: by sandy.ghostprotocols.net (Postfix, from userid 1000) id 8E65555CD; Fri, 15 Feb 2019 16:09:16 -0200 (BRST) Date: Fri, 15 Feb 2019 16:09:16 -0200 From: Arnaldo Carvalho de Melo To: Song Liu Cc: Netdev , linux-kernel , "ast@kernel.org" , "daniel@iogearbox.net" , Kernel Team , "peterz@infradead.org" , "jolsa@kernel.org" , "namhyung@kernel.org" Subject: Re: [PATCH v2 perf,bpf 11/11] perf, bpf: save information about short living bpf programs Message-ID: <20190215180916.GJ5784@redhat.com> References: <20190214235624.2579307-1-songliubraving@fb.com> <20190215000045.2592135-1-songliubraving@fb.com> <20190215000045.2592135-2-songliubraving@fb.com> <20190215144146.GF5784@redhat.com> <62DB92A4-F708-4E89-B668-4EAFD0FA6731@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <62DB92A4-F708-4E89-B668-4EAFD0FA6731@fb.com> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.5.20 (2009-12-10) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 15 Feb 2019 18:09:21 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Fri, Feb 15, 2019 at 05:13:01PM +0000, Song Liu escreveu: > > On Feb 15, 2019, at 6:41 AM, Arnaldo Carvalho de Melo wrote: > > Em Thu, Feb 14, 2019 at 04:00:45PM -0800, Song Liu escreveu: > >> +pthread_t poll_thread; > >> + > >> +int bpf_event__start_polling_thread(struct bpf_event_poll_args *args) > >> +{ > >> + struct perf_evsel *counter; > >> + > >> + args->evlist = perf_evlist__new(); > >> + > >> + if (args->evlist == NULL) > >> + return -1; > >> + > >> + if (perf_evlist__create_maps(args->evlist, args->target)) > > goto out_delete_evlist; > >> + > >> + if (perf_evlist__add_bpf_tracker(args->evlist)) > > goto out_delete_evlist; > >> + > >> + evlist__for_each_entry(args->evlist, counter) { > >> + if (perf_evsel__open(counter, args->evlist->cpus, > >> + args->evlist->threads) < 0) > > goto out_delete_evlist; > >> + } > >> + > >> + if (perf_evlist__mmap(args->evlist, UINT_MAX)) > > goto out_delete_evlist; > >> + > >> + evlist__for_each_entry(args->evlist, counter) { > >> + if (perf_evsel__enable(counter)) > > goto out_delete_evlist; > >> + } > >> + > >> + if (pthread_create(&poll_thread, NULL, bpf_poll_thread, args)) > > goto out_delete_evlist; > >> + > >> + return 0; > > out_delete_evlist: > > perf_evlist__delete(args->evlist); > > args->evlist = NULL; Have you seen the error handling suggestion above? > >> +int perf_evlist__add_bpf_tracker(struct perf_evlist *evlist) > >> +{ > >> + struct perf_event_attr attr = { > >> + .type = PERF_TYPE_SOFTWARE, > >> + .config = PERF_COUNT_SW_DUMMY, > >> + .watermark = 1, > >> + .bpf_event = 1, > >> + .wakeup_watermark = 1, > >> + .size = sizeof(attr), /* to capture ABI version */ > >> + }; > >> + struct perf_evsel *evsel = perf_evsel__new_idx(&attr, > >> + evlist->nr_entries); > >> + > >> + if (evsel == NULL) > >> + return -ENOMEM; > >> + > >> + perf_evlist__add(evlist, evsel); > > You could use: > > struct perf_evlist *evlist = perf_evlist__new_dummy(); > > if (evlist != NULL) { > > struct perf_evsel *evsel == perf_evlist__first(evlist); > > evsel->attr.bpf_event = evsel->attr.watermark = evsel->attr.wakeup_watermark = 1; > > return 0; > > } > > return -1; > This looks cleaner. Let me fix in next version. > > Because in this case all you'll have in this evlist is the bpf tracker, > > right? The add_bpf_tracker would be handy if we would want to have a > > pre-existing evlist with some other events and wanted to add a bpf > > tracker, no? > I think all we need is a side-band evlist instead of the main evlist. May > be we should call it side-band evlist, and make it more generic? Sure, you could for instance have something like: struct perf_event_attr attr = { .watermark = 1, .bpf_event = 1, .wakeup_watermark = 1, } struct perf_evlist *evlist = perf_evlist__new_side_band(&attr); And the other details will be set by it, i.e. the .config .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_DUMMY, .size = sizeof(attr), /* to capture ABI version */ And the idx arg. - Arnaldo