64-bit time for Linux 2.5.xx

This commit is contained in:
albert
2002-05-28 04:18:55 +00:00
parent ea1d89ec4f
commit bce2da1f9a
8 changed files with 93 additions and 100 deletions

View File

@@ -164,9 +164,11 @@ static void stat2proc(char* S, proc_t* P) {
num = sscanf(tmp + 2, /* skip space after ')' too */
"%c "
"%d %d %d %d %d "
"%lu %lu %lu %lu %lu %lu %lu "
"%ld %ld %ld %ld %ld %ld "
"%lu %lu "
"%lu %lu %lu %lu %lu "
"%Lu %Lu %Lu %Lu " /* utime stime cutime cstime */
"%ld %ld %ld %ld "
"%Lu " /* start_time */
"%lu "
"%ld "
"%lu %lu %lu %lu %lu %lu "
"%*s %*s %*s %*s " /* discard, no RT signals & Linux 2.1 used hex */
@@ -174,9 +176,11 @@ static void stat2proc(char* S, proc_t* P) {
"%d %d",
&P->state,
&P->ppid, &P->pgrp, &P->session, &P->tty, &P->tpgid,
&P->flags, &P->min_flt, &P->cmin_flt, &P->maj_flt, &P->cmaj_flt, &P->utime, &P->stime,
&P->cutime, &P->cstime, &P->priority, &P->nice, &P->timeout, &P->it_real_value,
&P->start_time, &P->vsize,
&P->flags, &P->min_flt, &P->cmin_flt, &P->maj_flt, &P->cmaj_flt,
&P->utime, &P->stime, &P->cutime, &P->cstime,
&P->priority, &P->nice, &P->timeout, &P->it_real_value,
&P->start_time,
&P->vsize,
&P->rss,
&P->rss_rlim, &P->start_code, &P->end_code, &P->start_stack, &P->kstk_esp, &P->kstk_eip,
/* P->signal, P->blocked, P->sigignore, P->sigcatch, */ /* can't use */

View File

@@ -44,9 +44,13 @@ typedef struct proc_s {
sigignore, /* mask of ignored signals */
sigcatch; /* mask of caught signals */
#endif
long
unsigned long long
cutime, /* cumulative utime of process and reaped children */
cstime, /* cumulative stime of process and reaped children */
utime, /* user-mode CPU time accumulated by process */
stime, /* kernel-mode CPU time accumulated by process */
start_time; /* start time of process -- seconds since 1-1-70 */
long
priority, /* kernel scheduling priority */
timeout, /* ? */
nice, /* standard unix nice level of process */
@@ -78,14 +82,11 @@ typedef struct proc_s {
cmaj_flt, /* cumulative maj_flt of process and child processes */
nswap, /* ? */
cnswap, /* cumulative nswap ? */
utime, /* user-mode CPU time accumulated by process */
stime, /* kernel-mode CPU time accumulated by process */
start_code, /* address of beginning of code segment */
end_code, /* address of end of code segment */
start_stack, /* address of the bottom of stack for the process */
kstk_esp, /* kernel stack pointer */
kstk_eip, /* kernel instruction pointer */
start_time, /* start time of process -- seconds since 1-1-70 */
wchan; /* address of kernel wait channel proc is sleeping in */
struct proc_s *l, /* ptrs for building arbitrary linked structs */
*r; /* (i.e. singly/doubly-linked lists and trees */

View File

@@ -115,12 +115,12 @@ int uptime(double *uptime_secs, double *idle_secs) {
* used with a kernel that doesn't support the ELF note. On some other
* architectures there may be a system call or sysctl() that will work.
*/
unsigned long Hertz;
unsigned long long Hertz;
static void init_Hertz_value(void) __attribute__((constructor));
static void init_Hertz_value(void){
unsigned long user_j, nice_j, sys_j, other_j; /* jiffies (clock ticks) */
unsigned long long user_j, nice_j, sys_j, other_j; /* jiffies (clock ticks) */
double up_1, up_2, seconds;
unsigned long jiffies, h;
unsigned long long jiffies, h;
char *savelocale;
smp_num_cpus = sysconf(_SC_NPROCESSORS_CONF);
@@ -134,11 +134,11 @@ static void init_Hertz_value(void){
sscanf(buf, "cpu %lu %lu %lu %lu", &user_j, &nice_j, &sys_j, &other_j);
FILE_TO_BUF(UPTIME_FILE,uptime_fd); sscanf(buf, "%lf", &up_2);
/* uptime(&up_2, NULL); */
} while((long)( (up_2-up_1)*1000.0/up_1 )); /* want under 0.1% error */
} while((long long)( (up_2-up_1)*1000.0/up_1 )); /* want under 0.1% error */
setlocale(LC_NUMERIC, savelocale);
jiffies = user_j + nice_j + sys_j + other_j;
seconds = (up_1 + up_2) / 2;
h = (unsigned long)( (double)jiffies/seconds/smp_num_cpus );
h = (unsigned long long)( (double)jiffies/seconds/smp_num_cpus );
/* actual values used by 2.4 kernels: 32 64 100 128 1000 1024 1200 */
switch(h){
case 9 ... 11 : Hertz = 10; break; /* S/390 (sometimes) */
@@ -158,7 +158,7 @@ static void init_Hertz_value(void){
case 1180 ... 1220 : Hertz = 1200; break; /* Alpha */
default:
#ifdef HZ
Hertz = (unsigned long)HZ; /* <asm/param.h> */
Hertz = (unsigned long long)HZ; /* <asm/param.h> */
#else
/* If 32-bit or big-endian (not Alpha or ia64), assume HZ is 100. */
Hertz = (sizeof(long)==sizeof(int) || htons(999)==999) ? 100UL : 1024UL;
@@ -176,7 +176,7 @@ static void init_Hertz_value(void){
#ifndef NAN
#define NAN (-0.0)
#endif
#define JT unsigned long
#define JT unsigned long long
void four_cpu_numbers(double *uret, double *nret, double *sret, double *iret){
double tmp_u, tmp_n, tmp_s, tmp_i;
double scale; /* scale values to % */

View File

@@ -1,7 +1,7 @@
#ifndef SYSINFO_H
#define SYSINFO_H
extern unsigned long Hertz; /* clock tick frequency */
extern unsigned long long Hertz; /* clock tick frequency */
extern long smp_num_cpus; /* number of CPUs */
#define JT double