Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2117408rbb; Tue, 27 Feb 2024 11:06:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUqFcdJc3nWARG7QoFjVq9Ti5egpTEv1c4FPQRys3FIBJ8Zj4AF8N7jistH7ZtxkDNcj697FUzfL3j3JZyBGkpFLFxX27Ep7oBRNwnXjQ== X-Google-Smtp-Source: AGHT+IF4GwUSnwUYUU2rndYEPAMdLRNqpVMaLPMjKW0hnxdCSigFO1y03tt4Hp0ogFaobQq6mveb X-Received: by 2002:a05:620a:2488:b0:787:cf11:7744 with SMTP id i8-20020a05620a248800b00787cf117744mr3414742qkn.10.1709060815803; Tue, 27 Feb 2024 11:06:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709060815; cv=pass; d=google.com; s=arc-20160816; b=cCJVs3rWahN6l2lVkHNLn00cyCI4tblnQCjwKukCdoxUsuKsdJ+ScAwnCKuNBebctO yT0ML+th4WW4lE8tlPt4g2Zuq2Kmpaa5RoHWtovV6qaOsin2zAQwh2spqmT68UeVb5cy jUbG6D1WIqGtV/nqhBN06/4Elkj9qxUdZUgq8Flkvyilg50CIzpyu+QGAKNF4V05bWbm iEKyhaPBjEH8WCoDkaOKMzpG6/fnjy2fewtOAKkEJ8E5sCiseXB5jXBPpFxNtPC0uUor CF7ALBF6KVHdEinHHZtVa0tYQ+CMkaiayqLoh6T99SJpjMxCAkKykYJJLdrssyPxvCdf RoPg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=fRRnLAvPnPJL+HqV6rL3Yv2zNLZuv51RwIxNYUJXEyo=; fh=9ho8cg0Mfug81c65eVar5mlqAOJb01gYl8kmazx/Hrk=; b=LmbL0wOeOH3R1+duMTV2+WWTvRyg1nZizNfUNbRIx+1+iURC8iQUGWujlHDG+ys1C9 MqUgWtHyqTheufmihy0IpvU40Ej6NGxD2Ymtpm21NK9VAVtbz3t76wcIG6Nia5yVkG9R iFUARF2trkQpSOgiFbLiAogrV1LchnZI/Ve3C5fWDUBkq9oy0Fk7vLyM3LYWUR8/RmiY HpDH6+waWBVT5ihi5mAI3ueyIpAkekdqWMhX9NC2Qnrq/cPoIXRRHtRIl3cD/5HeluYZ FsgTkPYdwhhDYhgyLqVv40vv49uuAhBBCUpxRwkgAW0uS+JhzBJ0wgcjJ5SS/tdffU1J FsUA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=CqHlh4sF; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-83892-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83892-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id t6-20020a05620a450600b0078790b3f988si8796360qkp.678.2024.02.27.11.06.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 11:06:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83892-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=CqHlh4sF; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-83892-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83892-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 630F91C284BD for ; Tue, 27 Feb 2024 19:05:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3159F14A09D; Tue, 27 Feb 2024 19:03:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="CqHlh4sF" Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 CD6A05103E for ; Tue, 27 Feb 2024 19:03:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709060595; cv=none; b=Xwj4h+o7IA29mkUVCZQPw1p6W1myjlYj+iMHuIdkJjCLGr/6w9FoIa0puKgLRK7KHpmWzw7NctKK6FETuH54IHGJHwnWHdva0VI5wmqOhX+CLFP3FPDMb4mPejlpLTkTzTCsQ/To9l28cyztgjhMtPqOVTkwHKJu6IPKKJ3D7eM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709060595; c=relaxed/simple; bh=9nLhrXPMhg/lpHUesGNCTSpBc6WvsvSD3/Ew6JjfWno=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=T8VP6zoaSpCX84DwYS1x3vvsZE8NByl+8Mje6GW5bS0RBKTsy4NYkJNNEbV38R3bFYhQD8fZOa6frOT00Ad39mbej+0SKlHUXZAJMqxf/CrLE2PnCJc/N4THKvXHlri4zn44DGgcCrxlO2eDUrKyfTFpbXgnBg8abQf3MwgbTsc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=CqHlh4sF; arc=none smtp.client-ip=209.85.214.172 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=google.com Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1dc744f54d0so21395ad.0 for ; Tue, 27 Feb 2024 11:03:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709060593; x=1709665393; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=fRRnLAvPnPJL+HqV6rL3Yv2zNLZuv51RwIxNYUJXEyo=; b=CqHlh4sF4sqxO6/CJ5naVIdHRRM7Q9iZWUmmVPbm43sC4DyVHXP/fNGOfhXHgNxtyS +aszEzGjmPMFDTNz1NdCdAkgmeLGyrl0jVblqHwzYyBEmbG8bpcZXEcm7+EhuCynsPrs 8ttx2SDGnExpjMU2IYCjVzxvjekbhTgRjbeGqziXaLIHZ4eI0AysYFhhtFVBZShEHN2X HDhqyecnkH1758H+tlIqwnuIhblJFcn7PQusxTtitjq9KORYOwBjH4XyXOdbpaRZMuT9 6zyV1aNssyZd8FnAABZYBjzZZ7gSFjn+KExoYPa9F6/Cp7zdY+waLYb6P3Z0EA4vzjKx 0f1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709060593; x=1709665393; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fRRnLAvPnPJL+HqV6rL3Yv2zNLZuv51RwIxNYUJXEyo=; b=J0HAY4lP8zSJShIrmGiZgMaSq8J+TGSN58Npb24wUeAmnpRU4qC50+bFVA+tI8TXPO 1lQhXdFKigVHe/oo1SdRMYQhxKTXDkdFIMfCmXFhihoiHfUQliPeyUGMBirF/kOmGW8Z aTpTk1bgOf3YZTbIT+cQAWvNZDr4BFt+gjNNt2P/wFx9THyayKEhsIeuu4Z+VJCWAt+h 08xY+2FN1HspfpFmseNHBYLQ/ha+w7AgSyDThC+YcspVAaIwTG5ML5HNzSYrjaiTwDPs mKOSigdJ9o1kio1veD1isZMFcRK2Dxotd2y8QzPvECwxipej6Ouu4haWwiE1H/ETfJgm 6UGA== X-Forwarded-Encrypted: i=1; AJvYcCVPoxSInm6oe89FQ3rOpFYM7Kii3BsaAvlvD33uiF0Q7H6H46X3GJg8rS00SVRuyQxu4G4cvuISOHbEZQ9pjJH1bq5IHAWuSZN1GI5U X-Gm-Message-State: AOJu0YxDNCjZKHxho2/dXrG9KuVfZY4lj/KGYrmNdgC0ejlah6Ij77vU rH9sc6mA7EVQdd/UTmuwxH1DRPTAQhxPR1eDQ5OqDwo0uo1JI32aZ/Cc4/adO2RWyr2kDCHQLVt daHW7s4/8yNTBvP31ly5wIV8l5ZUfjsfbZkhn X-Received: by 2002:a17:902:e1cc:b0:1db:7057:24df with SMTP id t12-20020a170902e1cc00b001db705724dfmr323406pla.14.1709060592780; Tue, 27 Feb 2024 11:03:12 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240214063708.972376-1-irogers@google.com> <20240214063708.972376-5-irogers@google.com> In-Reply-To: From: Ian Rogers Date: Tue, 27 Feb 2024 11:02:57 -0800 Message-ID: Subject: Re: [PATCH v1 4/6] perf threads: Move threads to its own files To: Namhyung Kim Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Oliver Upton , Yang Jihong , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Feb 27, 2024 at 9:31=E2=80=AFAM Namhyung Kim = wrote: > > On Mon, Feb 26, 2024 at 11:24=E2=80=AFPM Ian Rogers = wrote: > > > > On Mon, Feb 26, 2024 at 11:07=E2=80=AFPM Namhyung Kim wrote: > > > > > > On Tue, Feb 13, 2024 at 10:37=E2=80=AFPM Ian Rogers wrote: > > > > > > > > Move threads out of machine and move thread_rb_node into the C > > > > file. This hides the implementation of threads from the rest of the > > > > code allowing for it to be refactored. > > > > > > > > Locking discipline is tightened up in this change. > > > > > > Doesn't look like a simple code move. Can we split the locking > > > change from the move to make the reviewer's life a bit easier? :) > > > > Not sure I follow. Take threads_nr as an example. > > > > The old code is in machine.c, so: > > -static size_t machine__threads_nr(const struct machine *machine) > > -{ > > - size_t nr =3D 0; > > - > > - for (int i =3D 0; i < THREADS__TABLE_SIZE; i++) > > - nr +=3D machine->threads[i].nr; > > - > > - return nr; > > -} > > > > The new code is in threads.c: > > +size_t threads__nr(struct threads *threads) > > +{ > > + size_t nr =3D 0; > > + > > + for (int i =3D 0; i < THREADS__TABLE_SIZE; i++) { > > + struct threads_table_entry *table =3D &threads->table[i= ]; > > + > > + down_read(&table->lock); > > + nr +=3D table->nr; > > + up_read(&table->lock); > > + } > > + return nr; > > +} > > > > So it is a copy paste from one file to the other. The only difference > > is that the old code failed to take a lock when reading "nr" so the > > locking is added. I wanted to make sure all the functions in threads.c > > were properly correct wrt locking, semaphore creation and destruction, > > etc. We could have a broken threads.c and fix it in the next change, > > but given that's a bug it could make bisection more difficult. > > Ultimately I thought the locking changes were small enough to not > > warrant being on their own compared to the advantages of having a sane > > threads abstraction. > > I can see some other differences like machine__findnew_thread() > which I think is due to the locking change. Maybe we can fix the > problem before moving the code and let the code move simple. I'll see what I can split out in v2. I don't think findnew will change and the nr change is trivial. In the previous code the lock is taken before calling __machine__findnew_thread, which doesn't make sense when we try to abstract inside of threads, where it should take/release the lock in the threads and not the machine code. Moving the lock to __machine__findnew_thread doesn't really make sense as the __ implies the lock is already held. Thanks, Ian > Thanks, > Namhyung