X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=liblttng-ust%2Flttng-context-procname.c;h=95d5f28dbe20b9a2e21decd18e7b2db04ccb0efa;hb=74011e88983b12958dacd6621d60c18f6a84f59b;hp=4b8da28f255aa56d74fe87c67f12cdd214680782;hpb=553bbf7f38652084ed7966c7817b8ccb372b14e1;p=lttng-ust.git diff --git a/liblttng-ust/lttng-context-procname.c b/liblttng-ust/lttng-context-procname.c index 4b8da28f..95d5f28d 100644 --- a/liblttng-ust/lttng-context-procname.c +++ b/liblttng-ust/lttng-context-procname.c @@ -28,6 +28,9 @@ #include #include "compat.h" +/* Maximum number of nesting levels for the procname cache. */ +#define PROCNAME_NESTING_MAX 2 + /* * We cache the result to ensure we don't trigger a system call for * each event. @@ -37,22 +40,34 @@ * be set for a thread before the first event is logged within this * thread. */ -typedef char procname_array[17]; -static DEFINE_URCU_TLS_IE(procname_array, cached_procname); +typedef char procname_array[PROCNAME_NESTING_MAX][17]; + +static DEFINE_URCU_TLS(procname_array, cached_procname); + +static DEFINE_URCU_TLS(int, procname_nesting); static inline char *wrapper_getprocname(void) { - if (caa_unlikely(!URCU_TLS(cached_procname)[0])) { - lttng_ust_getprocname(URCU_TLS(cached_procname)); - URCU_TLS(cached_procname)[LTTNG_UST_PROCNAME_LEN - 1] = '\0'; + int nesting = URCU_TLS(procname_nesting); + + if (caa_unlikely(nesting >= PROCNAME_NESTING_MAX)) + return ""; + if (caa_unlikely(!URCU_TLS(cached_procname)[nesting][0])) { + CMM_STORE_SHARED(URCU_TLS(procname_nesting), nesting + 1); + lttng_ust_getprocname(URCU_TLS(cached_procname)[nesting]); + URCU_TLS(cached_procname)[nesting][LTTNG_UST_PROCNAME_LEN - 1] = '\0'; + CMM_STORE_SHARED(URCU_TLS(procname_nesting), nesting); } - return URCU_TLS(cached_procname); + return URCU_TLS(cached_procname)[nesting]; } void lttng_context_procname_reset(void) { - URCU_TLS(cached_procname)[0] = '\0'; + URCU_TLS(cached_procname)[1][0] = '\0'; + CMM_STORE_SHARED(URCU_TLS(procname_nesting), 1); + URCU_TLS(cached_procname)[0][0] = '\0'; + CMM_STORE_SHARED(URCU_TLS(procname_nesting), 0); } static