From nobody Sun Feb 8 20:33:04 2026 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.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 B0DF9225779 for ; Fri, 25 Apr 2025 21:40:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745617226; cv=none; b=PSMunY6M6yW94NqFBoMSYCSphJz6kTGKwRwKv+a8L3LbHdHmQpB3RuxRAXdK8mnIm7dHNnrKztZYaTPQYNCIgQcSUYQdZdkxWUwZpDGn49V5qJHUF9b3pi40ypy9hYnWouwaEIeEe3NGKSyr+2B0/ZJqfClC4xMyrl/ERnrJABw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745617226; c=relaxed/simple; bh=ZL08rcqyCgtd3fCAOlGvbvozdsTpLdsBGxJ125AYgWI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=YnOGGQ1UNWn5CBUA4fvaX8Ok0JZsfsfHpSsdrXhLs0amrOOAyqCxNMtRHFue4fSszOZgAuZGjj8B9CB5W+4SBJMVh8BYmYd7yKTelzYfB22zvCQLbgOjWsATbgWqGgEvrN1beCcBJ/lwzApjBT2Ra5A/BY7riu0P4mn9XLbv4YQ= 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=r7puIXBH; arc=none smtp.client-ip=209.85.215.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="r7puIXBH" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-af5310c1ac1so1567854a12.2 for ; Fri, 25 Apr 2025 14:40:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1745617224; x=1746222024; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=fAX+9khAQi7fMOsJvYWjYKrWaI2re/p3GAurUNFPS60=; b=r7puIXBH+rdF1IYC1waoyXxyIoRnLXWCAuRyXDU6Oy0Q45mrqperPH+xIRvGfjgNkS 7T+ET3VZXR4tI4yZ8zDcLzUraxkBk7xoMseyKSeL0RJdMYZaHK7e1ne3rJQSldPCBdsp KFF/4WJeARfCCzKU6F24IUMij8t7Ueje09r7tsjpJSxL0Lt+FqL8T5eESgqDIDOHxqEL mC1+WQ/XmvbrHVzLVcBm0idT6bFHue+2lAwfs/beumOk842zfY3O2XQPHUVxQQuJwH2g ObBwSQvzN3SNX58If/GuTuA+HKhqUSWdRJYpQngoacH71AA91iIqDh1X+ovY2pZC8zbE EDlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745617224; x=1746222024; h=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=fAX+9khAQi7fMOsJvYWjYKrWaI2re/p3GAurUNFPS60=; b=ta32JbPdDwCoqj+NSP30Y+0HvJcgj6p30AKwxW7wdmuHjlWiMKqoCFwTRE+Z2sQgc9 LvP9QNBpdnCGbQQbQl3fg7zjUq0TMG7/LYUMK4aGCOdfNHN1u/1/CxZaKJrRWxT2VD3H UAc+Eh7AYJvCtJv+bkOER45pBFYz1RWzi/+7BxJjRuI34H07Q94fqsfPhqq/t081gaHp bTVJ7uwJGFNewe0uX3CzNsnFbh60VZ0da1kr82YsJ2RKo/DSQ72FdHrz7JM2oRA9AjRl MbpoFtvbykQTJfPB++Y4AbjK+9R95rAnQC4CWzsLnHVO7KO/SoWF7If+Rhrp9VKIRmD4 VDLw== X-Forwarded-Encrypted: i=1; AJvYcCVQ0FjXCD1rFedvc0kNkbrNy7pszk4oSgzDfN4+WJBQavKWuTfpWTaKMmkHJzWl6TMJ9oXmHpJ4jb0sW1A=@vger.kernel.org X-Gm-Message-State: AOJu0YwWgaLux3g6sVWnbKlTeqE2O8+/q1TkdqKnqM3DDvfIImZ7fhZE 6K3KzR/x8/LL+cvT+HwuR06lcmk0IiakQBzONcGnT7Lfye28GQnqZYUwOXE8/1A94wX+0YaJr/v T30U/6w== X-Google-Smtp-Source: AGHT+IEOXvhmXgBH203IRvWhR6UGZfK84QlccQK0fbPrnmGOEV62oiaNtGPJB8OlZltmpiATXhLkEWG2ULWJ X-Received: from pjm5.prod.google.com ([2002:a17:90b:2fc5:b0:2f4:4222:ebba]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3c8f:b0:2fe:85f0:e115 with SMTP id 98e67ed59e1d1-309f8df728bmr4719663a91.26.1745617223972; Fri, 25 Apr 2025 14:40:23 -0700 (PDT) Date: Fri, 25 Apr 2025 14:39:59 -0700 In-Reply-To: <20250425214008.176100-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250425214008.176100-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.850.g28803427d3-goog Message-ID: <20250425214008.176100-2-irogers@google.com> Subject: [PATCH v3 01/10] perf parse-events filter: Use evsel__find_pmu From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Dapeng Mi , Thomas Richter , Veronika Molnarova , Hao Ge , Howard Chu , Weilin Wang , Levi Yun , "Dr. David Alan Gilbert" , Dominique Martinet , Xu Yang , Tengda Wu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Rather than manually scanning PMUs, use evsel__find_pmu that can use the PMU set during event parsing. Signed-off-by: Ian Rogers --- tools/perf/util/parse-events.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 89708d1769c8..2a60ea06d3bc 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -2463,9 +2463,8 @@ foreach_evsel_in_last_glob(struct evlist *evlist, static int set_filter(struct evsel *evsel, const void *arg) { const char *str =3D arg; - bool found =3D false; int nr_addr_filters =3D 0; - struct perf_pmu *pmu =3D NULL; + struct perf_pmu *pmu; =20 if (evsel =3D=3D NULL) { fprintf(stderr, @@ -2483,16 +2482,11 @@ static int set_filter(struct evsel *evsel, const vo= id *arg) return 0; } =20 - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) - if (pmu->type =3D=3D evsel->core.attr.type) { - found =3D true; - break; - } - - if (found) + pmu =3D evsel__find_pmu(evsel); + if (pmu) { perf_pmu__scan_file(pmu, "nr_addr_filters", "%d", &nr_addr_filters); - + } if (!nr_addr_filters) return perf_bpf_filter__parse(&evsel->bpf_filters, str); =20 --=20 2.49.0.850.g28803427d3-goog From nobody Sun Feb 8 20:33:04 2026 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 BBE81227E82 for ; Fri, 25 Apr 2025 21:40:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745617228; cv=none; b=QgCsDLKjOcWoXaeNP8PmZ9CJseTgCcPQ/P1zrF68cIhgGvTtzVkJBRd2185zNz0NkRZslbzjdv2XV2fnf3bnNR4JtBW2o53151VMTF/N2dPNvSP0Tm+zGZ+iAXO14cIaDZIVGT1mTOHoUWyTHMsNevB6uM+HGI8hO/zVqX8DkBY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745617228; c=relaxed/simple; bh=NW04OdUCBUXB0XwIkvNApQLAwj8ekPQOiMfdRIxQWTE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=Pn+23usexM1sqjxLHZiKhPtc9drdvjM32XCWhRH6tjIpJx96i4xLSlWCnnXmA/8XrCBwdlvbI/BnvTh2XOO2YV49QaebBe9iozAvqCIiEdQhfFHTn6ea6JoAFyguzl6rnjvNszpQP/cPmX+bKjyaeD7LtHWmD6+Jie7C34PmaTc= 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=rT+VduVM; arc=none smtp.client-ip=209.85.216.73 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="rT+VduVM" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2ff64898e2aso2828460a91.1 for ; Fri, 25 Apr 2025 14:40:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1745617226; x=1746222026; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=ZBRzvY9/oqGcvbYk2oQ/5pWM3xndZw3DROLAFfIr7HU=; b=rT+VduVMIASn2Mtjy8X+n8ZMTqllJQjpATimXQDfB/2Wb9SAgPUUglsncOp9P3yGWz f40Rzv4CzbE0NGXzgepuXt8Efb0oebzbmtgtSdR5aTOIusuFsfd6NYxBzoDq1/dwucBC AO6c/xDdXKEQ3aXXpmZffBEp/I3m6yPAQ2pVK2atwh52Orj3caTe5x0gWRjz9geahNEw UslxmGtoClL0vK6G6H/Ae71Ci1mmGAq398betV3yc0o2BCAFsTCaypXa06DSLTCDyQm/ +f454oe6+eGQMH/heHqY6wROMidhMhhHwnHK97m/di+JnlAVdw3RFX8QSkL8s4C0UbzH Xmmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745617226; x=1746222026; h=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=ZBRzvY9/oqGcvbYk2oQ/5pWM3xndZw3DROLAFfIr7HU=; b=ZYvUqs/yqICnUyawohn9FyjOZHsRXqHL6UQlsS43y2qDLoH2IKFOjhfK7yL3xM455Q /LmUN8YF848RdRJfZhUc63cuEc6ovBIbLBG8u2g40o8pHtvJrUBzfa5uJqnPc36CPQcv TsDes0K/frYKDVLxn/V/6iskVDMLPyKScUrMCNhlxnB+rI2dXSe1AdR9GJmFf1BUZnt1 E5LU/t/pBkoyOnEE8WEMq6TE3SMtS6/7GNmmUwRa4prrOq2r4GZQzSHOaCE7zjtF6lip ZQCkAvZz7qCvzTOXj4LCNPUK4M+p3HJu28qbZRTYi30DsBi1Zbl/hX78kWiSG1eTvSGb m+Yw== X-Forwarded-Encrypted: i=1; AJvYcCVKGHJMoKHtbAn8Mxan6Xe4LUk18bmdhloLLaNLAUS1NZcxNWqz4lhVbq4v2obW5mEdq6ChT57haba68iQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yzh9Ev/0z5WYAQEkTvFG24tTIz8op5oCvHDSmXKIa89JF07zh+M MHyRrDRYGqUqwnVArC23TOQGVmC9PRQu3tU/21gE/JO4LoVsaP51gjsMqBrN+fJQHU2SIE0q/ax WRAttwA== X-Google-Smtp-Source: AGHT+IGGlxlrXc4zeoAxvuCibveLAo4hf2bW6wySquqYWmKShkqKk+8FF4aoVv7ok9S5AQIRvxzmpRZUU6A2 X-Received: from pjbpa14.prod.google.com ([2002:a17:90b:264e:b0:2ef:95f4:4619]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:5104:b0:2ff:53d6:2b82 with SMTP id 98e67ed59e1d1-309ee3f9ac3mr11267255a91.11.1745617226120; Fri, 25 Apr 2025 14:40:26 -0700 (PDT) Date: Fri, 25 Apr 2025 14:40:00 -0700 In-Reply-To: <20250425214008.176100-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250425214008.176100-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.850.g28803427d3-goog Message-ID: <20250425214008.176100-3-irogers@google.com> Subject: [PATCH v3 02/10] perf target: Separate parse_uid into its own 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 , Kan Liang , James Clark , Dapeng Mi , Thomas Richter , Veronika Molnarova , Hao Ge , Howard Chu , Weilin Wang , Levi Yun , "Dr. David Alan Gilbert" , Dominique Martinet , Xu Yang , Tengda Wu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Allow parse_uid to be called without a struct target. Rather than have two errors, remove TARGET_ERRNO__USER_NOT_FOUND and use TARGET_ERRNO__INVALID_UID as the handling is identical. Signed-off-by: Ian Rogers --- tools/perf/util/target.c | 22 ++++++++++++---------- tools/perf/util/target.h | 3 ++- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/tools/perf/util/target.c b/tools/perf/util/target.c index 0f383418e3df..f3ad59ccfa99 100644 --- a/tools/perf/util/target.c +++ b/tools/perf/util/target.c @@ -94,15 +94,13 @@ enum target_errno target__validate(struct target *targe= t) return ret; } =20 -enum target_errno target__parse_uid(struct target *target) +uid_t parse_uid(const char *str) { struct passwd pwd, *result; char buf[1024]; - const char *str =3D target->uid_str; =20 - target->uid =3D UINT_MAX; if (str =3D=3D NULL) - return TARGET_ERRNO__SUCCESS; + return UINT_MAX; =20 /* Try user name first */ getpwnam_r(str, &pwd, buf, sizeof(buf), &result); @@ -115,16 +113,22 @@ enum target_errno target__parse_uid(struct target *ta= rget) int uid =3D strtol(str, &endptr, 10); =20 if (*endptr !=3D '\0') - return TARGET_ERRNO__INVALID_UID; + return UINT_MAX; =20 getpwuid_r(uid, &pwd, buf, sizeof(buf), &result); =20 if (result =3D=3D NULL) - return TARGET_ERRNO__USER_NOT_FOUND; + return UINT_MAX; } =20 - target->uid =3D result->pw_uid; - return TARGET_ERRNO__SUCCESS; + return result->pw_uid; +} + +enum target_errno target__parse_uid(struct target *target) +{ + target->uid =3D parse_uid(target->uid_str); + + return target->uid !=3D UINT_MAX ? TARGET_ERRNO__SUCCESS : TARGET_ERRNO__= INVALID_UID; } =20 /* @@ -142,7 +146,6 @@ static const char *target__error_str[] =3D { "BPF switch overriding UID", "BPF switch overriding THREAD", "Invalid User: %s", - "Problems obtaining information for user %s", }; =20 int target__strerror(struct target *target, int errnum, @@ -171,7 +174,6 @@ int target__strerror(struct target *target, int errnum, break; =20 case TARGET_ERRNO__INVALID_UID: - case TARGET_ERRNO__USER_NOT_FOUND: snprintf(buf, buflen, msg, target->uid_str); break; =20 diff --git a/tools/perf/util/target.h b/tools/perf/util/target.h index 2ee2cc30340f..e082bda990fb 100644 --- a/tools/perf/util/target.h +++ b/tools/perf/util/target.h @@ -48,12 +48,13 @@ enum target_errno { =20 /* for target__parse_uid() */ TARGET_ERRNO__INVALID_UID, - TARGET_ERRNO__USER_NOT_FOUND, =20 __TARGET_ERRNO__END, }; =20 enum target_errno target__validate(struct target *target); + +uid_t parse_uid(const char *str); enum target_errno target__parse_uid(struct target *target); =20 int target__strerror(struct target *target, int errnum, char *buf, size_t = buflen); --=20 2.49.0.850.g28803427d3-goog From nobody Sun Feb 8 20:33:04 2026 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.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 E9A30229B36 for ; Fri, 25 Apr 2025 21:40:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745617230; cv=none; b=Be7C4hdF3VTxorR1+3LQqnSq5XVLXnej/L3ufP0xQaVpFjp2Tcn+rQujrLSnFDFE37ihNRj98Wf8nskrMXdA2cnEYeAMpC6yE0kEje4+mxoluBAk4SbTHg+XX0wQIsY3j8uRd/sS0lCCgrVA4hdbl51nvo0xHf0on4pIGZiroGM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745617230; c=relaxed/simple; bh=gbjo4h3GHQFtFeOpJumdcLDVg3ih8INOSDQkXhcieIM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=HvPrJIv6QHKYNssM/mQdcFpjPpQE2rRW52AfXQQAPbN3NQjdeUkFkXGzYCG9BLKvjVHzTx7EQFaWp3/e05ZktkhZJQ7d1eZuXifMaf8SsZnE/uRsek+/Y9b2Qevq1K2KZr+WkxtshzYsOdF/NRmY2GTibZFzGaAWGaPoFrruo8w= 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=XdLYba0l; arc=none smtp.client-ip=209.85.215.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="XdLYba0l" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b048d1abbbfso2618547a12.0 for ; Fri, 25 Apr 2025 14:40:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1745617228; x=1746222028; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=bR45kodXZkA7EQ9UBPLhC24dTzfJslYN2Nb1yPoIsJQ=; b=XdLYba0l+X8n6rkMQT8Xj350nyZz6Qg78/3VH2nwTepRw+Kw4qqsq3hFQkZO+ex+Xu C59ILn0/o5H8xOA5er286nwcUglG81PHsDEzuFywVNMg/elUx1SLFrFhv46WuL6kTvfP CLsQjNFsEy+xdmFLFU/QWdHXa/t9oBAZRXC4DQbL4Tbe0dkvGFN3JK2DfYVT76w3hc+/ k+rxf3ZfmAPJ0eocXMq5ifELflQpueyMbnUb5Lmc1lku2ZVq/ot3OrjPBfSr8ZJqqOrh gUsx2zr7Xn3eJEtwDtCQJys4DkCZ0Ks3YztQ1HKg0nCU8ts+t6zGw2+aftF8/sKuvCer tRhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745617228; x=1746222028; h=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=bR45kodXZkA7EQ9UBPLhC24dTzfJslYN2Nb1yPoIsJQ=; b=XC/9TZiD2Y+80alJkR73U9/8eXhMsckqqVz0LIdPDNj+etQrp27TGQ0eUTIeunbLOP GesTqlW8iGOeUMnghTLJg0+ciAjZO4RLRWraOlp9AM8RB2j2vwSt/x55B6YgoYdvv+nh eowAmsWWbrisxZNEoHZx7SprbAipGiM0qTG7U8449zTyF3l6nG3PiX5LHEVaxAgHoJ5C kW+DXXXvA24ozWK3n8IFCnumAWxoiUXGy1CLgdjXSCTGKdx7+HmPwfyHUX8r9gxqrmFc DqTAeqpsQN49z2h3l449/vWuhAVY0gOA+hwYKrsnHWvn+bJjt2hQ+4PlL7VpFbJINesN qhng== X-Forwarded-Encrypted: i=1; AJvYcCVFv3l3eXWer7NUUn+K4VvwqrFDWp+0IqIL3BdDhM9TQlPaK7pTtnCElm1nS8tGUdUXQ+aFtIYJEomVIEs=@vger.kernel.org X-Gm-Message-State: AOJu0Yxhw17+HzcELd+XHHuM6KSqI/R3tQ+f6JHXUO1TmnZsMi1VwBH6 9E4yq5fiMV4KkfVHmSxqmUjhgG5wd3HNnP+ig31x2rlpFlaEYcew+w2VezUYb9K02gZUvh81Wex U2K1EZQ== X-Google-Smtp-Source: AGHT+IHu6jNsVxg2hinctPs3rIG3x23hifof5G2en1Olm7EYab4lBNXfdy6kgi4Gh069LsoL9yjCAM48VRnS X-Received: from pgbcl20.prod.google.com ([2002:a05:6a02:994:b0:af2:7bd1:57e6]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:12c4:b0:1ee:ef0b:7bf7 with SMTP id adf61e73a8af0-2046a57d131mr1026446637.19.1745617227918; Fri, 25 Apr 2025 14:40:27 -0700 (PDT) Date: Fri, 25 Apr 2025 14:40:01 -0700 In-Reply-To: <20250425214008.176100-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250425214008.176100-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.850.g28803427d3-goog Message-ID: <20250425214008.176100-4-irogers@google.com> Subject: [PATCH v3 03/10] perf parse-events: Add parse_uid_filter helper From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Dapeng Mi , Thomas Richter , Veronika Molnarova , Hao Ge , Howard Chu , Weilin Wang , Levi Yun , "Dr. David Alan Gilbert" , Dominique Martinet , Xu Yang , Tengda Wu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add parse_uid_filter filter as a helper to parse_filter, that constructs a uid filter string. As uid filters don't work with tracepoint filters, add a is_possible_tp_filter function so the tracepoint filter isn't attempted for tracepoint evsels. Signed-off-by: Ian Rogers --- tools/perf/util/parse-events.c | 19 ++++++++++++++++++- tools/perf/util/parse-events.h | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 2a60ea06d3bc..540864fc597c 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -2460,6 +2460,12 @@ foreach_evsel_in_last_glob(struct evlist *evlist, return 0; } =20 +/* Will a tracepoint filter work for str or should a BPF filter be used? */ +static bool is_possible_tp_filter(const char *str) +{ + return strstr(str, "uid") =3D=3D NULL; +} + static int set_filter(struct evsel *evsel, const void *arg) { const char *str =3D arg; @@ -2472,7 +2478,7 @@ static int set_filter(struct evsel *evsel, const void= *arg) return -1; } =20 - if (evsel->core.attr.type =3D=3D PERF_TYPE_TRACEPOINT) { + if (evsel->core.attr.type =3D=3D PERF_TYPE_TRACEPOINT && is_possible_tp_f= ilter(str)) { if (evsel__append_tp_filter(evsel, str) < 0) { fprintf(stderr, "not enough memory to hold filter string\n"); @@ -2508,6 +2514,17 @@ int parse_filter(const struct option *opt, const cha= r *str, (const void *)str); } =20 +int parse_uid_filter(struct evlist *evlist, uid_t uid) +{ + struct option opt =3D { + .value =3D &evlist, + }; + char buf[128]; + + snprintf(buf, sizeof(buf), "uid =3D=3D %d", uid); + return parse_filter(&opt, buf, /*unset=3D*/0); +} + static int add_exclude_perf_filter(struct evsel *evsel, const void *arg __maybe_unused) { diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index e176a34ab088..289afd42d642 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -45,6 +45,7 @@ static inline int parse_events(struct evlist *evlist, con= st char *str, int parse_event(struct evlist *evlist, const char *str); =20 int parse_filter(const struct option *opt, const char *str, int unset); +int parse_uid_filter(struct evlist *evlist, uid_t uid); int exclude_perf(const struct option *opt, const char *arg, int unset); =20 enum parse_events__term_val_type { --=20 2.49.0.850.g28803427d3-goog From nobody Sun Feb 8 20:33:04 2026 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.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 9BCD922A7F8 for ; Fri, 25 Apr 2025 21:40:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745617232; cv=none; b=RqBSqfPrcmCMJb5NU8ryd7vkMtH9saaT6QdKty2Rq5MLXQ9LN2MQt7sEyRMxf+YxzYP656Ew14WzNjqeqa2+30GiH+G6L8aJu5xcOndHFmoqxy1fyrzFFPFFAy6+8CZf29dv8DALoomISWBsKzOpDqi0KHr/a1WANqtWSLl6M1E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745617232; c=relaxed/simple; bh=LvH1IfFiRYzJWPR2DBxrtN9tmwFbXEeic3+ot8Z8LH4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=A5VxGflqo1zrsr7ypdLc3deo9TAmtf6V4PtoDnxMDXjXIayzj8K2jXObQyqSgFjNfZVg3c3d4ieepThXokhuhpJBg8MZ+V9Y/0ZeR3pRQFaa8/I9C5pNGii1W/xQ2W2klsF7BAPvwHyfPa9awiuQETO5efo+zeDbgSYXCWWmREQ= 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=j3k4QB3i; arc=none smtp.client-ip=209.85.215.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="j3k4QB3i" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b00aa1f50d1so1579506a12.3 for ; Fri, 25 Apr 2025 14:40:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1745617230; x=1746222030; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=/XmvjAR81O8HPM36SkAdYui69A1+Io4OkQZ3ltx3CRQ=; b=j3k4QB3i9pU4LSIS5+X5GyRNIPOsseSzehZ4lSpMVS6eC2cw4A3YqXC/hZ3IHQpQgd WR1gprJi53SVJM25kGM37XaD/62TQA3MmmJfDG3d25v3Bv3lb2Odsiv1L7k7ITxZClIO l/QUkmRDDlBwHDbHhSxVI+K3vLMEe2zOrPV3KI3x7Hzd5ThQkr7LQhfS+AUIY/7G3kMy 8o2Ivu62wJY8Ha9DuSHWwe2I4y3YbYgSqnm8ggOA56LRXqyg2OLYNaM2ltF3Uup1Q80s 7jmgI8SAQre+MSqqgEqN3aj3od+kZrrTLMf0ZB7nbS4x1+0a/Ovw/ZicrFFznZaUydc8 egFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745617230; x=1746222030; h=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=/XmvjAR81O8HPM36SkAdYui69A1+Io4OkQZ3ltx3CRQ=; b=ggaCcPOBY4H7BLtO0sR6As6j3FsiFvZhPoWXwK3hnN//6EafdrPOosf2+EtPoWvh1O r91hanZrSw9J8Vg78uz6nFmcIhf8XeGjEgL2gJTwtQDDSukQ2V2olCxW1VUDYnSAoV1e 8CHcUikfU4wvVLQe5YyXezpdiOZ1jfshqoLzXf1uD7mrG8IrIZP5z8LPMbcbMImSffVA 04lLMVbo45t8CG96WGxkhenkSb27rMX2/B6li1/vtexc4Xi+2DU1hg4B0pFx2vhX+dc0 +Djk3bpdoCjAQJMd30HfVCOis581s7M/oOizdFi9ohYFKAY/UZJC+rysmr0UH5XD1rPq ApOw== X-Forwarded-Encrypted: i=1; AJvYcCXDgiLZS4MyjfGiSzGsO/5pcvR+jrKH0RMMX+qZh2sUsHnYRjq0VzMa/TylXwCrN4KLSG8WBIGcXCbPiiw=@vger.kernel.org X-Gm-Message-State: AOJu0YyHLZiq+nv6I0dfQLbVseV5Zf9+LvRBUkHPGAXiubO13lEoL/uY ygmFgD5eTrOw3fv5Gkc61C0wq86AZHk+zmIi0Twyy2/PplhZHs8AXcCCiJ/nWOxPyVktePk08G0 cwzcLrQ== X-Google-Smtp-Source: AGHT+IFPx94l2No/fmon1OdF/8vvvV7PGuto3FEMdzF4QNWLs5H2WqILYAjuXpwf2f9FODWfheUbYlUZVcMv X-Received: from pgcp16.prod.google.com ([2002:a63:7410:0:b0:af2:448e:a04d]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:394b:b0:1f5:6878:1a43 with SMTP id adf61e73a8af0-2045b6f4c38mr5841222637.14.1745617230027; Fri, 25 Apr 2025 14:40:30 -0700 (PDT) Date: Fri, 25 Apr 2025 14:40:02 -0700 In-Reply-To: <20250425214008.176100-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250425214008.176100-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.850.g28803427d3-goog Message-ID: <20250425214008.176100-5-irogers@google.com> Subject: [PATCH v3 04/10] perf record: Switch user option to use BPF filter From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Dapeng Mi , Thomas Richter , Veronika Molnarova , Hao Ge , Howard Chu , Weilin Wang , Levi Yun , "Dr. David Alan Gilbert" , Dominique Martinet , Xu Yang , Tengda Wu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The existing --uid option finds user processes by scanning /proc. Scanning /proc is inherently racy due to processes being in /proc but then exiting before perf does the perf_event_open. When the perf_event_open fails perf will terminate reporting errors which is a disappointing user experience. Scanning /proc when perf starts also cannot inform perf of new user processes starting. The ability to filter perf events with BPF isn't new, and has been in the perf tool for 10 years: https://lore.kernel.org/all/1444826502-49291-8-git-send-email-wangnan0@huaw= ei.com/ An ability to do filtering on the command line with a BPF program that's part of perf was added 2 years ago: https://lore.kernel.org/all/20230314234237.3008956-1-namhyung@kernel.org/ This was then extended to support uids as a way of filtering: https://lore.kernel.org/all/20240524205227.244375-1-irogers@google.com/ This change switches the perf record --uid option to use the BPF filter code to avoid the inherent race and existing failures. To ensure all processes are considered by the filter, the change forces system-wide mode. Using BPF has permission issues in loading the BPF program not present in scanning /proc. As the scanning approach would miss new programs and fail due to the race, this is considered preferable. The change also avoids opening a perf event per PID, which is less overhead in the kernel. Signed-off-by: Ian Rogers --- tools/perf/builtin-record.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 7b64013ba8c0..5eddf3568b04 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -174,6 +174,7 @@ struct record { bool timestamp_boundary; bool off_cpu; const char *filter_action; + const char *uid_str; struct switch_output switch_output; unsigned long long samples; unsigned long output_max_size; /* =3D 0: unlimited */ @@ -3465,8 +3466,7 @@ static struct option __record_options[] =3D { "or ranges of time to enable events e.g. '-D 10-20,30-40'", record__parse_event_enable_time), OPT_BOOLEAN(0, "kcore", &record.opts.kcore, "copy /proc/kcore"), - OPT_STRING('u', "uid", &record.opts.target.uid_str, "user", - "user to profile"), + OPT_STRING('u', "uid", &record.uid_str, "user", "user to profile"), =20 OPT_CALLBACK_NOOPT('b', "branch-any", &record.opts.branch_stack, "branch any", "sample any taken branches", @@ -4205,19 +4205,24 @@ int cmd_record(int argc, const char **argv) ui__warning("%s\n", errbuf); } =20 - err =3D target__parse_uid(&rec->opts.target); - if (err) { - int saved_errno =3D errno; + if (rec->uid_str) { + uid_t uid =3D parse_uid(rec->uid_str); =20 - target__strerror(&rec->opts.target, err, errbuf, BUFSIZ); - ui__error("%s", errbuf); + if (uid =3D=3D UINT_MAX) { + ui__error("Invalid User: %s", rec->uid_str); + err =3D -EINVAL; + goto out; + } + err =3D parse_uid_filter(rec->evlist, uid); + if (err) + goto out; =20 - err =3D -saved_errno; - goto out; + /* User ID filtering implies system wide. */ + rec->opts.target.system_wide =3D true; } =20 - /* Enable ignoring missing threads when -u/-p option is defined. */ - rec->opts.ignore_missing_thread =3D rec->opts.target.uid !=3D UINT_MAX ||= rec->opts.target.pid; + /* Enable ignoring missing threads when -p option is defined. */ + rec->opts.ignore_missing_thread =3D rec->opts.target.pid; =20 evlist__warn_user_requested_cpus(rec->evlist, rec->opts.target.cpu_list); =20 --=20 2.49.0.850.g28803427d3-goog From nobody Sun Feb 8 20:33:04 2026 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.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 9575D22D4F9 for ; Fri, 25 Apr 2025 21:40:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745617234; cv=none; b=RIYOjuMQmrO1kZxXT/6lw7xDe4BwplRICr8jsKPLwvkjTYciFu5xMbQXanOsESK3p2qUJxF7WdBv6j9K6rLSVQJzrq38E1CR5vfY8oZIeskiuQf4SOoydTBj+If5m0gpo/R8m7oUQoKHOu+RN5nEBYVetzWphFYe3wh7qJuaplI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745617234; c=relaxed/simple; bh=KFCTNZByuOLUewbevYxsI1Ho0Fb2f3tRKqRks+3kA+E=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=ieIKqNSlWzX/46dZBrrdOCXvVhxm+HHTllTL4dnDSLyzINLi3Eusd6G3Xiqme1ti/3aTEcht95fwCLEcLID81UsG+bUzM0YSqWwMK7BDwqNd1J8/5pijAqsV0h+DON8MFaMA6FWlL2OfzrZ492MR6sIkQLTCg/tLz1boT7VCS2c= 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=KSc9L5nf; arc=none smtp.client-ip=209.85.215.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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="KSc9L5nf" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b15e08f1eb4so1529189a12.0 for ; Fri, 25 Apr 2025 14:40:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1745617232; x=1746222032; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=KqL5aSRe7NRip5o9p1kJq/fQhTkPb+WAWnf5Z1SdLc0=; b=KSc9L5nfRwsf/6gS1THcmVMrPlZr1yr1p6ArcYu4cqna1oOczgtIVlGS2Tg2OU5veu vmB/9z7bae7zXFHaQWgYGhz0Ldz7l+HE/cvxAv3ScyEygKEx3jC4YE1QV1xkL4JVTLBG 9MUw8fGAenXJ8/hfJKTdLLxQy9OohonjSmnFKWihNgH1pcAohROm/xcSio8UC3ZroVPK M3TRM2OWdpahV25kwq/uerNbyrcOT/PhVOaCeHqdRgjVHB+XFQ0pb78o0/fz2KrE6Azh A6XMcY4jQLBH431DVM4iSuB9PgTCBrjBSzaEdi55PpctbRvohP6xvIqckj+S+pm4gfTm Pwfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745617232; x=1746222032; h=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=KqL5aSRe7NRip5o9p1kJq/fQhTkPb+WAWnf5Z1SdLc0=; b=sXbmNFIePCLeO305uQxc3fltFiFdakFQdHY1v+guVWznZgG02a8fC61xDA9nH3nv8D AuCiWE6he7odOixHQNrawH6T7U9xACZdYRE9mDZY1o9NCf1PWKLQqv7BaErBNcI1MXK0 IHJNPAZwOCpQnkG1Qsc/pv/Q8Hy6xpEllHVXpHVloeHg6iWs5ufB70H1Tj3nyBLSn/ie 0QHyzlds73LVoY3HPRWOA6le1pNTknZt5SAS/SV24rS7e5dluB5UwVCPNxq2LfSuWZTk E8R1IngFyf5nDlBNt1sYdsfqJpLpXGhZ+C6iOm+Y3au/kUTyaF3FTGVu7TuHyqLv0PkN Gz0g== X-Forwarded-Encrypted: i=1; AJvYcCV8fZ1SgWZ7uIEatWv/BGEHLi6/wo/JxrTJLdcAspSI6g8Q6FO0yvIHrHwYxytMJXeEYBKbVF/YtLueWK4=@vger.kernel.org X-Gm-Message-State: AOJu0YyfUf7bG4ULUQmBnV/bJJWvNXW7YH/TIlp1mOk0r3TpOrPlBPhU RxwLexjbgjk81F+RaJ80u7/bCEC0Eh/zNmzVZgND6iRD56HF+HDJGybJE/89+UM1P2hKcpE5+jG gEiYW6Q== X-Google-Smtp-Source: AGHT+IFxmTwnav32Ao3wqFAMsFqZ8W3YUDMM4pQmneQ1C4rKRrx4+lyrHc7kj6jkvl5z0GDO6WD92smF7xbj X-Received: from pgbcs12.prod.google.com ([2002:a05:6a02:418c:b0:af9:5717:cfbb]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:2d0c:b0:1f5:5ca4:2744 with SMTP id adf61e73a8af0-2045b70317fmr5325258637.17.1745617231848; Fri, 25 Apr 2025 14:40:31 -0700 (PDT) Date: Fri, 25 Apr 2025 14:40:03 -0700 In-Reply-To: <20250425214008.176100-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250425214008.176100-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.850.g28803427d3-goog Message-ID: <20250425214008.176100-6-irogers@google.com> Subject: [PATCH v3 05/10] perf tests record: Add basic uid filtering test From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Dapeng Mi , Thomas Richter , Veronika Molnarova , Hao Ge , Howard Chu , Weilin Wang , Levi Yun , "Dr. David Alan Gilbert" , Dominique Martinet , Xu Yang , Tengda Wu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now the uid option doesn't race and fail, add a test of it. The test is based on the system-wide test with changes around how failure is handled - BPF permissions are a bigger issue than perf event paranoia. Signed-off-by: Ian Rogers --- tools/perf/tests/shell/record.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tools/perf/tests/shell/record.sh b/tools/perf/tests/shell/reco= rd.sh index 05d91a663fda..308916f9c292 100755 --- a/tools/perf/tests/shell/record.sh +++ b/tools/perf/tests/shell/record.sh @@ -231,6 +231,31 @@ test_cgroup() { echo "Cgroup sampling test [Success]" } =20 +test_uid() { + echo "Uid sampling test" + if ! perf record -aB --synth=3Dno --uid "$(id -u)" -o "${perfdata}" ${te= stprog} \ + > "${script_output}" 2>&1 + then + if grep -q "libbpf.*EPERM" "${script_output}" + then + echo "Uid sampling [Skipped permissions]" + return + else + echo "Uid sampling [Failed to record]" + err=3D1 + # cat "${script_output}" + return + fi + fi + if ! perf report -i "${perfdata}" -q | grep -q "${testsym}" + then + echo "Uid sampling [Failed missing output]" + err=3D1 + return + fi + echo "Uid sampling test [Success]" +} + test_leader_sampling() { echo "Basic leader sampling test" if ! perf record -o "${perfdata}" -e "{cycles,cycles}:Su" -- \ @@ -324,6 +349,7 @@ test_system_wide test_workload test_branch_counter test_cgroup +test_uid test_leader_sampling test_topdown_leader_sampling test_precise_max --=20 2.49.0.850.g28803427d3-goog From nobody Sun Feb 8 20:33:04 2026 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 9B13D22FF2D for ; Fri, 25 Apr 2025 21:40:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745617237; cv=none; b=fsFCPpcRKiWgMIXokS2CsgQdGKD0KuJtQRMBEDM9rboUNouImi5vJhRCp9kREcoSr7jY5TMzelguBm2nuClZLlt5uFhX9ECc+vbLcxHQI+77t7SevTvEwGGNzzNIQJ2xScDyLSvUXsqV0YPSsSxOp3Yy+qic6GYN28TxF/Efz6Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745617237; c=relaxed/simple; bh=ETJXpOiPkRJYGh3SfFCaOywsWvWJiPbgmQnbhQPzOXk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=rIYTRCx+b6nCUXyUOtaPUJsWZws3ZXHacW/1wCKunXdMlZmMdxYEKQccUnrixRQ3glPIInBfAmUdgbWeHy+8nx7dcXfmo8tIfzOUl2Bb9vClTXl4CVc3Kqt8x2lZjxo8+abQF7TXIUNfBPApKS+UZ+wxuCaFuxJN8F1T9SF0cPk= 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=WE7baxZT; arc=none smtp.client-ip=209.85.216.73 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="WE7baxZT" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-309c6e43a9aso4148000a91.2 for ; Fri, 25 Apr 2025 14:40:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1745617234; x=1746222034; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=02ryzVedAARQkanLp1HnvhE2SOHEE70YtQbGJrfmJUM=; b=WE7baxZTqyvbJAZz3VOLQn2aR1na+0LhrcrlATLpOLnQ8F76YsBEpW4VO6vyhTfe6C XSEZa3tqDFOILyJCzc2izyEUg0sWe1iC6l0RTNyeTZW34L4xlWxp8fnP50HJc2oWV7So n+BoC+ZyllxcJfJERJasyaKuE/mE3bqYpes48nkbb05oYij9BX+QpODrnkdx79DPASPJ ++z8M73b1HavKHTh0JLfs/sJ3XIlo6v3b1Uh1rVe3lycvywx//xjvM/CbzVIwLo0Bv0j 4d/bWHzOJeU/qJQkwsR0AxtjhGFgkt9Smhnrc+mvYGmkHu2ctmuMN+53VQ0peg8ANepx z33Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745617234; x=1746222034; h=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=02ryzVedAARQkanLp1HnvhE2SOHEE70YtQbGJrfmJUM=; b=Ywz5t1PSYV1kTaYUQVMWZVMt/n3ptZPRSLSbqTctdpPHo0Ib43ubgzX4NUNvzTCeQ/ tj6WcrHDHsF/NSpA9qqFL5J0n9VltkJr2KG2wiroXrQv2DJsTpI5/AniCIOZgSGhzYh1 lmPc8FrQ2KkheX27/bnRjm09TJgVOyEbR+3l5MELulONIy2rOcbbS1aZcDJl7xI+UiY+ DMFdrL4ISNooa/8ZjkkcePcCkqXessLIAK8uHDkH8RsoTTKNyy8ih05jaP7jii2bPTPJ 8AD39v83SxsXD5e054LVZEwtppReKx0eNxBQvnn99lzoGaKYYqFT1+9D/6RhM0KNJ30S PbWA== X-Forwarded-Encrypted: i=1; AJvYcCVUSTpG+yZzRaXk0qn9ZNYjX1Hs+OxkCDwUfmoJ84ka79Deg8998Uw8NUit9axqMbDp8aH8XwJGTHrcJi4=@vger.kernel.org X-Gm-Message-State: AOJu0Yz4ucV6dUoUz5bsGt7uVfSatXhSpi/pMel1TxQOSwaVjFOi9Mm2 kEvcXpGolkU6hnx0eydP6qAWQnnAcROR2c55V6yjImp7bu5KszchhRF0v+JtQ4wv/++dHENldsC 48DkzQg== X-Google-Smtp-Source: AGHT+IG19NnGKnApBu0HJSqww+Jf8NFjSpR0Yz/CRa2oNnzjitLT7j5APZLNXxEqls7FaDaLDMo4jCQ28ogZ X-Received: from pjur4.prod.google.com ([2002:a17:90a:d404:b0:301:2679:9d9]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:e70b:b0:2f8:49ad:4079 with SMTP id 98e67ed59e1d1-30a012fe1b5mr1565373a91.6.1745617234021; Fri, 25 Apr 2025 14:40:34 -0700 (PDT) Date: Fri, 25 Apr 2025 14:40:04 -0700 In-Reply-To: <20250425214008.176100-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250425214008.176100-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.850.g28803427d3-goog Message-ID: <20250425214008.176100-7-irogers@google.com> Subject: [PATCH v3 06/10] perf top: Switch user option to use BPF filter From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Dapeng Mi , Thomas Richter , Veronika Molnarova , Hao Ge , Howard Chu , Weilin Wang , Levi Yun , "Dr. David Alan Gilbert" , Dominique Martinet , Xu Yang , Tengda Wu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The existing --uid option finds user processes by scanning /proc. Scanning /proc is inherently racy due to processes being in /proc but then exiting before perf does the perf_event_open. When the perf_event_open fails perf will terminate reporting errors which is a disappointing user experience. Scanning /proc when perf starts also cannot inform perf of new user processes starting. The ability to filter perf events with BPF isn't new, and has been in the perf tool for 10 years: https://lore.kernel.org/all/1444826502-49291-8-git-send-email-wangnan0@huaw= ei.com/ An ability to do filtering on the command line with a BPF program that's part of perf was added 2 years ago: https://lore.kernel.org/all/20230314234237.3008956-1-namhyung@kernel.org/ This was then extended to support uids as a way of filtering: https://lore.kernel.org/all/20240524205227.244375-1-irogers@google.com/ This change switches the perf top --uid option to use the BPF filter code to avoid the inherent race and existing failures. Using BPF has permission issues in loading the BPF program not present in scanning /proc. As the scanning approach would miss new programs and fail due to the race, this is considered preferable. The change also avoids opening a perf event per PID, which is less overhead in the kernel. Signed-off-by: Ian Rogers --- tools/perf/builtin-top.c | 22 ++++++++++++---------- tools/perf/util/top.c | 4 ++-- tools/perf/util/top.h | 1 + 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index f9f31391bddb..8890bec9b63c 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -642,7 +642,7 @@ static void *display_thread_tui(void *arg) */ evlist__for_each_entry(top->evlist, pos) { struct hists *hists =3D evsel__hists(pos); - hists->uid_filter_str =3D top->record_opts.target.uid_str; + hists->uid_filter_str =3D top->uid_str; } =20 ret =3D evlist__tui_browse_hists(top->evlist, help, &hbt, top->min_percen= t, @@ -1566,7 +1566,7 @@ int cmd_top(int argc, const char **argv) "Add prefix to source file path names in programs (with --prefix-str= ip)"), OPT_STRING(0, "prefix-strip", &annotate_opts.prefix_strip, "N", "Strip first N entries of source file path name in programs (with --= prefix)"), - OPT_STRING('u', "uid", &target->uid_str, "user", "user to profile"), + OPT_STRING('u', "uid", &top.uid_str, "user", "user to profile"), OPT_CALLBACK(0, "percent-limit", &top, "percent", "Don't show entries under that percent", parse_percent_limit), OPT_CALLBACK(0, "percentage", NULL, "relative|absolute", @@ -1757,15 +1757,17 @@ int cmd_top(int argc, const char **argv) ui__warning("%s\n", errbuf); } =20 - status =3D target__parse_uid(target); - if (status) { - int saved_errno =3D errno; - - target__strerror(target, status, errbuf, BUFSIZ); - ui__error("%s\n", errbuf); + if (top.uid_str) { + uid_t uid =3D parse_uid(top.uid_str); =20 - status =3D -saved_errno; - goto out_delete_evlist; + if (uid =3D=3D UINT_MAX) { + ui__error("Invalid User: %s", top.uid_str); + status =3D -EINVAL; + goto out_delete_evlist; + } + status =3D parse_uid_filter(top.evlist, uid); + if (status) + goto out_delete_evlist; } =20 if (target__none(target)) diff --git a/tools/perf/util/top.c b/tools/perf/util/top.c index 4db3d1bd686c..b06e10a116bb 100644 --- a/tools/perf/util/top.c +++ b/tools/perf/util/top.c @@ -88,9 +88,9 @@ size_t perf_top__header_snprintf(struct perf_top *top, ch= ar *bf, size_t size) else if (target->tid) ret +=3D SNPRINTF(bf + ret, size - ret, " (target_tid: %s", target->tid); - else if (target->uid_str !=3D NULL) + else if (top->uid_str !=3D NULL) ret +=3D SNPRINTF(bf + ret, size - ret, " (uid: %s", - target->uid_str); + top->uid_str); else ret +=3D SNPRINTF(bf + ret, size - ret, " (all"); =20 diff --git a/tools/perf/util/top.h b/tools/perf/util/top.h index 4c5588dbb131..04ff926846be 100644 --- a/tools/perf/util/top.h +++ b/tools/perf/util/top.h @@ -48,6 +48,7 @@ struct perf_top { const char *sym_filter; float min_percent; unsigned int nr_threads_synthesize; + const char *uid_str; =20 struct { struct ordered_events *in; --=20 2.49.0.850.g28803427d3-goog From nobody Sun Feb 8 20:33:04 2026 Received: from mail-oa1-f74.google.com (mail-oa1-f74.google.com [209.85.160.74]) (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 28912233136 for ; Fri, 25 Apr 2025 21:40:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745617239; cv=none; b=Y3iOHnkjcyq2Hr0cUp7tvWzgrthuf06XyIom6u2S3JdQzeC/xieEJSXBVpexuArRyKah/ZgyM/6ER0uX3387p2RxvuQrMyKrnzXgxEmf1m57ODcNrjYx+gRgPdBbjdpRYG/RnwzuKRaGUGcPDw3lKFbxf0wHyZoHjAF9E91YS4c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745617239; c=relaxed/simple; bh=Mowkv5qqJ/F5GpiVJf300uqyE570+zdeev7heuBS7dE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=cyFIVfJrjHZel5g17BZfhdT0mSQLXIqkgKc4KZK7dUxlP4yMvrXYcZprS22fhLb4zHoiEgU2eWGSl2CKmOnoGSGlrkxznPLbJR6nLAiTNPBLQqIap++unwmP4VG82XdaZXlVUvvqR47UqgS/aYC+XL9pI7gau/wNlns7DclCzWc= 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=F0OtR/n/; arc=none smtp.client-ip=209.85.160.74 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="F0OtR/n/" Received: by mail-oa1-f74.google.com with SMTP id 586e51a60fabf-2c72e6e51ceso836289fac.3 for ; Fri, 25 Apr 2025 14:40:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1745617236; x=1746222036; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=MCiBNIgyIq3tfdIckzwQPIYGTlpSc1MEqAHEJmYBsOU=; b=F0OtR/n/fQy9LRG4SVceUixQ2QlE6KkYITdo+2Pt7T6YykS5pU0Moo8Ahn1W953rHH qq7qQL5wP0Ade5NzXr9nqEG5JEkaP1KnIP277FFN7y5gOqmy59OFzAZAqd1MNcqqAmQQ YeFpUPWNcEiSnotllGFyOHZaaE+p+yDzjzxxauv/2TSkaAcwYeJap7oT3uhjdV1E80gH vLHjYK4JGUGbob3Lqj0M1GIICHKcw23LjQtMU1KIfbc/XgaqQ6xsbM6tEd/uQH9n8WDM C2lIBYTrFd5s5j9uDgBqz8KjvxsJEijmbSVfFiKa2aFEgkOCX4C4/dHBEaryP7SLqaT1 Gwrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745617236; x=1746222036; h=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=MCiBNIgyIq3tfdIckzwQPIYGTlpSc1MEqAHEJmYBsOU=; b=IKo17OO+NWxcVTWmb/7NKFv+4ZK0lPRmkLaSGFOO1oxOhk1jlOuHXmJr26TBDMlW1t xZPkKr5Ws2m8Qr3MYoUPeF33KdK3hN5jr/1uG0Xrz599rRqOxOBG69Iw023y05TqbAUo xulkPLq+4NqQK1+KC1MpANhmXl6tJ+T8AZQE1YralYjre0kDEd17jEVw25vnZgEsgBIW bIw5qAr4EOKcKgOHJcDI9RJo5mz0oYORxn+LBhgFRieeObb/e8WOkwOlMfLB0gtS8CrY H8QPNoNC0ZjL4b9meTzBg9xtlNKvokBv/JDxz/4GGQTxOsYvxhotlyQXJ/lpBy3wbiVM aPEw== X-Forwarded-Encrypted: i=1; AJvYcCXAwGKs/jgj89/g0vzziSeRDGJabGY0xT1248jEDaqquq/cGjiZo5IEpZt7Ljny1T7Bg9IFILmOZYe/SXI=@vger.kernel.org X-Gm-Message-State: AOJu0YyFT7UyQMyu/nXecYFRHUXZW0ISTs0rxl01v2Z5lDchR6hTHN2J 1cXKzRyi0FifYD9Xy3OtQGTNzX0PwHwbJL15zqwzydzOKKr98CPw9+nbP/oqf409HDD+irGckgu WeFUavw== X-Google-Smtp-Source: AGHT+IEa2FLM10jcrrl+uJoBC09nP4IVEXI2lkCp+TFUaATjK6bauLtKrDXR6U2I/yDoVJ3h22f3O4wgOzrr X-Received: from oabwc14.prod.google.com ([2002:a05:6871:a50e:b0:2bc:6267:d082]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6870:a1a7:b0:2d0:3078:e72f with SMTP id 586e51a60fabf-2d99dc404cdmr2537739fac.26.1745617236166; Fri, 25 Apr 2025 14:40:36 -0700 (PDT) Date: Fri, 25 Apr 2025 14:40:05 -0700 In-Reply-To: <20250425214008.176100-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250425214008.176100-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.850.g28803427d3-goog Message-ID: <20250425214008.176100-8-irogers@google.com> Subject: [PATCH v3 07/10] perf trace: Switch user option to use BPF filter From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Dapeng Mi , Thomas Richter , Veronika Molnarova , Hao Ge , Howard Chu , Weilin Wang , Levi Yun , "Dr. David Alan Gilbert" , Dominique Martinet , Xu Yang , Tengda Wu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The existing --uid option finds user processes by scanning /proc. Scanning /proc is inherently racy due to processes being in /proc but then exiting before perf does the perf_event_open. When the perf_event_open fails perf will terminate reporting errors which is a disappointing user experience. Scanning /proc when perf starts also cannot inform perf of new user processes starting. The ability to filter perf events with BPF isn't new, and has been in the perf tool for 10 years: https://lore.kernel.org/all/1444826502-49291-8-git-send-email-wangnan0@huaw= ei.com/ An ability to do filtering on the command line with a BPF program that's part of perf was added 2 years ago: https://lore.kernel.org/all/20230314234237.3008956-1-namhyung@kernel.org/ This was then extended to support uids as a way of filtering: https://lore.kernel.org/all/20240524205227.244375-1-irogers@google.com/ This change switches the perf trace --uid option to use the BPF filter code to avoid the inherent race and existing failures. To ensure all processes are considered by the filter, the change forces system-wide mode. Using BPF has permission issues in loading the BPF program not present in scanning /proc. As the scanning approach would miss new programs and fail due to the race, this is considered preferable. The change also avoids opening a perf event per PID, which is less overhead in the kernel. Signed-off-by: Ian Rogers --- tools/perf/builtin-trace.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 6ac51925ea42..1f7d2b3d8b3d 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -240,6 +240,7 @@ struct trace { struct ordered_events data; u64 last; } oe; + const char *uid_str; }; =20 static void trace__load_vmlinux_btf(struct trace *trace __maybe_unused) @@ -4401,8 +4402,8 @@ static int trace__run(struct trace *trace, int argc, = const char **argv) evlist__add(evlist, pgfault_min); } =20 - /* Enable ignoring missing threads when -u/-p option is defined. */ - trace->opts.ignore_missing_thread =3D trace->opts.target.uid !=3D UINT_MA= X || trace->opts.target.pid; + /* Enable ignoring missing threads when -p option is defined. */ + trace->opts.ignore_missing_thread =3D trace->opts.target.pid; =20 if (trace->sched && evlist__add_newtp(evlist, "sched", "sched_stat_runtime", trace__sched= _stat_runtime)) @@ -5420,8 +5421,7 @@ int cmd_trace(int argc, const char **argv) "child tasks do not inherit counters"), OPT_CALLBACK('m', "mmap-pages", &trace.opts.mmap_pages, "pages", "number of mmap data pages", evlist__parse_mmap_pages), - OPT_STRING('u', "uid", &trace.opts.target.uid_str, "user", - "user to profile"), + OPT_STRING('u', "uid", &trace.uid_str, "user", "user to profile"), OPT_CALLBACK(0, "duration", &trace, "float", "show only events with duration > N.M ms", trace__set_duration), @@ -5762,11 +5762,19 @@ int cmd_trace(int argc, const char **argv) goto out_close; } =20 - err =3D target__parse_uid(&trace.opts.target); - if (err) { - target__strerror(&trace.opts.target, err, bf, sizeof(bf)); - fprintf(trace.output, "%s", bf); - goto out_close; + if (trace.uid_str) { + uid_t uid =3D parse_uid(trace.uid_str); + + if (uid =3D=3D UINT_MAX) { + ui__error("Invalid User: %s", trace.uid_str); + err =3D -EINVAL; + goto out_close; + } + err =3D parse_uid_filter(trace.evlist, uid); + if (err) + goto out_close; + + trace.opts.target.system_wide =3D true; } =20 if (!argc && target__none(&trace.opts.target)) --=20 2.49.0.850.g28803427d3-goog From nobody Sun Feb 8 20:33:04 2026 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.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 9C222238C10 for ; Fri, 25 Apr 2025 21:40:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745617240; cv=none; b=gzDPyqPnb1mATzNH5tjW+/H1ZRwmMw+yPh5yo/uNC7firCoE8xdCX6DQUd5E9UX+78I+eFs0IyxXzqh/6UPaSIJh1Q85K3h7CBrAK4JWaGkbAacpGuju+1y28PC7U6AETRHM3YKajrhs7THnJ0Rew/Jj26sg4WAKrn58VO24tLs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745617240; c=relaxed/simple; bh=7sThGMlojj0XQSMAaSSVxq437bh+PNtW6kO4Ul7euls=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=DpmB4YYksxnGhhfsSRVkjBGq+/YO1lsjnO5ZzqamWrBbtaoDTwanUeJ1wvXku+O8rDTYcghQN64pmLW0XbmpJcfcJSrcVCBMCWL6TkcWVpawoqRY+q2pbfEEKIDhkdle64ODNtt21BQnV8jagA/KhXjg4r27k/dfI1vyjbMbg6A= 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=zGn4dgkt; arc=none smtp.client-ip=209.85.214.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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="zGn4dgkt" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2242f3fd213so24529205ad.1 for ; Fri, 25 Apr 2025 14:40:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1745617238; x=1746222038; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=eYA6AZWIK6CayNWad0cBpPxgIziApDLZVOpF/REdjOE=; b=zGn4dgktwNXhplfOwpqchbYpMGquja7NDLdf4FQOUjdDoUDjrwyXBulA4QXoKacZTu /Bxw/+j90PIGx1PksymkxeEQU2c5TWniLfp1AIyNq7a9fQ3kkem6DSmWAysP62b5FYHk /qbp6BGR4U804kBbyda0Fy8zuFCl0Xo3lYDzTgDTOatP/mvKBYtD++zfC2YK9HovMd6A CHQct2z/P6Pqx51IIhr77tCCFX4JlnwQP1qjqZ9Zw2qLB0+XdldHcUXSJcK4vOq30bdf qG/QWIuR534EGzClep6gwWx1RfeYzYpUidbkqlDNBiuEEu5veXOfcJWa80lXq75EnoPk JgUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745617238; x=1746222038; h=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=eYA6AZWIK6CayNWad0cBpPxgIziApDLZVOpF/REdjOE=; b=MQUN1DakOCkbwL0wRwvk4eqyDDCnhBwJMytHoMZ29m+Wd9bxXrhzqanLlIxLwEhgKZ EP60K8ANmuJ8yVJyECt9piJth+AJzTpknnhbua4xzzo3haIak07xs5weMvY+Jq8/oKSt iyW/lq9qRsNYIjNjD4+DpG0+2jATJ8ZOqmQkNmxSeUBIvG/ynndEayDT/nLpWSl6tZN7 qVestPgTW1m9wHp7I/OavkxbGOsJRjfLuWTsiOu9HTOisvcPz7MVLlyaBnxWYCzidIPF iOim4LB7LFAH+tGn3fETgj0beHi8W09v5WYC3cZRvMLVrUt1X25ANJQLJfZZTlG9bAAu fs8g== X-Forwarded-Encrypted: i=1; AJvYcCXaIx7fX/JMffA42Mb9JMfRauLP9AA+uYxar+k3xCH1fs92P+sViYev+PgaKYBiXqGAyUlpUyaZhdgg3Ds=@vger.kernel.org X-Gm-Message-State: AOJu0Yz/y5W2FfdoySrNKiY+r1/p/oafFgheaZuxnelH6OOdm26RpXW/ /PF222GZeaGOQuYKO0GSGQNGIM8omVljZo98t/4DckvcoU1dx4mKmH7KvK68VPpzRvIOsO4DBfs Vo+n5Eg== X-Google-Smtp-Source: AGHT+IHTn5fXSVdxAGo0X1DREGkpHKj96NGB51yKJovIJ4pGCfpCEajtmcoknpGd2yTacuIeqaEDrGQ2lHTV X-Received: from pgc23.prod.google.com ([2002:a05:6a02:2f97:b0:b0b:2032:ef98]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:f60e:b0:224:c47:cb7 with SMTP id d9443c01a7336-22dc6809c39mr18556825ad.0.1745617238005; Fri, 25 Apr 2025 14:40:38 -0700 (PDT) Date: Fri, 25 Apr 2025 14:40:06 -0700 In-Reply-To: <20250425214008.176100-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250425214008.176100-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.850.g28803427d3-goog Message-ID: <20250425214008.176100-9-irogers@google.com> Subject: [PATCH v3 08/10] perf bench evlist-open-close: Switch user option to use BPF filter From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Dapeng Mi , Thomas Richter , Veronika Molnarova , Hao Ge , Howard Chu , Weilin Wang , Levi Yun , "Dr. David Alan Gilbert" , Dominique Martinet , Xu Yang , Tengda Wu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The existing --uid option finds user processes by scanning /proc. Scanning /proc is inherently racy due to processes being in /proc but then exiting before perf does the perf_event_open. When the perf_event_open fails perf will terminate reporting errors which is a disappointing user experience. Scanning /proc when perf starts also cannot inform perf of new user processes starting. The ability to filter perf events with BPF isn't new, and has been in the perf tool for 10 years: https://lore.kernel.org/all/1444826502-49291-8-git-send-email-wangnan0@huaw= ei.com/ An ability to do filtering on the command line with a BPF program that's part of perf was added 2 years ago: https://lore.kernel.org/all/20230314234237.3008956-1-namhyung@kernel.org/ This was then extended to support uids as a way of filtering: https://lore.kernel.org/all/20240524205227.244375-1-irogers@google.com/ This change switches the benchmark's --uid option to use the BPF filter code to avoid the inherent race and existing failures. Using BPF has permission issues in loading the BPF program not present in scanning /proc. As the scanning approach would miss new programs and fail due to the race, this is considered preferable. The change also avoids opening a perf event per PID, which is less overhead in the kernel. Signed-off-by: Ian Rogers --- tools/perf/bench/evlist-open-close.c | 36 ++++++++++++++++------------ 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/tools/perf/bench/evlist-open-close.c b/tools/perf/bench/evlist= -open-close.c index 79cedcf94a39..bfaf50e4e519 100644 --- a/tools/perf/bench/evlist-open-close.c +++ b/tools/perf/bench/evlist-open-close.c @@ -57,7 +57,7 @@ static int evlist__count_evsel_fds(struct evlist *evlist) return cnt; } =20 -static struct evlist *bench__create_evlist(char *evstr) +static struct evlist *bench__create_evlist(char *evstr, const char *uid_st= r) { struct parse_events_error err; struct evlist *evlist =3D evlist__new(); @@ -78,6 +78,18 @@ static struct evlist *bench__create_evlist(char *evstr) goto out_delete_evlist; } parse_events_error__exit(&err); + if (uid_str) { + uid_t uid =3D parse_uid(uid_str); + + if (uid =3D=3D UINT_MAX) { + pr_err("Invalid User: %s", uid_str); + ret =3D -EINVAL; + goto out_delete_evlist; + } + ret =3D parse_uid_filter(evlist, uid); + if (ret) + goto out_delete_evlist; + } ret =3D evlist__create_maps(evlist, &opts.target); if (ret < 0) { pr_err("Not enough memory to create thread/cpu maps\n"); @@ -117,10 +129,10 @@ static int bench__do_evlist_open_close(struct evlist = *evlist) return 0; } =20 -static int bench_evlist_open_close__run(char *evstr) +static int bench_evlist_open_close__run(char *evstr, const char *uid_str) { // used to print statistics only - struct evlist *evlist =3D bench__create_evlist(evstr); + struct evlist *evlist =3D bench__create_evlist(evstr, uid_str); double time_average, time_stddev; struct timeval start, end, diff; struct stats time_stats; @@ -142,7 +154,7 @@ static int bench_evlist_open_close__run(char *evstr) =20 for (i =3D 0; i < iterations; i++) { pr_debug("Started iteration %d\n", i); - evlist =3D bench__create_evlist(evstr); + evlist =3D bench__create_evlist(evstr, uid_str); if (!evlist) return -ENOMEM; =20 @@ -206,6 +218,7 @@ static char *bench__repeat_event_string(const char *evs= tr, int n) =20 int bench_evlist_open_close(int argc, const char **argv) { + const char *uid_str =3D NULL; const struct option options[] =3D { OPT_STRING('e', "event", &event_string, "event", "event selector. use 'perf list' to list available events"), @@ -221,7 +234,7 @@ int bench_evlist_open_close(int argc, const char **argv) "record events on existing process id"), OPT_STRING('t', "tid", &opts.target.tid, "tid", "record events on existing thread id"), - OPT_STRING('u', "uid", &opts.target.uid_str, "user", "user to profile"), + OPT_STRING('u', "uid", &uid_str, "user", "user to profile"), OPT_BOOLEAN(0, "per-thread", &opts.target.per_thread, "use per-thread mm= aps"), OPT_END() }; @@ -245,15 +258,8 @@ int bench_evlist_open_close(int argc, const char **arg= v) goto out; } =20 - err =3D target__parse_uid(&opts.target); - if (err) { - target__strerror(&opts.target, err, errbuf, sizeof(errbuf)); - pr_err("%s", errbuf); - goto out; - } - - /* Enable ignoring missing threads when -u/-p option is defined. */ - opts.ignore_missing_thread =3D opts.target.uid !=3D UINT_MAX || opts.targ= et.pid; + /* Enable ignoring missing threads when -p option is defined. */ + opts.ignore_missing_thread =3D opts.target.pid; =20 evstr =3D bench__repeat_event_string(event_string, nr_events); if (!evstr) { @@ -261,7 +267,7 @@ int bench_evlist_open_close(int argc, const char **argv) goto out; } =20 - err =3D bench_evlist_open_close__run(evstr); + err =3D bench_evlist_open_close__run(evstr, uid_str); =20 free(evstr); out: --=20 2.49.0.850.g28803427d3-goog From nobody Sun Feb 8 20:33:04 2026 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.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 BF51F24E4A9 for ; Fri, 25 Apr 2025 21:40:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745617242; cv=none; b=QSzuEzrt4yXiyW+Nuyi4NB4fOKjzzczoZ0Tolph3imt+0QwrWFx7BNq0VuxK1xJknuKfFxYxGb3/fAAG4LMBcOyPmaUe70D60er5MMAd6E+ttwmGlbZuPYuomE5bbToPj9Miun6PfH86Mx9f/bJRHph3hRGDypD0072ObQz2qNI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745617242; c=relaxed/simple; bh=txG5RZ/s604iECqbAkxhFGWQwLHjQHTg9L+54iRXeXg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=CJxjwUsJjuPUQBCy8kVeigkw752uZVwYwQAgj6d0l/dLVNIIQbmHwbSRyDAzNrW1jjktxUefWlzSSCO3aTbWsKPNlpFYDa5UJvHs0ySlyoVLtf8cAkfRweKHpK+0dUNvKMu7vPd3RJ4C4N6vgbv51vD4dB3fvbaRth3X3k8CQYc= 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=KFtOvyjQ; arc=none smtp.client-ip=209.85.215.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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="KFtOvyjQ" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b15e08f1eb4so1529239a12.0 for ; Fri, 25 Apr 2025 14:40:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1745617240; x=1746222040; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=Y+o0y2Xr/2vqMuWaMFlJgPCAPqw/FYZ1X/ud/CGzIhA=; b=KFtOvyjQxX92dBTdPuPytltNrzaWN7xeW++jUClGApnBwvk/Ui+4VIlljaME4H3nvJ da7efmhic7wIrvoHGhwRDYh6ldPvdG1spnTz23UGw4FuHW7GPzCMjxWUhSClcIBV57lw m2BiM9iQG20gcwvOI3uKvgZLBb541MATpFLVswBe2ENCuRqlP59TQd19HDNMOQUeBXIR c4Wr1unQq3tYPWbQcj9IyN8JPXOECc+Iid2KIB2B0QEPiV/PrlamR9NQkGfDN6LKxD9Q MfTVPYa2f/LikAcUmaN+ablkxtk6bVVdRJwecjlsTnHIY3QCFS/lAtGnyGvMRPYiyXoE kIog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745617240; x=1746222040; h=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=Y+o0y2Xr/2vqMuWaMFlJgPCAPqw/FYZ1X/ud/CGzIhA=; b=OtreKpSQPNc++1L5oQSPURNXueznLNCqu8um25oB7Z9Z2hRezgKG9xzwNt4t6BUzu2 1fEYsesRjr+IYoGckl+ErynFndDIffKrnoyP8E6cNShuZDf17O6PASM5k10ZbXtl+wuK fTXzfYXQemzQrZAbj69xHj+/hV/Lo585TJB+xQzj35Ti+TR3sl7wRkjf6MjIl0M0qbhM 2A4rM0GUceSQSqs13HIus+GCfOdAZ5Mc1th2Jl40Utj3L0qB7+zKcCAxbnGsQc7EXn+p 9IqEwdjBCKI9gJT5Ud2zS+P/3lH4mzQ3i2E7OlGfgwJ2LdBSAQsec7jdR+hbjVkUkQWH 6qlQ== X-Forwarded-Encrypted: i=1; AJvYcCXsjE0/3St7vrVpLQn/e526TGXhGyVCGxFoC+5ekAUat6OYodNup3iSk932CPPMonLbVGnaHUl61LKCoP4=@vger.kernel.org X-Gm-Message-State: AOJu0YwbLg9Z0C0SI/7L287QhtCKCHouxYM8PtZADDuWMuYU6daglJzy qghnb45C6CC7v7M6aB1Kvqe7COMsJeDRIfn1tOcYCMDj2ss28i3tZhquLUN26K0dWEr0qIZzEu8 QqpIATg== X-Google-Smtp-Source: AGHT+IFDoNOY10ZJCIMJHlocxbHQOatRaPfj34HXRIwx+RZyBDPer7aT+TN7oy11z+Psyw7MTMSK0mkzesDr X-Received: from pgns27.prod.google.com ([2002:a63:925b:0:b0:af0:e359:c50a]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:c707:b0:1f5:8754:324d with SMTP id adf61e73a8af0-2045b6c213fmr5225680637.9.1745617240108; Fri, 25 Apr 2025 14:40:40 -0700 (PDT) Date: Fri, 25 Apr 2025 14:40:07 -0700 In-Reply-To: <20250425214008.176100-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250425214008.176100-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.850.g28803427d3-goog Message-ID: <20250425214008.176100-10-irogers@google.com> Subject: [PATCH v3 09/10] perf target: Remove uid from target From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Dapeng Mi , Thomas Richter , Veronika Molnarova , Hao Ge , Howard Chu , Weilin Wang , Levi Yun , "Dr. David Alan Gilbert" , Dominique Martinet , Xu Yang , Tengda Wu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Gathering threads with a uid by scanning /proc is inherently racy leading to perf_event_open failures that quit perf. It also misses new processes a user starts. All users of the target functionality now use BPF filters, so remove uid and uid_str from target. Signed-off-by: Ian Rogers --- tools/perf/builtin-ftrace.c | 1 - tools/perf/builtin-kvm.c | 2 - tools/perf/builtin-stat.c | 4 +- tools/perf/builtin-trace.c | 1 - tools/perf/tests/backward-ring-buffer.c | 1 - tools/perf/tests/event-times.c | 4 +- tools/perf/tests/openat-syscall-tp-fields.c | 1 - tools/perf/tests/perf-record.c | 1 - tools/perf/tests/task-exit.c | 1 - tools/perf/util/bpf-filter.c | 2 +- tools/perf/util/evlist.c | 3 +- tools/perf/util/target.c | 46 +-------------------- tools/perf/util/target.h | 12 +----- 13 files changed, 6 insertions(+), 73 deletions(-) diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c index 7caa18d5ffc3..ae901f2a18ef 100644 --- a/tools/perf/builtin-ftrace.c +++ b/tools/perf/builtin-ftrace.c @@ -1590,7 +1590,6 @@ int cmd_ftrace(int argc, const char **argv) int (*cmd_func)(struct perf_ftrace *) =3D NULL; struct perf_ftrace ftrace =3D { .tracer =3D DEFAULT_TRACER, - .target =3D { .uid =3D UINT_MAX, }, }; const struct option common_options[] =3D { OPT_STRING('p', "pid", &ftrace.target.pid, "pid", diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 67fd2b006b0b..d75bd3684980 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -1871,8 +1871,6 @@ static int kvm_events_live(struct perf_kvm_stat *kvm, kvm->opts.user_interval =3D 1; kvm->opts.mmap_pages =3D 512; kvm->opts.target.uses_mmap =3D false; - kvm->opts.target.uid_str =3D NULL; - kvm->opts.target.uid =3D UINT_MAX; =20 symbol__init(NULL); disable_buildid_cache(); diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 300b6393bb41..c2ed49ff2048 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -108,9 +108,7 @@ static struct parse_events_option_args parse_events_opt= ion_args =3D { =20 static bool all_counters_use_bpf =3D true; =20 -static struct target target =3D { - .uid =3D UINT_MAX, -}; +static struct target target; =20 static volatile sig_atomic_t child_pid =3D -1; static int detailed_run =3D 0; diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 1f7d2b3d8b3d..aa0a27dd7d21 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -5374,7 +5374,6 @@ int cmd_trace(int argc, const char **argv) struct trace trace =3D { .opts =3D { .target =3D { - .uid =3D UINT_MAX, .uses_mmap =3D true, }, .user_freq =3D UINT_MAX, diff --git a/tools/perf/tests/backward-ring-buffer.c b/tools/perf/tests/bac= kward-ring-buffer.c index 79a980b1e786..c5e7999f2817 100644 --- a/tools/perf/tests/backward-ring-buffer.c +++ b/tools/perf/tests/backward-ring-buffer.c @@ -91,7 +91,6 @@ static int test__backward_ring_buffer(struct test_suite *= test __maybe_unused, in struct parse_events_error parse_error; struct record_opts opts =3D { .target =3D { - .uid =3D UINT_MAX, .uses_mmap =3D true, }, .freq =3D 0, diff --git a/tools/perf/tests/event-times.c b/tools/perf/tests/event-times.c index deefe5003bfc..2148024b4f4a 100644 --- a/tools/perf/tests/event-times.c +++ b/tools/perf/tests/event-times.c @@ -17,9 +17,7 @@ static int attach__enable_on_exec(struct evlist *evlist) { struct evsel *evsel =3D evlist__last(evlist); - struct target target =3D { - .uid =3D UINT_MAX, - }; + struct target target =3D {}; const char *argv[] =3D { "true", NULL, }; char sbuf[STRERR_BUFSIZE]; int err; diff --git a/tools/perf/tests/openat-syscall-tp-fields.c b/tools/perf/tests= /openat-syscall-tp-fields.c index 0ef4ba7c1571..2a139d2781a8 100644 --- a/tools/perf/tests/openat-syscall-tp-fields.c +++ b/tools/perf/tests/openat-syscall-tp-fields.c @@ -28,7 +28,6 @@ static int test__syscall_openat_tp_fields(struct test_sui= te *test __maybe_unused { struct record_opts opts =3D { .target =3D { - .uid =3D UINT_MAX, .uses_mmap =3D true, }, .no_buffering =3D true, diff --git a/tools/perf/tests/perf-record.c b/tools/perf/tests/perf-record.c index 0958c7c8995f..0b3c37e66871 100644 --- a/tools/perf/tests/perf-record.c +++ b/tools/perf/tests/perf-record.c @@ -45,7 +45,6 @@ static int test__PERF_RECORD(struct test_suite *test __ma= ybe_unused, int subtest { struct record_opts opts =3D { .target =3D { - .uid =3D UINT_MAX, .uses_mmap =3D true, }, .no_buffering =3D true, diff --git a/tools/perf/tests/task-exit.c b/tools/perf/tests/task-exit.c index 8e328bbd509d..4053ff2813bb 100644 --- a/tools/perf/tests/task-exit.c +++ b/tools/perf/tests/task-exit.c @@ -46,7 +46,6 @@ static int test__task_exit(struct test_suite *test __mayb= e_unused, int subtest _ struct evsel *evsel; struct evlist *evlist; struct target target =3D { - .uid =3D UINT_MAX, .uses_mmap =3D true, }; const char *argv[] =3D { "true", NULL }; diff --git a/tools/perf/util/bpf-filter.c b/tools/perf/util/bpf-filter.c index a4fdf6911ec1..ed4845ff4a10 100644 --- a/tools/perf/util/bpf-filter.c +++ b/tools/perf/util/bpf-filter.c @@ -449,7 +449,7 @@ int perf_bpf_filter__prepare(struct evsel *evsel, struc= t target *target) struct bpf_program *prog; struct bpf_link *link; struct perf_bpf_filter_entry *entry; - bool needs_idx_hash =3D !target__has_cpu(target) && !target->uid_str; + bool needs_idx_hash =3D !target__has_cpu(target); =20 entry =3D calloc(MAX_FILTERS, sizeof(*entry)); if (entry =3D=3D NULL) diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 0a21da4f990f..86b11ffc09b7 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -1005,8 +1005,7 @@ int evlist__create_maps(struct evlist *evlist, struct= target *target) * per-thread data. thread_map__new_str will call * thread_map__new_all_cpus to enumerate all threads. */ - threads =3D thread_map__new_str(target->pid, target->tid, target->uid, - all_threads); + threads =3D thread_map__new_str(target->pid, target->tid, UINT_MAX, all_t= hreads); =20 if (!threads) return -1; diff --git a/tools/perf/util/target.c b/tools/perf/util/target.c index f3ad59ccfa99..8cf71bea295a 100644 --- a/tools/perf/util/target.c +++ b/tools/perf/util/target.c @@ -28,20 +28,6 @@ enum target_errno target__validate(struct target *target) ret =3D TARGET_ERRNO__PID_OVERRIDE_CPU; } =20 - /* UID and PID are mutually exclusive */ - if (target->tid && target->uid_str) { - target->uid_str =3D NULL; - if (ret =3D=3D TARGET_ERRNO__SUCCESS) - ret =3D TARGET_ERRNO__PID_OVERRIDE_UID; - } - - /* UID and CPU are mutually exclusive */ - if (target->uid_str && target->cpu_list) { - target->cpu_list =3D NULL; - if (ret =3D=3D TARGET_ERRNO__SUCCESS) - ret =3D TARGET_ERRNO__UID_OVERRIDE_CPU; - } - /* PID and SYSTEM are mutually exclusive */ if (target->tid && target->system_wide) { target->system_wide =3D false; @@ -49,13 +35,6 @@ enum target_errno target__validate(struct target *target) ret =3D TARGET_ERRNO__PID_OVERRIDE_SYSTEM; } =20 - /* UID and SYSTEM are mutually exclusive */ - if (target->uid_str && target->system_wide) { - target->system_wide =3D false; - if (ret =3D=3D TARGET_ERRNO__SUCCESS) - ret =3D TARGET_ERRNO__UID_OVERRIDE_SYSTEM; - } - /* BPF and CPU are mutually exclusive */ if (target->bpf_str && target->cpu_list) { target->cpu_list =3D NULL; @@ -70,13 +49,6 @@ enum target_errno target__validate(struct target *target) ret =3D TARGET_ERRNO__BPF_OVERRIDE_PID; } =20 - /* BPF and UID are mutually exclusive */ - if (target->bpf_str && target->uid_str) { - target->uid_str =3D NULL; - if (ret =3D=3D TARGET_ERRNO__SUCCESS) - ret =3D TARGET_ERRNO__BPF_OVERRIDE_UID; - } - /* BPF and THREADS are mutually exclusive */ if (target->bpf_str && target->per_thread) { target->per_thread =3D false; @@ -124,31 +96,19 @@ uid_t parse_uid(const char *str) return result->pw_uid; } =20 -enum target_errno target__parse_uid(struct target *target) -{ - target->uid =3D parse_uid(target->uid_str); - - return target->uid !=3D UINT_MAX ? TARGET_ERRNO__SUCCESS : TARGET_ERRNO__= INVALID_UID; -} - /* * This must have a same ordering as the enum target_errno. */ static const char *target__error_str[] =3D { "PID/TID switch overriding CPU", - "PID/TID switch overriding UID", - "UID switch overriding CPU", "PID/TID switch overriding SYSTEM", - "UID switch overriding SYSTEM", "SYSTEM/CPU switch overriding PER-THREAD", "BPF switch overriding CPU", "BPF switch overriding PID/TID", - "BPF switch overriding UID", "BPF switch overriding THREAD", - "Invalid User: %s", }; =20 -int target__strerror(struct target *target, int errnum, +int target__strerror(struct target *target __maybe_unused, int errnum, char *buf, size_t buflen) { int idx; @@ -173,10 +133,6 @@ int target__strerror(struct target *target, int errnum, snprintf(buf, buflen, "%s", msg); break; =20 - case TARGET_ERRNO__INVALID_UID: - snprintf(buf, buflen, msg, target->uid_str); - break; - default: /* cannot reach here */ break; diff --git a/tools/perf/util/target.h b/tools/perf/util/target.h index e082bda990fb..84ebb9c940c6 100644 --- a/tools/perf/util/target.h +++ b/tools/perf/util/target.h @@ -9,9 +9,7 @@ struct target { const char *pid; const char *tid; const char *cpu_list; - const char *uid_str; const char *bpf_str; - uid_t uid; bool system_wide; bool uses_mmap; bool default_per_cpu; @@ -36,32 +34,24 @@ enum target_errno { =20 /* for target__validate() */ TARGET_ERRNO__PID_OVERRIDE_CPU =3D __TARGET_ERRNO__START, - TARGET_ERRNO__PID_OVERRIDE_UID, - TARGET_ERRNO__UID_OVERRIDE_CPU, TARGET_ERRNO__PID_OVERRIDE_SYSTEM, - TARGET_ERRNO__UID_OVERRIDE_SYSTEM, TARGET_ERRNO__SYSTEM_OVERRIDE_THREAD, TARGET_ERRNO__BPF_OVERRIDE_CPU, TARGET_ERRNO__BPF_OVERRIDE_PID, - TARGET_ERRNO__BPF_OVERRIDE_UID, TARGET_ERRNO__BPF_OVERRIDE_THREAD, =20 - /* for target__parse_uid() */ - TARGET_ERRNO__INVALID_UID, - __TARGET_ERRNO__END, }; =20 enum target_errno target__validate(struct target *target); =20 uid_t parse_uid(const char *str); -enum target_errno target__parse_uid(struct target *target); =20 int target__strerror(struct target *target, int errnum, char *buf, size_t = buflen); =20 static inline bool target__has_task(struct target *target) { - return target->tid || target->pid || target->uid_str; + return target->tid || target->pid; } =20 static inline bool target__has_cpu(struct target *target) --=20 2.49.0.850.g28803427d3-goog From nobody Sun Feb 8 20:33:04 2026 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.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 0A94B25DB0A for ; Fri, 25 Apr 2025 21:40:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745617245; cv=none; b=cbOWoIV7wWtFmrIhpTPMa+dQSVrGVpnVhncC+Dvnix222EoF4+9xD2IG5k+qMxIssnGFx6jCE7/SVvEXZn9RQ+I3n2Ns+7uBY/OeEkuUmVIbeWeDV2Qnb1XMS9qmB9ulD56mRQBA3h8dIc6pA4zIrrCduP47LnO44R5ybC2zt2c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745617245; c=relaxed/simple; bh=civL0ptmakP58BNTG6qRL/WfDNW9+VMZdvD44UQo1N4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=AeAPb3PkOIsmkWwZahN1AjnA2w8uu+eUnqquNeFSif6L1mXmcTz4Px/LRd6KgekkKuNAO9CZJwkUXOe0DQPd8iBHASQrQpQor2SLbIlkR0rgF7ubrMLuz2imyy5x9lLNO+uVRsy5hX5WhWf8zspwb9ARK3KKlRPkXz5/fOJ0590= 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=FZyxdf6v; arc=none smtp.client-ip=209.85.215.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="FZyxdf6v" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-af534e796baso1520388a12.3 for ; Fri, 25 Apr 2025 14:40:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1745617242; x=1746222042; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=PD/2gZzkdXqRjrGcRCMV5rPK+HPN6vuWAJ5aTNU/fMM=; b=FZyxdf6vIfEcVTxzWPLDxtB/ss62ZbMaPY2EO74jLnfNzg1DDlsj0TzYY0eWgcS0O0 34U2bPtfXzFadLZSTDto9UqDc57O4a4S8yZ8iN2HXr/aVH8AGnzCp99bb3cZT927kP0y bHaBmjFyTSi7BFhOoeivehYOrraMaoaQoEQBLltjaEAQVkIQR1tXB9s0rwBlPCdMcS+e 05Udm+ZGOOcGboOzABIdoN4g+wNFBe0nesHLEZ+mrw7NBEm/yT6QYQ5copaeHgH12dt5 lj7HcF1RAhuNaFJPwqxsu4bK6SWGsTaUsa+4HEfPCkuXStgUOw7Nr2Py9V1V0pvdFYNp TC4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745617242; x=1746222042; h=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=PD/2gZzkdXqRjrGcRCMV5rPK+HPN6vuWAJ5aTNU/fMM=; b=gEXrUneA/+qtTJBHfrrBHJtrOsn6lJZ3Mje9X67Id5Dmyus5LEoL7HdRGYHiyFvdRL obo1+nEtGIYh8LHwot8lDj8gKmONeM4J4qNc7KGwnkollVEQKmjF4QQmHtQPD9Rf6hG6 z3HiMNUJGTiiqyeCCxSs5SCv8plGd+RMomecCN0NgrU7nSuXXDNlI2FerQfpLKFdh+N+ 83uV3pLAk6Jty1bLOL/zArmk0bLbMjeoIRI5DF3rZuhuxpj3jRZoT4now52C1VLdJrld dIoS1lMnXGCkDSO8G8iUJI9lZwbaw/H/nTlUXdDmUd7WaMvrl6JZMZtaHLm4/fPD+Rqr +LZw== X-Forwarded-Encrypted: i=1; AJvYcCXCWhf2D1aLmXBQcZbQ0TBZShjjjazRK2eA/rgKqqt8Dm6MRzgjeuG4FKWeA0x6k9rDF9U67wp3HBJGENo=@vger.kernel.org X-Gm-Message-State: AOJu0YzZBRA7posm438ktH/qmXnsi6Wao77E6tqrMyPHQ7xPR+LZeNcf lgr7pGPsFwxGAP9efbo5o3H8l9YVjH4uyHRvOnM9gaTabdzILAyz4KqM6nQ9FNm0/VqG89k9+sc hshUQvg== X-Google-Smtp-Source: AGHT+IFCtEhRCBjDW2a8s4jRDfOQsUoZ7gsKizv5ygUaW1sjDqLjtvAoq2pOpHphbv7xIzozUy8B6xlFSZN6 X-Received: from pgbee7.prod.google.com ([2002:a05:6a02:4587:b0:b16:7375:98d2]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:6d8c:b0:1f5:8e04:f186 with SMTP id adf61e73a8af0-2045b9c0068mr5774268637.35.1745617242379; Fri, 25 Apr 2025 14:40:42 -0700 (PDT) Date: Fri, 25 Apr 2025 14:40:08 -0700 In-Reply-To: <20250425214008.176100-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250425214008.176100-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.850.g28803427d3-goog Message-ID: <20250425214008.176100-11-irogers@google.com> Subject: [PATCH v3 10/10] perf thread_map: Remove uid options From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Dapeng Mi , Thomas Richter , Veronika Molnarova , Hao Ge , Howard Chu , Weilin Wang , Levi Yun , "Dr. David Alan Gilbert" , Dominique Martinet , Xu Yang , Tengda Wu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now the target doesn't have a uid, it is handled through BPF filters, remove the uid options to thread_map creation. Tidy up the functions used in tests to avoid passing unused arguments. Signed-off-by: Ian Rogers --- tools/perf/tests/event-times.c | 4 +-- tools/perf/tests/keep-tracking.c | 2 +- tools/perf/tests/mmap-basic.c | 2 +- tools/perf/tests/openat-syscall-all-cpus.c | 2 +- tools/perf/tests/openat-syscall.c | 2 +- tools/perf/tests/perf-time-to-tsc.c | 2 +- tools/perf/tests/switch-tracking.c | 2 +- tools/perf/tests/thread-map.c | 2 +- tools/perf/util/evlist.c | 2 +- tools/perf/util/python.c | 10 +++---- tools/perf/util/thread_map.c | 32 ++-------------------- tools/perf/util/thread_map.h | 6 ++-- 12 files changed, 20 insertions(+), 48 deletions(-) diff --git a/tools/perf/tests/event-times.c b/tools/perf/tests/event-times.c index 2148024b4f4a..ae3b98bb42cf 100644 --- a/tools/perf/tests/event-times.c +++ b/tools/perf/tests/event-times.c @@ -62,7 +62,7 @@ static int attach__current_disabled(struct evlist *evlist) =20 pr_debug("attaching to current thread as disabled\n"); =20 - threads =3D thread_map__new(-1, getpid(), UINT_MAX); + threads =3D thread_map__new_by_tid(getpid()); if (threads =3D=3D NULL) { pr_debug("thread_map__new\n"); return -1; @@ -88,7 +88,7 @@ static int attach__current_enabled(struct evlist *evlist) =20 pr_debug("attaching to current thread as enabled\n"); =20 - threads =3D thread_map__new(-1, getpid(), UINT_MAX); + threads =3D thread_map__new_by_tid(getpid()); if (threads =3D=3D NULL) { pr_debug("failed to call thread_map__new\n"); return -1; diff --git a/tools/perf/tests/keep-tracking.c b/tools/perf/tests/keep-track= ing.c index 5a3b2bed07f3..eafb49eb0b56 100644 --- a/tools/perf/tests/keep-tracking.c +++ b/tools/perf/tests/keep-tracking.c @@ -78,7 +78,7 @@ static int test__keep_tracking(struct test_suite *test __= maybe_unused, int subte int found, err =3D -1; const char *comm; =20 - threads =3D thread_map__new(-1, getpid(), UINT_MAX); + threads =3D thread_map__new_by_tid(getpid()); CHECK_NOT_NULL__(threads); =20 cpus =3D perf_cpu_map__new_online_cpus(); diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c index bd2106628b34..04b547c6bdbe 100644 --- a/tools/perf/tests/mmap-basic.c +++ b/tools/perf/tests/mmap-basic.c @@ -46,7 +46,7 @@ static int test__basic_mmap(struct test_suite *test __may= be_unused, int subtest char sbuf[STRERR_BUFSIZE]; struct mmap *md; =20 - threads =3D thread_map__new(-1, getpid(), UINT_MAX); + threads =3D thread_map__new_by_tid(getpid()); if (threads =3D=3D NULL) { pr_debug("thread_map__new\n"); return -1; diff --git a/tools/perf/tests/openat-syscall-all-cpus.c b/tools/perf/tests/= openat-syscall-all-cpus.c index fb114118c876..3644d6f52c07 100644 --- a/tools/perf/tests/openat-syscall-all-cpus.c +++ b/tools/perf/tests/openat-syscall-all-cpus.c @@ -28,7 +28,7 @@ static int test__openat_syscall_event_on_all_cpus(struct = test_suite *test __mayb struct evsel *evsel; unsigned int nr_openat_calls =3D 111, i; cpu_set_t cpu_set; - struct perf_thread_map *threads =3D thread_map__new(-1, getpid(), UINT_MA= X); + struct perf_thread_map *threads =3D thread_map__new_by_tid(getpid()); char sbuf[STRERR_BUFSIZE]; char errbuf[BUFSIZ]; =20 diff --git a/tools/perf/tests/openat-syscall.c b/tools/perf/tests/openat-sy= scall.c index 131b62271bfa..b54cbe5f1808 100644 --- a/tools/perf/tests/openat-syscall.c +++ b/tools/perf/tests/openat-syscall.c @@ -20,7 +20,7 @@ static int test__openat_syscall_event(struct test_suite *= test __maybe_unused, int err =3D TEST_FAIL, fd; struct evsel *evsel; unsigned int nr_openat_calls =3D 111, i; - struct perf_thread_map *threads =3D thread_map__new(-1, getpid(), UINT_MA= X); + struct perf_thread_map *threads =3D thread_map__new_by_tid(getpid()); char sbuf[STRERR_BUFSIZE]; char errbuf[BUFSIZ]; =20 diff --git a/tools/perf/tests/perf-time-to-tsc.c b/tools/perf/tests/perf-ti= me-to-tsc.c index d3e40fa5482c..d4437410c99f 100644 --- a/tools/perf/tests/perf-time-to-tsc.c +++ b/tools/perf/tests/perf-time-to-tsc.c @@ -90,7 +90,7 @@ static int test__perf_time_to_tsc(struct test_suite *test= __maybe_unused, int su struct mmap *md; =20 =20 - threads =3D thread_map__new(-1, getpid(), UINT_MAX); + threads =3D thread_map__new_by_tid(getpid()); CHECK_NOT_NULL__(threads); =20 cpus =3D perf_cpu_map__new_online_cpus(); diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-t= racking.c index 8df3f9d9ffd2..96f880c922d1 100644 --- a/tools/perf/tests/switch-tracking.c +++ b/tools/perf/tests/switch-tracking.c @@ -351,7 +351,7 @@ static int test__switch_tracking(struct test_suite *tes= t __maybe_unused, int sub const char *comm; int err =3D -1; =20 - threads =3D thread_map__new(-1, getpid(), UINT_MAX); + threads =3D thread_map__new_by_tid(getpid()); if (!threads) { pr_debug("thread_map__new failed!\n"); goto out_err; diff --git a/tools/perf/tests/thread-map.c b/tools/perf/tests/thread-map.c index 1fe521466bf4..54209592168d 100644 --- a/tools/perf/tests/thread-map.c +++ b/tools/perf/tests/thread-map.c @@ -115,7 +115,7 @@ static int test__thread_map_remove(struct test_suite *t= est __maybe_unused, int s TEST_ASSERT_VAL("failed to allocate map string", asprintf(&str, "%d,%d", getpid(), getppid()) >=3D 0); =20 - threads =3D thread_map__new_str(str, NULL, 0, false); + threads =3D thread_map__new_str(str, /*tid=3D*/NULL, /*all_threads=3D*/fa= lse); free(str); =20 TEST_ASSERT_VAL("failed to allocate thread_map", diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 86b11ffc09b7..ba9e69b5acba 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -1005,7 +1005,7 @@ int evlist__create_maps(struct evlist *evlist, struct= target *target) * per-thread data. thread_map__new_str will call * thread_map__new_all_cpus to enumerate all threads. */ - threads =3D thread_map__new_str(target->pid, target->tid, UINT_MAX, all_t= hreads); + threads =3D thread_map__new_str(target->pid, target->tid, all_threads); =20 if (!threads) return -1; diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index f3c05da25b4a..56f8ae4cebf7 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -566,14 +566,14 @@ struct pyrf_thread_map { static int pyrf_thread_map__init(struct pyrf_thread_map *pthreads, PyObject *args, PyObject *kwargs) { - static char *kwlist[] =3D { "pid", "tid", "uid", NULL }; - int pid =3D -1, tid =3D -1, uid =3D UINT_MAX; + static char *kwlist[] =3D { "pid", "tid", NULL }; + int pid =3D -1, tid =3D -1; =20 - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|iii", - kwlist, &pid, &tid, &uid)) + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ii", + kwlist, &pid, &tid)) return -1; =20 - pthreads->threads =3D thread_map__new(pid, tid, uid); + pthreads->threads =3D thread_map__new(pid, tid); if (pthreads->threads =3D=3D NULL) return -1; return 0; diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c index b5f12390c355..ca193c1374ed 100644 --- a/tools/perf/util/thread_map.c +++ b/tools/perf/util/thread_map.c @@ -72,7 +72,7 @@ struct perf_thread_map *thread_map__new_by_tid(pid_t tid) return threads; } =20 -static struct perf_thread_map *__thread_map__new_all_cpus(uid_t uid) +static struct perf_thread_map *thread_map__new_all_cpus(void) { DIR *proc; int max_threads =3D 32, items, i; @@ -98,15 +98,6 @@ static struct perf_thread_map *__thread_map__new_all_cpu= s(uid_t uid) if (*end) /* only interested in proper numerical dirents */ continue; =20 - snprintf(path, sizeof(path), "/proc/%s", dirent->d_name); - - if (uid !=3D UINT_MAX) { - struct stat st; - - if (stat(path, &st) !=3D 0 || st.st_uid !=3D uid) - continue; - } - snprintf(path, sizeof(path), "/proc/%d/task", pid); items =3D scandir(path, &namelist, filter, NULL); if (items <=3D 0) { @@ -157,24 +148,11 @@ static struct perf_thread_map *__thread_map__new_all_= cpus(uid_t uid) goto out_closedir; } =20 -struct perf_thread_map *thread_map__new_all_cpus(void) -{ - return __thread_map__new_all_cpus(UINT_MAX); -} - -struct perf_thread_map *thread_map__new_by_uid(uid_t uid) -{ - return __thread_map__new_all_cpus(uid); -} - -struct perf_thread_map *thread_map__new(pid_t pid, pid_t tid, uid_t uid) +struct perf_thread_map *thread_map__new(pid_t pid, pid_t tid) { if (pid !=3D -1) return thread_map__new_by_pid(pid); =20 - if (tid =3D=3D -1 && uid !=3D UINT_MAX) - return thread_map__new_by_uid(uid); - return thread_map__new_by_tid(tid); } =20 @@ -289,15 +267,11 @@ struct perf_thread_map *thread_map__new_by_tid_str(co= nst char *tid_str) goto out; } =20 -struct perf_thread_map *thread_map__new_str(const char *pid, const char *t= id, - uid_t uid, bool all_threads) +struct perf_thread_map *thread_map__new_str(const char *pid, const char *t= id, bool all_threads) { if (pid) return thread_map__new_by_pid_str(pid); =20 - if (!tid && uid !=3D UINT_MAX) - return thread_map__new_by_uid(uid); - if (all_threads) return thread_map__new_all_cpus(); =20 diff --git a/tools/perf/util/thread_map.h b/tools/perf/util/thread_map.h index 00ec05fc1656..fc16d87f32fb 100644 --- a/tools/perf/util/thread_map.h +++ b/tools/perf/util/thread_map.h @@ -11,13 +11,11 @@ struct perf_record_thread_map; struct perf_thread_map *thread_map__new_dummy(void); struct perf_thread_map *thread_map__new_by_pid(pid_t pid); struct perf_thread_map *thread_map__new_by_tid(pid_t tid); -struct perf_thread_map *thread_map__new_by_uid(uid_t uid); -struct perf_thread_map *thread_map__new_all_cpus(void); -struct perf_thread_map *thread_map__new(pid_t pid, pid_t tid, uid_t uid); +struct perf_thread_map *thread_map__new(pid_t pid, pid_t tid); struct perf_thread_map *thread_map__new_event(struct perf_record_thread_ma= p *event); =20 struct perf_thread_map *thread_map__new_str(const char *pid, - const char *tid, uid_t uid, bool all_threads); + const char *tid, bool all_threads); =20 struct perf_thread_map *thread_map__new_by_tid_str(const char *tid_str); =20 --=20 2.49.0.850.g28803427d3-goog