Received: by 10.223.185.116 with SMTP id b49csp2071987wrg; Mon, 12 Feb 2018 03:56:28 -0800 (PST) X-Google-Smtp-Source: AH8x224eVTMaAQIhClwoFref+yj39X61JaY2+WY6rvGlYgnaAclf6hM/xMXnfSQf29fq0bV6ucrd X-Received: by 2002:a17:902:12f:: with SMTP id 44-v6mr10577788plb.403.1518436588232; Mon, 12 Feb 2018 03:56:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518436588; cv=none; d=google.com; s=arc-20160816; b=oTZm1AxQJ1cQCQnO63OhTS/TsL6w0A0iiyo7FSkI28lOi3CAkTI06R/nICPtHd9YAR DWsv+UggT3b+LK/cWHpQkOyfvbEGI3MByh+mX3zzeFeq6KD4OkcxbYTofMpVmAUexpLA rmfDm+CReADKivzUZiTSXXu+Y3ic+axuBcs61gBfaOlQjoMHI6sbTgc9hbKgUm/x8FZp hB8GvIxRDL1Lbo3/4zd09ac5Gt/S0scIbxnam5LgAIMFdf+1QNk3/cWfVzKO+u0wRUbO sg0lZXeFGdCtWHdt6KN4YwwkYR5SRPxV0t9BDqtGZdCSBsZGbbEB+1tsLxVzu3g77LlC S6Eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=EtE88PyJi+izzM9tAWI4jbCt78o2rIByJvpgmGPjOCk=; b=YPM98VfJL31PXcMLpS5m8aw4epi1D7SxAPJ9IY0c3dZTADaoU/RDF8TRs+9488zF2Q PCQ2frAXPoo1jpo9488N97ETrtJSFSFBDuCcTGNqDvitDUO4/N7fQeqM49rjNAsBz3Ad 4K24w3ItpjML2lWo/9vvkx/Gj6g/ayC6ur7ybv5wB4ce8bfRVpxOhnc7IEwfJA/aJ76a iHX7KovJM/jKVErp7Zo1KrjLxU7Oxv+JWC4Gvem6hffR41cYPwkvBxw4iARwJFTyt2bu aCYMgW5AhBlFwPvTEl3MtpFqsbkE1Ma64HOfHbJ2+Vvt3OAG9QSNGMpb8oHdwiUxPOeG yWxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@prevas.dk header.s=ironport2 header.b=SpwBB7zr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n12si5095566pgu.475.2018.02.12.03.56.14; Mon, 12 Feb 2018 03:56:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@prevas.dk header.s=ironport2 header.b=SpwBB7zr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933112AbeBLI6o (ORCPT + 99 others); Mon, 12 Feb 2018 03:58:44 -0500 Received: from mail02.prevas.se ([62.95.78.10]:54445 "EHLO mail02.prevas.se" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932630AbeBLI6l (ORCPT ); Mon, 12 Feb 2018 03:58:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=prevas.dk; i=@prevas.dk; l=2086; q=dns/txt; s=ironport2; t=1518425920; x=1549961920; h=subject:to:cc:references:from:message-id:date: mime-version:in-reply-to:content-transfer-encoding; bh=xA/iKwrLY8KaY+3Sz3hvf0RB0aw2Yi6BeY+itzYrmE8=; b=SpwBB7zrt/U2igerRQ4HDzaHAetv8VKIA6S3UyeG8rcZao8+mj67xAud IKPmAfI7bSlqcfVIwD0QmhG7ctSV74xq2yac71B0bDMrixbKajaMmJD+1 V4L/odBkCGAomI9KCoiIGH2kVoharkUMsEPSaXbZQxy88bkCZezl+JsQI Q=; X-IronPort-AV: E=Sophos;i="5.46,501,1511823600"; d="scan'208";a="3045692" Received: from vmprevas4.prevas.se (HELO smtp.prevas.se) ([172.16.8.104]) by ironport2.prevas.se with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Feb 2018 09:58:38 +0100 Received: from [172.16.11.22] (172.16.8.31) by smtp.prevas.se (172.16.8.104) with Microsoft SMTP Server (TLS) id 14.3.361.1; Mon, 12 Feb 2018 09:58:37 +0100 Subject: Re: [PATCH v2] of: cache phandle nodes to reduce cost of of_find_node_by_phandle() To: , Rob Herring , CC: , References: <1518416868-8804-1-git-send-email-frowand.list@gmail.com> From: Rasmus Villemoes Message-ID: <5ca5194d-8b87-bcb6-73ca-a671075e4704@prevas.dk> Date: Mon, 12 Feb 2018 09:58:37 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <1518416868-8804-1-git-send-email-frowand.list@gmail.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [172.16.8.31] Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018-02-12 07:27, frowand.list@gmail.com wrote: > From: Frank Rowand > > Create a cache of the nodes that contain a phandle property. Use this > cache to find the node for a given phandle value instead of scanning > the devicetree to find the node. If the phandle value is not found > in the cache, of_find_node_by_phandle() will fall back to the tree > scan algorithm. > > The cache is initialized in of_core_init(). > > The cache is freed via a late_initcall_sync() if modules are not > enabled. Maybe a few words about the memory consumption of this solution versus the other proposed ones. Other nits below. > +static void of_populate_phandle_cache(void) > +{ > + unsigned long flags; > + phandle max_phandle; > + u32 nodes = 0; > + struct device_node *np; > + > + if (phandle_cache) > + return; What's the point of that check? And shouldn't it be done inside the spinlock if at all? > + max_phandle = live_tree_max_phandle(); > + > + raw_spin_lock_irqsave(&devtree_lock, flags); > + > + for_each_of_allnodes(np) > + nodes++; Why not save a walk over all nodes and a spin_lock/unlock pair by combining the node count with the max_phandle computation? But you've just moved the existing live_tree_max_phandle, so probably better as a followup patch. > + /* sanity cap for malformed tree */ > + if (max_phandle > nodes) > + max_phandle = nodes; > + > + phandle_cache = kzalloc((max_phandle + 1) * sizeof(*phandle_cache), > + GFP_ATOMIC); Maybe kcalloc. Sure, you've capped max_phandle so there's no real risk of overflow. > + for_each_of_allnodes(np) > + if (np->phandle != OF_PHANDLE_ILLEGAL && > + np->phandle <= max_phandle && > + np->phandle) I'd reverse the order of these conditions so that for all the nodes with no phandle we only do the np->phandle check. Also, extra whitespace before &&. > + phandle_cache[np->phandle] = np; > + > + max_phandle_cache = max_phandle; > + > + raw_spin_unlock_irqrestore(&devtree_lock, flags); > +} > + Rasmus