Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1666153rda; Mon, 23 Oct 2023 22:19:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGapURaiuN4tV35QBBoso0vr2PxwtO+Ag/dHM6YO8+CrfVE/qjMzeKNt6FbcuNZEegJxF88 X-Received: by 2002:a05:6a21:6707:b0:163:a3ce:a699 with SMTP id wh7-20020a056a21670700b00163a3cea699mr1428934pzb.57.1698124790661; Mon, 23 Oct 2023 22:19:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698124790; cv=none; d=google.com; s=arc-20160816; b=uF/yn3OUeQV5S+VFM5UWfcsLqN2E6n5aFSgmxxg/WQZ3ltSgv/JS+IohEaj9FHaYLO Gdcc1yOksDqGBg2IU8FDDoMUPfieegsPKi4301uHoAdaninCfXh82mJ/ybQY11PqNAAX 28PtROAS4Y9p514QkJ2iWtfBpycP/3k9mDY0EUJ9cgm1aN4tD86bdEKfP1/5rFF0M7D1 T5hbcoR/Q6B7n2smYKDE/HqiIcgCBm3eu7CrmQVrRM8qNbUJ7wIRtMrbV/eQjAlH4kP5 DKjT97kOO1KUODaYJGCdfqZyD5JJhjWCh8sch/NH5hFY6D982OrE/z44J8hvXOAKnPfX wjLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=zGHQiKqlZEd2S3QD16NqFoMTAi8LWOGUkNItSoa6eI8=; fh=d2WCkEldfdjRgEHwKaKpJoFABvj4d3LlOU1Hue6060s=; b=T9P4TgjmukshupcrJ5wJnqPLw/hQxPD1rQW4oL9peQWZpxektygmTGnYehas5zQBm6 /69qEHUkoEvqUNhjj0uwFljuKAT90InNz/xW67ZCoIIqLDAhYRt9iAuSfMH2IDrI7P4p zWcPpfnL0Ff2CIcm/zHFteYetgsxJjs/BDGawrjrSqStcEMRW3PUDfYcey7SYZEA78GU IpOfTPw7nDJi5ALykWsCXo4J9JOJh8JkYFLu8LSVOpl2Q1nP1ghcSAsOedi+6N84JsHu 0RFJrH1ZfnwRJsLwpcdFbD041IaD9cuIFfz9o2yXEgdron0lDLIHf+uIkefescnN2g9T l5ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LdP94EYb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id gl14-20020a17090b120e00b0026ceee6848asi10075810pjb.180.2023.10.23.22.19.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 22:19:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LdP94EYb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id DFD9F802F975; Mon, 23 Oct 2023 22:19:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232069AbjJXFTi (ORCPT + 99 others); Tue, 24 Oct 2023 01:19:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229688AbjJXFTg (ORCPT ); Tue, 24 Oct 2023 01:19:36 -0400 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E052E5; Mon, 23 Oct 2023 22:19:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698124774; x=1729660774; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=MRmrUcwHWy3mkUYsQTE4raBpxOs+Zla7IRIOfm8KL0s=; b=LdP94EYbwv/ytljH0cn7zpVWlkdSx6vV5lBpBgVHz+VxyZcO65eVYhqp NRkFbCZg1HWova8I7SrwqrtqRvDt6oaDUdVH2F1nkcy0U+Opvp72aYoWJ ixqrrkDzxVGWKLE8frV968dT73GfVnMKAeMgpcBBYnaoZEBso6yPjfTF0 UK57PaqvnsB8Uu5/QHsRdaVgy3vTTO16/PL850AokJeeVEN8aIUYuQ1bf PYetRoOwJfvXVxZm3WG0FZrgsWNYO0jU8GOwaNe6MIjIyAtfBYlh+tP9k hzebVvjXRYRsk+8TBhPUtNNSvRKiWT491B/HK4KkoPsteT+qC8bOkMitu Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="5613032" X-IronPort-AV: E=Sophos;i="6.03,246,1694761200"; d="scan'208";a="5613032" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Oct 2023 22:19:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.03,246,1694761200"; d="scan'208";a="6335219" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO [10.0.2.15]) ([10.252.63.12]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Oct 2023 22:19:21 -0700 Message-ID: <92fe21ab-af6f-4417-b241-eac0532e115a@intel.com> Date: Tue, 24 Oct 2023 08:19:23 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 13/13] perf machine thread: Remove exited threads by default To: Ian Rogers Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Nick Terrell , Kan Liang , Song Liu , Sandipan Das , Anshuman Khandual , James Clark , Liam Howlett , Miguel Ojeda , Leo Yan , German Gomez , Ravi Bangoria , Artem Savkov , Athira Rajeev , Andi Kleen , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org References: <20231012062359.1616786-1-irogers@google.com> <20231012062359.1616786-14-irogers@google.com> Content-Language: en-US From: Adrian Hunter Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 23 Oct 2023 22:19:48 -0700 (PDT) On 23/10/23 21:49, Ian Rogers wrote: > On Mon, Oct 23, 2023 at 7:24 AM Adrian Hunter wrote: >> >> On 12/10/23 09:23, Ian Rogers wrote: >>> struct thread values hold onto references to mmaps, dsos, etc. When a >>> thread exits it is necessary to clean all of this memory up by >>> removing the thread from the machine's threads. Some tools require >>> this doesn't happen, such as perf report if offcpu events exist or if >>> a task list is being generated, so add a symbol_conf value to make the >>> behavior optional. When an exited thread is left in the machine's >>> threads, mark it as exited. >>> >>> This change relates to commit 40826c45eb0b ("perf thread: Remove >>> notion of dead threads"). Dead threads were removed as they had a >>> reference count of 0 and were difficult to reason about with the >>> reference count checker. Here a thread is removed from threads when it >>> exits, unless via symbol_conf the exited thread isn't remove and is >>> marked as exited. Reference counting behaves as it normally does. >> >> Can we exclude AUX area tracing? >> >> Essentially, the EXIT event happens when the task is still running >> in kernel mode, so the thread has not in fact fully exited. >> >> Example: >> >> # perf record -a --kcore -e intel_pt// uname >> >> Before: >> >> # perf script --itrace=b --show-task-events -C6 | grep -C10 EXIT >> uname 14740 [006] 26795.092638: 1 branches: ffffffffb63124ee __perf_event_header__init_id+0x5e ([kernel.kallsyms]) => ffffffffb63124f7 __perf_event_header__init_id+0x67 ([kernel.kallsyms]) >> uname 14740 [006] 26795.092638: 1 branches: ffffffffb6312501 __perf_event_header__init_id+0x71 ([kernel.kallsyms]) => ffffffffb6312512 __perf_event_header__init_id+0x82 ([kernel.kallsyms]) >> uname 14740 [006] 26795.092638: 1 branches: ffffffffb6312531 __perf_event_header__init_id+0xa1 ([kernel.kallsyms]) => ffffffffb6316b3a perf_event_task_output+0x26a ([kernel.kallsyms]) >> uname 14740 [006] 26795.092638: 1 branches: ffffffffb6316b40 perf_event_task_output+0x270 ([kernel.kallsyms]) => ffffffffb6316959 perf_event_task_output+0x89 ([kernel.kallsyms]) >> uname 14740 [006] 26795.092638: 1 branches: ffffffffb6316966 perf_event_task_output+0x96 ([kernel.kallsyms]) => ffffffffb6322040 perf_output_begin+0x0 ([kernel.kallsyms]) >> uname 14740 [006] 26795.092638: 1 branches: ffffffffb6322080 perf_output_begin+0x40 ([kernel.kallsyms]) => ffffffffb6194dc0 __rcu_read_lock+0x0 ([kernel.kallsyms]) >> uname 14740 [006] 26795.092638: 1 branches: ffffffffb6194de1 __rcu_read_lock+0x21 ([kernel.kallsyms]) => ffffffffb6322085 perf_output_begin+0x45 ([kernel.kallsyms]) >> uname 14740 [006] 26795.092638: 1 branches: ffffffffb63220ce perf_output_begin+0x8e ([kernel.kallsyms]) => ffffffffb611d280 preempt_count_add+0x0 ([kernel.kallsyms]) >> uname 14740 [006] 26795.092638: 1 branches: ffffffffb611d2bf preempt_count_add+0x3f ([kernel.kallsyms]) => ffffffffb63220d3 perf_output_begin+0x93 ([kernel.kallsyms]) >> uname 14740 [006] 26795.092638: 1 branches: ffffffffb63220e8 perf_output_begin+0xa8 ([kernel.kallsyms]) => ffffffffb63220ff perf_output_begin+0xbf ([kernel.kallsyms]) >> uname 14740 [006] 26795.092638: PERF_RECORD_EXIT(14740:14740):(14739:14739) >> uname 14740 [006] 26795.092638: 1 branches: ffffffffb6322119 perf_output_begin+0xd9 ([kernel.kallsyms]) => ffffffffb6322128 perf_output_begin+0xe8 ([kernel.kallsyms]) >> uname 14740 [006] 26795.092638: 1 branches: ffffffffb6322146 perf_output_begin+0x106 ([kernel.kallsyms]) => ffffffffb63220ea perf_output_begin+0xaa ([kernel.kallsyms]) >> uname 14740 [006] 26795.092638: 1 branches: ffffffffb63220f9 perf_output_begin+0xb9 ([kernel.kallsyms]) => ffffffffb63221ab perf_output_begin+0x16b ([kernel.kallsyms]) >> uname 14740 [006] 26795.092638: 1 branches: ffffffffb63221ae perf_output_begin+0x16e ([kernel.kallsyms]) => ffffffffb63221b6 perf_output_begin+0x176 ([kernel.kallsyms]) >> uname 14740 [006] 26795.092638: 1 branches: ffffffffb6322202 perf_output_begin+0x1c2 ([kernel.kallsyms]) => ffffffffb6322167 perf_output_begin+0x127 ([kernel.kallsyms]) >> uname 14740 [006] 26795.092638: 1 branches: ffffffffb632218c perf_output_begin+0x14c ([kernel.kallsyms]) => ffffffffb631696b perf_event_task_output+0x9b ([kernel.kallsyms]) >> uname 14740 [006] 26795.092638: 1 branches: ffffffffb6316990 perf_event_task_output+0xc0 ([kernel.kallsyms]) => ffffffffb61034a0 __task_pid_nr_ns+0x0 ([kernel.kallsyms]) >> uname 14740 [006] 26795.092638: 1 branches: ffffffffb61034b7 __task_pid_nr_ns+0x17 ([kernel.kallsyms]) => ffffffffb6194dc0 __rcu_read_lock+0x0 ([kernel.kallsyms]) >> uname 14740 [006] 26795.092638: 1 branches: ffffffffb6194de1 __rcu_read_lock+0x21 ([kernel.kallsyms]) => ffffffffb61034bc __task_pid_nr_ns+0x1c ([kernel.kallsyms]) >> uname 14740 [006] 26795.092638: 1 branches: ffffffffb6103503 __task_pid_nr_ns+0x63 ([kernel.kallsyms]) => ffffffffb610353b __task_pid_nr_ns+0x9b ([kernel.kallsyms]) >> >> After: >> >> $ perf script --itrace=b --show-task-events -C6 | grep -C10 EXIT >> uname 14740 [006] 26795.092638: 1 branches: ffffffffb63124ee __perf_event_header__init_id+0x5e ([kernel.kallsyms]) => ffffffffb63124f7 __perf_event_header__init_id+0x67 ([kernel.kallsyms]) >> uname 14740 [006] 26795.092638: 1 branches: ffffffffb6312501 __perf_event_header__init_id+0x71 ([kernel.kallsyms]) => ffffffffb6312512 __perf_event_header__init_id+0x82 ([kernel.kallsyms]) >> uname 14740 [006] 26795.092638: 1 branches: ffffffffb6312531 __perf_event_header__init_id+0xa1 ([kernel.kallsyms]) => ffffffffb6316b3a perf_event_task_output+0x26a ([kernel.kallsyms]) >> uname 14740 [006] 26795.092638: 1 branches: ffffffffb6316b40 perf_event_task_output+0x270 ([kernel.kallsyms]) => ffffffffb6316959 perf_event_task_output+0x89 ([kernel.kallsyms]) >> uname 14740 [006] 26795.092638: 1 branches: ffffffffb6316966 perf_event_task_output+0x96 ([kernel.kallsyms]) => ffffffffb6322040 perf_output_begin+0x0 ([kernel.kallsyms]) >> uname 14740 [006] 26795.092638: 1 branches: ffffffffb6322080 perf_output_begin+0x40 ([kernel.kallsyms]) => ffffffffb6194dc0 __rcu_read_lock+0x0 ([kernel.kallsyms]) >> uname 14740 [006] 26795.092638: 1 branches: ffffffffb6194de1 __rcu_read_lock+0x21 ([kernel.kallsyms]) => ffffffffb6322085 perf_output_begin+0x45 ([kernel.kallsyms]) >> uname 14740 [006] 26795.092638: 1 branches: ffffffffb63220ce perf_output_begin+0x8e ([kernel.kallsyms]) => ffffffffb611d280 preempt_count_add+0x0 ([kernel.kallsyms]) >> uname 14740 [006] 26795.092638: 1 branches: ffffffffb611d2bf preempt_count_add+0x3f ([kernel.kallsyms]) => ffffffffb63220d3 perf_output_begin+0x93 ([kernel.kallsyms]) >> uname 14740 [006] 26795.092638: 1 branches: ffffffffb63220e8 perf_output_begin+0xa8 ([kernel.kallsyms]) => ffffffffb63220ff perf_output_begin+0xbf ([kernel.kallsyms]) >> uname 14740 [006] 26795.092638: PERF_RECORD_EXIT(14740:14740):(14739:14739) >> :14740 14740 [006] 26795.092638: 1 branches: ffffffffb6322119 perf_output_begin+0xd9 ([kernel.kallsyms]) => ffffffffb6322128 perf_output_begin+0xe8 ([kernel.kallsyms]) >> :14740 14740 [006] 26795.092638: 1 branches: ffffffffb6322146 perf_output_begin+0x106 ([kernel.kallsyms]) => ffffffffb63220ea perf_output_begin+0xaa ([kernel.kallsyms]) >> :14740 14740 [006] 26795.092638: 1 branches: ffffffffb63220f9 perf_output_begin+0xb9 ([kernel.kallsyms]) => ffffffffb63221ab perf_output_begin+0x16b ([kernel.kallsyms]) >> :14740 14740 [006] 26795.092638: 1 branches: ffffffffb63221ae perf_output_begin+0x16e ([kernel.kallsyms]) => ffffffffb63221b6 perf_output_begin+0x176 ([kernel.kallsyms]) >> :14740 14740 [006] 26795.092638: 1 branches: ffffffffb6322202 perf_output_begin+0x1c2 ([kernel.kallsyms]) => ffffffffb6322167 perf_output_begin+0x127 ([kernel.kallsyms]) >> :14740 14740 [006] 26795.092638: 1 branches: ffffffffb632218c perf_output_begin+0x14c ([kernel.kallsyms]) => ffffffffb631696b perf_event_task_output+0x9b ([kernel.kallsyms]) >> :14740 14740 [006] 26795.092638: 1 branches: ffffffffb6316990 perf_event_task_output+0xc0 ([kernel.kallsyms]) => ffffffffb61034a0 __task_pid_nr_ns+0x0 ([kernel.kallsyms]) >> :14740 14740 [006] 26795.092638: 1 branches: ffffffffb61034b7 __task_pid_nr_ns+0x17 ([kernel.kallsyms]) => ffffffffb6194dc0 __rcu_read_lock+0x0 ([kernel.kallsyms]) >> :14740 14740 [006] 26795.092638: 1 branches: ffffffffb6194de1 __rcu_read_lock+0x21 ([kernel.kallsyms]) => ffffffffb61034bc __task_pid_nr_ns+0x1c ([kernel.kallsyms]) >> :14740 14740 [006] 26795.092638: 1 branches: ffffffffb6103503 __task_pid_nr_ns+0x63 ([kernel.kallsyms]) => ffffffffb610353b __task_pid_nr_ns+0x9b ([kernel.kallsyms]) >> >> This will also affect samples made after PERF_RECORD_EXIT but before >> the task finishes exiting. > > Makes sense. Would an appropriate fix be in perf_session__open to set: > symbol_conf.keep_exited_threads = true; > > when: > perf_header__has_feat(&session->header, HEADER_AUXTRACE) > > It is kind of hacky to be changing global state this way, but > symbol_conf is like that in general. That should work. Alternatively, could be added to perf_event__process_auxtrace_info() which would tie it more directly to auxtrace, and wouldn't have to check HEADER_AUXTRACE.