From nobody Thu Nov 13 10:34:09 2025 Delivered-To: importer@patchew.org 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; 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=1579571107; cv=none; d=zohomail.com; s=zohoarc; b=K7lpiETEWYoZ/l5cvHsuV0L0XymAVGvKh0vkPgT0PLOqx5EuGapifxvpx3aZoWFSl6vXm/JqJwtNT3FQGJXVeYHsYkPRTWJz8mgCCDa0nDD45NKMK7vrXm6Y2h0n4vHjrWi2HEsswLIwlqfqnudB1b5CGdq5PHrIdtSlz6PkSgM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579571107; 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=d8arDOv455rogF2dRq1K5W98O1g4hMO9yNUA10vG7Sk=; b=Yli6XzrI+boWVQiTRKjGJDuHfakM2jXnldnFhNy0PVLuNduMsEatE1NMGAk4J5D641TWJkL2zKLVuyz3EMTDgSl76X5ZL852zhZZNjAW0hm2XQ8gZHh+Nul2nRKaCdimpa69q6qcsWEEmIIicAQjH1KAA0tRNlQzjKH+uoCDxHA= 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 1579571107599191.27051952872137; Mon, 20 Jan 2020 17:45:07 -0800 (PST) Received: from localhost ([::1]:46894 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itibK-0008HI-4X for importer@patchew.org; Mon, 20 Jan 2020 20:45:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44291) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itiWV-0004EG-P9 for qemu-devel@nongnu.org; Mon, 20 Jan 2020 20:40:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itiWU-0004ce-Gb for qemu-devel@nongnu.org; Mon, 20 Jan 2020 20:40:07 -0500 Received: from lizzy.crudebyte.com ([91.194.90.13]:35429) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1itiWT-0003nh-O1 for qemu-devel@nongnu.org; Mon, 20 Jan 2020 20:40:06 -0500 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=d8arDOv455rogF2dRq1K5W98O1g4hMO9yNUA10vG7Sk=; b=JLAXE eVq9W9L2CVkcTuZlZsgOr0AMdSNP5UPVHJ9INwTtUs9Q3inlrs4vihL79CdpqjAfvVctZs/yCjw3L kguNuk5l8r17OjTx4G6o9hlXJ3IzuZ1fqkm3UzwFQtJDHXrDwnrix8yBV5KC2XdqkdMOnSxGs2A8v Gv56l7fbXZ8Ni6zST5FA1Ut+dyRgkt2QV5YVCsTNCxCpVMJIW2lrOisg4UPvyRKG0gKS1P1PtKOLt 3slY8EOV64D9VGBFvBa3WfmhMal+pVNjo1N5QTjPpkYO9alZGUWNDRurne8SyAeWU++izDGam0f75 67C2Kom3tHRxktqIKdxNLBTVwgT1A==; Message-Id: In-Reply-To: References: From: Christian Schoenebeck Date: Tue, 21 Jan 2020 01:26:15 +0100 Subject: [PATCH v4 09/11] hw/9pfs/9p-synth: avoid n-square issue in synth_readdir() To: qemu-devel@nongnu.org Cc: Greg Kurz X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] 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" This patch is just a temporary benchmark hack, not intended to be merged! 9pfs synth driver's readdir() implementation has a severe n-square performance problem. This patch is a quick and dirty hack to prevent that performance problem from tainting the readdir() benchmark results. In its current form, this patch is not useful for anything else than for an isolated readdir benchmark. NOTE: This patch would break the new readdir/split test, because it would alter the behaviour of seekdir() required for retrieving directory entries splitted over several requests. Signed-off-by: Christian Schoenebeck --- hw/9pfs/9p-synth.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/hw/9pfs/9p-synth.c b/hw/9pfs/9p-synth.c index 7eb210ffa8..54dc30f37b 100644 --- a/hw/9pfs/9p-synth.c +++ b/hw/9pfs/9p-synth.c @@ -225,7 +225,8 @@ static void synth_direntry(V9fsSynthNode *node, } =20 static struct dirent *synth_get_dentry(V9fsSynthNode *dir, - struct dirent *entry, off_t of= f) + struct dirent *entry, off_t off, + V9fsSynthNode **hack) { int i =3D 0; V9fsSynthNode *node; @@ -243,16 +244,38 @@ static struct dirent *synth_get_dentry(V9fsSynthNode = *dir, /* end of directory */ return NULL; } + *hack =3D node; synth_direntry(node, entry, off); return entry; } =20 static struct dirent *synth_readdir(FsContext *ctx, V9fsFidOpenState *fs) { - struct dirent *entry; + struct dirent *entry =3D NULL; V9fsSynthOpenState *synth_open =3D fs->private; V9fsSynthNode *node =3D synth_open->node; - entry =3D synth_get_dentry(node, &synth_open->dent, synth_open->offset= ); + + /* + * HACK: This is just intended for benchmark, to avoid severe n-square + * performance problem of synth driver's readdir implementation here w= hich + * would otherwise unncessarily taint the benchmark results. By simply + * caching (globally) the previous node (of the previous synth_readdir= () + * call) we can simply proceed to next node in chained list efficientl= y. + * + * not a good idea for any production code ;-) + */ + static struct V9fsSynthNode *cachedNode; + + if (!cachedNode) { + entry =3D synth_get_dentry(node, &synth_open->dent, synth_open->of= fset, + &cachedNode); + } else { + cachedNode =3D cachedNode->sibling.le_next; + if (cachedNode) { + entry =3D &synth_open->dent; + synth_direntry(cachedNode, entry, synth_open->offset + 1); + } + } if (entry) { synth_open->offset++; } --=20 2.20.1