From nobody Fri May 17 09:01:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1587313422; cv=none; d=zohomail.com; s=zohoarc; b=PY64nFFrxiHUWJa01Ri+0vDnxddZHXFlmi2BedlCd7N84XW6cOq+ed/kgtwtrUt+gexmMuBfgsIM/qC9DNLiHkCppNFIyjfjlxI9MxoVUYgMWxmiDGf9aq6NXokIIh7mbyTear0aUa8KO+MpUsRSXx6RemyWMyn1fS72iTZGp8g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587313422; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=IezmcX2Zz1GFPAfr+8apNBJ7XzlcmwBnC7ZbeGtNK9Q=; b=KRGbb6OvyKxTgQEFwy73A2xcFNwV2HTVqotyECv1EaIDEBKzRmfUNjotgEXA+ke7wiPrPndHFoL3dtYPP+4xiNPuOHht67tUpD42V2hvLLr7r0/gRWUfFzsPyiB7T5xyK7jAFFsXbhkrkY2njXfE3viMvikeKIB8FD2Az4sbiA0= 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) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1587313422472592.3601348532022; Sun, 19 Apr 2020 09:23:42 -0700 (PDT) Received: from localhost ([::1]:43926 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQCjN-0001xl-0O for importer@patchew.org; Sun, 19 Apr 2020 12:23:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41242 helo=eggs1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQCiJ-0001F1-Eb for qemu-devel@nongnu.org; Sun, 19 Apr 2020 12:22:35 -0400 Received: from Debian-exim by eggs1p.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jQCiI-0000AS-UR for qemu-devel@nongnu.org; Sun, 19 Apr 2020 12:22:35 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:41945) by eggs1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jQCiI-0007ux-AD for qemu-devel@nongnu.org; Sun, 19 Apr 2020 12:22:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=IezmcX2Zz1GFPAfr+8apNBJ7XzlcmwBnC7ZbeGtNK9Q=; b=c0kJI tpZMNIAU3AuNWTHz0ImVS87Dsv5GGt6qS578y04kpjJx1Fr9CMxDEFZqRcQrk8nnsPldr2HuPB2VG fOHJ+mIFnyqJ42YtbCtLTU8Yddhnt6S0kNr2ue2D3gw4RizwZ5SEx5J7FFiN6l0fvTOeNfUulT31O rEBQTaTimztBlzLhztATRcT3spThPRfZyGUfecRr221s+GpH0zgoba+/xeEpfjgwUzulFii+ywVZX TlNX1Wpn+La8S8EqQjPwV+AF2ynkzdYcUaT74DcwrjDnaFYDXPKImsznjA737EBKhG2dMz6qL2iQa inruYb0fjQbp6CT2N0qJ3d9UeaAnw==; Message-Id: In-Reply-To: References: From: Christian Schoenebeck Date: Sun, 19 Apr 2020 17:00:06 +0200 Subject: [PATCH v6 1/5] tests/virtio-9p: added split readdir tests To: qemu-devel@nongnu.org Cc: Greg Kurz 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: none client-ip=91.194.90.13; envelope-from=eedba1df29df6d0a13fec0c6ea9d751f0362995b@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-detected-operating-system: by eggs1p.gnu.org: Linux 3.11 and newer X-Received-From: 91.194.90.13 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" X-ZohoMail-DKIM: pass (identity @crudebyte.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The previous, already existing 'basic' readdir test simply used a 'count' parameter big enough to retrieve all directory entries with a single Treaddir request. In the 3 new 'split' readdir tests added by this patch, directory entries are retrieved, split over several Treaddir requests by picking small 'count' parameters which force the server to truncate the response. So the test client sends as many Treaddir requests as necessary to get all directory entries. The following 3 new tests are added (executed in this sequence): 1. Split readdir test with count=3D512 2. Split readdir test with count=3D256 3. Split readdir test with count=3D128 This test case sequence is chosen because the smaller the 'count' value, the higher the chance of errors in case of implementation bugs on server side. Signed-off-by: Christian Schoenebeck --- tests/qtest/virtio-9p-test.c | 108 +++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c index 2167322985..de30b717b6 100644 --- a/tests/qtest/virtio-9p-test.c +++ b/tests/qtest/virtio-9p-test.c @@ -578,6 +578,7 @@ static bool fs_dirents_contain_name(struct V9fsDirent *= e, const char* name) return false; } =20 +/* basic readdir test where reply fits into a single response message */ static void fs_readdir(void *obj, void *data, QGuestAllocator *t_alloc) { QVirtio9P *v9p =3D obj; @@ -631,6 +632,89 @@ static void fs_readdir(void *obj, void *data, QGuestAl= locator *t_alloc) g_free(wnames[0]); } =20 +/* readdir test where overall request is split over several messages */ +static void fs_readdir_split(void *obj, void *data, QGuestAllocator *t_all= oc, + uint32_t count) +{ + QVirtio9P *v9p =3D obj; + alloc =3D t_alloc; + char *const wnames[] =3D { g_strdup(QTEST_V9FS_SYNTH_READDIR_DIR) }; + uint16_t nqid; + v9fs_qid qid; + uint32_t nentries, npartialentries; + struct V9fsDirent *entries, *tail, *partialentries; + P9Req *req; + int fid; + uint64_t offset; + + fs_attach(v9p, NULL, t_alloc); + + fid =3D 1; + offset =3D 0; + entries =3D NULL; + nentries =3D 0; + tail =3D NULL; + + req =3D v9fs_twalk(v9p, 0, fid, 1, wnames, 0); + v9fs_req_wait_for_reply(req, NULL); + v9fs_rwalk(req, &nqid, NULL); + g_assert_cmpint(nqid, =3D=3D, 1); + + req =3D v9fs_tlopen(v9p, fid, O_DIRECTORY, 0); + v9fs_req_wait_for_reply(req, NULL); + v9fs_rlopen(req, &qid, NULL); + + /* + * send as many Treaddir requests as required to get all directory + * entries + */ + while (true) { + npartialentries =3D 0; + partialentries =3D NULL; + + req =3D v9fs_treaddir(v9p, fid, offset, count, 0); + v9fs_req_wait_for_reply(req, NULL); + v9fs_rreaddir(req, &count, &npartialentries, &partialentries); + if (npartialentries > 0 && partialentries) { + if (!entries) { + entries =3D partialentries; + nentries =3D npartialentries; + tail =3D partialentries; + } else { + tail->next =3D partialentries; + nentries +=3D npartialentries; + } + while (tail->next) { + tail =3D tail->next; + } + offset =3D tail->offset; + } else { + break; + } + } + + g_assert_cmpint( + nentries, =3D=3D, + QTEST_V9FS_SYNTH_READDIR_NFILES + 2 /* "." and ".." */ + ); + + /* + * Check all file names exist in returned entries, ignore their order + * though. + */ + g_assert_cmpint(fs_dirents_contain_name(entries, "."), =3D=3D, true); + g_assert_cmpint(fs_dirents_contain_name(entries, ".."), =3D=3D, true); + for (int i =3D 0; i < QTEST_V9FS_SYNTH_READDIR_NFILES; ++i) { + char *name =3D g_strdup_printf(QTEST_V9FS_SYNTH_READDIR_FILE, i); + g_assert_cmpint(fs_dirents_contain_name(entries, name), =3D=3D, tr= ue); + g_free(name); + } + + v9fs_free_dirents(entries); + + g_free(wnames[0]); +} + static void fs_walk_no_slash(void *obj, void *data, QGuestAllocator *t_all= oc) { QVirtio9P *v9p =3D obj; @@ -793,6 +877,24 @@ static void fs_flush_ignored(void *obj, void *data, QG= uestAllocator *t_alloc) g_free(wnames[0]); } =20 +static void fs_readdir_split_128(void *obj, void *data, + QGuestAllocator *t_alloc) +{ + fs_readdir_split(obj, data, t_alloc, 128); +} + +static void fs_readdir_split_256(void *obj, void *data, + QGuestAllocator *t_alloc) +{ + fs_readdir_split(obj, data, t_alloc, 256); +} + +static void fs_readdir_split_512(void *obj, void *data, + QGuestAllocator *t_alloc) +{ + fs_readdir_split(obj, data, t_alloc, 512); +} + static void register_virtio_9p_test(void) { qos_add_test("config", "virtio-9p", pci_config, NULL); @@ -810,6 +912,12 @@ static void register_virtio_9p_test(void) qos_add_test("fs/flush/ignored", "virtio-9p", fs_flush_ignored, NULL); qos_add_test("fs/readdir/basic", "virtio-9p", fs_readdir, NULL); + qos_add_test("fs/readdir/split_512", "virtio-9p", + fs_readdir_split_512, NULL); + qos_add_test("fs/readdir/split_256", "virtio-9p", + fs_readdir_split_256, NULL); + qos_add_test("fs/readdir/split_128", "virtio-9p", + fs_readdir_split_128, NULL); } =20 libqos_init(register_virtio_9p_test); --=20 2.20.1 From nobody Fri May 17 09:01:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1587313343; cv=none; d=zohomail.com; s=zohoarc; b=CuK/uZJh04BKcuZywUT9OF+Z5MmkbtBkkpKCSAq+7ZDiE4eS8IbtBheAyON1m+eb+efBeLsgQ/S046wFM6GnXfER8KsAhZTUZDjr61M9xi0jP4PtIgzEXWiDLMsZNoCj8QRqrok/nOiRlEvfGte3RXsQpMZUzwl9sCvZHeuKXy4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587313343; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=gC4AlObwl8Flida0/OUpjkhyIUUJyBjEp1XM5rPjBNk=; b=CyYE4FLoJsXhq7ogURHB19fHBJCRI9xAc21XgRbmNIDuZwYC5yB7CJuteDsiy5goJwXxAoLnCuAwRa+jgHwmklvcBpkxQ2cTaQD0cvarbsBAwcdekAuRio0o+cmVrwvWDHuhng4971kvtDSGz0iMXM6ueC52S/ZAh5f9xyfUEnI= 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) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1587313343543452.40450632238606; Sun, 19 Apr 2020 09:22:23 -0700 (PDT) Received: from localhost ([::1]:43892 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQCi5-0000lM-QM for importer@patchew.org; Sun, 19 Apr 2020 12:22:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40998 helo=eggs1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from <61e983e1855045ddc8c2418f87d7a096bdb72e53@lizzy.crudebyte.com>) id 1jQChK-0000Hn-Im for qemu-devel@nongnu.org; Sun, 19 Apr 2020 12:21:34 -0400 Received: from Debian-exim by eggs1p.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from <61e983e1855045ddc8c2418f87d7a096bdb72e53@lizzy.crudebyte.com>) id 1jQChI-0007us-QU for qemu-devel@nongnu.org; Sun, 19 Apr 2020 12:21:33 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:56377) by eggs1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <61e983e1855045ddc8c2418f87d7a096bdb72e53@lizzy.crudebyte.com>) id 1jQChI-0006xu-1q for qemu-devel@nongnu.org; Sun, 19 Apr 2020 12:21:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=gC4AlObwl8Flida0/OUpjkhyIUUJyBjEp1XM5rPjBNk=; b=gPNjd c3HkbtRZ3irVNo7VLPERaGmX/Cm2ARM4fx5sEpkPVm2FligDumB53QATPwDKmWqXds+1yIKJrrBDj uH7Rc/fBsXo6bqg3vm+HwqXcMlBRI5eReMxyOj0SuZJOpjsUjzaEJx5ycI5Q0ubhp0SqytWoVnc3g ODaC0ZtrnFzMc4+/i26q1Neuqwn6fQq9c0+KcpOcd47B40ndg4CTgRC8rzMF/tiWHEXWD6wRXc8Wl M+QQqk/uB8LiTmawd1Bkzuwp25IKwxzQ/sjwuJvG1rNKghOVV5laIjmud5C3TFEV+6bNeIm+unWmo ZLj8Wcrz1/t4E7hcSjphnO/3kvkNw==; Message-Id: <61e983e1855045ddc8c2418f87d7a096bdb72e53.1587309014.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Sun, 19 Apr 2020 17:00:59 +0200 Subject: [PATCH v6 2/5] 9pfs: make v9fs_readdir_response_size() public To: qemu-devel@nongnu.org Cc: Greg Kurz 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: none client-ip=91.194.90.13; envelope-from=61e983e1855045ddc8c2418f87d7a096bdb72e53@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-detected-operating-system: by eggs1p.gnu.org: Linux 3.11 and newer X-Received-From: 91.194.90.13 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" X-ZohoMail-DKIM: pass (identity @crudebyte.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Rename function v9fs_readdir_data_size() -> v9fs_readdir_response_size() and make it callable from other units. So far this function is only used by 9p.c, however subsequent patches require the function to be callable from another 9pfs unit. And as we're at it; also make it clear for what this function is used for. Signed-off-by: Christian Schoenebeck --- hw/9pfs/9p.c | 10 ++++++++-- hw/9pfs/9p.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 9e046f7acb..43584aca41 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -2322,7 +2322,13 @@ out_nofid: pdu_complete(pdu, err); } =20 -static size_t v9fs_readdir_data_size(V9fsString *name) +/** + * Returns size required in Rreaddir response for the passed dirent @p nam= e. + * + * @param name - directory entry's name (i.e. file name, directory name) + * @returns required size in bytes + */ +size_t v9fs_readdir_response_size(V9fsString *name) { /* * Size of each dirent on the wire: size of qid (13) + size of offset = (8) @@ -2357,7 +2363,7 @@ static int coroutine_fn v9fs_do_readdir(V9fsPDU *pdu,= V9fsFidState *fidp, } v9fs_string_init(&name); v9fs_string_sprintf(&name, "%s", dent->d_name); - if ((count + v9fs_readdir_data_size(&name)) > max_count) { + if ((count + v9fs_readdir_response_size(&name)) > max_count) { v9fs_readdir_unlock(&fidp->fs.dir); =20 /* Ran out of buffer. Set dir back to old position and return = */ diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h index b8f72a3bd9..9553700dbb 100644 --- a/hw/9pfs/9p.h +++ b/hw/9pfs/9p.h @@ -419,6 +419,7 @@ void v9fs_path_init(V9fsPath *path); void v9fs_path_free(V9fsPath *path); void v9fs_path_sprintf(V9fsPath *path, const char *fmt, ...); void v9fs_path_copy(V9fsPath *dst, const V9fsPath *src); +size_t v9fs_readdir_response_size(V9fsString *name); int v9fs_name_to_path(V9fsState *s, V9fsPath *dirpath, const char *name, V9fsPath *path); int v9fs_device_realize_common(V9fsState *s, const V9fsTransport *t, --=20 2.20.1 From nobody Fri May 17 09:01:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1587313646; cv=none; d=zohomail.com; s=zohoarc; b=muIRGN/JN8jQnIjKJzbyFQdMeSKMcat0YTA1nmXHan7w88wxmuBEsTPme6Rfp4wNy8s7KdG5IIYmjVt0/xJx2W0cps4SVMBWz7Xeu9ufR+It3kdSVlwUR/TODIVuiqjRBIAsvJQr5PxRmAVEmt0nR+GaOMJKZk01WmopGtyhN/M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587313646; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=Exi2eVU0aC9WtbkX7/D0N5Fl28ExllAxepKnldAijZ4=; b=dPZiK73ikyHwAzTLL6Gq3GYHno3Ll9GHv1hn1M1OmWt1JRm+x7pYWojDB6lTiYJV5789aPKr/jWG3A+dQirEIhIBFi73Rq7YAYoQrAxyC4469Y6cDikCd8UCJQ/Z9m6+Tkq12JqNkGVOYXJ8nAWuzkV7KHl+115bHv8inUrRlWs= 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) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1587313646638209.54828890273427; Sun, 19 Apr 2020 09:27:26 -0700 (PDT) Received: from localhost ([::1]:44010 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQCmz-0006XQ-A2 for importer@patchew.org; Sun, 19 Apr 2020 12:27:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42128 helo=eggs1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQCmK-0005mA-1w for qemu-devel@nongnu.org; Sun, 19 Apr 2020 12:26:44 -0400 Received: from Debian-exim by eggs1p.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jQCmJ-00063z-Ax for qemu-devel@nongnu.org; Sun, 19 Apr 2020 12:26:43 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:41361) by eggs1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jQCmI-0004j9-RE for qemu-devel@nongnu.org; Sun, 19 Apr 2020 12:26:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=Exi2eVU0aC9WtbkX7/D0N5Fl28ExllAxepKnldAijZ4=; b=Tir/A JZeE15PgLCj9TJ9cnqGNbRPqWNEfyzo5o0uidD98GZ9XjSiEP5eUOfX44gG+4byZVQOD2C+pG0Lg8 d+gN4MyPKhH9C9/CNn2J9rnfRFtKGWUTX3U7OWCRclXP3Lyc7/2F44pcHO2VCBCiHQJNTW9pFNMPq SagxeWPFJrsJY7AzLktP5/i5oiWelfmJyMYJjfYp6tbHdZrCOQYNuHDW/ySKnsHwGs6u3Z6LDguuo srGNPmqn3Hl5fQGNi/pgGCw8im2Nt8P2gATRLN+J6wtrOJLYOMS5fIajCuk4ZDzX4HdA9/DKseevj W+MrY5syL4L3Soq9i/iuiTn77fxvw==; Message-Id: In-Reply-To: References: From: Christian Schoenebeck Date: Sun, 19 Apr 2020 17:02:27 +0200 Subject: [PATCH v6 3/5] 9pfs: add new function v9fs_co_readdir_many() To: qemu-devel@nongnu.org Cc: Greg Kurz 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: none client-ip=91.194.90.13; envelope-from=fdb0e29a86d1df6005021a08078d7e69ed0de1a2@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-detected-operating-system: by eggs1p.gnu.org: Linux 3.11 and newer X-Received-From: 91.194.90.13 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" X-ZohoMail-DKIM: pass (identity @crudebyte.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The newly added function v9fs_co_readdir_many() retrieves multiple directory entries with a single fs driver request. It is intended to replace uses of v9fs_co_readdir(), the latter only retrives a single directory entry per fs driver request instead. The reason for this planned replacement is that for every fs driver request the coroutine is dispatched from main I/O thread to a background I/O thread and eventually dispatched back to main I/O thread. Hopping between threads adds latency. So if a 9pfs Treaddir request reads a large amount of directory entries, this currently sums up to huge latencies of several hundred ms or even more. So using v9fs_co_readdir_many() instead of v9fs_co_readdir() will provide significant performance improvements. Signed-off-by: Christian Schoenebeck --- hw/9pfs/9p.h | 22 ++++++ hw/9pfs/codir.c | 181 +++++++++++++++++++++++++++++++++++++++++++++--- hw/9pfs/coth.h | 3 + 3 files changed, 195 insertions(+), 11 deletions(-) diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h index 9553700dbb..116977939b 100644 --- a/hw/9pfs/9p.h +++ b/hw/9pfs/9p.h @@ -215,6 +215,28 @@ static inline void v9fs_readdir_init(V9fsDir *dir) qemu_mutex_init(&dir->readdir_mutex); } =20 +/** + * Type for 9p fs drivers' (a.k.a. 9p backends) result of readdir requests, + * which is a chained list of directory entries. + */ +typedef struct V9fsDirEnt { + /* mandatory (must not be NULL) information for all readdir requests */ + struct dirent *dent; + /* + * optional (may be NULL): A full stat of each directory entry is just + * done if explicitly told to fs driver. + */ + struct stat *st; + /* + * instead of an array, directory entries are always returned as + * chained list, that's because the amount of entries retrieved by fs + * drivers is dependent on the individual entries' name (since response + * messages are size limited), so the final amount cannot be estimated + * before hand + */ + struct V9fsDirEnt *next; +} V9fsDirEnt; + /* * Filled by fs driver on open and other * calls. diff --git a/hw/9pfs/codir.c b/hw/9pfs/codir.c index 73f9a751e1..45c65a8f5b 100644 --- a/hw/9pfs/codir.c +++ b/hw/9pfs/codir.c @@ -18,28 +18,187 @@ #include "qemu/main-loop.h" #include "coth.h" =20 +/* + * This is solely executed on a background IO thread. + */ +static int do_readdir(V9fsPDU *pdu, V9fsFidState *fidp, struct dirent **de= nt) +{ + int err =3D 0; + V9fsState *s =3D pdu->s; + struct dirent *entry; + + errno =3D 0; + entry =3D s->ops->readdir(&s->ctx, &fidp->fs); + if (!entry && errno) { + *dent =3D NULL; + err =3D -errno; + } else { + *dent =3D entry; + } + return err; +} + +/* + * TODO: This will be removed for performance reasons. + * Use v9fs_co_readdir_many() instead. + */ int coroutine_fn v9fs_co_readdir(V9fsPDU *pdu, V9fsFidState *fidp, struct dirent **dent) { int err; - V9fsState *s =3D pdu->s; =20 if (v9fs_request_cancelled(pdu)) { return -EINTR; } - v9fs_co_run_in_worker( - { - struct dirent *entry; + v9fs_co_run_in_worker({ + err =3D do_readdir(pdu, fidp, dent); + }); + return err; +} + +/* + * This is solely executed on a background IO thread. + * + * See v9fs_co_readdir_many() (as its only user) below for details. + */ +static int do_readdir_many(V9fsPDU *pdu, V9fsFidState *fidp, + struct V9fsDirEnt **entries, + int32_t maxsize, bool dostat) +{ + V9fsState *s =3D pdu->s; + V9fsString name; + int len, err =3D 0; + int32_t size =3D 0; + off_t saved_dir_pos; + struct dirent *dent; + struct V9fsDirEnt *e =3D NULL; + V9fsPath path; + struct stat stbuf; =20 - errno =3D 0; - entry =3D s->ops->readdir(&s->ctx, &fidp->fs); - if (!entry && errno) { + *entries =3D NULL; + v9fs_path_init(&path); + + /* + * TODO: Here should be a warn_report_once() if lock failed. + * + * With a good 9p client we should not get into concurrency here, + * because a good client would not use the same fid for concurrent + * requests. We do the lock here for safety reasons though. However + * the client would then suffer performance issues, so better log that + * issue here. + */ + v9fs_readdir_lock(&fidp->fs.dir); + + /* save the directory position */ + saved_dir_pos =3D s->ops->telldir(&s->ctx, &fidp->fs); + if (saved_dir_pos < 0) { + err =3D saved_dir_pos; + goto out; + } + + while (true) { + /* get directory entry from fs driver */ + err =3D do_readdir(pdu, fidp, &dent); + if (err || !dent) { + break; + } + + /* + * stop this loop as soon as it would exceed the allowed maximum + * response message size for the directory entries collected so fa= r, + * because anything beyond that size would need to be discarded by + * 9p controller (main thread / top half) anyway + */ + v9fs_string_init(&name); + v9fs_string_sprintf(&name, "%s", dent->d_name); + len =3D v9fs_readdir_response_size(&name); + v9fs_string_free(&name); + if (size + len > maxsize) { + /* this is not an error case actually */ + break; + } + + /* append next node to result chain */ + if (!e) { + *entries =3D e =3D g_malloc0(sizeof(V9fsDirEnt)); + } else { + e =3D e->next =3D g_malloc0(sizeof(V9fsDirEnt)); + } + e->dent =3D g_malloc0(sizeof(struct dirent)); + memcpy(e->dent, dent, sizeof(struct dirent)); + + /* perform a full stat() for directory entry if requested by calle= r */ + if (dostat) { + err =3D s->ops->name_to_path( + &s->ctx, &fidp->path, dent->d_name, &path + ); + if (err < 0) { err =3D -errno; - } else { - *dent =3D entry; - err =3D 0; + break; } - }); + + err =3D s->ops->lstat(&s->ctx, &path, &stbuf); + if (err < 0) { + err =3D -errno; + break; + } + + e->st =3D g_malloc0(sizeof(struct stat)); + memcpy(e->st, &stbuf, sizeof(struct stat)); + } + + size +=3D len; + saved_dir_pos =3D dent->d_off; + } + + /* restore (last) saved position */ + s->ops->seekdir(&s->ctx, &fidp->fs, saved_dir_pos); + +out: + v9fs_readdir_unlock(&fidp->fs.dir); + v9fs_path_free(&path); + if (err < 0) { + return err; + } + return size; +} + +/** + * @brief Reads multiple directory entries in one rush. + * + * Retrieves the requested (max. amount of) directory entries from the fs + * driver. This function must only be called by the main IO thread (top ha= lf). + * Internally this function call will be dispatched to a background IO thr= ead + * (bottom half) where it is eventually executed by the fs driver. + * + * Acquiring multiple directory entries in one rush from the fs driver, + * instead of retrieving each directory entry individually, is very benefi= cial + * from performance point of view. Because for every fs driver request lat= ency + * is added, which in practice could lead to overall latencies of several + * hundred ms for reading all entries (of just a single directory) if every + * directory entry was individually requested from driver. + * + * @param pdu - the causing 9p (T_readdir) client request + * @param fidp - already opened directory where readdir shall be performed= on + * @param entries - output for directory entries (must not be NULL) + * @param maxsize - maximum result message body size (in bytes) + * @param dostat - whether a stat() should be performed and returned for + * each directory entry + * @returns resulting response message body size (in bytes) on success, + * negative error code otherwise + */ +int coroutine_fn v9fs_co_readdir_many(V9fsPDU *pdu, V9fsFidState *fidp, + struct V9fsDirEnt **entries, + int32_t maxsize, bool dostat) +{ + int err =3D 0; + + if (v9fs_request_cancelled(pdu)) { + return -EINTR; + } + v9fs_co_run_in_worker({ + err =3D do_readdir_many(pdu, fidp, entries, maxsize, dostat); + }); return err; } =20 diff --git a/hw/9pfs/coth.h b/hw/9pfs/coth.h index c2cdc7a9ea..a6851822d5 100644 --- a/hw/9pfs/coth.h +++ b/hw/9pfs/coth.h @@ -49,6 +49,9 @@ void co_run_in_worker_bh(void *); int coroutine_fn v9fs_co_readlink(V9fsPDU *, V9fsPath *, V9fsString *); int coroutine_fn v9fs_co_readdir(V9fsPDU *, V9fsFidState *, struct dirent = **); +int coroutine_fn v9fs_co_readdir_many(V9fsPDU *, V9fsFidState *, + struct V9fsDirEnt **, + int32_t, bool); off_t coroutine_fn v9fs_co_telldir(V9fsPDU *, V9fsFidState *); void coroutine_fn v9fs_co_seekdir(V9fsPDU *, V9fsFidState *, off_t); void coroutine_fn v9fs_co_rewinddir(V9fsPDU *, V9fsFidState *); --=20 2.20.1 From nobody Fri May 17 09:01:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1587313578; cv=none; d=zohomail.com; s=zohoarc; b=RaCY8rpKmH2VGtZRaeT0kZmeFCMvdcPjAhVP97A/ZySo5Ur9KHuDz2pjIi+egGHqI/xikZQ2L6eKMEuhltFMo7mz9n6qgHIbtYZKaOR/NvRw8zm7QCbIHiauY0TvCKOyIzID5Eu/xsdt4NbQrnWx7HB+463DM6m7ivtoN41fhPw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587313578; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=vPRaDMJ4FktY+2WuNbhPAC/12T/foP/ReG2XD1IK6pU=; b=Y3xhPGnY5JWIg4SQh8BnnSMzMlnpS6LukUjcGlzPpD1lX+Ps+OGlVaVyTaF051PKHnAeyacanT74UD+SuNco0LvePlrkKrVUhE2iNfA0YVCwvj25bcFKGtMGJBhllYp8LMvhL+GAVlHCwSCs+I0paScvkYLqeLBDfVFhvd0q8nU= 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) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1587313578327417.40246039877786; Sun, 19 Apr 2020 09:26:18 -0700 (PDT) Received: from localhost ([::1]:43988 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQClt-0004qq-19 for importer@patchew.org; Sun, 19 Apr 2020 12:26:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41756 helo=eggs1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from <14ec5d880cfca878bf32e643243c7ab3f4a52440@lizzy.crudebyte.com>) id 1jQCkK-0003iX-BA for qemu-devel@nongnu.org; Sun, 19 Apr 2020 12:24:41 -0400 Received: from Debian-exim by eggs1p.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from <14ec5d880cfca878bf32e643243c7ab3f4a52440@lizzy.crudebyte.com>) id 1jQCkI-0002jL-JP for qemu-devel@nongnu.org; Sun, 19 Apr 2020 12:24:40 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:46681) by eggs1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <14ec5d880cfca878bf32e643243c7ab3f4a52440@lizzy.crudebyte.com>) id 1jQCkH-0001S7-3i for qemu-devel@nongnu.org; Sun, 19 Apr 2020 12:24:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=vPRaDMJ4FktY+2WuNbhPAC/12T/foP/ReG2XD1IK6pU=; b=Lkn4s RTtw42+H1WkKCFm8NJLbWTqx0hNus0hzJsdd2EppwkKBdAbocamq2mv+qOmIVa2ZdoiKuQCtYGAyD FdCj+R+WkU4e5uop9x1qm/4EunMWbuv9p7JIYuZpnkzCqjcY8v2XFdTxZJtl1KqGyOP3P+aEgh1ch s1pL7Lo8Brm2uyyz8FHVwUchKzXoDCJiigvS9uU0jeprAq+0PyEAjhelWfh5Bgu5fDOs3I2EvE7Hr IviTzF4isGA4OAVXbBHZN7o3XUE1M5Fi4JcUq/uKxa5QLdNdY+KTQjugGDvG1BKqDa9+gtEC+CNrx qfQVBMN3QWFQzfQobc8HJCLDI/cAg==; Message-Id: <14ec5d880cfca878bf32e643243c7ab3f4a52440.1587309014.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Sun, 19 Apr 2020 17:06:17 +0200 Subject: [PATCH v6 4/5] 9pfs: T_readdir latency optimization To: qemu-devel@nongnu.org Cc: Greg Kurz 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: none client-ip=91.194.90.13; envelope-from=14ec5d880cfca878bf32e643243c7ab3f4a52440@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-detected-operating-system: by eggs1p.gnu.org: Linux 3.11 and newer X-Received-From: 91.194.90.13 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" X-ZohoMail-DKIM: pass (identity @crudebyte.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Make top half really top half and bottom half really bottom half: Each T_readdir request handling is hopping between threads (main I/O thread and background I/O driver threads) several times for every individual directory entry, which sums up to huge latencies for handling just a single T_readdir request. Instead of doing that, collect now all required directory entries (including all potentially required stat buffers for each entry) in one rush on a background I/O thread from fs driver by calling the previously added function v9fs_co_readdir_many() instead of v9fs_co_readdir(), then assemble the entire resulting network response message for the readdir request on main I/O thread. The fs driver is still aborting the directory entry retrieval loop (on the background I/O thread inside of v9fs_co_readdir_many()) as soon as it would exceed the client's requested maximum R_readdir response size. So this will not introduce a performance penalty on another end. Signed-off-by: Christian Schoenebeck --- hw/9pfs/9p.c | 122 +++++++++++++++++++++++---------------------------- 1 file changed, 55 insertions(+), 67 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 43584aca41..8283a3cfbb 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -971,30 +971,6 @@ static int coroutine_fn fid_to_qid(V9fsPDU *pdu, V9fsF= idState *fidp, return 0; } =20 -static int coroutine_fn dirent_to_qid(V9fsPDU *pdu, V9fsFidState *fidp, - struct dirent *dent, V9fsQID *qidp) -{ - struct stat stbuf; - V9fsPath path; - int err; - - v9fs_path_init(&path); - - err =3D v9fs_co_name_to_path(pdu, &fidp->path, dent->d_name, &path); - if (err < 0) { - goto out; - } - err =3D v9fs_co_lstat(pdu, &path, &stbuf); - if (err < 0) { - goto out; - } - err =3D stat_to_qid(pdu, &stbuf, qidp); - -out: - v9fs_path_free(&path); - return err; -} - V9fsPDU *pdu_alloc(V9fsState *s) { V9fsPDU *pdu =3D NULL; @@ -2337,6 +2313,18 @@ size_t v9fs_readdir_response_size(V9fsString *name) return 24 + v9fs_string_size(name); } =20 +static void v9fs_free_dirents(struct V9fsDirEnt *e) +{ + struct V9fsDirEnt *next =3D NULL; + + for (; e; e =3D next) { + next =3D e->next; + g_free(e->dent); + g_free(e->st); + g_free(e); + } +} + static int coroutine_fn v9fs_do_readdir(V9fsPDU *pdu, V9fsFidState *fidp, int32_t max_count) { @@ -2345,54 +2333,53 @@ static int coroutine_fn v9fs_do_readdir(V9fsPDU *pd= u, V9fsFidState *fidp, V9fsString name; int len, err =3D 0; int32_t count =3D 0; - off_t saved_dir_pos; struct dirent *dent; + struct stat *st; + struct V9fsDirEnt *entries =3D NULL; =20 - /* save the directory position */ - saved_dir_pos =3D v9fs_co_telldir(pdu, fidp); - if (saved_dir_pos < 0) { - return saved_dir_pos; - } - - while (1) { - v9fs_readdir_lock(&fidp->fs.dir); + /* + * inode remapping requires the device id, which in turn might be + * different for different directory entries, so if inode remapping is + * enabled we have to make a full stat for each directory entry + */ + const bool dostat =3D pdu->s->ctx.export_flags & V9FS_REMAP_INODES; =20 - err =3D v9fs_co_readdir(pdu, fidp, &dent); - if (err || !dent) { - break; - } - v9fs_string_init(&name); - v9fs_string_sprintf(&name, "%s", dent->d_name); - if ((count + v9fs_readdir_response_size(&name)) > max_count) { - v9fs_readdir_unlock(&fidp->fs.dir); + /* + * Fetch all required directory entries altogether on a background IO + * thread from fs driver. We don't want to do that for each entry + * individually, because hopping between threads (this main IO thread + * and background IO driver thread) would sum up to huge latencies. + */ + count =3D v9fs_co_readdir_many(pdu, fidp, &entries, max_count, dostat); + if (count < 0) { + err =3D count; + count =3D 0; + goto out; + } + count =3D 0; =20 - /* Ran out of buffer. Set dir back to old position and return = */ - v9fs_co_seekdir(pdu, fidp, saved_dir_pos); - v9fs_string_free(&name); - return count; - } + for (struct V9fsDirEnt *e =3D entries; e; e =3D e->next) { + dent =3D e->dent; =20 if (pdu->s->ctx.export_flags & V9FS_REMAP_INODES) { - /* - * dirent_to_qid() implies expensive stat call for each entry, - * we must do that here though since inode remapping requires - * the device id, which in turn might be different for - * different entries; we cannot make any assumption to avoid - * that here. - */ - err =3D dirent_to_qid(pdu, fidp, dent, &qid); + st =3D e->st; + /* e->st should never be NULL, but just to be sure */ + if (!st) { + err =3D -1; + break; + } + + /* remap inode */ + err =3D stat_to_qid(pdu, st, &qid); if (err < 0) { - v9fs_readdir_unlock(&fidp->fs.dir); - v9fs_co_seekdir(pdu, fidp, saved_dir_pos); - v9fs_string_free(&name); - return err; + break; } } else { /* * Fill up just the path field of qid because the client uses * only that. To fill the entire qid structure we will have * to stat each dirent found, which is expensive. For the - * latter reason we don't call dirent_to_qid() here. Only draw= back + * latter reason we don't call stat_to_qid() here. Only drawba= ck * is that no multi-device export detection of stat_to_qid() * would be done and provided as error to the user here. But * user would get that error anyway when accessing those @@ -2405,25 +2392,26 @@ static int coroutine_fn v9fs_do_readdir(V9fsPDU *pd= u, V9fsFidState *fidp, qid.version =3D 0; } =20 + v9fs_string_init(&name); + v9fs_string_sprintf(&name, "%s", dent->d_name); + /* 11 =3D 7 + 4 (7 =3D start offset, 4 =3D space for storing count= ) */ len =3D pdu_marshal(pdu, 11 + count, "Qqbs", &qid, dent->d_off, dent->d_type, &name); =20 - v9fs_readdir_unlock(&fidp->fs.dir); + v9fs_string_free(&name); =20 if (len < 0) { - v9fs_co_seekdir(pdu, fidp, saved_dir_pos); - v9fs_string_free(&name); - return len; + err =3D len; + break; } + count +=3D len; - v9fs_string_free(&name); - saved_dir_pos =3D dent->d_off; } =20 - v9fs_readdir_unlock(&fidp->fs.dir); - +out: + v9fs_free_dirents(entries); if (err < 0) { return err; } --=20 2.20.1 From nobody Fri May 17 09:01:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1587313468; cv=none; d=zohomail.com; s=zohoarc; b=PwBQA66/fyypoo3H0Xw/rRuPynPu1SO/hL67OLaF98Hu/34zqvMI4V35LTthUKsJnXUWHqoxnmKbpjKh4jw6PxcL2B8l5hyDZiTiiDgo0VPz41gWqVXtqzJt8RX2GyU58cTR6+d50fQrzN5Lpo5bHQvQn4Vw6nkZgCRnAWSvbvk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587313468; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=jPdUMVvPDb49VGrJsLB5Dy+OTfiFUvEBcazVO3auyKA=; b=KEzRqHztTtAiE4f/ZEwLcPDxDbh7Fmc7bcw5vFPy7nvFX/gMdbtByJnTg6fdi8madVmY9XtL4FcskFBLVZlbNR6q5n5l1HZQzAtihhSss0jCsK+Pmw8aCGPu9yyR0GUddiSeIYC+fuciGf6DXfBtQdNrkVmnKuclvUKp6BPbXQQ= 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) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1587313468861289.867038885136; Sun, 19 Apr 2020 09:24:28 -0700 (PDT) Received: from localhost ([::1]:43948 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQCk7-00030B-Kl for importer@patchew.org; Sun, 19 Apr 2020 12:24:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41460 helo=eggs1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from <963b183c516011237108a0212402affd35f0b799@lizzy.crudebyte.com>) id 1jQCjI-00025J-Ko for qemu-devel@nongnu.org; Sun, 19 Apr 2020 12:23:36 -0400 Received: from Debian-exim by eggs1p.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from <963b183c516011237108a0212402affd35f0b799@lizzy.crudebyte.com>) id 1jQCjI-0001S2-8M for qemu-devel@nongnu.org; Sun, 19 Apr 2020 12:23:36 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:36621) by eggs1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <963b183c516011237108a0212402affd35f0b799@lizzy.crudebyte.com>) id 1jQCjH-0000AX-P2 for qemu-devel@nongnu.org; Sun, 19 Apr 2020 12:23:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=jPdUMVvPDb49VGrJsLB5Dy+OTfiFUvEBcazVO3auyKA=; b=mIz+o 3PDM0Xel6Awqkv1/reRMJZAQeH+9Mbs417FWxI4mKnPI+QcJI9W9dXQOfOvtbClRbcaSqh626hUQk DqepnK748Z6yiyhBsAyeNChBM9Cf5xwwtsJcICVMye+MGZc309qn3IXQ5/TLSIkDmYxZ8FU8QV+b/ i0JHXi5Xi8k6lQC35fgfDYf4n1m+V3CDBmtkg22JZbxR4xw23nCGSWq6L8Pif5v0ud8GaFVwdKcoE eY5fGbeNNPg/nOEleCC3WIdmh8BLI9rZLoQ3G/dYA8ElkL7f4wR94Bigdug0HWcBwwKog49So5ml+ +ug8IO6cZAQYFBlLXysO5xqwu6Fvg==; Message-Id: <963b183c516011237108a0212402affd35f0b799.1587309014.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Sun, 19 Apr 2020 17:07:01 +0200 Subject: [PATCH v6 5/5] 9pfs: clarify latency of v9fs_co_run_in_worker() To: qemu-devel@nongnu.org Cc: Greg Kurz 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: none client-ip=91.194.90.13; envelope-from=963b183c516011237108a0212402affd35f0b799@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-detected-operating-system: by eggs1p.gnu.org: Linux 3.11 and newer X-Received-From: 91.194.90.13 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" X-ZohoMail-DKIM: pass (identity @crudebyte.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" As we just fixed a severe performance issue with Treaddir request handling, clarify this overall issue as a comment on v9fs_co_run_in_worker() with the intention to hopefully prevent such performance mistakes in future (and fixing other yet outstanding ones). Signed-off-by: Christian Schoenebeck --- hw/9pfs/coth.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/hw/9pfs/coth.h b/hw/9pfs/coth.h index a6851822d5..8b6f76840a 100644 --- a/hw/9pfs/coth.h +++ b/hw/9pfs/coth.h @@ -19,7 +19,7 @@ #include "qemu/coroutine.h" #include "9p.h" =20 -/* +/** * we want to use bottom half because we want to make sure the below * sequence of events. * @@ -28,6 +28,16 @@ * 3. Enter the coroutine in the worker thread. * we cannot swap step 1 and 2, because that would imply worker thread * can enter coroutine while step1 is still running + * + * @b PERFORMANCE @b CONSIDERATIONS: As a rule of thumb, keep in mind + * that hopping between threads adds @b latency! So when handling a + * 9pfs request, avoid calling v9fs_co_run_in_worker() too often, because + * this might otherwise sum up to a significant, huge overall latency for + * providing the response for just a single request. For that reason it + * is highly recommended to fetch all data from fs driver with a single + * fs driver request on a background I/O thread (bottom half) in one rush + * first and then eventually assembling the final response from that data + * on main I/O thread (top half). */ #define v9fs_co_run_in_worker(code_block) \ do { \ --=20 2.20.1