Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp481395pxk; Wed, 23 Sep 2020 08:04:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6hesWwoOkxgV5eD8tNtqtwlat3QpbIvfQ/3vsO7DmIUr/ErR0k09v9X2gC/Ui26WJKDtY X-Received: by 2002:a17:907:9c3:: with SMTP id bx3mr105587ejc.164.1600873497244; Wed, 23 Sep 2020 08:04:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600873497; cv=none; d=google.com; s=arc-20160816; b=N6snJfepj3iM38TgiYkDxrLLIwoEjRtsSrwbmCpxjDhjBq7bLmSWrS7HbZFlL+LVOa h5CXQ+q6kmTqK2OX0wdQ9+yDS6P9zpVje6wDfyI0qhSY8WcEPKIOziruJPzZxpgvIF5h kNvM37ztDUSsTj7HQ3X1GKu9fbWuqUqDddppTieLJb9fpfP55BJvptDnZpamchxeXko2 O5uxvPHDGa1kcz0OVC1MxbL8+JvyG+rDhgABCZfxwvWib18P4c7wCn+nkA3orO81uzwl Jt6Ut1RCdURzx30k03cd2Z+huhWEDj7cB+gPJ6vpnswKnTo5TNXbBF5GROvQDIiz9+ZX Gh/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :mime-version:user-agent:date:message-id:subject:from:cc:to :dkim-signature; bh=ncTiycxbLLLABb828Z5CFC0O0VQndKnHSZDh9Pb2FUA=; b=NQnOaXcYGs3S957R5H2i3r6coypY07EtsQY9DbX7ET6mHSIsY6qXOt+00TI52ZmAcF HHXnQt6KRaHxWvVevQP1hQnFU3V57Y5z+f/vRnbU0paijeKr74jnNqO5Q5xc1JCLFqNf e0ZHDCNs3EP8S87t5z0O0t2d8Ad9HB4rvTlXeqCrDkY6Du/pF9asn9K2GH8nbaBJU4tU RqOj4DfYopTaMZ0obQx0tZrttisp2CCuCcyOs2s8KRTKMdK8FBJW8yLgV3tKNxyrTlyA xaFJk9RUGQnWmgwGfbD7eCPeQML6D9wDf0WpJjBpxHyAhxedWMhcc//lQnXBeAyIMA3J Mkhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=rTmFAlor; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id re10si161881ejb.57.2020.09.23.08.04.29; Wed, 23 Sep 2020 08:04:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=rTmFAlor; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726537AbgIWPAy (ORCPT + 99 others); Wed, 23 Sep 2020 11:00:54 -0400 Received: from smtp-fw-4101.amazon.com ([72.21.198.25]:15590 "EHLO smtp-fw-4101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726130AbgIWPAy (ORCPT ); Wed, 23 Sep 2020 11:00:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1600873253; x=1632409253; h=to:cc:from:subject:message-id:date:mime-version: content-transfer-encoding; bh=ncTiycxbLLLABb828Z5CFC0O0VQndKnHSZDh9Pb2FUA=; b=rTmFAlorAGGAk+ILKIy10Y1JeVgXeMpaEnaYjejtXbzJCtfUxxXkp2hR IeF+b4vChQD82MagQ0hvshtJ9I+nuXv/ltJUhXltE5V6SdBu0BZSYiSUi wosUIlLQ7vIjmm795DSWyY2r1TmCBiqj6lBD7o6REiPBpcTRrrPaZohlX Q=; X-IronPort-AV: E=Sophos;i="5.77,293,1596499200"; d="scan'208";a="55868833" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2b-859fe132.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 23 Sep 2020 15:00:49 +0000 Received: from EX13MTAUWC002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2b-859fe132.us-west-2.amazon.com (Postfix) with ESMTPS id 63C8F222BE2; Wed, 23 Sep 2020 15:00:45 +0000 (UTC) Received: from EX13D12UWC002.ant.amazon.com (10.43.162.253) by EX13MTAUWC002.ant.amazon.com (10.43.162.240) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 23 Sep 2020 15:00:45 +0000 Received: from [10.95.178.71] (10.43.161.71) by EX13D12UWC002.ant.amazon.com (10.43.162.253) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 23 Sep 2020 15:00:43 +0000 To: Peter Zijlstra , Ingo Molnar , Thomas Gleixner , Sebastian Andrzej Siewior , Peter Xu , Kaitao Cheng CC: From: George Prekas Subject: [PATCH] latency improvement in __smp_call_single_queue Message-ID: <281da382-4511-e1df-6917-154a5914dd43@amazon.com> Date: Wed, 23 Sep 2020 10:00:41 -0500 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Originating-IP: [10.43.161.71] X-ClientProxiedBy: EX13D48UWB004.ant.amazon.com (10.43.163.74) To EX13D12UWC002.ant.amazon.com (10.43.162.253) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If an interrupt arrives between llist_add and send_call_function_single_ipi in the following code snippet, then the remote CPU will not receive the IPI in a timely manner and subsequent SMP calls even from other CPUs for other functions will be delayed:     if (llist_add(node, &per_cpu(call_single_queue, cpu)))         send_call_function_single_ipi(cpu); Note: llist_add returns 1 if it was empty before the operation. CPU 0                           | CPU 1                     | CPU 2 __smp_call_single_q(2,f1)       | __smp_call_single_q(2,f2) |   llist_add returns 1           |                           |   interrupted                   |   llist_add returns 0     |       ...                       |   branch not taken        |       ...                       |                           |   resumed                       |                           |   send_call_function_single_ipi |                           |                                 |                           | f1                                 |                           | f2 The call from CPU 1 for function f2 will be delayed because CPU 0 was interrupted. Signed-off-by: George Prekas ---  kernel/smp.c | 4 ++++  1 file changed, 4 insertions(+) diff --git a/kernel/smp.c b/kernel/smp.c index aa17eedff5be..9dc679466cf0 100644 --- a/kernel/smp.c +++ b/kernel/smp.c @@ -135,6 +135,8 @@ static DEFINE_PER_CPU_SHARED_ALIGNED(call_single_data_t, csd_data);  void __smp_call_single_queue(int cpu, struct llist_node *node)  { +    unsigned long flags; +      /*       * The list addition should be visible before sending the IPI       * handler locks the list to pull the entry off it because of @@ -146,8 +148,10 @@ void __smp_call_single_queue(int cpu, struct llist_node *node)       * locking and barrier primitives. Generic code isn't really       * equipped to do the right thing...       */ +    local_irq_save(flags);      if (llist_add(node, &per_cpu(call_single_queue, cpu)))          send_call_function_single_ipi(cpu); +    local_irq_restore(flags);  }  /* -- 2.16.6