Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp6011151rwl; Wed, 22 Mar 2023 05:31:07 -0700 (PDT) X-Google-Smtp-Source: AK7set8Skijoun6n0qBTPm3O/xbcAfcBAEYOaReO+FhWZPNlCb1G0J2/BZSMKpOvK9e3FSVsw5XM X-Received: by 2002:a05:6a20:b91c:b0:d9:237e:9d08 with SMTP id fe28-20020a056a20b91c00b000d9237e9d08mr4788099pzb.3.1679488267159; Wed, 22 Mar 2023 05:31:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679488267; cv=none; d=google.com; s=arc-20160816; b=Mat3v//zHJ1vd/WLZ86BZsjgu5qi7rdBnqPhPhb/m9rHrv9TQmmz4ykdCtxq5JhHV+ gNLloIYEKNHcBT5tscgVnVMkYS24sDY/zUb1bxzDsbi2dLbuE0T+DVbJaihmMlSLOZRX jcdYCeel7uhZriJu851nU36CjoUam3gFCNmldlu/KHzkPAUCT5R2NgknzdVe5RwZl/4V i2kOdPR50/t5r5IEzApssbJJGclsIGBBqkd0ibW7OKN92CbaBAHz5xzToUQ4kHuLT1CD Lin0f+dES2+ZJOzn0LqhKladrX/F6yKZbumARnERs8Px/v6gugoBjrK+AJG1lWnIC5qT PXIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=hPXFCTl8qif3OA4s3YNypS2WhS0XvH7qdHBOusQ/gQI=; b=UXgwlF5MSXQHsivM4t8nMqYE3q6fyBt1ZwXvhSv64MZUHvr2/zg8eOc70m4JJUE4s1 QqE2fFwIQgLZ9uk7El53XOmArBe5a0RUvhza6Cds+akochIAB3LEI54cTmr3QhqXHlUH bW20YxuDdsR9tUOJhvO3vhNBquv1uNTbZkLsc2aUq0BUqtGx0Aid3QTR6INK22RBaV4J dweDaYBQY8z0/U0RGCsV+Mmp/CumhNHnefMwug7/1GnDegw9ji+L9rQMqq52DBV1YkiB fOQwlg+n/D1FXD16qQk1S00RTH/JtGLfzWJQ1kRk6yfJ2PY6xJt+NkOilGjAxXkC8G96 whgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FWhXR4Ok; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v64-20020a626143000000b005a919e42b9esi15173854pfb.196.2023.03.22.05.30.53; Wed, 22 Mar 2023 05:31:07 -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=@redhat.com header.s=mimecast20190719 header.b=FWhXR4Ok; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230127AbjCVMWO (ORCPT + 99 others); Wed, 22 Mar 2023 08:22:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230078AbjCVMWN (ORCPT ); Wed, 22 Mar 2023 08:22:13 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B39E01BCB for ; Wed, 22 Mar 2023 05:20:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679487637; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=hPXFCTl8qif3OA4s3YNypS2WhS0XvH7qdHBOusQ/gQI=; b=FWhXR4Ok61LhRAT9doiyOaUa66Wdps/iPFe05KaU+Ii16OWGMsiGYQf8HSAiqod3qaeG18 pIbSyPRpQyMYhKpzaNG+7pIysgXmysY/Nqmch3ueOXz7TD3rQT+KIoVf3Qq7y3ntBisdtp r+p8FYqQXgwTjRAYuDPDduYHCYlF3LI= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-18-fo76Be4ROzSoTDI59gNyLQ-1; Wed, 22 Mar 2023 08:20:36 -0400 X-MC-Unique: fo76Be4ROzSoTDI59gNyLQ-1 Received: by mail-qt1-f200.google.com with SMTP id b11-20020ac87fcb000000b003e37d72d532so4077630qtk.18 for ; Wed, 22 Mar 2023 05:20:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679487636; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hPXFCTl8qif3OA4s3YNypS2WhS0XvH7qdHBOusQ/gQI=; b=uLEsM9FTnqnkQV0b4UiOVLGCHhVEUYmizZJC75D5YIkImti2kqxqgT+poaUlAbpiOW TBRwT2afKtfq/qINV5hu+mOfeg9MBDArR9gB8+Hx0z01/RjgPt7L++fZzw3Gc/pwqX7y 1MTr+l5RRnzqJR1StLQnH/uKi8xc4q6C37J3GenOfiIr8t6n4KeXAc+kcJU9acmvPx0N CpqCdSJPAl45vFncbVcEBD3Aj+mjavArFfQC/QVQ4jhLVewt79ZvIdK/18PGGRZFFluQ tP5h5GuYe/0bEm/y6aJrgGSQ2aCHiOvYNph7Y3lVFeDw1VrOMYPUpVsfMFt9QmNqkjnQ hHGw== X-Gm-Message-State: AO0yUKWt0CdJNx4a8oLqDwEaHujZ/ZTYxNj/8ycVjzw8CR7GGLXBY5n/ qA23K0zr1yNaLEg4t4DDmyrmPqVvTDWZh+vk4RxIf2pAMN9VA71JbYedKIy5cWmbJPkVWVlEcCx E750eFPHQic/BZAtxd+pTIqDa X-Received: by 2002:a05:6214:e6e:b0:5c5:95db:858a with SMTP id jz14-20020a0562140e6e00b005c595db858amr5249109qvb.31.1679487636190; Wed, 22 Mar 2023 05:20:36 -0700 (PDT) X-Received: by 2002:a05:6214:e6e:b0:5c5:95db:858a with SMTP id jz14-20020a0562140e6e00b005c595db858amr5249039qvb.31.1679487635822; Wed, 22 Mar 2023 05:20:35 -0700 (PDT) Received: from vschneid.remote.csb ([154.57.232.159]) by smtp.gmail.com with ESMTPSA id d185-20020a37b4c2000000b007425ef4cbc2sm11175799qkf.100.2023.03.22.05.20.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Mar 2023 05:20:35 -0700 (PDT) From: Valentin Schneider To: Peter Zijlstra Cc: linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-hexagon@vger.kernel.org, linux-ia64@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, openrisc@lists.librecores.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-xtensa@linux-xtensa.org, x86@kernel.org, "Paul E. McKenney" , Steven Rostedt , Thomas Gleixner , Sebastian Andrzej Siewior , Juri Lelli , Daniel Bristot de Oliveira , Marcelo Tosatti , Frederic Weisbecker , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Marc Zyngier , Mark Rutland , Russell King , Nicholas Piggin , Guo Ren , "David S. Miller" Subject: Re: [PATCH v5 7/7] sched, smp: Trace smp callback causing an IPI In-Reply-To: <20230322095329.GS2017917@hirez.programming.kicks-ass.net> References: <20230307143558.294354-1-vschneid@redhat.com> <20230307143558.294354-8-vschneid@redhat.com> <20230322095329.GS2017917@hirez.programming.kicks-ass.net> Date: Wed, 22 Mar 2023 12:20:28 +0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 22/03/23 10:53, Peter Zijlstra wrote: > On Tue, Mar 07, 2023 at 02:35:58PM +0000, Valentin Schneider wrote: > >> @@ -477,6 +490,25 @@ static __always_inline void csd_unlock(struct __call_single_data *csd) >> smp_store_release(&csd->node.u_flags, 0); >> } >> >> +static __always_inline void >> +raw_smp_call_single_queue(int cpu, struct llist_node *node, smp_call_func_t func) >> +{ >> + /* >> + * The list addition should be visible to the target CPU when it pops >> + * the head of the list to pull the entry off it in the IPI handler >> + * because of normal cache coherency rules implied by the underlying >> + * llist ops. >> + * >> + * If IPIs can go out of order to the cache coherency protocol >> + * in an architecture, sufficient synchronisation should be added >> + * to arch code to make it appear to obey cache coherency WRT >> + * locking and barrier primitives. Generic code isn't really >> + * equipped to do the right thing... >> + */ >> + if (llist_add(node, &per_cpu(call_single_queue, cpu))) >> + send_call_function_single_ipi(cpu, func); >> +} >> + >> static DEFINE_PER_CPU_SHARED_ALIGNED(call_single_data_t, csd_data); >> >> void __smp_call_single_queue(int cpu, struct llist_node *node) >> @@ -493,21 +525,25 @@ void __smp_call_single_queue(int cpu, struct llist_node *node) >> } >> } >> #endif >> /* >> + * We have to check the type of the CSD before queueing it, because >> + * once queued it can have its flags cleared by >> + * flush_smp_call_function_queue() >> + * even if we haven't sent the smp_call IPI yet (e.g. the stopper >> + * executes migration_cpu_stop() on the remote CPU). >> */ >> + if (trace_ipi_send_cpumask_enabled()) { >> + call_single_data_t *csd; >> + smp_call_func_t func; >> + >> + csd = container_of(node, call_single_data_t, node.llist); >> + func = CSD_TYPE(csd) == CSD_TYPE_TTWU ? >> + sched_ttwu_pending : csd->func; >> + >> + raw_smp_call_single_queue(cpu, node, func); >> + } else { >> + raw_smp_call_single_queue(cpu, node, NULL); >> + } >> } > > Hurmph... so we only really consume @func when we IPI. Would it not be > more useful to trace this thing for *every* csd enqeued? It's true that any CSD enqueued on that CPU's call_single_queue in the [first CSD llist_add()'ed, IPI IRQ hits] timeframe is a potential source of interference. However, can we be sure that first CSD isn't an indirect cause for the following ones? say the target CPU exits RCU EQS due to the IPI, there's a bit of time before it gets to flush_smp_call_function_queue() where some other CSD could be enqueued *because* of that change in state. I couldn't find a easy example of that, I might be biased as this is where I'd like to go wrt IPI'ing isolated CPUs in usermode. But regardless, when correlating an IPI IRQ with its source, we'd always have to look at the first CSD in that CSD stack.