Skip to contentSkip to conversation

COMMON: Add __stringify() function

PATCH New Marek Vasut 3 participants 15 messages Jul 28, 2012 – Jul 31, 2012 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 COMMON: Add __stringify() function

This function converts static number to string in preprocessor. This is useful as it allows higher usage of puts() in favour of printf()

Cc Wolfgang Denk <[email protected]>
Cc Mike Frysinger <[email protected]>
---
 include/common.h |    7 +++++++
 1 file changed, 7 insertions(+)
include/common.h +7 -0
index d1dd65a..451917d 100644
@@ -268,6 +268,13 @@ typedef void (interrupt_handler_t)(void *);
 	const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
 	(type *)( (char *)__mptr - offsetof(type,member) );})
 
+/**
+ * __stringify - preprocessor magic to return string from number
+ * @x:           constant number
+ */
+#define __stringify_1(x...)     #x
+#define __stringify(x...)       __stringify_1(x)
+
 /*
  * Function Prototypes
  */
Signature · 1 line
1.7.10.4
#1 lore raw

RFC PATCH 2/2 crazy: Sort u_boot_cmd at runtime

This shall eliminate the need for bubblesorting of commands at runtime. Every command definition structure is now put into it's own subsection of section .u_boot_cmd, that is .u_boot_cmd.<name> . These are then put into .u_boot_cmd by linker and lastly, linker uses SORT() over these subsections to make proper order on them. This shall eliminate some runtime overhead.

Cc Wolfgang Denk <[email protected]>
Cc Mike Frysinger <[email protected]>
---
 arch/arm/cpu/u-boot.lds |    2 +-
 common/cmd_help.c       |    2 +-
 include/command.h       |    9 ++++++---
 3 files changed, 8 insertions(+), 5 deletions(-)

********
* NOTE * THIS PATCH IS CRAZY
********

Further notes:
- This is only compile-tested with gcc-4.7 (debian 4.7.1-5, binutils 2.22)
- This patch affects only arm926t, obviously to make it proper, every linkerscript would have to be adjusted
- I'm not sure at all the macro logic is correct, please check
- Can this crash on *BSD or with older linker/cpp?
- Please don't rip me limb to limb ;-)

arch/arm/cpu/u-boot.lds +1 -1
index e49ca0c..c39193b 100644
@@ -50,7 +50,7 @@ SECTIONS
 
 	. = .;
 	__u_boot_cmd_start = .;
-	.u_boot_cmd : { *(.u_boot_cmd) }
+	.u_boot_cmd : { *(SORT(.u_boot_cmd.*)) }
 	__u_boot_cmd_end = .;
 
 	. = ALIGN(4);
common/cmd_help.c +1 -1
index 8c8178e..5d778f5 100644
@@ -41,7 +41,7 @@ U_BOOT_CMD(
 );
 
 /* This does not use the U_BOOT_CMD macro as ? can't be used in symbol names */
