From nobody Tue Feb 10 00:59:43 2026 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; arc=pass (i=1 dmarc=pass fromdomain=oracle.com); dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=2; a=rsa-sha256; t=1651181192; cv=pass; d=zohomail.com; s=zohoarc; b=YG3sB4ls3FW4iRNOIvlr2aEYnwq+1En4QPuhrNcq5eumdK4plSQ5y3h0+ecVoABbCxftuVwbvH6b5Y4Uhy/cUGdlif0op0FUwj2qM7wjs7EyJj97pv6JBIzXwU/yjnZ1nJgvSXZG1vuRMneS9k59ROLdjFUklv8L8bQQcNYw824= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651181192; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ycl9bCTfViJUXB4zPoEGRaUlR1GC5CiBqImMZENF1bE=; b=abSVRxLC6H57Yy6I+cTEJP75zIvLSdj1IGNrm0xwZ/iL9bECPp6FF8nI2991CBxSVZxpxj8LuAHojLNNuY4HhySUe3EwePmslDGrgGRF8eNQ2J7gbWt17xr8j0KJ35BOezg/Ns/LdAyodQhgeGTLq6eKdlsWC860Pwjr6wogfx0= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=oracle.com); dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651181192544115.50066265972646; Thu, 28 Apr 2022 14:26:32 -0700 (PDT) Received: from localhost ([::1]:57660 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nkBeh-0007FM-HO for importer@patchew.org; Thu, 28 Apr 2022 17:26:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43602) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nkBTY-0001AL-43 for qemu-devel@nongnu.org; Thu, 28 Apr 2022 17:15:00 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:11816) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nkBTV-0005uA-LI for qemu-devel@nongnu.org; Thu, 28 Apr 2022 17:14:59 -0400 Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 23SJ5fta018590; Thu, 28 Apr 2022 21:14:53 GMT Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3fmb5k59ny-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 28 Apr 2022 21:14:53 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23SL5Cge028520; Thu, 28 Apr 2022 21:14:52 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2047.outbound.protection.outlook.com [104.47.66.47]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3fm7w79rpn-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 28 Apr 2022 21:14:52 +0000 Received: from BLAPR10MB4835.namprd10.prod.outlook.com (2603:10b6:208:331::11) by CH0PR10MB5289.namprd10.prod.outlook.com (2603:10b6:610:d8::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.14; Thu, 28 Apr 2022 21:14:50 +0000 Received: from BLAPR10MB4835.namprd10.prod.outlook.com ([fe80::b9e5:d1b6:b4be:f9d]) by BLAPR10MB4835.namprd10.prod.outlook.com ([fe80::b9e5:d1b6:b4be:f9d%5]) with mapi id 15.20.5206.013; Thu, 28 Apr 2022 21:14:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=Ycl9bCTfViJUXB4zPoEGRaUlR1GC5CiBqImMZENF1bE=; b=FP/9aFsugwFrjcahsTxVWg/RAdjx2yvfDJ9Z1VK/AqK9oS1wF+Lo6Uj1iS9Ip2x4nZG4 Lz87sG43gBzCWnfbiqoNDn0c3Mfhpdc3/8ke8aZOVYEhbAUyO4IUvB7iiz5e4PgCkadd t8Uo9fRhNSB7GXsHy1UTuJn2JJNcLGCsgba16hUrSvqkbNm/5TkksKwOw5yggaA+TMYA zhzmk7BZ9EI8jlnCPeokecw1PmFF746I5Xvkhbtja4ts2Fv64TUQKEtEpYxHK4ATOsfb T/6rO5FHlRMYlFdjCBPGpe21aloWNySJIv8HPvvomoc2C8VlxEQ9mN3L7K8MoaoFcHAY 0w== ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ixSBQukmaVS6NKb9mM9doqzXSWRuFNwb7smIpieKvdMHe/+CpwYHkfVq6nBHbUnAAiYuq21WSdQ85rFmvRJZo0nT4t177tO837HNXvOOohTwcvHoUiksjb/E2woOugyhzQxWIUp1Yww50CCDy8r24PT1miqDYmPp0dyr63fwtBjo6rRN4D3mb7vyOU0fESwWQdG+iHft2rxTabIBW2NRTVdMijuYsZ8Uf1QJHq32i/rhf9pjlQ04u7pGW3DUR3scucoqtTGL1IZQxZ2N/S4yaBcl+98TvLZV6j3h4Ynut6wg7uqFRyMW5maQ9VG3TcruqJWBlsrzFuZZmVjs/tIztA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Ycl9bCTfViJUXB4zPoEGRaUlR1GC5CiBqImMZENF1bE=; b=egYROaPK+gNVA6oGRWAJKxRB+ZU5ngPJT4NiGA8R8CkteDqiuunV9qLQMYRm2ds8oO7n9LEu1SXWlG98VOxYH78MjffGw4Cf6+nrzmXUdRvwSu9MdhOe0vX/jPZpGAz5AeA8mKZWwkY46VH6YeLgQxBnOu8Sh9EMuaomiKvHdSGOZMENPaxaVDqbfh1N88ro9wMs1bjKHhf1yH3QpBJcNyIPqb9O5wh2c3raRKCh4/9mN1tmFqedvNQUdxKCasXwoHBCQdGMKc0rjgrYHtmfRfFGESictmYPIHb8rMIGokwjndJFT20UmLwzRUYrjHkCzaQS295eVQ9vPpK5fhONGA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ycl9bCTfViJUXB4zPoEGRaUlR1GC5CiBqImMZENF1bE=; b=GOfvnENJiTkGE2J4QRKushuO2UYu3+YmXjiokMWGadmLoQkt5125jVD9AEe3M46NMErScvOjYKBHNUWkKnDYUk+JpsEi/zfqBrUqSHIkVMaiFJscu4IhZOaHp3tvlzYbD5oFK8Pl1o3jUj/q7bKLbyVdw+fxbdSv+k7i5vSSV0U= From: Joao Martins To: qemu-devel@nongnu.org Subject: [PATCH RFC 09/10] migration/dirtyrate: Expand dirty_bitmap to be tracked separately for devices Date: Thu, 28 Apr 2022 22:13:50 +0100 Message-Id: <20220428211351.3897-10-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20220428211351.3897-1-joao.m.martins@oracle.com> References: <20220428211351.3897-1-joao.m.martins@oracle.com> X-ClientProxiedBy: LO2P265CA0297.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a5::21) To BLAPR10MB4835.namprd10.prod.outlook.com (2603:10b6:208:331::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1443a39a-b421-4d11-76b0-08da295c2117 X-MS-TrafficTypeDiagnostic: CH0PR10MB5289:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YJ8sZapUH7MrnVGq9vohzlqcO30VlhC+eAa4j1UDIWR+/12NmGg3UMNw6yR2AkxnPDqzPQ8OO+/vInArgdB6bwInz2vq44OG/SHAfnfjJAMItJnNn19MVWm1mh0Gw4ifwYtRfP3FmIkMkjusfKwrIZYXn8S0FypDWu7BGuQwq5Wq3UW3xtmxYjd1e60CUMl3IFnumJGKFOVUL08Jwhw/kJWAVC9Oxi9L5USTINPp1OuG5PWBCW4RLPh9rBpY2d63uZo8j0henass0qehZ4FGbbCqMObi3u5nePslJA3kpgn7jOrafcH5fRSci4DBs8trMm7Me4kexs4pHT3gv+iV2ebZVkq0D5tPUbgbCNyQdQ+uUtO/5QXhyuasBuoTcRGQIrHW4rqoFQA/PZr+4+1QwuXr9pNfnIqLJonhn8u562SMjzSTVhnyjyXRtDP4hxkyDRMyeki+66Nd+RqwA3jXKqVk7v01M+8za71wgrbsdsNUYlpCGXzSzm1we3dO2qXdcafxkZit9UOdU2rX7oJLaGt4Aw59ubTYT7shpXOw6SEg0IQqAH1YKaeslE2M/SJSDIcA3RevFkxzK+Nq+Go93fGrK+7Iq3wpdqNKkRz8g1jXbn07TP/I4tyfa4qrpw5OJmGWWNXaDTiZewVr6/TlzRY0hGnuRnC++bsagrNKNe3zzL8yM+NrVqgokpR7rUyIA3YqaDlm8wFsCa+286yGSeqcaibfU0qJkwjtc8UwsAQ= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BLAPR10MB4835.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(54906003)(186003)(1076003)(30864003)(38350700002)(38100700002)(5660300002)(2616005)(7416002)(103116003)(26005)(316002)(6916009)(36756003)(66946007)(8676002)(66476007)(4326008)(66556008)(8936002)(52116002)(86362001)(6512007)(2906002)(6486002)(508600001)(83380400001)(6506007)(14143004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?pXNZeBqyIywJnEWLy9AnFUoc1LC9G91ouZSzByDW7P2/dpgqjj4X3D/DimdS?= =?us-ascii?Q?ECbFY8m+bXDm97gJPy80whmFjGHldwARHPYJfnTtP7ucGH8X1iQZYRoOf2/v?= =?us-ascii?Q?z8uOnHrexOuap7D+BNVf2rXqwQSyNJkm2aYEyV304aPHufLrgSJd0i+Tpzyv?= =?us-ascii?Q?qGnQsheSmbuiW6a/fagjv+HiTZ/EHokwGxTrFg+0BcfRklyHTeTGvDCpi12Z?= =?us-ascii?Q?5rr3pciP47YAu3YzKfsVE0V4aNej0mHkC7xP33XNAtHYMCZCAs/kA7D2GI/G?= =?us-ascii?Q?qDRDyEwv3KJgVLr9EbpCMuuGpkUDhHZQbFg+NJCY2Vm8wrFsRqTU9d+NgTXW?= =?us-ascii?Q?Gv7jrskFSbhnlioSmK2STY4oEW8pnkuCpIfXEth3XxwDjXxMlF+kSO0x7Wvu?= =?us-ascii?Q?vlponDOFOcBKVU8V9d8RA9ApVrZ1MU2Onzfm1aklLNIC3aRMkOYxxkOldsfT?= =?us-ascii?Q?ctWyAxUrW678dr39l2I1d1VHYUPI2tgWReEzQIapNK3L3oi6iCOwLL5crmh1?= =?us-ascii?Q?ATuf27mfakRBV5fOgun05xcgIqfiQV2HfY4Fmoe96Px1ybNFF3+NQWgV1n01?= =?us-ascii?Q?JF9a1oOJ/BLRdKcKvjL+jtR8HUCe0H26pHrxiw2PaDA+13Yr42743pVSMS6G?= =?us-ascii?Q?sL+Z32+kgNf1lC8Kpo6pJI6Ewt+vM+3f81h02MT9ae9dj/QJcUOt9c8Sw8Ve?= =?us-ascii?Q?GFBh8m9DPIuJtLDGs/FfPlJsbb/v5wifbPFUZNTDtLCgp9OUHZ2OFqjR/OdH?= =?us-ascii?Q?yeNjjzTkdbMMSDrLSt1O2R34Lr3ck11S3/G4vpaQakgzvwUYZa8WCBKnDTHB?= =?us-ascii?Q?zRQ3NSkalbhJsox1qNjVWTzUfZA8tPgvOAID4HLq28AOeKtV2VHGRFmvapED?= =?us-ascii?Q?jfq9EIsI/sI+vvtpI+w2mF2cfyAZW/H37ne4mDCYewUQKwohRVD/HgrjT7ml?= =?us-ascii?Q?u2x+ZBEfmFSHW7gg5eXfANd2YH4fl11pfOgMtiaptmtjJ3Fc8fkd4sepzyWd?= =?us-ascii?Q?N7dgUcjs/9yd49c0GP/Rtw4yqGE7/NxyVwnoiNW5fgy8d/4T3m9zGPRl0gDv?= =?us-ascii?Q?qRnbR3ic0Zv3KVu5oTKP0CMdS7QJmIDmdNYJJ44mUEjF904lkxRKs3dbiVWY?= =?us-ascii?Q?SAj4Oo0lh4AVQeAUdlF1arqpj8UXJlyvEaG6b4ScwoEQEhzhMd5Y5IxRqXOP?= =?us-ascii?Q?Yz9Eu+fn0aLTqH/6UzPOfLhvYgdFdlpE+9ThHoGD9FehsRgkjXclZPKJ6wMA?= =?us-ascii?Q?PZI3Q2QgZeV3U+UZ8zBVxmgqed/TWBONRyN6qHuLZ41nna5FzH5UpSeSR0Pm?= =?us-ascii?Q?y/eB3FfrXaSNV5R5dG2anC0vLAor7FHhmcoK5CcTrwaTukKBu92KP+sEQ6mD?= =?us-ascii?Q?EmqdKBLDHiHF+ecGFBR9J+WdBo9jbFuQl0BdMQdF+3iauB8Vfmv5xA/yKf34?= =?us-ascii?Q?1aAizGz9cji3PyNZfsiYyItKL6NXo5YRhgYjiy5gajZiw/0Lh1fvPdiNGxDS?= =?us-ascii?Q?kwKj1Pq3GIv4wJfwiXLQGd/CiGP9l6Xr7R8r/vPRNXLcoIFO+WELBWlHh+Y8?= =?us-ascii?Q?YHWSj2ygvZ7ytRQzZMdBb3yCTwA6eeWKUan4DapZmrkli3aBxOnidski3sXS?= =?us-ascii?Q?AkQBJB31b9dG0HGI9nVTWclvjnxWuI2Un0otgwkeY8LpzCAHnzVn98O2Kcmb?= =?us-ascii?Q?KmtHo/oWrCRzkYJ5NexxAIQBfXfOVSA7avwFauwWi/7HWbNp6G+Tj2CkiNqw?= =?us-ascii?Q?vuV/fCSHahIxnyoBx+MhmDnZ2THL2cs=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1443a39a-b421-4d11-76b0-08da295c2117 X-MS-Exchange-CrossTenant-AuthSource: BLAPR10MB4835.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Apr 2022 21:14:50.1667 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ICZ5Q6mEeN+EGwNhnQaLFHW6QZkDxuPmFTfCfOeKiPde8KTMZsuQEeLKw4GLMZqF1kPZSTDjrw7Huu87CxYZyQEwd4ey0uNR3LIZeN8p0fs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB5289 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-04-28_04:2022-04-28, 2022-04-28 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 spamscore=0 adultscore=0 mlxscore=0 bulkscore=0 suspectscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204280125 X-Proofpoint-GUID: qgvNMg-R-DSmfFP2Uojb43Rf05DEYZZr X-Proofpoint-ORIG-GUID: qgvNMg-R-DSmfFP2Uojb43Rf05DEYZZr 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=205.220.177.32; envelope-from=joao.m.martins@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: "John G . Johnson" , kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Peter Xu , Joao Martins , Eric Blake , Yi Liu , Juan Quintela , David Hildenbrand , Markus Armbruster , Nicolin Chen , Jason Gunthorpe , Kevin Tian , Richard Henderson , "Dr. David Alan Gilbert" , Eric Auger , Alex Williamson , Thanos Makatos , Eduardo Habkost , Yishai Hadas , Cornelia Huck , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @oracle.onmicrosoft.com) X-ZM-MESSAGEID: 1651181194430100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Expand dirtyrate measurer that is accessible via HMP calc_dirty_rate or QMP 'calc-dirty-rate' to receive a @scope argument. The scope then restricts the dirty tracking to be done at devices only, while neither enabling or using the KVM (CPU) dirty tracker. The default stays as is i.e. dirty-ring / dirty-bitmap from KVM. This is useful to test, exercise the IOMMU dirty tracker and observe how much a given device is dirtying memory. Signed-off-by: Joao Martins --- accel/kvm/kvm-all.c | 12 +++++++++ hmp-commands.hx | 5 ++-- hw/vfio/container.c | 8 ++++++ hw/vfio/iommufd.c | 4 +++ include/exec/memory.h | 10 +++++++- migration/dirtyrate.c | 59 +++++++++++++++++++++++++++++++++---------- migration/dirtyrate.h | 1 + qapi/migration.json | 15 +++++++++++ softmmu/memory.c | 5 ++++ 9 files changed, 102 insertions(+), 17 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 5f1377ca048c..b4bbe0d20f6e 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -1517,6 +1517,10 @@ static void kvm_log_sync(MemoryListener *listener, { KVMMemoryListener *kml =3D container_of(listener, KVMMemoryListener, l= istener); =20 + if (memory_global_dirty_devices()) { + return; + } + kvm_slots_lock(); kvm_physical_sync_dirty_bitmap(kml, section); kvm_slots_unlock(); @@ -1529,6 +1533,10 @@ static void kvm_log_sync_global(MemoryListener *l) KVMSlot *mem; int i; =20 + if (memory_global_dirty_devices()) { + return; + } + /* Flush all kernel dirty addresses into KVMSlot dirty bitmap */ kvm_dirty_ring_flush(); =20 @@ -1558,6 +1566,10 @@ static void kvm_log_clear(MemoryListener *listener, KVMMemoryListener *kml =3D container_of(listener, KVMMemoryListener, l= istener); int r; =20 + if (memory_global_dirty_devices()) { + return; + } + r =3D kvm_physical_log_clear(kml, section); if (r < 0) { error_report_once("%s: kvm log clear failed: mr=3D%s " diff --git a/hmp-commands.hx b/hmp-commands.hx index 8476277aa9c9..28122d268ea3 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1739,10 +1739,11 @@ ERST =20 { .name =3D "calc_dirty_rate", - .args_type =3D "dirty_ring:-r,dirty_bitmap:-b,second:l,sample_pag= es_per_GB:l?", - .params =3D "[-r] [-b] second [sample_pages_per_GB]", + .args_type =3D "dirty_devices:-d,dirty_ring:-r,dirty_bitmap:-b,se= cond:l,sample_pages_per_GB:l?", + .params =3D "[-d] [-r] [-b] second [sample_pages_per_GB]", .help =3D "start a round of guest dirty rate measurement (us= ing -r to" "\n\t\t\t specify dirty ring as the method of calcul= ation and" + "\n\t\t\t specify devices as the only scope and" "\n\t\t\t -b to specify dirty bitmap as method of ca= lculation)", .cmd =3D hmp_calc_dirty_rate, }, diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 6bc1b8763f75..fff8319c0036 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -84,6 +84,10 @@ static bool vfio_devices_all_dirty_tracking(VFIOContaine= r *bcontainer) VFIODevice *vbasedev; MigrationState *ms =3D migrate_get_current(); =20 + if (bcontainer->dirty_pages_supported) { + return true; + } + if (!migration_is_setup_or_active(ms->state)) { return false; } @@ -311,6 +315,10 @@ static int vfio_get_dirty_bitmap(VFIOContainer *bconta= iner, uint64_t iova, uint64_t pages; int ret; =20 + if (!memory_global_dirty_devices()) { + return 0; + } + dbitmap =3D g_malloc0(sizeof(*dbitmap) + sizeof(*range)); =20 dbitmap->argsz =3D sizeof(*dbitmap) + sizeof(*range); diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index d75ecbf2ae52..4686cc713aac 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -150,6 +150,10 @@ static int iommufd_get_dirty_bitmap(VFIOContainer *bco= ntainer, uint64_t iova, VFIOIOASHwpt *hwpt; unsigned long *data, page_size, bitmap_size, pages; =20 + if (!memory_global_dirty_devices()) { + return 0; + } + if (!bcontainer->dirty_pages_supported) { return 0; } diff --git a/include/exec/memory.h b/include/exec/memory.h index 4d5997e6bbae..59c1d8bcc495 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -69,7 +69,10 @@ static inline void fuzz_dma_read_cb(size_t addr, /* Dirty tracking enabled because measuring dirty rate */ #define GLOBAL_DIRTY_DIRTY_RATE (1U << 1) =20 -#define GLOBAL_DIRTY_MASK (0x3) +/* Dirty tracking enabled because measuring devices dirty rate */ +#define GLOBAL_DIRTY_DIRTY_RATE_DEVICES (1U << 2) + +#define GLOBAL_DIRTY_MASK (0x7) =20 extern unsigned int global_dirty_tracking; =20 @@ -2433,6 +2436,11 @@ void memory_global_dirty_log_start(unsigned int flag= s); */ void memory_global_dirty_log_stop(unsigned int flags); =20 +/** + * memory_global_dirty_devices: check if the scope is just devices + */ +bool memory_global_dirty_devices(void); + void mtree_info(bool flatview, bool dispatch_tree, bool owner, bool disabl= ed); =20 /** diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index aace12a78764..8c00cb6a3702 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -45,6 +45,8 @@ static int CalculatingState =3D DIRTY_RATE_STATUS_UNSTART= ED; static struct DirtyRateStat DirtyStat; static DirtyRateMeasureMode dirtyrate_mode =3D DIRTY_RATE_MEASURE_MODE_PAGE_SAMPLING; +static DirtyRateScope dirtyrate_scope =3D + DIRTY_RATE_SCOPE_ALL; =20 static int64_t set_sample_page_period(int64_t msec, int64_t initial_time) { @@ -99,6 +101,7 @@ static struct DirtyRateInfo *query_dirty_rate_info(void) info->calc_time =3D DirtyStat.calc_time; info->sample_pages =3D DirtyStat.sample_pages; info->mode =3D dirtyrate_mode; + info->scope =3D dirtyrate_scope; =20 if (qatomic_read(&CalculatingState) =3D=3D DIRTY_RATE_STATUS_MEASURED)= { info->has_dirty_rate =3D true; @@ -406,32 +409,44 @@ static inline void record_dirtypages(DirtyPageRecord = *dirty_pages, } } =20 -static void dirtyrate_global_dirty_log_start(void) +static void dirtyrate_global_dirty_log_start(DirtyRateScope scope) { + unsigned int flags =3D GLOBAL_DIRTY_DIRTY_RATE; + + if (scope =3D=3D DIRTY_RATE_SCOPE_DIRTY_DEVICES) { + flags |=3D GLOBAL_DIRTY_DIRTY_RATE_DEVICES; + } + qemu_mutex_lock_iothread(); - memory_global_dirty_log_start(GLOBAL_DIRTY_DIRTY_RATE); + memory_global_dirty_log_start(flags); qemu_mutex_unlock_iothread(); } =20 -static void dirtyrate_global_dirty_log_stop(void) +static void dirtyrate_global_dirty_log_stop(DirtyRateScope scope) { + unsigned int flags =3D GLOBAL_DIRTY_DIRTY_RATE; + + if (scope =3D=3D DIRTY_RATE_SCOPE_DIRTY_DEVICES) { + flags |=3D GLOBAL_DIRTY_DIRTY_RATE_DEVICES; + } + qemu_mutex_lock_iothread(); memory_global_dirty_log_sync(); - memory_global_dirty_log_stop(GLOBAL_DIRTY_DIRTY_RATE); + memory_global_dirty_log_stop(flags); qemu_mutex_unlock_iothread(); } =20 static int64_t do_calculate_dirtyrate_vcpu(DirtyPageRecord dirty_pages) { - uint64_t memory_size_MB; + uint64_t memory_size_KB; int64_t time_s; uint64_t increased_dirty_pages =3D dirty_pages.end_pages - dirty_pages.start_pages; =20 - memory_size_MB =3D (increased_dirty_pages * TARGET_PAGE_SIZE) >> 20; + memory_size_KB =3D (increased_dirty_pages * TARGET_PAGE_SIZE) >> 10; time_s =3D DirtyStat.calc_time; =20 - return memory_size_MB / time_s; + return memory_size_KB / time_s; } =20 static inline void record_dirtypages_bitmap(DirtyPageRecord *dirty_pages, @@ -466,9 +481,14 @@ static void calculate_dirtyrate_dirty_bitmap(struct Di= rtyRateConfig config) int64_t msec =3D 0; int64_t start_time; DirtyPageRecord dirty_pages; + unsigned int flags =3D GLOBAL_DIRTY_DIRTY_RATE; + + if (config.scope =3D=3D DIRTY_RATE_SCOPE_DIRTY_DEVICES) { + flags |=3D GLOBAL_DIRTY_DIRTY_RATE_DEVICES; + } =20 qemu_mutex_lock_iothread(); - memory_global_dirty_log_start(GLOBAL_DIRTY_DIRTY_RATE); + memory_global_dirty_log_start(flags); =20 /* * 1'round of log sync may return all 1 bits with @@ -500,7 +520,7 @@ static void calculate_dirtyrate_dirty_bitmap(struct Dir= tyRateConfig config) * 1. fetch dirty bitmap from kvm * 2. stop dirty tracking */ - dirtyrate_global_dirty_log_stop(); + dirtyrate_global_dirty_log_stop(config.scope); =20 record_dirtypages_bitmap(&dirty_pages, false); =20 @@ -527,7 +547,7 @@ static void calculate_dirtyrate_dirty_ring(struct Dirty= RateConfig config) DirtyStat.dirty_ring.nvcpu =3D nvcpu; DirtyStat.dirty_ring.rates =3D malloc(sizeof(DirtyRateVcpu) * nvcpu); =20 - dirtyrate_global_dirty_log_start(); + dirtyrate_global_dirty_log_start(config.scope); =20 CPU_FOREACH(cpu) { record_dirtypages(dirty_pages, cpu, true); @@ -540,7 +560,7 @@ static void calculate_dirtyrate_dirty_ring(struct Dirty= RateConfig config) msec =3D set_sample_page_period(msec, start_time); DirtyStat.calc_time =3D msec / 1000; =20 - dirtyrate_global_dirty_log_stop(); + dirtyrate_global_dirty_log_stop(config.scope); =20 CPU_FOREACH(cpu) { record_dirtypages(dirty_pages, cpu, false); @@ -631,6 +651,8 @@ void *get_dirtyrate_thread(void *arg) void qmp_calc_dirty_rate(int64_t calc_time, bool has_sample_pages, int64_t sample_pages, + bool has_scope, + DirtyRateScope scope, bool has_mode, DirtyRateMeasureMode mode, Error **errp) @@ -701,6 +723,7 @@ void qmp_calc_dirty_rate(int64_t calc_time, config.sample_period_seconds =3D calc_time; config.sample_pages_per_gigabytes =3D sample_pages; config.mode =3D mode; + config.scope =3D scope; =20 cleanup_dirtyrate_stat(config); =20 @@ -709,6 +732,7 @@ void qmp_calc_dirty_rate(int64_t calc_time, * been used in last calculation **/ dirtyrate_mode =3D mode; + dirtyrate_scope =3D scope; =20 start_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME) / 1000; init_dirtyrate_stat(start_time, config); @@ -736,9 +760,11 @@ void hmp_info_dirty_rate(Monitor *mon, const QDict *qd= ict) info->calc_time); monitor_printf(mon, "Mode: %s\n", DirtyRateMeasureMode_str(info->mode)); + monitor_printf(mon, "Scope: %s\n", + DirtyRateScope_str(info->scope)); monitor_printf(mon, "Dirty rate: "); if (info->has_dirty_rate) { - monitor_printf(mon, "%"PRIi64" (MB/s)\n", info->dirty_rate); + monitor_printf(mon, "%"PRIi64" (KB/s)\n", info->dirty_rate); if (info->has_vcpu_dirty_rate) { DirtyRateVcpuList *rate, *head =3D info->vcpu_dirty_rate; for (rate =3D head; rate !=3D NULL; rate =3D rate->next) { @@ -762,7 +788,9 @@ void hmp_calc_dirty_rate(Monitor *mon, const QDict *qdi= ct) bool has_sample_pages =3D (sample_pages !=3D -1); bool dirty_ring =3D qdict_get_try_bool(qdict, "dirty_ring", false); bool dirty_bitmap =3D qdict_get_try_bool(qdict, "dirty_bitmap", false); + bool dirty_devices =3D qdict_get_try_bool(qdict, "dirty_devices", fals= e); DirtyRateMeasureMode mode =3D DIRTY_RATE_MEASURE_MODE_PAGE_SAMPLING; + DirtyRateScope scope =3D DIRTY_RATE_SCOPE_ALL; Error *err =3D NULL; =20 if (!sec) { @@ -781,9 +809,12 @@ void hmp_calc_dirty_rate(Monitor *mon, const QDict *qd= ict) } else if (dirty_ring) { mode =3D DIRTY_RATE_MEASURE_MODE_DIRTY_RING; } + if (dirty_devices) { + scope =3D DIRTY_RATE_SCOPE_DIRTY_DEVICES; + } =20 - qmp_calc_dirty_rate(sec, has_sample_pages, sample_pages, true, - mode, &err); + qmp_calc_dirty_rate(sec, has_sample_pages, sample_pages, + true, scope, true, mode, &err); if (err) { hmp_handle_error(mon, err); return; diff --git a/migration/dirtyrate.h b/migration/dirtyrate.h index 69d4c5b8655f..4061edf9f4de 100644 --- a/migration/dirtyrate.h +++ b/migration/dirtyrate.h @@ -44,6 +44,7 @@ struct DirtyRateConfig { uint64_t sample_pages_per_gigabytes; /* sample pages per GB */ int64_t sample_period_seconds; /* time duration between two sampling */ DirtyRateMeasureMode mode; /* mode of dirtyrate measurement */ + DirtyRateScope scope; /* scope of dirtyrate measurement */ }; =20 /* diff --git a/qapi/migration.json b/qapi/migration.json index 27d7b281581d..082830c6e771 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -1793,6 +1793,19 @@ { 'enum': 'DirtyRateMeasureMode', 'data': ['page-sampling', 'dirty-ring', 'dirty-bitmap'] } =20 +## +# @DirtyRateScope: +# +# An enumeration of scope of measuring dirtyrate. +# +# @dirty-devices: calculate dirtyrate by devices only. +# +# Since: 6.2 +# +## +{ 'enum': 'DirtyRateScope', + 'data': ['all', 'dirty-devices'] } + ## # @DirtyRateInfo: # @@ -1827,6 +1840,7 @@ 'calc-time': 'int64', 'sample-pages': 'uint64', 'mode': 'DirtyRateMeasureMode', + 'scope': 'DirtyRateScope', '*vcpu-dirty-rate': [ 'DirtyRateVcpu' ] } } =20 ## @@ -1851,6 +1865,7 @@ ## { 'command': 'calc-dirty-rate', 'data': {'calc-time': 'int64', '*sample-pages': 'int', + '*scope': 'DirtyRateScope', '*mode': 'DirtyRateMeasureMode'} } =20 ## diff --git a/softmmu/memory.c b/softmmu/memory.c index bfa5d5178c5b..120c41f3b303 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -2826,6 +2826,11 @@ void memory_global_dirty_log_start(unsigned int flag= s) } } =20 +bool memory_global_dirty_devices(void) +{ + return !!(global_dirty_tracking & GLOBAL_DIRTY_DIRTY_RATE_DEVICES); +} + static void memory_global_dirty_log_do_stop(unsigned int flags) { assert(flags && !(flags & (~GLOBAL_DIRTY_MASK))); --=20 2.17.2