Module: xenomai-3
Branch: next
Commit: 6044426913c0447db6c4658092cb7674c1d1aa9d
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=6044426913c0447db6c4658092cb7674c1d1aa9d

Author: Philippe Gerum <r...@xenomai.org>
Date:   Tue May 12 10:11:18 2015 +0200

boilerplate, copperplate: introduce API to manipulate tunables

The core libraries define a set of tunable parameters, this commit
provides an API for applications to assign and fetch their current
value.

Parameters are divided in 'config' and 'runtime' tunable sets. The
former may be assigned new values until the core starts running the
->init() handlers from the setup descriptors, at which point any
attempt to change them triggers an assertion when --enable-assert is
in effect. The latter can be changed at any point in time.

A single API is provided in order to frame all possible manipulations
within a small set of generic helpers, so that we can do basic error
detection at build time and runtime, and keep options open for later
extending this API, such as automated tracing and reporting.

---

 include/boilerplate/Makefile.am |    3 +-
 include/boilerplate/setup.h     |   10 ++--
 include/boilerplate/tunables.h  |  116 +++++++++++++++++++++++++++++++++++++++
 include/copperplate/Makefile.am |    1 +
 include/copperplate/tunables.h  |   81 +++++++++++++++++++++++++++
 include/xenomai/Makefile.am     |    4 +-
 include/xenomai/init.h          |    6 +-
 include/xenomai/tunables.h      |   24 ++++++++
 lib/boilerplate/setup.c         |   13 ++++-
 lib/copperplate/internal.h      |   16 +-----
 lib/smokey/init.c               |    5 +-
 11 files changed, 251 insertions(+), 28 deletions(-)

diff --git a/include/boilerplate/Makefile.am b/include/boilerplate/Makefile.am
index b611364..2d3ace8 100644
--- a/include/boilerplate/Makefile.am
+++ b/include/boilerplate/Makefile.am
@@ -14,4 +14,5 @@ includesub_HEADERS =  \
        scope.h         \
        setup.h         \
        shared-list.h   \
-       time.h
+       time.h          \
+       tunables.h
diff --git a/include/boilerplate/setup.h b/include/boilerplate/setup.h
index 0879618..f1ff7b1 100644
--- a/include/boilerplate/setup.h
+++ b/include/boilerplate/setup.h
@@ -95,15 +95,17 @@ void __register_setup_call(struct setup_descriptor *p, int 
id);
 
 extern pid_t __node_id;
 
-extern struct base_setup_data __base_setup_data;
+extern int __config_done;
 
