Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1280300pxb; Sun, 12 Sep 2021 13:47:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywSYNE2P083xO/ZbARwkglRy16aOClQFwNaQF+dBhhy59UnkxuEhmd+7oypmvdV49uOIC2 X-Received: by 2002:a6b:6a13:: with SMTP id x19mr6428673iog.111.1631479628768; Sun, 12 Sep 2021 13:47:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631479628; cv=none; d=google.com; s=arc-20160816; b=Xx5VUN+3G1K0Ul6Ec/DsWnuAt6ml2De7D9kEiBuhjRbW9Jic+Qlw4NiID6EH07yJ6h RcKQ4yb6YFVpZ8E4MELX/Qedd4Nz5c+v18PZ6OVE7PT6zPX+HOH3h99UN6OkrVBqkMxn 2cFPBx4R5h40Q8CaBlkt9ka4wDwqxmA/4dDdGW13wXjJ/Z5f29w2Ks5mRTHC3QHwUiko K5Wt2HNMjMCoFoJg//iCWg0qnqeKvtVTU3eCBBtesl5Q4CYJfMRknoP0zKOcPM4aOB2W Z5MVe8Nn+evaPMm66rD0J+nLV5h8itvoe368Illeq8oVDF5D5F67/grZy+0oiGLk8II3 SNSg== 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=PjvlGSdnGG5wtWxkF3EyFLoH5h3Fuzy88PPCh+MZH4E=; b=OIu6zfRQR9tqvBXoGjYg+In09P5+f9g6YnCORuPgBq+bevxnPgyQIZ6A0rfIHVwERT x2XVSxRLn01MFOevQG4sqSjetsyVGrJv/CYSLtcCbEVstvMEIbNqvRdO2MrgxKGB9hYq smLhVDmv5Ot/+9/bL83I+GUHlzask1RNhKGGqJO4GauHP0N84Uk4y1TrxgTLssYyRfvT jc2be7sHBA4Rgu6TGaS5X/UfbCd72wOM34eowbZzK0TzhGKB0bKdeXdS4b1Q0bbq+KsN xuqgP9OgQyB6R1uiZK+8aKW9zXqCEgO/9WIijXzMLO9KoKxbYSSpoRzLf7Yt7KKaFdOK UQZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VilmpcwA; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b3si5027405iot.102.2021.09.12.13.46.58; Sun, 12 Sep 2021 13:47:08 -0700 (PDT) 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=@redhat.com header.s=mimecast20190719 header.b=VilmpcwA; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236493AbhILUrM (ORCPT + 99 others); Sun, 12 Sep 2021 16:47:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:33787 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236292AbhILUrL (ORCPT ); Sun, 12 Sep 2021 16:47:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631479556; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=PjvlGSdnGG5wtWxkF3EyFLoH5h3Fuzy88PPCh+MZH4E=; b=VilmpcwAY6CUb+UvkTALaoR0nb6/t+keXds9Ey5OVfC2VbtHUnREagVxZmkVHFkxUyHuT6 HwAA20n2+rd9RdRr19KzFQHxxAGn7FjIBhCQThaIPNRZpHCbxizl7yqDWQk7hoziCCLvON N+O7zC4u3p9Z/3mfLX0d1nVAtHfzQaA= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-162-LcPkuSeWP5iwO2sIv1pg-Q-1; Sun, 12 Sep 2021 16:45:55 -0400 X-MC-Unique: LcPkuSeWP5iwO2sIv1pg-Q-1 Received: by mail-ed1-f71.google.com with SMTP id g11-20020a056402090b00b003d114f9cb8aso1420286edz.20 for ; Sun, 12 Sep 2021 13:45:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=PjvlGSdnGG5wtWxkF3EyFLoH5h3Fuzy88PPCh+MZH4E=; b=FGOJsh8xt7ywSNTuK3XxLEKA0A5FG9EHsqDI/zPa30oOpjmV2Yi0Ri2Jk9SSZM5++v 95+xxEyW68CL5LqAdTX/+N22RvYaZPWJv5gz89xdgYMyr1Gxkvlt4nfD6+ugtOtfzoMi 6LbBnppDc5+E9bZOgcKhFvNGRZxHqmG3iqYFKk/tWWUnXbMo6LHm2SR1XCE3aO11HE/R cc9psVAbujaYQLqNDQli0iXHXjNi8/nHUhExNhOo5TZCZwB9gL6Di7jenHhi4rZcoUnz +mQVx7/GeDkBzQyuzsFgtrkkpavSTbMS+S/UoUNsE09iFVGbUaX731+uKTSu6+VYzAL1 3MIg== X-Gm-Message-State: AOAM531ReilCZFFv9k+UKMKjiVl0D7O2RY5U2WsChIHZ/NxoS4VVUgdj r0bPDx6aayGov7M5aM6mbJOkKwrUVSAT6gblHz16HrF2QwsslV5XeWGZncCbNWyoeKBl2HlrV7i RW+jvK7oiTn3o/qSghyiQp2As X-Received: by 2002:a17:906:5d6:: with SMTP id t22mr9060897ejt.98.1631479554365; Sun, 12 Sep 2021 13:45:54 -0700 (PDT) X-Received: by 2002:a17:906:5d6:: with SMTP id t22mr9060882ejt.98.1631479554232; Sun, 12 Sep 2021 13:45:54 -0700 (PDT) Received: from krava ([83.240.60.52]) by smtp.gmail.com with ESMTPSA id r16sm2841070edt.15.2021.09.12.13.45.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Sep 2021 13:45:53 -0700 (PDT) Date: Sun, 12 Sep 2021 22:45:52 +0200 From: Jiri Olsa To: Alexey Bayduraev Cc: Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , linux-kernel , Andi Kleen , Adrian Hunter , Alexander Antonov , Alexei Budankov , Riccardo Mancini Subject: Re: [PATCH v10 05/24] perf record: Introduce thread local variable Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 12, 2021 at 09:46:05AM +0300, Alexey Bayduraev wrote: > Introduce thread local variable and use it for threaded trace streaming. > Use thread affinity mask instead or record affinity mask in affinity > modes. > > Acked-by: Andi Kleen > Acked-by: Namhyung Kim > Signed-off-by: Alexey Bayduraev > --- > tools/perf/builtin-record.c | 139 ++++++++++++++++++++++++------------ > 1 file changed, 93 insertions(+), 46 deletions(-) > > diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c > index a25b23affc43..dfc5db24e037 100644 > --- a/tools/perf/builtin-record.c > +++ b/tools/perf/builtin-record.c > @@ -110,6 +110,8 @@ struct record_thread { > unsigned long waking; > }; > > +static __thread struct record_thread *thread; > + > struct record { > struct perf_tool tool; > struct record_opts opts; > @@ -132,7 +134,6 @@ struct record { > bool timestamp_boundary; > struct switch_output switch_output; > unsigned long long samples; > - struct mmap_cpu_mask affinity_mask; > unsigned long output_max_size; /* = 0: unlimited */ > int nr_threads; > struct thread_mask *thread_masks; > @@ -574,7 +575,7 @@ static int record__pushfn(struct mmap *map, void *to, void *bf, size_t size) > bf = map->data; > } > > - rec->samples++; > + thread->samples++; > return record__write(rec, map, bf, size); > } > > @@ -1317,19 +1318,29 @@ static struct perf_event_header finished_round_event = { > .type = PERF_RECORD_FINISHED_ROUND, > }; > > -static void record__adjust_affinity(struct record *rec, struct mmap *map) > +static int record__adjust_affinity(struct record *rec, struct mmap *map) hm, why changing the return value if the caller does not check it? jirka > { > + int ret = 0; > + > if (rec->opts.affinity != PERF_AFFINITY_SYS && > - !bitmap_equal(rec->affinity_mask.bits, map->affinity_mask.bits, > - rec->affinity_mask.nbits)) { > - bitmap_zero(rec->affinity_mask.bits, rec->affinity_mask.nbits); > - bitmap_or(rec->affinity_mask.bits, rec->affinity_mask.bits, > - map->affinity_mask.bits, rec->affinity_mask.nbits); > - sched_setaffinity(0, MMAP_CPU_MASK_BYTES(&rec->affinity_mask), > - (cpu_set_t *)rec->affinity_mask.bits); > - if (verbose == 2) > - mmap_cpu_mask__scnprintf(&rec->affinity_mask, "thread"); > + !bitmap_equal(thread->mask->affinity.bits, map->affinity_mask.bits, > + thread->mask->affinity.nbits)) { > + bitmap_zero(thread->mask->affinity.bits, thread->mask->affinity.nbits); > + bitmap_or(thread->mask->affinity.bits, thread->mask->affinity.bits, > + map->affinity_mask.bits, thread->mask->affinity.nbits); > + ret = sched_setaffinity(0, MMAP_CPU_MASK_BYTES(&thread->mask->affinity), > + (cpu_set_t *)thread->mask->affinity.bits); > + if (ret) > + pr_err("threads[%d]: sched_setaffinity() call failed: %s\n", > + thread->tid, strerror(errno)); > + if (verbose == 2) { > + pr_debug("threads[%d]: addr=", thread->tid); > + mmap_cpu_mask__scnprintf(&thread->mask->affinity, "thread"); > + pr_debug("threads[%d]: on cpu=%d\n", thread->tid, sched_getcpu()); > + } > } > + > + return ret; > } SNIP