-cmd_tbl_t __u_boot_cmd_question_mark Struct_Section = {
+cmd_tbl_t __u_boot_cmd_question_mark Struct_Section(?) = {
 	"?",	CONFIG_SYS_MAXARGS,	1,	do_help,
 	"alias for 'help'",
 #ifdef  CONFIG_SYS_LONGHELP
include/command.h +6 -3
index 6e1bdc2..42b4c6a 100644
@@ -149,8 +149,11 @@ int cmd_process(int flag, int argc, char * const argv[],
 #define CMD_FLAG_REPEAT		0x0001	/* repeat last command		*/
 #define CMD_FLAG_BOOTD		0x0002	/* command is from bootd	*/
 
-#define Struct_Section  __attribute__((unused, section(".u_boot_cmd"), \
-		aligned(4)))
+#define __sectstr(__cmd,__name)	.__cmd.__name
+#define sectstr(type, __name)		__stringify(__sectstr(type, __name))
+
+#define Struct_Section(__name)	\
+	__attribute__((unused, section(sectstr(u_boot_cmd, __name)), aligned(4)))
 
 #ifdef CONFIG_AUTO_COMPLETE
 # define _CMD_COMPLETE(x) x,
@@ -170,7 +173,7 @@ int cmd_process(int flag, int argc, char * const argv[],
 	U_BOOT_CMD_MKENT_COMPLETE(name,maxargs,rep,cmd,usage,help,NULL)
 
 #define U_BOOT_CMD_COMPLETE(name,maxargs,rep,cmd,usage,help,comp) \
-	cmd_tbl_t __u_boot_cmd_##name Struct_Section = \
+	cmd_tbl_t __u_boot_cmd_##name Struct_Section(name) = \
 		U_BOOT_CMD_MKENT_COMPLETE(name,maxargs,rep,cmd,usage,help,comp)
 
 #define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help) \
Signature · 1 line
1.7.10.4
#2 lore raw

RFC PATCH 2/2 crazy: Sort u_boot_cmd at runtime

Dear Marek Vasut,

Quoted 7 lines · In message <[email protected]> you wrote:

This shall eliminate the need for bubblesorting of commands at runtime. Every command definition structure is now put into it's own subsection of section .u_boot_cmd, that is .u_boot_cmd.<name> . These are then put into .u_boot_cmd by linker and lastly, linker uses SORT() over these subsections to make proper order on them. This shall eliminate some runtime overhead.

Quoted 8 lines
Cc Wolfgang Denk <[email protected]>
Cc Mike Frysinger <[email protected]>
---
 arch/arm/cpu/u-boot.lds |    2 +-
 common/cmd_help.c       |    2 +-
 include/command.h       |    9 ++++++---
 3 files changed, 8 insertions(+), 5 deletions(-)

Seems incomplete in several aspects:

1) what about all the non-ARM architecures and the board specific linker scripts?

2) what about removing the sort code?

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Men of peace usually are [brave].
	-- Spock, "The Savage Curtain", stardate 5906.5
#3 lore raw

RFC PATCH 2/2 crazy: Sort u_boot_cmd at runtime

Dear Wolfgang Denk,

Quoted 15 lines

Dear Marek Vasut,

Quoted 12 lines · In message <[email protected]> you wrote:

This shall eliminate the need for bubblesorting of commands at runtime. Every command definition structure is now put into it's own subsection of section .u_boot_cmd, that is .u_boot_cmd.<name> . These are then put into .u_boot_cmd by linker and lastly, linker uses SORT() over these subsections to make proper order on them. This shall eliminate some runtime overhead.

Cc Wolfgang Denk <[email protected]>
Cc Mike Frysinger <[email protected]>

---

Quoted 6 lines
Quoted 4 lines
 arch/arm/cpu/u-boot.lds |    2 +-
 common/cmd_help.c       |    2 +-
 include/command.h       |    9 ++++++---
 3 files changed, 8 insertions(+), 5 deletions(-)

Seems incomplete in several aspects:

Below the section:

* NOTE * THIS PATCH IS CRAZY

There are a few notes. I'd actually like to know if this approach is correct at all, it might break on some crazy configurations or such.

Quoted 2 lines

1) what about all the non-ARM architecures and the board specific linker scripts?

- This patch affects only arm926t, obviously to make it proper, every linkerscript would have to be adjusted

Which sucks, since there're a lot of them. But it can probably be automated.

Quoted 1 line

2) what about removing the sort code?

You mean in the _do_help() in common/command.c? We can do not only that, but we can do bisect search in find_cmd_tbl() now too. I'm still trying to figure out the most optimal implementation. The current one I have trimmed down the time by roughly 60%, but I don't like it.

Quoted 3 lines

Best regards,

Wolfgang Denk

Best regards,
Marek Vasut

#4 lore raw

RFC PATCH 2/2 crazy: Sort u_boot_cmd at runtime

Dear Marek Vasut,

Quoted 6 lines · In message <[email protected]> you wrote:
Quoted 2 lines

Seems incomplete in several aspects:

Below the section:

* NOTE * THIS PATCH IS CRAZY

Then what is actually the purpose of such a posting? Just dumping unsorted thoughts to community?

You are experienced enough to know what would be needed for a semi-clean patch, even if it's "just for RFC"...

Quoted 2 lines

There are a few notes. I'd actually like to know if this approach is correct at all, it might break on some crazy configurations or such.

Define "correct". It may be possible - but what would be the advantage? Which problem does it solve? In which way is it better than the current code?

Quoted 7 lines
Quoted 2 lines

1) what about all the non-ARM architecures and the board specific linker scripts?

