some review comments bellow:

On 07/01/16 10:34, Petri Savolainen wrote:
This is a minimal application which demostrates the startup and
shutdown steps of an ODP application. It can be also used to
debug API related build problems, etc. It does not use helpers
to minimize dependencies to anything else than the ODP API
header file.

Signed-off-by: Petri Savolainen <[email protected]>
---
  example/Makefile.am       |   2 +-
  example/hello/.gitignore  |   3 ++
  example/hello/Makefile.am |  11 +++++
  example/hello/odp_hello.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++
  example/m4/configure.m4   |   3 +-
  5 files changed, 118 insertions(+), 2 deletions(-)
  create mode 100644 example/hello/.gitignore
  create mode 100644 example/hello/Makefile.am
  create mode 100644 example/hello/odp_hello.c

diff --git a/example/Makefile.am b/example/Makefile.am
index 7f82c4d..37542af 100644
--- a/example/Makefile.am
+++ b/example/Makefile.am
@@ -1 +1 @@
-SUBDIRS = classifier generator ipsec packet time timer traffic_mgmt 
l2fwd_simple switch
+SUBDIRS = classifier generator ipsec packet time timer traffic_mgmt 
l2fwd_simple switch hello
diff --git a/example/hello/.gitignore b/example/hello/.gitignore
new file mode 100644
index 0000000..7c11c4c
--- /dev/null
+++ b/example/hello/.gitignore
@@ -0,0 +1,3 @@
+odp_hello
+*.log
+*.trs
diff --git a/example/hello/Makefile.am b/example/hello/Makefile.am
new file mode 100644
index 0000000..2e4e0ce
--- /dev/null
+++ b/example/hello/Makefile.am
@@ -0,0 +1,11 @@
+include $(top_srcdir)/example/Makefile.inc
+
+bin_PROGRAMS = odp_hello$(EXEEXT)
+odp_hello_LDFLAGS = $(AM_LDFLAGS) -static
+odp_hello_CFLAGS = $(AM_CFLAGS) -I${top_srcdir}/example
+
+dist_odp_hello_SOURCES = odp_hello.c
+
+if test_example
+TESTS = odp_hello
+endif
diff --git a/example/hello/odp_hello.c b/example/hello/odp_hello.c
new file mode 100644
index 0000000..9a0ec79
--- /dev/null
+++ b/example/hello/odp_hello.c
@@ -0,0 +1,101 @@
+/* Copyright (c) 2016, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+

needed to add here the same description what application does.


+/* Linux CPU affinity */
+#define _GNU_SOURCE
+#include <sched.h>
+
+/* Linux PID */
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <stdio.h>
+#include <string.h>
+
+#include <odp_api.h>
+
+typedef struct {
+       int cpu;
+       int num;
+} options_t;
+
+static int parse_args(int argc, char *argv[], options_t *opt)
+{
+       static const char * const args[] = {"-c", "-n"};
+       int i, tmp;
+
+       for (i = 1; i < argc; i++) {
+               if ((strcmp(argv[i], args[0]) == 0) &&
+                   (sscanf(argv[i + 1], "%i", &tmp) == 1)) {
+                       opt->cpu = tmp;
+                       i++;
+               } else if ((strcmp(argv[i], args[1]) == 0) &&
+                          (sscanf(argv[i + 1], "%i", &tmp) == 1)) {
+                       opt->num = tmp;
+                       i++;
+               } else {
+                       printf("\nUsage:\n"
+                              "  %s  CPU number\n"
+                              "  %s  Number of iterations\n\n",
+                              args[0], args[1]);
+                       return -1;
+               }
+       }
+
+       return 0;
+}
+
+int main(int argc, char *argv[])
+{
+       odp_instance_t inst;
+       options_t opt;
+       pid_t pid;
+       cpu_set_t cpu_set;
+       int i;
+
+       memset(&opt, 0, sizeof(opt));
+       opt.cpu = 0;
+       opt.num = 1;
+
+       if (parse_args(argc, argv, &opt))
+               return -1;
+
+       pid = getpid();
+       CPU_ZERO(&cpu_set);
+       CPU_SET(opt.cpu, &cpu_set);
+
+       if (sched_setaffinity(pid, sizeof(cpu_set_t), &cpu_set)) {
+               printf("Set CPU affinity failed.\n");
+               return -1;
+       }
+
+       if (odp_init_global(&inst, NULL, NULL)) {
+               printf("Global init failed.\n");
+               return -1;
+       }
+
+       if (odp_init_local(inst, ODP_THREAD_CONTROL)) {
+               printf("Local init failed.\n");

I think it's better to print errors to stderr.

Maxim.
+               return -1;
+       }
+
+       for (i = 0; i < opt.num; i++) {
+               printf("Hello world from CPU %i!\n", odp_cpu_id());
+               odp_time_wait_ns(ODP_TIME_SEC_IN_NS);
+       }
+
+       if (odp_term_local()) {
+               printf("Local term failed.\n");
+               return -1;
+       }
+
+       if (odp_term_global(inst)) {
+               printf("Global term failed.\n");
+               return -1;
+       }
+
+       return 0;
+}
diff --git a/example/m4/configure.m4 b/example/m4/configure.m4
index 9731d81..bbda38f 100644
--- a/example/m4/configure.m4
+++ b/example/m4/configure.m4
@@ -19,4 +19,5 @@ AC_CONFIG_FILES([example/classifier/Makefile
                 example/timer/Makefile
                 example/traffic_mgmt/Makefile
                 example/l2fwd_simple/Makefile
-                example/switch/Makefile])
+                example/switch/Makefile
+                example/hello/Makefile])

_______________________________________________
lng-odp mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to