Received: by 2002:ab2:3b09:0:b0:1ed:14ea:9113 with SMTP id b9csp237690lqc; Thu, 29 Feb 2024 16:19:38 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXmYEypo28T3XUomewjKzMZVY47mHMviHyRGmTiDwshjEYtpBuVbunsazlthjwbCvh+fpgF/KV52w6Pp1aldPCJ4VEDDF1yAQok7bUPCw== X-Google-Smtp-Source: AGHT+IF/Zhn4t/zkiGw4yZ7KNQG34XL7RbazDZh4KyAZTWGiLH4d4KYFVczUrmpf2sNCqIjLsRDi X-Received: by 2002:a05:6a00:cc5:b0:6e1:482b:8c8e with SMTP id b5-20020a056a000cc500b006e1482b8c8emr314284pfv.17.1709252378596; Thu, 29 Feb 2024 16:19:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709252378; cv=pass; d=google.com; s=arc-20160816; b=K69A6CfwQcddPpo4fkF4PIhkAcAqxcFB39YmTmrcPL+9lj+fDnE2c2NvGGjehkkRTA X9ZZiZWrtPZomfNqeUgKevt5d9cJZFH2/sxIc/D2up56ARz94EkrSzsGrxjSlHqhvAeF Ty1O/Kaj9G5vDLY0IKFDBvYQTxHoBMOTrndZy2F3R4+R2mggLbsNJklvoB1tNGrSCKJG iHvXu8xtJPwehr/Xxeke2NKjYFv3NdYHdKAGMGKk9XLb2M7vqEZryaa9bCvQNqdhZIij TzAXMrWyukiIOHxFECenF+pFVaNqvnAx67rCRrA7JwD7nTE4UdexA1kBBk+93b94BVjF xDng== 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=0UWpBAgUjQGEcDfT6+E949LPPMhHm1UHzIqySFkY11k=; fh=dSImqoi3ZkhajiCLc5RWAYH4CJe2GE3zi/OEZHdC7mc=; b=EZwCtH11caNSKrQBx5Q8XI+t+6btgRgoYLNYDhwHqfCZUVpsNNgzw+RFYgvVu5d0E5 sqOu8n2m23lPDHRbWzm/z7xUtAwtJrL3p6DL7a0mUB4yfzFoH9Il1pv8psrF0E5snbXV 4t3BvvdF1SUOOzFimSKq2rO8vBqnXVAZGbaJIELZvZ1Q1hWQTQ4Vc5MI37ifwJCSXJqR MVUkyTA3VzdhnQ1oikJD+y8qeXRQ65LJ6p8CYy7yvTDLHber/5zE6OebeeatZK3SjiQU cZjCyb/g70Oy4ZbGY2BI1xaqPUS9WRr1CFAgMh4F87c0xOOQPs6e8VVEuV7KG2hs8IiR SFZg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="NEAjVP/3"; 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-87730-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87730-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id a13-20020a63cd4d000000b005df58c84bfesi2320141pgj.506.2024.02.29.16.19.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 16:19:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-87730-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="NEAjVP/3"; 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-87730-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87730-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 487A1286B48 for ; Fri, 1 Mar 2024 00:19:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B26CD816; Fri, 1 Mar 2024 00:19:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NEAjVP/3" Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 71C0717E for ; Fri, 1 Mar 2024 00:19:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709252368; cv=none; b=Poat7WbTKJGR/JH1JHP2rqam+VP5JuP0ijld/59uhlJFEPFjv4b47K+BuvEfE/iGbywf+r/nQGdRswDDt31ZLtwY9tMaCr4BdsPC+qB/jgSEn2u4eyhX/Fmp9fkZxOqqNlTsF5dOmQgsFhDRdVSQqd8v2Mu8nFRWb92YdX/nAtA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709252368; c=relaxed/simple; bh=7oaRx7txOLY5lh/ghksCzjvbdA7i/vJfUT0jQTEBt2E=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=I5KDdr3PX7wwUV1ysDKpImXsVYGp7whdjnSfjUxZwWr9m4x//GmcIIVni5Au7zeS06N9yfKuSn2bk+2izcf9Q+01aSsh8z/Kv/fAG8t/1nkXfOHgax5pvv+hiuWINY7BRzZtqEeTjNCaiZ2quEvFJRIPYZ9MTGR3F8onfNqE3+0= 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=NEAjVP/3; arc=none smtp.client-ip=209.85.214.182 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-f182.google.com with SMTP id d9443c01a7336-1dbe7e51f91so24005ad.1 for ; Thu, 29 Feb 2024 16:19:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709252367; x=1709857167; 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=0UWpBAgUjQGEcDfT6+E949LPPMhHm1UHzIqySFkY11k=; b=NEAjVP/3lxBxNeGI51nhHxu7G41cEIy8va/gHYs61xSjqwHrWSxhthvcLYrWniZrqc ATRet53Ni8hZ/O8CZKXaM6yfYFFV+ungVLGxVXn4vRo43uynlS59P+bmQxcxCt86llvl kAmQq9OdEyMIS2+++6X7aWvljiWKuOj9bRI+3FPuLcsaN0TSKOrUs90OFU6m09OgqSe/ wipTBNL6vfrm2iAyYNSt34I4cMPOLxf1Fi7YAyPHXatC7Ibaomtv1daJun9odZSRIpas wmj9QXKQCW/ypOiHyKPaROgPbdYiP3uVsZmrhP/MiR2lEHGSS8y0MGfwJzn/4XnqI/7e 2njg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709252367; x=1709857167; 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=0UWpBAgUjQGEcDfT6+E949LPPMhHm1UHzIqySFkY11k=; b=WPqfP5BDJ72yOxlfI9ecGR21HrdLSe+O51/CI5Hs9H4Sh1v1M5fH5ao1iR2UbqFZXz XED49d9AhViKFlZhuuUUXERyCr1ddMxuR72HiHNvJFOvi8dbuhCLINKZjWUFWhAT3fnY ITSHe+vPqPAG6e8cdJycXhdKDtmQeRvJTO1jf5Vr+Y+6sGXBKxDWEEIJAK9y8LYWSGHF ETrgSG+KEan46rhAGirA7LVE1V0Y80O0dubtz/wPtyXLJbga4rS5amkbrmxskKXqMiEg frpCL4mZgmKyoKup27LXdnFGS3J6v1BiEQ0uxN9x/ONuG+WemE8SNF5NQwrFxSHgb6rj TR5g== X-Forwarded-Encrypted: i=1; AJvYcCVQBDwtI29Zu4gZYgX/ml0Cfn8yRrTjoCLzqj35LBv4U3JXjdNDU5SYB8ZCkfsbBQTK8UkM+SMkxzlCY9zFiOrwIaxgM+z2Ay/eWN8S X-Gm-Message-State: AOJu0YxeCLos2M5VRUOdrSL5OsayWaM4/taDtXJ1SgkcH/KSX9ND5zWq A60/RfSo87c8OZ+5X19tC/s9+zyzJwenlMzpalEtERZHq17MbAivFaFn8QorI9BwO0v0nSjDE9M 6MdoST2HsiPtOQ6JjQzgexOtmY6jgEMgBAAZl X-Received: by 2002:a17:902:db0d:b0:1dc:6cf4:5908 with SMTP id m13-20020a170902db0d00b001dc6cf45908mr80892plx.6.1709252366428; Thu, 29 Feb 2024 16:19:26 -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: Thu, 29 Feb 2024 16:19:11 -0800 Message-ID: Subject: Re: [PATCH v1 4/6] perf threads: Move threads to its own files To: David Laight Cc: Namhyung Kim , 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 Thu, Feb 29, 2024 at 1:59=E2=80=AFPM David Laight wrote: > > From: Ian Rogers > > Sent: 27 February 2024 07:24 > > > > 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. > > The lock is pretty much entirely pointless. > All it really does is slow the code down. > The most you could want is: > nr +=3D READ_ONCE(table->nr); > to avoid any hypothetical data tearing. Completely agreed, but as this is user space code I'm unclear on thread sanitizer support for READ_ONCE. The code is also only called in debug statements. The migration to a hashmap in the later patches means the complexity of taking the lock is more justified, although we're using libbpf's hashmap that has a size variable. Thanks, Ian > David > > - > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1= 1PT, UK > Registration No: 1397386 (Wales)