From 553873e1df63a20559ac9c336765dc7055cfc3d4 Mon Sep 17 00:00:00 2001 From: Borislav Petkov Date: Mon, 9 Dec 2013 17:14:23 +0100 Subject: tools/: Convert to new topic libraries Move debugfs.* to api/fs/. We have a common tools/lib/api/ place where the Makefile lives and then we place the headers in subdirs. For example, all the fs-related stuff goes to tools/lib/api/fs/ from which we get libapikfs.a (acme got almost the naming he wanted :-)) and we link it into the tools which need it - in this case perf and tools/vm/page-types. acme: "Looking at the implementation, I think some tools can even link directly to the .o files, avoiding the .a file altogether. But that is just an optimization/finer granularity tools/lib/ cherrypicking that toolers can make use of." Fixup documentation cleaning target while at it. Signed-off-by: Borislav Petkov Acked-by: Ingo Molnar Cc: Adrian Hunter Cc: Andi Kleen Cc: Arjan van de Ven Cc: David Ahern Cc: Frederic Weisbecker Cc: Ingo Molnar Cc: Jiri Olsa Cc: Mike Galbraith Cc: Namhyung Kim Cc: Paul Mackerras Cc: Pekka Enberg Cc: Peter Zijlstra Cc: Robert Richter Cc: Stanislav Fomichev Cc: Stephane Eranian Cc: Steven Rostedt Link: http://lkml.kernel.org/r/1386605664-24041-2-git-send-email-bp@alien8.de Signed-off-by: Arnaldo Carvalho de Melo --- tools/lib/api/Makefile | 42 +++++++++++++++++++ tools/lib/api/fs/debugfs.c | 100 +++++++++++++++++++++++++++++++++++++++++++++ tools/lib/api/fs/debugfs.h | 29 +++++++++++++ tools/lib/lk/Makefile | 38 ----------------- tools/lib/lk/debugfs.c | 100 --------------------------------------------- tools/lib/lk/debugfs.h | 29 ------------- 6 files changed, 171 insertions(+), 167 deletions(-) create mode 100644 tools/lib/api/Makefile create mode 100644 tools/lib/api/fs/debugfs.c create mode 100644 tools/lib/api/fs/debugfs.h delete mode 100644 tools/lib/lk/Makefile delete mode 100644 tools/lib/lk/debugfs.c delete mode 100644 tools/lib/lk/debugfs.h (limited to 'tools/lib') diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile new file mode 100644 index 00000000000..ed2f51e11b8 --- /dev/null +++ b/tools/lib/api/Makefile @@ -0,0 +1,42 @@ +include ../../scripts/Makefile.include +include ../../perf/config/utilities.mak # QUIET_CLEAN + +CC = $(CROSS_COMPILE)gcc +AR = $(CROSS_COMPILE)ar + +# guard against environment variables +LIB_H= +LIB_OBJS= + +LIB_H += fs/debugfs.h + +LIB_OBJS += $(OUTPUT)fs/debugfs.o + +LIBFILE = libapikfs.a + +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC +EXTLIBS = -lelf -lpthread -lrt -lm +ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 +ALL_LDFLAGS = $(LDFLAGS) + +RM = rm -f + +$(LIBFILE): $(LIB_OBJS) + $(QUIET_AR)$(RM) $@ && $(AR) rcs $(OUTPUT)$@ $(LIB_OBJS) + +$(LIB_OBJS): $(LIB_H) + +libapi_dirs: + $(QUIET_MKDIR)mkdir -p $(OUTPUT)fs/ + +$(OUTPUT)%.o: %.c libapi_dirs + $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $< +$(OUTPUT)%.s: %.c libapi_dirs + $(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $< +$(OUTPUT)%.o: %.S libapi_dirs + $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $< + +clean: + $(call QUIET_CLEAN, libapi) $(RM) $(LIB_OBJS) $(LIBFILE) + +.PHONY: clean diff --git a/tools/lib/api/fs/debugfs.c b/tools/lib/api/fs/debugfs.c new file mode 100644 index 00000000000..7c434796235 --- /dev/null +++ b/tools/lib/api/fs/debugfs.c @@ -0,0 +1,100 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "debugfs.h" + +char debugfs_mountpoint[PATH_MAX + 1] = "/sys/kernel/debug"; + +static const char * const debugfs_known_mountpoints[] = { + "/sys/kernel/debug/", + "/debug/", + 0, +}; + +static bool debugfs_found; + +/* find the path to the mounted debugfs */ +const char *debugfs_find_mountpoint(void) +{ + const char * const *ptr; + char type[100]; + FILE *fp; + + if (debugfs_found) + return (const char *)debugfs_mountpoint; + + ptr = debugfs_known_mountpoints; + while (*ptr) { + if (debugfs_valid_mountpoint(*ptr) == 0) { + debugfs_found = true; + strcpy(debugfs_mountpoint, *ptr); + return debugfs_mountpoint; + } + ptr++; + } + + /* give up and parse /proc/mounts */ + fp = fopen("/proc/mounts", "r"); + if (fp == NULL) + return NULL; + + while (fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n", + debugfs_mountpoint, type) == 2) { + if (strcmp(type, "debugfs") == 0) + break; + } + fclose(fp); + + if (strcmp(type, "debugfs") != 0) + return NULL; + + debugfs_found = true; + + return debugfs_mountpoint; +} + +/* verify that a mountpoint is actually a debugfs instance */ + +int debugfs_valid_mountpoint(const char *debugfs) +{ + struct statfs st_fs; + + if (statfs(debugfs, &st_fs) < 0) + return -ENOENT; + else if (st_fs.f_type != (long) DEBUGFS_MAGIC) + return -ENOENT; + + return 0; +} + +/* mount the debugfs somewhere if it's not mounted */ +char *debugfs_mount(const char *mountpoint) +{ + /* see if it's already mounted */ + if (debugfs_find_mountpoint()) + goto out; + + /* if not mounted and no argument */ + if (mountpoint == NULL) { + /* see if environment variable set */ + mountpoint = getenv(PERF_DEBUGFS_ENVIRONMENT); + /* if no environment variable, use default */ + if (mountpoint == NULL) + mountpoint = "/sys/kernel/debug"; + } + + if (mount(NULL, mountpoint, "debugfs", 0, NULL) < 0) + return NULL; + + /* save the mountpoint */ + debugfs_found = true; + strncpy(debugfs_mountpoint, mountpoint, sizeof(debugfs_mountpoint)); +out: + return debugfs_mountpoint; +} diff --git a/tools/lib/api/fs/debugfs.h b/tools/lib/api/fs/debugfs.h new file mode 100644 index 00000000000..f19d3df9609 --- /dev/null +++ b/tools/lib/api/fs/debugfs.h @@ -0,0 +1,29 @@ +#ifndef __API_DEBUGFS_H__ +#define __API_DEBUGFS_H__ + +#define _STR(x) #x +#define STR(x) _STR(x) + +/* + * On most systems would have given us this, but not on some systems + * (e.g. GNU/Hurd). + */ +#ifndef PATH_MAX +#define PATH_MAX 4096 +#endif + +#ifndef DEBUGFS_MAGIC +#define DEBUGFS_MAGIC 0x64626720 +#endif + +#ifndef PERF_DEBUGFS_ENVIRONMENT +#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR" +#endif + +const char *debugfs_find_mountpoint(void); +int debugfs_valid_mountpoint(const char *debugfs); +char *debugfs_mount(const char *mountpoint); + +extern char debugfs_mountpoint[]; + +#endif /* __API_DEBUGFS_H__ */ diff --git a/tools/lib/lk/Makefile b/tools/lib/lk/Makefile deleted file mode 100644 index 3dba0a4aebb..00000000000 --- a/tools/lib/lk/Makefile +++ /dev/null @@ -1,38 +0,0 @@ -include ../../scripts/Makefile.include - -CC = $(CROSS_COMPILE)gcc -AR = $(CROSS_COMPILE)ar - -# guard against environment variables -LIB_H= -LIB_OBJS= - -LIB_H += debugfs.h - -LIB_OBJS += $(OUTPUT)debugfs.o - -LIBFILE = liblk.a - -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC -EXTLIBS = -lelf -lpthread -lrt -lm -ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -ALL_LDFLAGS = $(LDFLAGS) - -RM = rm -f - -$(LIBFILE): $(LIB_OBJS) - $(QUIET_AR)$(RM) $@ && $(AR) rcs $(OUTPUT)$@ $(LIB_OBJS) - -$(LIB_OBJS): $(LIB_H) - -$(OUTPUT)%.o: %.c - $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $< -$(OUTPUT)%.s: %.c - $(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $< -$(OUTPUT)%.o: %.S - $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $< - -clean: - $(RM) $(LIB_OBJS) $(LIBFILE) - -.PHONY: clean diff --git a/tools/lib/lk/debugfs.c b/tools/lib/lk/debugfs.c deleted file mode 100644 index 7c434796235..00000000000 --- a/tools/lib/lk/debugfs.c +++ /dev/null @@ -1,100 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -#include "debugfs.h" - -char debugfs_mountpoint[PATH_MAX + 1] = "/sys/kernel/debug"; - -static const char * const debugfs_known_mountpoints[] = { - "/sys/kernel/debug/", - "/debug/", - 0, -}; - -static bool debugfs_found; - -/* find the path to the mounted debugfs */ -const char *debugfs_find_mountpoint(void) -{ - const char * const *ptr; - char type[100]; - FILE *fp; - - if (debugfs_found) - return (const char *)debugfs_mountpoint; - - ptr = debugfs_known_mountpoints; - while (*ptr) { - if (debugfs_valid_mountpoint(*ptr) == 0) { - debugfs_found = true; - strcpy(debugfs_mountpoint, *ptr); - return debugfs_mountpoint; - } - ptr++; - } - - /* give up and parse /proc/mounts */ - fp = fopen("/proc/mounts", "r"); - if (fp == NULL) - return NULL; - - while (fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n", - debugfs_mountpoint, type) == 2) { - if (strcmp(type, "debugfs") == 0) - break; - } - fclose(fp); - - if (strcmp(type, "debugfs") != 0) - return NULL; - - debugfs_found = true; - - return debugfs_mountpoint; -} - -/* verify that a mountpoint is actually a debugfs instance */ - -int debugfs_valid_mountpoint(const char *debugfs) -{ - struct statfs st_fs; - - if (statfs(debugfs, &st_fs) < 0) - return -ENOENT; - else if (st_fs.f_type != (long) DEBUGFS_MAGIC) - return -ENOENT; - - return 0; -} - -/* mount the debugfs somewhere if it's not mounted */ -char *debugfs_mount(const char *mountpoint) -{ - /* see if it's already mounted */ - if (debugfs_find_mountpoint()) - goto out; - - /* if not mounted and no argument */ - if (mountpoint == NULL) { - /* see if environment variable set */ - mountpoint = getenv(PERF_DEBUGFS_ENVIRONMENT); - /* if no environment variable, use default */ - if (mountpoint == NULL) - mountpoint = "/sys/kernel/debug"; - } - - if (mount(NULL, mountpoint, "debugfs", 0, NULL) < 0) - return NULL; - - /* save the mountpoint */ - debugfs_found = true; - strncpy(debugfs_mountpoint, mountpoint, sizeof(debugfs_mountpoint)); -out: - return debugfs_mountpoint; -} diff --git a/tools/lib/lk/debugfs.h b/tools/lib/lk/debugfs.h deleted file mode 100644 index 935c59bdb44..00000000000 --- a/tools/lib/lk/debugfs.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef __LK_DEBUGFS_H__ -#define __LK_DEBUGFS_H__ - -#define _STR(x) #x -#define STR(x) _STR(x) - -/* - * On most systems would have given us this, but not on some systems - * (e.g. GNU/Hurd). - */ -#ifndef PATH_MAX -#define PATH_MAX 4096 -#endif - -#ifndef DEBUGFS_MAGIC -#define DEBUGFS_MAGIC 0x64626720 -#endif - -#ifndef PERF_DEBUGFS_ENVIRONMENT -#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR" -#endif - -const char *debugfs_find_mountpoint(void); -int debugfs_valid_mountpoint(const char *debugfs); -char *debugfs_mount(const char *mountpoint); - -extern char debugfs_mountpoint[]; - -#endif /* __LK_DEBUGFS_H__ */ -- cgit v1.2.3-18-g5258