aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--clocks.c54
-rw-r--r--clocks.h38
-rw-r--r--display.c1
-rw-r--r--display.h28
-rw-r--r--powerdebug.h29
5 files changed, 123 insertions, 27 deletions
diff --git a/clocks.c b/clocks.c
index 1635e9d..7bedfa5 100644
--- a/clocks.c
+++ b/clocks.c
@@ -15,6 +15,7 @@
*******************************************************************************/
#include "powerdebug.h"
+#include "clocks.h"
#include <errno.h>
#include <sys/stat.h>
@@ -27,7 +28,24 @@ static int gadder = 0;
void init_clock_details(void)
{
- strcpy(clk_dir_path, "/debug/clock");
+ char *path = debugfs_locate_mpoint();
+ struct stat buf;
+
+
+ if (path)
+ strcpy(clk_dir_path, path);
+ else {
+ fprintf(stderr, "powerdebug: Unable to locate debugfs mount"
+ " point. Mount debugfs and try again..\n");
+ exit(1);
+ }
+ sprintf(clk_dir_path, "%s/clock", clk_dir_path);
+ //strcpy(clk_dir_path, "/debug/clock"); // Hardcoded for testing..
+ if (stat(clk_dir_path, &buf)) {
+ fprintf(stderr, "powerdebug: Unable to find clock tree"
+ " information at %s. Exiting..\n", clk_dir_path);
+ exit(1);
+ }
strcpy(clk_name, "");
strcpy(highlighted_path, "");
}
@@ -350,3 +368,37 @@ void print_clock_info(struct clock_info *clk, int level, int bmp)
}
}
}
+
+char *debugfs_locate_mpoint(void)
+{
+ int ret;
+ FILE *filep;
+ char **path;
+ char fsname[64];
+ struct statfs sfs;
+
+ path = likely_mpoints;
+ while (*path) {
+ ret = statfs(*path, &sfs);
+ if (ret >= 0 && sfs.f_type == (long)DEBUGFS_MAGIC)
+ return *path;
+ path++;
+ }
+
+ filep = fopen("/proc/mounts", "r");
+ if (filep == NULL) {
+ fprintf(stderr, "powerdebug: Error opening /proc/mounts.");
+ exit(1);
+ }
+
+ while (fscanf(filep, "%*s %s %s %*s %*d %*d\n",
+ debugfs_mntpoint, fsname) == 2)
+ if (!strcmp(fsname, "debugfs"))
+ break;
+ fclose(filep);
+
+ if (strcmp(fsname, "debugfs"))
+ return NULL;
+
+ return debugfs_mntpoint;
+}
diff --git a/clocks.h b/clocks.h
new file mode 100644
index 0000000..91cf434
--- /dev/null
+++ b/clocks.h
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (C) 2010, Linaro
+ * Copyright (C) 2010, IBM Corporation
+ *
+ * This file is part of PowerDebug.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Amit Arora <amit.arora@linaro.org> (IBM Corporation)
+ * - initial API and implementation
+ *******************************************************************************/
+
+#include <sys/stat.h>
+#include <sys/vfs.h>
+#include <linux/magic.h>
+
+struct clock_info {
+ char name[NAME_MAX];
+ int flags;
+ int rate;
+ int usecount;
+ int num_children;
+ int last_child;
+ struct clock_info *parent;
+ struct clock_info **children;
+} *clocks_info;
+
+char debugfs_mntpoint[1024];
+
+char *likely_mpoints[] = {
+ "/sys/kernel/debug",
+ "/debug",
+ NULL
+};
diff --git a/display.c b/display.c
index ee88ca1..b396367 100644
--- a/display.c
+++ b/display.c
@@ -15,6 +15,7 @@
*******************************************************************************/
#include "powerdebug.h"
+#include "display.h"
#define print(w, x, y, fmt, args...) do { mvwprintw(w, y, x, fmt, ##args); } while (0)
#define NUM_FOOTER_ITEMS 5
diff --git a/display.h b/display.h
new file mode 100644
index 0000000..c35bd44
--- /dev/null
+++ b/display.h
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (C) 2010, Linaro
+ * Copyright (C) 2010, IBM Corporation
+ *
+ * This file is part of PowerDebug.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Amit Arora <amit.arora@linaro.org> (IBM Corporation)
+ * - initial API and implementation
+ *******************************************************************************/
+
+#define VALUE_MAX 16
+
+WINDOW windows[TOTAL_FEATURE_WINS];
+
+#define PT_COLOR_DEFAULT 1
+#define PT_COLOR_HEADER_BAR 2
+#define PT_COLOR_ERROR 3
+#define PT_COLOR_RED 4
+#define PT_COLOR_YELLOW 5
+#define PT_COLOR_GREEN 6
+#define PT_COLOR_BRIGHT 7
+#define PT_COLOR_BLUE 8
diff --git a/powerdebug.h b/powerdebug.h
index bb9f1c0..901cf77 100644
--- a/powerdebug.h
+++ b/powerdebug.h
@@ -27,12 +27,7 @@
#define VALUE_MAX 16
#define TOTAL_FEATURE_WINS 3 /* Regulator, Clock and Sensor (for now) */
-
-WINDOW windows[TOTAL_FEATURE_WINS];
-extern char *win_names[TOTAL_FEATURE_WINS];
-
enum {REGULATOR, CLOCK, SENSOR};
-extern int selectedwindow;
struct regulator_info {
char name[NAME_MAX];
@@ -50,16 +45,8 @@ struct regulator_info {
int num_users;
} *regulators_info;
-struct clock_info {
- char name[NAME_MAX];
- int flags;
- int rate;
- int usecount;
- int num_children;
- int last_child;
- struct clock_info *parent;
- struct clock_info **children;
-} *clocks_info;
+extern char *win_names[TOTAL_FEATURE_WINS];
+extern int selectedwindow;
extern int numregulators;
extern int dump;
@@ -83,17 +70,7 @@ extern void print_clock_header(int level);
extern void print_sensor_header(void);
extern void print_clock_info_line(int line, char *clockname, int flags,
int rate, int usecount, int highlight);
-
-#define PT_COLOR_DEFAULT 1
-#define PT_COLOR_HEADER_BAR 2
-#define PT_COLOR_ERROR 3
-#define PT_COLOR_RED 4
-#define PT_COLOR_YELLOW 5
-#define PT_COLOR_GREEN 6
-#define PT_COLOR_BRIGHT 7
-#define PT_COLOR_BLUE 8
-
-
+extern char *debugfs_locate_mpoint(void);
extern void init_curses(void);
extern void fini_curses(void);