From d37ac3cdc4fe21f117edfb829db4d0eb7cf914a1 Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Mon, 6 Jul 2020 12:18:01 -0400 Subject: [PATCH] Add kernel and UST time namespace context MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Michael Jeanson Signed-off-by: Jérémie Galarneau Change-Id: I37a67cd61d55e1b94a9f54712143daeabfb47e84 --- include/lttng/event.h | 1 + src/bin/lttng-sessiond/context.c | 3 +++ src/bin/lttng-sessiond/save.c | 6 ++++++ src/bin/lttng-sessiond/trace-ust.c | 3 +++ src/bin/lttng-sessiond/ust-abi-internal.h | 1 + src/bin/lttng/commands/add_context.c | 2 ++ src/common/config/config-session-abi.h | 1 + src/common/config/session-config.c | 4 ++++ src/common/lttng-kernel.h | 1 + src/common/mi-lttng-4.0.xsd | 1 + src/common/mi-lttng.c | 2 ++ tests/regression/kernel/test_ns_contexts | 3 ++- tests/regression/kernel/test_ns_contexts_change | 1 + tests/regression/ust/namespaces/test_ns_contexts | 3 ++- tests/regression/ust/namespaces/test_ns_contexts_change | 1 + tests/utils/testapp/gen-ns-events/gen-ns-events.c | 9 +++++++-- .../utils/testapp/gen-ust-events-ns/gen-ust-events-ns.c | 9 +++++++-- 17 files changed, 45 insertions(+), 6 deletions(-) diff --git a/include/lttng/event.h b/include/lttng/event.h index 2bd44d686..bcde9a49e 100644 --- a/include/lttng/event.h +++ b/include/lttng/event.h @@ -155,6 +155,7 @@ enum lttng_event_context_type { LTTNG_EVENT_CONTEXT_VGID = 38, LTTNG_EVENT_CONTEXT_VEGID = 39, LTTNG_EVENT_CONTEXT_VSGID = 40, + LTTNG_EVENT_CONTEXT_TIME_NS = 41, }; enum lttng_event_field_type { diff --git a/src/bin/lttng-sessiond/context.c b/src/bin/lttng-sessiond/context.c index 0575ab91d..621c0b9fb 100644 --- a/src/bin/lttng-sessiond/context.c +++ b/src/bin/lttng-sessiond/context.c @@ -272,6 +272,9 @@ int context_kernel_add(struct ltt_kernel_session *ksession, case LTTNG_EVENT_CONTEXT_PID_NS: kctx->ctx.ctx = LTTNG_KERNEL_CONTEXT_PID_NS; break; + case LTTNG_EVENT_CONTEXT_TIME_NS: + kctx->ctx.ctx = LTTNG_KERNEL_CONTEXT_TIME_NS; + break; case LTTNG_EVENT_CONTEXT_USER_NS: kctx->ctx.ctx = LTTNG_KERNEL_CONTEXT_USER_NS; break; diff --git a/src/bin/lttng-sessiond/save.c b/src/bin/lttng-sessiond/save.c index c5ea4c873..09194008a 100644 --- a/src/bin/lttng-sessiond/save.c +++ b/src/bin/lttng-sessiond/save.c @@ -322,6 +322,9 @@ const char *get_kernel_context_type_string( case LTTNG_KERNEL_CONTEXT_PID_NS: context_type_string = config_event_context_pid_ns; break; + case LTTNG_KERNEL_CONTEXT_TIME_NS: + context_type_string = config_event_context_time_ns; + break; case LTTNG_KERNEL_CONTEXT_USER_NS: context_type_string = config_event_context_user_ns; break; @@ -408,6 +411,9 @@ const char *get_ust_context_type_string( case LTTNG_UST_CONTEXT_NET_NS: context_type_string = config_event_context_net_ns; break; + case LTTNG_UST_CONTEXT_TIME_NS: + context_type_string = config_event_context_time_ns; + break; case LTTNG_UST_CONTEXT_PID_NS: context_type_string = config_event_context_pid_ns; break; diff --git a/src/bin/lttng-sessiond/trace-ust.c b/src/bin/lttng-sessiond/trace-ust.c index 80dd8dc54..7ee379ef8 100644 --- a/src/bin/lttng-sessiond/trace-ust.c +++ b/src/bin/lttng-sessiond/trace-ust.c @@ -585,6 +585,9 @@ int trace_ust_context_type_event_to_ust( case LTTNG_EVENT_CONTEXT_PID_NS: utype = LTTNG_UST_CONTEXT_PID_NS; break; + case LTTNG_EVENT_CONTEXT_TIME_NS: + utype = LTTNG_UST_CONTEXT_TIME_NS; + break; case LTTNG_EVENT_CONTEXT_USER_NS: utype = LTTNG_UST_CONTEXT_USER_NS; break; diff --git a/src/bin/lttng-sessiond/ust-abi-internal.h b/src/bin/lttng-sessiond/ust-abi-internal.h index 99da583d5..14f214f67 100644 --- a/src/bin/lttng-sessiond/ust-abi-internal.h +++ b/src/bin/lttng-sessiond/ust-abi-internal.h @@ -143,6 +143,7 @@ enum lttng_ust_context_type { LTTNG_UST_CONTEXT_VGID = 18, LTTNG_UST_CONTEXT_VEGID = 19, LTTNG_UST_CONTEXT_VSGID = 20, + LTTNG_UST_CONTEXT_TIME_NS = 21, }; struct lttng_ust_perf_counter_ctx { diff --git a/src/bin/lttng/commands/add_context.c b/src/bin/lttng/commands/add_context.c index de54721cb..b33eb1d14 100644 --- a/src/bin/lttng/commands/add_context.c +++ b/src/bin/lttng/commands/add_context.c @@ -95,6 +95,7 @@ enum context_type { CONTEXT_VGID = 38, CONTEXT_VEGID = 39, CONTEXT_VSGID = 40, + CONTEXT_TIME_NS = 41, }; /* @@ -264,6 +265,7 @@ const struct ctx_opts { { (char *) "mnt_ns", CONTEXT_MNT_NS }, { (char *) "net_ns", CONTEXT_NET_NS }, { (char *) "pid_ns", CONTEXT_PID_NS }, + { (char *) "time_ns", CONTEXT_TIME_NS }, { (char *) "user_ns", CONTEXT_USER_NS }, { (char *) "uts_ns", CONTEXT_UTS_NS }, { (char *) "uid", CONTEXT_UID }, diff --git a/src/common/config/config-session-abi.h b/src/common/config/config-session-abi.h index 41f675041..75ff303d4 100644 --- a/src/common/config/config-session-abi.h +++ b/src/common/config/config-session-abi.h @@ -161,6 +161,7 @@ extern const char * const config_event_context_ipc_ns; extern const char * const config_event_context_mnt_ns; extern const char * const config_event_context_net_ns; extern const char * const config_event_context_pid_ns; +extern const char * const config_event_context_time_ns; extern const char * const config_event_context_user_ns; extern const char * const config_event_context_uts_ns; extern const char * const config_event_context_uid; diff --git a/src/common/config/session-config.c b/src/common/config/session-config.c index e893c1298..37c5ce383 100644 --- a/src/common/config/session-config.c +++ b/src/common/config/session-config.c @@ -223,6 +223,7 @@ LTTNG_HIDDEN const char * const config_event_context_ipc_ns = "IPC_NS"; LTTNG_HIDDEN const char * const config_event_context_mnt_ns = "MNT_NS"; LTTNG_HIDDEN const char * const config_event_context_net_ns = "NET_NS"; LTTNG_HIDDEN const char * const config_event_context_pid_ns = "PID_NS"; +LTTNG_HIDDEN const char * const config_event_context_time_ns = "TIME_NS"; LTTNG_HIDDEN const char * const config_event_context_user_ns = "USER_NS"; LTTNG_HIDDEN const char * const config_event_context_uts_ns = "UTS_NS"; LTTNG_HIDDEN const char * const config_event_context_uid = "UID"; @@ -1094,6 +1095,9 @@ int get_context_type(xmlChar *context_type) } else if (!strcmp((char *) context_type, config_event_context_pid_ns)) { ret = LTTNG_EVENT_CONTEXT_PID_NS; + } else if (!strcmp((char *) context_type, + config_event_context_time_ns)) { + ret = LTTNG_EVENT_CONTEXT_TIME_NS; } else if (!strcmp((char *) context_type, config_event_context_user_ns)) { ret = LTTNG_EVENT_CONTEXT_USER_NS; diff --git a/src/common/lttng-kernel.h b/src/common/lttng-kernel.h index d5904e79f..fc2a1e259 100644 --- a/src/common/lttng-kernel.h +++ b/src/common/lttng-kernel.h @@ -75,6 +75,7 @@ enum lttng_kernel_context_type { LTTNG_KERNEL_CONTEXT_VGID = 34, LTTNG_KERNEL_CONTEXT_VEGID = 35, LTTNG_KERNEL_CONTEXT_VSGID = 36, + LTTNG_KERNEL_CONTEXT_TIME_NS = 37, }; /* Perf counter attributes */ diff --git a/src/common/mi-lttng-4.0.xsd b/src/common/mi-lttng-4.0.xsd index fef655096..9b656ece4 100644 --- a/src/common/mi-lttng-4.0.xsd +++ b/src/common/mi-lttng-4.0.xsd @@ -109,6 +109,7 @@ SPDX-License-Identifier: MIT + diff --git a/src/common/mi-lttng.c b/src/common/mi-lttng.c index 71253fcd2..1088ba29c 100644 --- a/src/common/mi-lttng.c +++ b/src/common/mi-lttng.c @@ -431,6 +431,8 @@ const char *mi_lttng_event_contexttype_string(enum lttng_event_context_type val) return config_event_context_net_ns; case LTTNG_EVENT_CONTEXT_PID_NS: return config_event_context_pid_ns; + case LTTNG_EVENT_CONTEXT_TIME_NS: + return config_event_context_time_ns; case LTTNG_EVENT_CONTEXT_USER_NS: return config_event_context_user_ns; case LTTNG_EVENT_CONTEXT_UTS_NS: diff --git a/tests/regression/kernel/test_ns_contexts b/tests/regression/kernel/test_ns_contexts index 0ab31c3a3..1a25d8666 100755 --- a/tests/regression/kernel/test_ns_contexts +++ b/tests/regression/kernel/test_ns_contexts @@ -11,7 +11,7 @@ TESTDIR=$CURDIR/../.. TESTS_PER_NS=11 -NUM_TESTS=$((TESTS_PER_NS * 7)) +NUM_TESTS=$((TESTS_PER_NS * 8)) source "$TESTDIR/utils/utils.sh" @@ -131,5 +131,6 @@ test_ns ipc test_ns mnt test_ns net test_ns pid +test_ns time test_ns user test_ns uts diff --git a/tests/regression/kernel/test_ns_contexts_change b/tests/regression/kernel/test_ns_contexts_change index 1c5d15f02..118d120a6 100755 --- a/tests/regression/kernel/test_ns_contexts_change +++ b/tests/regression/kernel/test_ns_contexts_change @@ -172,5 +172,6 @@ test_ns ipc test_ns mnt test_ns net #test_ns pid # pid_ns is special, can't be changed that way +#test_ns time # time_ns is special, can't be changed that way test_ns user test_ns uts diff --git a/tests/regression/ust/namespaces/test_ns_contexts b/tests/regression/ust/namespaces/test_ns_contexts index 6f0e50472..c1c6a2ae6 100755 --- a/tests/regression/ust/namespaces/test_ns_contexts +++ b/tests/regression/ust/namespaces/test_ns_contexts @@ -17,7 +17,7 @@ EVENT_NAME="tp:tptest" TESTS_PER_NS=13 -NUM_TESTS=$((TESTS_PER_NS * 7)) +NUM_TESTS=$((TESTS_PER_NS * 8)) source "$TESTDIR/utils/utils.sh" @@ -89,5 +89,6 @@ test_ns ipc test_ns mnt test_ns net test_ns pid +test_ns time test_ns user test_ns uts diff --git a/tests/regression/ust/namespaces/test_ns_contexts_change b/tests/regression/ust/namespaces/test_ns_contexts_change index fb1e936cd..6ce614aba 100755 --- a/tests/regression/ust/namespaces/test_ns_contexts_change +++ b/tests/regression/ust/namespaces/test_ns_contexts_change @@ -118,5 +118,6 @@ test_ns ipc test_ns mnt test_ns net #test_ns pid # pid_ns is special, can't be changed that way +#test_ns time # time_ns is special, can't be changed that way #test_ns user # user_ns can only be change when the app is single threaded, this is always false for an ust instrumented app test_ns uts diff --git a/tests/utils/testapp/gen-ns-events/gen-ns-events.c b/tests/utils/testapp/gen-ns-events/gen-ns-events.c index 22398c314..7c2b6478c 100644 --- a/tests/utils/testapp/gen-ns-events/gen-ns-events.c +++ b/tests/utils/testapp/gen-ns-events/gen-ns-events.c @@ -53,6 +53,9 @@ #ifndef CLONE_NEWNET #define CLONE_NEWNET 0x40000000 #endif +#ifndef CLONE_NEWTIME +#define CLONE_NEWTIME 0x00000080 +#endif static int debug = 0; static char *ns_opt = NULL; @@ -217,7 +220,7 @@ int main(int argc, const char **argv) goto end; } - if (strncmp(ns_opt, "cgroup", 3) == 0) { + if (strncmp(ns_opt, "cgroup", 6) == 0) { ret = do_the_needful(CLONE_NEWCGROUP, "cgroup"); } else if (strncmp(ns_opt, "ipc", 3) == 0) { ret = do_the_needful(CLONE_NEWIPC, "ipc"); @@ -227,7 +230,9 @@ int main(int argc, const char **argv) ret = do_the_needful(CLONE_NEWNET, "net"); } else if (strncmp(ns_opt, "pid", 3) == 0) { ret = do_the_needful(CLONE_NEWPID, "pid"); - } else if (strncmp(ns_opt, "user", 3) == 0) { + } else if (strncmp(ns_opt, "time", 4) == 0) { + ret = do_the_needful(CLONE_NEWTIME, "time"); + } else if (strncmp(ns_opt, "user", 4) == 0) { /* * Will always fail, requires a single threaded application, * which can't happen with UST. diff --git a/tests/utils/testapp/gen-ust-events-ns/gen-ust-events-ns.c b/tests/utils/testapp/gen-ust-events-ns/gen-ust-events-ns.c index c5f25dd7b..907651d7c 100644 --- a/tests/utils/testapp/gen-ust-events-ns/gen-ust-events-ns.c +++ b/tests/utils/testapp/gen-ust-events-ns/gen-ust-events-ns.c @@ -55,6 +55,9 @@ #ifndef CLONE_NEWNET #define CLONE_NEWNET 0x40000000 #endif +#ifndef CLONE_NEWTIME +#define CLONE_NEWTIME 0x00000080 +#endif static int nr_iter = 100; static int debug = 0; @@ -233,7 +236,7 @@ int main(int argc, const char **argv) goto end; } - if (strncmp(ns_opt, "cgroup", 3) == 0) { + if (strncmp(ns_opt, "cgroup", 6) == 0) { ret = do_the_needful(CLONE_NEWCGROUP, "cgroup"); } else if (strncmp(ns_opt, "ipc", 3) == 0) { ret = do_the_needful(CLONE_NEWIPC, "ipc"); @@ -243,7 +246,9 @@ int main(int argc, const char **argv) ret = do_the_needful(CLONE_NEWNET, "net"); } else if (strncmp(ns_opt, "pid", 3) == 0) { ret = do_the_needful(CLONE_NEWPID, "pid"); - } else if (strncmp(ns_opt, "user", 3) == 0) { + } else if (strncmp(ns_opt, "time", 4) == 0) { + ret = do_the_needful(CLONE_NEWTIME, "time"); + } else if (strncmp(ns_opt, "user", 4) == 0) { /* * Will always fail, requires a single threaded application, * which can't happen with UST. -- 2.34.1