From patchwork Mon Jan 13 23:16:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Schoenebeck X-Patchwork-Id: 11331127 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 41B2B109A for ; Tue, 14 Jan 2020 00:36:36 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 17186207FD for ; Tue, 14 Jan 2020 00:36:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=crudebyte.com header.i=@crudebyte.com header.b="DpIKMuCV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 17186207FD Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=crudebyte.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:57475 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irACB-0004Eb-7z for patchwork-qemu-devel@patchwork.kernel.org; Mon, 13 Jan 2020 19:36:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34363) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from <8351c098c0bd0ff63a57587e0e6bbe09d4efb760@lizzy.crudebyte.com>) id 1irAAS-00081k-K6 for qemu-devel@nongnu.org; Mon, 13 Jan 2020 19:34:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from <8351c098c0bd0ff63a57587e0e6bbe09d4efb760@lizzy.crudebyte.com>) id 1irAAR-0000gN-FG for qemu-devel@nongnu.org; Mon, 13 Jan 2020 19:34:48 -0500 Received: from lizzy.crudebyte.com ([91.194.90.13]:45835) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from <8351c098c0bd0ff63a57587e0e6bbe09d4efb760@lizzy.crudebyte.com>) id 1irAAR-00083u-8a for qemu-devel@nongnu.org; Mon, 13 Jan 2020 19:34:47 -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=DpIKM uCVI8zRpoZ/n8I0P6zJMhODbkjgXYPRQ75/YPf+XPN82ILj+LKjwz29zxvrWk+3frssEZDfkniHse gzsacxTwpSaBErVxZ//J1kU8Ay3genkKBh4R1i3fmweT70jJvVHm3WGebPH6ssgBQ4e5jsXQRx1ox A/ITRrPAtYYcDRZ3R46qS6GhfFZ1frLPyeuKspkKy+fntZeZGmWVgXWqYmEC3aq8XBwR2fu3wfPFB M3mBEPzjTYYyJIVNNJsphYvlvqHecmzIv/3uGuiEBRfZ/bcmyttw8VlSp3Lsd54jAs2Woxs12cjBx QIjb4zr6MqqVsjwwW/e+9PgCXsfoA==; Message-Id: <8351c098c0bd0ff63a57587e0e6bbe09d4efb760.1578957500.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Tue, 14 Jan 2020 00:16:41 +0100 Subject: [PATCH v3 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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, } static struct dirent *synth_get_dentry(V9fsSynthNode *dir, - struct dirent *entry, off_t off) + struct dirent *entry, off_t off, + V9fsSynthNode **hack) { int i = 0; V9fsSynthNode *node; @@ -243,16 +244,38 @@ static struct dirent *synth_get_dentry(V9fsSynthNode *dir, /* end of directory */ return NULL; } + *hack = node; synth_direntry(node, entry, off); return entry; } static struct dirent *synth_readdir(FsContext *ctx, V9fsFidOpenState *fs) { - struct dirent *entry; + struct dirent *entry = NULL; V9fsSynthOpenState *synth_open = fs->private; V9fsSynthNode *node = synth_open->node; - entry = 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 which + * 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 efficiently. + * + * not a good idea for any production code ;-) + */ + static struct V9fsSynthNode *cachedNode; + + if (!cachedNode) { + entry = synth_get_dentry(node, &synth_open->dent, synth_open->offset, + &cachedNode); + } else { + cachedNode = cachedNode->sibling.le_next; + if (cachedNode) { + entry = &synth_open->dent; + synth_direntry(cachedNode, entry, synth_open->offset + 1); + } + } if (entry) { synth_open->offset++; }