- This patch affects only arm926t, obviously to make it proper, every linkerscript would have to be adjusted

Which sucks, since there're a lot of them. But it can probably be automated.

Actually I doubt it makes sense at all.

I envision a situation where some "pluggable" code (say, a standalone application, or some form of loadable module whatever) can add new commands - it would be nice if these would still appear in sorted order, but this cannot be done at compile-time.

So please explain which actual problem you are rying to solve.

Best regards,

Wolfgang Denk

Signature · 7 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
It [being a Vulcan] means to adopt a philosophy, a way of life  which
is logical and beneficial. We cannot disregard that philosophy merely
for personal gain, no matter how important that gain might be.
	-- Spock, "Journey to Babel", stardate 3842.4
#5 lore raw

RFC PATCH 2/2 crazy: Sort u_boot_cmd at runtime

Dear Wolfgang Denk,

Quoted 10 lines

Dear Marek Vasut,

Quoted 4 lines · In message <[email protected]> you wrote:
Quoted 1 line

Seems incomplete in several aspects:

Below the section:

* NOTE * THIS PATCH IS CRAZY

Then what is actually the purpose of such a posting? Just dumping unsorted thoughts to community?

I'd prefer to get some feedback, you know ...

Quoted 2 lines

You are experienced enough to know what would be needed for a semi-clean patch, even if it's "just for RFC"...

If you mean droping the ascii art ... well, yes.

But for draft patch, I'd like to actually see further ideas.

Quoted 4 lines
Quoted 2 lines

There are a few notes. I'd actually like to know if this approach is correct at all, it might break on some crazy configurations or such.

Define "correct".

If there's not some obvious flub in the code. If this kind of abuse of CPP is correct or not.

Quoted 1 line

It may be possible - but what would be the advantage?

The list of commands will be already sorted.

Quoted 1 line

Which problem does it solve?

Optimization, nothing else.

Quoted 1 line

In which way is it better than the current code?

It's a bit faster.

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

1) what about all the non-ARM architecures and the board specific

linker scripts?

Quoted 8 lines
Quoted 6 lines

- This patch affects only arm926t, obviously to make it proper, every

linkerscript would have to be adjusted

Which sucks, since there're a lot of them. But it can probably be automated.

Actually I doubt it makes sense at all.

It actually does ... but not in such a plain context.

I did this patch because we want the driver lists sorted. So I did this research and implemented it on the command list. I wanted to gather some feedback on if this actually can be done in such a way or if there'll be problems with toolchains maybe. Or any other issues.

Quoted 4 lines

I envision a situation where some "pluggable" code (say, a standalone application, or some form of loadable module whatever) can add new commands - it would be nice if these would still appear in sorted order, but this cannot be done at compile-time.

Certainly ... but we can keep a separate runtime table for these added commands.

Quoted 5 lines

So please explain which actual problem you are rying to solve.

Best regards,

Wolfgang Denk

Best regards,
Marek Vasut

#6 lore raw

PATCH 1/2 COMMON: Add __stringify() function

In reply to Marek Vasut

Dear Marek Vasut,

Quoted 9 lines · In message <[email protected]> you wrote:

This function converts static number to string in preprocessor. This is useful as it allows higher usage of puts() in favour of printf()

Cc Wolfgang Denk <[email protected]>
Cc Mike Frysinger <[email protected]>
---
 include/common.h |    7 +++++++
 1 file changed, 7 insertions(+)

We have similar things already, and we don't add dead code - you add a macro without users here.

If you want to unify the use of such a macro, fine - but then please replace all ocurrences of equivalent definitions all over the code.

Thanks.

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Bus error -- driver executed.
#7 lore raw

PATCH 1/2 COMMON: Add __stringify() function

Dear Wolfgang Denk,

Quoted 11 lines

Dear Marek Vasut,

Quoted 8 lines · In message <[email protected]> you wrote:

This function converts static number to string in preprocessor. This is useful as it allows higher usage of puts() in favour of printf()

Cc Wolfgang Denk <[email protected]>
Cc Mike Frysinger <[email protected]>

---

Quoted 5 lines
Quoted 2 lines
 include/common.h |    7 +++++++
 1 file changed, 7 insertions(+)

We have similar things already, and we don't add dead code - you add a macro without users here.

