From patchwork Thu Jun 16 20:29:43 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 2000 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 4448F23F3F for ; Thu, 16 Jun 2011 20:31:51 +0000 (UTC) Received: from mail-vw0-f50.google.com (mail-vw0-f50.google.com [209.85.212.50]) by fiordland.canonical.com (Postfix) with ESMTP id 14594A18585 for ; Thu, 16 Jun 2011 20:31:50 +0000 (UTC) Received: by mail-vw0-f50.google.com with SMTP id 14so1756035vws.37 for ; Thu, 16 Jun 2011 13:31:50 -0700 (PDT) Received: by 10.52.100.72 with SMTP id ew8mr1841006vdb.247.1308256310878; Thu, 16 Jun 2011 13:31:50 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.52.183.130 with SMTP id em2cs211216vdc; Thu, 16 Jun 2011 13:31:50 -0700 (PDT) Received: by 10.227.201.9 with SMTP id ey9mr1375699wbb.41.1308256306119; Thu, 16 Jun 2011 13:31:46 -0700 (PDT) Received: from smtp.smtpout.orange.fr (smtp08.smtpout.orange.fr [80.12.242.130]) by mx.google.com with ESMTP id fl7si1363890wbb.33.2011.06.16.13.31.45; Thu, 16 Jun 2011 13:31:46 -0700 (PDT) Received-SPF: neutral (google.com: 80.12.242.130 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) client-ip=80.12.242.130; Authentication-Results: mx.google.com; spf=neutral (google.com: 80.12.242.130 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) smtp.mail=daniel.lezcano@linaro.org Received: from monster.dhcp.lxc ([92.134.76.78]) by mwinf5d16 with ME id wkXf1g0031hMfSL03kXlJn; Thu, 16 Jun 2011 22:31:45 +0200 From: Daniel Lezcano To: patches@linaro.org Subject: [PATCH 14/28] use the tree code to dump the clocks Date: Thu, 16 Jun 2011 22:29:43 +0200 Message-Id: <1308256197-29155-14-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1308256197-29155-1-git-send-email-daniel.lezcano@linaro.org> References: <1308256197-29155-1-git-send-email-daniel.lezcano@linaro.org> Signed-off-by: Daniel Lezcano --- clocks.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 86 insertions(+), 4 deletions(-) diff --git a/clocks.c b/clocks.c index 848c52e..5bb04a4 100644 --- a/clocks.c +++ b/clocks.c @@ -42,11 +42,12 @@ struct clock_info { int last_child; int expanded; int level; + char *prefix; struct clock_info *parent; struct clock_info **children; } *clocks_info; -static struct tree *clock_tree; +static struct tree *clock_tree = NULL; static int locate_debugfs(char *clk_path) { @@ -123,7 +124,8 @@ out_free: return ret; } -static int file_read_from_format(char *file, int *value, const char *format) +static int file_read_from_format(const char *file, int *value, + const char *format) { FILE *f; int ret; @@ -137,12 +139,12 @@ static int file_read_from_format(char *file, int *value, const char *format) return !ret ? -1 : 0; } -static inline int file_read_int(char *file, int *value) +static inline int file_read_int(const char *file, int *value) { return file_read_from_format(file, value, "%d"); } -static inline int file_read_hex(char *file, int *value) +static inline int file_read_hex(const char *file, int *value) { return file_read_from_format(file, value, "%x"); } @@ -511,6 +513,24 @@ static struct clock_info *clock_alloc(const char *name) return ci; } +static int fill_clock_cb(struct tree *t, void *data) +{ + struct clock_info *clkinfo; + + clkinfo = clock_alloc(t->name); + if (!clkinfo) + return -1; + + t->private = clkinfo; + clkinfo->level = t->depth; + + file_read_value(t->path, "flags", "%x", &clkinfo->flags); + file_read_value(t->path, "rate", "%d", &clkinfo->rate); + file_read_value(t->path, "usecount", "%d", &clkinfo->usecount); + + return 0; +} + int read_clock_info(char *clkpath) { DIR *dir; @@ -520,6 +540,9 @@ int read_clock_info(char *clkpath) struct clock_info *cur; int ret = -1; + if (tree_for_each(clock_tree, fill_clock_cb, NULL)) + return -1; + dir = opendir(clkpath); if (!dir) return -1; @@ -564,6 +587,65 @@ void read_and_dump_clock_info_one(char *clk, bool dump) printf("\n\n"); } +static inline const char *clock_rate(int *rate) +{ + int r; + + /* GHZ */ + r = *rate >> 30; + if (r) { + *rate = r; + return "GHZ"; + } + + /* MHZ */ + r = *rate >> 20; + if (r) { + *rate = r; + return "MHZ"; + } + + /* KHZ */ + r = *rate >> 10; + if (r) { + *rate = r; + return "KHZ"; + } + + return ""; +} + +static int dump_clock_cb(struct tree *t, void *data) +{ + struct clock_info *clk = t->private; + struct clock_info *pclk; + const char *unit; + int ret = 0; + int rate = clk->rate; + + if (!t->parent) { + printf("/\n"); + clk->prefix = ""; + return 0; + } + + pclk = t->parent->private; + + if (!clk->prefix) + ret = asprintf(&clk->prefix, "%s%s%s", pclk->prefix, + t->depth > 1 ? " ": "", t->next ? "|" : " "); + if (ret < 0) + return -1; + + unit = clock_rate(&rate); + + printf("%s%s-- %s (flags:0x%x, usecount:%d, rate: %d %s)\n", + clk->prefix, !t->next ? "`" : "", t->name, clk->flags, + clk->usecount, rate, unit); + + return 0; +} + void dump_clock_info(struct clock_info *clk, int level, int bmp) { int i, j;