root/trunk/libffado/src/libutil/Time.c

Revision 445, 2.2 kB (checked in by pieterpalmers, 17 years ago)

* name change from FreeBoB to FFADO
* replaced tabs by 4 spaces
* got rid of end-of-line spaces
* made all license and copyrights conform

library becomes LGPL, apps become GPL
explicitly state LGPL v2.1 and GPL v2 (don't like v3 draft)

copyrights are 2005-2007 Daniel & Pieter
except for the MotU stuff (C) Jonathan, Pieter

Line 
1 /*
2     Copyright (C) 2005-2007 by Pieter Palmers
3
4     This file is part of FFADO
5     FFADO = Free Firewire (pro-)audio drivers for linux
6
7     FFADO is based upon FreeBoB.
8
9         Based upon JackTime.c from the jackdmp package.
10         Original Copyright:
11
12         Copyright (C) 2001-2003 Paul Davis
13         Copyright (C) 2004-2006 Grame
14
15         This program is free software; you can redistribute it and/or modify
16     it under the terms of the GNU General Public License as published by
17     the Free Software Foundation; either version 2 of the License, or
18     (at your option) any later version.
19
20     This program is distributed in the hope that it will be useful,
21     but WITHOUT ANY WARRANTY; without even the implied warranty of
22     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23     GNU General Public License for more details.
24
25     You should have received a copy of the GNU General Public License
26     along with this program; if not, write to the Free Software
27     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28
29 */
30
31 #include "Time.h"
32
33 #ifdef GETCYCLE_TIME
34
35 #include <stdio.h>
36 freebob_microsecs_t GetMhz(void)
37 {
38         FILE *f = fopen("/proc/cpuinfo", "r");
39         if (f == 0)
40         {
41                 perror("can't open /proc/cpuinfo\n");
42                 exit(1);
43         }
44
45         for ( ; ; )
46         {
47                 freebob_microsecs_t mhz;
48                 int ret;
49                 char buf[1000];
50
51                 if (fgets(buf, sizeof(buf), f) == NULL) {
52                         fprintf (stderr,"FATAL: cannot locate cpu MHz in "
53                                     "/proc/cpuinfo\n");
54                         exit(1);
55                 }
56
57 #if defined(__powerpc__)
58                 ret = sscanf(buf, "clock\t: %" SCNu64 "MHz", &mhz);
59 #elif defined( __i386__ ) || defined (__hppa__)  || defined (__ia64__) || \
60       defined(__x86_64__)
61                 ret = sscanf(buf, "cpu MHz         : %" SCNu64, &mhz);
62 #elif defined( __sparc__ )
63                 ret = sscanf(buf, "Cpu0Bogo        : %" SCNu64, &mhz);
64 #elif defined( __mc68000__ )
65                 ret = sscanf(buf, "Clocking:       %" SCNu64, &mhz);
66 #elif defined( __s390__  )
67                 ret = sscanf(buf, "bogomips per cpu: %" SCNu64, &mhz);
68 #else /* MIPS, ARM, alpha */
69                 ret = sscanf(buf, "BogoMIPS        : %" SCNu64, &mhz);
70 #endif
71                 if (ret == 1)
72                 {
73                         fclose(f);
74                         return (freebob_microsecs_t)mhz;
75                 }
76         }
77 }
78
79 freebob_microsecs_t __freebob_cpu_mhz;
80
81 void InitTime()
82 {
83         __freebob_cpu_mhz = GetMhz();
84 }
85
86 #else
87 void InitTime()
88 {}
89
90 #endif
91
Note: See TracBrowser for help on using the browser.