From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1137C2F530E; Fri, 14 Nov 2025 07:00:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763103623; cv=none; b=dUFXyE+akqshF9T0jG2u06we8pNrx65MeIUz8EepaXTEh0Ai44FZD+T4YtS6bdw7ySvq4HTJuumM1DKCnpDR+K/jZjWBn2BOFYjqDFB4zR/HcvSemuzMC8966J7Y5WVlm4aTQSQ65uqupuMYYnGJXP0cuYP28yD+MxS2k+Cxaas= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763103623; c=relaxed/simple; bh=UOiCoeF48H4T7ORW4hNVtpfRxJwQznQgrihtEbItWqY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jDULy7OuDw2XVMhE0w462O5o4yHTCh5h2jgVU4WwI6uIPN/6I1n1X+Mzg2ugQOuTri/2xGlUq9jIo6pHnKcJrWGM0quEfdPKF3yJyHTLZrZy4/anaUCAL64ZA1lG/h6hjp3rHjKXTXAK3NXyqE+hB5fqlS5WZO5o1Z8Im9C2vOM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=K86TRe9L; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="K86TRe9L" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 079A3C4AF15; Fri, 14 Nov 2025 07:00:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1763103622; bh=UOiCoeF48H4T7ORW4hNVtpfRxJwQznQgrihtEbItWqY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K86TRe9L5Bkh3UFkXl8muPY3C8myFbxI/zim8SAM45+5EUnrt3Fk2jzboZRDgtNDj pKQccZBjldheJXelosyE53pKwf4aS/k7agjUPRDOkHZYsSvKf3s6U7P94Gr8zfyAcN 113Ede9xallgO97sGd8NVRO9KnRagB2h3fPPhh3O5V6o1r7nuN5f1ITDa/OIsh6nja tV6hfzeYuApxZKkaTJbuwC17mY0D4cumAg/Pol3k9tBz+ZUCHyPD/SFIfAAPQeXW63 hyoj5ChU/5Nro5uMQcy8x9fjgEjshtPjhzxgTklfDkBRg0teS9OiNf/e7jGRTRY8xC sWXXd0n0z+eqw== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , James Clark Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Steven Rostedt , Josh Poimboeuf , Indu Bhagat , Jens Remus , Mathieu Desnoyers , linux-trace-kernel@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH v3 3/5] perf record: Enable defer_callchain for user callchains Date: Thu, 13 Nov 2025 23:00:16 -0800 Message-ID: <20251114070018.160330-4-namhyung@kernel.org> X-Mailer: git-send-email 2.52.0.rc1.455.g30608eb744-goog In-Reply-To: <20251114070018.160330-1-namhyung@kernel.org> References: <20251114070018.160330-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit And add the missing feature detection logic to clear the flag on old kernels. $ perf record -g -vv true ... ------------------------------------------------------------ perf_event_attr: type 0 (PERF_TYPE_HARDWARE) size 136 config 0 (PERF_COUNT_HW_CPU_CYCLES) { sample_period, sample_freq } 4000 sample_type IP|TID|TIME|CALLCHAIN|PERIOD read_format ID|LOST disabled 1 inherit 1 mmap 1 comm 1 freq 1 enable_on_exec 1 task 1 sample_id_all 1 mmap2 1 comm_exec 1 ksymbol 1 bpf_event 1 defer_callchain 1 defer_output 1 ------------------------------------------------------------ sys_perf_event_open: pid 162755 cpu 0 group_fd -1 flags 0x8 sys_perf_event_open failed, error -22 switching off deferred callchain support Signed-off-by: Namhyung Kim --- tools/perf/util/evsel.c | 24 ++++++++++++++++++++++++ tools/perf/util/evsel.h | 1 + 2 files changed, 25 insertions(+) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 244b3e44d090d413..f5652d00b457d096 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1061,6 +1061,14 @@ static void __evsel__config_callchain(struct evsel *evsel, struct record_opts *o } } + if (param->record_mode == CALLCHAIN_FP && !attr->exclude_callchain_user) { + /* + * Enable deferred callchains optimistically. It'll be switched + * off later if the kernel doesn't support it. + */ + attr->defer_callchain = 1; + } + if (function) { pr_info("Disabling user space callchains for function trace event.\n"); attr->exclude_callchain_user = 1; @@ -1511,6 +1519,7 @@ void evsel__config(struct evsel *evsel, struct record_opts *opts, attr->mmap2 = track && !perf_missing_features.mmap2; attr->comm = track; attr->build_id = track && opts->build_id; + attr->defer_output = track; /* * ksymbol is tracked separately with text poke because it needs to be @@ -2199,6 +2208,10 @@ static int __evsel__prepare_open(struct evsel *evsel, struct perf_cpu_map *cpus, static void evsel__disable_missing_features(struct evsel *evsel) { + if (perf_missing_features.defer_callchain && evsel->core.attr.defer_callchain) + evsel->core.attr.defer_callchain = 0; + if (perf_missing_features.defer_callchain && evsel->core.attr.defer_output) + evsel->core.attr.defer_output = 0; if (perf_missing_features.inherit_sample_read && evsel->core.attr.inherit && (evsel->core.attr.sample_type & PERF_SAMPLE_READ)) evsel->core.attr.inherit = 0; @@ -2473,6 +2486,13 @@ static bool evsel__detect_missing_features(struct evsel *evsel, struct perf_cpu /* Please add new feature detection here. */ + attr.defer_callchain = true; + if (has_attr_feature(&attr, /*flags=*/0)) + goto found; + perf_missing_features.defer_callchain = true; + pr_debug2("switching off deferred callchain support\n"); + attr.defer_callchain = false; + attr.inherit = true; attr.sample_type = PERF_SAMPLE_READ | PERF_SAMPLE_TID; if (has_attr_feature(&attr, /*flags=*/0)) @@ -2584,6 +2604,10 @@ static bool evsel__detect_missing_features(struct evsel *evsel, struct perf_cpu errno = old_errno; check: + if ((evsel->core.attr.defer_callchain || evsel->core.attr.defer_output) && + perf_missing_features.defer_callchain) + return true; + if (evsel->core.attr.inherit && (evsel->core.attr.sample_type & PERF_SAMPLE_READ) && perf_missing_features.inherit_sample_read) diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 3ae4ac8f9a37e009..a08130ff2e47a887 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -221,6 +221,7 @@ struct perf_missing_features { bool branch_counters; bool aux_action; bool inherit_sample_read; + bool defer_callchain; }; extern struct perf_missing_features perf_missing_features; -- 2.52.0.rc1.455.g30608eb744-goog