Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2407066pxp; Fri, 18 Mar 2022 09:52:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyWAWVj1L7j4qk+2pQMFk8mSv8AVdcs1GnviuIleb7OfVBbwnuqLPdTVAMEJ4b8/LoK349T X-Received: by 2002:a17:907:5009:b0:6db:385a:2b93 with SMTP id fw9-20020a170907500900b006db385a2b93mr9555069ejc.653.1647622368267; Fri, 18 Mar 2022 09:52:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647622368; cv=none; d=google.com; s=arc-20160816; b=gbYp53iiLGTiBumpkZErQ13GrjXoyjLjw1sCLc/9jFb6G9wIsAUDYxrI9mLGWSQV6X VW9N/0qEHuP/jZL1jqUovXXaSV51rccZpW+7QScmUjR+FPxSxYKdLVTeSyfuqFee50xc P6lInnQzHo8C3dZjZvz0loBg3aWOEqCSy3bzUQH+Jy15Jd0/bubwwy1mDe63vJ/1mWEA gVFhB2AaX7bef+M/7Yh7qY/ul+4LH3awFRZW7fGM+FAO71q4DCDUKDpD+fHkMl/TfynX 3ibq6fIKuVXbsAzzHV/0M+anQ1ARAwIhx3olUkjnRmAmEvHm86fnzOj5ILfs3u/1wHDu I/0w== 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=n32rgjP/yXbwdJvAGnm4un77KkghAXw5J0rcdgYFEwE=; b=agYp5SPoLeiIby3DaPF+fBg08UaTZmzk1YB4kEH077SnITw4X/h/GirrPrMHMSs1OV ekTM+puW0mSNO8HYRT+/eGTaPIYJ5JPP7Imw+6pwJOSSvCmYBYMABGlex04NxpyChU4x mYOhiKE4IVBj+t9+5N2zHbGWUrOU+wuALI1TClhqSL7MYl/rkundGadA3QlfgQEnEdna +6gT3DeOag/UZBfngATzPuXvkE6VsAqi4bU1X/EY0OA+n8DI0VvTL3KnamNYmgAA2zoi O8U2ELYth3l9ZGTeeKdxy/aZFMczNu9cd9QvO95MPOYPMJY9gEHUVfdmuKIaOG0w5V4b xCJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=QaXW0TKk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c14-20020a50e3ce000000b00418c2b5be0dsi4156875edm.239.2022.03.18.09.52.18; Fri, 18 Mar 2022 09:52:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=QaXW0TKk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238007AbiCRQpQ (ORCPT + 99 others); Fri, 18 Mar 2022 12:45:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232621AbiCRQpP (ORCPT ); Fri, 18 Mar 2022 12:45:15 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCFB325E32B; Fri, 18 Mar 2022 09:43:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=n32rgjP/yXbwdJvAGnm4un77KkghAXw5J0rcdgYFEwE=; b=QaXW0TKkaRn4ogxp5y8lTjILNH OQzo5+PUAwOnKCcNGrboJ6stcnq9DOUbuVXYAZL6e0LG+c9pxWnQwUyJgmPlxj9DjQNoafks27pXR SUrpOmQILEA9/371YJ17dWpkYPYSxvizY12WwQjB3SOu8PuggBa8mhwm5wxqrZkMg9ijgS3vczrdJ 3DgbIc2q5+5cEx0SxEpjI0TTJbWyAH2mfZDsJeousMDVXUYZ7uaJMmWrURD5I4H8HQNWPpFjYQSm+ n4alG9/UaaC4PhF/d2/cu5G2Bbkl+qmNv5TTMhBUEKQOZqIbRjo1PIjELldEtEhG4lp249fMzWFkc s+BWtUUw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nVFhK-00872d-8j; Fri, 18 Mar 2022 16:43:30 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id DAF4A30007E; Fri, 18 Mar 2022 17:43:26 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 71C2A200B82FA; Fri, 18 Mar 2022 17:43:26 +0100 (CET) Date: Fri, 18 Mar 2022 17:43:26 +0100 From: Peter Zijlstra To: Boqun Feng Cc: Namhyung Kim , Ingo Molnar , Will Deacon , Waiman Long , LKML , Thomas Gleixner , Steven Rostedt , Byungchul Park , "Paul E. McKenney" , Mathieu Desnoyers , Arnd Bergmann , Radoslaw Burny , linux-arch@vger.kernel.org, bpf@vger.kernel.org Subject: Re: [PATCH 2/2] locking: Apply contention tracepoints in the slow path Message-ID: References: <20220316224548.500123-1-namhyung@kernel.org> <20220316224548.500123-3-namhyung@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 18, 2022 at 08:55:32PM +0800, Boqun Feng wrote: > On Wed, Mar 16, 2022 at 03:45:48PM -0700, Namhyung Kim wrote: > [...] > > @@ -209,6 +210,7 @@ static inline int __sched __down_common(struct semaphore *sem, long state, > > long timeout) > > { > > struct semaphore_waiter waiter; > > + bool tracing = false; > > > > list_add_tail(&waiter.list, &sem->wait_list); > > waiter.task = current; > > @@ -220,18 +222,28 @@ static inline int __sched __down_common(struct semaphore *sem, long state, > > if (unlikely(timeout <= 0)) > > goto timed_out; > > __set_current_state(state); > > + if (!tracing) { > > + trace_contention_begin(sem, 0); > > This looks a littl ugly ;-/ Maybe we can rename __down_common() to > ___down_common() and implement __down_common() as: > > static inline int __sched __down_common(...) > { > int ret; > trace_contention_begin(sem, 0); > ret = ___down_common(...); > trace_contention_end(sem, ret); > return ret; > } > > Thoughts? Yeah, that works, except I think he wants a few extra __set_current_state()'s like so: diff --git a/kernel/locking/semaphore.c b/kernel/locking/semaphore.c index 9ee381e4d2a4..e2049a7e0ea4 100644 --- a/kernel/locking/semaphore.c +++ b/kernel/locking/semaphore.c @@ -205,8 +205,7 @@ struct semaphore_waiter { * constant, and thus optimised away by the compiler. Likewise the * 'timeout' parameter for the cases without timeouts. */ -static inline int __sched __down_common(struct semaphore *sem, long state, - long timeout) +static __always_inline int ___down_common(struct semaphore *sem, long state, long timeout) { struct semaphore_waiter waiter; @@ -227,15 +226,28 @@ static inline int __sched __down_common(struct semaphore *sem, long state, return 0; } - timed_out: +timed_out: list_del(&waiter.list); return -ETIME; - interrupted: +interrupted: list_del(&waiter.list); return -EINTR; } +static __always_inline int __down_common(struct semaphore *sem, long state, long timeout) +{ + int ret; + + __set_current_state(state); + trace_contention_begin(sem, 0); + ret = ___down_common(sem, state, timeout); + __set_current_state(TASK_RUNNING); + trace_contention_end(sem, ret); + + return ret; +} + static noinline void __sched __down(struct semaphore *sem) { __down_common(sem, TASK_UNINTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT);