Received: by 2002:ab2:4c07:0:b0:1f7:886a:16b6 with SMTP id o7csp1490326lqk; Mon, 6 May 2024 09:20:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUHkg1L+tzrc/7IsHsqHJxfJ+rGmUAOqBhn6lUvhi4HxTQN6CNo4C9MsEZR4Kyt8HXcPLDQpNI42mM2fRFZZKCIuXBeP0nNEhg0kZUbxw== X-Google-Smtp-Source: AGHT+IGheHksu8FW2pdwMLFEoHEPdmCCU6NfQqXJab6yItXIh8QHW4jQdP7hSvBmEjJkh/EAFnMi X-Received: by 2002:a17:90a:6fc7:b0:2aa:b57c:b178 with SMTP id e65-20020a17090a6fc700b002aab57cb178mr10572497pjk.34.1715012455412; Mon, 06 May 2024 09:20:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715012455; cv=pass; d=google.com; s=arc-20160816; b=bAM71PMv4QNhMjAdZyIMaI/l5L4GeJIfi+ZTRGkjspU6y2pqzrHGxrZaLrW8f/KNfV F4yTKuFjl6x5pwDpQkO9kcauK85nVPRKQgATafNFUFs3G7hnpkvnqexr+uokk8G7JW0O HyPwduUHfTZZXFIgTG1PV8Z3jEDFbWv8wwUJcTddY+nCI6pDWLwx2vVuhRaUnRsdtjcW CF5bY3fa+A9U32UWHC0YwmxSyyHjcXNPziG3fOEIA0bPwE++dcLdcDxMqkJ49WwQWz+y 1zu6HRks/7QeAF9gUNZwZLorhUi2xVfsZ+/vesN84mq0IUvUdLapbdNit+lfygum+lYJ BO6Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=kMBRKF0m+ZIYkax/WD20be0LrYx6C1oQnvg851lGN1U=; fh=6svwkvo8YC2CfDJV0ck/e2Bxq1ZbG9Z1CzniVf4deOY=; b=EetpDNhvPV5JdmMEzzBdp5JIXQ8lCY7C40xgYvESiL4HIvOvB5iQEsPOpn8rZXrwjI v/jNjUB602fN1HKfVBu/kdZOeORDA+BFi9O4daY1U+vSKvkqcDVMAXcMlvnUzVMWwQuy uI9g/YSyR2w+eKYwOkuMflRg/J/MRh1otm1SbgO/bvV1r0Yu6qVIivhtoksjXYkTOKvW +9Wxgg5veXQRGoRforw8mBRAxkfvCag0hSdJmiOISQOO6ocEsr8k56BF/esDr3u5SMHh yKoV1QQKhtiBOCSImoMzgdy0szf6BT9Xpk6C0PFnVL6rGOwoZDrqXsMzgYNnnXWzliXz d4pw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=Zl5mrDT5; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-170148-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170148-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id oa12-20020a17090b1bcc00b0029ba20feef7si11552886pjb.188.2024.05.06.09.20.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 09:20:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170148-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=Zl5mrDT5; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-170148-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170148-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 08B0D286126 for ; Mon, 6 May 2024 16:19:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A21CD157476; Mon, 6 May 2024 16:18:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="Zl5mrDT5" Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D94315664B; Mon, 6 May 2024 16:18:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715012303; cv=none; b=XHoEx2wxkEeYoouZdyJaNmaVTS5Zgp4HIP1JtugRzmH9672YolsPBXENuMnwLZ6x5igP31zxfOVBP+pApV1alvMtrV+hg0EsX8oJKZaFwb5uL+6hbpyi8ZyL44sfuAjSLXjEyI3CBlhE/1r9VuI4UIJ7z9oFQXZP6/iQ8PfwIlU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715012303; c=relaxed/simple; bh=fxNefskKpD2OANrNxXrnrAAT0Q0jJDzhonaTjHySxxo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fM8UgBtEmGaC9ozx9CkRg+T0tAyiw5JV8tzZWKoDAb7wodxu0XchyFeE6Ju5FYAE7bgpbrM099dCkAsgxCfDWzO4FatjxM2v7vyunGjaShpKEy0NblnFIN1vm0tOyLDyqSz41gQ7R+F3yqZ+ERqAjop41ee9AfNSN8OIpR4ANr4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=Zl5mrDT5; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 446FEDnQ006374; Mon, 6 May 2024 16:18:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=kMBRKF0m+ZIYkax/WD20be0LrYx6C1oQnvg851lGN1U=; b=Zl5mrDT5E/gnrFcd57mYQEDskqCsM/DYWyxnlk24i+4JEDVhyia1Q97BdBvlS0xzHcto eJ/MnMWhpgyXjNs4RybzO79C5YblFikQfLIyJtWBYPoLXe0oiFiVXXDqbIdcJs9Frjvo nYSTaUffMQCneTNcN9luweU8m012XUePy2Pl0/ohLoBshkBJ9PwUF5N6h0uQnWe49590 ovVyNuUfGzhex/XQWrwkld81agaDOUyGoPtLHPuZknLVVvlanRsgSsi7m5cl2qa4JTDd iy7yxHg37hcQdLrGmt7AWjTGAPEvnU9YFO0M0iZH8NJPoCeS6R0DkC4Dj5MYGtQR6zC+ SA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xy11k89ny-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 06 May 2024 16:18:13 +0000 Received: from m0353725.ppops.net (m0353725.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 446GIDHe011646; Mon, 6 May 2024 16:18:13 GMT Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xy11k89nw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 06 May 2024 16:18:13 +0000 Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 446G9qJ8010635; Mon, 6 May 2024 16:18:12 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3xx0bp0vec-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 06 May 2024 16:18:12 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 446GI6Dj48103934 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 6 May 2024 16:18:08 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A3D0C20043; Mon, 6 May 2024 16:18:06 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 12A1D20040; Mon, 6 May 2024 16:18:00 +0000 (GMT) Received: from li-c6426e4c-27cf-11b2-a85c-95d65bc0de0e.ibm.com.com (unknown [9.43.105.31]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 6 May 2024 16:17:58 +0000 (GMT) From: Gautam Menghani To: mpe@ellerman.id.au, npiggin@gmail.com, christophe.leroy@csgroup.eu, naveen.n.rao@linux.ibm.com Cc: Gautam Menghani , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] arch/powerpc/kvm: Optimize the server number -> ICP lookup Date: Mon, 6 May 2024 21:47:30 +0530 Message-ID: <20240506161735.83358-3-gautam@linux.ibm.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240506161735.83358-1-gautam@linux.ibm.com> References: <20240506161735.83358-1-gautam@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: UU-kyuhKFyzoEfxvb1KalCQhcwB5PbDh X-Proofpoint-ORIG-GUID: Br6O1nZSQbn2vhMdQCbldY1bQydJLiY6 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-06_11,2024-05-06_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=1 lowpriorityscore=0 mlxlogscore=220 impostorscore=0 mlxscore=1 adultscore=0 clxscore=1015 priorityscore=1501 spamscore=1 malwarescore=0 bulkscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2405060114 Given a server number, kvmppc_xics_find_server() does a linear search over the vcpus of a VM. Optimize this logic by using an array to maintain the mapping between server number -> icp. Signed-off-by: Gautam Menghani --- arch/powerpc/kvm/book3s_xics.c | 4 ++-- arch/powerpc/kvm/book3s_xics.h | 10 ++-------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/arch/powerpc/kvm/book3s_xics.c b/arch/powerpc/kvm/book3s_xics.c index 12de526f04c4..1dc2f77571e7 100644 --- a/arch/powerpc/kvm/book3s_xics.c +++ b/arch/powerpc/kvm/book3s_xics.c @@ -47,8 +47,6 @@ * TODO * ==== * - * - Speed up server# -> ICP lookup (array ? hash table ?) - * * - Make ICS lockless as well, or at least a per-interrupt lock or hashed * locks array to improve scalability */ @@ -1062,6 +1060,7 @@ static struct kvmppc_ics *kvmppc_xics_create_ics(struct kvm *kvm, static int kvmppc_xics_create_icp(struct kvm_vcpu *vcpu, unsigned long server_num) { struct kvmppc_icp *icp; + struct kvm *kvm = vcpu->kvm; if (!vcpu->kvm->arch.xics) return -ENODEV; @@ -1078,6 +1077,7 @@ static int kvmppc_xics_create_icp(struct kvm_vcpu *vcpu, unsigned long server_nu icp->state.mfrr = MASKED; icp->state.pending_pri = MASKED; vcpu->arch.icp = icp; + kvm->arch.xics->icps[server_num] = icp; XICS_DBG("created server for vcpu %d\n", vcpu->vcpu_id); diff --git a/arch/powerpc/kvm/book3s_xics.h b/arch/powerpc/kvm/book3s_xics.h index 8fcb34ea47a4..feeb0897d555 100644 --- a/arch/powerpc/kvm/book3s_xics.h +++ b/arch/powerpc/kvm/book3s_xics.h @@ -111,19 +111,13 @@ struct kvmppc_xics { u32 err_noics; u32 err_noicp; struct kvmppc_ics *ics[KVMPPC_XICS_MAX_ICS_ID + 1]; + DECLARE_FLEX_ARRAY(struct kvmppc_icp *, icps); }; static inline struct kvmppc_icp *kvmppc_xics_find_server(struct kvm *kvm, u32 nr) { - struct kvm_vcpu *vcpu = NULL; - unsigned long i; - - kvm_for_each_vcpu(i, vcpu, kvm) { - if (vcpu->arch.icp && nr == vcpu->arch.icp->server_num) - return vcpu->arch.icp; - } - return NULL; + return kvm->arch.xics->icps[nr]; } static inline struct kvmppc_ics *kvmppc_xics_find_ics(struct kvmppc_xics *xics, -- 2.44.0