Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4259491ybp; Mon, 7 Oct 2019 05:56:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqxPEwabT6z86g4gQy7F8/M9ovd2nw+0/nLOzWT+BctcxCo7i+2e7ssCnt7mVI/khirPrJy2 X-Received: by 2002:a17:906:f19a:: with SMTP id gs26mr23373097ejb.298.1570452961506; Mon, 07 Oct 2019 05:56:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570452961; cv=none; d=google.com; s=arc-20160816; b=zePfJnyYKI4nJfp/PXrJFkI5dulBG+hKkqnvJbH2np0l8UGIqt5p40+L0sC2mUEFwF UMlsnQFDJVxWj28SJHuKxlufdwhH64QqMwLh5+r9yvrEtCL7UVvzEUp68+crj94lVrzb 1C14REq+9n1cHQRE78Jim8X1LfGJfOXuX2gvL2+7gJEq62uiYvCbzoKjO+t6LxzRjnUt a0wLetvn8m4rWQ6dV2+/Oc0cG2vw3Oaozw0DU2Xr7dpUkHxbJGuQ9gtkB/D5a6E1QkBP kmLB9T51N/IrxqkbZKu9alGSvT3d/dLjHCn5YrnLp49coQ5zRHGWbPc407OysQsqkeP2 buPw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=i80fnOdBPjOTjS7d/9puP1DLY/k5T4kNiFufG5KxMSM=; b=aMWBP4/BYgosgGxq6UUVtySaVSQFLkEz9jE2EKYeh+0vEI5uEQVI/YmTzTXPBqbcG5 BgFbGdGr0EL5BdtJjkrDM7sviClRzg4kRYZv62yn9D+fkmQ+JbEQXql5cGdfHQBPV3Tj jXX0+WqXsNsEHNV+TpbyYWfCszyYysswXM/hCvVCeeOXaPt3T9ezQBlNBVORRlTlxufN Y2ro6TFhzRbywZ2KyCHZRrCx/q6sIlt4rtxlT3TatIf/LpxU33dOw6EchxIZ5WLkoK0s v2SG0aFbF00M/53bw3QT0C7dbZ+LDOKgI5fou5n6dD6u9TW0RM41zz89EUMghDA+J3Sj uujA== 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b3si9040628ede.118.2019.10.07.05.55.37; Mon, 07 Oct 2019 05:56:01 -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; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728404AbfJGMyr (ORCPT + 99 others); Mon, 7 Oct 2019 08:54:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34098 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728372AbfJGMyq (ORCPT ); Mon, 7 Oct 2019 08:54:46 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 530BC10CC1E0; Mon, 7 Oct 2019 12:54:46 +0000 (UTC) Received: from krava.brq.redhat.com (unknown [10.43.17.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF5455D9CC; Mon, 7 Oct 2019 12:54:43 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Michael Petlan Subject: [PATCH 25/36] libperf: Add perf_evlist__purge function Date: Mon, 7 Oct 2019 14:53:33 +0200 Message-Id: <20191007125344.14268-26-jolsa@kernel.org> In-Reply-To: <20191007125344.14268-1-jolsa@kernel.org> References: <20191007125344.14268-1-jolsa@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.65]); Mon, 07 Oct 2019 12:54:46 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adding static perf_evlist__purge function to purge and delete evsels from evlist. Adding also perf_evlist__for_each_entry_safe which is used by perf_evlist__purge. Link: http://lkml.kernel.org/n/tip-xcwsmyqcxe8zgbpapn27f8n9@git.kernel.org Signed-off-by: Jiri Olsa --- tools/perf/lib/evlist.c | 13 +++++++++++++ tools/perf/lib/include/internal/evlist.h | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c index 7ba98f0e6365..9534ad9a572f 100644 --- a/tools/perf/lib/evlist.c +++ b/tools/perf/lib/evlist.c @@ -109,6 +109,18 @@ perf_evlist__next(struct perf_evlist *evlist, struct perf_evsel *prev) return next; } +static void perf_evlist__purge(struct perf_evlist *evlist) +{ + struct perf_evsel *pos, *n; + + perf_evlist__for_each_entry_safe(evlist, n, pos) { + list_del_init(&pos->node); + perf_evsel__delete(pos); + } + + evlist->nr_entries = 0; +} + void perf_evlist__exit(struct perf_evlist *evlist) { perf_cpu_map__put(evlist->cpus); @@ -125,6 +137,7 @@ void perf_evlist__delete(struct perf_evlist *evlist) perf_evlist__munmap(evlist); perf_evlist__close(evlist); + perf_evlist__purge(evlist); perf_evlist__exit(evlist); free(evlist); } diff --git a/tools/perf/lib/include/internal/evlist.h b/tools/perf/lib/include/internal/evlist.h index 0721512ffb19..be0b25a70730 100644 --- a/tools/perf/lib/include/internal/evlist.h +++ b/tools/perf/lib/include/internal/evlist.h @@ -82,6 +82,24 @@ void perf_evlist__exit(struct perf_evlist *evlist); #define perf_evlist__for_each_entry_reverse(evlist, evsel) \ __perf_evlist__for_each_entry_reverse(&(evlist)->entries, evsel) +/** + * __perf_evlist__for_each_entry_safe - safely iterate thru all the evsels + * @list: list_head instance to iterate + * @tmp: struct evsel temp iterator + * @evsel: struct evsel iterator + */ +#define __perf_evlist__for_each_entry_safe(list, tmp, evsel) \ + list_for_each_entry_safe(evsel, tmp, list, node) + +/** + * perf_evlist__for_each_entry_safe - safely iterate thru all the evsels + * @evlist: evlist instance to iterate + * @evsel: struct evsel iterator + * @tmp: struct evsel temp iterator + */ +#define perf_evlist__for_each_entry_safe(evlist, tmp, evsel) \ + __perf_evlist__for_each_entry_safe(&(evlist)->entries, tmp, evsel) + static inline struct perf_evsel *perf_evlist__first(struct perf_evlist *evlist) { return list_entry(evlist->entries.next, struct perf_evsel, node); -- 2.21.0