Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp349269rdh; Tue, 13 Feb 2024 20:54:54 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXzIYVsL1nDa4s+jyyNJCJ9m9vyI2IUemCxAVmGixNi/cAhJ3RQOZn7W2dZuqCZeeQTCNbRPjx8ISYaen1tlMUl6ALNI6ojotHZg4BSzw== X-Google-Smtp-Source: AGHT+IG2gW47oPWF6qg/5GXh6qldJsxEesXw8ExurTquGxMG68eE+D1sFHku72APSJCyLy08Gwy6 X-Received: by 2002:a17:906:5596:b0:a38:7015:fc01 with SMTP id y22-20020a170906559600b00a387015fc01mr893581ejp.2.1707886494245; Tue, 13 Feb 2024 20:54:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707886494; cv=pass; d=google.com; s=arc-20160816; b=qSEuyvpFf24Jd6HFcohQGO89LZ1NtGP4uUIOz5afIjf5x8mQByj/89HrOGlsYtYJv4 uq0cTMX+QSGz1Zl6oyQnsAU3/ZXAOr4E0kOrba0qyjdlwiT8Lty26yA/14sXTizwnXo5 +ay+6PyLiFF9d6x30wGVvwC8uTb1kDTjdnYoIZtdGOufskz7/uumZR4uEMwSvzcIvsZS GrJ0KDsd8qD8IxKuUyO/mtrxZ4ATS093V3koXxppURUqlJR9NIJ1LXmHGEuKt9Im1bfz ZDm2BJ5Wz/GIo4pL6exBn087BeYGHRN23VX6jcQmWPNE/jEzkCsvwY/ZWFkH3ObE61pt qq+w== 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=RU+obyM8dBIXt7AFgSYSAW+UNzY91XinQ/JotFkxT/8=; b=wi6/q1+6N9bxjxy6R/i9ORTv6AK8EVzYiuHAMF0USsDistDLycdPtdentpvRTZwd7y Bblyo7lAUPgIJzc7rIlAdBgQJApHiLp4uuPr7pzPYZLjAz9X534U0Lg1sPZMdty/nvN1 EpfcHJJgVhlEdb+IcD9/pBcKHIRo6LMIGf3VKc+OeG3Cth3rTXisLMATWTw8zm0r/hPY PZhM0jxitaxRKKX2/MezOa+XYjcb7riWF9t4xiQZZJ/Rz40+IktZ42bsocvRl3I8HwPa eCcupG29mza9IKt8rqSZPKyOOayWhpL/QbWWX3uFmbHivoEXC9cTMQmEy6RXIUIn48M+ gfxA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=xUNo3MuT; 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-64737-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64737-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; AJvYcCWWHTxk5CWBmsRLp9AeketdY773YqAlKln4HbAQFosPbeXxCMKVW0d145cB0+I0hSERmOkU/AQjsBbtifh9jsDEV0N5N71kQGbcgSVsCw== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id he41-20020a1709073da900b00a3d39b3cf35si385625ejc.331.2024.02.13.20.54.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 20:54:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64737-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=xUNo3MuT; 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-64737-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64737-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 060771F289D1 for ; Wed, 14 Feb 2024 04:54:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3C41E10A2A; Wed, 14 Feb 2024 04:54:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="xUNo3MuT" 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 E8900C154 for ; Wed, 14 Feb 2024 04:54:34 +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=1707886476; cv=none; b=qay91gEqLcet8LBdX0RznmUP0bLKoGOIppzCH1WOVAyh4qT7rHFCHvbT2dw8FiTqaOkPHvLJpRULZgRKX1PK7SdIItJOsR2GyItm5KNao7tGO5Te+m3XIMO99dDtJjrUTNGD7uOR7Mczv0vGSPXu9t32tzkJUtJsCglc9jkX6TQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707886476; c=relaxed/simple; bh=9GvaQ8U/ciyGf0POxeefEusSW20t+DHMSsugj/N6ETY=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=KXd0EB6GbFEiBbX/ZcW3RVpfO8sBARiA/4vB7pD0PqmW32R2ecgqqn2XK5HXQz5sUkZ/1Ct2pK4ypd6YtSMuqsuFGn2SQ5Xpvgwzo4qT6vypE6uLEhaOEpvSKp2PvP6vAL3pY0M9bccWlsLlvaZ7grMjodTa3EH/cG5C5e7tYr0= 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=xUNo3MuT; 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-dc74645bfa8so2588395276.1 for ; Tue, 13 Feb 2024 20:54:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707886474; x=1708491274; 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=xUNo3MuTCHNPNBQSi0iOeCYRhkZNpLcWuhCz+RXhzVfhzxK+TFj5UCTqB1yjMiEgf4 Y2IG/TsNqIuLvuXhVgwCfrFqkulqkxzpGVoKkvlnkvgmtXb2fvm49DMi+Cx4GsUWHQrZ sWYmkj0jSbpPEK9d36KD+H81PqEqLB+Dy2jKJeYw3fZYvAS1ASJvzI4cLcAKXNtG/yUE TWjImoL4OLfJtmjCA1uNDwXgoX/RJOZzGnIhuSWn0e/QVWX2zxnobM7lxur5JaxWHXVI Q5X5Zf41wd99vLJfhXQ4rztXfxNuf+epH4qJaFXBRbgLreCLKQGyL2o/vWpZP1VeA/E9 3aAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707886474; x=1708491274; 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=EVrpg7TZ7ydQjUykt3RJKokphZVTT/hi+i318IJJc+H5AhxtqXvCxWXVX0Pp2SsuaD GPIYRT62ID5n8BXhq9vYoRuzPLMSHPJPVstNQ/Hs1KvfVu2UHP7ewsRI0gYMXsU03s2v Dsjst4rClrj2WMSwfI5fi83f3UsuPj1Gh+Crkjisscmb/WyN8NtmLT92WXYcc3KKN68C JD/vzGltgKcWepqSmhHQU63/VylN/xwqH5rgxB4ewPL26tGHUe0pU4/wfDpwksvKwkEv Fka+txiiKAW2i4I2dXAI2aPAh80tZB+ENUib9uYJHCkmKze8bJP9qRjcVGbZeH2rX0Ct UGVA== X-Forwarded-Encrypted: i=1; AJvYcCXd5/Pp6ZXramDNMiZw1c3sLrdrnjnm1TTeILrSe6Q9NBrnHPiXLovtC6hRoz8CMgJzkicz9nI3mRpFJj2ZHwjhwe/S3rKXrvzZnf74 X-Gm-Message-State: AOJu0Yw7EmPzVEiZ/B6jdZciohlbrWXBUax8v89gsepi8YnY4bb2+VQr ePHlPdrpMWfVbbBIM5M6MSo4R5BlJkLY1EoYSOATNQljaMwiu0Znmf1/oU+759ZlZAzSVnxFiRl kWPzVBw== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:6d92:85eb:9adc:66dd]) (user=irogers job=sendgmr) by 2002:a25:d3c6:0:b0:dc7:6cfa:dc59 with SMTP id e189-20020a25d3c6000000b00dc76cfadc59mr50124ybf.4.1707886473857; Tue, 13 Feb 2024 20:54:33 -0800 (PST) Date: Tue, 13 Feb 2024 20:53:49 -0800 In-Reply-To: <20240214045356.748330-1-irogers@google.com> Message-Id: <20240214045356.748330-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: <20240214045356.748330-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Subject: [PATCH v4 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