|
Packit |
c04fcb |
/*
|
|
Packit |
c04fcb |
* Copyright (C) 2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
|
|
Packit |
c04fcb |
*
|
|
Packit |
c04fcb |
* This library is free software; you can redistribute it and/or
|
|
Packit |
c04fcb |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
c04fcb |
* License as published by the Free Software Foundation; version 2.1 of
|
|
Packit |
c04fcb |
* the License.
|
|
Packit |
c04fcb |
*
|
|
Packit |
c04fcb |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
c04fcb |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
c04fcb |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
c04fcb |
* Lesser General Public License for more details.
|
|
Packit |
c04fcb |
*
|
|
Packit |
c04fcb |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
c04fcb |
* License along with this library; if not, write to the Free Software
|
|
Packit |
c04fcb |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
Packit |
c04fcb |
*/
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
#define _GNU_SOURCE
|
|
Packit |
c04fcb |
#include <error.h>
|
|
Packit |
c04fcb |
#include <dlfcn.h>
|
|
Packit |
c04fcb |
#include <stdlib.h>
|
|
Packit |
c04fcb |
#include <usterr-signal-safe.h>
|
|
Packit |
c04fcb |
#include <lttng/ust-getcpu.h>
|
|
Packit |
c04fcb |
#include <urcu/system.h>
|
|
Packit |
c04fcb |
#include <urcu/arch.h>
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
#include "getenv.h"
|
|
Packit |
c04fcb |
#include "../libringbuffer/getcpu.h"
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
int (*lttng_get_cpu)(void);
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
static
|
|
Packit |
c04fcb |
void *getcpu_handle;
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
int lttng_ust_getcpu_override(int (*getcpu)(void))
|
|
Packit |
c04fcb |
{
|
|
Packit |
c04fcb |
CMM_STORE_SHARED(lttng_get_cpu, getcpu);
|
|
Packit |
c04fcb |
return 0;
|
|
Packit |
c04fcb |
}
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
void lttng_ust_getcpu_init(void)
|
|
Packit |
c04fcb |
{
|
|
Packit |
c04fcb |
const char *libname;
|
|
Packit |
c04fcb |
void (*libinit)(void);
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
if (getcpu_handle)
|
|
Packit |
c04fcb |
return;
|
|
Packit |
c04fcb |
libname = lttng_secure_getenv("LTTNG_UST_GETCPU_PLUGIN");
|
|
Packit |
c04fcb |
if (!libname)
|
|
Packit |
c04fcb |
return;
|
|
Packit |
c04fcb |
getcpu_handle = dlopen(libname, RTLD_NOW);
|
|
Packit |
c04fcb |
if (!getcpu_handle) {
|
|
Packit |
c04fcb |
PERROR("Cannot load LTTng UST getcpu override library %s",
|
|
Packit |
c04fcb |
libname);
|
|
Packit |
c04fcb |
return;
|
|
Packit |
c04fcb |
}
|
|
Packit |
c04fcb |
dlerror();
|
|
Packit |
c04fcb |
libinit = (void (*)(void)) dlsym(getcpu_handle,
|
|
Packit |
c04fcb |
"lttng_ust_getcpu_plugin_init");
|
|
Packit |
c04fcb |
if (!libinit) {
|
|
Packit |
c04fcb |
PERROR("Cannot find LTTng UST getcpu override library %s initialization function lttng_ust_getcpu_plugin_init()",
|
|
Packit |
c04fcb |
libname);
|
|
Packit |
c04fcb |
return;
|
|
Packit |
c04fcb |
}
|
|
Packit |
c04fcb |
libinit();
|
|
Packit |
c04fcb |
}
|