Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1995219rdb; Wed, 31 Jan 2024 16:15:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IEgbaR4dPpHw9qqxeJfKqy5gAv5ZhUa9+pStFF1baCzLpYtgKBZ5MnmS5wVowQS4JTxTujO X-Received: by 2002:a05:6214:20cd:b0:68c:4fdd:9055 with SMTP id 13-20020a05621420cd00b0068c4fdd9055mr4012378qve.53.1706746531896; Wed, 31 Jan 2024 16:15:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706746531; cv=pass; d=google.com; s=arc-20160816; b=pD/cEFlUHdmOVKJpovBeWHUl7/07WbpW/SXGElqf9kDAOzKpcLFWgDHSHLjE+n+Mf4 YblRSZvYoHJIuCLFJBN/6dFetvE9XXLqY+3iYhTJRVOQqD0hnzgvG/9aHMBkgEiDNfst v04MUm3pPh6v7ZLmOs+IW0TUlwd5MgudUQgEZ1yS8dyPZhVaZh7JAIHgsGqbpRlFMIT1 AV97lfN/iVHkHdl8B5sHeYGcuGxtMJYWsUmJId0mtbPEQH+50I5rm8sK9O8H+7f4hw6Z OwmNpg/m9tnQtPHzyYLuCkzv2zFSP4UhWp4hOPvgL99qYkD2GzgakRLM8LdDRH4CGHPG xREg== 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=AvxQjAtVkBG3yBcGXl9dN2QMZn0MK0hUStcZowlM+/g=; b=M2vwLP+4CRyl/wIAGmCEiwKOABHGJa4OT4EwhQpkcWNxyflH/MIJ+UoXS1mSs2BQmo 0Zjzq6ZQsQlssROE1ghGUc4BgAAd8Zcwc+WcZwNhl6LIGAxN4kLuH7qaRnj/m0sJHVfo UN0L+RvEJIuZJRr4/sn2FxqDZ6dqJNtsBp/GpA5hsaC8mb+SpMLIIh+rfNHvuYcJ1mL/ 7HyPZw+T4YjfaYFFd4slUxI8BGnWBMVcfGR2B4P2Hh8F2p8EDOMfu6hW1gHkbuSPo2U5 oXG207iysGBaqhRQ10z95Nl+oqCcCeHErrQUKMVSyRzj8aPx3cu0ywiJYESmTOLpS6fC r6LQ==; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47413-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCUXpVaB7dD/LKdqWQKUa1AHFUTMiRegElntfYjt7UsmmOcwswhg5IKoKZtBNGHwqmAxDZVuIArsdyvvUz3V/smlPv6K976XGDzsGGrWOw== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id k9-20020ad45be9000000b0067f931f6bfcsi13879250qvc.395.2024.01.31.16.15.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 16:15:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47413-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47413-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 9D4781C257E6 for ; Thu, 1 Feb 2024 00:15:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9885BA40; Thu, 1 Feb 2024 00:15:25 +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 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 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; } -- 2.43.0.429.g432eaa2c6b-goog