From patchwork Wed Feb 28 12:53:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 207846 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3323604dyb; Wed, 28 Feb 2024 04:53:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUHo1km9cIeCfdC+Dl6t/+PD2p49W8UFUxeDoEeZ+RzORzx2GMk9CAF7ep25vcSit9FjHhaK1qCsCYTMgH3C1gleVppQA== X-Google-Smtp-Source: AGHT+IGI8PxGtiJ765phdHX4J4mfgcF3l1101usHDGUamGBmzBGriuFK/h2jFSqiYRg7lig5saip X-Received: by 2002:a17:906:2353:b0:a44:a5a:30c5 with SMTP id m19-20020a170906235300b00a440a5a30c5mr904714eja.41.1709124827942; Wed, 28 Feb 2024 04:53:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709124827; cv=pass; d=google.com; s=arc-20160816; b=q2jcWpvh94X0nRd5Sty7xUUpb7IsYiHBoCi7AfTB8eM0ajx60+eTy1JxidRVypcg9+ qRYIJQo5EEJf4Kqk5m4GMw933zEemdJ5Rew6HEqIm84a9qhM5wlV/GvwN+DVaYP/325Z omodYGjzY0lDpsQbVEGPHbvEixIWowCDhBQIMtBI4weQ8ov7IvwUUWup420MPPojHK3j tqKDYU9XEbEmP670LhlofZkgiynGvUAkfIX2yoHM0jQ3BTNPPoH/L7b1GuPbgBkV5dJ5 In5P0CTyohbparqtY4QXzCDHLLzG+BzWkT+f8qzYb45RAyH20l436D9tk2WuHu0MpWl5 2FgA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=kiBS1QRCgATOeMSN+G6V+QMrDH6WO5XpkcNGtlJ/Wx0=; fh=Oo8pQtqVlwfV9Jj4/AeutPVMMqDqx14iDVj3ZBMUqZE=; b=lIUr/ZjR3miQN9uZqDvci+BfF5YoDn/TOFUr2Dti1NEpwktrgp5SUkiFVi10+xz5Lq jFb/eO+Mm2oAZvKlqgrNjy4jeSWUDzxRS+WTETtCYcoVaXHWdgB3YWVgJYPh9a4xQCyH TS7wWjQT7+X4Wbfc39la2r59esXL5nt1ZobUlT9Jb1A3lV/5jYbNZ2N6ZEN0QKr/6fr+ IcwulP/gjYNkCKWUyPGGU9+evky1+GQYuN93tJoqib6btXcN1eriMQV51l1uitxIYkhz RXSMFm+6roLAOCorNiJlagG4qT1M002FM8eBI5ZLTuBD5uDbvrnie1ktHdU+9C6uWsqN hddA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=hlDZIrOm; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-85038-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85038-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id l5-20020a17090615c500b00a3f50f4e640si1769587ejd.232.2024.02.28.04.53.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 04:53:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85038-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=hlDZIrOm; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-85038-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85038-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de 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 8DA641F26D6C for ; Wed, 28 Feb 2024 12:53:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F01E214AD0A; Wed, 28 Feb 2024 12:53:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="hlDZIrOm"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="T0gpe7nS" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BAE5812D766; Wed, 28 Feb 2024 12:53:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709124804; cv=none; b=N6AeneAuT6L3crqY99mzaGevlyoxfB4wXGdrw6gD/88CL+2TcRa+oV9z/xaSXoiZVgnl8KSKj4wOWdeXrQb+Y/yIXuKB3Tea3Sdjza/gBDod5sJygxXRQoAbvZaHn6bmq6YPHCwv4GIviNClXKZwWWOJAC/x6fptV2Y2Rhgir5M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709124804; c=relaxed/simple; bh=Zu1jEXwEn04gHO4PYNO1FTohlyOqRbL9PKC8J3KVgTE=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=sYWIVoznwA9G1gb9PyqEcsHjHSHFpA7Lf2CHFXq0MMPtzEPNldxEkyaIj69yStIrWtGJ0qNafI2t4W4g5BoZtvV3NNDQNPz/9sp7JE9mZoVqGZbFSXJJVD5mbpKw6X6qiDsD/ThR+iar06i0nE8YN88IpuLOZrQ/gOulT+EV4gE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=hlDZIrOm; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=T0gpe7nS; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Wed, 28 Feb 2024 12:53:20 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1709124801; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kiBS1QRCgATOeMSN+G6V+QMrDH6WO5XpkcNGtlJ/Wx0=; b=hlDZIrOmrS2vU2pts2pStfQ3ny3m1mIdPnOb0+cX6CxI3DdHF/MsRi9v9FCuRZC7vu4zRM 1i26k3dv7FR4NoFHCn/FbGHyubBJrumHUAm5YwHHBI1GCSOI+iwlEgU6CRFOYzw2G3z9OV MXe3M6UZeEd08vsmzTTosCb9ROUAVYtHdJbXhon8Vixr9YyGqkQmIZ2RBufXbZhn5tVIij /KVhLVFki9eCHU+aCN4LZRdxXrIcDpGN5TCs8KTwOkSLaA+4CLXmvqWySbWNPfPWr2YMH2 IBdSZSdyd/B0FZzb+emdsytlk+tBat9LvLtS3WrHnpzc3Z/THtdt6x0KZBt27Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1709124801; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kiBS1QRCgATOeMSN+G6V+QMrDH6WO5XpkcNGtlJ/Wx0=; b=T0gpe7nSbBTeck1WBl9/2ZVD25RAYjR3ORVteE2f/Uj8gw+op9ygmjh7suQgEuav6b1eWx xJCO7dd+QjFqARBA== From: "tip-bot2 for Namhyung Kim" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/core] locking/percpu-rwsem: Trigger contention tracepoints only if contended Cc: Namhyung Kim , Ingo Molnar , Waiman Long , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231108215322.2845536-1-namhyung@kernel.org> References: <20231108215322.2845536-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <170912480008.398.3227781797788701181.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782034385460809058 X-GMAIL-MSGID: 1792147275582774499 The following commit has been merged into the locking/core branch of tip: Commit-ID: f3e3620f1a97fcd02a5f3606fa63888dbcffd82c Gitweb: https://git.kernel.org/tip/f3e3620f1a97fcd02a5f3606fa63888dbcffd82c Author: Namhyung Kim AuthorDate: Wed, 08 Nov 2023 13:53:22 -08:00 Committer: Ingo Molnar CommitterDate: Wed, 28 Feb 2024 13:10:29 +01:00 locking/percpu-rwsem: Trigger contention tracepoints only if contended We mistakenly always fire lock contention tracepoints in the writer path, while it should be conditional on the trylock result. Signed-off-by: Namhyung Kim Signed-off-by: Ingo Molnar Reviewed-by: Waiman Long Link: https://lore.kernel.org/r/20231108215322.2845536-1-namhyung@kernel.org --- kernel/locking/percpu-rwsem.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/kernel/locking/percpu-rwsem.c b/kernel/locking/percpu-rwsem.c index 185bd1c..6083883 100644 --- a/kernel/locking/percpu-rwsem.c +++ b/kernel/locking/percpu-rwsem.c @@ -223,9 +223,10 @@ static bool readers_active_check(struct percpu_rw_semaphore *sem) void __sched percpu_down_write(struct percpu_rw_semaphore *sem) { + bool contended = false; + might_sleep(); rwsem_acquire(&sem->dep_map, 0, 0, _RET_IP_); - trace_contention_begin(sem, LCB_F_PERCPU | LCB_F_WRITE); /* Notify readers to take the slow path. */ rcu_sync_enter(&sem->rss); @@ -234,8 +235,11 @@ void __sched percpu_down_write(struct percpu_rw_semaphore *sem) * Try set sem->block; this provides writer-writer exclusion. * Having sem->block set makes new readers block. */ - if (!__percpu_down_write_trylock(sem)) + if (!__percpu_down_write_trylock(sem)) { + trace_contention_begin(sem, LCB_F_PERCPU | LCB_F_WRITE); percpu_rwsem_wait(sem, /* .reader = */ false); + contended = true; + } /* smp_mb() implied by __percpu_down_write_trylock() on success -- D matches A */ @@ -247,7 +251,8 @@ void __sched percpu_down_write(struct percpu_rw_semaphore *sem) /* Wait for all active readers to complete. */ rcuwait_wait_event(&sem->writer, readers_active_check(sem), TASK_UNINTERRUPTIBLE); - trace_contention_end(sem, 0); + if (contended) + trace_contention_end(sem, 0); } EXPORT_SYMBOL_GPL(percpu_down_write);