It's used in 2/2 ... what macro do you have in mind ?

Quoted 8 lines

If you want to unify the use of such a macro, fine - but then please replace all ocurrences of equivalent definitions all over the code.

Thanks.

Best regards,

Wolfgang Denk

Best regards,
Marek Vasut

#8 lore raw

PATCH 1/2 COMMON: Add __stringify() function

Dear Marek Vasut,

Quoted 8 lines · In message <[email protected]> you wrote:
Quoted 6 lines
Quoted 3 lines
 include/common.h |    7 +++++++
 1 file changed, 7 insertions(+)

We have similar things already, and we don't add dead code - you add a macro without users here.

It's used in 2/2 ... what macro do you have in mind ?

Then add it with the patch that uses it.

As for existing use, see for example

arch/powerpc/include/asm/processor.h:#define stringify(s) tostring(s)
drivers/mtd/ubi/build.c:#include <linux/stringify.h>
include/configs/km/keymile-common.h:#define xstr(s) str(s)
include/configs/imx27lite-common.h:#define xstr(s) str(s)
include/configs/tx25.h:#define xstr(s) str(s)
include/configs/mx35pdk.h:#define xstr(s) str(s)
include/configs/cam_enc_4xx.h:#define xstr(s) str(s)
include/configs/ea20.h:#define xstr(s) str(s)
include/configs/MPC8308RDB.h:#define xstr(s) str(s)
include/configs/mpc8308_p1m.h:#define xstr(s) str(s)
include/configs/flea3.h:#define xstr(s) str(s)
include/configs/enbw_cmc.h:#define xstr(s) str(s)
include/configs/at91sam9263ek.h:#define xstr(s) str(s)
include/configs/amcc-common.h:#define xstr(s) str(s)
include/configs/tam3517-common.h:#define xstr(s) str(s)
include/configs/manroland/common.h:#define xstr(s) str(s)
include/configs/qong.h:#define xstr(s) str(s)
include/configs/ima3-mx53.h:#define xstr(s) str(s)

Quoted 2 lines
Quoted 2 lines

If you want to unify the use of such a macro, fine - but then please replace all ocurrences of equivalent definitions all over the code.

