Commit | Line | Data |
---|---|---|
5e1b7b8b MD |
1 | /* |
2 | * Copyright (C) 2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
3 | * | |
4 | * This library is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the GNU Lesser General Public | |
6 | * License as published by the Free Software Foundation; version 2.1 of | |
7 | * the License. | |
8 | * | |
9 | * This library is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | * Lesser General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU Lesser General Public | |
15 | * License along with this library; if not, write to the Free Software | |
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
17 | */ | |
18 | ||
19 | #define _GNU_SOURCE | |
20 | #include <error.h> | |
21 | #include <dlfcn.h> | |
22 | #include <stdlib.h> | |
23 | #include <usterr-signal-safe.h> | |
24 | #include <lttng/ust-getcpu.h> | |
25 | #include <urcu/system.h> | |
26 | #include <urcu/arch.h> | |
27 | ||
730bf2af | 28 | #include "getenv.h" |
5e1b7b8b MD |
29 | #include "../libringbuffer/getcpu.h" |
30 | ||
31 | int (*lttng_get_cpu)(void); | |
32 | ||
4bc1ccd7 MD |
33 | static |
34 | void *getcpu_handle; | |
35 | ||
5e1b7b8b MD |
36 | int lttng_ust_getcpu_override(int (*getcpu)(void)) |
37 | { | |
38 | CMM_STORE_SHARED(lttng_get_cpu, getcpu); | |
39 | return 0; | |
40 | } | |
41 | ||
42 | void lttng_ust_getcpu_init(void) | |
43 | { | |
44 | const char *libname; | |
5e1b7b8b MD |
45 | void (*libinit)(void); |
46 | ||
4bc1ccd7 MD |
47 | if (getcpu_handle) |
48 | return; | |
730bf2af | 49 | libname = lttng_secure_getenv("LTTNG_UST_GETCPU_PLUGIN"); |
5e1b7b8b MD |
50 | if (!libname) |
51 | return; | |
4bc1ccd7 MD |
52 | getcpu_handle = dlopen(libname, RTLD_NOW); |
53 | if (!getcpu_handle) { | |
5e1b7b8b MD |
54 | PERROR("Cannot load LTTng UST getcpu override library %s", |
55 | libname); | |
56 | return; | |
57 | } | |
58 | dlerror(); | |
4bc1ccd7 | 59 | libinit = (void (*)(void)) dlsym(getcpu_handle, |
5e1b7b8b MD |
60 | "lttng_ust_getcpu_plugin_init"); |
61 | if (!libinit) { | |
62 | PERROR("Cannot find LTTng UST getcpu override library %s initialization function lttng_ust_getcpu_plugin_init()", | |
63 | libname); | |
64 | return; | |
65 | } | |
66 | libinit(); | |
67 | } |