diff mbox series

[API-NEXT,3/8] linux-gen: system: implement system info print

Message ID 20170421131134.27992-4-petri.savolainen@linaro.org
State Superseded
Headers show
Series Use HW time counter | expand

Commit Message

Petri Savolainen April 21, 2017, 1:11 p.m. UTC
Print API, impl name, CPU model/freq, cache line size and
CPU count by default. Print CPU flags in case of x86.

Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>

---
 platform/linux-generic/arch/arm/odp_sysinfo_parse.c  |  4 ++++
 .../linux-generic/arch/default/odp_sysinfo_parse.c   |  4 ++++
 .../linux-generic/arch/mips64/odp_sysinfo_parse.c    |  4 ++++
 .../linux-generic/arch/powerpc/odp_sysinfo_parse.c   |  4 ++++
 platform/linux-generic/arch/x86/odp_sysinfo_parse.c  |  6 ++++++
 platform/linux-generic/include/odp_internal.h        |  1 +
 platform/linux-generic/odp_system_info.c             | 20 ++++++++++++++++++++
 7 files changed, 43 insertions(+)

-- 
2.11.0

Comments

Honnappa Nagarahalli April 24, 2017, 4:39 a.m. UTC | #1
On 21 April 2017 at 08:11, Petri Savolainen <petri.savolainen@linaro.org> wrote:
> Print API, impl name, CPU model/freq, cache line size and

> CPU count by default. Print CPU flags in case of x86.

>

> Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>

> ---

>  platform/linux-generic/arch/arm/odp_sysinfo_parse.c  |  4 ++++

>  .../linux-generic/arch/default/odp_sysinfo_parse.c   |  4 ++++

>  .../linux-generic/arch/mips64/odp_sysinfo_parse.c    |  4 ++++

>  .../linux-generic/arch/powerpc/odp_sysinfo_parse.c   |  4 ++++

>  platform/linux-generic/arch/x86/odp_sysinfo_parse.c  |  6 ++++++

>  platform/linux-generic/include/odp_internal.h        |  1 +

>  platform/linux-generic/odp_system_info.c             | 20 ++++++++++++++++++++

>  7 files changed, 43 insertions(+)

>

> diff --git a/platform/linux-generic/arch/arm/odp_sysinfo_parse.c b/platform/linux-generic/arch/arm/odp_sysinfo_parse.c

> index 53e2aaea..8ae2022a 100644

> --- a/platform/linux-generic/arch/arm/odp_sysinfo_parse.c

> +++ b/platform/linux-generic/arch/arm/odp_sysinfo_parse.c

> @@ -25,3 +25,7 @@ uint64_t odp_cpu_hz_current(int id ODP_UNUSED)

>  {

>         return 0;

>  }

> +

> +void sys_info_print_arch(void)

> +{

> +}

> diff --git a/platform/linux-generic/arch/default/odp_sysinfo_parse.c b/platform/linux-generic/arch/default/odp_sysinfo_parse.c

> index 53e2aaea..8ae2022a 100644

> --- a/platform/linux-generic/arch/default/odp_sysinfo_parse.c

> +++ b/platform/linux-generic/arch/default/odp_sysinfo_parse.c

> @@ -25,3 +25,7 @@ uint64_t odp_cpu_hz_current(int id ODP_UNUSED)

>  {

>         return 0;

>  }

> +

> +void sys_info_print_arch(void)

> +{

> +}

> diff --git a/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c b/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c

> index 407264b7..d6f75f28 100644

> --- a/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c

> +++ b/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c

> @@ -62,3 +62,7 @@ uint64_t odp_cpu_hz_current(int id ODP_UNUSED)

>  {

>         return 0;

>  }

> +

> +void sys_info_print_arch(void)

> +{

> +}

> diff --git a/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c b/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c

> index 3b88d55b..bd4b9b42 100644

> --- a/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c

> +++ b/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c

> @@ -61,3 +61,7 @@ uint64_t odp_cpu_hz_current(int id ODP_UNUSED)

>  {

>         return 0;

>  }

> +

> +void sys_info_print_arch(void)

> +{

> +}

> diff --git a/platform/linux-generic/arch/x86/odp_sysinfo_parse.c b/platform/linux-generic/arch/x86/odp_sysinfo_parse.c

> index 96127ec6..d77165a4 100644

> --- a/platform/linux-generic/arch/x86/odp_sysinfo_parse.c

> +++ b/platform/linux-generic/arch/x86/odp_sysinfo_parse.c

> @@ -5,6 +5,7 @@

>   */

>

>  #include <odp_internal.h>

> +#include <arch/x86/cpu_flags.h>

>  #include <string.h>

>

>  int cpuinfo_parser(FILE *file, system_info_t *sysinfo)

> @@ -73,3 +74,8 @@ uint64_t odp_cpu_hz_current(int id)

>

>         return 0;

>  }

> +

> +void sys_info_print_arch(void)

> +{

> +       cpu_flags_print_all();

> +}

> diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h

> index acfc3012..90e2a629 100644

