* Re: [PATCH] kselftest: Move the docs to the Documentation dir
From: Shuah Khan @ 2014-11-20 13:56 UTC (permalink / raw)
To: Tim Bird, linux-api, corbet
Cc: linux-kernel@vger.kernel.org, linux-embedded@vger.kernel.org,
Shuah Khan, linux-doc
In-Reply-To: <546D32D0.9090206@sonymobile.com>
On 11/19/2014 05:16 PM, Tim Bird wrote:
>
> Also, adjust the formatting a bit, and expand the section about using
> TARGETS= on the make command line.
>
> Signed-off-by: Tim Bird <tim.bird@sonymobile.com>
> ---
> Documentation/kselftest.txt | 69 ++++++++++++++++++++++++++++++++++++++
> tools/testing/selftests/README.txt | 61 ---------------------------------
> 2 files changed, 69 insertions(+), 61 deletions(-)
> create mode 100644 Documentation/kselftest.txt
> delete mode 100644 tools/testing/selftests/README.txt
>
> diff --git a/Documentation/kselftest.txt b/Documentation/kselftest.txt
> new file mode 100644
> index 0000000..a87d840
> --- /dev/null
> +++ b/Documentation/kselftest.txt
>
Tim,
Thanks for doing this. Looks good to me. I think you missed
Documentation maintainer. Adding linux-doc and Jon Corbet to
the thread with my ack to take this through Documentation tree.
Acked-by: shuahkh@osg.samsung.com
thanks,
-- Shuah
--
Shuah Khan
Sr. Linux Kernel Developer
Samsung Research America (Silicon Valley)
shuahkh@osg.samsung.com | (970) 217-8978
^ permalink raw reply
* Re: [PATCH v2] selftest: size: Add size test for Linux kernel
From: Shuah Khan @ 2014-11-20 21:58 UTC (permalink / raw)
To: Tim Bird, linux-api-u79uwXL29TY76Z2rM5mHXA
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-embedded-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Shuah Khan
In-Reply-To: <546D321F.2080405-/MT0OVThwyLZJqsBc5GL+g@public.gmane.org>
On 11/19/2014 05:13 PM, Tim Bird wrote:
>
> This test shows the amount of memory used by the system.
> Note that this is dependent on the user-space that is loaded
> when this program runs. Optimally, this program would be
> run as the init program itself.
>
> The program is optimized for size itself, to avoid conflating
> its own execution with that of the system software.
> The code is compiled statically, with no stdlibs. On my x86_64 system,
> this results in a statically linked binary of less than 5K.
>
> Changes from v1:
> - use more correct Copyright string in get_size.c
>
> Signed-off-by: Tim Bird <tim.bird-/MT0OVThwyLZJqsBc5GL+g@public.gmane.org>
> ---
> tools/testing/selftests/Makefile | 1 +
> tools/testing/selftests/size/Makefile | 21 +++++++
> tools/testing/selftests/size/get_size.c | 105 ++++++++++++++++++++++++++++++++
> 3 files changed, 127 insertions(+)
> create mode 100644 tools/testing/selftests/size/Makefile
> create mode 100644 tools/testing/selftests/size/get_size.c
Tim,
The test looks good, but you are missing .gitignore file.
Please add a .gitignore for the binary that gets generated to
avoid git status including the binary it in its output.
thanks,
-- Shuah
--
Shuah Khan
Sr. Linux Kernel Developer
Samsung Research America (Silicon Valley)
shuahkh-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org | (970) 217-8978
^ permalink raw reply
* Re: [PATCH] kselftest: Move the docs to the Documentation dir
From: Jonathan Corbet @ 2014-11-24 17:49 UTC (permalink / raw)
To: Shuah Khan
Cc: Tim Bird, linux-api-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-embedded-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-doc-u79uwXL29TY76Z2rM5mHXA
In-Reply-To: <546DF325.6060507-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org>
On Thu, 20 Nov 2014 06:56:53 -0700
Shuah Khan <shuahkh-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org> wrote:
> Thanks for doing this. Looks good to me. I think you missed
> Documentation maintainer. Adding linux-doc and Jon Corbet to
> the thread with my ack to take this through Documentation tree.
Thanks for the heads-up. I've applied it to the docs tree now.
jon
^ permalink raw reply
* Re: [PATCH v2] selftest: size: Add size test for Linux kernel
From: Tim Bird @ 2014-11-24 18:08 UTC (permalink / raw)
To: Shuah Khan, linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-embedded-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
In-Reply-To: <546E640F.1090006-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org>
On 11/20/2014 01:58 PM, Shuah Khan wrote:
> On 11/19/2014 05:13 PM, Tim Bird wrote:
>>
>> This test shows the amount of memory used by the system.
>> Note that this is dependent on the user-space that is loaded
>> when this program runs. Optimally, this program would be
>> run as the init program itself.
>>
>> The program is optimized for size itself, to avoid conflating
>> its own execution with that of the system software.
>> The code is compiled statically, with no stdlibs. On my x86_64 system,
>> this results in a statically linked binary of less than 5K.
>>
>> Changes from v1:
>> - use more correct Copyright string in get_size.c
>>
>> Signed-off-by: Tim Bird <tim.bird-/MT0OVThwyLZJqsBc5GL+g@public.gmane.org>
>> ---
>> tools/testing/selftests/Makefile | 1 +
>> tools/testing/selftests/size/Makefile | 21 +++++++
>> tools/testing/selftests/size/get_size.c | 105 ++++++++++++++++++++++++++++++++
>> 3 files changed, 127 insertions(+)
>> create mode 100644 tools/testing/selftests/size/Makefile
>> create mode 100644 tools/testing/selftests/size/get_size.c
>
> Tim,
>
> The test looks good, but you are missing .gitignore file.
> Please add a .gitignore for the binary that gets generated to
> avoid git status including the binary it in its output.
Will do.
I'll send v3 today.
Thanks,
-- Tim
^ permalink raw reply
* Re: [PATCH v3] selftest: size: Add size test for Linux kernel
From: Tim Bird @ 2014-11-24 18:20 UTC (permalink / raw)
To: Shuah Khan, linux-api-u79uwXL29TY76Z2rM5mHXA
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-embedded-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
In-Reply-To: <546D321F.2080405-/MT0OVThwyLZJqsBc5GL+g@public.gmane.org>
This test shows the amount of memory used by the system.
Note that this is dependent on the user-space that is loaded
when this program runs. Optimally, this program would be
run as the init program itself.
The program is optimized for size itself, to avoid conflating
its own execution with that of the system software.
The code is compiled statically, with no stdlibs. On my x86_64 system,
this results in a statically linked binary of less than 5K.
Changes from v2:
- add return values to print routines
- add .gitignore file
Changes from v1:
- use more correct Copyright string in get_size.c
Signed-off-by: Tim Bird <tim.bird-/MT0OVThwyLZJqsBc5GL+g@public.gmane.org>
---
tools/testing/selftests/Makefile | 1 +
tools/testing/selftests/size/.gitignore | 1 +
tools/testing/selftests/size/Makefile | 21 +++++++
tools/testing/selftests/size/get_size.c | 105 ++++++++++++++++++++++++++++++++
4 files changed, 128 insertions(+)
create mode 100644 tools/testing/selftests/size/.gitignore
create mode 100644 tools/testing/selftests/size/Makefile
create mode 100644 tools/testing/selftests/size/get_size.c
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 45f145c..fa91aef 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -15,6 +15,7 @@ TARGETS += user
TARGETS += sysctl
TARGETS += firmware
TARGETS += ftrace
+TARGETS += size
TARGETS_HOTPLUG = cpu-hotplug
TARGETS_HOTPLUG += memory-hotplug
diff --git a/tools/testing/selftests/size/.gitignore b/tools/testing/selftests/size/.gitignore
new file mode 100644
index 0000000..189b781
--- /dev/null
+++ b/tools/testing/selftests/size/.gitignore
@@ -0,0 +1 @@
+get_size
diff --git a/tools/testing/selftests/size/Makefile b/tools/testing/selftests/size/Makefile
new file mode 100644
index 0000000..51e5fbd
--- /dev/null
+++ b/tools/testing/selftests/size/Makefile
@@ -0,0 +1,21 @@
+#ifndef CC
+ CC = $(CROSS_COMPILE)gcc
+#endif
+
+#ifndef STRIP
+ STRIP = $(CROSS_COMPILE)strip
+#endif
+
+all: get_size
+
+get_size: get_size.c
+ $(CC) --static -ffreestanding -nostartfiles \
+ -Wl,--entry=main get_size.c -o get_size \
+ `cc -print-libgcc-file-name`
+ $(STRIP) -s get_size
+
+run_tests: all
+ ./get_size
+
+clean:
+ $(RM) get_size
diff --git a/tools/testing/selftests/size/get_size.c b/tools/testing/selftests/size/get_size.c
new file mode 100644
index 0000000..9c8d3cd
--- /dev/null
+++ b/tools/testing/selftests/size/get_size.c
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2014 Sony
+ *
+ * Licensed under the terms of the GNU GPL License version 2
+ *
+ * Selftest for runtime system size
+ *
+ * Prints the amount of RAM that the currently running system is using.
+ *
+ * This program tries to be as small as possible itself, to
+ * avoid perturbing the system memory utilization with its
+ * own execution. It also attempts to have as few dependencies
+ * on kernel features as possible.
+ *
+ * It should be statically linked, with startup libs avoided.
+ * It uses no library calls, and only the following 3 syscalls:
+ * sysinfo(), write(), and _exit()
+ *
+ * For output, it avoids printf (which in some C libraries
+ * has large external dependencies) by implementing its own
+ * strlen(), number output and print() routines.
+ */
+
+#include <sys/sysinfo.h>
+#include <unistd.h>
+
+#define STDOUT_FILENO 1
+
+int my_strlen(const char *s)
+{
+ int len = 0;
+
+ while (*s++)
+ len++;
+ return len;
+}
+
+/*
+ * num_to_str - put digits from num into *s, left to right
+ * do this by dividing the number by powers of 10
+ * the tricky part is to omit leading zeros
+ * don't print zeros until we've started printing any numbers at all
+ */
+void num_to_str(unsigned long num, char *s)
+{
+ unsigned long long temp, div;
+ int started;
+
+ temp = num;
+ div = 1000000000000000000LL;
+ started = 0;
+ while (div) {
+ if (temp/div || started) {
+ *s++ = (unsigned char)(temp/div + '0');
+ started = 1;
+ }
+ temp -= (temp/div)*div;
+ div /= 10;
+ }
+ *s = 0;
+}
+
+int print_num(unsigned long num)
+{
+ char num_buf[30];
+
+ num_to_str(num, num_buf);
+ return write(STDOUT_FILENO, num_buf, my_strlen(num_buf));
+}
+
+int print(char *s)
+{
+ return write(STDOUT_FILENO, s, my_strlen(s));
+}
+
+void main(int argc, char **argv)
+{
+ int ccode;
+ unsigned long used;
+ struct sysinfo info;
+ unsigned long long temp;
+
+ print("Testing system size.\n");
+ print("1..1\n");
+
+ ccode = sysinfo(&info);
+ if (ccode < 0) {
+ print("not ok 1 get size runtime size\n");
+ print("# could not get sysinfo\n");
+ _exit(ccode);
+ }
+
+ /* ignore cache complexities for now */
+ temp = info.totalram - info.freeram - info.bufferram;
+ temp = temp * info.mem_unit;
+ temp = temp / 1024;
+
+ used = temp;
+
+ print("ok 1 get runtime size # size = ");
+ print_num(used);
+ print(" K\n");
+
+ _exit(0);
+}
--
1.8.2.2
^ permalink raw reply related
* Re: [PATCH v3] selftest: size: Add size test for Linux kernel
From: Shuah Khan @ 2014-11-25 20:39 UTC (permalink / raw)
To: Tim Bird, linux-api-u79uwXL29TY76Z2rM5mHXA
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-embedded-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Shuah Khan
In-Reply-To: <547376D3.7070709-/MT0OVThwyLZJqsBc5GL+g@public.gmane.org>
On 11/24/2014 11:20 AM, Tim Bird wrote:
>
> This test shows the amount of memory used by the system.
> Note that this is dependent on the user-space that is loaded
> when this program runs. Optimally, this program would be
> run as the init program itself.
>
> The program is optimized for size itself, to avoid conflating
> its own execution with that of the system software.
> The code is compiled statically, with no stdlibs. On my x86_64 system,
> this results in a statically linked binary of less than 5K.
>
This following version information shouldn't be part of changelog.
> Changes from v2:
> - add return values to print routines
> - add .gitignore file
>
> Changes from v1:
> - use more correct Copyright string in get_size.c
>
> Signed-off-by: Tim Bird <tim.bird-/MT0OVThwyLZJqsBc5GL+g@public.gmane.org>
> ---
Goes here.
> tools/testing/selftests/Makefile | 1 +
> tools/testing/selftests/size/.gitignore | 1 +
> tools/testing/selftests/size/Makefile | 21 +++++++
> tools/testing/selftests/size/get_size.c | 105 ++++++++++++++++++++++++++++++++
> 4 files changed, 128 insertions(+)
> create mode 100644 tools/testing/selftests/size/.gitignore
> create mode 100644 tools/testing/selftests/size/Makefile
> create mode 100644 tools/testing/selftests/size/get_size.c
>
> diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
> index 45f145c..fa91aef 100644
> --- a/tools/testing/selftests/Makefile
> +++ b/tools/testing/selftests/Makefile
> @@ -15,6 +15,7 @@ TARGETS += user
> TARGETS += sysctl
> TARGETS += firmware
> TARGETS += ftrace
> +TARGETS += size
>
> TARGETS_HOTPLUG = cpu-hotplug
> TARGETS_HOTPLUG += memory-hotplug
> diff --git a/tools/testing/selftests/size/.gitignore b/tools/testing/selftests/size/.gitignore
> new file mode 100644
> index 0000000..189b781
> --- /dev/null
> +++ b/tools/testing/selftests/size/.gitignore
> @@ -0,0 +1 @@
> +get_size
> diff --git a/tools/testing/selftests/size/Makefile b/tools/testing/selftests/size/Makefile
> new file mode 100644
> index 0000000..51e5fbd
> --- /dev/null
> +++ b/tools/testing/selftests/size/Makefile
> @@ -0,0 +1,21 @@
> +#ifndef CC
> + CC = $(CROSS_COMPILE)gcc
> +#endif
> +
> +#ifndef STRIP
> + STRIP = $(CROSS_COMPILE)strip
> +#endif
> +
> +all: get_size
> +
> +get_size: get_size.c
> + $(CC) --static -ffreestanding -nostartfiles \
> + -Wl,--entry=main get_size.c -o get_size \
> + `cc -print-libgcc-file-name`
> + $(STRIP) -s get_size
> +
> +run_tests: all
> + ./get_size
> +
> +clean:
> + $(RM) get_size
> diff --git a/tools/testing/selftests/size/get_size.c b/tools/testing/selftests/size/get_size.c
> new file mode 100644
> index 0000000..9c8d3cd
> --- /dev/null
> +++ b/tools/testing/selftests/size/get_size.c
> @@ -0,0 +1,105 @@
> +/*
> + * Copyright 2014 Sony
> + *
> + * Licensed under the terms of the GNU GPL License version 2
> + *
> + * Selftest for runtime system size
> + *
> + * Prints the amount of RAM that the currently running system is using.
> + *
> + * This program tries to be as small as possible itself, to
> + * avoid perturbing the system memory utilization with its
> + * own execution. It also attempts to have as few dependencies
> + * on kernel features as possible.
> + *
> + * It should be statically linked, with startup libs avoided.
> + * It uses no library calls, and only the following 3 syscalls:
> + * sysinfo(), write(), and _exit()
> + *
> + * For output, it avoids printf (which in some C libraries
> + * has large external dependencies) by implementing its own
> + * strlen(), number output and print() routines.
> + */
> +
> +#include <sys/sysinfo.h>
> +#include <unistd.h>
> +
> +#define STDOUT_FILENO 1
> +
> +int my_strlen(const char *s)
> +{
> + int len = 0;
> +
> + while (*s++)
> + len++;
> + return len;
> +}
> +
> +/*
> + * num_to_str - put digits from num into *s, left to right
> + * do this by dividing the number by powers of 10
> + * the tricky part is to omit leading zeros
> + * don't print zeros until we've started printing any numbers at all
> + */
> +void num_to_str(unsigned long num, char *s)
> +{
> + unsigned long long temp, div;
> + int started;
> +
> + temp = num;
> + div = 1000000000000000000LL;
> + started = 0;
> + while (div) {
> + if (temp/div || started) {
> + *s++ = (unsigned char)(temp/div + '0');
> + started = 1;
> + }
> + temp -= (temp/div)*div;
> + div /= 10;
> + }
> + *s = 0;
> +}
> +
> +int print_num(unsigned long num)
> +{
> + char num_buf[30];
> +
> + num_to_str(num, num_buf);
> + return write(STDOUT_FILENO, num_buf, my_strlen(num_buf));
> +}
> +
> +int print(char *s)
> +{
> + return write(STDOUT_FILENO, s, my_strlen(s));
> +}
> +
> +void main(int argc, char **argv)
> +{
> + int ccode;
> + unsigned long used;
> + struct sysinfo info;
> + unsigned long long temp;
> +
> + print("Testing system size.\n");
> + print("1..1\n");
I ran this test and the reporting could be improved.
Could you change the above to say
System RAM in use instead of system size. Also can you also
print total RAM and other information you already have:
Maybe something along the lines of:
System RAM report (units Kilobytes):
Total:
Free:
Bufferram:
In use:
I would remove the print("1..1\n");
> +
> + ccode = sysinfo(&info);
> + if (ccode < 0) {
> + print("not ok 1 get size runtime size\n");
> + print("# could not get sysinfo\n");
> + _exit(ccode);
> + }
> +
> + /* ignore cache complexities for now */
> + temp = info.totalram - info.freeram - info.bufferram;
> + temp = temp * info.mem_unit;
> + temp = temp / 1024;
> +
> + used = temp;
> +
> + print("ok 1 get runtime size # size = ");
> + print_num(used);
> + print(" K\n");
Please see above. You can get rid of print(" K\n"); at the end.
Sorry for not giving this feedback earlier. The not so clear
reporting aspect stood out for me after running the test.
thanks,
-- Shuah
--
Shuah Khan
Sr. Linux Kernel Developer
Samsung Research America (Silicon Valley)
shuahkh-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org | (970) 217-8978
^ permalink raw reply
* Re: [PATCH v3] selftest: size: Add size test for Linux kernel
From: Tim Bird @ 2014-11-25 23:33 UTC (permalink / raw)
To: Shuah Khan, linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-embedded-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Josh Triplett
In-Reply-To: <5474E8F6.8010307-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org>
On 11/25/2014 12:39 PM, Shuah Khan wrote:
> On 11/24/2014 11:20 AM, Tim Bird wrote:
>>
>> This test shows the amount of memory used by the system.
>> Note that this is dependent on the user-space that is loaded
>> when this program runs. Optimally, this program would be
>> run as the init program itself.
>>
>> The program is optimized for size itself, to avoid conflating
>> its own execution with that of the system software.
>> The code is compiled statically, with no stdlibs. On my x86_64 system,
>> this results in a statically linked binary of less than 5K.
>>
>
> This following version information shouldn't be part of changelog.
>
>> Changes from v2:
>> - add return values to print routines
>> - add .gitignore file
>>
>> Changes from v1:
>> - use more correct Copyright string in get_size.c
>>
>> Signed-off-by: Tim Bird <tim.bird-/MT0OVThwyLZJqsBc5GL+g@public.gmane.org>
>> ---
>
> Goes here.
OK - I'll change this.
>
>> tools/testing/selftests/Makefile | 1 +
>> tools/testing/selftests/size/.gitignore | 1 +
>> tools/testing/selftests/size/Makefile | 21 +++++++
>> tools/testing/selftests/size/get_size.c | 105 ++++++++++++++++++++++++++++++++
>> 4 files changed, 128 insertions(+)
>> create mode 100644 tools/testing/selftests/size/.gitignore
>> create mode 100644 tools/testing/selftests/size/Makefile
>> create mode 100644 tools/testing/selftests/size/get_size.c
>>
>> diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
>> index 45f145c..fa91aef 100644
>> --- a/tools/testing/selftests/Makefile
>> +++ b/tools/testing/selftests/Makefile
>> @@ -15,6 +15,7 @@ TARGETS += user
>> TARGETS += sysctl
>> TARGETS += firmware
>> TARGETS += ftrace
>> +TARGETS += size
>>
>> TARGETS_HOTPLUG = cpu-hotplug
>> TARGETS_HOTPLUG += memory-hotplug
>> diff --git a/tools/testing/selftests/size/.gitignore b/tools/testing/selftests/size/.gitignore
>> new file mode 100644
>> index 0000000..189b781
>> --- /dev/null
>> +++ b/tools/testing/selftests/size/.gitignore
>> @@ -0,0 +1 @@
>> +get_size
>> diff --git a/tools/testing/selftests/size/Makefile b/tools/testing/selftests/size/Makefile
>> new file mode 100644
>> index 0000000..51e5fbd
>> --- /dev/null
>> +++ b/tools/testing/selftests/size/Makefile
>> @@ -0,0 +1,21 @@
>> +#ifndef CC
>> + CC = $(CROSS_COMPILE)gcc
>> +#endif
>> +
>> +#ifndef STRIP
>> + STRIP = $(CROSS_COMPILE)strip
>> +#endif
>> +
>> +all: get_size
>> +
>> +get_size: get_size.c
>> + $(CC) --static -ffreestanding -nostartfiles \
>> + -Wl,--entry=main get_size.c -o get_size \
>> + `cc -print-libgcc-file-name`
>> + $(STRIP) -s get_size
>> +
>> +run_tests: all
>> + ./get_size
>> +
>> +clean:
>> + $(RM) get_size
>> diff --git a/tools/testing/selftests/size/get_size.c b/tools/testing/selftests/size/get_size.c
>> new file mode 100644
>> index 0000000..9c8d3cd
>> --- /dev/null
>> +++ b/tools/testing/selftests/size/get_size.c
>> @@ -0,0 +1,105 @@
>> +/*
>> + * Copyright 2014 Sony
>> + *
>> + * Licensed under the terms of the GNU GPL License version 2
>> + *
>> + * Selftest for runtime system size
>> + *
>> + * Prints the amount of RAM that the currently running system is using.
>> + *
>> + * This program tries to be as small as possible itself, to
>> + * avoid perturbing the system memory utilization with its
>> + * own execution. It also attempts to have as few dependencies
>> + * on kernel features as possible.
>> + *
>> + * It should be statically linked, with startup libs avoided.
>> + * It uses no library calls, and only the following 3 syscalls:
>> + * sysinfo(), write(), and _exit()
>> + *
>> + * For output, it avoids printf (which in some C libraries
>> + * has large external dependencies) by implementing its own
>> + * strlen(), number output and print() routines.
>> + */
>> +
>> +#include <sys/sysinfo.h>
>> +#include <unistd.h>
>> +
>> +#define STDOUT_FILENO 1
>> +
>> +int my_strlen(const char *s)
>> +{
>> + int len = 0;
>> +
>> + while (*s++)
>> + len++;
>> + return len;
>> +}
>> +
>> +/*
>> + * num_to_str - put digits from num into *s, left to right
>> + * do this by dividing the number by powers of 10
>> + * the tricky part is to omit leading zeros
>> + * don't print zeros until we've started printing any numbers at all
>> + */
>> +void num_to_str(unsigned long num, char *s)
>> +{
>> + unsigned long long temp, div;
>> + int started;
>> +
>> + temp = num;
>> + div = 1000000000000000000LL;
>> + started = 0;
>> + while (div) {
>> + if (temp/div || started) {
>> + *s++ = (unsigned char)(temp/div + '0');
>> + started = 1;
>> + }
>> + temp -= (temp/div)*div;
>> + div /= 10;
>> + }
>> + *s = 0;
>> +}
>> +
>> +int print_num(unsigned long num)
>> +{
>> + char num_buf[30];
>> +
>> + num_to_str(num, num_buf);
>> + return write(STDOUT_FILENO, num_buf, my_strlen(num_buf));
>> +}
>> +
>> +int print(char *s)
>> +{
>> + return write(STDOUT_FILENO, s, my_strlen(s));
>> +}
>> +
>> +void main(int argc, char **argv)
>> +{
>> + int ccode;
>> + unsigned long used;
>> + struct sysinfo info;
>> + unsigned long long temp;
>> +
>> + print("Testing system size.\n");
>> + print("1..1\n");
>
> I ran this test and the reporting could be improved.
> Could you change the above to say
>
> System RAM in use instead of system size.
I'll have to think about this. I'm not sure what the
correct phrasing would be for XIP systems (for which part of
the kernel resides in flash, not RAM, maybe "memory"?)
> Also can you also
> print total RAM and other information you already have:
>
I can print it as part of total output, but for regression
testing and automation I want the tool to have a single
number result as output (well, one number relating to runtime
size, and I'm considering adding one number relating
to compile-time size.)
> Maybe something along the lines of:
>
> System RAM report (units Kilobytes):
> Total:
> Free:
> Bufferram:
> In use:
>
> I would remove the print("1..1\n");
This is part of the TAP output format.
Is there any (other) output format being standardized for selftest
programs?
TAP allows me to output more human-readable information to go
along with the "official" result, but I'd like to keep the
official result in TAP format so it can be handled by automated
tools. Maybe it would be best to output both.
I'll try to make a counter-proposal tomorrow that we can discus.
>> +
>> + ccode = sysinfo(&info);
>> + if (ccode < 0) {
>> + print("not ok 1 get size runtime size\n");
>> + print("# could not get sysinfo\n");
>> + _exit(ccode);
>> + }
>> +
>> + /* ignore cache complexities for now */
>> + temp = info.totalram - info.freeram - info.bufferram;
>> + temp = temp * info.mem_unit;
>> + temp = temp / 1024;
>> +
>> + used = temp;
>> +
>> + print("ok 1 get runtime size # size = ");
>> + print_num(used);
>> + print(" K\n");
>
> Please see above. You can get rid of print(" K\n"); at the end.
>
> Sorry for not giving this feedback earlier. The not so clear
> reporting aspect stood out for me after running the test.
No problem. Thanks for looking at it.
I have some additional changes, based on feedback from Josh Triplett,
so look for a v4 tomorrow.
-- Tim
^ permalink raw reply
* [PATCH v4] selftest: size: Add size test for Linux kernel
From: Tim Bird @ 2014-11-27 4:27 UTC (permalink / raw)
To: Shuah Khan
Cc: linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-embedded-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Josh Triplett
This test shows the amount of memory used by the system.
Note that this is dependent on the user-space that is loaded
when this program runs. Optimally, this program would be
run as the init program itself.
The program is optimized for size itself, to avoid conflating
its own execution with that of the system software.
The code is compiled statically, with no stdlibs. On my x86_64 system,
this results in a statically linked binary of less than 5K.
Signed-off-by: Tim Bird <tim.bird-/MT0OVThwyLZJqsBc5GL+g@public.gmane.org>
---
Changes from v3:
- fix copyright string (again!)
- use __builtin_strlen instead of my own strlen
- replace main with _start
- add more human-readable output
- put libgcc reference into a variable in Makefile
Changes from v2:
- add return values to print routines
- add .gitignore file
Changes from v1:
- use more correct Copyright string in get_size.c
tools/testing/selftests/Makefile | 1 +
tools/testing/selftests/size/.gitignore | 1 +
tools/testing/selftests/size/Makefile | 23 +++++++
tools/testing/selftests/size/get_size.c | 111 ++++++++++++++++++++++++++++++++
4 files changed, 136 insertions(+)
create mode 100644 tools/testing/selftests/size/.gitignore
create mode 100644 tools/testing/selftests/size/Makefile
create mode 100644 tools/testing/selftests/size/get_size.c
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 45f145c..fa91aef 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -15,6 +15,7 @@ TARGETS += user
TARGETS += sysctl
TARGETS += firmware
TARGETS += ftrace
+TARGETS += size
TARGETS_HOTPLUG = cpu-hotplug
TARGETS_HOTPLUG += memory-hotplug
diff --git a/tools/testing/selftests/size/.gitignore b/tools/testing/selftests/size/.gitignore
new file mode 100644
index 0000000..189b781
--- /dev/null
+++ b/tools/testing/selftests/size/.gitignore
@@ -0,0 +1 @@
+get_size
diff --git a/tools/testing/selftests/size/Makefile b/tools/testing/selftests/size/Makefile
new file mode 100644
index 0000000..1862786
--- /dev/null
+++ b/tools/testing/selftests/size/Makefile
@@ -0,0 +1,23 @@
+#ifndef CC
+ CC = $(CROSS_COMPILE)gcc
+#endif
+
+#ifndef STRIP
+ STRIP = $(CROSS_COMPILE)strip
+#endif
+
+all: get_size
+
+LIBGCC=$(shell $(CC) -print-libgcc-file-name)
+
+get_size: get_size.c
+ $(CC) --static -ffreestanding -nostartfiles \
+ -Wl,--entry=_start get_size.c $(LIBGCC) \
+ -o get_size
+ $(STRIP) -s get_size
+
+run_tests: all
+ ./get_size
+
+clean:
+ $(RM) get_size
diff --git a/tools/testing/selftests/size/get_size.c b/tools/testing/selftests/size/get_size.c
new file mode 100644
index 0000000..7e9bbb4
--- /dev/null
+++ b/tools/testing/selftests/size/get_size.c
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2014 Sony Mobile Communications Inc.
+ *
+ * Licensed under the terms of the GNU GPL License version 2
+ *
+ * Selftest for runtime system size
+ *
+ * Prints the amount of RAM that the currently running system is using.
+ *
+ * This program tries to be as small as possible itself, to
+ * avoid perturbing the system memory utilization with its
+ * own execution. It also attempts to have as few dependencies
+ * on kernel features as possible.
+ *
+ * It should be statically linked, with startup libs avoided.
+ * It uses no library calls, and only the following 3 syscalls:
+ * sysinfo(), write(), and _exit()
+ *
+ * For output, it avoids printf (which in some C libraries
+ * has large external dependencies) by implementing it's own
+ * number output and print routines, and using __builtin_strlen()
+ */
+
+#include <sys/sysinfo.h>
+#include <unistd.h>
+
+#define STDOUT_FILENO 1
+
+int print(const char *s)
+{
+ return write(STDOUT_FILENO, s, __builtin_strlen(s));
+}
+
+
+/*
+ * num_to_str - put digits from num into *s, left to right
+ * do this by dividing the number by powers of 10
+ * the tricky part is to omit leading zeros
+ * don't print zeros until we've started printing any numbers at all
+ */
+void num_to_str(unsigned long num, char *s)
+{
+ unsigned long long temp, div;
+ int started;
+
+ temp = num;
+ div = 1000000000000000000LL;
+ started = 0;
+ while (div) {
+ if (temp/div || started) {
+ *s++ = (unsigned char)(temp/div + '0');
+ started = 1;
+ }
+ temp -= (temp/div)*div;
+ div /= 10;
+ }
+ *s = 0;
+}
+
+int print_num(unsigned long num)
+{
+ char num_buf[30];
+
+ num_to_str(num, num_buf);
+ return print(num_buf);
+}
+
+int print_k_value(const char *s, unsigned long num, unsigned long units)
+{
+ unsigned long long temp;
+ int ccode;
+
+ print(s);
+
+ temp = num;
+ temp = (temp * units)/1024;
+ num = temp;
+ ccode = print_num(num);
+ print("\n");
+ return ccode;
+}
+
+/* this program has no main(), as startup libraries are not used */
+void _start(void)
+{
+ int ccode;
+ struct sysinfo info;
+ unsigned long used;
+
+ print("Testing system size.\n");
+ print("1..1\n");
+
+ ccode = sysinfo(&info);
+ if (ccode < 0) {
+ print("not ok 1 get size runtime size\n");
+ print("# could not get sysinfo\n");
+ _exit(ccode);
+ }
+ /* ignore cache complexities for now */
+ used = info.totalram - info.freeram - info.bufferram;
+ print_k_value("ok 1 get runtime memory use # size = ", used,
+ info.mem_unit);
+
+ print("# System runtime memory report (units in Kilobytes):\n");
+ print_k_value("# Total: ", info.totalram, info.mem_unit);
+ print_k_value("# Free: ", info.freeram, info.mem_unit);
+ print_k_value("# Buffer: ", info.bufferram, info.mem_unit);
+ print_k_value("# In use: ", used, info.mem_unit);
+
+ _exit(0);
+}
--
1.8.2.2
^ permalink raw reply related
* Re: [PATCH v4] selftest: size: Add size test for Linux kernel
From: Josh Triplett @ 2014-11-27 6:04 UTC (permalink / raw)
To: Tim Bird
Cc: Shuah Khan, linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-embedded-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
In-Reply-To: <5476A82B.2060903-/MT0OVThwyLZJqsBc5GL+g@public.gmane.org>
On Wed, Nov 26, 2014 at 08:27:23PM -0800, Tim Bird wrote:
> --- /dev/null
> +++ b/tools/testing/selftests/size/Makefile
[...]
> +LIBGCC=$(shell $(CC) -print-libgcc-file-name)
> +
> +get_size: get_size.c
> + $(CC) --static -ffreestanding -nostartfiles \
> + -Wl,--entry=_start get_size.c $(LIBGCC) \
> + -o get_size
You don't need -Wl,--entry=_start; that's the default.
You shouldn't need to manually find libgcc, either; the compiler should
do that for you. What goes wrong if you don't include that? If you're
trying to link libgcc statically, try -static-libgcc.
Also, static is normally spelled -static, not --static.
> --- /dev/null
> +++ b/tools/testing/selftests/size/get_size.c
[...]
> +int print(const char *s)
This function, and all the others apart from _start, should be declared
static.
> +void num_to_str(unsigned long num, char *s)
Likewise, static.
> +{
> + unsigned long long temp, div;
> + int started;
> +
> + temp = num;
> + div = 1000000000000000000LL;
> + started = 0;
> + while (div) {
> + if (temp/div || started) {
> + *s++ = (unsigned char)(temp/div + '0');
> + started = 1;
> + }
> + temp -= (temp/div)*div;
> + div /= 10;
> + }
> + *s = 0;
> +}
You'd probably end up with significantly smaller code (and no divisions,
and thus no corner cases on architectures that need a special function
to do unsigned long long division) if you print in hex. You could also
drop the "no leading zeros" logic, and just *always* print a 64-bit
value as 16 hex digits.
> +int print_num(unsigned long num)
Likewise, static.
> +{
> + char num_buf[30];
> +
> + num_to_str(num, num_buf);
> + return print(num_buf);
> +}
> +
> +int print_k_value(const char *s, unsigned long num, unsigned long units)
> +{
> + unsigned long long temp;
> + int ccode;
> +
> + print(s);
> +
> + temp = num;
> + temp = (temp * units)/1024;
> + num = temp;
> + ccode = print_num(num);
> + print("\n");
> + return ccode;
> +}
I'd suggest dropping this entirely, and just always printing the exact
values returned by sysinfo. Drop the multiply, too, and just print
info.mem_unit as well. It's easy to post-process the value in a more
capable environment.
> +/* this program has no main(), as startup libraries are not used */
> +void _start(void)
> +{
> + int ccode;
> + struct sysinfo info;
> + unsigned long used;
> +
> + print("Testing system size.\n");
> + print("1..1\n");
> +
> + ccode = sysinfo(&info);
> + if (ccode < 0) {
> + print("not ok 1 get size runtime size\n");
Shouldn't the "not ok" here and the "ok" below have the same test
description?
> + print("# could not get sysinfo\n");
> + _exit(ccode);
> + }
> + /* ignore cache complexities for now */
> + used = info.totalram - info.freeram - info.bufferram;
> + print_k_value("ok 1 get runtime memory use # size = ", used,
> + info.mem_unit);
> +
> + print("# System runtime memory report (units in Kilobytes):\n");
> + print_k_value("# Total: ", info.totalram, info.mem_unit);
> + print_k_value("# Free: ", info.freeram, info.mem_unit);
> + print_k_value("# Buffer: ", info.bufferram, info.mem_unit);
> + print_k_value("# In use: ", used, info.mem_unit);
> +
> + _exit(0);
> +}
> --
> 1.8.2.2
>
^ permalink raw reply
* Re: [PATCH v4] selftest: size: Add size test for Linux kernel
From: Tim Bird @ 2014-12-03 3:31 UTC (permalink / raw)
To: Josh Triplett
Cc: Shuah Khan, linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-embedded-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
In-Reply-To: <20141127060409.GB2773@thin>
On 11/26/2014 10:04 PM, Josh Triplett wrote:
> On Wed, Nov 26, 2014 at 08:27:23PM -0800, Tim Bird wrote:
>> --- /dev/null
>> +++ b/tools/testing/selftests/size/Makefile
> [...]
>> +LIBGCC=$(shell $(CC) -print-libgcc-file-name)
>> +
>> +get_size: get_size.c
>> + $(CC) --static -ffreestanding -nostartfiles \
>> + -Wl,--entry=_start get_size.c $(LIBGCC) \
>> + -o get_size
>
> You don't need -Wl,--entry=_start; that's the default.
OK - it works without this. Thanks.
> You shouldn't need to manually find libgcc, either; the compiler should
> do that for you. What goes wrong if you don't include that? If you're
> trying to link libgcc statically, try -static-libgcc.
>
> Also, static is normally spelled -static, not --static.
Hmm. Not sure where I got --static from, but it worked.
But if -static is the norm I'm fine changing to that.
Upon experimentation, I don't need the explicit libgcc or for that
matter the -static-libgcc either.
>> --- /dev/null
>> +++ b/tools/testing/selftests/size/get_size.c
> [...]
>> +int print(const char *s)
>
> This function, and all the others apart from _start, should be declared
> static.
OK will do.
>> +void num_to_str(unsigned long num, char *s)
>
> Likewise, static.
OK
>> +{
>> + unsigned long long temp, div;
>> + int started;
>> +
>> + temp = num;
>> + div = 1000000000000000000LL;
>> + started = 0;
>> + while (div) {
>> + if (temp/div || started) {
>> + *s++ = (unsigned char)(temp/div + '0');
>> + started = 1;
>> + }
>> + temp -= (temp/div)*div;
>> + div /= 10;
>> + }
>> + *s = 0;
>> +}
>
> You'd probably end up with significantly smaller code (and no divisions,
> and thus no corner cases on architectures that need a special function
> to do unsigned long long division) if you print in hex. You could also
> drop the "no leading zeros" logic, and just *always* print a 64-bit
> value as 16 hex digits.
I'd like to keep base-10 output. As far as size is concerned, the
code is now at well under 2 pages (8k), which is much smaller than
any actually useful program. The only noticeable change in size would
be if I got it under 4096, but I don't want to sacrifice too many
features to get there (as that's still only 1 page difference in
memory usage.)
BTW - using sstrip, I can get it to 4096 already, as is.
Unfortunately, 'sstrip -z', which gets it to 2061, makes
it not work. I need to check out what the problem is there.
Also, the ELF file still has an unneeded note section. I think
easier reductions, without sacrificing functionality, are available
by tweaking the ELF header (ie fixing sstrip, for those that
want to use it).
>> +int print_num(unsigned long num)
>
> Likewise, static.
OK
>> +{
>> + char num_buf[30];
>> +
>> + num_to_str(num, num_buf);
>> + return print(num_buf);
>> +}
>> +
>> +int print_k_value(const char *s, unsigned long num, unsigned long units)
>> +{
>> + unsigned long long temp;
>> + int ccode;
>> +
>> + print(s);
>> +
>> + temp = num;
>> + temp = (temp * units)/1024;
>> + num = temp;
>> + ccode = print_num(num);
>> + print("\n");
>> + return ccode;
>> +}
>
> I'd suggest dropping this entirely, and just always printing the exact
> values returned by sysinfo. Drop the multiply, too, and just print
> info.mem_unit as well. It's easy to post-process the value in a more
> capable environment.
I'd prefer to keep the output easily human-readable.
>> +/* this program has no main(), as startup libraries are not used */
>> +void _start(void)
>> +{
>> + int ccode;
>> + struct sysinfo info;
>> + unsigned long used;
>> +
>> + print("Testing system size.\n");
>> + print("1..1\n");
>> +
>> + ccode = sysinfo(&info);
>> + if (ccode < 0) {
>> + print("not ok 1 get size runtime size\n");
>
> Shouldn't the "not ok" here and the "ok" below have the same test
> description?
Yes. Thanks. Good catch.
>> + print("# could not get sysinfo\n");
>> + _exit(ccode);
>> + }
>> + /* ignore cache complexities for now */
>> + used = info.totalram - info.freeram - info.bufferram;
>> + print_k_value("ok 1 get runtime memory use # size = ", used,
>> + info.mem_unit);
>> +
>> + print("# System runtime memory report (units in Kilobytes):\n");
>> + print_k_value("# Total: ", info.totalram, info.mem_unit);
>> + print_k_value("# Free: ", info.freeram, info.mem_unit);
>> + print_k_value("# Buffer: ", info.bufferram, info.mem_unit);
>> + print_k_value("# In use: ", used, info.mem_unit);
>> +
>> + _exit(0);
>> +}
>> --
>> 1.8.2.2
OK - look for a new version shortly (maybe not today, though).
-- Tim
^ permalink raw reply
* [PATCH v5] selftest: size: Add size test for Linux kernel
From: Tim Bird @ 2014-12-03 3:36 UTC (permalink / raw)
To: Shuah Khan, linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: Josh Triplett,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-embedded-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
This test shows the amount of memory used by the system.
Note that this is dependent on the user-space that is loaded
when this program runs. Optimally, this program would be
run as the init program itself.
The program is optimized for size itself, to avoid conflating
its own execution with that of the system software.
The code is compiled statically, with no stdlibs. On my x86_64 system,
this results in a statically linked binary of less than 5K.
Signed-off-by: Tim Bird <tim.bird-/MT0OVThwyLZJqsBc5GL+g@public.gmane.org>
---
Changes from v5:
- make most routines static
- replace strip with gcc -s
- remove explicit reference to _start
- change --static to -static
- remove explicit reference to LIBGCC
- fix test description for ok and not ok paths, for test 1
Changes from v4:
- add more human-readable output
- put libgcc reference into a variable in Makefile
Changes from v3:
- fix copyright string (again!)
- use __builtin_strlen instead of my own strlen
- replace main with _start
Changes from v2:
- add return values to print routines
- add .gitignore file
Changes from v1:
- use more correct Copyright string in get_size.c
tools/testing/selftests/Makefile | 1 +
tools/testing/selftests/size/.gitignore | 1 +
tools/testing/selftests/size/Makefile | 15 +++++
tools/testing/selftests/size/get_size.c | 111 ++++++++++++++++++++++++++++++++
4 files changed, 128 insertions(+)
create mode 100644 tools/testing/selftests/size/.gitignore
create mode 100644 tools/testing/selftests/size/Makefile
create mode 100644 tools/testing/selftests/size/get_size.c
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 45f145c..fa91aef 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -15,6 +15,7 @@ TARGETS += user
TARGETS += sysctl
TARGETS += firmware
TARGETS += ftrace
+TARGETS += size
TARGETS_HOTPLUG = cpu-hotplug
TARGETS_HOTPLUG += memory-hotplug
diff --git a/tools/testing/selftests/size/.gitignore b/tools/testing/selftests/size/.gitignore
new file mode 100644
index 0000000..189b781
--- /dev/null
+++ b/tools/testing/selftests/size/.gitignore
@@ -0,0 +1 @@
+get_size
diff --git a/tools/testing/selftests/size/Makefile b/tools/testing/selftests/size/Makefile
new file mode 100644
index 0000000..47f8e9c
--- /dev/null
+++ b/tools/testing/selftests/size/Makefile
@@ -0,0 +1,15 @@
+#ifndef CC
+ CC = $(CROSS_COMPILE)gcc
+#endif
+
+all: get_size
+
+get_size: get_size.c
+ $(CC) -static -ffreestanding -nostartfiles \
+ -s get_size.c -o get_size
+
+run_tests: all
+ ./get_size
+
+clean:
+ $(RM) get_size
diff --git a/tools/testing/selftests/size/get_size.c b/tools/testing/selftests/size/get_size.c
new file mode 100644
index 0000000..808e7c6
--- /dev/null
+++ b/tools/testing/selftests/size/get_size.c
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2014 Sony Mobile Communications Inc.
+ *
+ * Licensed under the terms of the GNU GPL License version 2
+ *
+ * Selftest for runtime system size
+ *
+ * Prints the amount of RAM that the currently running system is using.
+ *
+ * This program tries to be as small as possible itself, to
+ * avoid perturbing the system memory utilization with its
+ * own execution. It also attempts to have as few dependencies
+ * on kernel features as possible.
+ *
+ * It should be statically linked, with startup libs avoided.
+ * It uses no library calls, and only the following 3 syscalls:
+ * sysinfo(), write(), and _exit()
+ *
+ * For output, it avoids printf (which in some C libraries
+ * has large external dependencies) by implementing it's own
+ * number output and print routines, and using __builtin_strlen()
+ */
+
+#include <sys/sysinfo.h>
+#include <unistd.h>
+
+#define STDOUT_FILENO 1
+
+static int print(const char *s)
+{
+ return write(STDOUT_FILENO, s, __builtin_strlen(s));
+}
+
+
+/*
+ * num_to_str - put digits from num into *s, left to right
+ * do this by dividing the number by powers of 10
+ * the tricky part is to omit leading zeros
+ * don't print zeros until we've started printing any numbers at all
+ */
+static void num_to_str(unsigned long num, char *s)
+{
+ unsigned long long temp, div;
+ int started;
+
+ temp = num;
+ div = 1000000000000000000LL;
+ started = 0;
+ while (div) {
+ if (temp/div || started) {
+ *s++ = (unsigned char)(temp/div + '0');
+ started = 1;
+ }
+ temp -= (temp/div)*div;
+ div /= 10;
+ }
+ *s = 0;
+}
+
+static int print_num(unsigned long num)
+{
+ char num_buf[30];
+
+ num_to_str(num, num_buf);
+ return print(num_buf);
+}
+
+static int print_k_value(const char *s, unsigned long num, unsigned long units)
+{
+ unsigned long long temp;
+ int ccode;
+
+ print(s);
+
+ temp = num;
+ temp = (temp * units)/1024;
+ num = temp;
+ ccode = print_num(num);
+ print("\n");
+ return ccode;
+}
+
+/* this program has no main(), as startup libraries are not used */
+void _start(void)
+{
+ int ccode;
+ struct sysinfo info;
+ unsigned long used;
+
+ print("Testing system size.\n");
+ print("1..1\n");
+
+ ccode = sysinfo(&info);
+ if (ccode < 0) {
+ print("not ok 1 get runtime memory use\n");
+ print("# could not get sysinfo\n");
+ _exit(ccode);
+ }
+ /* ignore cache complexities for now */
+ used = info.totalram - info.freeram - info.bufferram;
+ print_k_value("ok 1 get runtime memory use # size = ", used,
+ info.mem_unit);
+
+ print("# System runtime memory report (units in Kilobytes):\n");
+ print_k_value("# Total: ", info.totalram, info.mem_unit);
+ print_k_value("# Free: ", info.freeram, info.mem_unit);
+ print_k_value("# Buffer: ", info.bufferram, info.mem_unit);
+ print_k_value("# In use: ", used, info.mem_unit);
+
+ _exit(0);
+}
--
1.8.2.2
^ permalink raw reply related
* Re: [PATCH v5] selftest: size: Add size test for Linux kernel
From: Michael Ellerman @ 2014-12-03 3:43 UTC (permalink / raw)
To: Tim Bird
Cc: Shuah Khan, linux-api@vger.kernel.org, Josh Triplett,
linux-kernel@vger.kernel.org, linux-embedded@vger.kernel.org
In-Reply-To: <547E854E.5060101@sonymobile.com>
On Tue, 2014-12-02 at 19:36 -0800, Tim Bird wrote:
> This test shows the amount of memory used by the system.
> Note that this is dependent on the user-space that is loaded
> when this program runs. Optimally, this program would be
> run as the init program itself.
Sorry to only chime in at v5.
> diff --git a/tools/testing/selftests/size/Makefile b/tools/testing/selftests/size/Makefile
> new file mode 100644
> index 0000000..47f8e9c
> --- /dev/null
> +++ b/tools/testing/selftests/size/Makefile
> @@ -0,0 +1,15 @@
> +#ifndef CC
> + CC = $(CROSS_COMPILE)gcc
> +#endif
I think the following is preferable:
CC := $(CROSS_COMPILE)$(CC)
It allows optionally setting a custom CC, as well as optionally CROSS_COMPILE.
The only thing it doesn't do is choose gcc explicitly, but you shouldn't really
do that anyway - unless you absolutely require gcc. Let the user choose their
compiler by choosing where cc points.
cheers
^ permalink raw reply
* Re: [PATCH v5] selftest: size: Add size test for Linux kernel
From: Thomas Petazzoni @ 2014-12-03 13:01 UTC (permalink / raw)
To: Michael Ellerman
Cc: Tim Bird, Shuah Khan,
linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Josh Triplett,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-embedded-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
In-Reply-To: <1417578191.16722.11.camel@concordia>
Michael, Tim,
On Wed, 03 Dec 2014 14:43:11 +1100, Michael Ellerman wrote:
> > diff --git a/tools/testing/selftests/size/Makefile b/tools/testing/selftests/size/Makefile
> > new file mode 100644
> > index 0000000..47f8e9c
> > --- /dev/null
> > +++ b/tools/testing/selftests/size/Makefile
> > @@ -0,0 +1,15 @@
> > +#ifndef CC
> > + CC = $(CROSS_COMPILE)gcc
> > +#endif
>
> I think the following is preferable:
>
> CC := $(CROSS_COMPILE)$(CC)
It is even more necessary that #ifndef and #endif don't exist in make.
They are just comments, and therefore, ignored. Seems like Tim does too
much C :-)
Best regards,
Thomas
--
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
^ permalink raw reply
* Re: [PATCH v5] selftest: size: Add size test for Linux kernel
From: Tim Bird @ 2014-12-03 16:13 UTC (permalink / raw)
To: Thomas Petazzoni, Michael Ellerman
Cc: Shuah Khan, linux-api@vger.kernel.org, Josh Triplett,
linux-kernel@vger.kernel.org, linux-embedded@vger.kernel.org
In-Reply-To: <20141203140136.12997331@free-electrons.com>
On 12/03/2014 05:01 AM, Thomas Petazzoni wrote:
> Michael, Tim,
>
> On Wed, 03 Dec 2014 14:43:11 +1100, Michael Ellerman wrote:
>
>>> diff --git a/tools/testing/selftests/size/Makefile b/tools/testing/selftests/size/Makefile
>>> new file mode 100644
>>> index 0000000..47f8e9c
>>> --- /dev/null
>>> +++ b/tools/testing/selftests/size/Makefile
>>> @@ -0,0 +1,15 @@
>>> +#ifndef CC
>>> + CC = $(CROSS_COMPILE)gcc
>>> +#endif
>>
>> I think the following is preferable:
>>
>> CC := $(CROSS_COMPILE)$(CC)
>
> It is even more necessary that #ifndef and #endif don't exist in make.
> They are just comments, and therefore, ignored. Seems like Tim does too
> much C :-)
OK - that's hilarious. Saying 'Oops!' would be too casual for my degree of
embarrassment. :-)
Makefiles do have similar constructs. Those should have been
ifeq ($(CC),)
...
endif
This obviously got through via a failiure in testing - which is somewhat ironic.
Look for a v6 soon. (Geez, when is the merge window coming. I thought this trivial
program would get in pretty easily, but no... that's never the way. Of course
it helps if the submitter is not an idiot.)
-- Tim
^ permalink raw reply
* Re: [PATCH v5] selftest: size: Add size test for Linux kernel
From: Tim Bird @ 2014-12-03 16:29 UTC (permalink / raw)
To: Michael Ellerman
Cc: Shuah Khan, linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Josh Triplett,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-embedded-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
In-Reply-To: <1417578191.16722.11.camel@concordia>
On 12/02/2014 07:43 PM, Michael Ellerman wrote:
> On Tue, 2014-12-02 at 19:36 -0800, Tim Bird wrote:
>> This test shows the amount of memory used by the system.
>> Note that this is dependent on the user-space that is loaded
>> when this program runs. Optimally, this program would be
>> run as the init program itself.
>
> Sorry to only chime in at v5.
>
>> diff --git a/tools/testing/selftests/size/Makefile b/tools/testing/selftests/size/Makefile
>> new file mode 100644
>> index 0000000..47f8e9c
>> --- /dev/null
>> +++ b/tools/testing/selftests/size/Makefile
>> @@ -0,0 +1,15 @@
>> +#ifndef CC
>> + CC = $(CROSS_COMPILE)gcc
>> +#endif
>
> I think the following is preferable:
>
> CC := $(CROSS_COMPILE)$(CC)
>
>
> It allows optionally setting a custom CC, as well as optionally CROSS_COMPILE.
I'm not sure I follow this.
If CC is unset, you get only the CROSS_COMPILE prefix.
If CC is set to e.g. 'gcc', then you get a nicely formatted toolchain string.
But if CC already has the prefix applied, then this will result in
having it duplicated, which surely won't work correctly.
In the long run, I would hope that a higher level Makefile or environment setting
will be setting the toolchain string appropriately (as well as handling build flags)
which is why I wanted to use an ifndef (which Thomas correctly pointed out is just
wrong).
Actually, after getting this tiny program accepted, my next task was working on a
proper fix for handling cross compilation in a more generic (not case-by-case) way.
CROSS_COMPILE prefix usage looks a bit uncoordinated in the tools directory, but most
tests seem to be favoring $(CROSS_COMPILE)gcc.
$ cd tools ; mgrep CROSS
./vm/Makefile:CC = $(CROSS_COMPILE)gcc
./usb/Makefile:CC = $(CROSS_COMPILE)gcc
./testing/selftests/net/Makefile:CC = $(CROSS_COMPILE)gcc
./testing/selftests/vm/Makefile:CC = $(CROSS_COMPILE)gcc
./testing/selftests/efivarfs/Makefile:CC = $(CROSS_COMPILE)gcc
./testing/selftests/size/Makefile: CC = $(CROSS_COMPILE)gcc
./testing/selftests/powerpc/Makefile:CC := $(CROSS_COMPILE)$(CC)
./hv/Makefile:CC = $(CROSS_COMPILE)gcc
./perf/config/feature-checks/Makefile:CC := $(CROSS_COMPILE)gcc -MD
./perf/config/feature-checks/Makefile:PKG_CONFIG := $(CROSS_COMPILE)pkg-config
./lib/api/Makefile:CC = $(CROSS_COMPILE)gcc
./lib/api/Makefile:AR = $(CROSS_COMPILE)ar
./lib/lockdep/Makefile:# Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
./lib/lockdep/Makefile:$(call allow-override,CC,$(CROSS_COMPILE)gcc)
./lib/lockdep/Makefile:$(call allow-override,AR,$(CROSS_COMPILE)ar)
./lib/lockdep/Makefile:TRACK_CFLAGS = $(subst ','\'',$(CFLAGS)):$(ARCH):$(CROSS_COMPILE)
./lib/traceevent/Makefile:# Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
./lib/traceevent/Makefile:$(call allow-override,CC,$(CROSS_COMPILE)gcc)
./lib/traceevent/Makefile:$(call allow-override,AR,$(CROSS_COMPILE)ar)
./lib/traceevent/Makefile:TRACK_CFLAGS = $(subst ','\'',$(CFLAGS)):$(ARCH):$(CROSS_COMPILE)
./cgroup/Makefile:CC = $(CROSS_COMPILE)gcc
./power/acpi/Makefile:CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
./power/acpi/Makefile:CC = $(CROSS)gcc
./power/acpi/Makefile:LD = $(CROSS)gcc
./power/acpi/Makefile:STRIP = $(CROSS)strip
./power/cpupower/Makefile:CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
./power/cpupower/Makefile:CC = $(CROSS)gcc
./power/cpupower/Makefile:LD = $(CROSS)gcc
./power/cpupower/Makefile:AR = $(CROSS)ar
./power/cpupower/Makefile:STRIP = $(CROSS)strip
./power/cpupower/Makefile:RANLIB = $(CROSS)ranlib
./power/cpupower/Makefile:export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS LIB_OBJS
./power/x86/turbostat/Makefile:CC = $(CROSS_COMPILE)gcc
I agree it's desirable not to hardcode gcc, but we seem to be doing it all over
the place already.
-- Tim
^ permalink raw reply
* Re: [PATCH v5] selftest: size: Add size test for Linux kernel
From: Geert Uytterhoeven @ 2014-12-03 18:00 UTC (permalink / raw)
To: Tim Bird
Cc: Michael Ellerman, Shuah Khan, linux-api@vger.kernel.org,
Josh Triplett, linux-kernel@vger.kernel.org,
linux-embedded@vger.kernel.org
In-Reply-To: <547F3A57.7000106@sonymobile.com>
On Wed, Dec 3, 2014 at 5:29 PM, Tim Bird <tim.bird@sonymobile.com> wrote:
>>> diff --git a/tools/testing/selftests/size/Makefile b/tools/testing/selftests/size/Makefile
>>> new file mode 100644
>>> index 0000000..47f8e9c
>>> --- /dev/null
>>> +++ b/tools/testing/selftests/size/Makefile
>>> @@ -0,0 +1,15 @@
>>> +#ifndef CC
>>> + CC = $(CROSS_COMPILE)gcc
>>> +#endif
>>
>> I think the following is preferable:
>>
>> CC := $(CROSS_COMPILE)$(CC)
>>
>>
>> It allows optionally setting a custom CC, as well as optionally CROSS_COMPILE.
>
> I'm not sure I follow this.
>
> If CC is unset, you get only the CROSS_COMPILE prefix.
> If CC is set to e.g. 'gcc', then you get a nicely formatted toolchain string.
> But if CC already has the prefix applied, then this will result in
> having it duplicated, which surely won't work correctly.
>
> In the long run, I would hope that a higher level Makefile or environment setting
> will be setting the toolchain string appropriately (as well as handling build flags)
> which is why I wanted to use an ifndef (which Thomas correctly pointed out is just
> wrong).
>
> Actually, after getting this tiny program accepted, my next task was working on a
> proper fix for handling cross compilation in a more generic (not case-by-case) way.
>
> CROSS_COMPILE prefix usage looks a bit uncoordinated in the tools directory, but most
> tests seem to be favoring $(CROSS_COMPILE)gcc.
>
> $ cd tools ; mgrep CROSS
[...]
> I agree it's desirable not to hardcode gcc, but we seem to be doing it all over
> the place already.
Seems like it's time to start integrating the tests with the regular Kbuild
system, which handles cross-compilation fine...
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply
* Re: [PATCH v5] selftest: size: Add size test for Linux kernel
From: Tim Bird @ 2014-12-03 18:25 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Michael Ellerman, Shuah Khan,
linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Josh Triplett,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-embedded-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Thomas Petazzoni
In-Reply-To: <CAMuHMdVk9QLDRYDs3q7=51=qTMNRY+MQVhkqGE25XqYOkLbCxg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
On 12/03/2014 10:00 AM, Geert Uytterhoeven wrote:
> On Wed, Dec 3, 2014 at 5:29 PM, Tim Bird <tim.bird-/MT0OVThwyLZJqsBc5GL+g@public.gmane.org> wrote:
>>>> diff --git a/tools/testing/selftests/size/Makefile b/tools/testing/selftests/size/Makefile
>>>> new file mode 100644
>>>> index 0000000..47f8e9c
>>>> --- /dev/null
>>>> +++ b/tools/testing/selftests/size/Makefile
>>>> @@ -0,0 +1,15 @@
>>>> +#ifndef CC
>>>> + CC = $(CROSS_COMPILE)gcc
>>>> +#endif
>>>
>>> I think the following is preferable:
>>>
>>> CC := $(CROSS_COMPILE)$(CC)
>>>
>>>
>>> It allows optionally setting a custom CC, as well as optionally CROSS_COMPILE.
>>
>> I'm not sure I follow this.
>>
>> If CC is unset, you get only the CROSS_COMPILE prefix.
>> If CC is set to e.g. 'gcc', then you get a nicely formatted toolchain string.
>> But if CC already has the prefix applied, then this will result in
>> having it duplicated, which surely won't work correctly.
>>
>> In the long run, I would hope that a higher level Makefile or environment setting
>> will be setting the toolchain string appropriately (as well as handling build flags)
>> which is why I wanted to use an ifndef (which Thomas correctly pointed out is just
>> wrong).
>>
>> Actually, after getting this tiny program accepted, my next task was working on a
>> proper fix for handling cross compilation in a more generic (not case-by-case) way.
>>
>> CROSS_COMPILE prefix usage looks a bit uncoordinated in the tools directory, but most
>> tests seem to be favoring $(CROSS_COMPILE)gcc.
>>
>> $ cd tools ; mgrep CROSS
>
> [...]
>
>> I agree it's desirable not to hardcode gcc, but we seem to be doing it all over
>> the place already.
>
> Seems like it's time to start integrating the tests with the regular Kbuild
> system, which handles cross-compilation fine...
Where possible, yes. It would be nice to leverage CROSS_COMPILE and CFLAGS, or
a portion thereof, from the Kbuild system (as well a KBUILD_OUTPUT and friends).
It's on my to-do list, after getting my little C program accepted...
-- Tim
^ permalink raw reply
* [PATCH v6] selftest: size: Add size test for Linux kernel
From: Tim Bird @ 2014-12-03 18:42 UTC (permalink / raw)
To: Shuah Khan, linux-api@vger.kernel.org
Cc: Thomas Petazzoni, Michael Ellerman,
linux-embedded@vger.kernel.org, linux-kernel@vger.kernel.org,
Josh Triplett
This test shows the amount of memory used by the system.
Note that this is dependent on the user-space that is loaded
when this program runs. Optimally, this program would be
run as the init program itself.
The program is optimized for size itself, to avoid conflating
its own execution with that of the system software.
The code is compiled statically, with no stdlibs. On my x86_64 system,
this results in a statically linked binary of less than 5K.
Signed-off-by: Tim Bird <tim.bird@sonymobile.com>
---
Changes from v5:
- remove #ifdef in Makefile (doh!)
- use variables in build command
- use different num_to_str, with less conversions
Changes from v4:
- make most routines static
- replace strip with gcc -s
- remove explicit reference to _start
- change --static to -static
- remove explicit reference to LIBGCC
- fix test description for ok and not ok paths, for test 1
Changes from v3:
- add more human-readable output
- put libgcc reference into a variable in Makefile
Changes from v2:
- fix copyright string (again!)
- use __builtin_strlen instead of my own strlen
- replace main with _start
Changes from v1:
- add return values to print routines
- add .gitignore file
- use more correct Copyright string in get_size.c
tools/testing/selftests/Makefile | 1 +
tools/testing/selftests/size/.gitignore | 1 +
tools/testing/selftests/size/Makefile | 12 ++++
tools/testing/selftests/size/get_size.c | 100 ++++++++++++++++++++++++++++++++
4 files changed, 114 insertions(+)
create mode 100644 tools/testing/selftests/size/.gitignore
create mode 100644 tools/testing/selftests/size/Makefile
create mode 100644 tools/testing/selftests/size/get_size.c
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 45f145c..fa91aef 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -15,6 +15,7 @@ TARGETS += user
TARGETS += sysctl
TARGETS += firmware
TARGETS += ftrace
+TARGETS += size
TARGETS_HOTPLUG = cpu-hotplug
TARGETS_HOTPLUG += memory-hotplug
diff --git a/tools/testing/selftests/size/.gitignore b/tools/testing/selftests/size/.gitignore
new file mode 100644
index 0000000..189b781
--- /dev/null
+++ b/tools/testing/selftests/size/.gitignore
@@ -0,0 +1 @@
+get_size
diff --git a/tools/testing/selftests/size/Makefile b/tools/testing/selftests/size/Makefile
new file mode 100644
index 0000000..04dc25e
--- /dev/null
+++ b/tools/testing/selftests/size/Makefile
@@ -0,0 +1,12 @@
+CC = $(CROSS_COMPILE)gcc
+
+all: get_size
+
+get_size: get_size.c
+ $(CC) -static -ffreestanding -nostartfiles -s $< -o $@
+
+run_tests: all
+ ./get_size
+
+clean:
+ $(RM) get_size
diff --git a/tools/testing/selftests/size/get_size.c b/tools/testing/selftests/size/get_size.c
new file mode 100644
index 0000000..2d1af7c
--- /dev/null
+++ b/tools/testing/selftests/size/get_size.c
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2014 Sony Mobile Communications Inc.
+ *
+ * Licensed under the terms of the GNU GPL License version 2
+ *
+ * Selftest for runtime system size
+ *
+ * Prints the amount of RAM that the currently running system is using.
+ *
+ * This program tries to be as small as possible itself, to
+ * avoid perturbing the system memory utilization with its
+ * own execution. It also attempts to have as few dependencies
+ * on kernel features as possible.
+ *
+ * It should be statically linked, with startup libs avoided.
+ * It uses no library calls, and only the following 3 syscalls:
+ * sysinfo(), write(), and _exit()
+ *
+ * For output, it avoids printf (which in some C libraries
+ * has large external dependencies) by implementing it's own
+ * number output and print routines, and using __builtin_strlen()
+ */
+
+#include <sys/sysinfo.h>
+#include <unistd.h>
+
+#define STDOUT_FILENO 1
+
+static int print(const char *s)
+{
+ return write(STDOUT_FILENO, s, __builtin_strlen(s));
+}
+
+static inline char *num_to_str(unsigned long num, char *buf, int len)
+{
+ unsigned int digit;
+
+ /* put digits in buffer from back to front */
+ buf += len - 1;
+ *buf = 0;
+ do {
+ digit = num % 10;
+ *(--buf) = digit + '0';
+ num /= 10;
+ } while (num > 0);
+
+ return buf;
+}
+
+static int print_num(unsigned long num)
+{
+ char num_buf[30];
+
+ return print(num_to_str(num, num_buf, sizeof(num_buf)));
+}
+
+static int print_k_value(const char *s, unsigned long num, unsigned long units)
+{
+ unsigned long long temp;
+ int ccode;
+
+ print(s);
+
+ temp = num;
+ temp = (temp * units)/1024;
+ num = temp;
+ ccode = print_num(num);
+ print("\n");
+ return ccode;
+}
+
+/* this program has no main(), as startup libraries are not used */
+void _start(void)
+{
+ int ccode;
+ struct sysinfo info;
+ unsigned long used;
+
+ print("Testing system size.\n");
+ print("1..1\n");
+
+ ccode = sysinfo(&info);
+ if (ccode < 0) {
+ print("not ok 1 get runtime memory use\n");
+ print("# could not get sysinfo\n");
+ _exit(ccode);
+ }
+ /* ignore cache complexities for now */
+ used = info.totalram - info.freeram - info.bufferram;
+ print_k_value("ok 1 get runtime memory use # size = ", used,
+ info.mem_unit);
+
+ print("# System runtime memory report (units in Kilobytes):\n");
+ print_k_value("# Total: ", info.totalram, info.mem_unit);
+ print_k_value("# Free: ", info.freeram, info.mem_unit);
+ print_k_value("# Buffer: ", info.bufferram, info.mem_unit);
+ print_k_value("# In use: ", used, info.mem_unit);
+
+ _exit(0);
+}
--
1.8.2.2
^ permalink raw reply related
* Re: [PATCH v5] selftest: size: Add size test for Linux kernel
From: Michael Ellerman @ 2014-12-04 0:08 UTC (permalink / raw)
To: Tim Bird
Cc: Shuah Khan, linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Josh Triplett,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-embedded-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
In-Reply-To: <547F3A57.7000106-/MT0OVThwyLZJqsBc5GL+g@public.gmane.org>
On Wed, 2014-12-03 at 08:29 -0800, Tim Bird wrote:
>
> On 12/02/2014 07:43 PM, Michael Ellerman wrote:
> > On Tue, 2014-12-02 at 19:36 -0800, Tim Bird wrote:
> >> This test shows the amount of memory used by the system.
> >> Note that this is dependent on the user-space that is loaded
> >> when this program runs. Optimally, this program would be
> >> run as the init program itself.
> >
> > Sorry to only chime in at v5.
> >
> >> diff --git a/tools/testing/selftests/size/Makefile b/tools/testing/selftests/size/Makefile
> >> new file mode 100644
> >> index 0000000..47f8e9c
> >> --- /dev/null
> >> +++ b/tools/testing/selftests/size/Makefile
> >> @@ -0,0 +1,15 @@
> >> +#ifndef CC
> >> + CC = $(CROSS_COMPILE)gcc
> >> +#endif
> >
> > I think the following is preferable:
> >
> > CC := $(CROSS_COMPILE)$(CC)
> >
> >
> > It allows optionally setting a custom CC, as well as optionally CROSS_COMPILE.
>
> I'm not sure I follow this.
>
> If CC is unset, you get only the CROSS_COMPILE prefix.
CC is never unset. The default value is 'cc'.
> If CC is set to e.g. 'gcc', then you get a nicely formatted toolchain string.
Right.
> But if CC already has the prefix applied, then this will result in
> having it duplicated, which surely won't work correctly.
That's just PEBKAC. Don't specify CROSS_COMPILE and also a fully specified CC.
Try it with the kernel Makefile and see how well it works.
> CROSS_COMPILE prefix usage looks a bit uncoordinated in the tools directory, but most
> tests seem to be favoring $(CROSS_COMPILE)gcc.
That doesn't make it right :)
>
> $ cd tools ; mgrep CROSS
...
> ./testing/selftests/powerpc/Makefile:CC := $(CROSS_COMPILE)$(CC)
You can run git blame on that one if you like ;)
> I agree it's desirable not to hardcode gcc, but we seem to be doing it all over
> the place already.
If everyone jumped off a bridge ... :)
cheers
^ permalink raw reply
* Re: [PATCH v6] selftest: size: Add size test for Linux kernel
From: Josh Triplett @ 2014-12-04 0:36 UTC (permalink / raw)
To: Tim Bird
Cc: Shuah Khan, linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Thomas Petazzoni, Michael Ellerman,
linux-embedded-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
In-Reply-To: <547F598D.7030205-/MT0OVThwyLZJqsBc5GL+g@public.gmane.org>
On Wed, Dec 03, 2014 at 10:42:21AM -0800, Tim Bird wrote:
> This test shows the amount of memory used by the system.
> Note that this is dependent on the user-space that is loaded
> when this program runs. Optimally, this program would be
> run as the init program itself.
>
> The program is optimized for size itself, to avoid conflating
> its own execution with that of the system software.
> The code is compiled statically, with no stdlibs. On my x86_64 system,
> this results in a statically linked binary of less than 5K.
>
> Signed-off-by: Tim Bird <tim.bird-/MT0OVThwyLZJqsBc5GL+g@public.gmane.org>
v6 looks good to me.
Reviewed-by: Josh Triplett <josh-iaAMLnmF4UmaiuxdJuQwMA@public.gmane.org>
Should this go through the tinification tree or the selftests tree?
- Josh Triplett
> Changes from v5:
> - remove #ifdef in Makefile (doh!)
> - use variables in build command
> - use different num_to_str, with less conversions
>
> Changes from v4:
> - make most routines static
> - replace strip with gcc -s
> - remove explicit reference to _start
> - change --static to -static
> - remove explicit reference to LIBGCC
> - fix test description for ok and not ok paths, for test 1
>
> Changes from v3:
> - add more human-readable output
> - put libgcc reference into a variable in Makefile
>
> Changes from v2:
> - fix copyright string (again!)
> - use __builtin_strlen instead of my own strlen
> - replace main with _start
>
> Changes from v1:
> - add return values to print routines
> - add .gitignore file
> - use more correct Copyright string in get_size.c
>
> tools/testing/selftests/Makefile | 1 +
> tools/testing/selftests/size/.gitignore | 1 +
> tools/testing/selftests/size/Makefile | 12 ++++
> tools/testing/selftests/size/get_size.c | 100 ++++++++++++++++++++++++++++++++
> 4 files changed, 114 insertions(+)
> create mode 100644 tools/testing/selftests/size/.gitignore
> create mode 100644 tools/testing/selftests/size/Makefile
> create mode 100644 tools/testing/selftests/size/get_size.c
>
> diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
> index 45f145c..fa91aef 100644
> --- a/tools/testing/selftests/Makefile
> +++ b/tools/testing/selftests/Makefile
> @@ -15,6 +15,7 @@ TARGETS += user
> TARGETS += sysctl
> TARGETS += firmware
> TARGETS += ftrace
> +TARGETS += size
>
> TARGETS_HOTPLUG = cpu-hotplug
> TARGETS_HOTPLUG += memory-hotplug
> diff --git a/tools/testing/selftests/size/.gitignore b/tools/testing/selftests/size/.gitignore
> new file mode 100644
> index 0000000..189b781
> --- /dev/null
> +++ b/tools/testing/selftests/size/.gitignore
> @@ -0,0 +1 @@
> +get_size
> diff --git a/tools/testing/selftests/size/Makefile b/tools/testing/selftests/size/Makefile
> new file mode 100644
> index 0000000..04dc25e
> --- /dev/null
> +++ b/tools/testing/selftests/size/Makefile
> @@ -0,0 +1,12 @@
> +CC = $(CROSS_COMPILE)gcc
> +
> +all: get_size
> +
> +get_size: get_size.c
> + $(CC) -static -ffreestanding -nostartfiles -s $< -o $@
> +
> +run_tests: all
> + ./get_size
> +
> +clean:
> + $(RM) get_size
> diff --git a/tools/testing/selftests/size/get_size.c b/tools/testing/selftests/size/get_size.c
> new file mode 100644
> index 0000000..2d1af7c
> --- /dev/null
> +++ b/tools/testing/selftests/size/get_size.c
> @@ -0,0 +1,100 @@
> +/*
> + * Copyright 2014 Sony Mobile Communications Inc.
> + *
> + * Licensed under the terms of the GNU GPL License version 2
> + *
> + * Selftest for runtime system size
> + *
> + * Prints the amount of RAM that the currently running system is using.
> + *
> + * This program tries to be as small as possible itself, to
> + * avoid perturbing the system memory utilization with its
> + * own execution. It also attempts to have as few dependencies
> + * on kernel features as possible.
> + *
> + * It should be statically linked, with startup libs avoided.
> + * It uses no library calls, and only the following 3 syscalls:
> + * sysinfo(), write(), and _exit()
> + *
> + * For output, it avoids printf (which in some C libraries
> + * has large external dependencies) by implementing it's own
> + * number output and print routines, and using __builtin_strlen()
> + */
> +
> +#include <sys/sysinfo.h>
> +#include <unistd.h>
> +
> +#define STDOUT_FILENO 1
> +
> +static int print(const char *s)
> +{
> + return write(STDOUT_FILENO, s, __builtin_strlen(s));
> +}
> +
> +static inline char *num_to_str(unsigned long num, char *buf, int len)
> +{
> + unsigned int digit;
> +
> + /* put digits in buffer from back to front */
> + buf += len - 1;
> + *buf = 0;
> + do {
> + digit = num % 10;
> + *(--buf) = digit + '0';
> + num /= 10;
> + } while (num > 0);
> +
> + return buf;
> +}
> +
> +static int print_num(unsigned long num)
> +{
> + char num_buf[30];
> +
> + return print(num_to_str(num, num_buf, sizeof(num_buf)));
> +}
> +
> +static int print_k_value(const char *s, unsigned long num, unsigned long units)
> +{
> + unsigned long long temp;
> + int ccode;
> +
> + print(s);
> +
> + temp = num;
> + temp = (temp * units)/1024;
> + num = temp;
> + ccode = print_num(num);
> + print("\n");
> + return ccode;
> +}
> +
> +/* this program has no main(), as startup libraries are not used */
> +void _start(void)
> +{
> + int ccode;
> + struct sysinfo info;
> + unsigned long used;
> +
> + print("Testing system size.\n");
> + print("1..1\n");
> +
> + ccode = sysinfo(&info);
> + if (ccode < 0) {
> + print("not ok 1 get runtime memory use\n");
> + print("# could not get sysinfo\n");
> + _exit(ccode);
> + }
> + /* ignore cache complexities for now */
> + used = info.totalram - info.freeram - info.bufferram;
> + print_k_value("ok 1 get runtime memory use # size = ", used,
> + info.mem_unit);
> +
> + print("# System runtime memory report (units in Kilobytes):\n");
> + print_k_value("# Total: ", info.totalram, info.mem_unit);
> + print_k_value("# Free: ", info.freeram, info.mem_unit);
> + print_k_value("# Buffer: ", info.bufferram, info.mem_unit);
> + print_k_value("# In use: ", used, info.mem_unit);
> +
> + _exit(0);
> +}
> --
> 1.8.2.2
>
^ permalink raw reply
* Re: [PATCH v6] selftest: size: Add size test for Linux kernel
From: Shuah Khan @ 2014-12-04 0:50 UTC (permalink / raw)
To: Josh Triplett, Tim Bird
Cc: linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Thomas Petazzoni, Michael Ellerman,
linux-embedded-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Shuah Khan
In-Reply-To: <20141204003653.GA5004@thin>
On 12/03/2014 05:36 PM, Josh Triplett wrote:
> On Wed, Dec 03, 2014 at 10:42:21AM -0800, Tim Bird wrote:
>> This test shows the amount of memory used by the system.
>> Note that this is dependent on the user-space that is loaded
>> when this program runs. Optimally, this program would be
>> run as the init program itself.
>>
>> The program is optimized for size itself, to avoid conflating
>> its own execution with that of the system software.
>> The code is compiled statically, with no stdlibs. On my x86_64 system,
>> this results in a statically linked binary of less than 5K.
>>
>> Signed-off-by: Tim Bird <tim.bird-/MT0OVThwyLZJqsBc5GL+g@public.gmane.org>
>
> v6 looks good to me.
>
> Reviewed-by: Josh Triplett <josh-iaAMLnmF4UmaiuxdJuQwMA@public.gmane.org>
>
> Should this go through the tinification tree or the selftests tree?
>
Josh/Tim,
Thanks both. Yes v6 looks good. I will take this through kselftest
tree. I will apply this to kselftes fixes.
-- Shuah
--
Shuah Khan
Sr. Linux Kernel Developer
Samsung Research America (Silicon Valley)
shuahkh-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org | (970) 217-8978
^ permalink raw reply
* Re: [PATCH v6] selftest: size: Add size test for Linux kernel
From: Shuah Khan @ 2014-12-04 2:33 UTC (permalink / raw)
To: Josh Triplett, Tim Bird
Cc: linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Thomas Petazzoni, Michael Ellerman,
linux-embedded-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Shuah Khan
In-Reply-To: <547FAFC3.40609-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org>
On 12/03/2014 05:50 PM, Shuah Khan wrote:
> On 12/03/2014 05:36 PM, Josh Triplett wrote:
>> On Wed, Dec 03, 2014 at 10:42:21AM -0800, Tim Bird wrote:
>>> This test shows the amount of memory used by the system.
>>> Note that this is dependent on the user-space that is loaded
>>> when this program runs. Optimally, this program would be
>>> run as the init program itself.
>>>
>>> The program is optimized for size itself, to avoid conflating
>>> its own execution with that of the system software.
>>> The code is compiled statically, with no stdlibs. On my x86_64 system,
>>> this results in a statically linked binary of less than 5K.
>>>
>>> Signed-off-by: Tim Bird <tim.bird-/MT0OVThwyLZJqsBc5GL+g@public.gmane.org>
>>
>> v6 looks good to me.
>>
>> Reviewed-by: Josh Triplett <josh-iaAMLnmF4UmaiuxdJuQwMA@public.gmane.org>
>>
>> Should this go through the tinification tree or the selftests tree?
>>
>
> Josh/Tim,
>
> Thanks both. Yes v6 looks good. I will take this through kselftest
> tree. I will apply this to kselftes fixes.
>
Applied to kselftest fixes branch.
-- Shuah
--
Shuah Khan
Sr. Linux Kernel Developer
Samsung Open Source Group
Samsung Research America (Silicon Valley)
shuahkh-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org | (970) 217-8978
^ permalink raw reply
* Re: [PATCH v5] selftest: size: Add size test for Linux kernel
From: Tim Bird @ 2014-12-04 16:39 UTC (permalink / raw)
To: Michael Ellerman
Cc: Shuah Khan, linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Josh Triplett,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-embedded-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Geert Uytterhoeven
In-Reply-To: <1417651707.9123.1.camel@concordia>
On 12/03/2014 04:08 PM, Michael Ellerman wrote:
> On Wed, 2014-12-03 at 08:29 -0800, Tim Bird wrote:
>>
>> On 12/02/2014 07:43 PM, Michael Ellerman wrote:
>>> On Tue, 2014-12-02 at 19:36 -0800, Tim Bird wrote:
>>>> This test shows the amount of memory used by the system.
>>>> Note that this is dependent on the user-space that is loaded
>>>> when this program runs. Optimally, this program would be
>>>> run as the init program itself.
>>>
>>> Sorry to only chime in at v5.
>>>
>>>> diff --git a/tools/testing/selftests/size/Makefile b/tools/testing/selftests/size/Makefile
>>>> new file mode 100644
>>>> index 0000000..47f8e9c
>>>> --- /dev/null
>>>> +++ b/tools/testing/selftests/size/Makefile
>>>> @@ -0,0 +1,15 @@
>>>> +#ifndef CC
>>>> + CC = $(CROSS_COMPILE)gcc
>>>> +#endif
>>>
>>> I think the following is preferable:
>>>
>>> CC := $(CROSS_COMPILE)$(CC)
>>>
>>>
>>> It allows optionally setting a custom CC, as well as optionally CROSS_COMPILE.
>>
>> I'm not sure I follow this.
>>
>> If CC is unset, you get only the CROSS_COMPILE prefix.
>
> CC is never unset. The default value is 'cc'.
Yeah - I found that out by experimentation yesterday. So my whole
idea for configuring it based on an unset CC was misguided.
>
>> If CC is set to e.g. 'gcc', then you get a nicely formatted toolchain string.
>
> Right.
>
>> But if CC already has the prefix applied, then this will result in
>> having it duplicated, which surely won't work correctly.
>
> That's just PEBKAC. Don't specify CROSS_COMPILE and also a fully specified CC.
> Try it with the kernel Makefile and see how well it works.
>
>> CROSS_COMPILE prefix usage looks a bit uncoordinated in the tools directory, but most
>> tests seem to be favoring $(CROSS_COMPILE)gcc.
>
> That doesn't make it right :)
Agreed. I'd like to separate this issue from the rest of the patch.
Shuah has accepted the patch as it currently is, but I'd like
to start working on the best way to support cross compilation
throughout the kselftest suite.
Ideally we can have CC set properly in a higher-level Makefile,
and not reference CROSS_COMPILE at all in the sub-directory Makefiles.
This may involve copying how CROSS_COMPILE and CFLAGS work in
the rest of the kernel tree, or making some kselftest-specific
modifications.
-- Tim
^ permalink raw reply
* RFC: kselftest size roadmap
From: Tim Bird @ 2014-12-04 16:56 UTC (permalink / raw)
To: Josh Triplett
Cc: Shuah Khan, linux-api@vger.kernel.org, Thomas Petazzoni,
Michael Ellerman, linux-embedded@vger.kernel.org,
linux-kernel@vger.kernel.org
In-Reply-To: <20141204003653.GA5004@thin>
Here's an RFC on my roadmap for the kselftest size test going forward...
In the long term, I'd like to be able to use the test for bisecting
size regressions, and to allow any kernel developer to use this even if they
don't have hardware for a particular architecture.
What I'd like to add to this in the future:
- cleaned up approach to cross-compilation
- put CROSS_COMPILE handling outside sub-directory Makefiles
- this should include support for KBUILD_OUTPUT
- handle CFLAGS for user-space programs (as opposed to
kernel CFLAGS), and in a unified way
- ability to run on target or in emulator
- will involve adding an "install phase", and
possibly a "collect results" phase. These are needed
throughout kselftest to do any host/target
testing.
- add a size threshold parameter to allow the
test to check for a regression
- test needs to return failure code that git
bisect can use (not sure about mechanism for this yet)
- regression test might utilize a feature to save off a
"baseline" size to measure against, for the ability
to indicate a regression as "current size > baseline + 20k"
Any feedback on this?
Thanks,
-- Tim
^ permalink raw reply
* ELC CFP deadline is Jan 9
From: Tim Bird @ 2015-01-08 22:45 UTC (permalink / raw)
To: linux-embedded@vger.kernel.org
Hi embedded Linux developers,
This is quick reminder that the deadline for the Call For Participation for
Embedded Linux Conference 2015 is January 9 (this Friday). The event
is on March 23-25 in San Jose, California.
Please make sure to propose something if you are interested in coming.
I'd write more, but I'm probably breaking list etiquette enough as it is... :-)
Check out the CFP for details:
http://events.linuxfoundation.org/events/embedded-linux-conference/program/cfp
-- Tim
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox