Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2634055rdb; Mon, 12 Feb 2024 10:59:23 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUJjWEqR7sn2KsWOhwFhWmjG1IhC0WWVkqX8FlAlokLPXQlaG1OCddTJw7x2CVdd0tEqAkg/jWv2Q9KYMRzyowZUXp8lLLHA2EIaXf09g== X-Google-Smtp-Source: AGHT+IGMfbCmAUxaegDkhG8JpV0jxY0AbhyJHG8lixapLXx8PMdM18Ty+rQdTTfBfmjmoQiIljAQ X-Received: by 2002:a05:6a00:98a:b0:6e0:f3f4:8d9f with SMTP id u10-20020a056a00098a00b006e0f3f48d9fmr1388045pfg.8.1707764363017; Mon, 12 Feb 2024 10:59:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707764362; cv=pass; d=google.com; s=arc-20160816; b=Kti1qqJ2Rjyd1m2q6nQ5AgFRycCuSLijyI25X569Qofc2G0M4CWC/qMZJK1yxVHT4p gNifdQUmqN05AHK08iNan9EriTBOxM5999E7BG0taBb1WfttqpmWXLZSZMRVKa9q909s Jwh4HBVkV708/MODh0lQgUAb1tpjBY5q2bp/+l8FEPDVavKGhllJJn8TXJdszJKLsm1P XX9mj7n8XfZnR5RmeqFSHbNtE2bDDAxhJekL1b+ayEq4qK+9TMyPNh7HEgBKpcx4Gdrv eRfPJ6lT52ikI36DyVgmHhjEAP5F9s/k4UR+K9wUXoJLHdf9/uvTKNpZ/MJuT8TsJx52 5E6w== 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=F6UUwQ6uU0gh1AgBT5LAdlyWuLVQW/eRWP9wNVATd0w=; fh=T9lrA9ffT0TTkX5l2bYooyB+0fUgefFmEgLc7nUpbaU=; b=mGlEb5otDWqhHitJqqbVSOVcsPehSvz60pb+Pl4YgM1PZFrKwcMmKelsm5mDO2tJ64 MRHKw8TE5lafuc8dwUc+vs7UBjIOpCFLfHDCCP0pjScD6a/l0iGmmWgN5fct7pfUBgzU eOegMrI+WyTomVuJcWQM1XYhE9cO/BclF0JkkxhQeyzQjYXTyQnMHQlWj50Z8WdUiyIm xlc/6/XNCNaOBvyfbwwzI3iCPB1SUU+3V4Vv7Xkp1c6FqceG7m3+FJgy30uCJ1NNN9+Q UX8LB6Y5rSxFtiLjTRWxOE+4H9S7lDdN760uXG7xjPNzh+lKjSelqZYaIZUID3qYx9f5 95qQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=pma60R5z; 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-62240-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62240-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCWTc3zTYYJmf7npfvSqqdlJHTbvJ9yrQSpKVaIeqTM/OHahSwSMu4L3NhOnQyiqEuG5y1vc8M8DKRaoxljtwcmLAKozj5m1rEV8UvoGFQ== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id p5-20020aa78605000000b006e0822dd294si5238962pfn.274.2024.02.12.10.59.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 10:59:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62240-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=pma60R5z; 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-62240-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62240-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id AB460285CAB for ; Mon, 12 Feb 2024 18:59:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E805346435; Mon, 12 Feb 2024 18:59:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="pma60R5z" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.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 A96624596E for ; Mon, 12 Feb 2024 18:59:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707764352; cv=none; b=NOx5yXPbZmEmVEIAz20dffNTgxiDMM23PkEDi6C2WNnRw6CezSBWMnQ2xfCzuOiFOxX8ZTMDCwLM04X7iy+tY/mpaJ41GxPdL1kCL2VEBgPOeGoRSJn7saBEgDQIZMy1WiXsSZYMKfeydGPdv3WfNy29qkfcpEihI7HU1E1czp8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707764352; c=relaxed/simple; bh=9GvaQ8U/ciyGf0POxeefEusSW20t+DHMSsugj/N6ETY=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=p9Xyycqz5OAzMP5x6AH9UXmDPib0it4ITP/p7IFBYBsdCSJo0wjWIu81r1avH+G3omxzL0ia4/VxTDZkEut3ZUsKuIB/oj2AGX650A6bbtKDmXTnTWqaJ0fid943lVfwbMkjC4oDP0TaQurvQ7Hm9o0rnVYgIcyUn3MZga/X5UM= 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=pma60R5z; arc=none smtp.client-ip=209.85.219.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-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc74645bfa8so126788276.1 for ; Mon, 12 Feb 2024 10:59:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707764349; x=1708369149; 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=F6UUwQ6uU0gh1AgBT5LAdlyWuLVQW/eRWP9wNVATd0w=; b=pma60R5zHeE04LRBeGIwCBhS8j+w+e2dINMD07Tw+sO5K5oDGkV3vTBu/jkDZmkF99 qwEVMpLxFthmRUMx5AxSQ8NEQ37PW5Irh1yLy8fLO2a2FKJKwL21V9PbXDDjLR/ieVfG JvxHiZHuxiWB8pXKIXI3cGDaorGndfGbxoODxJC4t2fMgrdw37Es6Yb8qRxf9Wp1Ob12 V5u0JG34Vf0PD5T73GviB9uZJLoFPmHh0nrkatnb7YrH6bysD6XKOxKAaCprEwDUS1Eq cTxkjM3E5s980bQ2KqFN5FXhuetSNbnh7EArJVqfsSEgQBRFwRwwYrIw2K1ebfZlMV53 DRzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707764349; x=1708369149; 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=F6UUwQ6uU0gh1AgBT5LAdlyWuLVQW/eRWP9wNVATd0w=; b=ci7Abvej/wqf8tAeISXzj7mLKp5jVFGb5Pm8hT/tVp3wS/aU+eRN8ZFkJp8eqUv3/E kBk36CtRQYUcqa/3Ews3zUfb10+cR/5Iv5R/VnqbtyuhYqx7MdAWO9OWVI1D059xm17u jcvBDR4FbTHAUDgUzzeL0M38zM1TRMMaYopvJzAMJ5su418OdhoDneLAe8EA6XqnoxbC 7zawCsEI7tm9tUCTwxKAu9ILLLxUtSBzLo7Ts9dA6xIjvCeEk/LYaJk8mauqL1lM3nTY d9pz3VVyelmSwVoxv2sDo8dcbpuUa28q9W3ZnD+JWl691fNqBePSZ+snHC5jz58vPLtk slwg== X-Forwarded-Encrypted: i=1; AJvYcCUU8d8BZZc1glFfNspCYJVnRmkRxSlxPZhWP0j8uvqQxFoJtsWwjuCHsz3U6jxjdVFc7v6qcsGu7+oSZUPLXmqK7t81+Q207CJ7YNT4 X-Gm-Message-State: AOJu0YyXvicO59MrU6AZsSS1U43C9frMWSXEFrl0Ss7cnhGrYu2abi8h tyYCp5amLoFjuEKv1HkEV1AuQB1sQ2b2Cd7EAVEN3LjJFEKqDQLsONv3vvxdIyG5tCDWf/+5F19 2LSPySQ== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:125c:bcda:4fe2:b6e6]) (user=irogers job=sendgmr) by 2002:a25:aa2a:0:b0:dcc:41ad:fb3b with SMTP id s39-20020a25aa2a000000b00dcc41adfb3bmr6327ybi.10.1707764349685; Mon, 12 Feb 2024 10:59:09 -0800 (PST) Date: Mon, 12 Feb 2024 10:58:51 -0800 In-Reply-To: <20240212185858.68189-1-irogers@google.com> Message-Id: <20240212185858.68189-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: <20240212185858.68189-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Subject: [PATCH v3 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 , James Clark , Athira Jajeev , Kan Liang , Yang Jihong , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, llvm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" 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.43.0.687.g38aa6559b0-goog