Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2193121pxp; Mon, 21 Mar 2022 13:31:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJiPe3fBvzL/Tpsv98b9yM2FHZ+Ap6UQgFLFzdcf2V9WeQpKRLuzSmNsiYpTgLC7MjKull X-Received: by 2002:a17:906:7947:b0:6da:892f:2503 with SMTP id l7-20020a170906794700b006da892f2503mr21911186ejo.710.1647894700308; Mon, 21 Mar 2022 13:31:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647894700; cv=none; d=google.com; s=arc-20160816; b=K9RLjBvUj4d2cCc1LXe4CbTdQtW2pVn3MxV97nVBzMF38UwUyUND0KuHTyeSr3Su6M w5/9uho35eI1cTe7Qvge6Q0rSAIHwrCAwAuX8I9RQupyxnqOaZO5yiAoTVu4cSSAH3Td pxdW2qblU+JYebjTg0EbnuNCvArGca49QDZh8GnXRGHVB2jX4AnJtU7iatmCUTxbiHFZ iaZdT+Sjfdz4Is3IPNxbr1kUHS+NWTWeBie41cj6vxN9JwJFBrJ76I500p+EDg9qIBI9 Nne8PfBcsu/JOZKUL5Af5s73LJ9Zg5Al5ymYQG70suVnIjGTSnwJGpgnm6yoFNpHnmFP U/pA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=EiM2o7+WvhkUxC02l3Vrb5uNgnPHPpHM0pgA8i6E2so=; b=qf0qRDMuIjNFcmEzmp3BkYSORFJCi537HOuc/ch87PP4DwBe8R/VadIfkO/rL5eUud 3sMcWvWg/ZgpMQCjT1bUzbYeIScVBagqnEw7WnKhnRQlgLzCb4gPMWRvmFBUaP+gxqgo APwA1plq4mjkueBf/tmTD/w7VEhiWThN30xTHCdDVFPPLZiYO8rZiQpzuXUtkEgRQWlN hUZx8eRm8ffkSuErF9Z1fe3lPmgEsq+DNpAgEYzVo3GLISTFrihi0he2Q/Bea83wmF0l FHDfn1tYysgE2VshqmZ2ASrBxaR9edJbunsaW02zj4FAuV5HiozRsgqUHnd2ExKOpUz5 LIiA== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z14-20020a17090674ce00b006dfa5eab470si7963888ejl.949.2022.03.21.13.31.14; Mon, 21 Mar 2022 13:31:40 -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; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241213AbiCRV5A (ORCPT + 99 others); Fri, 18 Mar 2022 17:57:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241208AbiCRV47 (ORCPT ); Fri, 18 Mar 2022 17:56:59 -0400 Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CECB230A882; Fri, 18 Mar 2022 14:55:39 -0700 (PDT) Received: by mail-lf1-f53.google.com with SMTP id t25so16063633lfg.7; Fri, 18 Mar 2022 14:55:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=EiM2o7+WvhkUxC02l3Vrb5uNgnPHPpHM0pgA8i6E2so=; b=Bbg+bxp2UySbPVchJ8a0AOTNv5+UhnoXcGHnckHFIWsa6+GLTb6ER8kFZfKU0t1NhV 4VhA6M7vSGzYNIO/EJHr5v74pZr+h5BNTyUyeoQo5BmLgeK+paLcX4a82pZG7fkMN61+ 55JhPrRPJ7NZsQ0Uu7wcI23CluUFg91l3PeOYLEQU+zE80uBXj95o0IC8d9HOzYvZEkP /i4QG701ubv4n8RWNdvHzWY4ytrKYpOejOPfra6Q+t1BFZkGlN4gsWY188/+M6Vfy3+D Mvmzoc7W+BXiB2StNxp8M0WuqMPhvBd0GNaahPYRT4nz299By8UNiOX1b41FKrjNupLY tvMw== X-Gm-Message-State: AOAM532I5uIcoB/kuImtDnqMSivo4BVsiQRzEaSGUY1H4CREluSEmdqm 7RRMhOw6ON4p/N6R/W6pEKj+8gwg43I+oxv6Z7g= X-Received: by 2002:a05:6512:2104:b0:448:68c5:e78f with SMTP id q4-20020a056512210400b0044868c5e78fmr7140679lfr.47.1647640538186; Fri, 18 Mar 2022 14:55:38 -0700 (PDT) MIME-Version: 1.0 References: <20220316224548.500123-1-namhyung@kernel.org> <20220316224548.500123-3-namhyung@kernel.org> In-Reply-To: From: Namhyung Kim Date: Fri, 18 Mar 2022 14:55:27 -0700 Message-ID: Subject: Re: [PATCH 2/2] locking: Apply contention tracepoints in the slow path To: Peter Zijlstra Cc: Boqun Feng , Ingo Molnar , Will Deacon , Waiman Long , LKML , Thomas Gleixner , Steven Rostedt , Byungchul Park , "Paul E. McKenney" , Mathieu Desnoyers , Arnd Bergmann , Radoslaw Burny , linux-arch , bpf Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no 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 Hello, On Fri, Mar 18, 2022 at 9:43 AM Peter Zijlstra wrote: > > 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: Not anymore, I decided not to because of noise in the task state. Also I'm considering two tracepoints for the return path to reduce the buffer size as Mathieu suggested. Normally it'd return with 0 so we can ignore it in the contention_end. For non-zero cases, we can add a new tracepoint to save the return value. Thanks, Namhyung > > 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);