Anybody, could You plz help me.
Which mechanism in QNX6 to learn
(to know) which is cpuload at current
mement.
Thanks!
vasilii mailto:vasilii@cambira.com
Anybody, could You plz help me.
Which mechanism in QNX6 to learn
(to know) which is cpuload at current
mement.
Thanks!
vasilii mailto:vasilii@cambira.com
At the current moment, the CPU is running. That is if there is a program
trying to query its state, it’s running. (Sorry. I know I’m being a
wiseass.)
What I think you want is the CPU usage over a brief period, like 70% in use
over the last second. That can be done. You need to iterate through all
threads and query their CPU usage. Then iterate through them again, query
their usage again, subtract and divide. I have not done this but it has
been documented here in this newsgroup.
“vasilii” <vv40in@rambler.ru> wrote in message
news:a9m8rf$ngq$1@inn.qnx.com…
Anybody, could You plz help me.
Which mechanism in QNX6 to learn
(to know) which is cpuload at current
mement.Thanks!
vasilii mailto:> vasilii@cambira.com
“Bill Caroselli (Q-TPS)” <QTPS@earthlink.net> wrote:
At the current moment, the CPU is running. That is if there is a program
trying to query its state, it’s running. (Sorry. I know I’m being a
wiseass.)What I think you want is the CPU usage over a brief period, like 70% in use
over the last second. That can be done. You need to iterate through all
threads and query their CPU usage. Then iterate through them again, query
their usage again, subtract and divide. I have not done this but it has
been documented here in this newsgroup.
Actually Bill, you only need to query one thread. The idle thread only runs
when there is nothing else running so if you are only interested in overall
system load then it is the only thing you need to inspect…
http://qnx.wox.org/qnx/sources/load-src.tar.gz
…has the source to a simple CPU load monitor.
Chris McKillop <cdm@qnx.com> “The faster I go, the behinder I get.”
Software Engineer, QSSL – Lewis Carroll –
http://qnx.wox.org/
What about using hogs? Works for me. Type “use hogs” from the command
line.
–
Randy Aeberhardt
<raeberhardt@tantalus-systems.com>
<www.tantalus-systems.com>
“Chris McKillop” <cdm@qnx.com> wrote in message
news:a9n7kh$ohm$3@nntp.qnx.com…
“Bill Caroselli (Q-TPS)” <> QTPS@earthlink.net> > wrote:
At the current moment, the CPU is running. That is if there is a
program
trying to query its state, it’s running. (Sorry. I know I’m being a
wiseass.)What I think you want is the CPU usage over a brief period, like 70% in
use
over the last second. That can be done. You need to iterate through
all
threads and query their CPU usage. Then iterate through them again,
query
their usage again, subtract and divide. I have not done this but it has
been documented here in this newsgroup.
Actually Bill, you only need to query one thread. The idle thread only
runs
when there is nothing else running so if you are only interested in
overall
system load then it is the only thing you need to inspect…http://qnx.wox.org/qnx/sources/load-src.tar.gz
…has the source to a simple CPU load monitor.
chris
\Chris McKillop <> cdm@qnx.com> > “The faster I go, the behinder I get.”
Software Engineer, QSSL – Lewis Carroll –
http://qnx.wox.org/
Hey Vasilii,
Here is a simple application that calculates and prints cpu loading. It has
a few limitations, but it is pretty precise too ( at least for me .
Take a look…
-Misha.
— cpuload.c —
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sched.h>
#include <pthread.h>
#include <sys/syspage.h>
#include <sys/neutrino.h>
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
volatile static long long counter;
/*************************************************************** USE_CPU2()
***/
int
use_cpu2( int i )
{
return i+1;
}
/**************************************************************** USE_CPU()
***/
void
use_cpu( long long n )
{
static int cnt;
for( counter = 0; counter < n; counter ++ ) {
for( cnt = 0; cnt < 100; ) {
cnt = use_cpu2( cnt );
}
}
return;
}
/********************************************************* CPULOAD_THREAD()
***/
static void *
cpuload_thread( void *data )
{
pthread_mutex_lock( &mutex );
use_cpu( LLONG_MAX );
return 0;
}
/******************************************************************* MAIN()
***/
int
main( int argc, char *argv[] )
{
pthread_t tid;
long long cycles, initial_limit = 1000, counter_val;
struct sched_param param;
double loading = 0, old_loading = -1;
int policy = SCHED_FIFO, prio = 30, delay_msec = 1000;
double sec, cycles_per_sec;
{
int c, err = 0;
while( -1 != ( c = getopt( argc, argv, “d:” )) ) {
switch( c ) {
case ‘d’:
delay_msec = atoi( optarg );
break;
default:
err++;
}
}
if( err )
return 1;
}
sched_getparam( 0, ¶m );
param.sched_priority = prio;
sched_setscheduler( 0, policy, ¶m );
/* Let it “cool” down */
delay(500);
cycles = ClockCycles();
use_cpu( initial_limit );
/* Get number of cycles per use_cpu cycle */
cycles = (ClockCycles() - cycles) / initial_limit;
/* Total number of use_cpu() cycles per second */
cycles_per_sec = (SYSPAGE_ENTRY( qtime )->cycles_per_sec/cycles);
pthread_mutex_lock( &mutex );
/* Create calculating thread */
if( 0 != pthread_create( &tid, NULL, &cpuload_thread, 0 ) ) {
perror( “pthread_create()” );
return 1;
}
/* We are going to run the calculating thread on priority 1 */
param.sched_priority = 1;
pthread_setschedparam( tid, SCHED_FIFO, ¶m );
printf( “\nNOTE: \n”
" This cpu loading monitor won’t provide proper results\n"
" if there are applications running on priority 1.\n\n" );
printf( “Average loading (%d msec intervals):\n”, delay_msec );
/* “hit” calculating thread */
pthread_mutex_unlock( &mutex );
for(; {
cycles = ClockCycles();
counter = 0;
delay( delay_msec );
cycles = (ClockCycles() - cycles);
counter_val = counter;
sec = cycles/(double)(SYSPAGE_ENTRY( qtime )->cycles_per_sec);
if( sec )
loading = 100.0 - min( 100.0,
(double)counter_val/(cycles_per_sec*sec)*100);
if( old_loading != loading ) {
old_loading = loading;
printf( “%6.2f%%\r”, loading );
fflush( stdout );
}
}
return 0;
}
— cpuload.c end —
“vasilii” <vv40in@rambler.ru> wrote in message
news:a9m8rf$ngq$1@inn.qnx.com…
Anybody, could You plz help me.
Which mechanism in QNX6 to learn
(to know) which is cpuload at current
mement.Thanks!
vasilii mailto:> vasilii@cambira.com