2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; only version 2
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 * Return cpu cycle counter
29 cycles_t
get_cycles(void)
31 return caa_get_cycles();
35 * Calculate CPU frequency.
37 uint64_t get_cpu_freq(void)
40 struct timeval tvstart
, tvstop
;
41 cycles_t c_before
, c_after
;
42 unsigned long microseconds
;
44 memset(&tz
, 0, sizeof(tz
));
46 gettimeofday(&tvstart
, &tz
);
47 c_before
= get_cycles();
48 gettimeofday(&tvstart
, &tz
);
52 gettimeofday(&tvstop
, &tz
);
53 c_after
= get_cycles();
54 gettimeofday(&tvstop
, &tz
);
56 microseconds
= ((tvstop
.tv_sec
- tvstart
.tv_sec
) * 1000000) +
57 (tvstop
.tv_usec
- tvstart
.tv_usec
);
59 return (uint64_t) ((c_after
- c_before
) / microseconds
);
This page took 0.033284 seconds and 4 git commands to generate.