From patchwork Thu Feb 1 00:14:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 195094 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:106:209c:c626 with SMTP id mn5csp110104dyc; Wed, 31 Jan 2024 16:15:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IGyav3QJLA+gpAs+K4cTHNdNIwSfsg82Z+CqfPXzUbHTRo5sfF8U9ARB1oXNPzpZKwjUM7Y X-Received: by 2002:a50:bb23:0:b0:55f:1eb5:25ff with SMTP id y32-20020a50bb23000000b0055f1eb525ffmr1691722ede.41.1706746547353; Wed, 31 Jan 2024 16:15:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706746547; cv=pass; d=google.com; s=arc-20160816; b=kTF2RxAZLdbE+vWXCfapgIkpQ6h5gUz0w44FeTMHyryM14iYIUaqwkTKetTsUk4OlG LpMT1n1KYx4ZrLBg+1zrLYvz9UwIR3YkJxxsamZQLSxfDv8Qu9+VJxuK992V56P9ncF2 v6jVkA+3GdPGMILUc3UjXy8ikgf/RlVXZYe8wYde0vOgcQotNoOagg5qSgHsafiYaZ0X RNFUhsdl4uOPG4YLxFaEGkSRlSyg4Qx1x0Mxd6N1FDMo0B9jKscRW9m20M9Gf+T5qNTb jyFvz/3jRoS1J275ssMLNFGA8BVRl8i5dlPvILdDwwq8AJuCFIvqS0jbjwKhEIrN7tK8 0FkA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:from:subject:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:date:dkim-signature; bh=2F04A0OfF26PLB6g2tCcO6N4OtMZoaSU7mdBY8RaIms=; fh=SqfxwNQoviY2f+MdOb5zrBaeccyaYrbRPQdug0turTk=; b=onqMMYbr/d+7SMStgzDDkw6z53PQ8qjQOztI5I4atzrFwaHKLRnhSX8Y4cpc8tUwjg Hw531QDRYlXiXyO+NvAStDcuLpxv4L7/cgpoENr5aQdzo8MUFDh5NRvkQ6sInsjCdBN4 Py9LXAFa+oLf6mK/ninovSf3Hyi2GyTGc1VIXHx7R87x0a7GciCZba2QEe2a7eJFS99I /cJt8Kjy2I7un9jU9XK2cyuzeh/DQC4h68ONkR3ZITqI3BB45Vh89t+d8NYXt4qz+RAY I874nHoX0vnblUQEAdMY17TRwx8mQmzHKGO/vK1eSHHVuTJqi8QOm297MHlIZRztbIaY rCcQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=RCpoy+4x; 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-47413-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47413-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCUZ7a0376CdzeOrhBQb/3RfWNfgdTe5kpyJAKEfDkT7E7R60laRsuDnvvFbM7So7ZQwadm+1BVGFLhHwWRJ6Ip3tHMTcQ== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id d33-20020a056402402100b0055f82c281dcsi1254643eda.254.2024.01.31.16.15.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 16:15:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47413-ouuuleilei=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=RCpoy+4x; 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-47413-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47413-ouuuleilei=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 E35C21F2699D for ; Thu, 1 Feb 2024 00:15:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A3EB92116; Thu, 1 Feb 2024 00:15:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="RCpoy+4x" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 21EC023B9 for ; Thu, 1 Feb 2024 00:15:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706746524; cv=none; b=U9TznbkMuVqlsTHa3/6xZjYmjVd46evaktfT96Z3kLJXZ/ynTjbmjmQxevAcJCvscIJwxg9oRfe6JXfzLLDkuJdWnnADL9yJazox3E7WTiCaZV5TPYb6xGREJkjZa5Cw6ILGPZlVJK0poOVL+eUoNExMEpoWptCUS/NTyN9FukA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706746524; c=relaxed/simple; bh=27wmXzsgBuwC0/tRLzTcix6eSwjml4hF8vNJfLSfj4s=; h=Date:Message-Id:Mime-Version:Subject:From:To:Content-Type; b=YDYddOWFJO9I0PkS6PNRNejZ/CCCcX4vKvrGASU0xAHhdY90bWsuiZ/zIlhuDsHhxE/Fw/ow/w5fIijQnadQfJWz52t/NqI1ZAG9/+IcooJoxFh49I30UqS8gjxWmrMZnj2JmfrDqFxYHrF4m7Le7Q0o217fTQYqooKbQblhakE= 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=RCpoy+4x; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc6b269b172so1981933276.1 for ; Wed, 31 Jan 2024 16:15:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706746521; x=1707351321; darn=vger.kernel.org; h=to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=2F04A0OfF26PLB6g2tCcO6N4OtMZoaSU7mdBY8RaIms=; b=RCpoy+4xNYVZ43QkZLSHHifaV4kGY06lOGdGP8aikinISvVYTnjmdhEBoBqYIuEn0a EhDartG/g472QtNgZgtuXDjDPF7RiW6RC8VmXElaZSVjWi/XPvQrvqGkeseDFDYBPhwl MN7+/UYkBS75VH7yCrVq627ZIocrbAPgAzRfQSkQDm5utQJ5edzgyynXwLGCe8zFrsKL P6CIv4Dg3JKvGXV1kb+dZwsIhTideAFzyflIim862YviQZpVSY+YnVjhSiynJSFMQ8n8 AvV6Npkt4Z5zgQlyKYG+noi6oGEGI5yaewQuGbTZmaEoDEwx1CSniwprfkPJezsbBXRl tMTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706746521; x=1707351321; h=to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=2F04A0OfF26PLB6g2tCcO6N4OtMZoaSU7mdBY8RaIms=; b=oIV2E7M5Svma0JKpv1N8aZNKe57p71zm1X39GiT0h21JtOPpNsUNyfMmFHXXGfy8H8 F733MsWkb8K9Y5q1zOvxtRbc131J1LEgSAPvXVY9yhxwdP4uGZkMNudCrEw0aI0Gbu1a kAbUc7UXhn0XiSgEEUBEbenjBwAKlQpuDvrflVK3TAEImBOMPlcqAaTSwsidOPCG7m9A YzQMoHZ01XM4M7gGJypFuGFmZD5LYkJqF8MpAZvjPwWMSCPXh8x2V9NnlS5wNAw8Y5t8 QGVrdDwe37Lv7NvmQ8C6W48KkzHrJKIx5vdibx/F0ZS4QaaJ0elnxltATY+XFDtASH9W gh8g== X-Gm-Message-State: AOJu0Yy/3FYqrarKP/RJ6hMijsXkSTuKqZkhJ1LjzXmJE6YYCfSgmEvo dUcja6n2j3NQD6Vr5zidonXm/90H+1k0VYmGNl2QsXuu/YBiHV3/TC8OTJ9lVJTEwDJzTr+7YFP P0JdNSA== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:16c5:1feb:bf99:a5d1]) (user=irogers job=sendgmr) by 2002:a25:8912:0:b0:dc6:19b9:5b83 with SMTP id e18-20020a258912000000b00dc619b95b83mr1132435ybl.6.1706746521125; Wed, 31 Jan 2024 16:15:21 -0800 (PST) Date: Wed, 31 Jan 2024 16:14:55 -0800 Message-Id: <20240201001504.1348511-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Subject: [PATCH v2 1/9] perf thread_map: Skip exited threads when scanning /proc From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Nathan Chancellor , Nick Desaulniers , Tom Rix , Ravi Bangoria , James Clark , Kan Liang , John Garry , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, llvm@lists.linux.dev X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789653467789079762 X-GMAIL-MSGID: 1789653467789079762 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 e848579e61a8..18fbc41d09f3 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; }