From mboxrd@z Thu Jan 1 00:00:00 1970 From: Joe Perches Subject: Re: [PATCH v2] vsprintf: Add %p extension "%pOF" for device tree Date: Thu, 22 Jun 2017 20:01:52 -0700 Message-ID: <1498186912.24295.9.camel@perches.com> References: <20170614203025.7581-4-robh@kernel.org> <20170622204445.14930-1-robh@kernel.org> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20170622204445.14930-1-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> Sender: devicetree-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: Rob Herring , Grant Likely , Frank Rowand , Mark Rutland Cc: Pantelis Antoniou , devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-Id: devicetree@vger.kernel.org On Thu, 2017-06-22 at 15:44 -0500, Rob Herring wrote: > From: Pantelis Antoniou > > 90% of the usage of device node's full_name is printing it out in a > kernel message. However, storing the full path for every node is > wasteful and redundant. With a custom format specifier, we can generate > the full path at run-time and eventually remove the full path from every > node. > > For instance typical use is: > pr_info("Frobbing node %s\n", node->full_name); > > Which can be written now as: > pr_info("Frobbing node %pOF\n", node); I still think this should use another identifier like %pO for object then another letter for type of object maybe N for node. And F is flags, f is name > diff --git a/lib/vsprintf.c b/lib/vsprintf.c [] > @@ -1470,6 +1471,131 @@ char *flags_string(char *buf, char *end, void *flags_ptr, const char *fmt) > return format_flags(buf, end, flags, names); > } > > +static int device_node_calc_depth(const struct device_node *np) > +{ > + int d; > + > + for (d = 0; np; d++) > + np = np->parent; > + > + return d; > +} > + > +static noinline_for_stack > +char *device_node_gen_full_name(const struct device_node *np, char *buf, char *end) > +{ > + int i; > + int depth = device_node_calc_depth(np); > + static const struct printf_spec strspec = { > + .field_width = -1, > + .precision = -1, > + }; > + const struct device_node *nodes[depth]; > + > + if (!depth) > + returnuf; > + /* special case for root node */ > + if (depth == 1) > + return string(buf, end, "/", strspec); > + > + depth--; > + for (i = depth - 1; i >= 0; i--) { > + nodes[i] = np; > + np = np->parent; > + } > + for (i = 0; i < depth; i++) { > + buf = string(buf, end, "/", strspec); > + buf = string(buf, end, kbasename(nodes[i]->full_name), strspec); > + } > + return buf; > +} I think there should be another function to get a particular struct device_node * at a particular depth to avoid all the pointers on stack. Basically, adapt the for (i = depth - 1 loop to a function that returns nodes[i] -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754130AbdFWDB6 (ORCPT ); Thu, 22 Jun 2017 23:01:58 -0400 Received: from smtprelay0005.hostedemail.com ([216.40.44.5]:43465 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753557AbdFWDB5 (ORCPT ); Thu, 22 Jun 2017 23:01:57 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::,RULES_HIT:41:355:379:541:599:800:960:968:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2828:3138:3139:3140:3141:3142:3354:3622:3743:3865:3866:3867:3868:3870:3871:3872:3874:4321:5007:7576:7904:7974:10004:10400:10482:10848:11026:11232:11658:11914:12043:12048:12296:12438:12740:12760:12895:13095:13439:14181:14659:14721:19901:19997:21080:21433:21451:21627:30029:30030:30054:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:2,LUA_SUMMARY:none X-HE-Tag: bat10_8512c799cc70e X-Filterd-Recvd-Size: 3076 Message-ID: <1498186912.24295.9.camel@perches.com> Subject: Re: [PATCH v2] vsprintf: Add %p extension "%pOF" for device tree From: Joe Perches To: Rob Herring , Grant Likely , Frank Rowand , Mark Rutland Cc: Pantelis Antoniou , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Date: Thu, 22 Jun 2017 20:01:52 -0700 In-Reply-To: <20170622204445.14930-1-robh@kernel.org> References: <20170614203025.7581-4-robh@kernel.org> <20170622204445.14930-1-robh@kernel.org> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.22.6-1ubuntu1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2017-06-22 at 15:44 -0500, Rob Herring wrote: > From: Pantelis Antoniou > > 90% of the usage of device node's full_name is printing it out in a > kernel message. However, storing the full path for every node is > wasteful and redundant. With a custom format specifier, we can generate > the full path at run-time and eventually remove the full path from every > node. > > For instance typical use is: > pr_info("Frobbing node %s\n", node->full_name); > > Which can be written now as: > pr_info("Frobbing node %pOF\n", node); I still think this should use another identifier like %pO for object then another letter for type of object maybe N for node. And F is flags, f is name > diff --git a/lib/vsprintf.c b/lib/vsprintf.c [] > @@ -1470,6 +1471,131 @@ char *flags_string(char *buf, char *end, void *flags_ptr, const char *fmt) > return format_flags(buf, end, flags, names); > } > > +static int device_node_calc_depth(const struct device_node *np) > +{ > + int d; > + > + for (d = 0; np; d++) > + np = np->parent; > + > + return d; > +} > + > +static noinline_for_stack > +char *device_node_gen_full_name(const struct device_node *np, char *buf, char *end) > +{ > + int i; > + int depth = device_node_calc_depth(np); > + static const struct printf_spec strspec = { > + .field_width = -1, > + .precision = -1, > + }; > + const struct device_node *nodes[depth]; > + > + if (!depth) > + returnuf; > + /* special case for root node */ > + if (depth == 1) > + return string(buf, end, "/", strspec); > + > + depth--; > + for (i = depth - 1; i >= 0; i--) { > + nodes[i] = np; > + np = np->parent; > + } > + for (i = 0; i < depth; i++) { > + buf = string(buf, end, "/", strspec); > + buf = string(buf, end, kbasename(nodes[i]->full_name), strspec); > + } > + return buf; > +} I think there should be another function to get a particular struct device_node * at a particular depth to avoid all the pointers on stack. Basically, adapt the for (i = depth - 1 loop to a function that returns nodes[i]