> --- a/platform/linux-generic/include/odp_internal.h

> +++ b/platform/linux-generic/include/odp_internal.h

> @@ -133,6 +133,7 @@ int _odp_modules_init_global(void);

>

>  int cpuinfo_parser(FILE *file, system_info_t *sysinfo);

>  uint64_t odp_cpu_hz_current(int id);

> +void sys_info_print_arch(void);

>

>  #ifdef __cplusplus

>  }

> diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c

> index 18c61dbe..4d6f7f81 100644

> --- a/platform/linux-generic/odp_system_info.c

> +++ b/platform/linux-generic/odp_system_info.c

> @@ -14,6 +14,7 @@

>  #include <odp_posix_extensions.h>

>

>  #include <odp/api/system_info.h>

> +#include <odp/api/version.h>

>  #include <odp_internal.h>

>  #include <odp_debug_internal.h>

>  #include <odp/api/align.h>

> @@ -405,3 +406,22 @@ int odp_cpu_count(void)

>  {

>         return odp_global_data.system_info.cpu_count;

>  }

> +

> +void odp_sys_info_print(void)

> +{

> +       printf("\n"

> +              "ODP system info\n"

> +              "---------------\n"

> +              "ODP API version: %s\n"

> +              "ODP impl name:   %s\n"

> +              "CPU model:       %s\n"

> +              "CPU freq (hz):   %" PRIu64 "\n"

> +              "Cache line size: %i\n"

> +              "CPU count:       %i\n"

> +              "\n",

> +              odp_version_api_str(), odp_version_impl_name(),

> +              odp_cpu_model_str(), odp_cpu_hz_max(),

> +              odp_sys_cache_line_size(), odp_cpu_count());

> +

> +       sys_info_print_arch();

> +}


printf should be changed to ODP_LOG.

What is the purpose of this API? There are commands in various OS to
provide the system information. If an application wants to print the
system information, it could do that using those commands. Those
commands also provide more rich information than what is provided
here. For ex: What is the amount of memory available, the frequency of
the memory, number of memory channels, cache size (L1i, L1d, L2, L3)
etc

> --

> 2.11.0

>
Savolainen, Petri (Nokia - FI/Espoo) April 24, 2017, 7:06 a.m. UTC | #2
> > +

> > +void odp_sys_info_print(void)

> > +{

> > +       printf("\n"

> > +              "ODP system info\n"

> > +              "---------------\n"

> > +              "ODP API version: %s\n"

> > +              "ODP impl name:   %s\n"

> > +              "CPU model:       %s\n"

> > +              "CPU freq (hz):   %" PRIu64 "\n"

> > +              "Cache line size: %i\n"

> > +              "CPU count:       %i\n"

> > +              "\n",

> > +              odp_version_api_str(), odp_version_impl_name(),

> > +              odp_cpu_model_str(), odp_cpu_hz_max(),

> > +              odp_sys_cache_line_size(), odp_cpu_count());

> > +

> > +       sys_info_print_arch();

> > +}

> 

> printf should be changed to ODP_LOG.


Log functions cannot handle inttypes (PRIu64) directly, but I'll try snprintf + ODP_PRINT().

> 

> What is the purpose of this API? There are commands in various OS to

> provide the system information. If an application wants to print the

> system information, it could do that using those commands. Those

> commands also provide more rich information than what is provided

> here. For ex: What is the amount of memory available, the frequency of

> the memory, number of memory channels, cache size (L1i, L1d, L2, L3)

> etc


Answered that for 1/8. The beef here is sys_info_print_arch() call, which prints out tens of x86 cpu flags on a x86 system. This can print out anything, hundreds of HW details that Linux do not know about / care about / do not give you API. It's for implementer to print out all the debug information about the system.

-Petri
Maxim Uvarov April 24, 2017, 1:30 p.m. UTC | #3
On 24.04.2017 10:06, Savolainen, Petri (Nokia - FI/Espoo) wrote:
>>> +

>>> +void odp_sys_info_print(void)

>>> +{

>>> +       printf("\n"

>>> +              "ODP system info\n"

>>> +              "---------------\n"

>>> +              "ODP API version: %s\n"

>>> +              "ODP impl name:   %s\n"

>>> +              "CPU model:       %s\n"

>>> +              "CPU freq (hz):   %" PRIu64 "\n"

>>> +              "Cache line size: %i\n"

>>> +              "CPU count:       %i\n"

>>> +              "\n",

>>> +              odp_version_api_str(), odp_version_impl_name(),

>>> +              odp_cpu_model_str(), odp_cpu_hz_max(),

>>> +              odp_sys_cache_line_size(), odp_cpu_count());

>>> +

>>> +       sys_info_print_arch();

>>> +}

>>

>> printf should be changed to ODP_LOG.

> 

> Log functions cannot handle inttypes (PRIu64) directly, but I'll try snprintf + ODP_PRINT().

> 



how about just returning pointer to system info text?

char *buf = odp_sys_get_info();

printf(buf);

Maxim.


>>

