[ltp] Running without a battery?
Daniel Kraus
linux-thinkpad@linux-thinkpad.org
Wed, 14 Jan 2004 16:33:43 +0100
--AqsLC8rIMeq19msA
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
mukesh agrawal wrote:
> On Wed, 14 Jan 2004, Dr. Jason Breitweg wrote:
>
> > Yeah, that would be really cool if you could check that out. How does
> > one tell if the CPU is running at a lower speed?
> Any program that just executes a CPU loop would work. bogomips is one such
> program, that might already be installed.
>
> If not, something like the following should do the trick:
>
> --- spin.c ---
>
> main() {
> int i = 1E6;
>
> while (i) --i;
> }
> --------------
Use the attached programm to get you current cpu speed.
Cheers,
Daniel
--AqsLC8rIMeq19msA
Content-Type: text/x-csrc; charset=us-ascii
Content-Disposition: attachment; filename="cpui.c"
#include <stdio.h>
#include <sys/time.h>
__inline__ unsigned long long int rdtsc()
{
unsigned long long int x;
__asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
return x;
}
main ()
{
struct timezone tz;
struct timeval tvstart, tvstop;
unsigned long long int cycles[2]; /* gotta be 64 bit */
unsigned int microseconds; /* total time taken */
bzero(&tz, sizeof(tz));
/* get this function in cached memory */
gettimeofday(&tvstart, &tz);
cycles[0] = rdtsc();
gettimeofday(&tvstart, &tz);
/* we don't trust that this is any specific length of time */
sleep(1);
cycles[1] = rdtsc();
gettimeofday(&tvstop, &tz);
microseconds = ((tvstop.tv_sec-tvstart.tv_sec)*1000000) +
(tvstop.tv_usec-tvstart.tv_usec);
printf("%f MHz processor.\n",
(float)(cycles[1]-cycles[0])/microseconds);
}
--AqsLC8rIMeq19msA--