Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2132466rdb; Tue, 20 Feb 2024 19:42:24 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUpjkgwS35/wMyNodhT+lYpIbmsSKqeyUZe0/sPx3V/fyKmce+uGm99jmLPUmHgmkJRLpsblNDQAsf1sK+Gxri8ONnRmi1/s/9J6q8TLQ== X-Google-Smtp-Source: AGHT+IGgiWnal3qW+mQljic8fTMrZLLZjfoAHCDzaFEzypBwZSf9xfFdraTxjNFRFmKMBOeCtjCz X-Received: by 2002:a17:906:d285:b0:a3f:4b56:b9ab with SMTP id ay5-20020a170906d28500b00a3f4b56b9abmr1535ejb.8.1708486944455; Tue, 20 Feb 2024 19:42:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708486944; cv=pass; d=google.com; s=arc-20160816; b=TW5XWnq6im6uNJbqcW9sRxKGmer6/6vBR0RcXxv8drzI4hMrlP7h2AzZz7mfUJtJZh 11vgl3FcJhAhX/VCB05YJbiMQYBRUzHIRkInTPUlztEP8o8qCIQDxbKTL/ke77MkpA35 YbpfdjlpeQtqzalS72JBceAFV3N2BQXJVP1p3hJRN8GRtKKOHIg1K0mZB3hiLGLhelPY ED9ZKCTZNI5/q/jwpL1iDORBvW07xg9m5aguLhqEAbbHfWr4s3gkZJnjeGKTAEGZP7tj ITesh9JQN/N0MFMHC+DF1i2DN2WrHR1+enRQZ7+6VPiUeGk4WL2eRRh6fJti6NKd945i WT/Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:from:subject:references:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:in-reply-to:date :dkim-signature; bh=uv/9NgKdLz0z52mqtvy0vTSbbBgaPJcb0Vk69+L979Q=; fh=0u1l5NUOKyleDkk51CMo2hSU5OQ7hFsid2V+kG+D3ZE=; b=cSWBkJUlLyV2EFuqMWhVESL66mBGWXA5EtDUVMOfTHDOrUJUgoFbmRhwXO7aZU9kmk h5fCklfIrRqrgLc77qw9SsOJ6GPgBROs5WeVt8ma3ItOENqLv1K0yzwn3wxq4o1C8lVz AKufupB9ehJhUy4yanqvzQ2gs4EFHGKyxMosoeh3dD/WCeBdreWc8yI82W9s3+mYx0V+ 7wqLVLLVi6CIlTWIxWgrlGpPs89wS5ya016rhizw7FaK4968I0eAYfA4uv8q2pgbGRA/ 9/a8HeE1AWTdZF9NPTbqeNN2iu7rMFkbJtsSWivOZJQ0GzBSSAQG4sK4mmYE828AQye0 VZWQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=bvs0jjKY; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-74007-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74007-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id n2-20020a170906840200b00a3e5952b3ffsi2997503ejx.75.2024.02.20.19.42.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 19:42:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74007-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=bvs0jjKY; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-74007-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74007-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 12FFA1F221D3 for ; Wed, 21 Feb 2024 03:42:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3ABC139864; Wed, 21 Feb 2024 03:42:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="bvs0jjKY" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 BB6ED38DE6 for ; Wed, 21 Feb 2024 03:42:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708486927; cv=none; b=eCv+nGSQBmQYOk6Na9xrPmffHZJ4SO9/Qo3b2dcdx3se+bRv7yg7gchcvu4PF3zK8TLG3SlB7ydi5AnPMWIZA7zhCFJ1korA3o7A2hylsjQal9C69/7hVqWHMmtoP+r6ldsvvQ4rnDz6t5pntLybOduqiR4VotioTtuACgULSfM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708486927; c=relaxed/simple; bh=o/osGCI+hvlD14sD3OCM5ESdLYEEWx1V7jgoXENiCKc=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=bZ9mz9mnXPRTFPibPRgfUKv6IlyzWnFf29chPDpm7EF3IOO6BDuZJlC9AeTslrevU2RiDRoNqg1Lv/PMkzjsqMyCNPr22lCVyBV/ilTEckBdRt4weoydtQ7+sT29JTAuf0hMmVSzXkbvVU9hHlPe33ImFXpkM00AOafUb3cHyuI= 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=bvs0jjKY; arc=none smtp.client-ip=209.85.128.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 Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-607cd6c11d7so89979957b3.0 for ; Tue, 20 Feb 2024 19:42:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708486925; x=1709091725; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=uv/9NgKdLz0z52mqtvy0vTSbbBgaPJcb0Vk69+L979Q=; b=bvs0jjKYG21ZkB+YgfE5BE740UXuO77Aq3aGQVuxlIvR4Api1Wd4UkAzo8tzSYpyxu qgIcKEqtQo9kzYmWGUOYEzQqHm3T419K97jcCG6JD54rA6kt9TW3725qnQ91FWLCSKld DkO2R3m1FoX6F5W9P+Lz18oSTagIl5/cO6lUWg1G7Uw/eXm39MRhHadPE9CjR24Tt3FS w8g6c+vm1zP/XJcMZJ9rTkmPOW5IHsHgB9NA5KU0rMlj3wY9F4rKgehtcnq40to/jKhT GaZmDyaiksQFqofW5FfXSwirlu2KlyFgPt0WQcQmCX1WZ6nZR/aWrE31NPuKo38UqC21 W9Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708486925; x=1709091725; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=uv/9NgKdLz0z52mqtvy0vTSbbBgaPJcb0Vk69+L979Q=; b=FiSE3G/wbQeeZHE2Yyxj96B+pbzEA9YdCXNDZhjv1mXCpy13cdQ+ooVhKlLHC5zIXO SREMRVAR78iWfzQOuPAfflkbbILjJi/MtKvLVo5xHQo+E9CRUmbnx0cpD8JeIiwsuOi7 jIPh8byUHMVhkVxlt7aEPY/uiTYWkphKYDbh/lYQR+jVcoUHu4ja9UaHox6zmpIPUF9a 1RHoujmP1XC0xuU0DBLZs2MHQo+jPfUJQAKUNuDk9agDRWeW3Z/Tz48BWwsbMHunsoki yrxPlxZLGSwzCsNoLTtSSyHnuzsV848hL2AwN4W9pgL3DUh4uB1Cwm0bn18hjsUg51rj Y9AQ== X-Forwarded-Encrypted: i=1; AJvYcCUtQxHnKdxUa5ft6FxY0TE8f9c4FkSX46hJ51HrvpG/g+zKh6acWPeYzBiKCh7sXjdsPEPwvnW+wlpQN+hox5QWocmgjiN7SqDDX5je X-Gm-Message-State: AOJu0YxhNijls3m6aAbKPZQEQVBVT9XXSF9NUyo1+qN5F13VgRpvZkcZ LCwJX1iAZjqBZgmW1gfSif08HEPEsi1PL1Z5eWYuDdIg1P1hgLaEA0RzWUqvUrJ7FXw4kqWshkB BtBnN+Q== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:3c02:f882:5876:b7ab]) (user=irogers job=sendgmr) by 2002:a25:db93:0:b0:dc7:9218:df3b with SMTP id g141-20020a25db93000000b00dc79218df3bmr708882ybf.10.1708486924814; Tue, 20 Feb 2024 19:42:04 -0800 (PST) Date: Tue, 20 Feb 2024 19:41:48 -0800 In-Reply-To: <20240221034155.1500118-1-irogers@google.com> Message-Id: <20240221034155.1500118-2-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240221034155.1500118-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Subject: [PATCH v6 1/8] perf thread_map: Skip exited threads when scanning /proc From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Athira Jajeev , James Clark , Kan Liang , Yang Jihong , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, llvm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" Scanning /proc is inherently racy. Scanning /proc/pid/task within that is also racy as the pid can terminate. Rather than failing in __thread_map__new_all_cpus, skip pids for such failures. Signed-off-by: Ian Rogers --- tools/perf/util/thread_map.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c index ea3b431b9783..b5f12390c355 100644 --- a/tools/perf/util/thread_map.c +++ b/tools/perf/util/thread_map.c @@ -109,9 +109,10 @@ static struct perf_thread_map *__thread_map__new_all_cpus(uid_t uid) snprintf(path, sizeof(path), "/proc/%d/task", pid); items = scandir(path, &namelist, filter, NULL); - if (items <= 0) - goto out_free_closedir; - + if (items <= 0) { + pr_debug("scandir for %d returned empty, skipping\n", pid); + continue; + } while (threads->nr + items >= max_threads) { max_threads *= 2; grow = true; @@ -152,8 +153,6 @@ static struct perf_thread_map *__thread_map__new_all_cpus(uid_t uid) for (i = 0; i < items; i++) zfree(&namelist[i]); free(namelist); - -out_free_closedir: zfree(&threads); goto out_closedir; } -- 2.44.0.rc0.258.g7320e95886-goog