Received: by 2002:a19:ef0c:0:0:0:0:0 with SMTP id n12csp952459lfh; Tue, 1 Feb 2022 12:56:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJyk8VCxpqLN49NA8Q5SNC7npxqr4/XrtCx9OUZMzn05EQPtwtulK4YWiAooD4ndPCLtkPSK X-Received: by 2002:a17:90b:4a06:: with SMTP id kk6mr4421215pjb.140.1643748664443; Tue, 01 Feb 2022 12:51:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643748664; cv=none; d=google.com; s=arc-20160816; b=H1KCJEl4WSZ3ZkOrkJBDVp8EuEYNgD2PFnSz1LNXzkcDGdR6ivhp1khMBdLCc5Gobq io3Uy5opUbsw3wlLUXFR7V4h9F+C/W8gQL0MQe1hEbQnbLnixPrM9IlhTsS7Yjb+yF4o BJmrN2R6avkO5MnGckmTsbtO0TAOCcri31bezhlGQXoepW6dec29ZUOoOpQYojIyOMQO snvSVFWhj6uQZEaxEny5/9r1f+3eD4evYi4KxX0mzPfGbP5uQICe1671YeHbx8oUy/sE LUfcEzPAC+xz+QcS1rCYNmfHYN1Ww1XbmPhgngiQi5gpXmPzQnBM926hBeyKFhD7pyQ+ yPxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=LEIW+Nf/QbI3vJxTHaufDbpWB+Xx6Ct7nx7pccZoG0w=; b=bYm5K4luKMFlv+50G9FQQJ5QcPd5+3Zp4l9DtaKxBSqDFOpIXQORL+uhvjHE+DdQ4M EoUnAd/odumKUGz8C+FMXGheoNFU8xa3t3G5NH0/WW/7LksvPiyVCCY6s8TTgE3I/vJD sMqSyEjpZuQYqN7RP/bQuJ/iAKOGjJkUAZN7ZqFr1aL5tT80tj0wH+RS4Ym3R3YScyn0 sQWBQVjp4u6X5pe8vsUN9XvDw26ZscqKNcp7WfzvmQHNooNbHPpjpzZAOYMHuuCh4IGN oCEULi8K/AN2nz0lvv3+vI6N024XdPnYLP8Ewb6vNP6R+kjpXliUVxwanAsVEjhv4sjD uzOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iukrbAK7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y9si3054927pjp.56.2022.02.01.12.50.53; Tue, 01 Feb 2022 12:51:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iukrbAK7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381162AbiAaVlx (ORCPT + 99 others); Mon, 31 Jan 2022 16:41:53 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:49496 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381294AbiAaVjp (ORCPT ); Mon, 31 Jan 2022 16:39:45 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 62ABCB82C34 for ; Mon, 31 Jan 2022 21:39:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D513FC340E8; Mon, 31 Jan 2022 21:39:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643665182; bh=VYksMSxSzjbcHcVo3bU2HJeQ6tQJPtdJTlSrX35F7KY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=iukrbAK78NTQn3W7vcyduYTbrMrwUogsoPhRr2py9KmisvCny2aLMYnkMXgekyPA5 KIMHyDcBPxu/ar0JlU6Hbs5ykAqg8JUKvm7iz8b1q48/a5hMP9O8KzRsP5NTuGq7B/ CoAhvbNenxWqIze9ey5hekSd2Y0EFDMrptUr1LqQOcD+NlnGi2QURntanQaLC0UkXN qV3+qUAtL8UBZ+WW79glfyMYw72/QVwqV4eFudfpIoxqVoT01VAAXv5lFRRx/lfSuY MpwCqCNPf27lujyWo2qRRoKrSMb2RlflJdSRyD5ufgkR0Pa6qp/g4nckCwVCFiJELP PRZ1GPBnTJ67A== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 2600440466; Mon, 31 Jan 2022 18:39:39 -0300 (-03) Date: Mon, 31 Jan 2022 18:39:39 -0300 From: Arnaldo Carvalho de Melo To: Alexey Bayduraev Cc: Jiri Olsa , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , linux-kernel , Andi Kleen , Adrian Hunter , Alexander Antonov , Alexei Budankov , Riccardo Mancini Subject: Re: [PATCH v13 03/16] perf record: Introduce thread specific data array Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Mon, Jan 17, 2022 at 09:34:23PM +0300, Alexey Bayduraev escreveu: > Introduce thread specific data object and array of such objects > to store and manage thread local data. Implement functions to > allocate, initialize, finalize and release thread specific data. > > Thread local maps and overwrite_maps arrays keep pointers to > mmap buffer objects to serve according to maps thread mask. > Thread local pollfd array keeps event fds connected to mmaps > buffers according to maps thread mask. > > Thread control commands are delivered via thread local comm pipes > and ctlfd_pos fd. External control commands (--control option) > are delivered via evlist ctlfd_pos fd and handled by the main > tool thread. > > Acked-by: Namhyung Kim > Reviewed-by: Riccardo Mancini > Tested-by: Riccardo Mancini > Signed-off-by: Alexey Bayduraev Some changes to reduce patch size, I have them in my local tree, will publish later. diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 1645b40540b870aa..a8c7118a95c6a3fa 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -924,7 +924,7 @@ static void record__thread_data_close_pipes(struct record_thread *thread_data) static int record__thread_data_init_maps(struct record_thread *thread_data, struct evlist *evlist) { - int m, tm, nr_mmaps = evlist->core.nr_mmaps; + int nr_mmaps = evlist->core.nr_mmaps; struct mmap *mmap = evlist->mmap; struct mmap *overwrite_mmap = evlist->overwrite_mmap; struct perf_cpu_map *cpus = evlist->core.cpus; @@ -946,7 +946,7 @@ static int record__thread_data_init_maps(struct record_thread *thread_data, stru pr_debug2("thread_data[%p]: nr_mmaps=%d, maps=%p, ow_maps=%p\n", thread_data, thread_data->nr_mmaps, thread_data->maps, thread_data->overwrite_maps); - for (m = 0, tm = 0; m < nr_mmaps && tm < thread_data->nr_mmaps; m++) { + for (int m = 0, tm = 0; m < nr_mmaps && tm < thread_data->nr_mmaps; m++) { if (test_bit(cpus->map[m].cpu, thread_data->mask->maps.bits)) { if (thread_data->maps) { thread_data->maps[tm] = &mmap[m]; @@ -967,21 +967,18 @@ static int record__thread_data_init_maps(struct record_thread *thread_data, stru static int record__thread_data_init_pollfd(struct record_thread *thread_data, struct evlist *evlist) { - int f, tm, pos; - struct mmap *map, *overwrite_map; - fdarray__init(&thread_data->pollfd, 64); - for (tm = 0; tm < thread_data->nr_mmaps; tm++) { - map = thread_data->maps ? thread_data->maps[tm] : NULL; - overwrite_map = thread_data->overwrite_maps ? - thread_data->overwrite_maps[tm] : NULL; + for (int tm = 0; tm < thread_data->nr_mmaps; tm++) { + struct mmap *map = thread_data->maps ? thread_data->maps[tm] : NULL, + *overwrite_map = thread_data->overwrite_maps ? + thread_data->overwrite_maps[tm] : NULL; - for (f = 0; f < evlist->core.pollfd.nr; f++) { + for (int f = 0; f < evlist->core.pollfd.nr; f++) { void *ptr = evlist->core.pollfd.priv[f].ptr; if ((map && ptr == map) || (overwrite_map && ptr == overwrite_map)) { - pos = fdarray__dup_entry_from(&thread_data->pollfd, f, + int pos = fdarray__dup_entry_from(&thread_data->pollfd, f, &evlist->core.pollfd); if (pos < 0) return pos; @@ -996,13 +993,12 @@ static int record__thread_data_init_pollfd(struct record_thread *thread_data, st static void record__free_thread_data(struct record *rec) { - int t; struct record_thread *thread_data = rec->thread_data; if (thread_data == NULL) return; - for (t = 0; t < rec->nr_threads; t++) { + for (int t = 0; t < rec->nr_threads; t++) { record__thread_data_close_pipes(&thread_data[t]); zfree(&thread_data[t].maps); zfree(&thread_data[t].overwrite_maps); @@ -1014,20 +1010,18 @@ static void record__free_thread_data(struct record *rec) static int record__alloc_thread_data(struct record *rec, struct evlist *evlist) { - int t, ret; - struct record_thread *thread_data; + struct record_thread *thread_data = rec->thread_data = zalloc(rec->nr_threads * sizeof(*(rec->thread_data))); + int ret; - rec->thread_data = zalloc(rec->nr_threads * sizeof(*(rec->thread_data))); if (!rec->thread_data) { pr_err("Failed to allocate thread data\n"); return -ENOMEM; } - thread_data = rec->thread_data; - for (t = 0; t < rec->nr_threads; t++) + for (int t = 0; t < rec->nr_threads; t++) record__thread_data_init_pipes(&thread_data[t]); - for (t = 0; t < rec->nr_threads; t++) { + for (int t = 0; t < rec->nr_threads; t++) { thread_data[t].rec = rec; thread_data[t].mask = &rec->thread_masks[t]; ret = record__thread_data_init_maps(&thread_data[t], evlist);