From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:58184) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QjxPB-0001r7-7s for qemu-devel@nongnu.org; Thu, 21 Jul 2011 13:51:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QjxPA-0000gt-89 for qemu-devel@nongnu.org; Thu, 21 Jul 2011 13:51:25 -0400 Received: from tx2ehsobe004.messaging.microsoft.com ([65.55.88.14]:29179 helo=TX2EHSOBE007.bigfish.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QjxPA-0000ga-2Q for qemu-devel@nongnu.org; Thu, 21 Jul 2011 13:51:24 -0400 Date: Thu, 21 Jul 2011 12:51:18 -0500 From: Scott Wood Message-ID: <20110721125118.4e64ec21@schlenkerla.am.freescale.net> In-Reply-To: <1311211654-14326-15-git-send-email-agraf@suse.de> References: <1311211654-14326-1-git-send-email-agraf@suse.de> <1311211654-14326-15-git-send-email-agraf@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 14/23] PPC: KVM: Add generic function to read host clockfreq List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alexander Graf Cc: QEMU-devel Developers On Thu, 21 Jul 2011 03:27:25 +0200 Alexander Graf wrote: > +/* Try to find a device tree node for a CPU with clock-frequency property */ > +static int kvmppc_find_cpu_dt(char *buf, int buf_len) > +{ > + struct dirent *dirp; > + DIR *dp; > + > + if ((dp = opendir(PROC_DEVTREE_CPU)) == NULL) { > + printf("Can't open directory " PROC_DEVTREE_CPU "\n"); > + return -1; > + } > + > + buf[0] = '\0'; > + while ((dirp = readdir(dp)) != NULL) { > + FILE *f; > + snprintf(buf, buf_len, "%s%s/clock-frequency", PROC_DEVTREE_CPU, > + dirp->d_name); > + f = fopen(buf, "r"); > + if (f) { > + snprintf(buf, buf_len, "%scpus/%s", PROC_DEVTREE_CPU, dirp->d_name); > + fclose(f); > + break; > + } > + buf[0] = '\0'; > + } > + closedir(dp); > + if (buf[0] == '\0') { > + printf("Unknown host!\n"); > + return -1; > + } "Unknown host!" is a little vague for an error message. > +uint32_t kvmppc_get_clockfreq(void) > +{ > + char buf[512]; > + uint32_t tb; > + FILE *f; > + int len; > + > + if (kvmppc_find_cpu_dt(buf, sizeof(buf))) { > + return 0; > + } > + > + snprintf(buf, sizeof(buf), "%s/clock-frequency", buf); > + > + f = fopen(buf, "rb"); > + if (!f) { > + return -1; > + } > + > + len = fread(&tb, sizeof(tb), 1, f); > + if (len != 1) { > + goto err; > + } > + > + return tb; > +err: > + fclose(f); > + return 0; > +} Need to convert endian from big to host. Also, the frequency can be 64-bit. -Scott