All these above (and any I eventually didn't find) should be replaced, then.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
In the bathtub of history the truth is harder to hold than the  soap,
and much more difficult to find ...     - Terry Pratchett, _Sourcery_
#9 lore raw

PATCH 1/2 COMMON: Add __stringify() function

Dear Wolfgang Denk,

Quoted 6 lines

Dear Marek Vasut,

Quoted 3 lines · In message <[email protected]> you wrote:
Quoted 3 lines
Quoted 2 lines
 include/common.h |    7 +++++++
 1 file changed, 7 insertions(+)
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

We have similar things already, and we don't add dead code - you add a macro without users here.

It's used in 2/2 ... what macro do you have in mind ?

Then add it with the patch that uses it.

I really wanted to keep this one separate, but I'll bend here. But if you mention those xstr()s below, it might be actually better to add __stringify() and then replace all those crazy xstr()s.

Quoted 1 line

As for existing use, see for example

[...]

Quoted 1 line

include/configs/ima3-mx53.h:#define xstr(s) str(s)

Thanks for pointing this out.

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

If you want to unify the use of such a macro, fine - but then please replace all ocurrences of equivalent definitions all over the code.

All these above (and any I eventually didn't find) should be replaced, then.

Good.

Quoted 3 lines

Best regards,

Wolfgang Denk

Best regards,
Marek Vasut

#10 lore raw

PATCH 1/2 COMMON: Add __stringify() function

In reply to Wolfgang Denk
Quoted 4 lines · On Saturday 28 July 2012 15:57:33 Wolfgang Denk wrote:
Quoted 3 lines · Marek Vasut
Quoted 3 lines
Quoted 2 lines
 include/common.h |    7 +++++++
 1 file changed, 7 insertions(+)
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

We have similar things already, and we don't add dead code - you add a macro without users here.

It's used in 2/2 ... what macro do you have in mind ?

Then add it with the patch that uses it.

As for existing use, see for example

there's also MK_STR() and XMK_STR(). would be good to import linux/stringify.h (rather than adding these macros to common.h) and converting all consumers over to that.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120731/0b2baae2/attachment.pgp>

#11 lore raw

PATCH 1/2 COMMON: Add __stringify() function

Dear Mike Frysinger,

Quoted 8 lines · On Saturday 28 July 2012 15:57:33 Wolfgang Denk wrote:
Quoted 7 lines
Quoted 6 lines · Marek Vasut
Quoted 5 lines
Quoted 2 lines
 include/common.h |    7 +++++++
 1 file changed, 7 insertions(+)

We have similar things already, and we don't add dead code - you add a macro without users here.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

It's used in 2/2 ... what macro do you have in mind ?

Then add it with the patch that uses it.

As for existing use, see for example

there's also MK_STR() and XMK_STR().

Grunt ... how do you find those? Or is it that you just happened to run over them?

Quoted 3 lines

would be good to import
linux/stringify.h (rather than adding these macros to common.h) and converting all consumers over to that.

I wonder, what's the gain?

Quoted 1 line

-mike

Best regards,
Marek Vasut

#12 lore raw

PATCH 1/2 COMMON: Add __stringify() function

Quoted 11 lines · On Tuesday 31 July 2012 09:55:55 Marek Vasut wrote:

Dear Mike Frysinger,

Quoted 10 lines · On Saturday 28 July 2012 15:57:33 Wolfgang Denk wrote:
Quoted 9 lines
Quoted 7 lines · Marek Vasut
Quoted 5 lines
Quoted 2 lines
 include/common.h |    7 +++++++
 1 file changed, 7 insertions(+)

We have similar things already, and we don't add dead code - you add a macro without users here.

It's used in 2/2 ... what macro do you have in mind ?

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Then add it with the patch that uses it.

As for existing use, see for example

there's also MK_STR() and XMK_STR().

Grunt ... how do you find those? Or is it that you just happened to run over them?

these are the ones we use in Blackfin boards that i happened to stumble across when reading some common code

Quoted 5 lines
Quoted 3 lines

would be good to import
linux/stringify.h (rather than adding these macros to common.h) and converting all consumers over to that.

I wonder, what's the gain?

one less way we're different from linux for importing code
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120731/42e5ba39/attachment.pgp>

#13 lore raw

PATCH 1/2 COMMON: Add __stringify() function

Dear Mike Frysinger,

Quoted 17 lines · On Tuesday 31 July 2012 09:55:55 Marek Vasut wrote:
Quoted 16 lines

Dear Mike Frysinger,

Quoted 14 lines · On Saturday 28 July 2012 15:57:33 Wolfgang Denk wrote:
Quoted 12 lines
Quoted 7 lines · Marek Vasut
Quoted 5 lines
Quoted 2 lines
 include/common.h |    7 +++++++
 1 file changed, 7 insertions(+)

We have similar things already, and we don't add dead code - you add a macro without users here.

It's used in 2/2 ... what macro do you have in mind ?

Then add it with the patch that uses it.

As for existing use, see for example

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

there's also MK_STR() and XMK_STR().

Grunt ... how do you find those? Or is it that you just happened to run over them?

these are the ones we use in Blackfin boards that i happened to stumble across when reading some common code

Ugh ... makes you feel like Indy, discovering gems in crazy places and fighting hordes of evil code ...

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

would be good to import
linux/stringify.h (rather than adding these macros to common.h) and converting all consumers over to that.

I wonder, what's the gain?

one less way we're different from linux for importing code

Not that that macro is ever gonna change, but so be it.

Quoted 1 line

-mike

Best regards,
Marek Vasut

#14 lore raw

PATCH 1/2 COMMON: Add __stringify() function

Quoted 7 lines · On Tuesday 31 July 2012 10:08:51 Marek Vasut wrote:

Dear Mike Frysinger,

Quoted 6 lines · On Tuesday 31 July 2012 09:55:55 Marek Vasut wrote:
Quoted 5 lines

Dear Mike Frysinger,

Quoted 3 lines

would be good to import
linux/stringify.h (rather than adding these macros to common.h) and converting all consumers over to that.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

I wonder, what's the gain?

one less way we're different from linux for importing code

Not that that macro is ever gonna change, but so be it.

i meant #include's, not the API itself. you're right that likely this API will never change.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120731/0e397e95/attachment.pgp>