Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1412394ybe; Fri, 13 Sep 2019 16:35:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqx7gZ5J2TrvanukAlzmZI8NHZyBNvRPBOkuVYn8nd3YBHTTTtsaHS9Bwwm1QGfJ5P2/pOqW X-Received: by 2002:a17:906:414:: with SMTP id d20mr41896827eja.165.1568417721242; Fri, 13 Sep 2019 16:35:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568417721; cv=none; d=google.com; s=arc-20160816; b=HXMZV/Zp78/Ke9RGXYDNVpzSEVcBpVgG1j4OVkg82Ql54v+PpnHfV7dLIlwtT3QYQC oHIfjQMLn4HpR4D/0dvVtY3+Uk1NCECRLrIyp1YmuP4chYXvbACaxH0hTeRZ9jTab0qj qzo7Pz6rP70uH3D00T8i//J0mLIYOoxK3nI69+fJS+l5cwQYdl01x1JYXqx4omkAHqGE 8qSSLCelO/mYfckwZep/FBUP0+6xBYGjfkVS2WQc9Dat9s8TaYGc1fuKAs9NPERry5Fr stLEHXnLXJouEb/GFLmpdv549CIQW2O9jwqIK1RSwanptzVeHxGWD2ZOy9Fy9bzSF6RG 7JgQ== 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=YvFWWmAaW92RrSUcs/02OW5rRFchhEMc7PsrIxt+trU=; b=k7UkrVX8NI9qsG3BGtXpQrBtDWcvFEZADNf0pv14YOpcXzETtpRK4DjB7+tSXdVayA XQvWn9GnkE/6yVj+xqwJ2Yj0toYV66xMWwhSc9qzQu/1ZMXfshP3raxtYzH8BLaoJ3rO ErItMCw9FOy5LLCUWyJZ10qcTb0WYgjH8zKtT5OiHZntJ/dQPustK3NjrlOuVlXFqJV0 Mny0OxQ4h5wNWs5naW9a3SohGz5DeBzj36kZC/o5KWOjLRse2l/a3kGEYv1P7kqDn4Bn QIrYYUuI3QuLMkzIU5n0NOCQVh1fYQSrk7WogdBFiDtMjlxEApu89fAIfM7Ylgu8vL4z CjUQ== 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 f47si18028376ede.263.2019.09.13.16.34.58; Fri, 13 Sep 2019 16:35:21 -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 S2390580AbfIMN1Y (ORCPT + 99 others); Fri, 13 Sep 2019 09:27:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42794 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403816AbfIMN0b (ORCPT ); Fri, 13 Sep 2019 09:26:31 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 860798665A; Fri, 13 Sep 2019 13:26:31 +0000 (UTC) Received: from krava.brq.redhat.com (unknown [10.43.17.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id DC0A25C1D4; Fri, 13 Sep 2019 13:26:29 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Michael Petlan Subject: [PATCH 63/73] libperf: Add perf_evlist__purge function Date: Fri, 13 Sep 2019 15:23:45 +0200 Message-Id: <20190913132355.21634-64-jolsa@kernel.org> In-Reply-To: <20190913132355.21634-1-jolsa@kernel.org> References: <20190913132355.21634-1-jolsa@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 13 Sep 2019 13:26:31 +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 b9dd040a6162..1c8a9e283adc 100644 --- a/tools/perf/lib/evlist.c +++ b/tools/perf/lib/evlist.c @@ -107,6 +107,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); @@ -120,6 +132,7 @@ void perf_evlist__exit(struct perf_evlist *evlist) void perf_evlist__delete(struct perf_evlist *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 1ca822eeab1d..a5bf13df08dc 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