Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp572890lqh; Tue, 7 May 2024 07:48:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW1oPSilN6BZx5HxQmdBwWeNXESBYm6MuAN6hV8tLwuCYjP2bz5ZDskPc07/H8Om0OeX3hRxwYxmuiHP0Cp0ji7T4YBGyQNxP+gvXuGKw== X-Google-Smtp-Source: AGHT+IGQ9I1/S5l1z41wj92V1r88r+86A5tq6k1ybbmPhBTxszE1iCedvYeTH7puxHlhM7dtC8B2 X-Received: by 2002:a17:907:944e:b0:a59:c209:3e31 with SMTP id dl14-20020a170907944e00b00a59c2093e31mr5867987ejc.21.1715093307036; Tue, 07 May 2024 07:48:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715093307; cv=pass; d=google.com; s=arc-20160816; b=jdRPZPcnowWYMBd20OFNBAEorAcsFsKSa1JEtc5CPRrOqai5e8wJ6gtBWxD9TkaPe5 JKtWBax+KxvlcdLzbl8PAjvF62FBxTTENQneQe3qawMfBVKwoLXjN12+BxyayPAZbt0c oeAOnjQo/c4nEjV9dW6iqQE3Gv3EfAClLz66YMvzhYV8tbcV7CxztJZ6qW8i1M9KsKyh kdSMwhmcfJ7U5Hdzd1ucOGdNxwaUb1Owm+ga6wFlSZX1CrSViA78Uewu5ALQWnVeMFfS SuwHqFm4T0biaNlYvJIQs2Q3QmzyTXfpL+f4PIoR57xqoy7UWuljGAncoipC8tkGmt3r VwAA== 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=6E2tOH2LZeelmKHGCVRYEwTjym6Omr1xato4eYpOm4E=; fh=H/Eyqtbxot1aLJroVGYoGb2d7tTXgjKuiaP7dZS02jI=; b=FSplYNdvko1x022EdMPByGHw4ldu2xcqtF/JQ14jvvo4WKzB748Q6p6Rr50lh5nQ43 7yhPsyUyj2brspYPmJEOI/TYux8DdL4Qp9UvWwDec7TQ/GeetGxhqS2HEr5wfqj+Nxsm MryUiohHQSbjNr9AtgUFGn99tSoqZTfUMLk1Ds5Wx3KP0D7A6J2pmlvA1r/4/mpfctbg GRUKUwuftIGoFYzM0GNH4rOwigdvlJj+SNFI0kSUDVCQPKmqw84QUdCMkoY5XKh0lldt GsWLHhyGmJ4mJlRg+hKFtLcadmmrCze3wrKCircy1l6jG+o2Lgwe5t1FHlGkg3vn/TvM 0DGA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=PCHoPc57; arc=pass (i=1 dkim=pass dkdomain=bgdev-pl.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-171609-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171609-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id go36-20020a1709070da400b00a59bad094acsi3512001ejc.853.2024.05.07.07.48.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 07:48:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-171609-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=PCHoPc57; arc=pass (i=1 dkim=pass dkdomain=bgdev-pl.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-171609-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171609-linux.lists.archive=gmail.com@vger.kernel.org" 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 9ACDA1F24DEB for ; Tue, 7 May 2024 14:48:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A251015FD10; Tue, 7 May 2024 14:48:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="PCHoPc57" Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) (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 E5CD22F50 for ; Tue, 7 May 2024 14:48:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715093299; cv=none; b=D8KDTuEZvaLgOCceN1jUYETLLSYXjOKbWbLWBHWw29GMzUrptx6zfjKhRwaF6QYW+wCA9GIfooUKr4t8CaRW1Axp97Q41Kv9+EzOmpHhTcgaOlu2ZnRHbJS0GZXXg+Z0B5HA8wL1m+515J3qptQJ+XS7jPUHSSmV+ahe7wCfs7s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715093299; c=relaxed/simple; bh=O9U7eifATy8AucP2fwKsqv2Qi7a/NxF2S8DlLhQxBOk=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=EomIPQ9YDNVdMdwmYVjE1cavpHoFlqydeKrFrAqAlsEYkuYYsXCzXRu13Ai2foJRjhptSXMnC/dwsJ3Tmb/s2OIre5o2FtlEJaLoD8YWDRE5zqwuBm2HRmTTzXHUUhs5qBKwy9SppcD7IlNhgagINJfUKRegjHTBa66IV9jV6DA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=PCHoPc57; arc=none smtp.client-ip=209.85.208.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Received: by mail-lj1-f180.google.com with SMTP id 38308e7fff4ca-2e43c481b53so1945381fa.2 for ; Tue, 07 May 2024 07:48:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1715093296; x=1715698096; 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=6E2tOH2LZeelmKHGCVRYEwTjym6Omr1xato4eYpOm4E=; b=PCHoPc57NicYWeCbCLKQYtSzZ48TuQrqMCrl8LMUNj1+cWv5FFlocjDP5Ngpw3Xj6A /8O3ynUZRCUQnO7z8PJfGkD+AeDrPLCEzEk+AVONMHcEneXGaArld6X6WA3Ruc4aj1WE QfrZoxDS293sasejpLyGJFGL2JMNrQX12NRBu7NYcqFpg1z3v+qkf5VzNZksenEbbrbl mPBFHb0dDbkWG6ec0QgMx4EmflB1wo8dJhXIfllZD7DgxIXEY787uqhvgD0BCJ80uBTh 5svbzqg8tseNOdKKzNBkyFi//p++C6BnsSiQOKXVWfpljM8AO/a7vaBdlSwR0wW1MIyX ttVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715093296; x=1715698096; 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=6E2tOH2LZeelmKHGCVRYEwTjym6Omr1xato4eYpOm4E=; b=CJFhQ9Bww3DrmrcbKGApuXYVqsccMsADybCMMsJxyNRfBdaSLnrQPZfwdsE06SQno9 Brog8yCXLt96LQ43VlIdZRuaLXKc1EgJVm+1bifqchKBYMlv15Y71z0QtumdV8TRDxgH daWHhQ7OlFyxzxGMILt39S6Hne0RyhxbJHfYBC7hLDE9aMX1d4ZCjKhvm8eV9UPkBQFj WL+EUV5udr5D0K082FWUiN57FK/FlPPrRBVIanaD56DP34etY3FiKmbAU8FwGW3Ocz0q nUj3askcKIrK2g8FsmEpk3K9nFOc2S1Aqyk2VBU99we/0DDz1UMo9+fxyuwlzjd/yL5S iYhw== X-Forwarded-Encrypted: i=1; AJvYcCW0o0Fm9zZK+U1np3FvryEfQHwcqmZqVfMWsubGZp+5Yqk+gUb9Tte41xlcTrPYSFnDeBFzvJM1A3Y0L3Zeaw8h2nWcZflQj68sVZoV X-Gm-Message-State: AOJu0YzovEiwaLhVV6gK/l1vkW56WdM/MdOF9Zm0im774USy22hzPdF8 LbbA69ZmW3S4aXJ+IRhL+qylxFdvZwUU+R/rV1bjjyL5MUqfSXVLdkUclfbCf15zKXg2LikBFcb NZdEIiOx1vh9UI4c1lRNaf5I/rdTv8631fRL5sf/K2FKHGuqC X-Received: by 2002:a2e:b0d5:0:b0:2e1:d94a:773f with SMTP id g21-20020a2eb0d5000000b002e1d94a773fmr8924737ljl.11.1715093295962; Tue, 07 May 2024 07:48:15 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240507121346.16969-1-brgl@bgdev.pl> <597f5da2-71be-4144-a570-fdc4f06c4cc6@paulmck-laptop> In-Reply-To: <597f5da2-71be-4144-a570-fdc4f06c4cc6@paulmck-laptop> From: Bartosz Golaszewski Date: Tue, 7 May 2024 16:48:04 +0200 Message-ID: Subject: Re: [PATCH] gpiolib: fix the speed of descriptor label setting with SRCU To: paulmck@kernel.org Cc: Kent Gibson , Linus Walleij , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski , Neil Armstrong Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, May 7, 2024 at 4:24=E2=80=AFPM Paul E. McKenney wrote: > > On Tue, May 07, 2024 at 02:13:46PM +0200, Bartosz Golaszewski wrote: > > From: Bartosz Golaszewski > > > > Commit 1f2bcb8c8ccd ("gpio: protect the descriptor label with SRCU") > > caused a massive drop in performance of requesting GPIO lines due to th= e > > call to synchronize_srcu() on each label change. Rework the code to not > > wait until all read-only users are done with reading the label but > > instead atomically replace the label pointer and schedule its release > > after all read-only critical sections are done. > > > > To that end wrap the descriptor label in a struct that also contains th= e > > rcu_head struct required for deferring tasks using call_srcu() and stop > > using kstrdup_const() as we're required to allocate memory anyway. Just > > allocate enough for the label string and rcu_head in one go. > > > > Reported-by: Neil Armstrong > > Closes: https://lore.kernel.org/linux-gpio/CAMRc=3DMfig2oooDQYTqo23W3PX= SdzhVO4p=3DG4+P8y1ppBOrkrJQ@mail.gmail.com/ > > Fixes: 1f2bcb8c8ccd ("gpio: protect the descriptor label with SRCU") > > Suggested-by: Paul E. McKenney > > Signed-off-by: Bartosz Golaszewski > > Looks good to me! > > Acked-by: Paul E. McKenney > > One semi-related question... Why the per-descriptor srcu_struct? > > If the srcu_struct was shared among all of these, you could just do one > synchronize_srcu() and one cleanup_srcu_struct() instead of needing to > do one per gdev->desc[] entry. > > You might be able to go further and have one srcu_struct for all the > gpio devices. > > Or did you guys run tests and find some performance problem with sharing > srcu_struct structures? (I wouldn't expect one, but sometimes the > hardware has a better imagination than I do.) > I guess my goal was not to make synchronize_srcu() for descriptor X wait for read-only operations on descriptor Y. But with that gone, I suppose you're right, we can improve this patch further by switching to a single SRCU descriptor. I'll send a v2. Bart