Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp350148rdh; Tue, 13 Feb 2024 20:57:35 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWs+cnknG+YncGUpWVfunSWEdTh8lHjq8NIlJ7Ir3a5K6lbs+nn+6q4aMaayH3pg/BwjU+XRIUoosf3UIWFUUsRZIKZo/Tf44py77XkGA== X-Google-Smtp-Source: AGHT+IGMjDpdgBEITrEJP5dHOQTPAHQZ4iYw5MkHcVnnvCkh4FGJAIadzzCG+mT/0olSTspab9c8 X-Received: by 2002:a05:6871:5227:b0:219:3054:3ea5 with SMTP id ht39-20020a056871522700b0021930543ea5mr1681622oac.45.1707886655209; Tue, 13 Feb 2024 20:57:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707886655; cv=pass; d=google.com; s=arc-20160816; b=0Poopb41Jhfo3SCVAsRxA7NjKjyc+Ynm9V29gM/Wfta9Xp5V3RwGD/JR8oyjP50dEv Xs7m3LWRFBq0cFx2km7vGd4IAm+pxY4KOPGYb+YApXFhpgcqjreHm/XbRB8zI/aVEtP2 5guMFwjLj6OvoTqzORRIwLXY/RpJwZcdIBIFZgTDuPPi1KllSgsxco36JiNh8NIeLaAT NtjdTdqJNEG29o248rJl6SHJ+EI5e+zEeB/akquebuwb1yFLBde+vLRh+MV1eeugtdop wT5MyC7mfofqmQEwuGg7OfQtKFRap1oHp0fwcdSTePUaEa/Sose+vdkuSrRz83k4OhD6 Y+IQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:from:subject:references:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:in-reply-to:date :dkim-signature; bh=YmSZNQ356QtM9WesWCMinXmK9k2yULQ13GYKx7NLJhc=; fh=osyQkrHa66TcsYojIaUxUTAHE8ji2/slajK6ivRcNU4=; b=KlHnzPdXCIN7NsZf3ti/MYDWIbEscge2K2vs+e/kdzWH+I3kdhP+/FuMt2olRH01zX 4CBOoK95sTG4NnWLz/OC1eXndd6E4tIDMZG9mYV1QbnMeVjyu/kjygHKWviJyo0mWjf9 MovjJJYTry0grc+EqpduMN6V85AMRYUhdE00x/NbPUbM0xAS1DCgB/r2+sIRcFMDdIas Yzhxi7Tyh47/13F1BBtVr6krjx2qjMmj8YlCEsbGTyLMBFiD2/LlAYl4Yrn0cbvE7NnZ h0rAfQyr088cKo1lu5Nnd2cD9uZlWfF95KZAG9KKWSodZopQnX2bEbGlLaTp6zsuUX4b Hq2g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=1xGd8ewx; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-64738-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64738-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCWscZBpfFJ9wV80E7bolAx9VMLEr+Q7tqa/yvfi9IaVzCQByqIsbueuZehW7NCwIBbBvOyOLFhgqhTk6k9U4jUGJzKRheOF7hov2moyaQ== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id j186-20020a638bc3000000b005c220a94525si3182457pge.90.2024.02.13.20.57.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 20:57:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64738-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=1xGd8ewx; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-64738-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64738-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 9272028C2A8 for ; Wed, 14 Feb 2024 04:55:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 66ED9111A2; Wed, 14 Feb 2024 04:54:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="1xGd8ewx" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 F3DD210A25 for ; Wed, 14 Feb 2024 04:54:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707886478; cv=none; b=Bd1c4UUg3LZJmDYpDWECBoP/UFsBh2UnaL5lnxJOdghYbQpXw+BQwxSykvETl3Xlzum8MWp8/SuddrHzVTJ0tKinac38Yi8ICdJKgvBpyDcVl5gF+IPE70IdaMShtwMI+dciUL+RTcf/G3AmG63b4y+Rbs2KoZjohyRQcNhUM7M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707886478; c=relaxed/simple; bh=NhiwdSNsgGhanFThf3Y8+0MhiUWCknICtVTm6IyvRmw=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=TAaxskLtKMsEGgjIOXEIwKqsrSnWjPh/YbR8TP9B03LEGKsoIXQ+Ujg1Ly4wiRrhNqWa/XZYHZxSi2myjYg0cODWL3XTfm9abYYy9CAgRFnz0ovqT2Bae8GXu8mLY/NBYROBKxQN6CPNsONjKt/usKymneeJ7UaVI8nYZ0AWGjY= 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=1xGd8ewx; arc=none smtp.client-ip=209.85.128.201 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 Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6077e9dd249so25754347b3.3 for ; Tue, 13 Feb 2024 20:54:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707886476; x=1708491276; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=YmSZNQ356QtM9WesWCMinXmK9k2yULQ13GYKx7NLJhc=; b=1xGd8ewx+6QMWMCOnsEdqMLKF2N81vwpOJk7nUzwCgdEYXsLrTJ+FvcIBrAaaK0lR8 OdMY2SIRkPKDvbaN3kpV+gyiHeUQ3yRTZoz1mjG8gYUEJ17CBxBR9rVa0lrF7+uUqODs 62fDERGEZcArpHvYVrZLkGPkirMca7cqqdND83MY4HlQSdnKDWM66nzIBG5gGTuH1Fbz zrQoakOgLq3ugaAcRwzYXOfXAkTkzM1IfveEWAJkjZUx/XMnXjS+xUXFVy/EZTRV5Mpm m4n2rf6GgWIWvxIc4gY8sGqF30Bw/bt+//CYY9KPgYhwRkj5wF/ddt9cikvbcpISDtvA xpyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707886476; x=1708491276; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=YmSZNQ356QtM9WesWCMinXmK9k2yULQ13GYKx7NLJhc=; b=Qu3OCMITEMOw1j1tjIMzR1KElREa3r9DDbyNUNHqA/mzx1ha1A5HVzsDott7iamsq0 DCsD3k2++gHGHUyNh5FoR0liJm3vkpu9uyYKlS3TuEupicZIY1BdwI6XpR0bF9RwObRr J8UXRWuEMY9Kpx8Na2ViIiom/q3eP33VwSyl3lAFmXBE3d8LG35qyXd1DPUlBOsF9NT9 E4Y/AEjXcEChCWIJ0Ogty97UGKk6I63g1mVgMuBjqsuJmDg32Q4MGFPD/uiSkTRU4IwV m9TXO3y1Ge/VR5doaxfNc1oVR0wqbitpBbskZLb99TPP8JCbvLR4XJ4Gv6/CYBRQp4uq tCdw== X-Forwarded-Encrypted: i=1; AJvYcCVVVps3OS8fC79db+H8fqwVTKep0law2u5lUpxpAhGWyIBstJm+66VxvIzOfi04y4WnUkAkjEkxCDAVjg79vSjR1r5wIQL8jmcNtNFT X-Gm-Message-State: AOJu0YzoxKS+VjQON5zCE0ZTq50XldNk29/utQepkwOce2BeIIg3ybfG NJxLYqAftKKdY8gfrY+svNnqTd/B1me7Jljvt18mbz7phJGKvQBe4SPMBVGA1FHTNM5gJeSZ3Hu kjxl0cA== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:6d92:85eb:9adc:66dd]) (user=irogers job=sendgmr) by 2002:a0d:eb15:0:b0:602:b7ce:f382 with SMTP id u21-20020a0deb15000000b00602b7cef382mr240294ywe.7.1707886476058; Tue, 13 Feb 2024 20:54:36 -0800 (PST) Date: Tue, 13 Feb 2024 20:53:50 -0800 In-Reply-To: <20240214045356.748330-1-irogers@google.com> Message-Id: <20240214045356.748330-3-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240214045356.748330-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Subject: [PATCH v4 2/8] perf list: Add scandirat compatibility function From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , James Clark , Athira Jajeev , Kan Liang , Yang Jihong , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, llvm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" scandirat is used during the printing of tracepoint events but may be missing from certain libcs. Add a compatibility implementation that uses the symlink of an fd in /proc as a path for the reliably present scandir. Signed-off-by: Ian Rogers --- tools/perf/util/print-events.c | 12 +++--------- tools/perf/util/util.c | 19 +++++++++++++++++++ tools/perf/util/util.h | 8 ++++++++ 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c index 9e47712507cc..bf79dd366e2e 100644 --- a/tools/perf/util/print-events.c +++ b/tools/perf/util/print-events.c @@ -63,6 +63,8 @@ void print_tracepoint_events(const struct print_callbacks *print_cb __maybe_unus { char *events_path = get_tracing_file("events"); int events_fd = open(events_path, O_PATH); + struct dirent **sys_namelist = NULL; + int sys_items; put_tracing_file(events_path); if (events_fd < 0) { @@ -70,10 +72,7 @@ void print_tracepoint_events(const struct print_callbacks *print_cb __maybe_unus return; } -#ifdef HAVE_SCANDIRAT_SUPPORT -{ - struct dirent **sys_namelist = NULL; - int sys_items = tracing_events__scandir_alphasort(&sys_namelist); + sys_items = tracing_events__scandir_alphasort(&sys_namelist); for (int i = 0; i < sys_items; i++) { struct dirent *sys_dirent = sys_namelist[i]; @@ -130,11 +129,6 @@ void print_tracepoint_events(const struct print_callbacks *print_cb __maybe_unus } free(sys_namelist); -} -#else - printf("\nWARNING: Your libc doesn't have the scandirat function, please ask its maintainers to implement it.\n" - " As a rough fallback, please do 'ls %s' to see the available tracepoint events.\n", events_path); -#endif close(events_fd); } diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index c1fd9ba6d697..4f561e5e4162 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c @@ -552,3 +552,22 @@ int sched_getcpu(void) return -1; } #endif + +#ifndef HAVE_SCANDIRAT_SUPPORT +int scandirat(int dirfd, const char *dirp, + struct dirent ***namelist, + int (*filter)(const struct dirent *), + int (*compar)(const struct dirent **, const struct dirent **)) +{ + char path[PATH_MAX]; + int err, fd = openat(dirfd, dirp, O_PATH); + + if (fd < 0) + return fd; + + snprintf(path, sizeof(path), "/proc/%d/fd/%d", getpid(), fd); + err = scandir(path, namelist, filter, compar); + close(fd); + return err; +} +#endif diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 7c8915d92dca..9966c21aaf04 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h @@ -6,6 +6,7 @@ /* glibc 2.20 deprecates _BSD_SOURCE in favour of _DEFAULT_SOURCE */ #define _DEFAULT_SOURCE 1 +#include #include #include #include @@ -56,6 +57,13 @@ int perf_tip(char **strp, const char *dirpath); int sched_getcpu(void); #endif +#ifndef HAVE_SCANDIRAT_SUPPORT +int scandirat(int dirfd, const char *dirp, + struct dirent ***namelist, + int (*filter)(const struct dirent *), + int (*compar)(const struct dirent **, const struct dirent **)); +#endif + extern bool perf_singlethreaded; void perf_set_singlethreaded(void); -- 2.43.0.687.g38aa6559b0-goog