Message ID | 20231122022154.12772-1-CruzZhao@linux.alibaba.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp1050899vqb; Tue, 21 Nov 2023 18:22:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IF5exVc8EWeyXXuTn8jEf48wRFHKRMP5SR9QK29egN7KxSniDfxm8dAoXtzUcCUfkQmZyXu X-Received: by 2002:a05:6830:154b:b0:6d3:1e5a:d928 with SMTP id l11-20020a056830154b00b006d31e5ad928mr1327713otp.9.1700619728840; Tue, 21 Nov 2023 18:22:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700619728; cv=none; d=google.com; s=arc-20160816; b=uICmCegZCLb27sYS5ksgjBy1SAiL6C6qFbLKlZ7Xpi/vfGtojsLr27//5c+DfX3Sh4 ii2VrJ9SAJyZskDRg9D8EtPeptqtySFVVldC5d/YnKaAC7Uf/W8AB+wt1ePgqi8rV64I tlh+gIBMFnwR6cLpXpHhXcsqyiZzCE0Kmuw4LlaxDxgCw3pWJxTCh10XJm0PvYGxdnVq Vutp5PI329kekKTPt/eu5D+jfhCFfNP3x0ZOjxtPuwo9YNFJoNpHjwi0aJjMxHJDS/05 YqAkkUdGfvvT9C0NMKL/J7HOdZukH6dHYLkOww6uut9Rs5BtYG9QbogWLz/3eJ4H1ZCL gaHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=qgisKt73fQumAx11GTZyQM/d5lcW2vbNFz8RC4Qej0c=; fh=e14CFnRZCKQqEEYpuba2MA9vUEvyg8O1JALRrWxbDeY=; b=Brys4Mjvg7UgtgmDRQ1AOkQZCBUIfqfQgS6d2C1ILQOGTL/QJvdpwQjCieRYajkTbN VoKpDl2+DEi5eEkjKgIBUJ8EoNf6We26Gmf6m84rVZYWbrsiaGXnQHDfduaroVY1jP4A OQBj99/FOLqT4Hx8ne/8gdE1YELkE7aVKdeqsLh5kQ9YBr6AZms2a56UThBSwBkHCKWr JJhnopaKIhxoDBILj+hgoyP1A178MwCtawwhmfLKsdbsYCn3EDeqHMKD3asV6KTluGgC 9ew9yB1+Y7L90bTfS+e3L4OZ2MQhkGPiX1ymMvzWu3mNjflUUiV6Gmt5MznHL8aeWFjI tWuw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id a21-20020a631a55000000b005c16f07b3e6si11485775pgm.164.2023.11.21.18.22.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 18:22:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id BC0BA818ABDF; Tue, 21 Nov 2023 18:22:07 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235024AbjKVCWJ (ORCPT <rfc822;ouuuleilei@gmail.com> + 99 others); Tue, 21 Nov 2023 21:22:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229498AbjKVCWH (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 21 Nov 2023 21:22:07 -0500 Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA171E7 for <linux-kernel@vger.kernel.org>; Tue, 21 Nov 2023 18:22:03 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R771e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046050;MF=cruzzhao@linux.alibaba.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---0VwuMgws_1700619714; Received: from localhost.localdomain(mailfrom:CruzZhao@linux.alibaba.com fp:SMTPD_---0VwuMgws_1700619714) by smtp.aliyun-inc.com; Wed, 22 Nov 2023 10:22:01 +0800 From: Cruz Zhao <CruzZhao@linux.alibaba.com> To: mingo@redhat.com, peterz@infradead.org, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org, irogers@google.com, adrian.hunter@intel.com, kprateek.nayak@amd.com Cc: linux-kernel@vger.kernel.org Subject: [PATCH] perf: ignore exited thread when synthesize thread map Date: Wed, 22 Nov 2023 10:21:54 +0800 Message-Id: <20231122022154.12772-1-CruzZhao@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 21 Nov 2023 18:22:08 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783229032577065879 X-GMAIL-MSGID: 1783229032577065879 |
Series |
perf: ignore exited thread when synthesize thread map
|
|
Commit Message
cruzzhao
Nov. 22, 2023, 2:21 a.m. UTC
When synthesize thread map, some threads in thread map may have
already exited, so that __event__synthesize_thread() returns -1
and the synthesis breaks. However, It will not have any effect
if we just ignore the exited thread. So just ignore it and continue.
Signed-off-by: Cruz Zhao <CruzZhao@linux.alibaba.com>
---
tools/perf/util/synthetic-events.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
Comments
Hello, On Tue, Nov 21, 2023 at 6:22 PM Cruz Zhao <CruzZhao@linux.alibaba.com> wrote: > > When synthesize thread map, some threads in thread map may have > already exited, so that __event__synthesize_thread() returns -1 > and the synthesis breaks. However, It will not have any effect > if we just ignore the exited thread. So just ignore it and continue. Looks ok. But I guess you want to do the same for the leader thread below as well. Thanks, Namhyung > > Signed-off-by: Cruz Zhao <CruzZhao@linux.alibaba.com> > --- > tools/perf/util/synthetic-events.c | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c > index a0579c7d7b9e..43ad2298a933 100644 > --- a/tools/perf/util/synthetic-events.c > +++ b/tools/perf/util/synthetic-events.c > @@ -866,14 +866,16 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool, > > err = 0; > for (thread = 0; thread < threads->nr; ++thread) { > + /* > + * We may race with exiting thread, so don't stop just because > + * one thread couldn't be synthesized. > + */ > if (__event__synthesize_thread(comm_event, mmap_event, > fork_event, namespaces_event, > perf_thread_map__pid(threads, thread), 0, > process, tool, machine, > - needs_mmap, mmap_data)) { > - err = -1; > - break; > - } > + needs_mmap, mmap_data)) > + continue; > > /* > * comm.pid is set to thread group id by > -- > 2.39.3 >
在 2023/11/23 上午5:05, Namhyung Kim 写道: > Hello, > > On Tue, Nov 21, 2023 at 6:22 PM Cruz Zhao <CruzZhao@linux.alibaba.com> wrote: >> >> When synthesize thread map, some threads in thread map may have >> already exited, so that __event__synthesize_thread() returns -1 >> and the synthesis breaks. However, It will not have any effect >> if we just ignore the exited thread. So just ignore it and continue. > > Looks ok. But I guess you want to do the same for the leader > thread below as well. > > Thanks, > Namhyung > With my testcase, no error is returned even if we don't do the same for the leader thread blow. Well, I'll check whether the logic is still correct if we do so. Many thanks for reviewing. Best, Cruz Zhao
On Mon, Nov 27, 2023 at 10:23 PM cruzzhao <cruzzhao@linux.alibaba.com> wrote: > > > > 在 2023/11/23 上午5:05, Namhyung Kim 写道: > > Hello, > > > > On Tue, Nov 21, 2023 at 6:22 PM Cruz Zhao <CruzZhao@linux.alibaba.com> wrote: > >> > >> When synthesize thread map, some threads in thread map may have > >> already exited, so that __event__synthesize_thread() returns -1 > >> and the synthesis breaks. However, It will not have any effect > >> if we just ignore the exited thread. So just ignore it and continue. > > > > Looks ok. But I guess you want to do the same for the leader > > thread below as well. > > > > Thanks, > > Namhyung > > > > With my testcase, no error is returned even if we don't do the same for > the leader thread blow. Well, I'll check whether the logic is still > correct if we do so. > > Many thanks for reviewing. Thanks for looking at this. Could you share the test? It looks like the thread be removed from the thread map to avoid potential future broken accesses like below: https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/util/synthetic-events.c?h=perf-tools-next#n887 Some of the race will hopefully get narrowed by switching to a less memory intense readdir: https://lore.kernel.org/lkml/20231127220902.1315692-7-irogers@google.com/ Threads racing is an issue in this example: ``` $ sudo perf top --stdio -u `whoami` Error: The sys_perf_event_open() syscall returned with 3 (No such process) for event (cycles:P). /bin/dmesg | grep -i perf may provide additional information. ``` Generally the races are covered by the dummy event that gathers sideband data like thread creation and exits, which is created prior to synthesis. It would be nice to have a better threading abstraction to avoid these races. Thanks, Ian > Best, > Cruz Zhao
On Tue, Nov 28, 2023 at 9:12 AM Ian Rogers <irogers@google.com> wrote: > > On Mon, Nov 27, 2023 at 10:23 PM cruzzhao <cruzzhao@linux.alibaba.com> wrote: > > > > > > > > 在 2023/11/23 上午5:05, Namhyung Kim 写道: > > > Hello, > > > > > > On Tue, Nov 21, 2023 at 6:22 PM Cruz Zhao <CruzZhao@linux.alibaba.com> wrote: > > >> > > >> When synthesize thread map, some threads in thread map may have > > >> already exited, so that __event__synthesize_thread() returns -1 > > >> and the synthesis breaks. However, It will not have any effect > > >> if we just ignore the exited thread. So just ignore it and continue. > > > > > > Looks ok. But I guess you want to do the same for the leader > > > thread below as well. > > > > > > Thanks, > > > Namhyung > > > > > > > With my testcase, no error is returned even if we don't do the same for > > the leader thread blow. Well, I'll check whether the logic is still > > correct if we do so. > > > > Many thanks for reviewing. > > Thanks for looking at this. Could you share the test? It looks like > the thread be removed from the thread map to avoid potential future > broken accesses like below: > https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/util/synthetic-events.c?h=perf-tools-next#n887 > > Some of the race will hopefully get narrowed by switching to a less > memory intense readdir: > https://lore.kernel.org/lkml/20231127220902.1315692-7-irogers@google.com/ > > Threads racing is an issue in this example: > ``` > $ sudo perf top --stdio -u `whoami` > Error: > The sys_perf_event_open() syscall returned with 3 (No such process) > for event (cycles:P). > /bin/dmesg | grep -i perf may provide additional information. > ``` > > Generally the races are covered by the dummy event that gathers > sideband data like thread creation and exits, which is created prior > to synthesis. It would be nice to have a better threading abstraction > to avoid these races. > > Thanks, > Ian Fwiw, we hit more of these issues when running the test suite in parallel. I posted changes to do that along with a similar fix: https://lore.kernel.org/lkml/20231201235031.475293-1-irogers@google.com/ Thanks, Ian > > Best, > > Cruz Zhao
diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c index a0579c7d7b9e..43ad2298a933 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -866,14 +866,16 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool, err = 0; for (thread = 0; thread < threads->nr; ++thread) { + /* + * We may race with exiting thread, so don't stop just because + * one thread couldn't be synthesized. + */ if (__event__synthesize_thread(comm_event, mmap_event, fork_event, namespaces_event, perf_thread_map__pid(threads, thread), 0, process, tool, machine, - needs_mmap, mmap_data)) { - err = -1; - break; - } + needs_mmap, mmap_data)) + continue; /* * comm.pid is set to thread group id by