Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp3948599ybg; Fri, 25 Oct 2019 11:08:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqxYnog9h9kM/H9MLlOj0lgZ/X4WJRZ1d/Yxdi7++DVTCVDvTHtIsUdo7s9yzlXd8M8l/VMp X-Received: by 2002:a05:6402:328:: with SMTP id q8mr5331125edw.136.1572026938631; Fri, 25 Oct 2019 11:08:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572026938; cv=none; d=google.com; s=arc-20160816; b=eObnhW7JDiSJLvvJjXHovooGHP9wH2XcoZRMGl5fzfWq//IKdVbhxyU+joLuPlv039 ue7xT/zNieRuAQd0OmQRFUUohJmpwYfC4rhiUOOyTDCFmyVRkArGDA6ZnbgOb4ezqv+j AvZ3I6VTKZyqE2CFeDXRva4a/8GbL6mGRf7d5j/1+/nhHyzCuUERwpDa3BoDF0X1JnwL zqJnITKeoZerZMZc0df1m3tGCpb4Czl/+zpW+dzPn/JluflvE3dVdPg1rWVILc6xlsmi wwhGZSoUH2wEW+KAWG2WUmwBqCT9SczjrwkCDndpQ/tRpcnX2/BzqoiUvTafFsXS/KRp rYmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=3wFDaqZ0NbxQNGne9paddG3mzo8aRis+uvC8kKNNdSM=; b=ZtDOng024O2SQayLerN3rdQDZy4dPIgO4EJPZnJwo/jBfb/++GZYCMAUAMH+CntWDR 7s/zeP+w7SC1DHbUvfsQeNkZIt0PIoKUA6skK4Y8vPM4Bsu/LcROdsvo4bc7J8HqeVpZ 0hFjg4uRUlHwQgopktHWdSYpD4E5aOpK9lMUq+qTcl6Ha/XCr6yNsgdIXHnYvcdY9kKW eQoZ+W7uzoGnAo1JAgJKL666luuz9nTIGW0neoQxKJIgln16enVPpF0XmEwzTq2J0PiE gDYvQXvtQ5RDnEK/ohrOuChU6Eu8lhxctf/YwrlaF0JmBjmLGlGMvzsLXoFHT98m9ALQ 8L/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=d2nf1cpj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e7si1720546ejk.20.2019.10.25.11.08.34; Fri, 25 Oct 2019 11:08:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=d2nf1cpj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S2407447AbfJXPlV (ORCPT + 99 others); Thu, 24 Oct 2019 11:41:21 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:35241 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2405824AbfJXPlV (ORCPT ); Thu, 24 Oct 2019 11:41:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571931680; 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: content-transfer-encoding:content-transfer-encoding; bh=3wFDaqZ0NbxQNGne9paddG3mzo8aRis+uvC8kKNNdSM=; b=d2nf1cpjgMHDl3jGz3GYBAgIuwwO3b/xCtn1EfFM0RdNT0FJhAaceOV8aS1tvjHMxaTd8I QvMSnHRFi1BlbA/drCjhCejf0bAHg2ev3St3ANB0cFe23B8Y3d849PEKn7yllz4Y5KNUA/ 038XQpwsx/s8VVzVDU8INuVryb8jOnY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-336-ra28wWr0N-iUCwABpxgLJw-1; Thu, 24 Oct 2019 11:41:11 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 35FCA801E74; Thu, 24 Oct 2019 15:21:58 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.34.246.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 90C7C5D9CA; Thu, 24 Oct 2019 15:21:53 +0000 (UTC) From: Vitaly Kuznetsov To: linux-hyperv@vger.kernel.org Cc: linux-kernel@vger.kernel.org, x86@kernel.org, "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Sasha Levin , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Roman Kagan , Michael Kelley Subject: [PATCH] x86/hyper-v: micro-optimize send_ipi_one case Date: Thu, 24 Oct 2019 17:21:52 +0200 Message-Id: <20191024152152.25577-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: ra28wWr0N-iUCwABpxgLJw-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When sending an IPI to a single CPU there is no need to deal with cpumasks. With 2 CPU guest on WS2019 I'm seeing a minor (like 3%, 8043 -> 7761 CPU cycles) improvement with smp_call_function_single() loop benchmark. The optimization, however, is tiny and straitforward. Also, send_ipi_one() is important for PV spinlock kick. I was also wondering if it would make sense to switch to using regular APIC IPI send for CPU > 64 case but no, it is twice as expesive (12650 CPU cycles for __send_ipi_mask_ex() call, 26000 for orig_apic.send_IPI(cpu, vector)). Signed-off-by: Vitaly Kuznetsov --- arch/x86/hyperv/hv_apic.c | 22 +++++++++++++++++++--- arch/x86/include/asm/trace/hyperv.h | 15 +++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/arch/x86/hyperv/hv_apic.c b/arch/x86/hyperv/hv_apic.c index e01078e93dd3..847f9d0328fe 100644 --- a/arch/x86/hyperv/hv_apic.c +++ b/arch/x86/hyperv/hv_apic.c @@ -194,10 +194,26 @@ static bool __send_ipi_mask(const struct cpumask *mas= k, int vector) =20 static bool __send_ipi_one(int cpu, int vector) { -=09struct cpumask mask =3D CPU_MASK_NONE; +=09int ret; =20 -=09cpumask_set_cpu(cpu, &mask); -=09return __send_ipi_mask(&mask, vector); +=09trace_hyperv_send_ipi_one(cpu, vector); + +=09if (unlikely(!hv_hypercall_pg)) +=09=09return false; + +=09if (unlikely((vector < HV_IPI_LOW_VECTOR) || +=09=09 (vector > HV_IPI_HIGH_VECTOR))) +=09=09return false; + +=09if (cpu >=3D 64) +=09=09goto do_ex_hypercall; + +=09ret =3D hv_do_fast_hypercall16(HVCALL_SEND_IPI, vector, +=09=09=09=09 BIT_ULL(hv_cpu_number_to_vp_number(cpu))); +=09return ((ret =3D=3D 0) ? true : false); + +do_ex_hypercall: +=09return __send_ipi_mask_ex(cpumask_of(cpu), vector); } =20 static void hv_send_ipi(int cpu, int vector) diff --git a/arch/x86/include/asm/trace/hyperv.h b/arch/x86/include/asm/tra= ce/hyperv.h index ace464f09681..4d705cb4d63b 100644 --- a/arch/x86/include/asm/trace/hyperv.h +++ b/arch/x86/include/asm/trace/hyperv.h @@ -71,6 +71,21 @@ TRACE_EVENT(hyperv_send_ipi_mask, =09=09 __entry->ncpus, __entry->vector) =09); =20 +TRACE_EVENT(hyperv_send_ipi_one, +=09 TP_PROTO(int cpu, +=09=09 int vector), +=09 TP_ARGS(cpu, vector), +=09 TP_STRUCT__entry( +=09=09 __field(int, cpu) +=09=09 __field(int, vector) +=09=09 ), +=09 TP_fast_assign(__entry->cpu =3D cpu; +=09=09=09 __entry->vector =3D vector; +=09=09 ), +=09 TP_printk("cpu %d vector %x", +=09=09 __entry->cpu, __entry->vector) +=09); + #endif /* CONFIG_HYPERV */ =20 #undef TRACE_INCLUDE_PATH --=20 2.20.1