From nobody Thu Dec 18 19:28:14 2025 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=1733278402; cv=none; d=zohomail.com; s=zohoarc; b=eqS2dFc4BcNoHJNRJo627s4wk/ZnvsKEoxHDrYc6ikn+0ZtWnl40Wk8XD/wUqyV33EfpP51nyiiSG3+CdRTGqohfjBiMh72CUQWjTXEOXRcnQ6P//ZOobcRxxXLC9Nq+19oJxeoA4yxj0wiPw8hecj/BzNGLvhPjL+ZvlNeZJRk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733278402; 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=/0wN4j/oJJNTRC4MBF1twlWeye36pdO8I/CrrqHAcjQ=; b=no5AhcpYXdEkeGKmHH9sgHA0p/sCrQFaMvOD63xwO4Rq/ajX5VvlEkOeWnzwVdmoI0wi8yRoS8OhW4s3Nr139VrVAQ7OcZHeBwopt6ZIsGSbQQzgaCrqUW3AK7oVuskHEte4lOSLFfPEoT1JBYFOXZIc+SRBuPV8nPIU2P6SrXU= 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 1733278402477716.2619926697195; Tue, 3 Dec 2024 18:13:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIerv-0003qN-It; Tue, 03 Dec 2024 21:11: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 1tIert-0003q7-KW for qemu-devel@nongnu.org; Tue, 03 Dec 2024 21:11:57 -0500 Received: from mail-qv1-xf2d.google.com ([2607:f8b0:4864:20::f2d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIerq-0005PA-Lp for qemu-devel@nongnu.org; Tue, 03 Dec 2024 21:11:57 -0500 Received: by mail-qv1-xf2d.google.com with SMTP id 6a1803df08f44-6d896be3992so19272376d6.1 for ; Tue, 03 Dec 2024 18:11:54 -0800 (PST) Received: from DY4X0N7X05.bytedance.net ([2601:646:8900:323:644e:288b:2b6d:d94c]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d87ec537ebsm63488986d6.30.2024.12.03.18.11.51 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 03 Dec 2024 18:11:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1733278313; x=1733883113; 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=/0wN4j/oJJNTRC4MBF1twlWeye36pdO8I/CrrqHAcjQ=; b=frxrB2IKlmySaXuNaEAhw1cfQdcHOpzwLIm4DeokjllG88cLFk6zIDlFC2DW4StDTm ZYVNda2jakU470KQiUQ81CJPCasXM+HX0Chizn6hCepwS93Ofp7D14kMkhighw37wSp/ sVgtfC5xGFvuX0zJb9DjTas3EanEgR1zE5Bf/Q45vjI8TSL1t21YOCX/UeufaEJVAnWm ZvrUxi/Bi3rdaql4g6nzsl/mN+p7dmm9DZav8TPGMD9oeDKyaIxAD2757hDpD1cqYa3b AD4SbtJKPf55auC8WUBN6fKIW/bGX7axZk0ahkEzanmDRxxWgdMGB4lYVbz3GBKipFZN NVag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733278313; x=1733883113; 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=/0wN4j/oJJNTRC4MBF1twlWeye36pdO8I/CrrqHAcjQ=; b=ksxcckKbRczC6b1xhVD8zd8Cnustp4rke4GX0MqvWLbzABCmDy+fiu/iIGD+QJnGjY yYZk/Mcvm6OF3dIaxK27ve4uw1oNLT7tLlNpnudWs6XF8V1yD6dEX5diIR2fhvgP5hEn T7TG2SA7xrrqeThEQIL9joWp9Y4HgUZ2vRt0iAxlK5xCABO0ZFNIsaMsfWfFixOMqNzy /mN7b3xSQn2hCZCY89DOfwsiMBUj98vvumxpNaKpV+CCeEKCe+zWp9jhKgRDFMPbCGvM bsVJ/ZLP5g+X6XADZkYCCZ7MLL3uDDGJeW8VK9O2+B+/4Vmqo1yVmVntoumxSDbrIrkB g9+w== X-Forwarded-Encrypted: i=1; AJvYcCXHJ704PO6JrDlwnsscwiViiF/WCGaKkowpHqQrdFEIefKSIz2PGpftMDbRQiz8KVD+W9xj6C6spATN@nongnu.org X-Gm-Message-State: AOJu0YygvJwNWYveN63XBawKFW89c0EiEOYhNurHS7s7GoRHS0dmF1Bo bhDOTNDDY8uK4inOQTDtZb4um7LGHQV1OI26QOyp4WNaED6pALGZDVxidi42iEQ= X-Gm-Gg: ASbGncvyc+X90A6uu2+o9/3/VjZlH6zMB19mEI3Bk6Dmh2QdiEw4MH+1QR7dXqP8mt8 Fnf+CP492UJEOj6Xq5bVLp0JaVXmes1t4YI0zYP/ksgm0qySNNgFp3Xm1uIhHN9VgUCZ2jmZsrx kDrsj/KizCEL7pxu34vxpCA93UsDTRSwyMKTfzBN1fRlOyWOpOCnD5Yiwy4xL+Nbi2Em5x1n6ly XpidgZ0kxZzvxt3FfdiiBsZfnR03VN81HFkutQaPz1zU/fzYOqqniaI4GhNUdoEmovi7t8G4ipe iBtYmn9iyGRLsU4KqQ== X-Google-Smtp-Source: AGHT+IEN99xczOXj8OW/XtgjGtM089VwEZOvzDW5uzYqGf7/sMYDdnkqq+ragp9D1WtsYWXJ4C/2Mw== X-Received: by 2002:ad4:5bc4:0:b0:6d8:ac5d:b83e with SMTP id 6a1803df08f44-6d8b747b62emr97529876d6.47.1733278313526; Tue, 03 Dec 2024 18:11:53 -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 v8 01/12] meson: Introduce new instruction set enqcmd to the build system. Date: Tue, 3 Dec 2024 18:11:30 -0800 Message-Id: <20241204021142.24184-2-yichen.wang@bytedance.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241204021142.24184-1-yichen.wang@bytedance.com> References: <20241204021142.24184-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::f2d; envelope-from=yichen.wang@bytedance.com; helo=mail-qv1-xf2d.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: 1733278404057116600 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 147097c652..50df5dd3e0 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 Thu Dec 18 19:28:14 2025 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=1733278431; cv=none; d=zohomail.com; s=zohoarc; b=Jpgk9JcY8czehKe9AstpFuLeQX0XbWbgOlYRYMR6L0S2gN+pcS1Fpel7LXP6WBLI3a4DXALHPrA/lMYBVT3uroMbl2GYvBLsKiHS2ZuTBky++E4xwRy5ihIzRA506DdcPd2w1QZTk44kmkag8zjQRbF8ch8aP9GjWcLvrAE79xw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733278431; 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=2mmBF5CVSuEv5Hs4OjTWSCjE9+8hQXVfJDcSidunhtM=; b=OECSX75NJf7fbxQmWSeyN5NNb3WKyjUq2oU15JwpgPV8rOUO2BhbFfS92w0s5tsAMinCHdohfXVs+5glizVYGMaA69SJx5h1GNak5aNInasnSI/2Oxc0m2jvPHyhFFzHeo5v10kWSUijuN+4WZerIm4IHNbGxoM0He12GZhNQ7o= 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 1733278431941174.4829946440152; Tue, 3 Dec 2024 18:13:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIes0-0003xN-Gv; Tue, 03 Dec 2024 21:12: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 1tIerv-0003qa-P2 for qemu-devel@nongnu.org; Tue, 03 Dec 2024 21:12:00 -0500 Received: from mail-qv1-xf2a.google.com ([2607:f8b0:4864:20::f2a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIeru-0005Pf-2L for qemu-devel@nongnu.org; Tue, 03 Dec 2024 21:11:59 -0500 Received: by mail-qv1-xf2a.google.com with SMTP id 6a1803df08f44-6d89dc50927so20473026d6.3 for ; Tue, 03 Dec 2024 18:11:57 -0800 (PST) Received: from DY4X0N7X05.bytedance.net ([2601:646:8900:323:644e:288b:2b6d:d94c]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d87ec537ebsm63488986d6.30.2024.12.03.18.11.54 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 03 Dec 2024 18:11:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1733278317; x=1733883117; 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=2mmBF5CVSuEv5Hs4OjTWSCjE9+8hQXVfJDcSidunhtM=; b=POw/v5ilRghSPrErURBmS+V431xPFb8cbsx3s918pOTBsSRcgkYZHksMnpqmsDuZ4f E+ixJWTaxaYowFIKgLqNHzrXM6cRqfMEYdGqE0+usB0PlmUDDJI3Lvizu0azbfK5bAAa VTKXh+jR3VGh78JmmaFh8gUNMJ8IbHiordzO4e934W37XZGMZFaA41Is95YpLaiVnucR FGq2b9+4MHwwUByNwepWf2X6B4a7ei2lKluXmQgnTxmJHw/G1RoFJy6sOlnfqzzQpMsm H6765RDuCwmUuWA81OJnwdHVjNKW75I0Bt6RrwbnubjBj2ykJx2iV7r7LcOGvI80WyZG TYVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733278317; x=1733883117; 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=2mmBF5CVSuEv5Hs4OjTWSCjE9+8hQXVfJDcSidunhtM=; b=TFxsRxRoQYpIZzQvDkxTcHpnFmOo15Q4ln0bBaUmKov6rpOwjNPaOeUSY3EL542+X1 wR3qL3E8ZJyQ8oMa4zboeY6R7v49z8XZCu58nkPsxOnzG8EZ4zjS0OjqUYOXlqGZ7qYZ 4MgQqrImCzziN7IJxrxKvndgrz89YsPb7yTC5n/wlgLOKQdtwmuqNtnKu80JWfC9lSWe OFySaHTyPsURUw+5JZQD5jgvtVJUEyNBZdq++ZF3VHelbNDY6AjcOXxDQTw+Gkprc/im Ryb7CBDazBmx2kRS8noHWuSUKfzRNlDV6pv+fXcJbyhWdBEHG3FwYbnH/m+qy9aLVDYX /siw== X-Forwarded-Encrypted: i=1; AJvYcCW3hD6otX178w5uSH7UubYjPTyXkWLCeToanJm9cozrKe6KVDiCoVJaSwCd7pIwlySKrxars4/SH2Hy@nongnu.org X-Gm-Message-State: AOJu0YwF3lImCAs7iasC8vTJOscUV+u0NG58eLmSzc8KZB8NgLrkf/6f Mnxs0dxrOeeDpZP2mO5+dZSoRvbU70t7vB4zIVHxZr8X6nvwjpIGGUnslg/9nzE= X-Gm-Gg: ASbGnct998Pk/T8Hu3+M+BK4Qys/1SqE9Oc6LtudVG7cDReXeoBswVz5VPvCvSdENP2 htq6VP5bfMc0TDRsadAgI8CLtqp6b9nek/mFXoOJEc8Ub0+D4fWOWz1rdjhhlxllbw5c2FERnfW x1E6rooj8nxj7BXtc7TapzOgrSLMZZFXxpyfrzC0C8TaaOgbsj4kCLuqTEgk+KRbR5Mv6HLhpO2 jJXv7nQSNz6rQCPgrKgP9cbIroHAXl014clkVxbiU2CDK+MDT8dUPOs4XdCPVmo9dpbCR7jU6xA ncsOcuVVv9zEPvLZuw== X-Google-Smtp-Source: AGHT+IGmXEgJ4230AasQ3H4vQpPTWDlSZa90avoi4T6n+fgxO/Ox8pgZDTVShHskOSyN645mUvfy0g== X-Received: by 2002:a05:6214:529a:b0:6d8:a570:faee with SMTP id 6a1803df08f44-6d8b737eb6emr80611826d6.16.1733278316901; Tue, 03 Dec 2024 18:11:56 -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 v8 02/12] util/dsa: Add idxd into linux header copy list. Date: Tue, 3 Dec 2024 18:11:31 -0800 Message-Id: <20241204021142.24184-3-yichen.wang@bytedance.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241204021142.24184-1-yichen.wang@bytedance.com> References: <20241204021142.24184-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::f2a; envelope-from=yichen.wang@bytedance.com; helo=mail-qv1-xf2a.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: 1733278434363116600 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 Thu Dec 18 19:28:14 2025 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=1733278355; cv=none; d=zohomail.com; s=zohoarc; b=eFjL6hpZj7/7WsJRL0edVvpMMuX+TYILp5XV+4umySs8HspgOffhsqpb5PmINjTFmbfkA8dGxqkMiPbS+m8jzDcwqf1VxcDTIE7hYjwIKJrMgKfb827Idjb7HZoFf+8x3VgcLhcvN+zu+KcrS6TqwF5Glgw/oHyiPVjcXqiwwY8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733278355; 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=081ar3D+q2I5dbHey0ExnsftyZ/LMfe2DNt/cF/PLBs=; b=TgCtMrvDoFyzbstPF4NCgeGAjMia2CmR3yaTBxbhWcLy9e6fB2z8cgR0guasdNg2JusxSm8IkmTjhUEOoVXQGw+97/KdkcV49I5dq8vONbY+YrZ5texRNtEGJel4g517MikfAkC8NFRuw6eyPr1EkoZpNSVNrz5orfCfEdI+UHU= 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 1733278355193324.56627276944744; Tue, 3 Dec 2024 18:12:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIes2-00040Z-PI; Tue, 03 Dec 2024 21:12:06 -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 1tIes1-0003zx-MT for qemu-devel@nongnu.org; Tue, 03 Dec 2024 21:12:05 -0500 Received: from mail-yw1-x1129.google.com ([2607:f8b0:4864:20::1129]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIerz-0005Q2-Nh for qemu-devel@nongnu.org; Tue, 03 Dec 2024 21:12:05 -0500 Received: by mail-yw1-x1129.google.com with SMTP id 00721157ae682-6ef66fd2183so47773207b3.1 for ; Tue, 03 Dec 2024 18:12:02 -0800 (PST) Received: from DY4X0N7X05.bytedance.net ([2601:646:8900:323:644e:288b:2b6d:d94c]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d87ec537ebsm63488986d6.30.2024.12.03.18.11.57 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 03 Dec 2024 18:12:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1733278321; x=1733883121; 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=081ar3D+q2I5dbHey0ExnsftyZ/LMfe2DNt/cF/PLBs=; b=CwUKRX9yc1EqNO9Y/guveAkQE8tY+hOkuR4KB/ne8BO3SFDYZ2hrBRajO7L3ZwvmKP XzDVg1QU1dndww63cPFk3VrSyta39JZnV1ozv2DRyzoUn9JqMiaZRWWiMS1diwP4Hnm8 iyGp1oQuIpX3bb4exHB1MpmSRzNIgB4DMOo3E10aIpulRyaFj/wM2/twAhEBUs5yFJxH ugj4vNNVn/MQRPnEOqmvAdRfsMsORLHXiJK1LulDPO6Bvux3iD2vjiGiXxhisxZF4Lwa WWYJJUCPH68eCs3fZB7P/LwRalxRuX8jTat4P8g9K47RKouDuzXr/sdE1URDOFFt1b4r atZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733278321; x=1733883121; 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=081ar3D+q2I5dbHey0ExnsftyZ/LMfe2DNt/cF/PLBs=; b=R+HXlykFFCpfa8UDhULcxStBJ5OAm2SACESicaJpWaYd1Jggu1vST+Ap8GbUkH5WLa i391MaLTIS6HfWwflMlVtqUONx/JmD8Y/mwcXNESRBhIG922TdoToFQDwykjQHQOexM1 cRwV9qqnFktnaB20FZIgBc0Y7kP7uxjhKc355KumQzEI5vY/4bjqy2CX6wMsngPW3FeM MdGN0Tycqoi8I4QZt7ntkKg3SPIftfXkHQj8rcHRhyOQpO82U3KrIgaN3ErlYcQBobJ4 jMtb7j22UC42JtVjkBCBrLUJ3J6GI4rNQYz2kXpqEFY0omia/2q2qoUEFVD5tsJUmfAD 9uoA== X-Forwarded-Encrypted: i=1; AJvYcCWx0Q70d65BoTFJEfyN3iDwI76caRUmPTLLUnZSqfHSDyekXOmve7jZJa3q60AFw1qK1y30oshMXfdh@nongnu.org X-Gm-Message-State: AOJu0YxHB00aFRDx0IUFO+At8TANUgO9mQ9aX9+m+LVizEBWL0aE2u1F /54Yj3/zspcMPZro3rERMCmMArmWM2+C/mCaLh8IMF/bl//rIj5gfg4GK0UMQic= X-Gm-Gg: ASbGncvHGzLoepRkGucwRN+5y4FHW0Eof315xM2/4/wWwRFU/ObZILPQMtV2MmP1xfD W85oQYB6G4j/G0tt0d/62X0RPliTEYuzyUyYc6g//O8avbUBphXw3W2NG3JOSbYeoU8ucNJKAF9 XIiKLqYHU9DtRwYJgS0PMhglvj3lob9/hAO1UICn+JIRKcvkWs0o0q31A9rorXJaZlZIFbSZN6Z Tu7zmNoRBdUr0GntIvttxcDA7EDV5pLyfksgG7gdj2/Qhpd4VWua+8nVYf901oXkWGPciex7HDL UK/h4fds1/yo2pctGg== X-Google-Smtp-Source: AGHT+IFPMp7SnZB+j2aApaYONqwE+4GR6+Yv2XqI/150LFU00r0dVanpAeD5J9wgtq27fwfAqrD8yA== X-Received: by 2002:a05:690c:4a10:b0:6ef:61b9:e003 with SMTP id 00721157ae682-6efad2f6fd7mr68582587b3.36.1733278320553; Tue, 03 Dec 2024 18:12: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" , Bryan Zhang Subject: [PATCH v8 03/12] util/dsa: Implement DSA device start and stop logic. Date: Tue, 3 Dec 2024 18:11:32 -0800 Message-Id: <20241204021142.24184-4-yichen.wang@bytedance.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241204021142.24184-1-yichen.wang@bytedance.com> References: <20241204021142.24184-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::1129; envelope-from=yichen.wang@bytedance.com; helo=mail-yw1-x1129.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: 1733278356197116600 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 Reviewed-by: Fabiano Rosas --- include/qemu/dsa.h | 99 ++++++++++++++++ util/dsa.c | 280 +++++++++++++++++++++++++++++++++++++++++++++ util/meson.build | 3 + 3 files changed, 382 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..fbf0dcd692 --- /dev/null +++ b/include/qemu/dsa.h @@ -0,0 +1,99 @@ +/* + * 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) +{ + error_setg(errp, "DSA accelerator is not enabled."); + return -1; +} + +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..57f1cbe68f --- /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 && ret !=3D -1) { + 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 Thu Dec 18 19:28:14 2025 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=1733278382; cv=none; d=zohomail.com; s=zohoarc; b=I++bY07MpFFmKdmXyYNyn8+qdsfMr6cyJv8buyxbyaH8wGNXsMljfhtc6C+0PCuPwUV3foYNMbOJDeuTd5wL6Q7hZfYTgGqFfeGc7J6qWv/5GZgfAAAiAXy+z+j21U0cp5DMDEpzRjQn65GdT3FpOUGE3TtYwpFDHlZvJ8PSTjc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733278382; 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=KnUY00dVfAj00E93vDwPcekd902hKsW3zrJHMP+oaS8=; b=e4xBUxbIF6faV5mtSI7m8cNRYU0a2iDZIFnNDFBzlIJL98J+rgl7J+6ltUPahKYsRnX6B5hpU6Wtgz7el8Hk2ZA/vV69hsLU3kicKCxMB8BxYO2Zs2SRW1kXLfTVfjHg5L0AxXBfvpbRvDQxP9cRXvTGqNdZxmP/QQ2gIJMz7vQ= 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 173327838270162.01383735768434; Tue, 3 Dec 2024 18:13:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIes3-00040p-Eh; Tue, 03 Dec 2024 21:12:07 -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 1tIes2-00040E-8Q for qemu-devel@nongnu.org; Tue, 03 Dec 2024 21:12:06 -0500 Received: from mail-qk1-x72e.google.com ([2607:f8b0:4864:20::72e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIes0-0005QA-Fu for qemu-devel@nongnu.org; Tue, 03 Dec 2024 21:12:06 -0500 Received: by mail-qk1-x72e.google.com with SMTP id af79cd13be357-7b66ea49407so44238285a.0 for ; Tue, 03 Dec 2024 18:12:04 -0800 (PST) Received: from DY4X0N7X05.bytedance.net ([2601:646:8900:323:644e:288b:2b6d:d94c]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d87ec537ebsm63488986d6.30.2024.12.03.18.12.01 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 03 Dec 2024 18:12:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1733278323; x=1733883123; 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=KnUY00dVfAj00E93vDwPcekd902hKsW3zrJHMP+oaS8=; b=cLb+/mLYS7nLseU6ny6I6CuLVXse5AlQ3lbC7SWffBes/VRJM9aKkgcZ06P+ZaYJxd S7johgVAPIK1ynEUKnhTVJ5KfnOn8Uf7B5Fd8TYJ5pdw7Ca3fVDGn6vdjcYOISloD9KJ rzEfSq8W9IjYtP/6sVafZqWy5bLNcglZ4wmJslF9nzS0bCF4ba9cNfyh70bKPXlawUs4 IIh23+S+BTifNOZ8Xj07lvyDugtaxt50J+wO2TRyoGWP9DrzPMsiN7wRy1j6KHvUxU1M /XHORjHfSOpKe1aobAYuvZWHlJP0Y9GWKCM+IQhLHEWADUBVR0csHmenqhQDJqYB6u0T Gxdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733278323; x=1733883123; 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=KnUY00dVfAj00E93vDwPcekd902hKsW3zrJHMP+oaS8=; b=OeOB2//zYyOHQREs02kY8h0CjRxCf6XNfdg3VJpffeZuSorzKGSujNRENupeqpMm0Y G4AKDA0aytn6OpVi42o7GbegK6YGoJUy0lmjC6HHygRYS8bW27XjMYI3H6n5SBli3Cw1 2XWL2PxlIMGBe79Hzbg5g9n/NQq5HsVGAx+mMxqXrr9s8bAEx+dzsGMX2cO8Zn2itPtp +lcNan8yVAxpTKgUZsXl6uQOISzAH0agOMdRo7GCDxAN7xfd/bQbK+t2laEgDcRuuHeT LaiGS3qBgdlfmap33G3hssYF7QhTlJXN6oFDFhtyHwqtqp1ouFjgWFgvpwZQexI6jpNC dbsw== X-Forwarded-Encrypted: i=1; AJvYcCWdwIVOUQ3zcYhxjUxXbe9m/nxw2NZNFdYHvkFKTW/DO8aT+J0i/9WAlfXulqp2wW4rFDmnp7BHR3JA@nongnu.org X-Gm-Message-State: AOJu0YxDyqi1t4HH0e7kpmTW24xKn+kE401FLS05CUAPEXdbylcHqmOr BkMLYaSvqlmDKi7KUc3+T1NtsE+op2YgND4YnhF4E2+d9AJMpraij8ApkH/delM= X-Gm-Gg: ASbGncsPMhf7l++0ggPDgPxrQJznC3BT2SzJwc+z4ojxb/qczlfiORmJRAL5IPhWdsq RZXxS0pIo2XKPIq5+gVlafpSGq52ppVPAaE8kf7d354XFR2AjRq0se9Lx3pbuVGy20oqtMA1+Hu aqLmNUMD+M3DzWkftWG2TXIkp5lTgxtGSe11WCQQHmxPTe10acWPLIjEy1lDpHadwyTNgrXsVoH 5JewbmAFn2283Nya0bGb4awF7yK5ZfglfJHM+4SKuDvNCfnXQjfYOIXOxEc6uhkIwatVjNGcVez BkaX2nyuFM2L2C6z/A== X-Google-Smtp-Source: AGHT+IGI4sXeCRpoqRq/aZDYYHtwGjmP6rV+MEy9cY0xJsvVdCQ2oPHPASr3b1AGYu4KvYvc1KntNQ== X-Received: by 2002:a05:620a:4588:b0:7b1:5545:7104 with SMTP id af79cd13be357-7b683961d86mr3979893685a.2.1733278323329; Tue, 03 Dec 2024 18:12: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 v8 04/12] util/dsa: Implement DSA task enqueue and dequeue. Date: Tue, 3 Dec 2024 18:11:33 -0800 Message-Id: <20241204021142.24184-5-yichen.wang@bytedance.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241204021142.24184-1-yichen.wang@bytedance.com> References: <20241204021142.24184-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::72e; envelope-from=yichen.wang@bytedance.com; helo=mail-qk1-x72e.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: 1733278384048116600 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 | 186 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 214 insertions(+), 1 deletion(-) diff --git a/include/qemu/dsa.h b/include/qemu/dsa.h index fbf0dcd692..a32b75c387 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 57f1cbe68f..8e78215903 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,182 @@ 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 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 +400,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 +448,8 @@ void qemu_dsa_stop(void) if (!group->running) { return; } + + dsa_empty_task_queue(group); } =20 /** --=20 Yichen Wang From nobody Thu Dec 18 19:28:14 2025 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=1733278384; cv=none; d=zohomail.com; s=zohoarc; b=IHmgWIs1xfMokeFHQFr2m3DNTLXsx3p/oUnbgSpEx+/eLGDLQbeVX77qi/x1n/iklDg+uMJRkQl7rwcBLRiyv6jUu3gGcaotl6Ga+HR4hw5mC7VRoY2Od6GmvDLm19InB/WsjHIHehZkiwsMzZ3uIXpKGuhFVH7A264/kQDPQKw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733278384; 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=WOkdQXfhMlMNsUsnnl15U7tgloUxCN5E+1OgsVHEgkw=; b=Icb/a15zpCJKHVgDIUn+W1rU6bavGPN8Sca8Yma8vAq3qSOUWquhAcItB9y1o+nxd6IQlBgwgnd3/UL3Vpn6FUQc/6zSxXLg5zm4Kx8nLW/fIGhZpnfeWIeGlvaZyMdxuelSSHSSbLmV/noICNquXsgiwYtTX5v4delOcrkjIg4= 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 1733278384726282.3226091950677; Tue, 3 Dec 2024 18:13:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIes8-000425-1V; Tue, 03 Dec 2024 21:12:12 -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 1tIes6-00041J-3Y for qemu-devel@nongnu.org; Tue, 03 Dec 2024 21:12:10 -0500 Received: from mail-qt1-x833.google.com ([2607:f8b0:4864:20::833]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIes4-0005Qm-7n for qemu-devel@nongnu.org; Tue, 03 Dec 2024 21:12:09 -0500 Received: by mail-qt1-x833.google.com with SMTP id d75a77b69052e-466a079bc5eso50406711cf.3 for ; Tue, 03 Dec 2024 18:12:07 -0800 (PST) Received: from DY4X0N7X05.bytedance.net ([2601:646:8900:323:644e:288b:2b6d:d94c]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d87ec537ebsm63488986d6.30.2024.12.03.18.12.03 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 03 Dec 2024 18:12:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1733278327; x=1733883127; 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=WOkdQXfhMlMNsUsnnl15U7tgloUxCN5E+1OgsVHEgkw=; b=Scj4yxEjLMxYn4LqV1vZdbeqX3W6GHhBF0UrsME580p0YFHTcW8htikspMJc4Fa7nY qH+gT+aeoRLgfxs2OORRgRNEKSpxLkr+q48OEAZ3K5gl/QCfMeeJ2Gn2JnTjlagOx1Q/ 2xhKNwWtC2o/+LCdkfZ97NELpqDELc1/FPaZh02wefCR/nC6O7lbRLdkxDe9FidKr4dq cP+1hd0cXlusQod0HQvoa/1OC/Dz0E8QaQRwdqKktoe2SOJ33TCDXhuOZtiVu+baKpLM U64VPAG9qNgw9Tzm50ZCIJypjhbXt+2QzWrHp7go3oqqBFbdOY+3KfTyBTRW6i7osal+ Ccfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733278327; x=1733883127; 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=WOkdQXfhMlMNsUsnnl15U7tgloUxCN5E+1OgsVHEgkw=; b=NMEjrF/hREQUYk7pV/I+XDWVDSiZ72WndTNA4RN5+Gim9AgxKTJ3+iHkq2yucJwALM p8vo6eMyrTiLCEXjSVuZDXYluri0jLFnFLY+mi9cqFn1xkU1iT7+Xu4M4g1PcikYSIck UHs0kLHJKIQ4rWMNZPJBimwPNYF7SHqqOa5Pkvw3VBRCU/pCzW2A/X+qmrdOUYWjG2qa L1m+wD4SU2ps2kYnhewKAPQS/qUMwCrPa+gegudnPcfZW1nWdW4rNQyf+Z/XjEkXL4fg 5npbXxEnpEFwPnurGf8RMM+v2FJDSXn8tw+dQlNty06zGDB2YZnOgCG3pmrDlEgb95Zv prNQ== X-Forwarded-Encrypted: i=1; AJvYcCVYgbb8m5h4H4Wuds5vHdovIzrGpHE14IljZGxHThYw1Ir1tz2Nj02UrGK0Y+2/hXhwj+yrqZRSNr28@nongnu.org X-Gm-Message-State: AOJu0YyMLcEeXqusdjaDTrmOrzmnFFlYnZnBt6h6RLarJAa/WXTGwkqL qUxOSy6f4Uu1Oh5RSvdzoe0RWfnVz4v9rAMVcX2dSw2YYiE7OGxgyh6LLqMVpiQ= X-Gm-Gg: ASbGncvJdmds8G38ZNhtgVjbLtdumaaEvgGAaOLHcGNSFzOWS15p8LWHbnche3tJn1H rvcbtslv6x3SI1vywnaRxqXi0qocRbcaXLwvzhmOWq/F0sUOZI8wT5SIPdG6Uw5GgLJ1bzFhY3h EuR+7KiswJqHvgBfR11BeahVeohBDx++YmuFK/GbDnNXxTQ3W07aFkPIjwGBzZuECVbokzqNoEr eoZpwrbALUH6JXnkpWlcpbs3Q2PDZ7T19TKtpko4La/a1z6wGB11Arym+b3BFmQuZEXDFBRK/Py QPuhEvNr5leyl2qJfA== X-Google-Smtp-Source: AGHT+IGHdK/+ieEW0Es2NWEaRArvYd3IyysXMFAMVlRMV50uMrJOZlqJoC+AbQbwfQg6MbftdqOpNw== X-Received: by 2002:a05:6214:d6f:b0:6d4:36ff:435b with SMTP id 6a1803df08f44-6d8b738a673mr88456976d6.20.1733278327207; Tue, 03 Dec 2024 18:12:07 -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 v8 05/12] util/dsa: Implement DSA task asynchronous completion thread model. Date: Tue, 3 Dec 2024 18:11:34 -0800 Message-Id: <20241204021142.24184-6-yichen.wang@bytedance.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241204021142.24184-1-yichen.wang@bytedance.com> References: <20241204021142.24184-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::833; envelope-from=yichen.wang@bytedance.com; helo=mail-qt1-x833.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: 1733278386120116600 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 | 272 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 272 insertions(+), 1 deletion(-) diff --git a/include/qemu/dsa.h b/include/qemu/dsa.h index a32b75c387..ca78b06069 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 8e78215903..5c4821e23e 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 /** @@ -387,6 +398,263 @@ 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; + } + + 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. * @@ -394,7 +662,7 @@ submit_batch_wi_async(QemuDsaBatchTask *batch_task) */ bool qemu_dsa_is_running(void) { - return false; + return completion_thread.running; } =20 static void @@ -435,6 +703,7 @@ void qemu_dsa_start(void) return; } dsa_device_group_start(&dsa_group); + dsa_completion_thread_init(&completion_thread, &dsa_group); } =20 /** @@ -449,6 +718,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 Thu Dec 18 19:28:14 2025 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=1733278366; cv=none; d=zohomail.com; s=zohoarc; b=GsNvA/q62CpxRPPvX0XTaFmnY21ZUOHAJV3tvj69dRkYDx6webUb3o2FYBvP9pK54YB/zKT+YQaA1JQertSKvWUFbXykTYXnx1Et9C+v/VZS5uNfQhnHCmoOQeP307d+4yYSwAQSB9ZWie8we5wY3elasBvAIiEngEleJIfQl/g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733278366; 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=e9vStfzUBxxgKVwIFXMSCX6zoPh5pwr3IO8YMjkQPUE=; b=jQcT1/xTif5+/vrwF+mIlyy7BctXGwJqvDMJbU51PkEZB+YNZUNSr1vW09s2zmpo2eMWyQl8qaK59aVdkbcqtuDkMuGly353H3oY/7dUPd3vkH9k0fUvWsC7jssuZoLKHS4GTUgrzEtn4zkSVmQSphkMkKDC3MNd9cj/MN2UACk= 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 1733278366153204.8137056127872; Tue, 3 Dec 2024 18:12:46 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIesB-00042l-FX; Tue, 03 Dec 2024 21:12:15 -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 1tIesA-00042V-5h for qemu-devel@nongnu.org; Tue, 03 Dec 2024 21:12:14 -0500 Received: from mail-vk1-xa36.google.com ([2607:f8b0:4864:20::a36]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIes7-0005R7-As for qemu-devel@nongnu.org; Tue, 03 Dec 2024 21:12:13 -0500 Received: by mail-vk1-xa36.google.com with SMTP id 71dfb90a1353d-515d0e09f2fso143924e0c.3 for ; Tue, 03 Dec 2024 18:12:10 -0800 (PST) Received: from DY4X0N7X05.bytedance.net ([2601:646:8900:323:644e:288b:2b6d:d94c]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d87ec537ebsm63488986d6.30.2024.12.03.18.12.07 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 03 Dec 2024 18:12:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1733278330; x=1733883130; 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=e9vStfzUBxxgKVwIFXMSCX6zoPh5pwr3IO8YMjkQPUE=; b=JOLO2WuOP9HmktqEhKyZLv/7kvp/E5HDegT+R8tQHVOqsPMK7Ko+Fe1Lm8/hV0YP0I zJYWW1GkxhcuT0Z65MGxjA3Vj9nnZNie4v6YkEQUNzVl98MQ35Mil6k0EeLIUESD0WLN u2iyfJJnUy235EnpCcoD/6HQFa8vkoj03wtW2j9ovpQYxQDBn//Fx84UTaOmDf7+8br0 mPHyHSbBerb9UgHjY/EJnMIViD9daULy0H5wnXk1aA8CRlpdjPW03WcHrdAq116vr9FL 2JfUjh3+xyNsqURdahq1YWLxeR6UV8L60KcM/YmG5wJ0vaJSQyQULA6YxEgXKNvlkOqH AYUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733278330; x=1733883130; 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=e9vStfzUBxxgKVwIFXMSCX6zoPh5pwr3IO8YMjkQPUE=; b=QVi2zc5otW1IEyf485m4kKDyFHtoPtYGdqi6ykMDC8fwBWrcRcdDchWXf7uZXQROML UytZ6o9uYXZG49cNUu/urIsn7eixTR0aRe0y2hZcjiJ0hiNuDB+/gmoUN5TZpBpQSWcr 9P/djWhh4TxevDfKy7oVaFpQfrhntD/EDfdU2jjUeGLwG0bcZ93HaP16mG7aLDZzAwny IS3/lObTeG77XwGEVxTIFQtr2KOvYbWr0OANkZJTtYmRsDdHrRGjG8b04EnX+tsqiS74 Cq6goRx3VEHge64q5nU5NLBg6NfvZeGthv2cny/EvjXj5/KLxNj47kHO72KQJDS5wgsx hUrQ== X-Forwarded-Encrypted: i=1; AJvYcCUmO5cYkUtScb6zhW8GZ4inDiJZx+r9UafapDTWuFTRkbS0Mc7Btj8FaAxp7oN/ZjQLsOoDBGH44CNj@nongnu.org X-Gm-Message-State: AOJu0YwuSUxNR/s9G7CB+0vOQt/0asGYrb9+Dw8wJHrfiv0bJzZWPOVu KdgimauIpekewRi7XQ8JCMcmQqbsNdrxws1V2F+URDfcBMHSn6FJ5LU83oM+/lY= X-Gm-Gg: ASbGncujk1U+37xaj9ILOsqyZzYrhthMfKZiiVw+gzNXmXbJ41PYhcTRMYW+pMXTpXi 5BF/XWFr1bQ9XkF3BKQpDEJ3VYaEW3rf8l1dIoYr9/5ZfMBGI4xauzTt/u7/TF2VJpE9kqHkfg3 +nB0xOfC89Vz9temYhP8QwKUfEdvrCvMeoqjalI7x482UnBDbddtz68srPSFGBwfrc7+J6wJcg+ WjaHRYjopUgxU9fsBsnazqVGJMmzzcYf8aZGjq3Xenn5wNZIC44RwWUECACaUMwYxItTsvEjZDF WqNksxemCFTR4QxE/Q== X-Google-Smtp-Source: AGHT+IH8+UqBanMKszF3Xt16iavdMG9NJuFGy5f3YBqsl2Bq36hvD3M0LTc34s4D5zjqxobcOu1ZOQ== X-Received: by 2002:a05:6122:2511:b0:50d:8248:83bf with SMTP id 71dfb90a1353d-515bf515260mr6733341e0c.9.1733278330146; Tue, 03 Dec 2024 18:12: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" , Bryan Zhang Subject: [PATCH v8 06/12] util/dsa: Implement zero page checking in DSA task. Date: Tue, 3 Dec 2024 18:11:35 -0800 Message-Id: <20241204021142.24184-7-yichen.wang@bytedance.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241204021142.24184-1-yichen.wang@bytedance.com> References: <20241204021142.24184-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::a36; envelope-from=yichen.wang@bytedance.com; helo=mail-vk1-xa36.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: 1733278368137116600 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 Reviewed-by: Fabiano Rosas --- include/qemu/dsa.h | 36 ++++++- util/dsa.c | 238 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 268 insertions(+), 6 deletions(-) diff --git a/include/qemu/dsa.h b/include/qemu/dsa.h index ca78b06069..a9aa394e5b 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; @@ -124,6 +144,20 @@ static inline void qemu_dsa_stop(void) {} =20 static inline void qemu_dsa_cleanup(void) {} =20 +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; +} + #endif =20 #endif diff --git a/util/dsa.c b/util/dsa.c index 5c4821e23e..a897ccac90 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) { @@ -346,7 +344,6 @@ submit_wi_int(void *wq, struct dsa_hw_desc *descriptor) * * @return int Zero if successful, non-zero otherwise. */ -__attribute__((unused)) static int submit_wi_async(QemuDsaBatchTask *task) { @@ -375,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) { @@ -732,3 +728,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 Thu Dec 18 19:28:14 2025 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=1733278399; cv=none; d=zohomail.com; s=zohoarc; b=S7x/DUe96I8upu0XSXp0Q5jbAl99rVSPR+I636QH0cfL5EmI3J5wdlU349ag/iTRXvWO8ZMoEm2+f9tSFb+RqaPmU8J92RcIHSKe5WOBoN6CmiSLTpxwzGV3GsbWNJUcEupyoBV14XUNvSa6YZafE71UsSZFopxbj21o8DWMvo8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733278399; 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=AmWLJIQJ8N12JbkkyHiQfgxCXrtZm1tXnIWK6/dvu9s=; b=THteWFgNTVGJxtmW8ypj1Xgzq6eDZAlF4DenWlIUK/qJZX5rv0ZSkqqfWdQcXqyGSunOeIgLY3u3MCKaP2P7/qAcS1lzg92JdB8wbm3fuGJ5GY93rQjoyJ+sUQ0sZ/Fz5SlFpGzyq6hWggcwdChSxe8Hx1UIDiWcaDGqonwMeGk= 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 1733278399968302.5893726033362; Tue, 3 Dec 2024 18:13:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIesE-00044V-3b; Tue, 03 Dec 2024 21:12:18 -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 1tIesB-000432-Sb for qemu-devel@nongnu.org; Tue, 03 Dec 2024 21:12:15 -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 1tIesA-0005RV-15 for qemu-devel@nongnu.org; Tue, 03 Dec 2024 21:12:15 -0500 Received: by mail-qv1-xf2e.google.com with SMTP id 6a1803df08f44-6d89811946eso27480876d6.2 for ; Tue, 03 Dec 2024 18:12:13 -0800 (PST) Received: from DY4X0N7X05.bytedance.net ([2601:646:8900:323:644e:288b:2b6d:d94c]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d87ec537ebsm63488986d6.30.2024.12.03.18.12.10 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 03 Dec 2024 18:12:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1733278333; x=1733883133; 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=AmWLJIQJ8N12JbkkyHiQfgxCXrtZm1tXnIWK6/dvu9s=; b=lQQPDHhnUCgHncdQhg8apmo7tBYPOVxPxI1/LRzMDnagxoYeG7PPPbuhJfq+jCUSvA 3AVA5MWOAlj41GHEniIE6pjy6kkX4o1iCJnQ+aDj77gZlfl1+fXZtrIici1CvMm3owsH 9dXQVo00KHR7QSNMs/jy/+yaIow/tY3zU2Kxxity1M7TiIe4vRzpxEG69UJdV/B/kyR4 vXSTkauOjpuWkL0JZ7/SNOyBICNFhUOdCWBmInRwvFb+00w4FsvWItf3Vi6dGe6HlKpI HqYuc0O/KwI5/7je3V7lQmtS9gQYvTXL8hcmXRTUgDhCq+iTaetPltoN/KMuI2ywxhcI y8mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733278333; x=1733883133; 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=AmWLJIQJ8N12JbkkyHiQfgxCXrtZm1tXnIWK6/dvu9s=; b=Kevd8nOP83yVSgD8L3IYbCDU7mzpLn9t9OM1EIUO6MNHXivjeQeQvEEKCCRKaq/pM/ z8KplDuphLEpRoUKV5p3SCtFyxsdJWvDdersVyO6zD3hxex1gN1dkPdZ+4TmhCcBkT+w 4uDXYzal29YByqqzbVtlEQVnMj+oQpQS9btDrqUVA8mwnAbFQ2tCzgAjMjam13UwtpqK r+4J7i8bvvlQEOFJN43HB+RezthS4qJPPeq6QB5KvHXu9Am+4y2+7GHSFOye3Y0aPagT ofSV+CCVp+Z68Uig5R6FinsaBQTMKSCCFsAYUvbCcEqqg5DzH5IaokwpHDTGAjOpFUxn Ysjg== X-Forwarded-Encrypted: i=1; AJvYcCV9RoIZA5nBOjfFzHmpYwwK/adOOhVgp3UJAbqCOCR/OLNkH4TYkt3PEgp2gMwOdV4jjv9/9UWONTDD@nongnu.org X-Gm-Message-State: AOJu0YwqRv4N0OuL2jiKVHgTLKlhm1GuUBwE72uiPwYWV7OaBqHNxwJl wDx/6QeqRDIWcEwilju+suWIMqtwgZsffPxh8exrYw8y05YEE++3grk/UW+cV2Y= X-Gm-Gg: ASbGncv++dZ7ol4uPZU5Oz/GivXigeBUj2shwMFQlkRZWUd2gyR1wqDO5SqCf9PcXve xGjjpA03gTDq1ufizNxxFQ4Eivd+hRZAnYFtQLmYIIEiHG3RXCYRYiRDq/YUW6tTHvFLQqRUVo7 Aii/mDk3v5OdAve9w/UY3fhqeZNpWA6nnluL6QVALa+nQmuTse4/5SEoAz48i/xU3bl6XIkmtog +9wbpgpAkoiUKjhfsgn1XxkGPdRU1NkNJULQCUfHtoanJ4XnnJ0s9UNPsp35i/HEJg6x6eP23Vw rnbUNZLDIfjNS34ZtA== X-Google-Smtp-Source: AGHT+IH4HNXO428Jp9onbiLf0da8k0EgfQ8EREF6TkS7WE68vEyOY4euq/SBf9OcpEyOcGMaj4EuRQ== X-Received: by 2002:a05:6214:1312:b0:6d8:af66:6344 with SMTP id 6a1803df08f44-6d8c443d31fmr45981306d6.2.1733278332962; Tue, 03 Dec 2024 18:12:12 -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 v8 07/12] util/dsa: Implement DSA task asynchronous submission and wait for completion. Date: Tue, 3 Dec 2024 18:11:36 -0800 Message-Id: <20241204021142.24184-8-yichen.wang@bytedance.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241204021142.24184-1-yichen.wang@bytedance.com> References: <20241204021142.24184-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: 1733278402140116600 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 Reviewed-by: Fabiano Rosas --- 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 a9aa394e5b..4972332bdf 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 a897ccac90..e6b7db2cf6 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. * @@ -559,7 +595,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 @@ -827,7 +863,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) @@ -846,7 +881,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) @@ -877,13 +911,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. * @@ -960,3 +1042,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) +{ + assert(batch_task !=3D NULL); + assert(len !=3D 0); + assert(buf !=3D NULL); + + if (count <=3D 0 || count > batch_task->batch_size) { + return -1; + } + + 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 Thu Dec 18 19:28:14 2025 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=1733278390; cv=none; d=zohomail.com; s=zohoarc; b=C384qQgptYkFyx6mcXWwNOaPhWBSCri/s3CyuY6wHzDKYnjOkTEGiaV7hq6i4NkEvY9ptHREIFxcfRJzNjMN+nAAXKw7ufzOy9mRG63yN5bgJB76gWjYDSUSUtaNfTSVFk8YULNLQkjU7DySAii6501bHSOCiHOpSXHq6QpIs00= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733278390; 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=GBxKBMcgm24PL+d/ZdkCtapbZJgYee+RaBCTcWpygwU=; b=jcG7hF3oMKY8ntKYVlH9GbxOJGg1gLoZY2siyhAj0qanNDHVWOqHm+M4KBmtzFSITMB2XWGALgfU6yLNKH0IdLX3/mIH6tWXQehqmPgP4GGkKFlVD+Waq0vxxg6teAaHfiJ1quc4uyv1Ki2yQ2SQXp2dub1frubKSoZwPhrTt7E= 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 1733278390919313.42433131147493; Tue, 3 Dec 2024 18:13:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIesL-0004CU-Vf; Tue, 03 Dec 2024 21:12:26 -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 1tIesJ-0004Bn-Qw for qemu-devel@nongnu.org; Tue, 03 Dec 2024 21:12:24 -0500 Received: from mail-qk1-x732.google.com ([2607:f8b0:4864:20::732]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIesH-0005SH-Jl for qemu-devel@nongnu.org; Tue, 03 Dec 2024 21:12:23 -0500 Received: by mail-qk1-x732.google.com with SMTP id af79cd13be357-7b6662bc408so487526585a.1 for ; Tue, 03 Dec 2024 18:12:21 -0800 (PST) Received: from DY4X0N7X05.bytedance.net ([2601:646:8900:323:644e:288b:2b6d:d94c]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d87ec537ebsm63488986d6.30.2024.12.03.18.12.13 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 03 Dec 2024 18:12:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1733278340; x=1733883140; 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=GBxKBMcgm24PL+d/ZdkCtapbZJgYee+RaBCTcWpygwU=; b=AzKZMBjrSG9L7MA9pFZe072fErYH60trLsYYOmOtf+XDmphuOAaokqL8PP3Q4Z964t rExigN0R6qKKBtjtUXdGT5yEn+EfUyg2FvBW/4EJ0qW0ssd4bvhFghyav8uz4oMrJa/g aiING0qXPhzpcj7fLLZRXcqQwcWEi5xYWAtN6o8IKrQmXeS4aFa8/1ul+rull5SFZxWp /PRe/+02KFW/O5yNNI3lCkpTgjwhkU0g5NJuVMWcEKe0WBImlH0gnjoY1JmF9uZ7XrMz yWHc/6NRUEA7tACpDK0DgD09B1cYi+FUqPsshJ3tRSyl3lewWt9mcOYABgYR/GMBJz/B 7Scw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733278340; x=1733883140; 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=GBxKBMcgm24PL+d/ZdkCtapbZJgYee+RaBCTcWpygwU=; b=jdyN6SK3fJsdar1OVSnRld/hmKOdF+HCsbKPlpGvMosduSvR2579OHtQ48ivOKnmIF 45gJ+7kepiStZLb7emWBHDbU5FmW/y6XtiiaX4FczM+4p9n0dbsre8CZGY3Uu5SkMmYl GX0tWNr3+tcm67xZjNwDfKLMvAhWR5Vll2aYCqPLbuBbE5lPdN5eUOg5132xpUol+yB9 UXFZs5Z94YtW5bsA/hk5RWT+eNdN0T68Jns3IIrS/WKkKq5lcl573fV4MgDjPmMHjvQm 2dEw9XIxM1WSt9hgwA/1Vodcz/WD41TFpOdTx5SdOQprowqVLN/y1Lca3R6OrYJjc66t /Crw== X-Forwarded-Encrypted: i=1; AJvYcCUEiuTYRnxOtKEhzcCefFLS6GuYjMNbA3AZJeMv2xWnWrAqzG8QkoTdWY69mm8qLTsKZazbTZI0zEzs@nongnu.org X-Gm-Message-State: AOJu0YzcxBRFUkFANt9ZktQFl1A6JBJL/Vz8WT7DD8fVk1vhzWQA9yxv OhAvv0L1+zlFpjipJMlAy31xuS6B1OQ5SAwfkpLb7qvDkhkNG0oi1aNYfBYQzmE= X-Gm-Gg: ASbGncvrcnhagGs1Zn8IDsBc2TNSybUbNi+BLyf2X1T0Vu0+4Lmb6dRXfV87Ndh4tE2 O8BtDr/fEcGyTiy0V5ULg2K19oEFFBSYRWBnCAQ5+a/YYKJ2xAC38EMb75hd99X5uO4611JaHtf jnu+0vSJKvHSaqjMDWtxNIkrS5CJhxdyANMgdxTsWrkx+KLWaVQ65rUGTnc/A/u1RRdAIlxNQsG BCO8tLZI25cwpIPmRVo7go8lI8qs5N/35XNIAqeOGDmccKA2t2fJ5e+vuXlKiXFp44FFpaK116L NmvAO7CklSZjRlikzw== X-Google-Smtp-Source: AGHT+IFzmtbRz4cfCJTgTUGON7gj9m7MqKwmSjVEBizNxCzQ6qfZJaQyXqWXZ2b9HQEVn20lG6B2Cw== X-Received: by 2002:a05:620a:45a9:b0:7b1:41d9:7b30 with SMTP id af79cd13be357-7b6abbc0a20mr414661485a.60.1733278337318; Tue, 03 Dec 2024 18:12:17 -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 v8 08/12] migration/multifd: Add new migration option for multifd DSA offloading. Date: Tue, 3 Dec 2024 18:11:37 -0800 Message-Id: <20241204021142.24184-9-yichen.wang@bytedance.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241204021142.24184-1-yichen.wang@bytedance.com> References: <20241204021142.24184-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::732; envelope-from=yichen.wang@bytedance.com; helo=mail-qk1-x732.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: 1733278392241116600 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 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 | 20 +++++++++++++++++++- migration/options.c | 30 ++++++++++++++++++++++++++++++ migration/options.h | 1 + qapi/migration.json | 32 ++++++++++++++++++++++++++++---- util/dsa.c | 31 +++++++++++++++++++++++++++++++ 7 files changed, 123 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 4972332bdf..18cb1df223 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..3bb8d97393 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,15 @@ 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; + 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]); + } + g_strfreev(strv); + 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 e6b7db2cf6..a530a607e7 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") @@ -687,6 +688,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 Thu Dec 18 19:28:14 2025 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=1733278366; cv=none; d=zohomail.com; s=zohoarc; b=MHP3GA5nh0IoPdO4gq1+yTphxa+u5ASzpikMWQAbKWGoL/sVA/KkOjy20LABhMNBhTYAzhN6kGGxX4BdnboemQaLhWXrQ0hOPywL3vXyEoHfEX6Z3+bOl0pBW3VsfOkcqEprHkXqSCBLVhP+rPClgdacnZjpez84GOGaV+om8js= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733278366; 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=bbUPrKbHo+ydSUVTX+fN/+RwQV2PeUZSPIiRYWjVXn4=; b=LpGC1eUaCpT9uGn6WhCC5IhaAAl/ifCPWI4fy7IRbN79O0K2Xr5a5xxRvxZ6oBmZamEA6P0dd3PiYRxxj1dbqdGuZzbh3i2gZVhlR56/PZVD86vtE02pXFlo2G0YaNklK3ntAYkTEVO2ORee6IkLpbFYi2WrgnGMcnAQkFE6rfQ= 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 1733278366262998.3603665965583; Tue, 3 Dec 2024 18:12:46 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIesO-0004EO-SO; Tue, 03 Dec 2024 21:12:28 -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 1tIesM-0004Cl-Iq for qemu-devel@nongnu.org; Tue, 03 Dec 2024 21:12:26 -0500 Received: from mail-qv1-xf35.google.com ([2607:f8b0:4864:20::f35]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIesK-0005Sp-9l for qemu-devel@nongnu.org; Tue, 03 Dec 2024 21:12:26 -0500 Received: by mail-qv1-xf35.google.com with SMTP id 6a1803df08f44-6d889a1f7a6so32008916d6.2 for ; Tue, 03 Dec 2024 18:12:23 -0800 (PST) Received: from DY4X0N7X05.bytedance.net ([2601:646:8900:323:644e:288b:2b6d:d94c]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d87ec537ebsm63488986d6.30.2024.12.03.18.12.20 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 03 Dec 2024 18:12:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1733278343; x=1733883143; 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=bbUPrKbHo+ydSUVTX+fN/+RwQV2PeUZSPIiRYWjVXn4=; b=fsbrdK4KbD6YF0oQHNdXwUIm1BwZhsgmYJc8V2dbgt2rYe3DYAe+Jb08+qH6mYWUQJ CU3Gtpisj/pQaF86cYTJiJ+sbIYDQepWDQM7T1fUttQYfYTh0T1FH3B7LYyUPZmfXsVj WODPIKnc66XAH3Ze/UkMBrRpIO5efC4RMtRN91tBb9lsEz+aZQ5i3/+ILAeRnI7jMPmW 544GxwIAxEU1Sb5g7T1Ev5kJfF7KnM5vmWC0UQuQ1eCcGzwJQWj8Ifkx2JTyoH6uYrQd 8Hs9eDt2JWuvr+QAgE4jSVCggMyL4PFIP1/I//4LDljDsB0H6k8ifMNG8+ZpPyV+6v9L Aj2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733278343; x=1733883143; 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=bbUPrKbHo+ydSUVTX+fN/+RwQV2PeUZSPIiRYWjVXn4=; b=oGs+RoyrkeBApa39lE4JwbnDwh8Az3C2KW+U2trQdniIqeguVEwhPN1OpNFH8gqBEG HKWj1DTEsXD1SgUXMemjOyX+/6KHU65MJ8oI6gDPztV9VY7xBy/j8oY3ZMApGtDzhh5w tdoV/39Cw3LLbw4mRjN4rSuL+Vu7FFfzWH/B3cWQ6/9fFS9PyklkY9UoyY+gpMXDbr4/ u8ZiX4fic1v/V6usRKPSBQQCjS/mEdlEw8r7JSBp3V5EBulzfwdTKO6hPVQkdIes7FLJ /+B0VuUWGoj/3ldZEbAYSeuafj2QhEZIrrv0xpkPR8tNbKn7KijWGGdILYeQy4WyQze3 2VWQ== X-Forwarded-Encrypted: i=1; AJvYcCXvZBHO4CQCmvqemE+mJmSUITP3thSVBnBbDMA4+TbfNx0MO/5nwTotlzgef6uswQ2CvJ1gvuHv92sB@nongnu.org X-Gm-Message-State: AOJu0YwN3wTUcBjxPin6tcu3keptdQdvYfxvEcTaKoTUJDPTx92DfMy/ r787K1niyMH6oMir27y7nNkeZvCtKXWv5f4mO1V9VACqbjJn79GuMR2MFLI4ZoI= X-Gm-Gg: ASbGncttOHBxFxp+qRkNaNksH9RWmi/P93y9kTHN6XtFxU/N+/DfF4Pe/J8THVrTft+ muVqD6NLnOu4XOsjW6fN7Fr1HOXI2GhYGy8SJfygiu11VrzeVVrbxlFHB6Dg7YZHRtAbBK7R3GU HbFPQxpiM0eAERa+iBjZejY7tyS8DPNBrBm0mWjxs905fVWYigCaF4ZkdhD+Q8O8W2q1d3+G15H SjSNkIJwosMcR7cS+asrJQEr1YGWqtYV/vHaRgId9W/L8j6aTeatG2Aa8xaInY0DY+7wDZpOZg5 t0eeonVp1N6XM4Mi3g== X-Google-Smtp-Source: AGHT+IFQmwqIhGpPgUt7laPiHHGAkBJDN0c22tEOFX0SMoS+fkdAmSpPYpX0ITZOOXHUbFc8x2jUfA== X-Received: by 2002:a05:6214:c25:b0:6d8:a148:9ac1 with SMTP id 6a1803df08f44-6d8b7440996mr79555036d6.47.1733278343251; Tue, 03 Dec 2024 18:12:23 -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 v8 09/12] migration/multifd: Enable DSA offloading in multifd sender path. Date: Tue, 3 Dec 2024 18:11:38 -0800 Message-Id: <20241204021142.24184-10-yichen.wang@bytedance.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241204021142.24184-1-yichen.wang@bytedance.com> References: <20241204021142.24184-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::f35; envelope-from=yichen.wang@bytedance.com; helo=mail-qv1-xf35.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: 1733278367922116600 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 | 149 ++++++++++++++++++++++++++++++---- migration/multifd.c | 15 +++- migration/multifd.h | 6 ++ migration/options.c | 13 +++ migration/options.h | 1 + 5 files changed, 168 insertions(+), 16 deletions(-) diff --git a/migration/multifd-zero-page.c b/migration/multifd-zero-page.c index f1e988a959..08e7fc3d92 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,59 @@ 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); +int multifd_dsa_setup(MigrationState *s, Error *local_err) +{ + g_autofree strList *dsa_parameter =3D g_malloc0(sizeof(strList)); + migrate_dsa_accel_path(dsa_parameter); + if (qemu_dsa_init(dsa_parameter, &local_err)) { + migrate_set_error(s, local_err); + return -1; + } else { + qemu_dsa_start(); + } + + return 0; +} + +void multifd_dsa_cleanup(void) +{ + qemu_dsa_cleanup(); +} + +#else + +static void zero_page_detect_dsa(MultiFDSendParams *p) +{ + g_assert_not_reached(); } =20 +int multifd_dsa_setup(MigrationState *s, Error *local_err) +{ + g_assert_not_reached(); + return -1; +} + +void multifd_dsa_cleanup(void) +{ + return ; +} + +#endif + void multifd_recv_zero_page_process(MultiFDRecvParams *p) { for (int i =3D 0; i < p->zero_num; i++) { @@ -92,3 +153,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 498e71fd10..946144fc2f 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,17 @@ 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) { + ret =3D multifd_dsa_setup(s, local_err); + } + 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 +840,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 +876,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 +1057,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..da53b0bdfd 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,8 @@ 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); +int multifd_dsa_setup(MigrationState *s, Error *local_err); +void multifd_dsa_cleanup(void); =20 static inline void multifd_send_prepare_header(MultiFDSendParams *p) { diff --git a/migration/options.c b/migration/options.c index ca89fdc4f4..cc40d3dfea 100644 --- a/migration/options.c +++ b/migration/options.c @@ -817,6 +817,19 @@ const strList *migrate_accel_path(void) return s->parameters.accel_path; } =20 +void migrate_dsa_accel_path(strList *dsa_accel_path) +{ + MigrationState *s =3D migrate_get_current(); + strList *accel_path =3D s->parameters.accel_path; + strList **tail =3D &dsa_accel_path; + 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; + } +} + const char *migrate_tls_hostname(void) { MigrationState *s =3D migrate_get_current(); diff --git a/migration/options.h b/migration/options.h index 3d1e91dc52..5e34b7c997 100644 --- a/migration/options.h +++ b/migration/options.h @@ -85,6 +85,7 @@ 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); +void migrate_dsa_accel_path(strList *dsa_accel_path); =20 /* parameters helpers */ =20 --=20 Yichen Wang From nobody Thu Dec 18 19:28:14 2025 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=1733278387; cv=none; d=zohomail.com; s=zohoarc; b=UUigg3RgFKaU0gAzrD7xLcShL0dqUhPg1bi0gpD1DK1yid7Olu35CyB5ep9u3iSLS6r3jnl020hrY5WbfBDhVYRnIH9l9+mZff9Iin0CEsFlnuUYh1vUhNe8su6cP/yT+KI8bTU5d8CcMtJuKo1cxydJ7BOjwXjy6WHXLmGsRn0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733278387; 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=cDtxZlQ+AF2u0uvmdF+y4/B7uIYqaZhzDq0i7qtKaqoTkpuTQtrYoLND/cgbnjPtc0e3h5HcPyHgde5+orOzShNiNjNLOBS4dwd0qeN1vZkqxA0W/2uX1+ji/zDfOdGrxPbTIscGtbJR2igZReBkmS5H/uz7TTIXdT7kRiJhFp0= 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 1733278387069791.9349511571053; Tue, 3 Dec 2024 18:13:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIesY-0004M0-03; Tue, 03 Dec 2024 21:12:41 -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 1tIesQ-0004FD-VP for qemu-devel@nongnu.org; Tue, 03 Dec 2024 21:12:32 -0500 Received: from mail-qv1-xf29.google.com ([2607:f8b0:4864:20::f29]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIesO-0005TH-FQ for qemu-devel@nongnu.org; Tue, 03 Dec 2024 21:12:30 -0500 Received: by mail-qv1-xf29.google.com with SMTP id 6a1803df08f44-6d8a2d0588bso22642476d6.2 for ; Tue, 03 Dec 2024 18:12:28 -0800 (PST) Received: from DY4X0N7X05.bytedance.net ([2601:646:8900:323:644e:288b:2b6d:d94c]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d87ec537ebsm63488986d6.30.2024.12.03.18.12.23 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 03 Dec 2024 18:12:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1733278347; x=1733883147; 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=LrJNljUkbucNOvIGrodxLtFkgF+CvvIkBtfp1+1dKMfM+yfhu4USwuVj/Gabi/EZnw 9saCC17rdkEArPVP1blSI/HmHOkXNUdMHMkvtzvaafiwPRr7FTc2ZAXG9FPQQzrBbP61 Z4zyvrzyjQgo/zhSbBAgqWHkggPmcPmUJOU4/LGZPBSgaxXNcyZIyupmcR4PN00JUHPu G4xBOBZPGEOmOEERqwRWmTUvwCWmKRI+OYKum97L8jPUsD/1n2OpURG/edCkkF8hB/sG 3XGUbPUihxguQggpW6NcWUW6THGPp1byOTA4i1115wdcgIUlIX7646gmD+7DU41rN7PX S1lQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733278347; x=1733883147; 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=e9EDEzAo+diGG2UKZAZXYMfSy54grZjuWzOS8cTz+7SFlXEBq1eogzON5rF/VRotM2 HReNhAwdOdGY9mc5EeDmEcL99sIeD3BavxuQ1E4sTmJrhPNxlpPNBTe3Wk/mbMdVKNFm A/QjLUycJiXaO2tgcs+GabxFkGBgKvU8d4A1ie3j8iA9bQQJKq+YDyrJMXoPmXiOV0E+ vfZdQ/bjoHj+Df1jhnF7THthL8AA59nyJWafXXzlEVfOI9Bot1Hv4gKqGszOBYjKe5h+ B/regO5fEYfS17JJQajk5MTJ5WE/octDEhptdwjVrTA7w4MDqV7iF55eWb8JKePSf0G+ Dx0g== X-Forwarded-Encrypted: i=1; AJvYcCWSFzKCmrPfiMwy5rEFSjRSVxB+MPuURwkGOHuJZOKaeB6o2tOTP/57yv/xem6c9bEWKG5Y2BiBKT1U@nongnu.org X-Gm-Message-State: AOJu0Yw4JFg9SCCxET+K0dr7tiWsJ4HTFQS8MMi1JDM3WgXXF/0oMnBU iVa687Ud+gy2EvVQEmG4TPI55skFudmcDm4Xcfhwhdg4i+7L+CcgpN0rbSRU4gY= X-Gm-Gg: ASbGncsjV6x/ItMdxvKTECDa3fPgJDb3u5vKp4HkqchR3sAM0hVQlhOHzoLeiVC6hEK wqIEsHab5VtF3pqQcKgR0Lz7ARG9jHxzIW8LePLb2WRY7PzNp6hyKu5eYL5jsLW4ATkWjpIlSdj AOXOqg6ifOjJxkQVkm5twWnFkk0nkP3ZNsWaoQJYbfjYGcsZkDOGa8jfe7dsReWucniLbcV3Avz RraLhqcflRGAq59zMq40yun3ZIydwMEdovxWpaeUAMsazBu1eeVG+dVS0x2ln0MAmuvNBXekgdG chwChq6wyt9WDNDDWw== X-Google-Smtp-Source: AGHT+IHoFSfav35xkAG7BrkX3muG1R/g0Zz9mbP0fZSgxb8nwdOM+rV3l9b+a9Zlnvx/r8QBhflscg== X-Received: by 2002:a05:6214:21e4:b0:6d8:a5f7:f108 with SMTP id 6a1803df08f44-6d8b73a5492mr86480876d6.26.1733278347365; Tue, 03 Dec 2024 18:12:27 -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 v8 10/12] util/dsa: Add unit test coverage for Intel DSA task submission and completion. Date: Tue, 3 Dec 2024 18:11:39 -0800 Message-Id: <20241204021142.24184-11-yichen.wang@bytedance.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241204021142.24184-1-yichen.wang@bytedance.com> References: <20241204021142.24184-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::f29; envelope-from=yichen.wang@bytedance.com; helo=mail-qv1-xf29.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: 1733278387910116600 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 Thu Dec 18 19:28:14 2025 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=1733278397; cv=none; d=zohomail.com; s=zohoarc; b=lxmDDSHgGLppQa3Ps3lxIt7dNuIkjadhrBU4F5bPQyCAiVc1M4IctD056eU69MMneTxNxomFObNVqb8QpyfGzf5AkuwDErqWWamesfMmn8n9F4dUWGpFhFQ+f5Eb3xiNZEXSTT45lGsCBm4SBFW6+cKREWTDQez00jMfCWLdJRk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733278397; 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=yMUZjSVVMo2pOYihqAfV7zRvytzhfUlPnoItmHg7JkQ=; b=KbAG/Vr446ssfAIZ0diLzw9lBbR01RUJDGyD6MgDZV47uz0MIo0GOzlis0GI+L3oFLSFaQ79kvBQ8Jv4peiKRpyupajRXek+1GfXUqXNTF4SP8MSy9auBaDeNu8tqRNNBHrm70/RdzAtPWpoksX3vuJhY42a271CQxQc4giatYY= 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 1733278397811357.2066328855599; Tue, 3 Dec 2024 18:13:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIesh-0004zq-Fi; Tue, 03 Dec 2024 21:12:47 -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 1tIesU-0004M6-1u for qemu-devel@nongnu.org; Tue, 03 Dec 2024 21:12:36 -0500 Received: from mail-yw1-x112e.google.com ([2607:f8b0:4864:20::112e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIesR-0005Tk-0y for qemu-devel@nongnu.org; Tue, 03 Dec 2024 21:12:33 -0500 Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-6ef402e4589so60808307b3.0 for ; Tue, 03 Dec 2024 18:12:30 -0800 (PST) Received: from DY4X0N7X05.bytedance.net ([2601:646:8900:323:644e:288b:2b6d:d94c]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d87ec537ebsm63488986d6.30.2024.12.03.18.12.27 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 03 Dec 2024 18:12:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1733278350; x=1733883150; 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=yMUZjSVVMo2pOYihqAfV7zRvytzhfUlPnoItmHg7JkQ=; b=Y2uHKp+RbWMDd9L5ewSZoWoxLIV+VQcEsqkJ1p4Zm7F0tMGr+2Ls7tnjtCcrTKG9Tj rJ8CAE1PZWrdfUOqejCgBAiiKmjCo980Q9w1/WW4Lr5PbSXkpLx1JMSk+Yj/q8h5m0wA i4WFEtCYRbGNfjKdto4GOytEB5JsUO+Yji5mVhrbmCoA87DvfL5tL/SDTnLo2Kkgmbjx dap/J3HKu7HiZ7JeGP2jdrAerzTq7ULpr0sDvj35xj65wY5iy0c6uEl51VyhPDdXHxBJ 8VqXndyqVuhRjsb3gdou0v50dfy9PGrHl7hx3PbC+jbRJqYcrH24NvbG0tXbRap52X58 G4VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733278350; x=1733883150; 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=yMUZjSVVMo2pOYihqAfV7zRvytzhfUlPnoItmHg7JkQ=; b=E2qZY5LXU/3UO5WLXIzVNz9e6Mw7dC2ZBnZzW05SSQMqP1suwiaUbshE9CbXzUHjrC e3/L9ujbgoFR2dzwEZvcS9YxTN5b5vjiJc6taAljif7Fqu5SlEjnTU8Mvax1qxJIJiEv 5s+6yawH9NFn3iXqkwHsNdIn2L9WW5GKz3tPsitHeSJ6dDWiaHdngMzVeGm9m7eGTjg4 xojq5NislZ+96IJAujDP8jmMbkGeeT08LauH5XiD7ZFLnipEYvIG9QPboUnCzj6KV45q DemoZ+SFAldRUPD6AhMSiICoZsaqyYkgfXrvODMmqqB2K4HOtRKfLR22EyrjMBjNiBVg K48w== X-Forwarded-Encrypted: i=1; AJvYcCXwLRmRpANpOBGIb388Dto2DrnH5Hto6xh+2vNw4bWwi04fMR+cRcsmkSeSPJWux7XiVvPAHvPU+pmy@nongnu.org X-Gm-Message-State: AOJu0YwzhUtJ/90+yxbQa8kYwdGnmqhTRh7VH5cEWwJj57YV7vguJMPa 2F7bTIZMzS+bndkoNDUIftn4h3G1nPSmRPPR+eBe+Kgxbwp4PdGgyvOZf272kfc= X-Gm-Gg: ASbGncseINQQpD+xuNelx/55BCUg4Sx/8+7XmOtL3d4BmVdm0VciH3EqoFbegCGfr3q y8SGO98a+UabucQFCcOOuvLLa9fDwnGr7B+2ZYXYmWaCi/+1zwe44FNBtjmShfA43dHOPXQ5Dlw mzfdGcAhwV1ewulVkHr5oYodTHU/qPmQB4tEYquHG+kLA7sW7rXPHfiFMOBNpbA2TU74YRNOT0x AtKx6EpO3xce9DiknsW7t1pEYCBRJ9AHpK0omQNOQF80XGx1Q9PL9OAKBdq5tTNN6wW+P3qN7jX UiLP8UcfsPHw+4cbrQ== X-Google-Smtp-Source: AGHT+IHLzlBpsbMLVMYog1iK9ht/ElBnpnnRjfixt+PLy/Dn4GTT53borTiQmE58VJNzX0ZpL4zf3Q== X-Received: by 2002:a05:690c:48c8:b0:6ee:988b:16d4 with SMTP id 00721157ae682-6efad1dcfefmr70261077b3.29.1733278349983; Tue, 03 Dec 2024 18:12:29 -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 v8 11/12] migration/multifd: Add integration tests for multifd with Intel DSA offloading. Date: Tue, 3 Dec 2024 18:11:40 -0800 Message-Id: <20241204021142.24184-12-yichen.wang@bytedance.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241204021142.24184-1-yichen.wang@bytedance.com> References: <20241204021142.24184-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::112e; envelope-from=yichen.wang@bytedance.com; helo=mail-yw1-x112e.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: 1733278400145116600 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 Reviewed-by: Fabiano Rosas --- 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 74d3000198..e1cef36143 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 @@ -3266,7 +3272,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, @@ -3286,6 +3292,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 @@ -3344,6 +3355,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, @@ -3774,6 +3828,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; @@ -3986,6 +4054,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 Thu Dec 18 19:28:14 2025 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=1733278444; cv=none; d=zohomail.com; s=zohoarc; b=nD5HRQwCbq0tei5Ef7L2YtQnZORKmOWyybMj0fDwS86AYjRQJhUCEFmNlS6R6GMYS7nJcjh59MxpXT19jzTlCeW1ptOuRZfmo8iTtKOfK4MawSMeRlLhgVNQVG/sjL4/UBzHs/T6PnHG+KiXeplyMWCaOy2Ofo3bB3zOfRPFsXY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733278444; 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=K+SlF2FR3ZV2vuRhtIQV4BC/j1/AENizpBsFIvnrz4w=; b=djrZZix6VqAW5zU2Dqt6bKOixurD30VGQRYx9tjkieRTJaT0i6nVGRhIwpN3rywWLkff9FUWxrLu+MElO9hCiZO1DjN0DRmr9QRxw6mnisd1cHQ2vUWScmpYSp/ztAD3kCglHj780X8y1PR/NM+UNX/MYyyN1euF8PZm/3S2leI= 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 1733278444328445.3582370918092; Tue, 3 Dec 2024 18:14:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIesg-0004sI-0N; Tue, 03 Dec 2024 21:12:46 -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 1tIesX-0004e6-MX for qemu-devel@nongnu.org; Tue, 03 Dec 2024 21:12:39 -0500 Received: from mail-yw1-x1136.google.com ([2607:f8b0:4864:20::1136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIesV-0005UV-AN for qemu-devel@nongnu.org; Tue, 03 Dec 2024 21:12:37 -0500 Received: by mail-yw1-x1136.google.com with SMTP id 00721157ae682-6ef7f8d4f30so37380077b3.1 for ; Tue, 03 Dec 2024 18:12:34 -0800 (PST) Received: from DY4X0N7X05.bytedance.net ([2601:646:8900:323:644e:288b:2b6d:d94c]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d87ec537ebsm63488986d6.30.2024.12.03.18.12.30 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 03 Dec 2024 18:12:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1733278354; x=1733883154; 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=K+SlF2FR3ZV2vuRhtIQV4BC/j1/AENizpBsFIvnrz4w=; b=ZSYR9QAcTD8BO11Sh+YXTpwXM0zYrbA0v+9wUQNnjM0i4gQhsejmcS0u0SkLttKe9v zP7h0M37aK/BY+kDm7qOn3xVzRLyu2WrFwiq79Af8HA8p60WDXN+oYvBY8waJ5i7LBCq 2SQz+pi1rP7PZbKc0yU/kS8SgcKHN/Rt/BOwaPIaGj0NqjkGZMXJdyI5cWi7yRmuPgda Iw5bwfxun3PhxHbjbha7SQlTIozIphW7tHf8t02m5afP8f832INvHNYpyteaWuRifWh6 SVkAs6dxLtzuyihxcT+3KyMSV/mxOLKVpq+qFw7hD5Ttu9GB+ecjgunzALsYO6cQBEGr 1Dlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733278354; x=1733883154; 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=K+SlF2FR3ZV2vuRhtIQV4BC/j1/AENizpBsFIvnrz4w=; b=o2jjlIkqCLNhSC+ldqqpv/8fjZ+CG1N57U2/Y19lCZA18fUSNQKFzdPN3Rs9WcPmBg kTrgn8ZIDpA1PBFx38q/d88bFz6VXUM8vOpH1c8qIPplsKuoOSBA6F33NIfyyrTo+2ZI 3ArbikQ6sWlrU9KcbS3V2X62CwNu3Sk7hpZ6AusCMLmh8loy6veuQfeayfC9SMNnDNz0 /uSqh1u99QJknxUdNP8UFqwsKW9YVwfUAunQCTrUSV7Qi3uL1A5j0ZVZOKoTiMHfrksZ NOxswCh7+UDwNSB1nq0wmbTFCa4L8NhyA/KIYT9HAeEe8uDQGBaz2OTeMe0Rv5A1V4Sg rXAA== X-Forwarded-Encrypted: i=1; AJvYcCXl4YnWPdeb8f9zFNvw3lmlUTRWQ+gN/p+4iN5PNIN7xngN3c/SFybh4/C4gqUYyL5x4LCK5fRKdAtj@nongnu.org X-Gm-Message-State: AOJu0Yx/45jFLO4KMXZLGu7gZnNhcE0295JpR5+xhhw+9rPEklCMQmzc aitavXNZ2/EVx4dhhBFpc+GHS1CBhh40sBBstAzZJbLfkp62qD+nlLu4JUXxdYI= X-Gm-Gg: ASbGncteNF/Vs/J29KsihvuzkSZJQAqQ0H+OPtwo3l/2kAN0qpDwXZKXeG6ne8/FNY5 mVbbfgoEknwOeb1clSUunw+ktG2TO9OyEosxI7klmoKSfbS6UJrox/ygGJuY4Pw3ehtAQDyVemj NO+ET155ZE7fnu6Zfr9w5CsvfpRflCABsz1OPu2EM9kBdUDiI5gfWRMblCeHRu3nsM+o0kNtsci jXLDsTDTZahQKq9VE+rfQXdaGqCokqiwiunT6Utj8wb3OVRo/3eUyY3PP3HQK8RAFo1Vi0oKyz0 rpfs11kscphCRKZ1dg== X-Google-Smtp-Source: AGHT+IHMmCdTgFZZzIJmqPh1ukpmVNGX7GxYw+6bF0TIGKu/gY4wNSUNvmxD4Axnb5hYbf6g9nZj9Q== X-Received: by 2002:a05:690c:4809:b0:6ef:6c57:ddae with SMTP id 00721157ae682-6efad1de4f3mr70543377b3.34.1733278353903; Tue, 03 Dec 2024 18:12:33 -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 v8 12/12] migration/doc: Add DSA zero page detection doc Date: Tue, 3 Dec 2024 18:11:41 -0800 Message-Id: <20241204021142.24184-13-yichen.wang@bytedance.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241204021142.24184-1-yichen.wang@bytedance.com> References: <20241204021142.24184-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::1136; envelope-from=yichen.wang@bytedance.com; helo=mail-yw1-x1136.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: 1733278446401116600 Content-Type: text/plain; charset="utf-8" From: Yuan Liu Signed-off-by: Yuan Liu Signed-off-by: Yichen Wang Reviewed-by: Fabiano Rosas --- .../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