>> What is the purpose of this API? There are commands in various OS to

>> provide the system information. If an application wants to print the

>> system information, it could do that using those commands. Those

>> commands also provide more rich information than what is provided

>> here. For ex: What is the amount of memory available, the frequency of

>> the memory, number of memory channels, cache size (L1i, L1d, L2, L3)

>> etc

> 

> Answered that for 1/8. The beef here is sys_info_print_arch() call, which prints out tens of x86 cpu flags on a x86 system. This can print out anything, hundreds of HW details that Linux do not know about / care about / do not give you API. It's for implementer to print out all the debug information about the system.

> 

> -Petri

> 

>
diff mbox series

Patch

diff --git a/platform/linux-generic/arch/arm/odp_sysinfo_parse.c b/platform/linux-generic/arch/arm/odp_sysinfo_parse.c
index 53e2aaea..8ae2022a 100644
--- a/platform/linux-generic/arch/arm/odp_sysinfo_parse.c
+++ b/platform/linux-generic/arch/arm/odp_sysinfo_parse.c
@@ -25,3 +25,7 @@  uint64_t odp_cpu_hz_current(int id ODP_UNUSED)
 {
 	return 0;
 }
+
+void sys_info_print_arch(void)
+{
+}
diff --git a/platform/linux-generic/arch/default/odp_sysinfo_parse.c b/platform/linux-generic/arch/default/odp_sysinfo_parse.c
index 53e2aaea..8ae2022a 100644
--- a/platform/linux-generic/arch/default/odp_sysinfo_parse.c
+++ b/platform/linux-generic/arch/default/odp_sysinfo_parse.c
@@ -25,3 +25,7 @@  uint64_t odp_cpu_hz_current(int id ODP_UNUSED)
 {
 	return 0;
 }
+
+void sys_info_print_arch(void)
+{
+}
diff --git a/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c b/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c
index 407264b7..d6f75f28 100644
--- a/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c
+++ b/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c
@@ -62,3 +62,7 @@  uint64_t odp_cpu_hz_current(int id ODP_UNUSED)
 {
 	return 0;
 }
+
+void sys_info_print_arch(void)
+{
+}
diff --git a/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c b/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c
index 3b88d55b..bd4b9b42 100644
--- a/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c
+++ b/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c
@@ -61,3 +61,7 @@  uint64_t odp_cpu_hz_current(int id ODP_UNUSED)
 {
 	return 0;
 }
+
+void sys_info_print_arch(void)
+{
+}
diff --git a/platform/linux-generic/arch/x86/odp_sysinfo_parse.c b/platform/linux-generic/arch/x86/odp_sysinfo_parse.c
index 96127ec6..d77165a4 100644
--- a/platform/linux-generic/arch/x86/odp_sysinfo_parse.c
+++ b/platform/linux-generic/arch/x86/odp_sysinfo_parse.c
@@ -5,6 +5,7 @@ 
  */
 
 #include <odp_internal.h>
+#include <arch/x86/cpu_flags.h>
 #include <string.h>
 
 int cpuinfo_parser(FILE *file, system_info_t *sysinfo)
@@ -73,3 +74,8 @@  uint64_t odp_cpu_hz_current(int id)
 
 	return 0;
 }
+
+void sys_info_print_arch(void)
+{
+	cpu_flags_print_all();
+}
diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h
index acfc3012..90e2a629 100644
--- a/platform/linux-generic/include/odp_internal.h
+++ b/platform/linux-generic/include/odp_internal.h
@@ -133,6 +133,7 @@  int _odp_modules_init_global(void);
 
 int cpuinfo_parser(FILE *file, system_info_t *sysinfo);
 uint64_t odp_cpu_hz_current(int id);
+void sys_info_print_arch(void);
 
 #ifdef __cplusplus
 }
diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c
index 18c61dbe..4d6f7f81 100644
--- a/platform/linux-generic/odp_system_info.c
+++ b/platform/linux-generic/odp_system_info.c
@@ -14,6 +14,7 @@ 
 #include <odp_posix_extensions.h>
 
 #include <odp/api/system_info.h>
+#include <odp/api/version.h>
 #include <odp_internal.h>
 #include <odp_debug_internal.h>
 #include <odp/api/align.h>
@@ -405,3 +406,22 @@  int odp_cpu_count(void)
 {
 	return odp_global_data.system_info.cpu_count;
 }
+
+void odp_sys_info_print(void)
+{
+	printf("\n"
+	       "ODP system info\n"
+	       "---------------\n"
+	       "ODP API version: %s\n"
+	       "ODP impl name:   %s\n"
+	       "CPU model:       %s\n"
+	       "CPU freq (hz):   %" PRIu64 "\n"
+	       "Cache line size: %i\n"
+	       "CPU count:       %i\n"
+	       "\n",
+	       odp_version_api_str(), odp_version_impl_name(),
+	       odp_cpu_model_str(), odp_cpu_hz_max(),
+	       odp_sys_cache_line_size(), odp_cpu_count());
+
+	sys_info_print_arch();
+}