From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f202.google.com (mail-dy1-f202.google.com [74.125.82.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B2D91480971 for ; Fri, 5 Jun 2026 07:40:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780645249; cv=none; b=p+vo05zMccVhmU+hbayfv43Jd4QWHHmNXWLjH0LlJS90k2eHEwR+qxIsBql6A+08vx0J41oPzVUldoOJjKYsooGUPo9o6z01qyhyXl9g/OqTGYBdDFnXfOZ3o5vki+9gJeWoV2DINpKB/RtZgnb3/DekKewFtRDH/KyFc2WYcd8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780645249; c=relaxed/simple; bh=xmtIENNajy6s2avADkic3uk2mTmWfZy7KD5pWYP2COk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=T2XvYNr2dS4C1YfL3+Ubvo1TlSvB9tE0QbIctbQZ8CjCIg4e3YPC8kAaLSdhDQHnnapY9Si7oBAfn82XOyqDDOeGcVhG/tRwwDYZSDLVvGZpzd8jz2lkoX9CUzRyxcv3Q8AQCVQzDIMht68xmeAP74EuobhPtOmjO5JlfxNec0A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=oqmn8OKv; arc=none smtp.client-ip=74.125.82.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="oqmn8OKv" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-304e7fc90b1so1450507eec.1 for ; Fri, 05 Jun 2026 00:40:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780645247; x=1781250047; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=X9w81A1e/wdJiOZvP0teOaZnpSggvivJtvNKbzR4KV0=; b=oqmn8OKvcPrQuoOGBQmJmm+14SOv4TdoOqt1PHHwThrTdrRQP7a/Zlj6+SOX9Isybp 1TBcMg3pWnpZl2Z0AH+2vyH3xWY1ZfR41nninrqUHRUdvo6UyVynSK2e+YUhgHE7wUJc er0WeTveDv6MFWnyUEjLO9h8fmel2+zzHIOkuuuhIuqBlj/FYAOU9E2a9I1uOQkro4z9 hS6vbWtSbB3lvYIECet0CHoXfyyo56YnJ/jpKqqv/k8skqC2QBDHTWoVbBy83Qy+UGQR MlT8lAKw16YKWv6LMs5gVVPFd/eEBWCTXF+dwV7Q41v1rSZmH0L1Ea6j9nNesUkAVp9J r3Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780645247; x=1781250047; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=X9w81A1e/wdJiOZvP0teOaZnpSggvivJtvNKbzR4KV0=; b=of1Apyf95HR8urOPvCTeN5CtrVmFvY2hLJHR98R/5mspE5fE6Nh1OALHVjskOWzsoB tyIpkAt7RzBvrAAjnUvZ04DnkAyawm/d7gjfz+RC3kB1I+1rZ9lGth6hjw5639XEuajj k+wMN/xPW0yWKvhhHsTJZP7COquWgxWXot/HBF0cWi3Vt2/VBmlJyR7CZ9brZ8g1fZxZ Sp3pgOfswZeXStLT5IGhHCmeXlFdAFPG2gymiia3qfYb0lvfiqO7tK9GK3SJYi5v07TS HD2FLJy8GFxFCr43bh81YzFIzXTcR8AT/9K7UqS2iKa7W+Zj0Mgjqp3kQUWCLRrh4hGJ 3mhQ== X-Forwarded-Encrypted: i=1; AFNElJ9fm7unUXgyTKUurF+ublhuYWZfG6xYREhNjgLBCVLdikecjlOeA5JBmNc2Zx4gtlWXPgG/yVJpYwTxZrXbfWRH@vger.kernel.org X-Gm-Message-State: AOJu0Yyc9FRmuR+1OlLgXb96Aj56IV/V9/5HtweYvKiXghM75iyYh+EQ arWGcCtndCTq+m2iPaFzvjL2WB0b1zz+vHOPQ84AhEQc9MgHHdxGQ6/jaRzaNiIGZOah9rfECVn cvDzHl+WOBA== X-Received: from dybpj5.prod.google.com ([2002:a05:7301:4245:b0:304:e192:a836]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:72c9:b0:2ed:935:aa33 with SMTP id 5a478bee46e88-3077af330fdmr1183020eec.5.1780645246678; Fri, 05 Jun 2026 00:40:46 -0700 (PDT) Date: Fri, 5 Jun 2026 00:39:52 -0700 In-Reply-To: <20260605074003.1730715-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260522220435.2378363-1-irogers@google.com> <20260605074003.1730715-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.1032.g2f8565e1d1-goog Message-ID: <20260605074003.1730715-9-irogers@google.com> Subject: [PATCH v10 08/19] perf python: Use evsel in sample in pyrf_event From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org Cc: adrian.hunter@intel.com, alice.mei.rogers@gmail.com, dapeng1.mi@linux.intel.com, james.clark@linaro.org, leo.yan@linux.dev, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, mingo@redhat.com, peterz@infradead.org, tmricht@linux.ibm.com Content-Type: text/plain; charset="UTF-8" Avoid a duplicated evsel by using the one in sample. Add evsel__get/put to the evsel in perf_sample. Signed-off-by: Ian Rogers --- tools/perf/util/evsel.c | 2 +- tools/perf/util/python.c | 10 +++------- tools/perf/util/sample.c | 17 ++++++++++++----- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index ba88c29ebe5c..d01c78da51e2 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -3365,7 +3365,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, union u64_swap u; perf_sample__init(data, /*all=*/true); - data->evsel = evsel; + data->evsel = evsel__get(evsel); data->cpu = data->pid = data->tid = -1; data->stream_id = data->id = data->time = -1ULL; data->period = evsel->core.attr.sample_period; diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index efe8c3b898ea..8b922d3013f2 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -63,7 +63,6 @@ PyMODINIT_FUNC PyInit_perf(void); struct pyrf_event { PyObject_HEAD - struct evsel *evsel; struct perf_sample sample; union perf_event event; }; @@ -294,7 +293,6 @@ static PyMemberDef pyrf_sample_event__members[] = { static void pyrf_sample_event__delete(struct pyrf_event *pevent) { - evsel__put(pevent->evsel); perf_sample__exit(&pevent->sample); Py_TYPE(pevent)->tp_free((PyObject*)pevent); } @@ -316,7 +314,7 @@ static PyObject *pyrf_sample_event__repr(const struct pyrf_event *pevent) #ifdef HAVE_LIBTRACEEVENT static bool is_tracepoint(const struct pyrf_event *pevent) { - return pevent->evsel->core.attr.type == PERF_TYPE_TRACEPOINT; + return pevent->sample.evsel->core.attr.type == PERF_TYPE_TRACEPOINT; } static PyObject* @@ -363,7 +361,7 @@ tracepoint_field(const struct pyrf_event *pe, struct tep_format_field *field) static PyObject* get_tracepoint_field(struct pyrf_event *pevent, PyObject *attr_name) { - struct evsel *evsel = pevent->evsel; + struct evsel *evsel = pevent->sample.evsel; struct tep_event *tp_format = evsel__tp_format(evsel); struct tep_format_field *field; @@ -529,7 +527,7 @@ static PyObject *pyrf_event__new(const union perf_event *event) pevent = PyObject_New(struct pyrf_event, ptype); if (pevent != NULL) { memcpy(&pevent->event, event, event->header.size); - pevent->evsel = NULL; + perf_sample__init(&pevent->sample, /*all=*/false); } return (PyObject *)pevent; } @@ -1899,8 +1897,6 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist, return Py_None; } - pevent->evsel = evsel__get(evsel); - perf_mmap__consume(&md->core); err = evsel__parse_sample(evsel, &pevent->event, &pevent->sample); diff --git a/tools/perf/util/sample.c b/tools/perf/util/sample.c index cf73329326d7..bccc19e2aaf2 100644 --- a/tools/perf/util/sample.c +++ b/tools/perf/util/sample.c @@ -1,18 +1,23 @@ /* SPDX-License-Identifier: GPL-2.0 */ #include "sample.h" + +#include +#include + +#include +#include + +#include "../../arch/x86/include/asm/insn.h" #include "debug.h" +#include "evsel.h" #include "thread.h" -#include + #ifndef EM_CSKY #define EM_CSKY 252 #endif #ifndef EM_LOONGARCH #define EM_LOONGARCH 258 #endif -#include -#include -#include -#include "../../arch/x86/include/asm/insn.h" void perf_sample__init(struct perf_sample *sample, bool all) { @@ -29,6 +34,8 @@ void perf_sample__init(struct perf_sample *sample, bool all) void perf_sample__exit(struct perf_sample *sample) { + evsel__put(sample->evsel); + sample->evsel = NULL; zfree(&sample->user_regs); zfree(&sample->intr_regs); if (sample->merged_callchain) { -- 2.54.0.1032.g2f8565e1d1-goog