-#ifdef __cplusplus
-}
-#endif
+extern struct base_setup_data __base_setup_data;
 
 static inline const char *get_program_name(void)
 {
        return basename(__base_setup_data.arg0 ?: "program");
 }
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* !_BOILERPLATE_SETUP_H */
diff --git a/include/boilerplate/tunables.h b/include/boilerplate/tunables.h
new file mode 100644
index 0000000..796a19c
--- /dev/null
+++ b/include/boilerplate/tunables.h
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2015 Philippe Gerum <r...@xenomai.org>.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
+ */
+#ifndef _BOILERPLATE_TUNABLES_H
+#define _BOILERPLATE_TUNABLES_H
+
+#include <assert.h>
+#include <boilerplate/setup.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static inline int __may_change_config_tunable(void)
+{
+       return !__config_done;
+}
+
+#define __tunable_set_call(__name, __scope)    \
+       __assign_ ## __name ## _ ## __scope
+
+#define __tunable_get_call(__name, __scope)    \
+       __read_ ## __name ## _ ## __scope
+
+#define __define_tunable(__name, __type, __val, __scope)       \
+       void __tunable_set_call(__name, __scope)(typeof(__type) __val)
+
+#define __read_tunable(__name, __type, __scope)        \
+       typeof(__type) __tunable_get_call(__name, __scope)(void)
+
+#define define_config_tunable(__name, __type, __val)   \
+       __define_tunable(__name, __type, __val, config)
+
+#define define_runtime_tunable(__name, __type, __val)  \
+       __define_tunable(__name, __type, __val, runtime)
+
+#define read_config_tunable(__name, __type)            \
+       __read_tunable(__name, __type, config)
+
+#define read_runtime_tunable(__name, __type)           \
+       __read_tunable(__name, __type, runtime)
+
+#define set_config_tunable(__name, __val)                      \
+       do {                                                    \
+               assert(__may_change_config_tunable());          \
+               __tunable_set_call(__name, config)(__val);      \
+       } while (0)
+
+#define get_config_tunable(__name)             \
+       __tunable_get_call(__name, config)()
+
+#define set_runtime_tunable(__name, __val)     \
+       __tunable_set_call(__name, runtime)(__val)
+
+#define get_runtime_tunable(__name)            \
+       __tunable_get_call(__name, runtime)()
+
+static inline define_config_tunable(cpu_affinity, cpu_set_t, cpus)
+{
+       __base_setup_data.cpu_affinity = cpus;
+}
+
+static inline read_config_tunable(cpu_affinity, cpu_set_t)
+{
+       return __base_setup_data.cpu_affinity;
+}
+
+static inline define_config_tunable(no_mlock, int, nolock)
+{
+       __base_setup_data.no_mlock = nolock;
+}
+
+static inline read_config_tunable(no_mlock, int)
+{
+       return __base_setup_data.no_mlock;
+}
+
+static inline define_config_tunable(no_sanity, int, nosanity)
+{
+       __base_setup_data.no_sanity = nosanity;
+}
+
+static inline read_config_tunable(no_sanity, int)
+{
+       return __base_setup_data.no_sanity;
+}
+
+static inline define_runtime_tunable(quiet_mode, int, mode)
+{
+       __base_setup_data.quiet_mode = mode;
+}
+
+static inline read_runtime_tunable(quiet_mode, int)
+{
+       return __base_setup_data.quiet_mode;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !_BOILERPLATE_TUNABLES_H */
diff --git a/include/copperplate/Makefile.am b/include/copperplate/Makefile.am
index 2cd3079..5b97c63 100644
--- a/include/copperplate/Makefile.am
+++ b/include/copperplate/Makefile.am
@@ -13,6 +13,7 @@ includesub_HEADERS =          \
        threadobj.h             \
        timerobj.h              \
        traceobj.h              \
+       tunables.h              \
        wrappers.h
 
 noinst_HEADERS =               \
diff --git a/include/copperplate/tunables.h b/include/copperplate/tunables.h
new file mode 100644
index 0000000..be697da
--- /dev/null
+++ b/include/copperplate/tunables.h
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2015 Philippe Gerum <r...@xenomai.org>.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
+ */
+#ifndef _COPPERPLATE_TUNABLES_H
+#define _COPPERPLATE_TUNABLES_H
+
+#include <boilerplate/tunables.h>
+
+struct copperplate_setup_data {
+       const char *session_root;
+       const char *session_label;
+       const char *registry_root;
+       int no_registry;
+       size_t mem_pool;
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern struct copperplate_setup_data __copperplate_setup_data;
+
+static inline define_config_tunable(session_label, const char *, label)
+{
+       __copperplate_setup_data.session_label = label;
+}
+
+static inline read_config_tunable(session_label, const char *)
+{
+       return __copperplate_setup_data.session_label;
+}
+
+static inline define_config_tunable(registry_root, const char *, root)
+{
+       __copperplate_setup_data.registry_root = root;
+}
+
+static inline read_config_tunable(registry_root, const char *)
+{
+       return __copperplate_setup_data.registry_root;
+}
+
+static inline define_config_tunable(no_registry, int, noreg)
+{
+       __copperplate_setup_data.no_registry = noreg;
+}
+
+static inline read_config_tunable(no_registry, int)
+{
+       return __copperplate_setup_data.no_registry;
+}
+
+static inline define_config_tunable(mem_pool_size, size_t, size)
+{
+       __copperplate_setup_data.mem_pool = size;
+}
+
+static inline read_config_tunable(mem_pool_size, size_t)
+{
+       return __copperplate_setup_data.mem_pool;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !_COPPERPLATE_TUNABLES_H */
diff --git a/include/xenomai/Makefile.am b/include/xenomai/Makefile.am
index b5f941d..871cf2b 100644
--- a/include/xenomai/Makefile.am
+++ b/include/xenomai/Makefile.am
@@ -1,4 +1,6 @@
 includesubdir = $(includedir)/xenomai
 
 includesub_HEADERS =   \
-       init.h
+       init.h          \
+       tunables.h
+
diff --git a/include/xenomai/init.h b/include/xenomai/init.h
index bd99da7..6b3636b 100644
--- a/include/xenomai/init.h
+++ b/include/xenomai/init.h
@@ -15,8 +15,8 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
  */
-#ifndef _XENOMAI_XENOMAI_INIT_H
-#define _XENOMAI_XENOMAI_INIT_H
+#ifndef _XENOMAI_INIT_H
+#define _XENOMAI_INIT_H
 
 #include <boilerplate/setup.h>
 
@@ -38,4 +38,4 @@ extern const char *xenomai_version_string;
 }
 #endif
 
-#endif /* _XENOMAI_XENOMAI_INIT_H */
+#endif /* _XENOMAI_INIT_H */
diff --git a/include/xenomai/tunables.h b/include/xenomai/tunables.h
new file mode 100644
index 0000000..9eebc22
--- /dev/null
+++ b/include/xenomai/tunables.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2015 Philippe Gerum <r...@xenomai.org>.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
+ */
+#ifndef _XENOMAI_TUNABLES_H
+#define _XENOMAI_TUNABLES_H
+
+#include <boilerplate/tunables.h>
+#include <copperplate/tunables.h>
+
+#endif /* !_XENOMAI_TUNABLES_H */
diff --git a/lib/boilerplate/setup.c b/lib/boilerplate/setup.c
index 9dca6a0..24b2550 100644
--- a/lib/boilerplate/setup.c
+++ b/lib/boilerplate/setup.c
@@ -40,7 +40,9 @@ struct base_setup_data __base_setup_data = {
        .no_mlock = 0,
 };
 
-pid_t __node_id;
+pid_t __node_id = 0;
+
+int __config_done = 0;
 
 static int init_done;
 
@@ -504,6 +506,12 @@ void xenomai_init(int *argcp, char *const **argvp)
                if (ret)
                        goto fail;
 
+               /*
+                * From now on, we may not assign configuration
+                * tunables anymore.
+                */
+               __config_done = 1;
+       
                CANCEL_DEFER(svc);
 
                pvlist_for_each_entry(setup, &setup_list, __reserved.next) {
@@ -520,7 +528,8 @@ void xenomai_init(int *argcp, char *const **argvp)
                        early_warning("setup call %s failed", setup->name);
                        goto fail;
                }
-       }
+       } else
+               __config_done = 1;
 
        free(options);
 
