From nobody Sat Nov 23 17:14:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1731621795; cv=none; d=zohomail.com; s=zohoarc; b=JXmmX/F0kh1rHM1eRUPw818z+DqcxUYndpTjMhec8jm89QLdbexIoJRE5q5hwVRuMDmjqEmifkFGscbN9TivB0/AhCmDAJ9B1GKMfBBurXgdXDkIGF78+lB/k873pLY0Ty6V25j7+g/HnpDfsxJWCXFVXcL0+Ll6IOnAP7vFguM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731621795; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=k2shGJzNrO4ttucD6ydWtQy0fNVwT+v2Fj5gAFSJcfE=; b=G0uCdwyZ0unfIad4IzQ/45vY2jtqs14sonDxtQdRRLknmixNmT3spuKWeI6il3t9ZdlTLRCAhivJIXQAy9fc8JchxhReSASv/o/BYlZ7NtoeMUPPYHMd8MZzwSDpObEkq03vOpGSHfPa3Y5yNpztdOSOJYindMNQIXwMvQvWQFM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1731621795425729.6609620539941; Thu, 14 Nov 2024 14:03:15 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tBhuY-0003Mj-15; Thu, 14 Nov 2024 17:01:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tBhuO-0003MQ-34 for qemu-devel@nongnu.org; Thu, 14 Nov 2024 17:01:48 -0500 Received: from mail-qk1-x733.google.com ([2607:f8b0:4864:20::733]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tBhuM-0007dk-7V for qemu-devel@nongnu.org; Thu, 14 Nov 2024 17:01:47 -0500 Received: by mail-qk1-x733.google.com with SMTP id af79cd13be357-7b18da94ba9so96403085a.0 for ; Thu, 14 Nov 2024 14:01:43 -0800 (PST) Received: from DY4X0N7X05.bytedance.net ([130.44.212.152]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b35ca308bdsm93742485a.83.2024.11.14.14.01.40 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 14 Nov 2024 14:01:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1731621702; x=1732226502; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=k2shGJzNrO4ttucD6ydWtQy0fNVwT+v2Fj5gAFSJcfE=; b=ZAnHXPMF2Y2A14EuML4JV2dTblno3/s3JCNbqfPIGYt/n51Zm5e0muw89mcCTPixmW 4v1lQ0R0d0gkGeJFnFpw20lszN0/S2o+abYGTjmaBrcXTdlOom7sElSEdsuoEoMqH9eI IHEN4TJiyhW+qK09GB7MhgkBfdosuO8kDjX/4pMU3xqIQ6inXf0h0zjM2Ol/0SFzHs/r S/tOvNdL9GZMD/7+2CRC1OY0qo02MNbGlamw2rL1ECVuNt3HLzNfKYEzdm2/v20C7aCD AITyowyovcHyzyJ3ZGtXHnqvnbz15YsOyEsuZdyuLAH7ZaXw8AuB8zg+B+T9gPZdU6Vt j8JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731621702; x=1732226502; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=k2shGJzNrO4ttucD6ydWtQy0fNVwT+v2Fj5gAFSJcfE=; b=NmGyfp0zIWssz2KmAJ9jKLSoqFpg4BBPTKjcM7+AFYk5SWUXfdfgC6tiXSyRMuT1/u qg1I5Vc7YGVTWbfce7ovsErXzccTBgxmX1NnkP80sCLIhkkXpFHy8pJ0w3j5AXGdPm1J JziB6T5CBiB1ic1Ebx8cZrrOPT/55IhuoBOA8NYJXdi/PLV6aXmgjXKH+6VJPJBCCh3q aK86MpXB/WYt7ZWv1wqF+UwAASN+zU0v8FYx+uKbD5v9v7WoIkE9sVs2TiW4B0ENdeqL H9AbsAtko2Za+60Y5zxOHCvIwUhgJNxLUMfiudNxFtftplJk4ynNO+WSWmTUrae996zF o6fA== X-Forwarded-Encrypted: i=1; AJvYcCWfUTk9/Wxkb3OQ0tebyfSy4cQUcj4ZMRJCA9IAi1XoU6Fu7h5BuCl2qJz4hNghPHDeboINpDx2e5dk@nongnu.org X-Gm-Message-State: AOJu0Yy1pdsYMdquuocC7qovQOm5MYZoygAOz97kYAXkgCwGB07/f+RA Fd0eD/CGqzG8QI1mgGJ9Rxnwk/7xJumM3dvgxNqKWWEKj7THmZPWx7ExrHw19RY= X-Google-Smtp-Source: AGHT+IE5ZfxJ9JnXL9+p4qk/aeSEj3SLjuZjF0gGDi76MxHyQTRWthj3NfrVueuGoa/8NAgrA2uFng== X-Received: by 2002:a05:620a:c44:b0:7a2:e2e:31c6 with SMTP id af79cd13be357-7b362005b43mr109464485a.21.1731621702187; Thu, 14 Nov 2024 14:01:42 -0800 (PST) From: Yichen Wang To: Peter Xu , Fabiano Rosas , "Dr. David Alan Gilbert" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eric Blake , Markus Armbruster , "Michael S. Tsirkin" , Cornelia Huck , qemu-devel@nongnu.org Cc: "Hao Xiang" , "Liu, Yuan1" , "Shivam Kumar" , "Ho-Ren (Jack) Chuang" , "Yichen Wang" Subject: [PATCH v7 01/12] meson: Introduce new instruction set enqcmd to the build system. Date: Thu, 14 Nov 2024 14:01:21 -0800 Message-Id: <20241114220132.27399-2-yichen.wang@bytedance.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241114220132.27399-1-yichen.wang@bytedance.com> References: <20241114220132.27399-1-yichen.wang@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::733; envelope-from=yichen.wang@bytedance.com; helo=mail-qk1-x733.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1731621795975116600 Content-Type: text/plain; charset="utf-8" From: Hao Xiang Enable instruction set enqcmd in build. Signed-off-by: Hao Xiang Signed-off-by: Yichen Wang Reviewed-by: Fabiano Rosas --- meson.build | 14 ++++++++++++++ meson_options.txt | 2 ++ scripts/meson-buildoptions.sh | 3 +++ 3 files changed, 19 insertions(+) diff --git a/meson.build b/meson.build index e0b880e4e1..fbcb75d161 100644 --- a/meson.build +++ b/meson.build @@ -3062,6 +3062,20 @@ config_host_data.set('CONFIG_AVX512BW_OPT', get_opti= on('avx512bw') \ int main(int argc, char *argv[]) { return bar(argv[0]); } '''), error_message: 'AVX512BW not available').allowed()) =20 +config_host_data.set('CONFIG_DSA_OPT', get_option('enqcmd') \ + .require(have_cpuid_h, error_message: 'cpuid.h not available, cannot ena= ble ENQCMD') \ + .require(cc.links(''' + #include + #include + #include + static int __attribute__((target("enqcmd"))) bar(void *a) { + uint64_t dst[8] =3D { 0 }; + uint64_t src[8] =3D { 0 }; + return _enqcmd(dst, src); + } + int main(int argc, char *argv[]) { return bar(argv[argc - 1]); } + '''), error_message: 'ENQCMD not available').allowed()) + # For both AArch64 and AArch32, detect if builtins are available. config_host_data.set('CONFIG_ARM_AES_BUILTIN', cc.compiles(''' #include diff --git a/meson_options.txt b/meson_options.txt index 5eeaf3eee5..4386e8b1fc 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -125,6 +125,8 @@ option('avx2', type: 'feature', value: 'auto', description: 'AVX2 optimizations') option('avx512bw', type: 'feature', value: 'auto', description: 'AVX512BW optimizations') +option('enqcmd', type: 'feature', value: 'disabled', + description: 'ENQCMD optimizations') option('keyring', type: 'feature', value: 'auto', description: 'Linux keyring support') option('libkeyutils', type: 'feature', value: 'auto', diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh index a8066aab03..ff6c66db1e 100644 --- a/scripts/meson-buildoptions.sh +++ b/scripts/meson-buildoptions.sh @@ -99,6 +99,7 @@ meson_options_help() { printf "%s\n" ' auth-pam PAM access control' printf "%s\n" ' avx2 AVX2 optimizations' printf "%s\n" ' avx512bw AVX512BW optimizations' + printf "%s\n" ' enqcmd ENQCMD optimizations' printf "%s\n" ' blkio libblkio block device driver' printf "%s\n" ' bochs bochs image format support' printf "%s\n" ' bpf eBPF support' @@ -246,6 +247,8 @@ _meson_option_parse() { --disable-avx2) printf "%s" -Davx2=3Ddisabled ;; --enable-avx512bw) printf "%s" -Davx512bw=3Denabled ;; --disable-avx512bw) printf "%s" -Davx512bw=3Ddisabled ;; + --enable-enqcmd) printf "%s" -Denqcmd=3Denabled ;; + --disable-enqcmd) printf "%s" -Denqcmd=3Ddisabled ;; --enable-gcov) printf "%s" -Db_coverage=3Dtrue ;; --disable-gcov) printf "%s" -Db_coverage=3Dfalse ;; --enable-lto) printf "%s" -Db_lto=3Dtrue ;; --=20 Yichen Wang From nobody Sat Nov 23 17:14:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1731621880; cv=none; d=zohomail.com; s=zohoarc; b=X5RmTWFtb/z5MqLwglPJkRka5a7/0auEMl1ryKzenYXCh6UYsmkR2SHGcZYYWsEYaO69EE9NJN8yfkV6k1O1/Uy+vtE6+UKzkUcgV5AifnaNsv98JccCuK5F5t6SNok88FPLTZGzv8qwqiC9fqnTHbbuxz97PL82ldePzk05Kwk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731621880; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=xY5QAGLhchl42gNHNAI66DnGmTQK1VTLeOyVk0oAer8=; b=bOip5pVodnsVvC+dsE74Rg2SHXWMPScNjPhMxAYLUGSuipeMhQ9L4mYDMkmXMo5OK9LkcYARM5EvZjWU4gEgp9FRLB3pfE1ROrJSZk4dloJiYVGt6KvTb0EUNqoB9kJ3u+S3o94UPcGOPmYYT65gm7T8VVraDveBbUUCucCDWZI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1731621880430769.8517211226691; Thu, 14 Nov 2024 14:04:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tBhuZ-0003OM-SS; Thu, 14 Nov 2024 17:01:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tBhuP-0003Ma-Cn for qemu-devel@nongnu.org; Thu, 14 Nov 2024 17:01:49 -0500 Received: from mail-qk1-x733.google.com ([2607:f8b0:4864:20::733]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tBhuN-0007do-NZ for qemu-devel@nongnu.org; Thu, 14 Nov 2024 17:01:48 -0500 Received: by mail-qk1-x733.google.com with SMTP id af79cd13be357-7b35b1ca0c2so130907785a.0 for ; Thu, 14 Nov 2024 14:01:45 -0800 (PST) Received: from DY4X0N7X05.bytedance.net ([130.44.212.152]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b35ca308bdsm93742485a.83.2024.11.14.14.01.42 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 14 Nov 2024 14:01:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1731621705; x=1732226505; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xY5QAGLhchl42gNHNAI66DnGmTQK1VTLeOyVk0oAer8=; b=DBcJh8pNZYpyFWJTsq0mv1bVwhtPot0Q9O3Fz6rao6TaoPWosk17uzDpnWMFydL7mX hDflK6NnLtGc13FVXZcUrr2XLy7fxypudX53/pGDpQsfcJ+MdaKCXf2yE48XzOwCzDza yjIuOHsQYamrkuuPt+trQ3noMvvepRVSAu91uzgod5XAsniTFzH9kJVb2CYrYXcdhMOp 7l2ezcNHFxrQ0f8anhIYeblLRmDX7bQqvOQJ4vTJhqkI9DYRAliSlcYiqAw58PVUfJAf 2kgo83hxjJXt2JZIOuTQjcGc+oQpOuRPktFLT1KuUrThfVVl7ekPsy3DeG0KNZacRJZw aSMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731621705; x=1732226505; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xY5QAGLhchl42gNHNAI66DnGmTQK1VTLeOyVk0oAer8=; b=ASLS5/Ta6sOlw1eLy45GZos3kEUQnttnsp0XZPVHwPHv+xw8KOC5c2LPg1oUVJwtFi mIBuX8cvUxikz/TIes0+dMU3Fq9bfPOo24EyGXNgRcyA4xZlJwsETL0nSQ3XbsCGr1Sg 174+FQzgyw/HU/URoqrLWaoqRLvW4gARoKbsm3XdPlBMb1rGuKagEG9pKbPQLK0BxXE6 pBl+cj0DroINfsk5JUd+ox/u2VWPlQZ81hid4jnhLmnfTrwMJYmEv6d/dUjBppSMRar+ H7FDqyGfB2hOgf6U+2HAl+KR+zDCbPP5+eMMoqtwBj+69EBaygq4RQ9TY9TGQKeHgB1t UTLw== X-Forwarded-Encrypted: i=1; AJvYcCXn8DxQI2Z4/RBRoQKUjARISQgbGyqMkwmawRd7MOlmSdxyAAN4vJWWOGPODrDK/fjeeXrHnUJrAD79@nongnu.org X-Gm-Message-State: AOJu0YxaDjB7ERZecWDlbbiOFmTrSd/2OSH9DDn6Pe6S15wmGv6RKCyF th3Oz10V/bxx8Ahm5y3jM6SkNpHB1tIStAWOvI5ekLPZX4SX4rmfuJc2h1BB0as= X-Google-Smtp-Source: AGHT+IGUtxuqNM7Zulv0qK6XluzsFRH6oycNUZNFecDCEYBhfV3CXTXz1EGoPpFFKtoboMDboXVlWQ== X-Received: by 2002:a05:620a:3f97:b0:7b1:4778:1564 with SMTP id af79cd13be357-7b361fa8ed5mr123817985a.3.1731621704758; Thu, 14 Nov 2024 14:01:44 -0800 (PST) From: Yichen Wang To: Peter Xu , Fabiano Rosas , "Dr. David Alan Gilbert" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eric Blake , Markus Armbruster , "Michael S. Tsirkin" , Cornelia Huck , qemu-devel@nongnu.org Cc: "Hao Xiang" , "Liu, Yuan1" , "Shivam Kumar" , "Ho-Ren (Jack) Chuang" , "Yichen Wang" Subject: [PATCH v7 02/12] util/dsa: Add idxd into linux header copy list. Date: Thu, 14 Nov 2024 14:01:22 -0800 Message-Id: <20241114220132.27399-3-yichen.wang@bytedance.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241114220132.27399-1-yichen.wang@bytedance.com> References: <20241114220132.27399-1-yichen.wang@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::733; envelope-from=yichen.wang@bytedance.com; helo=mail-qk1-x733.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1731621882344116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Yichen Wang Reviewed-by: Fabiano Rosas --- scripts/update-linux-headers.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/update-linux-headers.sh b/scripts/update-linux-headers= .sh index 99a8d9fa4c..9128c7499b 100755 --- a/scripts/update-linux-headers.sh +++ b/scripts/update-linux-headers.sh @@ -200,7 +200,7 @@ rm -rf "$output/linux-headers/linux" mkdir -p "$output/linux-headers/linux" for header in const.h stddef.h kvm.h vfio.h vfio_ccw.h vfio_zdev.h vhost.h= \ psci.h psp-sev.h userfaultfd.h memfd.h mman.h nvme_ioctl.h \ - vduse.h iommufd.h bits.h; do + vduse.h iommufd.h bits.h idxd.h; do cp "$hdrdir/include/linux/$header" "$output/linux-headers/linux" done =20 --=20 Yichen Wang From nobody Sat Nov 23 17:14:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1731621825; cv=none; d=zohomail.com; s=zohoarc; b=cR3gG/ls14ssJGTTBcFtl3SyfS/3H+ZMO7jv9GP1lwlyVhWcNTbU8bP+Ru2HjQrAZmaPXjWAoXtkOkI8BxIYolsePQYdb3qy6behDCU8l1CD3r2oimi7RxzdXJ2Oq1Dp+RRgkb5XKJFtSifxv13T3pWXdSdcLE/OZ6ywteo19Rk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731621825; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Zycd3hKEsTNJl0uSME9pJLVf1urG5elY3XBlARnUxHY=; b=YLA17rYJXGBSTmSP/Uu+eQ0AODyJEN83nZ4lC+0f8WhOMBWUastJCSEG4IKjP1oLwqk6lwQVjNr7HiKpPS845JP4EJT/RKgGnx6GPiYogzKdZOMcl0t9XIyDwrhtJ5YK2/KbNXNiXjeY44WLH1m9g/SF3qUZMgR5uC3VtIzjM1w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1731621825660993.1931305650035; Thu, 14 Nov 2024 14:03:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tBhub-0003Om-1f; Thu, 14 Nov 2024 17:02:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tBhuQ-0003Mn-Fx for qemu-devel@nongnu.org; Thu, 14 Nov 2024 17:01:54 -0500 Received: from mail-qk1-x733.google.com ([2607:f8b0:4864:20::733]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tBhuO-0007e2-H4 for qemu-devel@nongnu.org; Thu, 14 Nov 2024 17:01:50 -0500 Received: by mail-qk1-x733.google.com with SMTP id af79cd13be357-7b14554468fso69367785a.1 for ; Thu, 14 Nov 2024 14:01:48 -0800 (PST) Received: from DY4X0N7X05.bytedance.net ([130.44.212.152]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b35ca308bdsm93742485a.83.2024.11.14.14.01.45 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 14 Nov 2024 14:01:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1731621707; x=1732226507; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Zycd3hKEsTNJl0uSME9pJLVf1urG5elY3XBlARnUxHY=; b=KL7/MhGMoEuuXiW450fvsHxoT7+f8yq9pIZGiuXIaq46MFA/u7o4leWKuxBSEPQDFx G/gYfrPFleRmTjejEeONsMP38Rq1fE7VsXMFHgEmcnFLi/MjeZHymNPFwmHHqTLZPPDd fo0EkXigao5+h5t0i0OHamOOOF/Imj1TA8stOzoyz+gtnJyVjPnQDhrXtKwiIO4BRX+i w5/92icrC/v1NQ0pMEl0MIq0rXPFOH5RFd+MM4HsMp+oRV82+TMQEf7O6A8MJr0LjYl9 IhzbpGD+YLE3K1mq3mC908TwnRMhZNd7m13HsXoMfESMC6SBOGnCRjv/nS+KakApXtdP yGvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731621707; x=1732226507; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Zycd3hKEsTNJl0uSME9pJLVf1urG5elY3XBlARnUxHY=; b=mEmpCq1PirGI3eJuQA4S+6St0ySJqgvk9kOdaL4SwzP4U1lUw0cY+HOl7CFlcwphqm sGWd28At4gb/kY1GIEG2dFg5jLK2YZC8mo5MjYNzW7Rr0Q6mQKejnnoS1Q7PODkbBDvX XdNU2Bv0Nj1EvVKoaLUdPBAZaG+E8B3Jb8Cm6yHwWoL9RNyWhU1tyMKpCXsVpotsXwxM jNNld3+E/b+sWpesmGgXNniYjtHjp8gzVbHd2ldxVndf4wYlwoshnEWWeZg/zv8vCgmg HBG2/Zvu/4blbBFJr6IaCKUnagLoUNGk9Rftz6RBk2kDxCGYMNXkTbAaIORDvnVM94Lt qPNw== X-Forwarded-Encrypted: i=1; AJvYcCUws6kP5xTuBPY9wKQSL7vW29IqOw86KNM7Z9OTQ/h9n9BFNPuCjdi7zxBXNM4QsJ3rXD5PNh3Qmqg6@nongnu.org X-Gm-Message-State: AOJu0Yx+zDf95Z/gsLvI0se9ximWRCr6UixKNluQiue00DC2lOuwmP0Y pXDudf2C/wwagnKPnvNFpP7t8DjkNBSpQTIuDWnZhh/e311vH18N8jA18WvEO1c= X-Google-Smtp-Source: AGHT+IEkXqVAN9tFShn/9XDLrj3tncsyMxUVy+GTC0oaUE5g4pEwOrR+XYXTc9fq+Nm1Dj43s0prDg== X-Received: by 2002:a05:620a:4487:b0:7a9:b883:68c2 with SMTP id af79cd13be357-7b36234330fmr65347585a.48.1731621707414; Thu, 14 Nov 2024 14:01:47 -0800 (PST) From: Yichen Wang To: Peter Xu , Fabiano Rosas , "Dr. David Alan Gilbert" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eric Blake , Markus Armbruster , "Michael S. Tsirkin" , Cornelia Huck , qemu-devel@nongnu.org Cc: "Hao Xiang" , "Liu, Yuan1" , "Shivam Kumar" , "Ho-Ren (Jack) Chuang" , "Yichen Wang" , Bryan Zhang Subject: [PATCH v7 03/12] util/dsa: Implement DSA device start and stop logic. Date: Thu, 14 Nov 2024 14:01:23 -0800 Message-Id: <20241114220132.27399-4-yichen.wang@bytedance.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241114220132.27399-1-yichen.wang@bytedance.com> References: <20241114220132.27399-1-yichen.wang@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::733; envelope-from=yichen.wang@bytedance.com; helo=mail-qk1-x733.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1731621826054116600 Content-Type: text/plain; charset="utf-8" From: Hao Xiang * DSA device open and close. * DSA group contains multiple DSA devices. * DSA group configure/start/stop/clean. Signed-off-by: Hao Xiang Signed-off-by: Bryan Zhang Signed-off-by: Yichen Wang --- include/qemu/dsa.h | 103 +++++++++++++++++ util/dsa.c | 280 +++++++++++++++++++++++++++++++++++++++++++++ util/meson.build | 3 + 3 files changed, 386 insertions(+) create mode 100644 include/qemu/dsa.h create mode 100644 util/dsa.c diff --git a/include/qemu/dsa.h b/include/qemu/dsa.h new file mode 100644 index 0000000000..71686af28f --- /dev/null +++ b/include/qemu/dsa.h @@ -0,0 +1,103 @@ +/* + * Interface for using Intel Data Streaming Accelerator to offload certain + * background operations. + * + * Copyright (C) Bytedance Ltd. + * + * Authors: + * Hao Xiang + * Yichen Wang + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#ifndef QEMU_DSA_H +#define QEMU_DSA_H + +#include "qapi/error.h" +#include "qemu/thread.h" +#include "qemu/queue.h" + +#ifdef CONFIG_DSA_OPT + +#pragma GCC push_options +#pragma GCC target("enqcmd") + +#include +#include "x86intrin.h" + +typedef struct { + void *work_queue; +} QemuDsaDevice; + +typedef QSIMPLEQ_HEAD(QemuDsaTaskQueue, QemuDsaBatchTask) QemuDsaTaskQueue; + +typedef struct { + QemuDsaDevice *dsa_devices; + int num_dsa_devices; + /* The index of the next DSA device to be used. */ + uint32_t device_allocator_index; + bool running; + QemuMutex task_queue_lock; + QemuCond task_queue_cond; + QemuDsaTaskQueue task_queue; +} QemuDsaDeviceGroup; + +/** + * @brief Initializes DSA devices. + * + * @param dsa_parameter A list of DSA device path from migration parameter. + * + * @return int Zero if successful, otherwise non zero. + */ +int qemu_dsa_init(const strList *dsa_parameter, Error **errp); + +/** + * @brief Start logic to enable using DSA. + */ +void qemu_dsa_start(void); + +/** + * @brief Stop the device group and the completion thread. + */ +void qemu_dsa_stop(void); + +/** + * @brief Clean up system resources created for DSA offloading. + */ +void qemu_dsa_cleanup(void); + +/** + * @brief Check if DSA is running. + * + * @return True if DSA is running, otherwise false. + */ +bool qemu_dsa_is_running(void); + +#else + +static inline bool qemu_dsa_is_running(void) +{ + return false; +} + +static inline int qemu_dsa_init(const strList *dsa_parameter, Error **errp) +{ + if (dsa_parameter !=3D NULL && strlen(dsa_parameter) !=3D 0) { + error_setg(errp, "DSA is not supported."); + return -1; + } + + return 0; +} + +static inline void qemu_dsa_start(void) {} + +static inline void qemu_dsa_stop(void) {} + +static inline void qemu_dsa_cleanup(void) {} + +#endif + +#endif diff --git a/util/dsa.c b/util/dsa.c new file mode 100644 index 0000000000..79dab5d62c --- /dev/null +++ b/util/dsa.c @@ -0,0 +1,280 @@ +/* + * Use Intel Data Streaming Accelerator to offload certain background + * operations. + * + * Copyright (C) Bytedance Ltd. + * + * Authors: + * Hao Xiang + * Bryan Zhang + * Yichen Wang + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/queue.h" +#include "qemu/memalign.h" +#include "qemu/lockable.h" +#include "qemu/cutils.h" +#include "qemu/dsa.h" +#include "qemu/bswap.h" +#include "qemu/error-report.h" +#include "qemu/rcu.h" + +#pragma GCC push_options +#pragma GCC target("enqcmd") + +#include +#include "x86intrin.h" + +#define DSA_WQ_PORTAL_SIZE 4096 +#define MAX_DSA_DEVICES 16 + +uint32_t max_retry_count; +static QemuDsaDeviceGroup dsa_group; + + +/** + * @brief This function opens a DSA device's work queue and + * maps the DSA device memory into the current process. + * + * @param dsa_wq_path A pointer to the DSA device work queue's file path. + * @return A pointer to the mapped memory, or MAP_FAILED on failure. + */ +static void * +map_dsa_device(const char *dsa_wq_path) +{ + void *dsa_device; + int fd; + + fd =3D open(dsa_wq_path, O_RDWR); + if (fd < 0) { + error_report("Open %s failed with errno =3D %d.", + dsa_wq_path, errno); + return MAP_FAILED; + } + dsa_device =3D mmap(NULL, DSA_WQ_PORTAL_SIZE, PROT_WRITE, + MAP_SHARED | MAP_POPULATE, fd, 0); + close(fd); + if (dsa_device =3D=3D MAP_FAILED) { + error_report("mmap failed with errno =3D %d.", errno); + return MAP_FAILED; + } + return dsa_device; +} + +/** + * @brief Initializes a DSA device structure. + * + * @param instance A pointer to the DSA device. + * @param work_queue A pointer to the DSA work queue. + */ +static void +dsa_device_init(QemuDsaDevice *instance, + void *dsa_work_queue) +{ + instance->work_queue =3D dsa_work_queue; +} + +/** + * @brief Cleans up a DSA device structure. + * + * @param instance A pointer to the DSA device to cleanup. + */ +static void +dsa_device_cleanup(QemuDsaDevice *instance) +{ + if (instance->work_queue !=3D MAP_FAILED) { + munmap(instance->work_queue, DSA_WQ_PORTAL_SIZE); + } +} + +/** + * @brief Initializes a DSA device group. + * + * @param group A pointer to the DSA device group. + * @param dsa_parameter A list of DSA device path from are separated by sp= ace + * character migration parameter. Multiple DSA device path. + * + * @return Zero if successful, non-zero otherwise. + */ +static int +dsa_device_group_init(QemuDsaDeviceGroup *group, + const strList *dsa_parameter, + Error **errp) +{ + if (dsa_parameter =3D=3D NULL) { + error_setg(errp, "dsa device path is not supplied."); + return -1; + } + + int ret =3D 0; + const char *dsa_path[MAX_DSA_DEVICES]; + int num_dsa_devices =3D 0; + + while (dsa_parameter) { + dsa_path[num_dsa_devices++] =3D dsa_parameter->value; + if (num_dsa_devices =3D=3D MAX_DSA_DEVICES) { + break; + } + dsa_parameter =3D dsa_parameter->next; + } + + group->dsa_devices =3D + g_new0(QemuDsaDevice, num_dsa_devices); + group->num_dsa_devices =3D num_dsa_devices; + group->device_allocator_index =3D 0; + + group->running =3D false; + qemu_mutex_init(&group->task_queue_lock); + qemu_cond_init(&group->task_queue_cond); + QSIMPLEQ_INIT(&group->task_queue); + + void *dsa_wq =3D MAP_FAILED; + for (int i =3D 0; i < num_dsa_devices; i++) { + dsa_wq =3D map_dsa_device(dsa_path[i]); + if (dsa_wq =3D=3D MAP_FAILED) { + error_setg(errp, "map_dsa_device failed MAP_FAILED."); + ret =3D -1; + } + dsa_device_init(&group->dsa_devices[i], dsa_wq); + } + + return ret; +} + +/** + * @brief Starts a DSA device group. + * + * @param group A pointer to the DSA device group. + */ +static void +dsa_device_group_start(QemuDsaDeviceGroup *group) +{ + group->running =3D true; +} + +/** + * @brief Stops a DSA device group. + * + * @param group A pointer to the DSA device group. + */ +__attribute__((unused)) +static void +dsa_device_group_stop(QemuDsaDeviceGroup *group) +{ + group->running =3D false; +} + +/** + * @brief Cleans up a DSA device group. + * + * @param group A pointer to the DSA device group. + */ +static void +dsa_device_group_cleanup(QemuDsaDeviceGroup *group) +{ + if (!group->dsa_devices) { + return; + } + for (int i =3D 0; i < group->num_dsa_devices; i++) { + dsa_device_cleanup(&group->dsa_devices[i]); + } + g_free(group->dsa_devices); + group->dsa_devices =3D NULL; + + qemu_mutex_destroy(&group->task_queue_lock); + qemu_cond_destroy(&group->task_queue_cond); +} + +/** + * @brief Returns the next available DSA device in the group. + * + * @param group A pointer to the DSA device group. + * + * @return struct QemuDsaDevice* A pointer to the next available DSA device + * in the group. + */ +__attribute__((unused)) +static QemuDsaDevice * +dsa_device_group_get_next_device(QemuDsaDeviceGroup *group) +{ + if (group->num_dsa_devices =3D=3D 0) { + return NULL; + } + uint32_t current =3D qatomic_fetch_inc(&group->device_allocator_index); + current %=3D group->num_dsa_devices; + return &group->dsa_devices[current]; +} + +/** + * @brief Check if DSA is running. + * + * @return True if DSA is running, otherwise false. + */ +bool qemu_dsa_is_running(void) +{ + return false; +} + +static void +dsa_globals_init(void) +{ + max_retry_count =3D UINT32_MAX; +} + +/** + * @brief Initializes DSA devices. + * + * @param dsa_parameter A list of DSA device path from migration parameter. + * + * @return int Zero if successful, otherwise non zero. + */ +int qemu_dsa_init(const strList *dsa_parameter, Error **errp) +{ + dsa_globals_init(); + + return dsa_device_group_init(&dsa_group, dsa_parameter, errp); +} + +/** + * @brief Start logic to enable using DSA. + * + */ +void qemu_dsa_start(void) +{ + if (dsa_group.num_dsa_devices =3D=3D 0) { + return; + } + if (dsa_group.running) { + return; + } + dsa_device_group_start(&dsa_group); +} + +/** + * @brief Stop the device group and the completion thread. + * + */ +void qemu_dsa_stop(void) +{ + QemuDsaDeviceGroup *group =3D &dsa_group; + + if (!group->running) { + return; + } +} + +/** + * @brief Clean up system resources created for DSA offloading. + * + */ +void qemu_dsa_cleanup(void) +{ + qemu_dsa_stop(); + dsa_device_group_cleanup(&dsa_group); +} + diff --git a/util/meson.build b/util/meson.build index 5d8bef9891..5ec2158f9e 100644 --- a/util/meson.build +++ b/util/meson.build @@ -123,6 +123,9 @@ if cpu =3D=3D 'aarch64' util_ss.add(files('cpuinfo-aarch64.c')) elif cpu in ['x86', 'x86_64'] util_ss.add(files('cpuinfo-i386.c')) + if config_host_data.get('CONFIG_DSA_OPT') + util_ss.add(files('dsa.c')) + endif elif cpu =3D=3D 'loongarch64' util_ss.add(files('cpuinfo-loongarch.c')) elif cpu in ['ppc', 'ppc64'] --=20 Yichen Wang From nobody Sat Nov 23 17:14:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1731621891; cv=none; d=zohomail.com; s=zohoarc; b=c/YhC5HE6C1HLqFqpwBE+1v2p4R4H4SxyStQ8ODaejNLTn6BHKZi3Xn985bkN+ldmaHxdVAagf2qoghti1UsDbIzV2f0/6PV6DwE/HqRTF66pL4PhvK6OoJhzfpyX5HZt3YG8rv6v4GTXiKOUL7OY+pTPbOsstaj9c3DNxp/NuE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731621891; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Y5ccyaMJduIz/3YSCSIg1cp3jQKkuXtEIUcvrNn75vU=; b=jTXIklNILSAnYw8vUfGOj0O02RVhWP8b/uQ91DiJv31Zb+jxNwyCSnLjKqZHTMTfAqywtXu9GAFoyMeDjHEXAkC/8iABfmH1Y8i6gWvWFAHdx2NIZPWmhMXrDzJ3wXEFO2Uxeyusgm03KA/Q+I+Q+Qzn/oFxNK5QHpcC/Kt8zxw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1731621891369437.26063868816595; Thu, 14 Nov 2024 14:04:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tBhuZ-0003OK-Ut; Thu, 14 Nov 2024 17:02:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tBhuU-0003N2-1T for qemu-devel@nongnu.org; Thu, 14 Nov 2024 17:01:57 -0500 Received: from mail-qk1-x72f.google.com ([2607:f8b0:4864:20::72f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tBhuR-0007ec-6B for qemu-devel@nongnu.org; Thu, 14 Nov 2024 17:01:52 -0500 Received: by mail-qk1-x72f.google.com with SMTP id af79cd13be357-7b15416303aso66569885a.1 for ; Thu, 14 Nov 2024 14:01:50 -0800 (PST) Received: from DY4X0N7X05.bytedance.net ([130.44.212.152]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b35ca308bdsm93742485a.83.2024.11.14.14.01.47 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 14 Nov 2024 14:01:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1731621710; x=1732226510; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Y5ccyaMJduIz/3YSCSIg1cp3jQKkuXtEIUcvrNn75vU=; b=CPdyuoQi+n23tr1Hmca76z+juRQXmYQlg6OIIYOk5HCsNaAVW00mWACtk8W0XJ4zyI DOiXkQU/C6vhoG8PHGAKOxRCeyt49DgQHoqoPyDlgrC1/NSP6XdWVNgTTbjajp/xOEbX gQZeiGGevnrWiywohjOoG5lLjV+szuXqF+7twSM6w5mvDOLuRjiLP4ssjVlfOmKSMeFk +cSKBb3mE/ZvkVJEwZVdCp3gJSum1h4O67cshfFGKoysOiTF3PSNdwloYLhTgpxcDwT8 b935r5uzzyToHk3DBCnSk/rOL1nwHQ5LF1YWF/F2plliT56e3uf0NyBHeojGLWdHp46n 69vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731621710; x=1732226510; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y5ccyaMJduIz/3YSCSIg1cp3jQKkuXtEIUcvrNn75vU=; b=E3Q24WcvI3uc/FoyKgE0Csof2v30d/Y9wY0r9Jn7NUstqaY/ncGVhg274SuYKTIQlX tiqwAYcXVFNxj1ZeDxbAeeifdHkRuMZdz3qiguvx6xFz4ocdzAGHEiLzEGEzfYis1nNC tppKw+5x7lmZUUuk3NOmGk1PDMWaupbgJVS33rxHlvNRWrxeJ5Y1g4Re41DsoEvLN4YD UZ4suaDN5ULSxvlFnFC14Q0fN+6u/xAJMB2QvrJKj5OMaddN1L0QmFIcMzUbzAhXvllm 3JiKeZ2IshSSgRVEO5h71AYLO2BgBEVtWQibZjMT1UObqSNzA9OtaO61U2cWdvuR/uAw RXDA== X-Forwarded-Encrypted: i=1; AJvYcCXe7PsjrTN6ytFTRwsAYc45h337XA5lV4TVKPfamhly2dAgaVfRA2ImJM7L2kq7/EA9JjhgVb+KdXge@nongnu.org X-Gm-Message-State: AOJu0YyGzX83GKVHryMgU7ctcfWQ7GKuxV8B5JTwpF8X9VUL1twGvUwu XlbNZqOUbHI49Sowz0HFYGXPNgh80FB6izfxLb1e3h0njwT+bTpA3CTg2Lt8rps= X-Google-Smtp-Source: AGHT+IHXTWS7/H/Q5aLUpRoBH3tpBsnQkzVRRp3WVjnx+2EhICqd87raHL35N3vSeAxEg94lkKZsZg== X-Received: by 2002:a05:6214:5b11:b0:6d3:9292:6ce with SMTP id 6a1803df08f44-6d3fb83ded2mr3582066d6.27.1731621710074; Thu, 14 Nov 2024 14:01:50 -0800 (PST) From: Yichen Wang To: Peter Xu , Fabiano Rosas , "Dr. David Alan Gilbert" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eric Blake , Markus Armbruster , "Michael S. Tsirkin" , Cornelia Huck , qemu-devel@nongnu.org Cc: "Hao Xiang" , "Liu, Yuan1" , "Shivam Kumar" , "Ho-Ren (Jack) Chuang" , "Yichen Wang" Subject: [PATCH v7 04/12] util/dsa: Implement DSA task enqueue and dequeue. Date: Thu, 14 Nov 2024 14:01:24 -0800 Message-Id: <20241114220132.27399-5-yichen.wang@bytedance.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241114220132.27399-1-yichen.wang@bytedance.com> References: <20241114220132.27399-1-yichen.wang@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::72f; envelope-from=yichen.wang@bytedance.com; helo=mail-qk1-x72f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1731621892605116600 Content-Type: text/plain; charset="utf-8" From: Hao Xiang * Use a safe thread queue for DSA task enqueue/dequeue. * Implement DSA task submission. * Implement DSA batch task submission. Signed-off-by: Hao Xiang Signed-off-by: Yichen Wang Reviewed-by: Fabiano Rosas --- include/qemu/dsa.h | 29 +++++++ util/dsa.c | 202 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 230 insertions(+), 1 deletion(-) diff --git a/include/qemu/dsa.h b/include/qemu/dsa.h index 71686af28f..04ee8924ab 100644 --- a/include/qemu/dsa.h +++ b/include/qemu/dsa.h @@ -27,6 +27,17 @@ #include #include "x86intrin.h" =20 +typedef enum QemuDsaTaskType { + QEMU_DSA_TASK =3D 0, + QEMU_DSA_BATCH_TASK +} QemuDsaTaskType; + +typedef enum QemuDsaTaskStatus { + QEMU_DSA_TASK_READY =3D 0, + QEMU_DSA_TASK_PROCESSING, + QEMU_DSA_TASK_COMPLETION +} QemuDsaTaskStatus; + typedef struct { void *work_queue; } QemuDsaDevice; @@ -44,6 +55,24 @@ typedef struct { QemuDsaTaskQueue task_queue; } QemuDsaDeviceGroup; =20 +typedef void (*qemu_dsa_completion_fn)(void *); + +typedef struct QemuDsaBatchTask { + struct dsa_hw_desc batch_descriptor; + struct dsa_hw_desc *descriptors; + struct dsa_completion_record batch_completion __attribute__((aligned(3= 2))); + struct dsa_completion_record *completions; + QemuDsaDeviceGroup *group; + QemuDsaDevice *device; + qemu_dsa_completion_fn completion_callback; + QemuSemaphore sem_task_complete; + QemuDsaTaskType task_type; + QemuDsaTaskStatus status; + int batch_size; + QSIMPLEQ_ENTRY(QemuDsaBatchTask) entry; +} QemuDsaBatchTask; + + /** * @brief Initializes DSA devices. * diff --git a/util/dsa.c b/util/dsa.c index 79dab5d62c..b55fa599f0 100644 --- a/util/dsa.c +++ b/util/dsa.c @@ -31,6 +31,7 @@ #include "x86intrin.h" =20 #define DSA_WQ_PORTAL_SIZE 4096 +#define DSA_WQ_DEPTH 128 #define MAX_DSA_DEVICES 16 =20 uint32_t max_retry_count; @@ -210,6 +211,198 @@ dsa_device_group_get_next_device(QemuDsaDeviceGroup *= group) return &group->dsa_devices[current]; } =20 +/** + * @brief Empties out the DSA task queue. + * + * @param group A pointer to the DSA device group. + */ +static void +dsa_empty_task_queue(QemuDsaDeviceGroup *group) +{ + qemu_mutex_lock(&group->task_queue_lock); + QemuDsaTaskQueue *task_queue =3D &group->task_queue; + while (!QSIMPLEQ_EMPTY(task_queue)) { + QSIMPLEQ_REMOVE_HEAD(task_queue, entry); + } + qemu_mutex_unlock(&group->task_queue_lock); +} + +/** + * @brief Adds a task to the DSA task queue. + * + * @param group A pointer to the DSA device group. + * @param task A pointer to the DSA task to enqueue. + * + * @return int Zero if successful, otherwise a proper error code. + */ +static int +dsa_task_enqueue(QemuDsaDeviceGroup *group, + QemuDsaBatchTask *task) +{ + bool notify =3D false; + + qemu_mutex_lock(&group->task_queue_lock); + + if (!group->running) { + error_report("DSA: Tried to queue task to stopped device queue."); + qemu_mutex_unlock(&group->task_queue_lock); + return -1; + } + + /* The queue is empty. This enqueue operation is a 0->1 transition. */ + if (QSIMPLEQ_EMPTY(&group->task_queue)) { + notify =3D true; + } + + QSIMPLEQ_INSERT_TAIL(&group->task_queue, task, entry); + + /* We need to notify the waiter for 0->1 transitions. */ + if (notify) { + qemu_cond_signal(&group->task_queue_cond); + } + + qemu_mutex_unlock(&group->task_queue_lock); + + return 0; +} + +/** + * @brief Takes a DSA task out of the task queue. + * + * @param group A pointer to the DSA device group. + * @return QemuDsaBatchTask* The DSA task being dequeued. + */ +__attribute__((unused)) +static QemuDsaBatchTask * +dsa_task_dequeue(QemuDsaDeviceGroup *group) +{ + QemuDsaBatchTask *task =3D NULL; + + qemu_mutex_lock(&group->task_queue_lock); + + while (true) { + if (!group->running) { + goto exit; + } + task =3D QSIMPLEQ_FIRST(&group->task_queue); + if (task !=3D NULL) { + break; + } + qemu_cond_wait(&group->task_queue_cond, &group->task_queue_lock); + } + + QSIMPLEQ_REMOVE_HEAD(&group->task_queue, entry); + +exit: + qemu_mutex_unlock(&group->task_queue_lock); + return task; +} + +/** + * @brief Submits a DSA work item to the device work queue. + * + * @param wq A pointer to the DSA work queue's device memory. + * @param descriptor A pointer to the DSA work item descriptor. + * + * @return Zero if successful, non-zero otherwise. + */ +static int +submit_wi_int(void *wq, struct dsa_hw_desc *descriptor) +{ + uint32_t retry =3D 0; + + _mm_sfence(); + + while (true) { + if (_enqcmd(wq, descriptor) =3D=3D 0) { + break; + } + retry++; + if (retry > max_retry_count) { + error_report("Submit work retry %u times.", retry); + return -1; + } + } + + return 0; +} + +/** + * @brief Synchronously submits a DSA work item to the + * device work queue. + * + * @param wq A pointer to the DSA work queue's device memory. + * @param descriptor A pointer to the DSA work item descriptor. + * + * @return int Zero if successful, non-zero otherwise. + */ +__attribute__((unused)) +static int +submit_wi(void *wq, struct dsa_hw_desc *descriptor) +{ + return submit_wi_int(wq, descriptor); +} + +/** + * @brief Asynchronously submits a DSA work item to the + * device work queue. + * + * @param task A pointer to the task. + * + * @return int Zero if successful, non-zero otherwise. + */ +__attribute__((unused)) +static int +submit_wi_async(QemuDsaBatchTask *task) +{ + QemuDsaDeviceGroup *device_group =3D task->group; + QemuDsaDevice *device_instance =3D task->device; + int ret; + + assert(task->task_type =3D=3D QEMU_DSA_TASK); + + task->status =3D QEMU_DSA_TASK_PROCESSING; + + ret =3D submit_wi_int(device_instance->work_queue, + &task->descriptors[0]); + if (ret !=3D 0) { + return ret; + } + + return dsa_task_enqueue(device_group, task); +} + +/** + * @brief Asynchronously submits a DSA batch work item to the + * device work queue. + * + * @param batch_task A pointer to the batch task. + * + * @return int Zero if successful, non-zero otherwise. + */ +__attribute__((unused)) +static int +submit_batch_wi_async(QemuDsaBatchTask *batch_task) +{ + QemuDsaDeviceGroup *device_group =3D batch_task->group; + QemuDsaDevice *device_instance =3D batch_task->device; + int ret; + + assert(batch_task->task_type =3D=3D QEMU_DSA_BATCH_TASK); + assert(batch_task->batch_descriptor.desc_count <=3D batch_task->batch_= size); + assert(batch_task->status =3D=3D QEMU_DSA_TASK_READY); + + batch_task->status =3D QEMU_DSA_TASK_PROCESSING; + + ret =3D submit_wi_int(device_instance->work_queue, + &batch_task->batch_descriptor); + if (ret !=3D 0) { + return ret; + } + + return dsa_task_enqueue(device_group, batch_task); +} + /** * @brief Check if DSA is running. * @@ -223,7 +416,12 @@ bool qemu_dsa_is_running(void) static void dsa_globals_init(void) { - max_retry_count =3D UINT32_MAX; + /* + * This value follows a reference example by Intel. The POLL_RETRY_MAX= is + * defined to 10000, so here we used the max WQ depth * 100 for the th= e max + * polling retry count. + */ + max_retry_count =3D DSA_WQ_DEPTH * 100; } =20 /** @@ -266,6 +464,8 @@ void qemu_dsa_stop(void) if (!group->running) { return; } + + dsa_empty_task_queue(group); } =20 /** --=20 Yichen Wang From nobody Sat Nov 23 17:14:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1731621825; cv=none; d=zohomail.com; s=zohoarc; b=OWhwu7vvniQbD8Z5rZGP6YGEDAdrJ0azKLmsd0ajzqQk2do261lnjKsYJZBWdtg7gKiuyXvc9nx8TvkAhkzaYM2o06RsYA063Q4UoqcJavX6Ap5iTkqC5heF1hQ2Yb8K9kUDwhdDgDIdR+BWIc+h2/KlkpJS0KUIeynZbMSnpXU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731621825; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Y19pH1Iiy23CexJwYgaTfG2UlFbNf/+6u5xSvmqbnXU=; b=JFUq24VaRiFYIB/vIMk/jrvvO95vBfXdgRqjn9VEa8j7tSnBSTTu+UsnxNXU5EEjEIPtbp4EAn6nNaahX6x0pmMj4zL6G/SAAV0J4Ow3A06Gi62bCbqHoJoE1qrJ8SD8Zzklktw8utp6hpTxL19cShRujPfrP8RvzvrV9EeCt/Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17316218251751015.4656214318657; Thu, 14 Nov 2024 14:03:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tBhue-0003Pu-55; Thu, 14 Nov 2024 17:02:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tBhuV-0003N4-MW for qemu-devel@nongnu.org; Thu, 14 Nov 2024 17:01:57 -0500 Received: from mail-qv1-xf2e.google.com ([2607:f8b0:4864:20::f2e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tBhuT-0007ej-Qg for qemu-devel@nongnu.org; Thu, 14 Nov 2024 17:01:55 -0500 Received: by mail-qv1-xf2e.google.com with SMTP id 6a1803df08f44-6d3f3cc0585so5639686d6.1 for ; Thu, 14 Nov 2024 14:01:53 -0800 (PST) Received: from DY4X0N7X05.bytedance.net ([130.44.212.152]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b35ca308bdsm93742485a.83.2024.11.14.14.01.50 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 14 Nov 2024 14:01:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1731621712; x=1732226512; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Y19pH1Iiy23CexJwYgaTfG2UlFbNf/+6u5xSvmqbnXU=; b=AhDeSFhM3Te3/q9dPsZKkPeu+0qFs09hVJ4q0n26L/qTu7zeDAljSXogPkQztPm9EF 92JJGDEx6wnxkQVQQseKgrXAIziasKWquzjtq88pvSUuQWjy7UAuVacy+AWV57w0kmCu I2bD3Mbnn/+7MLWw7ngGZ4yNAD4JkZErkyipPsYNadNfe7qlRdujVZHAug607LCRBSOR tA8kJFqRYqCieGs0vafxX11Yw1daiHhb4MUPCx0yVzi6Hhf6rUWRKTYG5pEBrsBg3OV1 H+BLb/HgR7Tv85/0pUaFErRsIaLMaN3bv6deyNJpyYrFg3JT+HCffHOUiboFZmacJkoF FLTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731621712; x=1732226512; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y19pH1Iiy23CexJwYgaTfG2UlFbNf/+6u5xSvmqbnXU=; b=egDgxzgDOpY6c9CclQQ3+E7K910dlnXR6UO3t26UjXtq897zF6vlnCRbleux1mTSfr gLla8Vp+Uns8G4oqlPn80mRxGuhpZ8KMRvoJuHJMtVudYWIgAnaATVa1vFhg2cQQfc/G JXPxHEqQ54XJzS8CrhWUziuUBSgXnZJwkOA9ayLPyWGNcs3QN07G/nDUbpUdkuftnhra PKPKV9NKiU54zwDaVkkydCtApGCUoLLXAzF6Gzkmo7Wgee2n2P33Go5CxxbJTe30HriA m9PftaaxWtgfMTY81wAtv4de/L/2uDeuVPrpKXWaibLaHSZLUTyEonvSziMRZtJbuSGK iqNQ== X-Forwarded-Encrypted: i=1; AJvYcCVW2CrhTdkq5SvZjhW/5bdPBSpn/QsUM77cQgTXTjKvTLH+OIMK61U2xn1PA5kvv3hyGh3He0dw/M5E@nongnu.org X-Gm-Message-State: AOJu0YyVzDpCSmlI7m0aWlLONeJFh01hU/xbOQC/t+0TRvKU5Bx9RDmQ GaQCKROkb53zXWktm9nA/vOWSI6LOuNNPA+0ttIn7ZrVlEZ4+zFK18b2GGpsLHU= X-Google-Smtp-Source: AGHT+IFiknonYoDlBa66zPPWbD6gTv71S22Fi/H0UIM5LzL7vS7KAvzSgqdC4AT6VD9IQN32KExAdA== X-Received: by 2002:a05:6214:54c3:b0:6cc:567:d595 with SMTP id 6a1803df08f44-6d3fb78ede8mr5058506d6.7.1731621712596; Thu, 14 Nov 2024 14:01:52 -0800 (PST) From: Yichen Wang To: Peter Xu , Fabiano Rosas , "Dr. David Alan Gilbert" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eric Blake , Markus Armbruster , "Michael S. Tsirkin" , Cornelia Huck , qemu-devel@nongnu.org Cc: "Hao Xiang" , "Liu, Yuan1" , "Shivam Kumar" , "Ho-Ren (Jack) Chuang" , "Yichen Wang" Subject: [PATCH v7 05/12] util/dsa: Implement DSA task asynchronous completion thread model. Date: Thu, 14 Nov 2024 14:01:25 -0800 Message-Id: <20241114220132.27399-6-yichen.wang@bytedance.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241114220132.27399-1-yichen.wang@bytedance.com> References: <20241114220132.27399-1-yichen.wang@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::f2e; envelope-from=yichen.wang@bytedance.com; helo=mail-qv1-xf2e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1731621826084116600 Content-Type: text/plain; charset="utf-8" From: Hao Xiang * Create a dedicated thread for DSA task completion. * DSA completion thread runs a loop and poll for completed tasks. * Start and stop DSA completion thread during DSA device start stop. User space application can directly submit task to Intel DSA accelerator by writing to DSA's device memory (mapped in user space). Once a task is submitted, the device starts processing it and write the completion status back to the task. A user space application can poll the task's completion status to check for completion. This change uses a dedicated thread to perform DSA task completion checking. Signed-off-by: Hao Xiang Signed-off-by: Yichen Wang Reviewed-by: Fabiano Rosas --- include/qemu/dsa.h | 1 + util/dsa.c | 274 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 274 insertions(+), 1 deletion(-) diff --git a/include/qemu/dsa.h b/include/qemu/dsa.h index 04ee8924ab..d24567f0be 100644 --- a/include/qemu/dsa.h +++ b/include/qemu/dsa.h @@ -69,6 +69,7 @@ typedef struct QemuDsaBatchTask { QemuDsaTaskType task_type; QemuDsaTaskStatus status; int batch_size; + bool *results; QSIMPLEQ_ENTRY(QemuDsaBatchTask) entry; } QemuDsaBatchTask; =20 diff --git a/util/dsa.c b/util/dsa.c index b55fa599f0..c3ca71df86 100644 --- a/util/dsa.c +++ b/util/dsa.c @@ -33,9 +33,20 @@ #define DSA_WQ_PORTAL_SIZE 4096 #define DSA_WQ_DEPTH 128 #define MAX_DSA_DEVICES 16 +#define DSA_COMPLETION_THREAD "qemu_dsa_completion" + +typedef struct { + bool stopping; + bool running; + QemuThread thread; + int thread_id; + QemuSemaphore sem_init_done; + QemuDsaDeviceGroup *group; +} QemuDsaCompletionThread; =20 uint32_t max_retry_count; static QemuDsaDeviceGroup dsa_group; +static QemuDsaCompletionThread completion_thread; =20 =20 /** @@ -403,6 +414,265 @@ submit_batch_wi_async(QemuDsaBatchTask *batch_task) return dsa_task_enqueue(device_group, batch_task); } =20 +/** + * @brief Poll for the DSA work item completion. + * + * @param completion A pointer to the DSA work item completion record. + * @param opcode The DSA opcode. + * + * @return Zero if successful, non-zero otherwise. + */ +static int +poll_completion(struct dsa_completion_record *completion, + enum dsa_opcode opcode) +{ + uint8_t status; + uint64_t retry =3D 0; + + while (true) { + /* The DSA operation completes successfully or fails. */ + status =3D completion->status; + if (status =3D=3D DSA_COMP_SUCCESS || + status =3D=3D DSA_COMP_PAGE_FAULT_NOBOF || + status =3D=3D DSA_COMP_BATCH_PAGE_FAULT || + status =3D=3D DSA_COMP_BATCH_FAIL) { + break; + } else if (status !=3D DSA_COMP_NONE) { + error_report("DSA opcode %d failed with status =3D %d.", + opcode, status); + return 1; + } + retry++; + if (retry > max_retry_count) { + error_report("DSA wait for completion retry %lu times.", retry= ); + return 1; + } + _mm_pause(); + } + + return 0; +} + +/** + * @brief Complete a single DSA task in the batch task. + * + * @param task A pointer to the batch task structure. + * + * @return Zero if successful, otherwise non-zero. + */ +static int +poll_task_completion(QemuDsaBatchTask *task) +{ + assert(task->task_type =3D=3D QEMU_DSA_TASK); + + struct dsa_completion_record *completion =3D &task->completions[0]; + uint8_t status; + int ret; + + ret =3D poll_completion(completion, task->descriptors[0].opcode); + if (ret !=3D 0) { + goto exit; + } + + status =3D completion->status; + if (status =3D=3D DSA_COMP_SUCCESS) { + task->results[0] =3D (completion->result =3D=3D 0); + goto exit; + } + + assert(status =3D=3D DSA_COMP_PAGE_FAULT_NOBOF); + +exit: + return ret; +} + +/** + * @brief Poll a batch task status until it completes. If DSA task doesn't + * complete properly, use CPU to complete the task. + * + * @param batch_task A pointer to the DSA batch task. + * + * @return Zero if successful, otherwise non-zero. + */ +static int +poll_batch_task_completion(QemuDsaBatchTask *batch_task) +{ + struct dsa_completion_record *batch_completion =3D + &batch_task->batch_completion; + struct dsa_completion_record *completion; + uint8_t batch_status; + uint8_t status; + bool *results =3D batch_task->results; + uint32_t count =3D batch_task->batch_descriptor.desc_count; + int ret; + + ret =3D poll_completion(batch_completion, + batch_task->batch_descriptor.opcode); + if (ret !=3D 0) { + goto exit; + } + + batch_status =3D batch_completion->status; + + if (batch_status =3D=3D DSA_COMP_SUCCESS) { + if (batch_completion->bytes_completed =3D=3D count) { + /* + * Let's skip checking for each descriptors' completion status + * if the batch descriptor says all succedded. + */ + for (int i =3D 0; i < count; i++) { + assert(batch_task->completions[i].status =3D=3D DSA_COMP_S= UCCESS); + results[i] =3D (batch_task->completions[i].result =3D=3D 0= ); + } + goto exit; + } + } else { + assert(batch_status =3D=3D DSA_COMP_BATCH_FAIL || + batch_status =3D=3D DSA_COMP_BATCH_PAGE_FAULT); + } + + for (int i =3D 0; i < count; i++) { + + completion =3D &batch_task->completions[i]; + status =3D completion->status; + + if (status =3D=3D DSA_COMP_SUCCESS) { + results[i] =3D (completion->result =3D=3D 0); + continue; + } + + assert(status =3D=3D DSA_COMP_PAGE_FAULT_NOBOF); + + if (status !=3D DSA_COMP_PAGE_FAULT_NOBOF) { + error_report("Unexpected DSA completion status =3D %u.", statu= s); + ret =3D 1; + goto exit; + } + } + +exit: + return ret; +} + +/** + * @brief Handles an asynchronous DSA batch task completion. + * + * @param task A pointer to the batch buffer zero task structure. + */ +static void +dsa_batch_task_complete(QemuDsaBatchTask *batch_task) +{ + batch_task->status =3D QEMU_DSA_TASK_COMPLETION; + batch_task->completion_callback(batch_task); +} + +/** + * @brief The function entry point called by a dedicated DSA + * work item completion thread. + * + * @param opaque A pointer to the thread context. + * + * @return void* Not used. + */ +static void * +dsa_completion_loop(void *opaque) +{ + QemuDsaCompletionThread *thread_context =3D + (QemuDsaCompletionThread *)opaque; + QemuDsaBatchTask *batch_task; + QemuDsaDeviceGroup *group =3D thread_context->group; + int ret; + + rcu_register_thread(); + + thread_context->thread_id =3D qemu_get_thread_id(); + qemu_sem_post(&thread_context->sem_init_done); + + while (thread_context->running) { + batch_task =3D dsa_task_dequeue(group); + assert(batch_task !=3D NULL || !group->running); + if (!group->running) { + assert(!thread_context->running); + break; + } + if (batch_task->task_type =3D=3D QEMU_DSA_TASK) { + ret =3D poll_task_completion(batch_task); + } else { + assert(batch_task->task_type =3D=3D QEMU_DSA_BATCH_TASK); + ret =3D poll_batch_task_completion(batch_task); + } + + if (ret !=3D 0) { + goto exit; + } + + dsa_batch_task_complete(batch_task); + } + +exit: + if (ret !=3D 0) { + error_report("DSA completion thread exited due to internal error."= ); + } + rcu_unregister_thread(); + return NULL; +} + +/** + * @brief Initializes a DSA completion thread. + * + * @param completion_thread A pointer to the completion thread context. + * @param group A pointer to the DSA device group. + */ +static void +dsa_completion_thread_init( + QemuDsaCompletionThread *completion_thread, + QemuDsaDeviceGroup *group) +{ + completion_thread->stopping =3D false; + completion_thread->running =3D true; + completion_thread->thread_id =3D -1; + qemu_sem_init(&completion_thread->sem_init_done, 0); + completion_thread->group =3D group; + + qemu_thread_create(&completion_thread->thread, + DSA_COMPLETION_THREAD, + dsa_completion_loop, + completion_thread, + QEMU_THREAD_JOINABLE); + + /* Wait for initialization to complete */ + qemu_sem_wait(&completion_thread->sem_init_done); +} + +/** + * @brief Stops the completion thread (and implicitly, the device group). + * + * @param opaque A pointer to the completion thread. + */ +static void dsa_completion_thread_stop(void *opaque) +{ + QemuDsaCompletionThread *thread_context =3D + (QemuDsaCompletionThread *)opaque; + + QemuDsaDeviceGroup *group =3D thread_context->group; + + qemu_mutex_lock(&group->task_queue_lock); + + thread_context->stopping =3D true; + thread_context->running =3D false; + + /* Prevent the compiler from setting group->running first. */ + barrier(); + dsa_device_group_stop(group); + + qemu_cond_signal(&group->task_queue_cond); + qemu_mutex_unlock(&group->task_queue_lock); + + qemu_thread_join(&thread_context->thread); + + qemu_sem_destroy(&thread_context->sem_init_done); +} + /** * @brief Check if DSA is running. * @@ -410,7 +680,7 @@ submit_batch_wi_async(QemuDsaBatchTask *batch_task) */ bool qemu_dsa_is_running(void) { - return false; + return completion_thread.running; } =20 static void @@ -451,6 +721,7 @@ void qemu_dsa_start(void) return; } dsa_device_group_start(&dsa_group); + dsa_completion_thread_init(&completion_thread, &dsa_group); } =20 /** @@ -465,6 +736,7 @@ void qemu_dsa_stop(void) return; } =20 + dsa_completion_thread_stop(&completion_thread); dsa_empty_task_queue(group); } =20 --=20 Yichen Wang From nobody Sat Nov 23 17:14:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1731621900; cv=none; d=zohomail.com; s=zohoarc; b=EkQIUrcD+lWKSgskx1alTy7m+QpX3ZEJg8rw6Ydd1269RzNW7y/eap+qdn1jzRQULpkmm6rmI4onPAdHu6k9wlvv6UTBu6Nm3GvGrfF0kbhkZ7PVI9JD1ATDLw8uSRvvX9SE+k8VUNtWPpdfzaUChns5Soz7yh/EgEwIugl3I9w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731621900; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=IZ2Pu4kJ0nsFYzxGgx50/4JNn2XpzKJ6226m8PzsTU8=; b=l2QTvs1JBONR75xyJZfb3uvm2TUa0foxNR3fMCnVoEgllDr8Zn9RvAsrZAvQxJaUR8gMAJ5nzOW0FmzdoYQWtEujKAH86QjPitPjECktkDQVslyDedmO3QcSn36A2Ptkn3sMoD/qUG7FCZnnAnECSM5PPIS6f1pRLXS1pmmeldI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1731621900506988.1017513369477; Thu, 14 Nov 2024 14:05:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tBhua-0003Ol-UG; Thu, 14 Nov 2024 17:02:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tBhuZ-0003ON-UN for qemu-devel@nongnu.org; Thu, 14 Nov 2024 17:01:59 -0500 Received: from mail-qk1-x72c.google.com ([2607:f8b0:4864:20::72c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tBhuW-0007f1-Fc for qemu-devel@nongnu.org; Thu, 14 Nov 2024 17:01:59 -0500 Received: by mail-qk1-x72c.google.com with SMTP id af79cd13be357-7b153047b29so68800685a.3 for ; Thu, 14 Nov 2024 14:01:56 -0800 (PST) Received: from DY4X0N7X05.bytedance.net ([130.44.212.152]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b35ca308bdsm93742485a.83.2024.11.14.14.01.53 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 14 Nov 2024 14:01:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1731621715; x=1732226515; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IZ2Pu4kJ0nsFYzxGgx50/4JNn2XpzKJ6226m8PzsTU8=; b=f8XaRJatrAD5nH24IJu8kD6Z/FrSeedkIHJz0KR9BYrVDwylP8TEjlsPwCEsuvYpvN BAVEdOj9YeyaNvn0zMMAdrCKgGX7pKb6eJKrJAITMrIJP5CPkjlpZjCNzL/JRtnFSx67 Sq/n5fJvy5p4trqhJjuO/8xDfYLvgkRCz8iLfzzwLCllAn8eF1FSx5CFIrFirlqejRlj DsoqNA+Rvp104gSQNQv80IExqLFkV3WK5SKnNVIVL9IcSbHeNXk32bhq4mVrlpsNxRoI jqDNviAeuUUj9c8tpRqJincCW8sgY6Di82IqoFIps5HOrSO8Re6ijS7X2inkACWUHSvP HmQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731621715; x=1732226515; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IZ2Pu4kJ0nsFYzxGgx50/4JNn2XpzKJ6226m8PzsTU8=; b=sPH8liqZvhT0Jy3FYYzAOGuSoG0aFWJMXXFs8oby/+sjpePtIwzeFJJ44ySu9UqV6R e8dDMc3X1iDCjS8oF1oC3CcoKNYyjeWwPlgJ/QJUiKMczo6LHIhohs5NOguhGi4jru34 64S4Z0FcF9IzXnXCorGk9oYLE7R2xzfhz9RNWJl1zLYsAXiera/vc3HDto4tRYQ4TNFx tC9/PQrSgbFfhX3i4LnP2iObZJ3Ilxuq6Lm+Jk/kcSjJbm8LuodfGR7DKbdmObUvX2Dr mRA5e4EKcC1Yccnm88QHzb1sxJateBLzKyImUWcjHoHZWDwOfnairX4fOFx3iMUpVWj9 N9Qw== X-Forwarded-Encrypted: i=1; AJvYcCWbb3P0t+7oltNBDeDYSlKaMPneIgtmNfd5p8nYkptB0PU5VMtHtsuqByzuYl7sYGJSPN+z/3AkpsjZ@nongnu.org X-Gm-Message-State: AOJu0YxWicOTbatr0GIfweGQYf9+rLQl0mA/iEUB0B3KQF7fWrBBTJfo LYwMxTs2t7QMstJO9OKfwH9PfotPTyLqP8cVdl/1cSnbMOUkesHEKN1xb/8WXV0= X-Google-Smtp-Source: AGHT+IHF3yTUAxAwOtgen67mStelkGsCa/A5yQVKBWwW5hrkSOeoR3oJ9UldaZd3Yldhc34iFdLs6g== X-Received: by 2002:a05:620a:2495:b0:7ac:9c07:e90 with SMTP id af79cd13be357-7b3622c24d2mr53223385a.12.1731621715165; Thu, 14 Nov 2024 14:01:55 -0800 (PST) From: Yichen Wang To: Peter Xu , Fabiano Rosas , "Dr. David Alan Gilbert" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eric Blake , Markus Armbruster , "Michael S. Tsirkin" , Cornelia Huck , qemu-devel@nongnu.org Cc: "Hao Xiang" , "Liu, Yuan1" , "Shivam Kumar" , "Ho-Ren (Jack) Chuang" , "Yichen Wang" , Bryan Zhang Subject: [PATCH v7 06/12] util/dsa: Implement zero page checking in DSA task. Date: Thu, 14 Nov 2024 14:01:26 -0800 Message-Id: <20241114220132.27399-7-yichen.wang@bytedance.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241114220132.27399-1-yichen.wang@bytedance.com> References: <20241114220132.27399-1-yichen.wang@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::72c; envelope-from=yichen.wang@bytedance.com; helo=mail-qk1-x72c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1731621902424116600 Content-Type: text/plain; charset="utf-8" From: Hao Xiang Create DSA task with operation code DSA_OPCODE_COMPVAL. Here we create two types of DSA tasks, a single DSA task and a batch DSA task. Batch DSA task reduces task submission overhead and hence should be the default option. However, due to the way DSA hardware works, a DSA batch task must contain at least two individual tasks. There are times we need to submit a single task and hence a single DSA task submission is also required. Signed-off-by: Hao Xiang Signed-off-by: Bryan Zhang Signed-off-by: Yichen Wang --- include/qemu/dsa.h | 44 ++++++-- util/dsa.c | 254 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 269 insertions(+), 29 deletions(-) diff --git a/include/qemu/dsa.h b/include/qemu/dsa.h index d24567f0be..cb407b8b49 100644 --- a/include/qemu/dsa.h +++ b/include/qemu/dsa.h @@ -16,6 +16,7 @@ #define QEMU_DSA_H =20 #include "qapi/error.h" +#include "exec/cpu-common.h" #include "qemu/thread.h" #include "qemu/queue.h" =20 @@ -70,10 +71,11 @@ typedef struct QemuDsaBatchTask { QemuDsaTaskStatus status; int batch_size; bool *results; + /* Address of each pages in pages */ + ram_addr_t *addr; QSIMPLEQ_ENTRY(QemuDsaBatchTask) entry; } QemuDsaBatchTask; =20 - /** * @brief Initializes DSA devices. * @@ -105,8 +107,26 @@ void qemu_dsa_cleanup(void); */ bool qemu_dsa_is_running(void); =20 +/** + * @brief Initializes a buffer zero DSA batch task. + * + * @param batch_size The number of zero page checking tasks in the batch. + * @return A pointer to the zero page checking tasks initialized. + */ +QemuDsaBatchTask * +buffer_zero_batch_task_init(int batch_size); + +/** + * @brief Performs the proper cleanup on a DSA batch task. + * + * @param task A pointer to the batch task to cleanup. + */ +void buffer_zero_batch_task_destroy(QemuDsaBatchTask *task); + #else =20 +typedef struct QemuDsaBatchTask {} QemuDsaBatchTask; + static inline bool qemu_dsa_is_running(void) { return false; @@ -114,19 +134,27 @@ static inline bool qemu_dsa_is_running(void) =20 static inline int qemu_dsa_init(const strList *dsa_parameter, Error **errp) { - if (dsa_parameter !=3D NULL && strlen(dsa_parameter) !=3D 0) { - error_setg(errp, "DSA is not supported."); - return -1; - } - - return 0; + error_setg(errp, "DSA accelerator is not enabled."); + return -1; } =20 static inline void qemu_dsa_start(void) {} =20 static inline void qemu_dsa_stop(void) {} =20 -static inline void qemu_dsa_cleanup(void) {} +static inline QemuDsaBatchTask *buffer_zero_batch_task_init(int batch_size) +{ + return NULL; +} + +static inline void buffer_zero_batch_task_destroy(QemuDsaBatchTask *task) = {} + +static inline int +buffer_is_zero_dsa_batch_sync(QemuDsaBatchTask *batch_task, + const void **buf, size_t count, size_t len) +{ + return -1; +} =20 #endif =20 diff --git a/util/dsa.c b/util/dsa.c index c3ca71df86..408c163195 100644 --- a/util/dsa.c +++ b/util/dsa.c @@ -48,6 +48,7 @@ uint32_t max_retry_count; static QemuDsaDeviceGroup dsa_group; static QemuDsaCompletionThread completion_thread; =20 +static void buffer_zero_dsa_completion(void *context); =20 /** * @brief This function opens a DSA device's work queue and @@ -174,7 +175,6 @@ dsa_device_group_start(QemuDsaDeviceGroup *group) * * @param group A pointer to the DSA device group. */ -__attribute__((unused)) static void dsa_device_group_stop(QemuDsaDeviceGroup *group) { @@ -210,7 +210,6 @@ dsa_device_group_cleanup(QemuDsaDeviceGroup *group) * @return struct QemuDsaDevice* A pointer to the next available DSA device * in the group. */ -__attribute__((unused)) static QemuDsaDevice * dsa_device_group_get_next_device(QemuDsaDeviceGroup *group) { @@ -283,7 +282,6 @@ dsa_task_enqueue(QemuDsaDeviceGroup *group, * @param group A pointer to the DSA device group. * @return QemuDsaBatchTask* The DSA task being dequeued. */ -__attribute__((unused)) static QemuDsaBatchTask * dsa_task_dequeue(QemuDsaDeviceGroup *group) { @@ -338,22 +336,6 @@ submit_wi_int(void *wq, struct dsa_hw_desc *descriptor) return 0; } =20 -/** - * @brief Synchronously submits a DSA work item to the - * device work queue. - * - * @param wq A pointer to the DSA work queue's device memory. - * @param descriptor A pointer to the DSA work item descriptor. - * - * @return int Zero if successful, non-zero otherwise. - */ -__attribute__((unused)) -static int -submit_wi(void *wq, struct dsa_hw_desc *descriptor) -{ - return submit_wi_int(wq, descriptor); -} - /** * @brief Asynchronously submits a DSA work item to the * device work queue. @@ -362,7 +344,6 @@ submit_wi(void *wq, struct dsa_hw_desc *descriptor) * * @return int Zero if successful, non-zero otherwise. */ -__attribute__((unused)) static int submit_wi_async(QemuDsaBatchTask *task) { @@ -391,7 +372,6 @@ submit_wi_async(QemuDsaBatchTask *task) * * @return int Zero if successful, non-zero otherwise. */ -__attribute__((unused)) static int submit_batch_wi_async(QemuDsaBatchTask *batch_task) { @@ -750,3 +730,235 @@ void qemu_dsa_cleanup(void) dsa_device_group_cleanup(&dsa_group); } =20 + +/* Buffer zero comparison DSA task implementations */ +/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */ + +/** + * @brief Sets a buffer zero comparison DSA task. + * + * @param descriptor A pointer to the DSA task descriptor. + * @param buf A pointer to the memory buffer. + * @param len The length of the buffer. + */ +static void +buffer_zero_task_set_int(struct dsa_hw_desc *descriptor, + const void *buf, + size_t len) +{ + struct dsa_completion_record *completion =3D + (struct dsa_completion_record *)descriptor->completion_addr; + + descriptor->xfer_size =3D len; + descriptor->src_addr =3D (uintptr_t)buf; + completion->status =3D 0; + completion->result =3D 0; +} + +/** + * @brief Resets a buffer zero comparison DSA batch task. + * + * @param task A pointer to the DSA batch task. + */ +static void +buffer_zero_task_reset(QemuDsaBatchTask *task) +{ + task->completions[0].status =3D DSA_COMP_NONE; + task->task_type =3D QEMU_DSA_TASK; + task->status =3D QEMU_DSA_TASK_READY; +} + +/** + * @brief Resets a buffer zero comparison DSA batch task. + * + * @param task A pointer to the batch task. + * @param count The number of DSA tasks this batch task will contain. + */ +static void +buffer_zero_batch_task_reset(QemuDsaBatchTask *task, size_t count) +{ + task->batch_completion.status =3D DSA_COMP_NONE; + task->batch_descriptor.desc_count =3D count; + task->task_type =3D QEMU_DSA_BATCH_TASK; + task->status =3D QEMU_DSA_TASK_READY; +} + +/** + * @brief Sets a buffer zero comparison DSA task. + * + * @param task A pointer to the DSA task. + * @param buf A pointer to the memory buffer. + * @param len The buffer length. + */ +static void +buffer_zero_task_set(QemuDsaBatchTask *task, + const void *buf, + size_t len) +{ + buffer_zero_task_reset(task); + buffer_zero_task_set_int(&task->descriptors[0], buf, len); +} + +/** + * @brief Sets a buffer zero comparison batch task. + * + * @param batch_task A pointer to the batch task. + * @param buf An array of memory buffers. + * @param count The number of buffers in the array. + * @param len The length of the buffers. + */ +static void +buffer_zero_batch_task_set(QemuDsaBatchTask *batch_task, + const void **buf, size_t count, size_t len) +{ + assert(count > 0); + assert(count <=3D batch_task->batch_size); + + buffer_zero_batch_task_reset(batch_task, count); + for (int i =3D 0; i < count; i++) { + buffer_zero_task_set_int(&batch_task->descriptors[i], buf[i], len); + } +} + +/** + * @brief Asychronously perform a buffer zero DSA operation. + * + * @param task A pointer to the batch task structure. + * @param buf A pointer to the memory buffer. + * @param len The length of the memory buffer. + * + * @return int Zero if successful, otherwise an appropriate error code. + */ +__attribute__((unused)) +static int +buffer_zero_dsa_async(QemuDsaBatchTask *task, + const void *buf, size_t len) +{ + buffer_zero_task_set(task, buf, len); + + return submit_wi_async(task); +} + +/** + * @brief Sends a memory comparison batch task to a DSA device and wait + * for completion. + * + * @param batch_task The batch task to be submitted to DSA device. + * @param buf An array of memory buffers to check for zero. + * @param count The number of buffers. + * @param len The buffer length. + */ +__attribute__((unused)) +static int +buffer_zero_dsa_batch_async(QemuDsaBatchTask *batch_task, + const void **buf, size_t count, size_t len) +{ + assert(count <=3D batch_task->batch_size); + buffer_zero_batch_task_set(batch_task, buf, count, len); + + return submit_batch_wi_async(batch_task); +} + +/** + * @brief The completion callback function for buffer zero + * comparison DSA task completion. + * + * @param context A pointer to the callback context. + */ +static void +buffer_zero_dsa_completion(void *context) +{ + assert(context !=3D NULL); + + QemuDsaBatchTask *task =3D (QemuDsaBatchTask *)context; + qemu_sem_post(&task->sem_task_complete); +} + +/** + * @brief Wait for the asynchronous DSA task to complete. + * + * @param batch_task A pointer to the buffer zero comparison batch task. + */ +__attribute__((unused)) +static void +buffer_zero_dsa_wait(QemuDsaBatchTask *batch_task) +{ + qemu_sem_wait(&batch_task->sem_task_complete); +} + +/** + * @brief Initializes a buffer zero comparison DSA task. + * + * @param descriptor A pointer to the DSA task descriptor. + * @param completion A pointer to the DSA task completion record. + */ +static void +buffer_zero_task_init_int(struct dsa_hw_desc *descriptor, + struct dsa_completion_record *completion) +{ + descriptor->opcode =3D DSA_OPCODE_COMPVAL; + descriptor->flags =3D IDXD_OP_FLAG_RCR | IDXD_OP_FLAG_CRAV; + descriptor->comp_pattern =3D (uint64_t)0; + descriptor->completion_addr =3D (uint64_t)completion; +} + +/** + * @brief Initializes a buffer zero DSA batch task. + * + * @param batch_size The number of zero page checking tasks in the batch. + * @return A pointer to the zero page checking tasks initialized. + */ +QemuDsaBatchTask * +buffer_zero_batch_task_init(int batch_size) +{ + QemuDsaBatchTask *task =3D qemu_memalign(64, sizeof(QemuDsaBatchTask)); + int descriptors_size =3D sizeof(*task->descriptors) * batch_size; + + memset(task, 0, sizeof(*task)); + task->addr =3D g_new0(ram_addr_t, batch_size); + task->results =3D g_new0(bool, batch_size); + task->batch_size =3D batch_size; + task->descriptors =3D + (struct dsa_hw_desc *)qemu_memalign(64, descriptors_size); + memset(task->descriptors, 0, descriptors_size); + task->completions =3D (struct dsa_completion_record *)qemu_memalign( + 32, sizeof(*task->completions) * batch_size); + + task->batch_completion.status =3D DSA_COMP_NONE; + task->batch_descriptor.completion_addr =3D (uint64_t)&task->batch_comp= letion; + /* TODO: Ensure that we never send a batch with count <=3D 1 */ + task->batch_descriptor.desc_count =3D 0; + task->batch_descriptor.opcode =3D DSA_OPCODE_BATCH; + task->batch_descriptor.flags =3D IDXD_OP_FLAG_RCR | IDXD_OP_FLAG_CRAV; + task->batch_descriptor.desc_list_addr =3D (uintptr_t)task->descriptors; + task->status =3D QEMU_DSA_TASK_READY; + task->group =3D &dsa_group; + task->device =3D dsa_device_group_get_next_device(&dsa_group); + + for (int i =3D 0; i < task->batch_size; i++) { + buffer_zero_task_init_int(&task->descriptors[i], + &task->completions[i]); + } + + qemu_sem_init(&task->sem_task_complete, 0); + task->completion_callback =3D buffer_zero_dsa_completion; + + return task; +} + +/** + * @brief Performs the proper cleanup on a DSA batch task. + * + * @param task A pointer to the batch task to cleanup. + */ +void +buffer_zero_batch_task_destroy(QemuDsaBatchTask *task) +{ + g_free(task->addr); + g_free(task->results); + qemu_vfree(task->descriptors); + qemu_vfree(task->completions); + task->results =3D NULL; + qemu_sem_destroy(&task->sem_task_complete); + qemu_vfree(task); +} --=20 Yichen Wang From nobody Sat Nov 23 17:14:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1731621782; cv=none; d=zohomail.com; s=zohoarc; b=AsyI8NSFEBLPw8qVkLOEllPQYEDgFgS6IpTIWAJ2iQly1OIBEWmYWb4eebWNGYk9BdON+0nUn+1rN9QISC1VKzMa4QhurNfzEcTUnQavbPtvq0xjn1jIHkNNXPRc6bk4GqcL7/ZO6QvrbT1AB0A0QH6fZCUMqyolzCgz6R3V9Fo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731621782; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=PXb0xU9EUeq/o2lDkxhUbldwZ6kS44ZWhCyxS7PxJXE=; b=N+EWRHRXNUBRanmc9gcPn++phXj9tLA5emksN0BMYtnzLADKZHAnUP6dKdG/pm6MP3e3oYvHbfzTUcGfXAJV9GFJdnC6d4z5/6aodi+wJlR5CQ+zifn9VM4LJnBiPotMEmLorMwXlbiofCy9Uhz/NH3fmXvU5n1uXKaBgEU38l4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1731621782464297.5634737211552; Thu, 14 Nov 2024 14:03:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tBhue-0003Pv-7Z; Thu, 14 Nov 2024 17:02:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tBhub-0003On-3n for qemu-devel@nongnu.org; Thu, 14 Nov 2024 17:02:01 -0500 Received: from mail-qk1-x72a.google.com ([2607:f8b0:4864:20::72a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tBhuY-0007f9-Vs for qemu-devel@nongnu.org; Thu, 14 Nov 2024 17:02:00 -0500 Received: by mail-qk1-x72a.google.com with SMTP id af79cd13be357-7b35b1eb7e3so92388085a.1 for ; Thu, 14 Nov 2024 14:01:58 -0800 (PST) Received: from DY4X0N7X05.bytedance.net ([130.44.212.152]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b35ca308bdsm93742485a.83.2024.11.14.14.01.55 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 14 Nov 2024 14:01:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1731621718; x=1732226518; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PXb0xU9EUeq/o2lDkxhUbldwZ6kS44ZWhCyxS7PxJXE=; b=c63hHOxwTHLaumgEG/sCcY55cDhvcmRUXtwWq8mFZ2guXwN0rj72nLT5+AjvFo1DR6 liogt+vJ6QagPhRClVglr7TtOdFQt922ItIaziI/LWfSSWD8NC5o8qg+oiMYephmx/1e c/AFV3aA/dSnZAcMBureCsH8gNCQZEGnUG/8XOm2X6tRd0Pv24CcPQNLahoBhwGFUREX e21MxV8IE4EqgNBHXKJIQ9nWac5N3fsabPKPOhmuR06g/8ovnpJgSwMFose+BD8sPc5J voDnE5EWLtNBicPNUIYlenvYGXgpMccB3nmhAU735iTRd8vAuqfaJ5z2Sq88d3xl9Rgv TMAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731621718; x=1732226518; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PXb0xU9EUeq/o2lDkxhUbldwZ6kS44ZWhCyxS7PxJXE=; b=eMwpn8ws1q+XS69UvSxDQ62UqyzBPOtxchspxY03j7vjBvNhChHYIopSoJxgkvtxS7 VnWH50LSoOUUvmD81xAV/J8eIk1x1yN7GmAR8hfi8H9Z8REcGgmFL/vLCEhf1cTK8+50 thb9SYlJMQcDv25+EiaQDWtEss8FCbXu9JXMMct9hQWdbbxJknXEkX0FptTmAAJUlkRx M1Iwh6nD3JX1mW1AmsImMwOdBoWUd1jMQnEO8Xcvvd8EQrFN4DDgZYlNKByW3gp89D6U 8JBqhuCDyj99u4p+cQ6QYDQlGb/5/13Pal+X0K/N7Yieu8XO4hOB0bUhM3aCxwfgHxHn ZsaA== X-Forwarded-Encrypted: i=1; AJvYcCXC/VRSsbQbJo7Rv6UWEFfjQ8HD/QYhJyUNNs71b2PpF3ggbJWdpw20+B2kMf4gubkjlUjYAQ6prCBX@nongnu.org X-Gm-Message-State: AOJu0YxBAOC+zGKAs9QCnJ8OCnjdbSzl4GTSZ+okN9MdWPE7O0qse54n HDE5j8Rltwwcdwr5Anu8Wqe3kpSTfvpWXOWATN6wsLY82iYAvXmm1JXgk4chxHA= X-Google-Smtp-Source: AGHT+IFO9VfUPozhH419UUIWb1LRxPAAycLA7wFFCgRtEPRe9H6hvAZyTv+TzzpqlCOEIJuglaqLjw== X-Received: by 2002:a05:620a:1923:b0:7ac:b197:4037 with SMTP id af79cd13be357-7b361fd5530mr117640885a.18.1731621717886; Thu, 14 Nov 2024 14:01:57 -0800 (PST) From: Yichen Wang To: Peter Xu , Fabiano Rosas , "Dr. David Alan Gilbert" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eric Blake , Markus Armbruster , "Michael S. Tsirkin" , Cornelia Huck , qemu-devel@nongnu.org Cc: "Hao Xiang" , "Liu, Yuan1" , "Shivam Kumar" , "Ho-Ren (Jack) Chuang" , "Yichen Wang" , Bryan Zhang Subject: [PATCH v7 07/12] util/dsa: Implement DSA task asynchronous submission and wait for completion. Date: Thu, 14 Nov 2024 14:01:27 -0800 Message-Id: <20241114220132.27399-8-yichen.wang@bytedance.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241114220132.27399-1-yichen.wang@bytedance.com> References: <20241114220132.27399-1-yichen.wang@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::72a; envelope-from=yichen.wang@bytedance.com; helo=mail-qk1-x72a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1731621786022116600 Content-Type: text/plain; charset="utf-8" From: Hao Xiang * Add a DSA task completion callback. * DSA completion thread will call the tasks's completion callback on every task/batch task completion. * DSA submission path to wait for completion. * Implement CPU fallback if DSA is not able to complete the task. Signed-off-by: Hao Xiang Signed-off-by: Bryan Zhang Signed-off-by: Yichen Wang --- include/qemu/dsa.h | 14 +++++ util/dsa.c | 125 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 135 insertions(+), 4 deletions(-) diff --git a/include/qemu/dsa.h b/include/qemu/dsa.h index cb407b8b49..8284804a32 100644 --- a/include/qemu/dsa.h +++ b/include/qemu/dsa.h @@ -123,6 +123,20 @@ buffer_zero_batch_task_init(int batch_size); */ void buffer_zero_batch_task_destroy(QemuDsaBatchTask *task); =20 +/** + * @brief Performs buffer zero comparison on a DSA batch task synchronousl= y. + * + * @param batch_task A pointer to the batch task. + * @param buf An array of memory buffers. + * @param count The number of buffers in the array. + * @param len The buffer length. + * + * @return Zero if successful, otherwise non-zero. + */ +int +buffer_is_zero_dsa_batch_sync(QemuDsaBatchTask *batch_task, + const void **buf, size_t count, size_t len); + #else =20 typedef struct QemuDsaBatchTask {} QemuDsaBatchTask; diff --git a/util/dsa.c b/util/dsa.c index 408c163195..50f53ec24b 100644 --- a/util/dsa.c +++ b/util/dsa.c @@ -433,6 +433,42 @@ poll_completion(struct dsa_completion_record *completi= on, return 0; } =20 +/** + * @brief Helper function to use CPU to complete a single + * zero page checking task. + * + * @param completion A pointer to a DSA task completion record. + * @param descriptor A pointer to a DSA task descriptor. + * @param result A pointer to the result of a zero page checking. + */ +static void +task_cpu_fallback_int(struct dsa_completion_record *completion, + struct dsa_hw_desc *descriptor, bool *result) +{ + const uint8_t *buf; + size_t len; + + if (completion->status =3D=3D DSA_COMP_SUCCESS) { + return; + } + + /* + * DSA was able to partially complete the operation. Check the + * result. If we already know this is not a zero page, we can + * return now. + */ + if (completion->bytes_completed !=3D 0 && completion->result !=3D 0) { + *result =3D false; + return; + } + + /* Let's fallback to use CPU to complete it. */ + buf =3D (const uint8_t *)descriptor->src_addr; + len =3D descriptor->xfer_size; + *result =3D buffer_is_zero(buf + completion->bytes_completed, + len - completion->bytes_completed); +} + /** * @brief Complete a single DSA task in the batch task. * @@ -561,7 +597,7 @@ dsa_completion_loop(void *opaque) (QemuDsaCompletionThread *)opaque; QemuDsaBatchTask *batch_task; QemuDsaDeviceGroup *group =3D thread_context->group; - int ret; + int ret =3D 0; =20 rcu_register_thread(); =20 @@ -829,7 +865,6 @@ buffer_zero_batch_task_set(QemuDsaBatchTask *batch_task, * * @return int Zero if successful, otherwise an appropriate error code. */ -__attribute__((unused)) static int buffer_zero_dsa_async(QemuDsaBatchTask *task, const void *buf, size_t len) @@ -848,7 +883,6 @@ buffer_zero_dsa_async(QemuDsaBatchTask *task, * @param count The number of buffers. * @param len The buffer length. */ -__attribute__((unused)) static int buffer_zero_dsa_batch_async(QemuDsaBatchTask *batch_task, const void **buf, size_t count, size_t len) @@ -879,13 +913,61 @@ buffer_zero_dsa_completion(void *context) * * @param batch_task A pointer to the buffer zero comparison batch task. */ -__attribute__((unused)) static void buffer_zero_dsa_wait(QemuDsaBatchTask *batch_task) { qemu_sem_wait(&batch_task->sem_task_complete); } =20 +/** + * @brief Use CPU to complete the zero page checking task if DSA + * is not able to complete it. + * + * @param batch_task A pointer to the batch task. + */ +static void +buffer_zero_cpu_fallback(QemuDsaBatchTask *batch_task) +{ + if (batch_task->task_type =3D=3D QEMU_DSA_TASK) { + if (batch_task->completions[0].status =3D=3D DSA_COMP_SUCCESS) { + return; + } + task_cpu_fallback_int(&batch_task->completions[0], + &batch_task->descriptors[0], + &batch_task->results[0]); + } else if (batch_task->task_type =3D=3D QEMU_DSA_BATCH_TASK) { + struct dsa_completion_record *batch_completion =3D + &batch_task->batch_completion; + struct dsa_completion_record *completion; + uint8_t status; + bool *results =3D batch_task->results; + uint32_t count =3D batch_task->batch_descriptor.desc_count; + + /* DSA is able to complete the entire batch task. */ + if (batch_completion->status =3D=3D DSA_COMP_SUCCESS) { + assert(count =3D=3D batch_completion->bytes_completed); + return; + } + + /* + * DSA encounters some error and is not able to complete + * the entire batch task. Use CPU fallback. + */ + for (int i =3D 0; i < count; i++) { + + completion =3D &batch_task->completions[i]; + status =3D completion->status; + + assert(status =3D=3D DSA_COMP_SUCCESS || + status =3D=3D DSA_COMP_PAGE_FAULT_NOBOF); + + task_cpu_fallback_int(completion, + &batch_task->descriptors[i], + &results[i]); + } + } +} + /** * @brief Initializes a buffer zero comparison DSA task. * @@ -962,3 +1044,38 @@ buffer_zero_batch_task_destroy(QemuDsaBatchTask *task) qemu_sem_destroy(&task->sem_task_complete); qemu_vfree(task); } + +/** + * @brief Performs buffer zero comparison on a DSA batch task synchronousl= y. + * + * @param batch_task A pointer to the batch task. + * @param buf An array of memory buffers. + * @param count The number of buffers in the array. + * @param len The buffer length. + * + * @return Zero if successful, otherwise non-zero. + */ +int +buffer_is_zero_dsa_batch_sync(QemuDsaBatchTask *batch_task, + const void **buf, size_t count, size_t len) +{ + if (count <=3D 0 || count > batch_task->batch_size) { + return -1; + } + + assert(batch_task !=3D NULL); + assert(len !=3D 0); + assert(buf !=3D NULL); + + if (count =3D=3D 1) { + /* DSA doesn't take batch operation with only 1 task. */ + buffer_zero_dsa_async(batch_task, buf[0], len); + } else { + buffer_zero_dsa_batch_async(batch_task, buf, count, len); + } + + buffer_zero_dsa_wait(batch_task); + buffer_zero_cpu_fallback(batch_task); + + return 0; +} --=20 Yichen Wang From nobody Sat Nov 23 17:14:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1731621825; cv=none; d=zohomail.com; s=zohoarc; b=Qkj9OtFGi7/yrz+av9Osu2vTZJcgc58607N4b1w1Y8++ECM5hnBjCgnJMd3UO2nKh2S7tGbmvCQQxeSkE5gRlrIa4ae8VX+j4SMD2Ii6Zbcu2U5D7cYxBgP1ykSzw0qxNBhqh+W+EinZyLt611jJWeNq/iMm44GFx4aUd3jrGHw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731621825; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=mKamMVfAYEStZ//LZHWWiAwcDZtZMVRd0IMX0qbphsU=; b=NzW1AyJmHtpdP+3SWyfHkHVOzV9AiA/M5RFx0lFAzxzld11WAychlX3OzJMG9KzX41ONqp6G7f27/g8bkVb009HsupRXdSP0oVttqCXnYbY1fi3Ey1iGZfxgRETwmTIXcXsCJtx7d5T8bxxGkY9Lt15TSp4Np1d2Rn1hjjt09VA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1731621825346788.169834156822; Thu, 14 Nov 2024 14:03:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tBhul-0003Qe-0p; Thu, 14 Nov 2024 17:02:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tBhue-0003Q2-JU for qemu-devel@nongnu.org; Thu, 14 Nov 2024 17:02:05 -0500 Received: from mail-qk1-x72b.google.com ([2607:f8b0:4864:20::72b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tBhuc-0007ff-2t for qemu-devel@nongnu.org; Thu, 14 Nov 2024 17:02:04 -0500 Received: by mail-qk1-x72b.google.com with SMTP id af79cd13be357-7b148919e82so6585485a.0 for ; Thu, 14 Nov 2024 14:02:01 -0800 (PST) Received: from DY4X0N7X05.bytedance.net ([130.44.212.152]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b35ca308bdsm93742485a.83.2024.11.14.14.01.58 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 14 Nov 2024 14:02:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1731621721; x=1732226521; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mKamMVfAYEStZ//LZHWWiAwcDZtZMVRd0IMX0qbphsU=; b=B4qYGS69GJsJQVbxTN7y8FC3rr5T83JolAd+cohw/QC/I4Noqq9MYKl6NrqCVaGjR0 Bski4FPaC5lNIVRZoak78TAbxfEyTzMYTvAbl+QGgtsF1+4jQ7O5e1l002id17+z0HMN S8m76ZUB/hq2+r/eDEbGfCkEcGtKHTNuTASWv4CE6vYK7a3EE1ER2FQa8GY4fkUwGZ6g Y8bw7WV3jPYv24xKLHquTsdtlpjs2jo+SJmGVDfOcUUqHmOROwr5CG1kzzz0ruJ8+doY xunRX2gP5iAkSxvLJ7uPQYCRdD15K4cissVF32zAD3eLkKNUlHP9GUHjVHiBzO5SBZWr fOBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731621721; x=1732226521; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mKamMVfAYEStZ//LZHWWiAwcDZtZMVRd0IMX0qbphsU=; b=H8COI9iwQ6S8sD9pv7ZDdRGOPsqWuHqz0z1+swhi/UgGBJ98aGchZ38ovhfO0B8y7w XsLVIoMueDsn++VQZXfxonzFaWIkTCFFbTZVcWo29PIim/4qYWvSa9t8ZCWj7w+E26Hm 8rq+lnIep4m+BCaypufInbtX/dAzVTxpTWy2t4ValGBfz7kJh4q3dREj/0zEx8PtM/t/ dddudIvG6gLYooTVaVLKjz/JvyBgcfaI6C+caMTHbYcR2riK890AGRsm5gPwgJ78zejH 1zuxXgWkYwmos29RDtISGQDHnH/asISyn2gn6N14PySEKJIEomvCT6O925P9PUd0pXcA b4CA== X-Forwarded-Encrypted: i=1; AJvYcCXgNx6IYIpbUtE5tZRrIB+XZHmnZq4mMLBXdr3ma7L8x5+h08Wf+box0OtZ5g1X7k1JtZnrArgljYB6@nongnu.org X-Gm-Message-State: AOJu0YyeYIfy7PoVhjw3HvB9bZy/aqpdo8MqQmS357JcOm89HwVvf+xr 1LMSMQ19q+E+h+5/mRGNa4X7qfT9w/4jHmFOtaFYhphwORiqMgzr/RtRUyvFit8= X-Google-Smtp-Source: AGHT+IHSe9Mzcgu4+AaEwcNdD7+Dt8lHnPvUC3jqOc0g0uWA+uGjS4Rk3SNDz5C8CRPG5pQRudah3Q== X-Received: by 2002:a05:620a:3f85:b0:7a9:aae5:331 with SMTP id af79cd13be357-7b3622b96a4mr81000585a.21.1731621720572; Thu, 14 Nov 2024 14:02:00 -0800 (PST) From: Yichen Wang To: Peter Xu , Fabiano Rosas , "Dr. David Alan Gilbert" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eric Blake , Markus Armbruster , "Michael S. Tsirkin" , Cornelia Huck , qemu-devel@nongnu.org Cc: "Hao Xiang" , "Liu, Yuan1" , "Shivam Kumar" , "Ho-Ren (Jack) Chuang" , "Yichen Wang" Subject: [PATCH v7 08/12] migration/multifd: Add new migration option for multifd DSA offloading. Date: Thu, 14 Nov 2024 14:01:28 -0800 Message-Id: <20241114220132.27399-9-yichen.wang@bytedance.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241114220132.27399-1-yichen.wang@bytedance.com> References: <20241114220132.27399-1-yichen.wang@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::72b; envelope-from=yichen.wang@bytedance.com; helo=mail-qk1-x72b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1731621826135116600 Content-Type: text/plain; charset="utf-8" From: Hao Xiang Intel DSA offloading is an optional feature that turns on if proper hardware and software stack is available. To turn on DSA offloading in multifd live migration by setting: zero-page-detection=3Ddsa-accel dsa-accel-path=3D"dsa: dsa:[dsa_dev_path2] ..." This feature is turned off by default. Signed-off-by: Hao Xiang Signed-off-by: Yichen Wang Acked-by: Dr. David Alan Gilbert --- hmp-commands.hx | 2 +- include/qemu/dsa.h | 13 +++++++++++++ migration/migration-hmp-cmds.c | 19 ++++++++++++++++++- migration/options.c | 30 ++++++++++++++++++++++++++++++ migration/options.h | 1 + qapi/migration.json | 32 ++++++++++++++++++++++++++++---- util/dsa.c | 31 +++++++++++++++++++++++++++++++ 7 files changed, 122 insertions(+), 6 deletions(-) diff --git a/hmp-commands.hx b/hmp-commands.hx index 06746f0afc..0e04eac7c7 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1009,7 +1009,7 @@ ERST =20 { .name =3D "migrate_set_parameter", - .args_type =3D "parameter:s,value:s", + .args_type =3D "parameter:s,value:S", .params =3D "parameter value", .help =3D "Set the parameter for migration", .cmd =3D hmp_migrate_set_parameter, diff --git a/include/qemu/dsa.h b/include/qemu/dsa.h index 8284804a32..258860bd20 100644 --- a/include/qemu/dsa.h +++ b/include/qemu/dsa.h @@ -100,6 +100,13 @@ void qemu_dsa_stop(void); */ void qemu_dsa_cleanup(void); =20 +/** + * @brief Check if DSA is supported. + * + * @return True if DSA is supported, otherwise false. + */ +bool qemu_dsa_is_supported(void); + /** * @brief Check if DSA is running. * @@ -141,6 +148,12 @@ buffer_is_zero_dsa_batch_sync(QemuDsaBatchTask *batch_= task, =20 typedef struct QemuDsaBatchTask {} QemuDsaBatchTask; =20 +static inline bool qemu_dsa_is_supported(void) +{ + return false; +} + + static inline bool qemu_dsa_is_running(void) { return false; diff --git a/migration/migration-hmp-cmds.c b/migration/migration-hmp-cmds.c index 20d1a6e219..01c528b80a 100644 --- a/migration/migration-hmp-cmds.c +++ b/migration/migration-hmp-cmds.c @@ -312,7 +312,16 @@ void hmp_info_migrate_parameters(Monitor *mon, const Q= Dict *qdict) monitor_printf(mon, "%s: '%s'\n", MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ), params->tls_authz); - + if (params->has_accel_path) { + strList *accel_path =3D params->accel_path; + monitor_printf(mon, "%s:", + MigrationParameter_str(MIGRATION_PARAMETER_ACCEL_PATH)); + while (accel_path) { + monitor_printf(mon, " '%s'", accel_path->value); + accel_path =3D accel_path->next; + } + monitor_printf(mon, "\n"); + } if (params->has_block_bitmap_mapping) { const BitmapMigrationNodeAliasList *bmnal; =20 @@ -563,6 +572,14 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDi= ct *qdict) p->has_x_checkpoint_delay =3D true; visit_type_uint32(v, param, &p->x_checkpoint_delay, &err); break; + case MIGRATION_PARAMETER_ACCEL_PATH: + p->has_accel_path =3D true; + g_autofree char **strv =3D g_strsplit(valuestr ? : "", " ", -1); + strList **tail =3D &p->accel_path; + for (int i =3D 0; strv[i]; i++) { + QAPI_LIST_APPEND(tail, strv[i]); + } + break; case MIGRATION_PARAMETER_MULTIFD_CHANNELS: p->has_multifd_channels =3D true; visit_type_uint8(v, param, &p->multifd_channels, &err); diff --git a/migration/options.c b/migration/options.c index ad8d6989a8..ca89fdc4f4 100644 --- a/migration/options.c +++ b/migration/options.c @@ -13,6 +13,7 @@ =20 #include "qemu/osdep.h" #include "qemu/error-report.h" +#include "qemu/dsa.h" #include "exec/target_page.h" #include "qapi/clone-visitor.h" #include "qapi/error.h" @@ -809,6 +810,13 @@ const char *migrate_tls_creds(void) return s->parameters.tls_creds; } =20 +const strList *migrate_accel_path(void) +{ + MigrationState *s =3D migrate_get_current(); + + return s->parameters.accel_path; +} + const char *migrate_tls_hostname(void) { MigrationState *s =3D migrate_get_current(); @@ -922,6 +930,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error= **errp) params->zero_page_detection =3D s->parameters.zero_page_detection; params->has_direct_io =3D true; params->direct_io =3D s->parameters.direct_io; + params->has_accel_path =3D true; + params->accel_path =3D QAPI_CLONE(strList, s->parameters.accel_path); =20 return params; } @@ -930,6 +940,7 @@ void migrate_params_init(MigrationParameters *params) { params->tls_hostname =3D g_strdup(""); params->tls_creds =3D g_strdup(""); + params->accel_path =3D NULL; =20 /* Set has_* up only for parameter checks */ params->has_throttle_trigger_threshold =3D true; @@ -1142,6 +1153,14 @@ bool migrate_params_check(MigrationParameters *param= s, Error **errp) return false; } =20 + if (params->has_zero_page_detection && + params->zero_page_detection =3D=3D ZERO_PAGE_DETECTION_DSA_ACCEL) { + if (!qemu_dsa_is_supported()) { + error_setg(errp, "DSA acceleration is not supported."); + return false; + } + } + return true; } =20 @@ -1255,6 +1274,11 @@ static void migrate_params_test_apply(MigrateSetPara= meters *params, if (params->has_direct_io) { dest->direct_io =3D params->direct_io; } + + if (params->has_accel_path) { + dest->has_accel_path =3D true; + dest->accel_path =3D params->accel_path; + } } =20 static void migrate_params_apply(MigrateSetParameters *params, Error **err= p) @@ -1387,6 +1411,12 @@ static void migrate_params_apply(MigrateSetParameter= s *params, Error **errp) if (params->has_direct_io) { s->parameters.direct_io =3D params->direct_io; } + if (params->has_accel_path) { + qapi_free_strList(s->parameters.accel_path); + s->parameters.has_accel_path =3D true; + s->parameters.accel_path =3D + QAPI_CLONE(strList, params->accel_path); + } } =20 void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp) diff --git a/migration/options.h b/migration/options.h index 79084eed0d..3d1e91dc52 100644 --- a/migration/options.h +++ b/migration/options.h @@ -84,6 +84,7 @@ const char *migrate_tls_creds(void); const char *migrate_tls_hostname(void); uint64_t migrate_xbzrle_cache_size(void); ZeroPageDetection migrate_zero_page_detection(void); +const strList *migrate_accel_path(void); =20 /* parameters helpers */ =20 diff --git a/qapi/migration.json b/qapi/migration.json index a605dc26db..389776065d 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -629,10 +629,14 @@ # multifd migration is enabled, else in the main migration thread # as for @legacy. # +# @dsa-accel: Perform zero page checking with the DSA accelerator +# offloading in multifd sender thread if multifd migration is +# enabled, else in the main migration thread as for @legacy. +# # Since: 9.0 ## { 'enum': 'ZeroPageDetection', - 'data': [ 'none', 'legacy', 'multifd' ] } + 'data': [ 'none', 'legacy', 'multifd', 'dsa-accel' ] } =20 ## # @BitmapMigrationBitmapAliasTransform: @@ -840,6 +844,12 @@ # See description in @ZeroPageDetection. Default is 'multifd'. # (since 9.0) # +# @accel-path: If enabled, specify the accelerator paths that to be +# used in QEMU. For example, enable DSA accelerator for zero page +# detection offloading by setting the @zero-page-detection to +# dsa-accel, and defines the accel-path to "dsa:". +# This parameter is default to an empty list. (Since 9.2) +# # @direct-io: Open migration files with O_DIRECT when possible. This # only has effect if the @mapped-ram capability is enabled. # (Since 9.1) @@ -858,7 +868,7 @@ 'cpu-throttle-initial', 'cpu-throttle-increment', 'cpu-throttle-tailslow', 'tls-creds', 'tls-hostname', 'tls-authz', 'max-bandwidth', - 'avail-switchover-bandwidth', 'downtime-limit', + 'avail-switchover-bandwidth', 'downtime-limit', 'accel-path', { 'name': 'x-checkpoint-delay', 'features': [ 'unstable' ] }, 'multifd-channels', 'xbzrle-cache-size', 'max-postcopy-bandwidth', @@ -1021,6 +1031,12 @@ # See description in @ZeroPageDetection. Default is 'multifd'. # (since 9.0) # +# @accel-path: If enabled, specify the accelerator paths that to be +# used in QEMU. For example, enable DSA accelerator for zero page +# detection offloading by setting the @zero-page-detection to +# dsa-accel, and defines the accel-path to "dsa:". +# This parameter is default to an empty list. (Since 9.2) +# # @direct-io: Open migration files with O_DIRECT when possible. This # only has effect if the @mapped-ram capability is enabled. # (Since 9.1) @@ -1066,7 +1082,8 @@ '*vcpu-dirty-limit': 'uint64', '*mode': 'MigMode', '*zero-page-detection': 'ZeroPageDetection', - '*direct-io': 'bool' } } + '*direct-io': 'bool', + '*accel-path': [ 'str' ] } } =20 ## # @migrate-set-parameters: @@ -1231,6 +1248,12 @@ # See description in @ZeroPageDetection. Default is 'multifd'. # (since 9.0) # +# @accel-path: If enabled, specify the accelerator paths that to be +# used in QEMU. For example, enable DSA accelerator for zero page +# detection offloading by setting the @zero-page-detection to +# dsa-accel, and defines the accel-path to "dsa:". +# This parameter is default to an empty list. (Since 9.2) +# # @direct-io: Open migration files with O_DIRECT when possible. This # only has effect if the @mapped-ram capability is enabled. # (Since 9.1) @@ -1273,7 +1296,8 @@ '*vcpu-dirty-limit': 'uint64', '*mode': 'MigMode', '*zero-page-detection': 'ZeroPageDetection', - '*direct-io': 'bool' } } + '*direct-io': 'bool', + '*accel-path': [ 'str' ] } } =20 ## # @query-migrate-parameters: diff --git a/util/dsa.c b/util/dsa.c index 50f53ec24b..18ed36e354 100644 --- a/util/dsa.c +++ b/util/dsa.c @@ -23,6 +23,7 @@ #include "qemu/bswap.h" #include "qemu/error-report.h" #include "qemu/rcu.h" +#include =20 #pragma GCC push_options #pragma GCC target("enqcmd") @@ -689,6 +690,36 @@ static void dsa_completion_thread_stop(void *opaque) qemu_sem_destroy(&thread_context->sem_init_done); } =20 +/** + * @brief Check if DSA is supported. + * + * @return True if DSA is supported, otherwise false. + */ +bool qemu_dsa_is_supported(void) +{ + /* + * movdir64b is indicated by bit 28 of ecx in CPUID leaf 7, subleaf 0. + * enqcmd is indicated by bit 29 of ecx in CPUID leaf 7, subleaf 0. + * Doc: https://cdrdv2-public.intel.com/819680/architecture-instructio= n-\ + * set-extensions-programming-reference.pdf + */ + uint32_t eax, ebx, ecx, edx; + bool movedirb_enabled; + bool enqcmd_enabled; + + __get_cpuid_count(7, 0, &eax, &ebx, &ecx, &edx); + movedirb_enabled =3D (ecx >> 28) & 0x1; + if (!movedirb_enabled) { + return false; + } + enqcmd_enabled =3D (ecx >> 29) & 0x1; + if (!enqcmd_enabled) { + return false; + } + + return true; +} + /** * @brief Check if DSA is running. * --=20 Yichen Wang From nobody Sat Nov 23 17:14:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1731621877; cv=none; d=zohomail.com; s=zohoarc; b=g79nRKmEpnut2u3jb408JDLHrzx4HYL59UFPa8aCpe9ljui63Q3Y/GPlCmzsWEHx636kRs4F26dMXrI4LE0ksGSVQmvBX/ZTmqE6UjRXbtVkWo3uA3CiS3uPNIMoFSIyeBCyA5NrEhE03be5PfaDT5wLgnmbceyg0H/xL5/awf4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731621877; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=QmhqRW3U1pl791t5RppIlNfZ1KlFfiKhHBzyCjfOoKA=; b=UeLk0AtH3+uilvgHUgFm3vFCqwQYRxPnMpbp2apjDpcx8WnDEia/L6KziR8rMEWvXcfWVk3jp7IfSogXSHeGLeokYOiLO4mswRTOvcBOWxkdQscQFjmu2OrjY1wMSI1oN8Sl8mNo07fqCL/byrbz3y1ZrlK3HLjanokOoWFhfbg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1731621877600994.4219418821392; Thu, 14 Nov 2024 14:04:37 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tBhun-0003Qv-An; Thu, 14 Nov 2024 17:02:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tBhug-0003QK-2f for qemu-devel@nongnu.org; Thu, 14 Nov 2024 17:02:07 -0500 Received: from mail-qk1-x72f.google.com ([2607:f8b0:4864:20::72f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tBhue-0007fu-1D for qemu-devel@nongnu.org; Thu, 14 Nov 2024 17:02:05 -0500 Received: by mail-qk1-x72f.google.com with SMTP id af79cd13be357-7b1511697a5so62603585a.2 for ; Thu, 14 Nov 2024 14:02:03 -0800 (PST) Received: from DY4X0N7X05.bytedance.net ([130.44.212.152]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b35ca308bdsm93742485a.83.2024.11.14.14.02.01 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 14 Nov 2024 14:02:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1731621723; x=1732226523; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QmhqRW3U1pl791t5RppIlNfZ1KlFfiKhHBzyCjfOoKA=; b=LAF2ffWKkSbCHldSCwZ3gRzBlDSdPmP2azJLV0TXU8tJzfBDpanNQFyvhUUDr4NZnY 0vSsNTQ6pVvC787MEldCdGTAJvgwghif/e1+mRzNnJ3lU6pcMr2QWfrLEfzJeIqJcUqH 6LcdZzPYVeTph7VyS7VAcJGfkG1dkCVbBOD0Pdwwz3vbL2pTqe2LgtRPOD/SpivU9kco 7/aDHMlDVhAb6011EZv/ho5JNuqDanvG9PB+b8FRlzpAQLQxHAI0VqFYQgT8y+IsGQkV R/qduFBNoR/1fox83HdLpZ0x9uNMnn4mOeztCiEx9zIqWdqTYpqGgNIiNAVP/jLTIdXB Ftaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731621723; x=1732226523; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QmhqRW3U1pl791t5RppIlNfZ1KlFfiKhHBzyCjfOoKA=; b=NEVHhVQPRaCgqA5nSYuMiYczQcIT3O1WJ/HrINIjZq22xo70JzY1XKnddpC3SmmPkw u3GfG72mMfMRPslwVtyN+g4bkUUqeUcYu512ofartPekt6wZdJ+CBL5fqhCPFAk4jhUM alAM3SL3iHOa5D6ci4Mx/QVQKt56JOEUjZWURazknbQS/BBqJTCq5joC2yevfpw/l9+c ynGmZpyd5omIqdbtd7XuIB9AQXD0ZAN29ErzswsQPSsZhXT5INX8wXfPjRtbliYH50Zo ZpAAIoEgvqnI29so3aljgnryvkFNsKcC0eWuztbSO5Iu6PWNSgDFS6LqNfuUt+QHi1BO N7QQ== X-Forwarded-Encrypted: i=1; AJvYcCXKzKybjN3SpRFGHRqG9hmayollQNsavG1xWDypXo+6IsxwcbkmLRUtRO/u9J+evbPWzdUvf8Rrb9Lw@nongnu.org X-Gm-Message-State: AOJu0YxgjX1/dJl68XmxLFm1uylgwlSpxomjT2ZqchEv+eT3Pg2jeQnN Z9o4fUAP/PEuVAVJz+uzVcGb10AC9Bl2oGNm1tJd8du8lgkWphaOlSDsHjbAKWU= X-Google-Smtp-Source: AGHT+IE2XdE2iGSgiLUUq6q++iS8Fb/nyQadLBsRXhBgrz0WxrUY0o0CvKQdXb9Nha806+U2rqTJVQ== X-Received: by 2002:a05:620a:4493:b0:7ae:d2cf:aef4 with SMTP id af79cd13be357-7b3622d1e10mr58746385a.29.1731621723099; Thu, 14 Nov 2024 14:02:03 -0800 (PST) From: Yichen Wang To: Peter Xu , Fabiano Rosas , "Dr. David Alan Gilbert" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eric Blake , Markus Armbruster , "Michael S. Tsirkin" , Cornelia Huck , qemu-devel@nongnu.org Cc: "Hao Xiang" , "Liu, Yuan1" , "Shivam Kumar" , "Ho-Ren (Jack) Chuang" , "Yichen Wang" Subject: [PATCH v7 09/12] migration/multifd: Enable DSA offloading in multifd sender path. Date: Thu, 14 Nov 2024 14:01:29 -0800 Message-Id: <20241114220132.27399-10-yichen.wang@bytedance.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241114220132.27399-1-yichen.wang@bytedance.com> References: <20241114220132.27399-1-yichen.wang@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::72f; envelope-from=yichen.wang@bytedance.com; helo=mail-qk1-x72f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1731621878565116600 Content-Type: text/plain; charset="utf-8" From: Hao Xiang Multifd sender path gets an array of pages queued by the migration thread. It performs zero page checking on every page in the array. The pages are classfied as either a zero page or a normal page. This change uses Intel DSA to offload the zero page checking from CPU to the DSA accelerator. The sender thread submits a batch of pages to DSA hardware and waits for the DSA completion thread to signal for work completion. Signed-off-by: Hao Xiang Signed-off-by: Yichen Wang --- migration/multifd-zero-page.c | 129 ++++++++++++++++++++++++++++++---- migration/multifd.c | 29 +++++++- migration/multifd.h | 5 ++ 3 files changed, 147 insertions(+), 16 deletions(-) diff --git a/migration/multifd-zero-page.c b/migration/multifd-zero-page.c index f1e988a959..639aed9f6b 100644 --- a/migration/multifd-zero-page.c +++ b/migration/multifd-zero-page.c @@ -21,7 +21,9 @@ =20 static bool multifd_zero_page_enabled(void) { - return migrate_zero_page_detection() =3D=3D ZERO_PAGE_DETECTION_MULTIF= D; + ZeroPageDetection curMethod =3D migrate_zero_page_detection(); + return (curMethod =3D=3D ZERO_PAGE_DETECTION_MULTIFD || + curMethod =3D=3D ZERO_PAGE_DETECTION_DSA_ACCEL); } =20 static void swap_page_offset(ram_addr_t *pages_offset, int a, int b) @@ -37,26 +39,49 @@ static void swap_page_offset(ram_addr_t *pages_offset, = int a, int b) pages_offset[b] =3D temp; } =20 +#ifdef CONFIG_DSA_OPT + +static void swap_result(bool *results, int a, int b) +{ + bool temp; + + if (a =3D=3D b) { + return; + } + + temp =3D results[a]; + results[a] =3D results[b]; + results[b] =3D temp; +} + /** - * multifd_send_zero_page_detect: Perform zero page detection on all pages. + * zero_page_detect_dsa: Perform zero page detection using + * Intel Data Streaming Accelerator (DSA). * - * Sorts normal pages before zero pages in p->pages->offset and updates - * p->pages->normal_num. + * Sorts normal pages before zero pages in pages->offset and updates + * pages->normal_num. * * @param p A pointer to the send params. */ -void multifd_send_zero_page_detect(MultiFDSendParams *p) +static void zero_page_detect_dsa(MultiFDSendParams *p) { MultiFDPages_t *pages =3D &p->data->u.ram; RAMBlock *rb =3D pages->block; - int i =3D 0; - int j =3D pages->num - 1; + bool *results =3D p->dsa_batch_task->results; =20 - if (!multifd_zero_page_enabled()) { - pages->normal_num =3D pages->num; - goto out; + for (int i =3D 0; i < pages->num; i++) { + p->dsa_batch_task->addr[i] =3D + (ram_addr_t)(rb->host + pages->offset[i]); } =20 + buffer_is_zero_dsa_batch_sync(p->dsa_batch_task, + (const void **)p->dsa_batch_task->addr, + pages->num, + multifd_ram_page_size()); + + int i =3D 0; + int j =3D pages->num - 1; + /* * Sort the page offset array by moving all normal pages to * the left and all zero pages to the right of the array. @@ -64,23 +89,39 @@ void multifd_send_zero_page_detect(MultiFDSendParams *p) while (i <=3D j) { uint64_t offset =3D pages->offset[i]; =20 - if (!buffer_is_zero(rb->host + offset, multifd_ram_page_size())) { + if (!results[i]) { i++; continue; } =20 + swap_result(results, i, j); swap_page_offset(pages->offset, i, j); ram_release_page(rb->idstr, offset); j--; } =20 pages->normal_num =3D i; +} =20 -out: - stat64_add(&mig_stats.normal_pages, pages->normal_num); - stat64_add(&mig_stats.zero_pages, pages->num - pages->normal_num); +void multifd_dsa_cleanup(void) +{ + qemu_dsa_cleanup(); +} + +#else + +static void zero_page_detect_dsa(MultiFDSendParams *p) +{ + g_assert_not_reached(); +} + +void multifd_dsa_cleanup(void) +{ + return ; } =20 +#endif + void multifd_recv_zero_page_process(MultiFDRecvParams *p) { for (int i =3D 0; i < p->zero_num; i++) { @@ -92,3 +133,63 @@ void multifd_recv_zero_page_process(MultiFDRecvParams *= p) } } } + +/** + * zero_page_detect_cpu: Perform zero page detection using CPU. + * + * Sorts normal pages before zero pages in p->pages->offset and updates + * p->pages->normal_num. + * + * @param p A pointer to the send params. + */ +static void zero_page_detect_cpu(MultiFDSendParams *p) +{ + MultiFDPages_t *pages =3D &p->data->u.ram; + RAMBlock *rb =3D pages->block; + int i =3D 0; + int j =3D pages->num - 1; + + /* + * Sort the page offset array by moving all normal pages to + * the left and all zero pages to the right of the array. + */ + while (i <=3D j) { + uint64_t offset =3D pages->offset[i]; + + if (!buffer_is_zero(rb->host + offset, multifd_ram_page_size())) { + i++; + continue; + } + + swap_page_offset(pages->offset, i, j); + ram_release_page(rb->idstr, offset); + j--; + } + + pages->normal_num =3D i; +} + +/** + * multifd_send_zero_page_detect: Perform zero page detection on all pages. + * + * @param p A pointer to the send params. + */ +void multifd_send_zero_page_detect(MultiFDSendParams *p) +{ + MultiFDPages_t *pages =3D &p->data->u.ram; + + if (!multifd_zero_page_enabled()) { + pages->normal_num =3D pages->num; + goto out; + } + + if (qemu_dsa_is_running()) { + zero_page_detect_dsa(p); + } else { + zero_page_detect_cpu(p); + } + +out: + stat64_add(&mig_stats.normal_pages, pages->normal_num); + stat64_add(&mig_stats.zero_pages, pages->num - pages->normal_num); +} diff --git a/migration/multifd.c b/migration/multifd.c index 4374e14a96..689acceff2 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -13,6 +13,7 @@ #include "qemu/osdep.h" #include "qemu/cutils.h" #include "qemu/rcu.h" +#include "qemu/dsa.h" #include "exec/target_page.h" #include "sysemu/sysemu.h" #include "exec/ramblock.h" @@ -462,6 +463,8 @@ static bool multifd_send_cleanup_channel(MultiFDSendPar= ams *p, Error **errp) p->name =3D NULL; g_free(p->data); p->data =3D NULL; + buffer_zero_batch_task_destroy(p->dsa_batch_task); + p->dsa_batch_task =3D NULL; p->packet_len =3D 0; g_free(p->packet); p->packet =3D NULL; @@ -493,6 +496,8 @@ void multifd_send_shutdown(void) =20 multifd_send_terminate_threads(); =20 + multifd_dsa_cleanup(); + for (i =3D 0; i < migrate_multifd_channels(); i++) { MultiFDSendParams *p =3D &multifd_send_state->params[i]; Error *local_err =3D NULL; @@ -814,11 +819,31 @@ bool multifd_send_setup(void) uint32_t page_count =3D multifd_ram_page_count(); bool use_packets =3D multifd_use_packets(); uint8_t i; + Error *local_err =3D NULL; =20 if (!migrate_multifd()) { return true; } =20 + if (s && + s->parameters.zero_page_detection =3D=3D ZERO_PAGE_DETECTION_DSA_A= CCEL) { + // Populate the dsa device path from accel-path + const strList *accel_path =3D migrate_accel_path(); + g_autofree strList *dsa_parameter =3D g_malloc0(sizeof(strList)); + strList **tail =3D &dsa_parameter; + while (accel_path) { + if (strncmp(accel_path->value, "dsa:", 4) =3D=3D 0) { + QAPI_LIST_APPEND(tail, &accel_path->value[4]); + } + accel_path =3D accel_path->next; + } + if (qemu_dsa_init(dsa_parameter, &local_err)) { + ret =3D -1; + } else { + qemu_dsa_start(); + } + } + thread_count =3D migrate_multifd_channels(); multifd_send_state =3D g_malloc0(sizeof(*multifd_send_state)); multifd_send_state->params =3D g_new0(MultiFDSendParams, thread_count); @@ -829,12 +854,12 @@ bool multifd_send_setup(void) =20 for (i =3D 0; i < thread_count; i++) { MultiFDSendParams *p =3D &multifd_send_state->params[i]; - Error *local_err =3D NULL; =20 qemu_sem_init(&p->sem, 0); qemu_sem_init(&p->sem_sync, 0); p->id =3D i; p->data =3D multifd_send_data_alloc(); + p->dsa_batch_task =3D buffer_zero_batch_task_init(page_count); =20 if (use_packets) { p->packet_len =3D sizeof(MultiFDPacket_t) @@ -865,7 +890,6 @@ bool multifd_send_setup(void) =20 for (i =3D 0; i < thread_count; i++) { MultiFDSendParams *p =3D &multifd_send_state->params[i]; - Error *local_err =3D NULL; =20 ret =3D multifd_send_state->ops->send_setup(p, &local_err); if (ret) { @@ -1047,6 +1071,7 @@ void multifd_recv_cleanup(void) qemu_thread_join(&p->thread); } } + multifd_dsa_cleanup(); for (i =3D 0; i < migrate_multifd_channels(); i++) { multifd_recv_cleanup_channel(&multifd_recv_state->params[i]); } diff --git a/migration/multifd.h b/migration/multifd.h index 50d58c0c9c..e293ddbc1d 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -15,6 +15,7 @@ =20 #include "exec/target_page.h" #include "ram.h" +#include "qemu/dsa.h" =20 typedef struct MultiFDRecvData MultiFDRecvData; typedef struct MultiFDSendData MultiFDSendData; @@ -155,6 +156,9 @@ typedef struct { bool pending_sync; MultiFDSendData *data; =20 + /* Zero page checking batch task */ + QemuDsaBatchTask *dsa_batch_task; + /* thread local variables. No locking required */ =20 /* pointer to the packet */ @@ -313,6 +317,7 @@ void multifd_send_fill_packet(MultiFDSendParams *p); bool multifd_send_prepare_common(MultiFDSendParams *p); void multifd_send_zero_page_detect(MultiFDSendParams *p); void multifd_recv_zero_page_process(MultiFDRecvParams *p); +void multifd_dsa_cleanup(void); =20 static inline void multifd_send_prepare_header(MultiFDSendParams *p) { --=20 Yichen Wang From nobody Sat Nov 23 17:14:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1731621877; cv=none; d=zohomail.com; s=zohoarc; b=USfsa9HOV2jAp7gA2hDZTNfwOImfFai5aLOKWf0ldfzDkXdy2/SB0q2xZ29DF0eo+aa4k3TObiergEm49urQuM2sfHKC9ijivzt2WTV7P7WEx0Lby5uHmVj6fngvf2ZY5dKC1341V5YBsKLgyFDJT+rFu6PydyUFLWrcEaBugB8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731621877; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=QhcJa+cHhe6ao2Bt0/MyVwDuA8e0xe0uuQoaXDZtjb0=; b=VYZ83wRz9VDHZOTp7bHTcLKUYsY51DF5C1Ll6zXcd+Jq5/UOFMG+0G521rilQ01vVeHuXV5EMrapK1jhfB4Ha6cPslnXeiX535CZRcH73sCFCe5M8D4cQiNepCZsFlzHMG7/FeAJ8Y4c6MqUVO69VwBYWZLrJkvtWLFbonsyytQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1731621877230957.4325606547591; Thu, 14 Nov 2024 14:04:37 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tBhuv-0003Ss-8i; Thu, 14 Nov 2024 17:02:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tBhuj-0003Qb-5O for qemu-devel@nongnu.org; Thu, 14 Nov 2024 17:02:09 -0500 Received: from mail-qk1-x735.google.com ([2607:f8b0:4864:20::735]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tBhug-0007gY-S4 for qemu-devel@nongnu.org; Thu, 14 Nov 2024 17:02:08 -0500 Received: by mail-qk1-x735.google.com with SMTP id af79cd13be357-7b15d7b7a32so70987885a.1 for ; Thu, 14 Nov 2024 14:02:06 -0800 (PST) Received: from DY4X0N7X05.bytedance.net ([130.44.212.152]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b35ca308bdsm93742485a.83.2024.11.14.14.02.03 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 14 Nov 2024 14:02:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1731621726; x=1732226526; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QhcJa+cHhe6ao2Bt0/MyVwDuA8e0xe0uuQoaXDZtjb0=; b=Kjmqv/YtT8K9OEfrLZh8TWQ0uw5D1YQ38Ofn+ZkI514bBdAryHK+MopkA2sauz1eRD /LVCzwoSS8srsiFMfq7uBpVeT62MOPYD5xIlPuMaLNmhkLh772m8uxFyPBP23p90cudJ 9BpxwDbVSegPzOWYLEJl4vR85SsG+5j66l4pdOMs2+p5sf4f2MLrULhIE7YpUNfPV4dA WRG9NCiNwai6nw+X21vg9gpCo/NEksj0OfzXQh+YLRuWgujjyAF1D8RMfxw1r8O6e9lT YlqHIwfro2eZzNVPDxLoa5oQANgvXY3a+Z6U1Ipa6uiR5iYEB+2+fdc+q1/dqjQHx+/7 3xXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731621726; x=1732226526; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QhcJa+cHhe6ao2Bt0/MyVwDuA8e0xe0uuQoaXDZtjb0=; b=JbJK2Ecb18IcfEJFQGgEd8izY2ogt9vQq7P2VG3yBkevas61+63j2Aj5EjRwkyQH7D mQqr0Pilmnibgz7agBgO7wBSJWjraQqJIHYJoenh8fzV0fWfKZoX0t9VskKGw+2IJqpd RA7/QwX71MSYxffjh5WAJ817h6REOZXXljKOE467zriDdvxR8J7C7UokS7D5FPcUfi6/ KKRsULNmiWeOGpCSYalbUnEp1Yvn1E4YbrHdGIMMTpZacYgTYXNsrGw3liUvFb9wzBID /bazJPioO3PedXbIc8zNaTmQqSswFpyzNNv4nPHAE9gvv/1mfvaealx+5Ouw1UaQISYj 96uw== X-Forwarded-Encrypted: i=1; AJvYcCVXySaiB+vBsRmi2WEP+CdLI+jPvVLVlEC8utfkGCVJbXZ/xn3wmk2hnQJ7cdaSGdWsx/Hai+35H8P5@nongnu.org X-Gm-Message-State: AOJu0YwsFD4W+yrTY7SfcbzH8YFnRcVjur5cG/Om/2SLp7Cq/qILb0RG ypf9XqVY5sJkIApE9NL7yDVhPAux616a9k5f88ij+gRKWBpNoshuXqsJyD1mnT8= X-Google-Smtp-Source: AGHT+IG8Osu4O0Qf6cch2QqQccsUCbzX9k72LIQ/bVUgnUwqxDN+O9q2qFg8Wue4Uqc/gWfd3ZRsRw== X-Received: by 2002:a05:620a:2402:b0:7a9:b250:d57b with SMTP id af79cd13be357-7b362298c94mr66572685a.5.1731621725643; Thu, 14 Nov 2024 14:02:05 -0800 (PST) From: Yichen Wang To: Peter Xu , Fabiano Rosas , "Dr. David Alan Gilbert" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eric Blake , Markus Armbruster , "Michael S. Tsirkin" , Cornelia Huck , qemu-devel@nongnu.org Cc: "Hao Xiang" , "Liu, Yuan1" , "Shivam Kumar" , "Ho-Ren (Jack) Chuang" , "Yichen Wang" , Bryan Zhang Subject: [PATCH v7 10/12] util/dsa: Add unit test coverage for Intel DSA task submission and completion. Date: Thu, 14 Nov 2024 14:01:30 -0800 Message-Id: <20241114220132.27399-11-yichen.wang@bytedance.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241114220132.27399-1-yichen.wang@bytedance.com> References: <20241114220132.27399-1-yichen.wang@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::735; envelope-from=yichen.wang@bytedance.com; helo=mail-qk1-x735.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1731621878373116600 Content-Type: text/plain; charset="utf-8" From: Hao Xiang * Test DSA start and stop path. * Test DSA configure and cleanup path. * Test DSA task submission and completion path. Signed-off-by: Bryan Zhang Signed-off-by: Hao Xiang Signed-off-by: Yichen Wang --- tests/unit/meson.build | 6 + tests/unit/test-dsa.c | 503 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 509 insertions(+) create mode 100644 tests/unit/test-dsa.c diff --git a/tests/unit/meson.build b/tests/unit/meson.build index d5248ae51d..394219e903 100644 --- a/tests/unit/meson.build +++ b/tests/unit/meson.build @@ -50,6 +50,12 @@ tests =3D { 'test-fifo': [], } =20 +if config_host_data.get('CONFIG_DSA_OPT') + tests +=3D { + 'test-dsa': [], + } +endif + if have_system or have_tools tests +=3D { 'test-qmp-event': [testqapi], diff --git a/tests/unit/test-dsa.c b/tests/unit/test-dsa.c new file mode 100644 index 0000000000..181a547528 --- /dev/null +++ b/tests/unit/test-dsa.c @@ -0,0 +1,503 @@ +/* + * Test DSA functions. + * + * Copyright (C) Bytedance Ltd. + * + * Authors: + * Hao Xiang + * Bryan Zhang + * Yichen Wang + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qemu/host-utils.h" + +#include "qemu/cutils.h" +#include "qemu/memalign.h" +#include "qemu/dsa.h" + +/* + * TODO Communicate that DSA must be configured to support this batch size. + * TODO Alternatively, poke the DSA device to figure out batch size. + */ +#define batch_size 128 +#define page_size 4096 + +#define oversized_batch_size (batch_size + 1) +#define num_devices 2 +#define max_buffer_size (64 * 1024) + +/* TODO Make these not-hardcoded. */ +static const strList path1[] =3D { + {.value =3D (char *)"/dev/dsa/wq4.0", .next =3D NULL} +}; +static const strList path2[] =3D { + {.value =3D (char *)"/dev/dsa/wq4.0", .next =3D (strList*)&path2[1]}, + {.value =3D (char *)"/dev/dsa/wq4.1", .next =3D NULL} +}; + +static Error **errp; + +static QemuDsaBatchTask *task; + +/* A helper for running a single task and checking for correctness. */ +static void do_single_task(void) +{ + task =3D buffer_zero_batch_task_init(batch_size); + char buf[page_size]; + char *ptr =3D buf; + + buffer_is_zero_dsa_batch_sync(task, + (const void **)&ptr, + 1, + page_size); + g_assert(task->results[0] =3D=3D buffer_is_zero(buf, page_size)); + + buffer_zero_batch_task_destroy(task); +} + +static void test_single_zero(void) +{ + g_assert(!qemu_dsa_init(path1, errp)); + qemu_dsa_start(); + + task =3D buffer_zero_batch_task_init(batch_size); + + char buf[page_size]; + char *ptr =3D buf; + + memset(buf, 0x0, page_size); + buffer_is_zero_dsa_batch_sync(task, + (const void **)&ptr, + 1, page_size); + g_assert(task->results[0]); + + buffer_zero_batch_task_destroy(task); + + qemu_dsa_cleanup(); +} + +static void test_single_zero_async(void) +{ + test_single_zero(); +} + +static void test_single_nonzero(void) +{ + g_assert(!qemu_dsa_init(path1, errp)); + qemu_dsa_start(); + + task =3D buffer_zero_batch_task_init(batch_size); + + char buf[page_size]; + char *ptr =3D buf; + + memset(buf, 0x1, page_size); + buffer_is_zero_dsa_batch_sync(task, + (const void **)&ptr, + 1, page_size); + g_assert(!task->results[0]); + + buffer_zero_batch_task_destroy(task); + + qemu_dsa_cleanup(); +} + +static void test_single_nonzero_async(void) +{ + test_single_nonzero(); +} + +/* count =3D=3D 0 should return quickly without calling into DSA. */ +static void test_zero_count_async(void) +{ + char buf[page_size]; + buffer_is_zero_dsa_batch_sync(task, + (const void **)&buf, + 0, + page_size); +} + +static void test_null_task_async(void) +{ + if (g_test_subprocess()) { + g_assert(!qemu_dsa_init(path1, errp)); + + char buf[page_size * batch_size]; + char *addrs[batch_size]; + for (int i =3D 0; i < batch_size; i++) { + addrs[i] =3D buf + (page_size * i); + } + + buffer_is_zero_dsa_batch_sync(NULL, (const void **)addrs, + batch_size, + page_size); + } else { + g_test_trap_subprocess(NULL, 0, 0); + g_test_trap_assert_failed(); + } +} + +static void test_oversized_batch(void) +{ + g_assert(!qemu_dsa_init(path1, errp)); + qemu_dsa_start(); + + task =3D buffer_zero_batch_task_init(batch_size); + + char buf[page_size * oversized_batch_size]; + char *addrs[batch_size]; + for (int i =3D 0; i < oversized_batch_size; i++) { + addrs[i] =3D buf + (page_size * i); + } + + int ret =3D buffer_is_zero_dsa_batch_sync(task, + (const void **)addrs, + oversized_batch_size, + page_size); + g_assert(ret !=3D 0); + + buffer_zero_batch_task_destroy(task); + + qemu_dsa_cleanup(); +} + +static void test_oversized_batch_async(void) +{ + test_oversized_batch(); +} + +static void test_zero_len_async(void) +{ + if (g_test_subprocess()) { + g_assert(!qemu_dsa_init(path1, errp)); + + task =3D buffer_zero_batch_task_init(batch_size); + + char buf[page_size]; + + buffer_is_zero_dsa_batch_sync(task, + (const void **)&buf, + 1, + 0); + + buffer_zero_batch_task_destroy(task); + } else { + g_test_trap_subprocess(NULL, 0, 0); + g_test_trap_assert_failed(); + } +} + +static void test_null_buf_async(void) +{ + if (g_test_subprocess()) { + g_assert(!qemu_dsa_init(path1, errp)); + + task =3D buffer_zero_batch_task_init(batch_size); + + buffer_is_zero_dsa_batch_sync(task, NULL, 1, page_size); + + buffer_zero_batch_task_destroy(task); + } else { + g_test_trap_subprocess(NULL, 0, 0); + g_test_trap_assert_failed(); + } +} + +static void test_batch(void) +{ + g_assert(!qemu_dsa_init(path1, errp)); + qemu_dsa_start(); + + task =3D buffer_zero_batch_task_init(batch_size); + + char buf[page_size * batch_size]; + char *addrs[batch_size]; + for (int i =3D 0; i < batch_size; i++) { + addrs[i] =3D buf + (page_size * i); + } + + /* + * Using whatever is on the stack is somewhat random. + * Manually set some pages to zero and some to nonzero. + */ + memset(buf + 0, 0, page_size * 10); + memset(buf + (10 * page_size), 0xff, page_size * 10); + + buffer_is_zero_dsa_batch_sync(task, + (const void **)addrs, + batch_size, + page_size); + + bool is_zero; + for (int i =3D 0; i < batch_size; i++) { + is_zero =3D buffer_is_zero((const void *)&buf[page_size * i], page= _size); + g_assert(task->results[i] =3D=3D is_zero); + } + + buffer_zero_batch_task_destroy(task); + + qemu_dsa_cleanup(); +} + +static void test_batch_async(void) +{ + test_batch(); +} + +static void test_page_fault(void) +{ + g_assert(!qemu_dsa_init(path1, errp)); + qemu_dsa_start(); + + char *buf[2]; + int prot =3D PROT_READ | PROT_WRITE; + int flags =3D MAP_SHARED | MAP_ANON; + buf[0] =3D (char *)mmap(NULL, page_size * batch_size, prot, flags, -1,= 0); + assert(buf[0] !=3D MAP_FAILED); + buf[1] =3D (char *)malloc(page_size * batch_size); + assert(buf[1] !=3D NULL); + + for (int j =3D 0; j < 2; j++) { + task =3D buffer_zero_batch_task_init(batch_size); + + char *addrs[batch_size]; + for (int i =3D 0; i < batch_size; i++) { + addrs[i] =3D buf[j] + (page_size * i); + } + + buffer_is_zero_dsa_batch_sync(task, + (const void **)addrs, + batch_size, + page_size); + + bool is_zero; + for (int i =3D 0; i < batch_size; i++) { + is_zero =3D buffer_is_zero((const void *)&buf[j][page_size * i= ], + page_size); + g_assert(task->results[i] =3D=3D is_zero); + } + buffer_zero_batch_task_destroy(task); + } + + assert(!munmap(buf[0], page_size * batch_size)); + free(buf[1]); + qemu_dsa_cleanup(); +} + +static void test_various_buffer_sizes(void) +{ + g_assert(!qemu_dsa_init(path1, errp)); + qemu_dsa_start(); + + char *buf =3D malloc(max_buffer_size * batch_size); + char *addrs[batch_size]; + + for (int len =3D 16; len <=3D max_buffer_size; len *=3D 2) { + task =3D buffer_zero_batch_task_init(batch_size); + + for (int i =3D 0; i < batch_size; i++) { + addrs[i] =3D buf + (len * i); + } + + buffer_is_zero_dsa_batch_sync(task, + (const void **)addrs, + batch_size, + len); + + bool is_zero; + for (int j =3D 0; j < batch_size; j++) { + is_zero =3D buffer_is_zero((const void *)&buf[len * j], len); + g_assert(task->results[j] =3D=3D is_zero); + } + + buffer_zero_batch_task_destroy(task); + } + + free(buf); + + qemu_dsa_cleanup(); +} + +static void test_various_buffer_sizes_async(void) +{ + test_various_buffer_sizes(); +} + +static void test_double_start_stop(void) +{ + g_assert(!qemu_dsa_init(path1, errp)); + /* Double start */ + qemu_dsa_start(); + qemu_dsa_start(); + g_assert(qemu_dsa_is_running()); + do_single_task(); + + /* Double stop */ + qemu_dsa_stop(); + g_assert(!qemu_dsa_is_running()); + qemu_dsa_stop(); + g_assert(!qemu_dsa_is_running()); + + /* Restart */ + qemu_dsa_start(); + g_assert(qemu_dsa_is_running()); + do_single_task(); + qemu_dsa_cleanup(); +} + +static void test_is_running(void) +{ + g_assert(!qemu_dsa_init(path1, errp)); + + g_assert(!qemu_dsa_is_running()); + qemu_dsa_start(); + g_assert(qemu_dsa_is_running()); + qemu_dsa_stop(); + g_assert(!qemu_dsa_is_running()); + qemu_dsa_cleanup(); +} + +static void test_multiple_engines(void) +{ + g_assert(!qemu_dsa_init(path2, errp)); + qemu_dsa_start(); + + QemuDsaBatchTask *tasks[num_devices]; + char bufs[num_devices][page_size * batch_size]; + char *addrs[num_devices][batch_size]; + + /* + * This is a somewhat implementation-specific way + * of testing that the tasks have unique engines + * assigned to them. + */ + tasks[0] =3D buffer_zero_batch_task_init(batch_size); + tasks[1] =3D buffer_zero_batch_task_init(batch_size); + g_assert(tasks[0]->device !=3D tasks[1]->device); + + for (int i =3D 0; i < num_devices; i++) { + for (int j =3D 0; j < batch_size; j++) { + addrs[i][j] =3D bufs[i] + (page_size * j); + } + + buffer_is_zero_dsa_batch_sync(tasks[i], + (const void **)addrs[i], + batch_size, page_size); + + bool is_zero; + for (int j =3D 0; j < batch_size; j++) { + is_zero =3D buffer_is_zero((const void *)&bufs[i][page_size * = j], + page_size); + g_assert(tasks[i]->results[j] =3D=3D is_zero); + } + } + + buffer_zero_batch_task_destroy(tasks[0]); + buffer_zero_batch_task_destroy(tasks[1]); + + qemu_dsa_cleanup(); +} + +static void test_configure_dsa_twice(void) +{ + g_assert(!qemu_dsa_init(path2, errp)); + g_assert(!qemu_dsa_init(path2, errp)); + qemu_dsa_start(); + do_single_task(); + qemu_dsa_cleanup(); +} + +static void test_configure_dsa_bad_path(void) +{ + const strList *bad_path =3D &(strList) { + .value =3D (char *)"/not/a/real/path", .next =3D NULL + }; + g_assert(qemu_dsa_init(bad_path, errp)); +} + +static void test_cleanup_before_configure(void) +{ + qemu_dsa_cleanup(); + g_assert(!qemu_dsa_init(path2, errp)); +} + +static void test_configure_dsa_num_devices(void) +{ + g_assert(!qemu_dsa_init(path1, errp)); + qemu_dsa_start(); + + do_single_task(); + qemu_dsa_stop(); + qemu_dsa_cleanup(); +} + +static void test_cleanup_twice(void) +{ + g_assert(!qemu_dsa_init(path2, errp)); + qemu_dsa_cleanup(); + qemu_dsa_cleanup(); + + g_assert(!qemu_dsa_init(path2, errp)); + qemu_dsa_start(); + do_single_task(); + qemu_dsa_cleanup(); +} + +static int check_test_setup(void) +{ + const strList *path[2] =3D {path1, path2}; + for (int i =3D 0; i < sizeof(path) / sizeof(strList *); i++) { + if (qemu_dsa_init(path[i], errp)) { + return -1; + } + qemu_dsa_cleanup(); + } + return 0; +} + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + + if (check_test_setup() !=3D 0) { + /* + * This test requires extra setup. The current + * setup is not correct. Just skip this test + * for now. + */ + exit(0); + } + + if (num_devices > 1) { + g_test_add_func("/dsa/multiple_engines", test_multiple_engines); + } + + g_test_add_func("/dsa/async/batch", test_batch_async); + g_test_add_func("/dsa/async/various_buffer_sizes", + test_various_buffer_sizes_async); + g_test_add_func("/dsa/async/null_buf", test_null_buf_async); + g_test_add_func("/dsa/async/zero_len", test_zero_len_async); + g_test_add_func("/dsa/async/oversized_batch", test_oversized_batch_asy= nc); + g_test_add_func("/dsa/async/zero_count", test_zero_count_async); + g_test_add_func("/dsa/async/single_zero", test_single_zero_async); + g_test_add_func("/dsa/async/single_nonzero", test_single_nonzero_async= ); + g_test_add_func("/dsa/async/null_task", test_null_task_async); + g_test_add_func("/dsa/async/page_fault", test_page_fault); + + g_test_add_func("/dsa/double_start_stop", test_double_start_stop); + g_test_add_func("/dsa/is_running", test_is_running); + + g_test_add_func("/dsa/configure_dsa_twice", test_configure_dsa_twice); + g_test_add_func("/dsa/configure_dsa_bad_path", test_configure_dsa_bad_= path); + g_test_add_func("/dsa/cleanup_before_configure", + test_cleanup_before_configure); + g_test_add_func("/dsa/configure_dsa_num_devices", + test_configure_dsa_num_devices); + g_test_add_func("/dsa/cleanup_twice", test_cleanup_twice); + + return g_test_run(); +} --=20 Yichen Wang From nobody Sat Nov 23 17:14:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1731621850; cv=none; d=zohomail.com; s=zohoarc; b=FBfVe0xrrXtJ/hjPvE1kkN6wknnUqPQ2aP6WhoRaAGXNjl/eyPwyT5llSeskWXbVcKvMSJ1/aVaJs+fcYqTT+DKXed2rMXmI10RXl5cvLp4cj7PBINnT4PBvsK/v1YjaG+w1aYWkjs9s6bFXkyb5il29Y4s866sjdOjpjK+rgTA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731621850; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=OxaPcDi0GvROdbHCP2XrpVAr3pG96W88atG3C9gr0r0=; b=RZQz0zYxCw8dI5bN6Mw93dvNTkC4mRa39Algoe0fazc0heB96YmdTaGHmipxK3Gn7a6FdF4yAuFx1PLc3caPcIAR4bv3MnNtRmoGZhOqDs38VtdSOZAFPjuZzhXu3dGkFGKKh/wmX9QupAnY2At8Kjw/l/y6BZDKp8FQCtu+pIk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1731621850160194.46319533902454; Thu, 14 Nov 2024 14:04:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tBhut-0003SS-5j; Thu, 14 Nov 2024 17:02:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tBhuk-0003Qh-MG for qemu-devel@nongnu.org; Thu, 14 Nov 2024 17:02:10 -0500 Received: from mail-qk1-x72c.google.com ([2607:f8b0:4864:20::72c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tBhuj-0007gr-1g for qemu-devel@nongnu.org; Thu, 14 Nov 2024 17:02:10 -0500 Received: by mail-qk1-x72c.google.com with SMTP id af79cd13be357-7b13ff3141aso72509885a.1 for ; Thu, 14 Nov 2024 14:02:08 -0800 (PST) Received: from DY4X0N7X05.bytedance.net ([130.44.212.152]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b35ca308bdsm93742485a.83.2024.11.14.14.02.06 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 14 Nov 2024 14:02:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1731621728; x=1732226528; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OxaPcDi0GvROdbHCP2XrpVAr3pG96W88atG3C9gr0r0=; b=FtLTfvvsoPIGg/50MCaXAV9JT1ssP+pFDVd/3EQzJ2QzA+3GEcx0mTc+J2wcENZ2Sr AoXVN41zANHEpHVhc+YZl7XBYvDIiDHxyKTs1OzTXPdoNpI3ttJcypAOWlpv88m+8YgM HXl1umOUKYBXvvKQQMe2sJoLNTI0AygxPHrWfkFoRyQyTiqrUHTA3wqi8YSKgc8ozPga 6X91sTL+b8wX1kFEUsWm9b1apZPj/auXdon4h2vssJUreqT1IT+lxkwlsHiDebcmZp+e 2viSSjgZeQ+f+/y/ss5JssLetL5JX+Eg/yfWC/kAwNRYxY9uGz8DJdY00vzbuP7qd8kD ckPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731621728; x=1732226528; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OxaPcDi0GvROdbHCP2XrpVAr3pG96W88atG3C9gr0r0=; b=jRZTFps5Narvr3yW8dson65TeNIx6EWPleOkgywPkxUvc2jaGA1B2EDJOx3jqfPUgq UwY3F6CHYnV5wWJpn56f2FHLChOyNEFjkNZVeMT4ugL6mhUJdoDnuH3uV/4Si+EkPScZ 731kC+273Cl4WY0SZPGai6V83o3ZtwbC1LathLClYFpta5V0VO/toFBPxp66BADrDAac gkU1tWHKtpD3rcgaeNQKGArFMA8WsuRQvYl1b4ZmpxzF01DMV0qfsh8sMd7cZjw9NHpg Bdvyjj3hynecLqwG8YAqoLBaN67n4KQV77leBXWbv7BLzgSTPuOfNXxVrdXf3RMluQAT UIpA== X-Forwarded-Encrypted: i=1; AJvYcCVeXdY2jGv17eYdL0JZtBe7zMZVBf9d/soV+SWjiQ0pg3xQUUUT+GT3k6tDYvRTh+/55OboX4Jn2w2v@nongnu.org X-Gm-Message-State: AOJu0Yzhgx/a1ZLyCNreU+wJw3usO9KTiEfIa4GIAvpTfvM4CJwAyr59 5UJXUkjJz+FZbdRZduDeJK2elLqUny7QxmJSrJwqHvg4G/2BcoDSUXnYWekQiVo= X-Google-Smtp-Source: AGHT+IE1flOo8GUuiBFeSBKTr2iYCSF0phHR9gfIh8/Ngv56jyN7hKPftARShzppOjSZ6PmsvTnO7w== X-Received: by 2002:a05:620a:1a28:b0:7b1:52a0:48eb with SMTP id af79cd13be357-7b3622b5e03mr67182685a.22.1731621728057; Thu, 14 Nov 2024 14:02:08 -0800 (PST) From: Yichen Wang To: Peter Xu , Fabiano Rosas , "Dr. David Alan Gilbert" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eric Blake , Markus Armbruster , "Michael S. Tsirkin" , Cornelia Huck , qemu-devel@nongnu.org Cc: "Hao Xiang" , "Liu, Yuan1" , "Shivam Kumar" , "Ho-Ren (Jack) Chuang" , "Yichen Wang" , Bryan Zhang Subject: [PATCH v7 11/12] migration/multifd: Add integration tests for multifd with Intel DSA offloading. Date: Thu, 14 Nov 2024 14:01:31 -0800 Message-Id: <20241114220132.27399-12-yichen.wang@bytedance.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241114220132.27399-1-yichen.wang@bytedance.com> References: <20241114220132.27399-1-yichen.wang@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::72c; envelope-from=yichen.wang@bytedance.com; helo=mail-qk1-x72c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1731621852569116600 Content-Type: text/plain; charset="utf-8" From: Hao Xiang * Add test case to start and complete multifd live migration with DSA offloading enabled. * Add test case to start and cancel multifd live migration with DSA offloading enabled. Signed-off-by: Bryan Zhang Signed-off-by: Hao Xiang Signed-off-by: Yichen Wang --- tests/qtest/migration-test.c | 80 +++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index e6a2803e71..cd551ce70c 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -611,6 +611,12 @@ typedef struct { bool suspend_me; } MigrateStart; =20 +/* + * It requires separate steps to configure and enable DSA device. + * This test assumes that the configuration is done already. + */ +static const char *dsa_dev_path_p =3D "['dsa:/dev/dsa/wq4.0']"; + /* * A hook that runs after the src and dst QEMUs have been * created, but before the migration is started. This can @@ -3262,7 +3268,7 @@ static void test_multifd_tcp_tls_x509_reject_anon_cli= ent(void) * * And see that it works */ -static void test_multifd_tcp_cancel(void) +static void test_multifd_tcp_cancel_common(bool use_dsa) { MigrateStart args =3D { .hide_stderr =3D true, @@ -3282,6 +3288,11 @@ static void test_multifd_tcp_cancel(void) migrate_set_capability(from, "multifd", true); migrate_set_capability(to, "multifd", true); =20 + if (use_dsa) { + migrate_set_parameter_str(from, "zero-page-detection", "dsa-accel"= ); + migrate_set_parameter_str(from, "accel-path", dsa_dev_path_p); + } + /* Start incoming migration from the 1st socket */ migrate_incoming_qmp(to, "tcp:127.0.0.1:0", "{}"); =20 @@ -3340,6 +3351,49 @@ static void test_multifd_tcp_cancel(void) test_migrate_end(from, to2, true); } =20 +/* + * This test does: + * source target + * migrate_incoming + * migrate + * migrate_cancel + * launch another target + * migrate + * + * And see that it works + */ +static void test_multifd_tcp_cancel(void) +{ + test_multifd_tcp_cancel_common(false); +} + +#ifdef CONFIG_DSA_OPT + +static void *test_migrate_precopy_tcp_multifd_start_dsa(QTestState *from, + QTestState *to) +{ + migrate_set_parameter_str(from, "zero-page-detection", "dsa-accel"); + migrate_set_parameter_str(from, "accel-path", dsa_dev_path_p); + return test_migrate_precopy_tcp_multifd_start_common(from, to, "none"); +} + +static void test_multifd_tcp_zero_page_dsa(void) +{ + MigrateCommon args =3D { + .listen_uri =3D "defer", + .start_hook =3D test_migrate_precopy_tcp_multifd_start_dsa, + }; + + test_precopy_common(&args); +} + +static void test_multifd_tcp_cancel_dsa(void) +{ + test_multifd_tcp_cancel_common(true); +} + +#endif + static void calc_dirty_rate(QTestState *who, uint64_t calc_time) { qtest_qmp_assert_success(who, @@ -3767,6 +3821,20 @@ static bool kvm_dirty_ring_supported(void) #endif } =20 +#ifdef CONFIG_DSA_OPT +static const char *dsa_dev_path =3D "/dev/dsa/wq4.0"; +static int test_dsa_setup(void) +{ + int fd; + fd =3D open(dsa_dev_path, O_RDWR); + if (fd < 0) { + return -1; + } + close(fd); + return 0; +} +#endif + int main(int argc, char **argv) { bool has_kvm, has_tcg; @@ -3979,6 +4047,16 @@ int main(int argc, char **argv) test_multifd_tcp_zero_page_legacy); migration_test_add("/migration/multifd/tcp/plain/zero-page/none", test_multifd_tcp_no_zero_page); + +#ifdef CONFIG_DSA_OPT + if (g_str_equal(arch, "x86_64") && test_dsa_setup() =3D=3D 0) { + migration_test_add("/migration/multifd/tcp/plain/zero-page/dsa", + test_multifd_tcp_zero_page_dsa); + migration_test_add("/migration/multifd/tcp/plain/cancel/dsa", + test_multifd_tcp_cancel_dsa); + } +#endif + migration_test_add("/migration/multifd/tcp/plain/cancel", test_multifd_tcp_cancel); migration_test_add("/migration/multifd/tcp/plain/zlib", --=20 Yichen Wang From nobody Sat Nov 23 17:14:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1731621881; cv=none; d=zohomail.com; s=zohoarc; b=kPAWR1CWdF9zUzzt8kTG+Q+sufYjORr5t0dFLzEHTYPxSRMQSvNK4eVy09/LeyUw/KhP2QLWVHeL/r8KGTWnurnzRVh0qg3vEdrMbs1p5ZLXOqgu1UX+cfNuKyuTaWB3JcoILbixlgMMehydc3UnrHRoYFc65MzlU91ExPXKUWY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731621881; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CufjBvzPBvmSNHMmNvk4bj+ZKdXjyb+9rtabtha1IGs=; b=j0WJTS1Q/Lmh5f/WmTtpsLegyqVaIUYT4wmpQP9/bsK3n21DA3c6CbBihDxz3Ags4sj05+2a6zA1+2KGDVqUm2i7NA9foW3vyMj1eb00oexujyaPoVCqdn1bOt6zSh2juVkVnNuxoUp3f53xigeWWNTG6a1WAkJScx3G214YTbM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 173162188184474.69344695802818; Thu, 14 Nov 2024 14:04:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tBhut-0003SP-5h; Thu, 14 Nov 2024 17:02:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tBhun-0003RL-Sm for qemu-devel@nongnu.org; Thu, 14 Nov 2024 17:02:14 -0500 Received: from mail-qk1-x72f.google.com ([2607:f8b0:4864:20::72f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tBhul-0007h9-Js for qemu-devel@nongnu.org; Thu, 14 Nov 2024 17:02:13 -0500 Received: by mail-qk1-x72f.google.com with SMTP id af79cd13be357-7b14df8f821so80872485a.2 for ; Thu, 14 Nov 2024 14:02:11 -0800 (PST) Received: from DY4X0N7X05.bytedance.net ([130.44.212.152]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b35ca308bdsm93742485a.83.2024.11.14.14.02.08 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 14 Nov 2024 14:02:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1731621731; x=1732226531; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CufjBvzPBvmSNHMmNvk4bj+ZKdXjyb+9rtabtha1IGs=; b=L8G/1WUNMrv9DsMbv0mGezvyXDz+S3v3oWBeJ/BfXW0HSIboADIknT2SKaB7CvKBTb myX5wXmkOcWzD7uKghEAh8VkCy2VgjQuy5naJPM/yGAtWkt4vAN+x2m8pDp+C67mIqok yVE2cIqg7tEDSxGCzNlDiLnwPj1G68lyd6qI4mK41GgyrrEp8Pz3wIX8SVV733Hg1mMB 2qkeFn6K/zJMb/8MRsz4i0D9CiFtwZ528q6Uy+aoVenf3yKrhqXfS0Jxo01OgpGeaZMW TSSNVjNRSlTSaIwX+n7LyDTxo0XBuGNuKG5TUMpK3pkBWJcTFhGksQvue3dvAHrL8BRR CLzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731621731; x=1732226531; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CufjBvzPBvmSNHMmNvk4bj+ZKdXjyb+9rtabtha1IGs=; b=JnTWmdGD6E0lRQ9sl+w0xqsFe+wkTUmDKy3dbsIy70EOgoO2S8kEWygVgmjg6mnYn8 AZyK/+hxy48E1AdPg6muASk7TVORbQ+Dm64avamk9gdZaRHB6oCzbICryPg8lrPX4Gek 2YJVyqKtBwWYv4jJQX0bdlzDwBFpX0licYNsexMhV4FEPApDvXo/iD8HUGGA+pstteAf y6akbxQY2DjMxQNONFcYFjXY6pTnR1JQAdQsvhOZOLGopRtREiGfmULSbOUwVPhEUOHY U+E3vdD+uDMtUmsOSgBjOzr0oHcTfdV+IV6muydhHC0JWpPyhljiHtZiwTrXYmK+IDf3 OvDg== X-Forwarded-Encrypted: i=1; AJvYcCVTOrwlpCEOL5WdQac6Q2QC6Qbmh8g6XH5a+yrfoDJLDyk4m7JHw+675PFDoSf6B8s5l8KY+abcr8zO@nongnu.org X-Gm-Message-State: AOJu0YydvjDT9WRlQ2xcSy2CogQDcvCWSL/RvPMvRzmuDB5MkH+Gxx2N Y0vrU+0uzsE+jXlpnyd0lBqSR+qbsn2EZilPWE6JtDuzBHTpBHt55KNFx1MXOWU= X-Google-Smtp-Source: AGHT+IFeOaKBaAqEeCXluB7q8D5x2b2pa1e3UBTWjvKSz0z8lGE6fvRkh+jqvUWHSYbqNFTRkw689g== X-Received: by 2002:a05:620a:28c4:b0:7b1:5143:8da1 with SMTP id af79cd13be357-7b36236278fmr64689585a.43.1731621730664; Thu, 14 Nov 2024 14:02:10 -0800 (PST) From: Yichen Wang To: Peter Xu , Fabiano Rosas , "Dr. David Alan Gilbert" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eric Blake , Markus Armbruster , "Michael S. Tsirkin" , Cornelia Huck , qemu-devel@nongnu.org Cc: "Hao Xiang" , "Liu, Yuan1" , "Shivam Kumar" , "Ho-Ren (Jack) Chuang" , "Yichen Wang" Subject: [PATCH v7 12/12] migration/doc: Add DSA zero page detection doc Date: Thu, 14 Nov 2024 14:01:32 -0800 Message-Id: <20241114220132.27399-13-yichen.wang@bytedance.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241114220132.27399-1-yichen.wang@bytedance.com> References: <20241114220132.27399-1-yichen.wang@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::72f; envelope-from=yichen.wang@bytedance.com; helo=mail-qk1-x72f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1731621882501116600 Content-Type: text/plain; charset="utf-8" From: Yuan Liu Signed-off-by: Yuan Liu Signed-off-by: Yichen Wang --- .../migration/dsa-zero-page-detection.rst | 290 ++++++++++++++++++ docs/devel/migration/features.rst | 1 + 2 files changed, 291 insertions(+) create mode 100644 docs/devel/migration/dsa-zero-page-detection.rst diff --git a/docs/devel/migration/dsa-zero-page-detection.rst b/docs/devel/= migration/dsa-zero-page-detection.rst new file mode 100644 index 0000000000..1279fcdd99 --- /dev/null +++ b/docs/devel/migration/dsa-zero-page-detection.rst @@ -0,0 +1,290 @@ +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D +DSA-Based Zero Page Detection +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D +Intel Data Streaming Accelerator(``DSA``) is introduced in Intel's 4th +generation Xeon server, aka Sapphire Rapids(``SPR``). One of the things +DSA can do is to offload memory comparison workload from CPU to DSA accele= rator +hardware. + +The main advantages of using DSA to accelerate zero pages detection include + +1. Reduces CPU usage in multifd live migration workflow across all use cas= es. + +2. Reduces migration total time in some use cases. + + +DSA-Based Zero Page Detection Introduction +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +:: + + + +----------------+ +------------------+ + | MultiFD Thread | |accel-config tool | + +-+--------+-----+ +--------+---------+ + | | | + | | Open DSA | Setup DSA + | | Work Queues | Resources + | | +-----+-----+ | + | +------>|idxd driver|<-+ + | +-----+-----+ + | | + | | + | +-----+-----+ + +----------------+DSA Devices| + Submit jobs +-----------+ + via enqcmd + + +DSA Introduction +---------------- +Intel Data Streaming Accelerator (DSA) is a high-performance data copy and +transformation accelerator that is integrated in Intel Xeon processors, +targeted for optimizing streaming data movement and transformation operati= ons +common with applications for high-performance storage, networking, persist= ent +memory, and various data processing applications. + +For more ``DSA`` introduction, please refer to `DSA Introduction +`_ + +For ``DSA`` specification, please refer to `DSA Specification +`_ + +For ``DSA`` user guide, please refer to `DSA User Guide +`_ + +DSA Device Management +--------------------- + +The number of ``DSA`` devices will vary depending on the Xeon product mode= l. +On a ``SPR`` server, there can be a maximum of 8 ``DSA`` devices, with up = to +4 devices per socket. + +By default, all ``DSA`` devices are disabled and need to be configured and +enabled by users manually. + +Check the number of devices through the following command + +.. code-block:: shell + + #lspci -d 8086:0b25 + 6a:01.0 System peripheral: Intel Corporation Device 0b25 + 6f:01.0 System peripheral: Intel Corporation Device 0b25 + 74:01.0 System peripheral: Intel Corporation Device 0b25 + 79:01.0 System peripheral: Intel Corporation Device 0b25 + e7:01.0 System peripheral: Intel Corporation Device 0b25 + ec:01.0 System peripheral: Intel Corporation Device 0b25 + f1:01.0 System peripheral: Intel Corporation Device 0b25 + f6:01.0 System peripheral: Intel Corporation Device 0b25 + + +DSA Device Configuration And Enabling +------------------------------------- + +The ``accel-config`` tool is used to enable ``DSA`` devices and configure +``DSA`` hardware resources(work queues and engines). One ``DSA`` device +has 8 work queues and 4 processing engines, multiple engines can be assign= ed +to a work queue via ``group`` attribute. + +For ``accel-config`` installation, please refer to `accel-config installat= ion +`_ + +One example of configuring and enabling an ``DSA`` device. + +.. code-block:: shell + + #accel-config config-engine dsa0/engine0.0 -g 0 + #accel-config config-engine dsa0/engine0.1 -g 0 + #accel-config config-engine dsa0/engine0.2 -g 0 + #accel-config config-engine dsa0/engine0.3 -g 0 + #accel-config config-wq dsa0/wq0.0 -g 0 -s 128 -p 10 -b 1 -t 128 -m shar= ed -y user -n app1 -d user + #accel-config enable-device dsa0 + #accel-config enable-wq dsa0/wq0.0 + +- The ``DSA`` device index is 0, use ``ls -lh /sys/bus/dsa/devices/dsa*`` + command to query the ``DSA`` device index. + +- 4 engines and 1 work queue are configured in group 0, so that all zero-p= age + detection jobs submitted to this work queue can be processed by all engi= nes + simultaneously. + +- Set work queue attributes including the work mode, work queue size and s= o on. + +- Enable the ``dsa0`` device and work queue ``dsa0/wq0.0`` + +.. note:: + + 1. ``DSA`` device driver is Intel Data Accelerator Driver (idxd), it is + recommended that the minimum version of Linux kernel is 5.18. + + 2. Only ``DSA`` shared work queue mode is supported, it needs to add + ``"intel_iommu=3Don,sm_on"`` parameter to kernel command line. + +For more detailed configuration, please refer to `DSA Configuration Samples +`_ + + +Performances +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +We use two Intel 4th generation Xeon servers for testing. + +:: + + Architecture: x86_64 + CPU(s): 192 + Thread(s) per core: 2 + Core(s) per socket: 48 + Socket(s): 2 + NUMA node(s): 2 + Vendor ID: GenuineIntel + CPU family: 6 + Model: 143 + Model name: Intel(R) Xeon(R) Platinum 8457C + Stepping: 8 + CPU MHz: 2538.624 + CPU max MHz: 3800.0000 + CPU min MHz: 800.0000 + +We perform multifd live migration with below setup: + +1. VM has 100GB memory. + +2. Use the new migration option multifd-set-normal-page-ratio to control t= he + total size of the payload sent over the network. + +3. Use 8 multifd channels. + +4. Use tcp for live migration. + +5. Use CPU to perform zero page checking as the baseline. + +6. Use one DSA device to offload zero page checking to compare with the ba= seline. + +7. Use "perf sched record" and "perf sched timehist" to analyze CPU usage. + + +A) Scenario 1: 50% (50GB) normal pages on an 100GB vm +----------------------------------------------------- + +:: + + CPU usage + + |---------------|---------------|---------------|---------------| + | |comm |runtime(msec) |totaltime(msec)| + |---------------|---------------|---------------|---------------| + |Baseline |live_migration |5657.58 | | + | |multifdsend_0 |3931.563 | | + | |multifdsend_1 |4405.273 | | + | |multifdsend_2 |3941.968 | | + | |multifdsend_3 |5032.975 | | + | |multifdsend_4 |4533.865 | | + | |multifdsend_5 |4530.461 | | + | |multifdsend_6 |5171.916 | | + | |multifdsend_7 |4722.769 |41922 | + |---------------|---------------|---------------|---------------| + |DSA |live_migration |6129.168 | | + | |multifdsend_0 |2954.717 | | + | |multifdsend_1 |2766.359 | | + | |multifdsend_2 |2853.519 | | + | |multifdsend_3 |2740.717 | | + | |multifdsend_4 |2824.169 | | + | |multifdsend_5 |2966.908 | | + | |multifdsend_6 |2611.137 | | + | |multifdsend_7 |3114.732 | | + | |dsa_completion |3612.564 |32568 | + |---------------|---------------|---------------|---------------| + +Baseline total runtime is calculated by adding up all multifdsend_X +and live_migration threads runtime. DSA offloading total runtime is +calculated by adding up all multifdsend_X, live_migration and +dsa_completion threads runtime. 41922 msec VS 32568 msec runtime and +that is 23% total CPU usage savings. + +:: + + Latency + |---------------|---------------|---------------|---------------|--------= -------|---------------| + | |total time |down time |throughput |transferred-ram|total-ram | + |---------------|---------------|---------------|---------------|--------= -------|---------------| + |Baseline |10343 ms |161 ms |41007.00 mbps |51583797 kb |102400520 kb | + |---------------|---------------|---------------|---------------|--------= -----------------------| + |DSA offload |9535 ms |135 ms |46554.40 mbps |53947545 kb |102400520 kb | + |---------------|---------------|---------------|---------------|--------= -------|---------------| + +Total time is 8% faster and down time is 16% faster. + + +B) Scenario 2: 100% (100GB) zero pages on an 100GB vm +----------------------------------------------------- + +:: + + CPU usage + |---------------|---------------|---------------|---------------| + | |comm |runtime(msec) |totaltime(msec)| + |---------------|---------------|---------------|---------------| + |Baseline |live_migration |4860.718 | | + | |multifdsend_0 |748.875 | | + | |multifdsend_1 |898.498 | | + | |multifdsend_2 |787.456 | | + | |multifdsend_3 |764.537 | | + | |multifdsend_4 |785.687 | | + | |multifdsend_5 |756.941 | | + | |multifdsend_6 |774.084 | | + | |multifdsend_7 |782.900 |11154 | + |---------------|---------------|-------------------------------| + |DSA offloading |live_migration |3846.976 | | + | |multifdsend_0 |191.880 | | + | |multifdsend_1 |166.331 | | + | |multifdsend_2 |168.528 | | + | |multifdsend_3 |197.831 | | + | |multifdsend_4 |169.580 | | + | |multifdsend_5 |167.984 | | + | |multifdsend_6 |198.042 | | + | |multifdsend_7 |170.624 | | + | |dsa_completion |3428.669 |8700 | + |---------------|---------------|---------------|---------------| + +Baseline total runtime is 11154 msec and DSA offloading total runtime is +8700 msec. That is 22% CPU savings. + +:: + + Latency + |------------------------------------------------------------------------= --------------------| + | |total time |down time |throughput |transferred-ram|total-ram | + |---------------|---------------|---------------|---------------|--------= -------|------------| + |Baseline |4867 ms |20 ms |1.51 mbps |565 kb |102400520 kb| + |---------------|---------------|---------------|---------------|--------= --------------------| + |DSA offload |3888 ms |18 ms |1.89 mbps |565 kb |102400520 kb| + |---------------|---------------|---------------|---------------|--------= -------|------------| + +Total time 20% faster and down time 10% faster. + + +How To Use DSA In Migration +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D + +The migration parameter ``accel-path`` is used to specify the resource +allocation for DSA. After the user configures +``zero-page-detection=3Ddsa-accel``, one or more DSA work queues need to be +specified for migration. + +The following example shows two DSA work queues for zero page detection + +.. code-block:: shell + + migrate_set_parameter zero-page-detection=3Ddsa-accel + migrate_set_parameter accel-path=3Ddsa:/dev/dsa/wq0.0 dsa:/dev/dsa/wq1.0 + +.. note:: + + Accessing DSA resources requires ``sudo`` command or ``root`` privileges + by default. Administrators can modify the DSA device node ownership + so that QEMU can use DSA with specified user permissions. + + For example: + + #chown -R qemu /dev/dsa + diff --git a/docs/devel/migration/features.rst b/docs/devel/migration/featu= res.rst index 8f431d52f9..ea2893d80f 100644 --- a/docs/devel/migration/features.rst +++ b/docs/devel/migration/features.rst @@ -15,3 +15,4 @@ Migration has plenty of features to support different use= cases. qpl-compression uadk-compression qatzip-compression + dsa-zero-page-detection --=20 Yichen Wang