[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [MiNT] How to get CPU time?
Hi!
It should be like on Linux. If not it's a bug or it's missing. The idea 
was to simplify porting of Linux apps that use /proc. You just need to 
replace /proc with /kern (as already mentioned we couldn't use /proc as 
this was already in use under FreeMiNT; otherwise we had for sure 
choosen /proc :-)).
Ok, but something is strange, maybe a MiNT's bug.. look at my code:
------------------------
int16 get_cpu_usage( void)
{
    static int32 pre_used = 0, pre_total = 0;
    int16 usage = 0, factor = 100;
    int32 cpu, nice, system, idle, used = 0, total = 0;
    FILE *fp;
    if ( !( fp = fopen("U:/kern/stat", "r")))
        return usage;
    fscanf( fp, "%*s %ld %ld %ld %ld", &cpu, &nice, &system, &idle);
    fclose(fp);
    used  = cpu + system + nice;
    total = used + idle;
    /* calc CPU usage */
    if( total - pre_total > 0)
    usage = ( int16)(( factor * ( double)( used - pre_used)) / 
(double)( total - pre_total));
    if( usage < 0)
        usage = 0;
    pre_used = used;
    pre_total = total;
    return usage;
}
-----------------------
It works on linux ( of course with /proc/stat) but on MiNT, I must set 
the 'factor' variable at 20 to have the good CPU load in percent. ( ??)
It seems that the idle's value is 5 times superior that it should be.
Nevertheless, it works like a charm, thanks again for your help !
We also have some FreMiNT specific extension like the cookijar list, 
sysdir and such things. Ideas and improvements welcome.
Well, the real lacks aren't in MiNT itself but in the Mintlib.
I dream at a shareable mintlib because actually, deal with threads or 
externals libraries like SLB or LDG using libc functions is impossible :/
But that's another story...
2) This data are updated every second or faster( every 'clock tick')?
The data are updated if you read it :-)
Ask and MiNT gives :)
MiNT is really a "strange" Unix system.. some stuffs are like in Linux 
and others like in BSD :)
Don't know what you mean. BSD and Linux are both Unix systems. 
I mean that, for example, MiNT is a monolithic kernel with external 
extentions like linux but it's provide a BSD socket, etc etc..
It's a "mix" of Linux and BSD.
Ciao,
Zorro