diff --git a/lib/copperplate/internal.h b/lib/copperplate/internal.h
index 5c464a5..eaaa340 100644
--- a/lib/copperplate/internal.h
+++ b/lib/copperplate/internal.h
@@ -30,6 +30,7 @@
 #include <boilerplate/sched.h>
 #include <boilerplate/setup.h>
 #include <copperplate/heapobj.h>
+#include <copperplate/tunables.h>
 
 #ifdef CONFIG_XENO_REGISTRY
 #define DEFAULT_REGISTRY_ROOT          CONFIG_XENO_REGISTRY_ROOT
@@ -37,14 +38,6 @@
 #define DEFAULT_REGISTRY_ROOT          NULL
 #endif
 
-struct copperplate_setup_data {
-       const char *session_root;
-       const char *session_label;
-       const char *registry_root;
-       int no_registry;
-       unsigned int mem_pool;
-};
-
 #define HOBJ_MINLOG2    3
 #define HOBJ_MAXLOG2    22     /* Must hold pagemap::bcount objects */
 #define HOBJ_NBUCKETS   (HOBJ_MAXLOG2 - HOBJ_MINLOG2 + 2)
@@ -85,13 +78,6 @@ struct corethread_attributes {
        } __reserved;
 };
 
-extern struct copperplate_setup_data __copperplate_setup_data;
-
-static inline void copperplate_set_quiet(void)
-{
-       __base_setup_data.quiet_mode = 1;
-}
-
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/lib/smokey/init.c b/lib/smokey/init.c
index e5ccf0a..136f5c8 100644
--- a/lib/smokey/init.c
+++ b/lib/smokey/init.c
@@ -29,6 +29,7 @@
 #include <boilerplate/ancillaries.h>
 #include "copperplate/internal.h"
 #include <xenomai/init.h>
+#include <xenomai/tunables.h>
 #include <smokey/smokey.h>
 
 /**
@@ -448,9 +449,9 @@ static int smokey_parse_option(int optnum, const char 
*optarg)
 static int smokey_init(void)
 {
        if (pvlist_empty(&smokey_test_list))
-               copperplate_set_quiet();
+               set_runtime_tunable(quiet_mode, 1);
        else
-               smokey_quiet_mode = __base_setup_data.quiet_mode;
+               smokey_quiet_mode = get_runtime_tunable(quiet_mode);
 
        return 0;
 }


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to