Remove some usage of 64bit functions (minix/u64.h)
. Removed the usage of 64 bit functions in top.c. Compiles successfully. . Scaling 64 bit values to 32 bit is removed. . Retain make64 instead of using | with shift. . Add order cycling display
This commit is contained in:
parent
2e26c872c4
commit
8de781761f
6 changed files with 54 additions and 73 deletions
|
@ -18,7 +18,6 @@
|
|||
#include <minix/config.h>
|
||||
#include <minix/const.h>
|
||||
#include <minix/partition.h>
|
||||
#include <minix/u64.h>
|
||||
#include <machine/partition.h>
|
||||
#include <termios.h>
|
||||
#include <stdarg.h>
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#include <sys/stat.h>
|
||||
#include <machine/partition.h>
|
||||
#include <minix/partition.h>
|
||||
#include <minix/u64.h>
|
||||
#include <sys/ioc_disk.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
@ -48,6 +47,6 @@ char *device;
|
|||
exit(1);
|
||||
}
|
||||
close(fd);
|
||||
d = div64u(entry.size, 512);
|
||||
d = entry.size / 512;
|
||||
return d;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/ioc_disk.h>
|
||||
#include <minix/partition.h>
|
||||
#include <minix/u64.h>
|
||||
#include <time.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
@ -84,7 +83,7 @@ char *argv[];
|
|||
{
|
||||
struct partition entry;
|
||||
int fd, s, i, badprinted;
|
||||
long b = 0, nblocks;
|
||||
u64_t b = 0, nblocks;
|
||||
char *p;
|
||||
time_t starttime;
|
||||
|
||||
|
@ -118,13 +117,13 @@ char *argv[];
|
|||
perror("ioctl DIOCGETP");
|
||||
return 1;
|
||||
}
|
||||
nblocks = div64u(entry.size, BLOCK_SIZE);
|
||||
nblocks = entry.size / BLOCK_SIZE;
|
||||
|
||||
time(&starttime);
|
||||
/* Read the entire file. Try it in large chunks, but if an error
|
||||
* occurs, go to single reads for a while. */
|
||||
while (1) {
|
||||
if(lseek64(fd, mul64u(BLOCK_SIZE, b), SEEK_SET, NULL) < 0) {
|
||||
if(lseek64(fd, (BLOCK_SIZE * b), SEEK_SET, NULL) < 0) {
|
||||
perror("lseek64");
|
||||
return 1;
|
||||
}
|
||||
|
@ -162,7 +161,7 @@ char *argv[];
|
|||
output(b);
|
||||
fprintf(stderr, "\n");
|
||||
} else fprintf(stderr, "\r%*s\n", -WIDTH, "Done scanning.");
|
||||
if (total) printf("%8ld\n", b);
|
||||
if (total) printf("%8lld\n", b);
|
||||
if ((errors == 0) || total) exit(0);
|
||||
badprinted = 0;
|
||||
if (normal) printf("Summary of bad blocks\n");
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include <minix/config.h>
|
||||
#include <minix/const.h>
|
||||
#include <minix/partition.h>
|
||||
#include <minix/u64.h>
|
||||
#include <machine/partition.h>
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
|
@ -249,8 +248,8 @@ int main(int argc, char **argv)
|
|||
if (diocntl(hdst.st_rdev, DGETP, &whole) < 0) fatal(dev_file);
|
||||
|
||||
/* Use sector numbers. */
|
||||
base = div64u(whole.base, SECTOR_SIZE);
|
||||
size = div64u(whole.size, SECTOR_SIZE);
|
||||
base = whole.base / SECTOR_SIZE;
|
||||
size = whole.size / SECTOR_SIZE;
|
||||
limit = base + size;
|
||||
|
||||
show_part(dev_file, base, size);
|
||||
|
@ -271,8 +270,8 @@ int main(int argc, char **argv)
|
|||
pe->size= part_limit - pe->lowsec;
|
||||
}
|
||||
|
||||
entry.base= mul64u(pe->lowsec, SECTOR_SIZE);
|
||||
entry.size= mul64u(pe->size, SECTOR_SIZE);
|
||||
entry.base= pe->lowsec * SECTOR_SIZE;
|
||||
entry.size= pe->size * SECTOR_SIZE;
|
||||
if (diocntl(makedev(hd_major, device), DSETP, &entry) < 0)
|
||||
fatal(dev_file);
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#include <minix/minlib.h>
|
||||
#include <minix/u64.h>
|
||||
// #include <minix/u64.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* -DNEW prints time to 0.01 sec. */
|
||||
|
@ -89,7 +89,7 @@ char *argv[];
|
|||
times(&pre_buf);
|
||||
} while (wait(&status) != pid);
|
||||
read_tsc_64(&end_tsc);
|
||||
spent_tsc = sub64(end_tsc, start_tsc);
|
||||
spent_tsc = end_tsc - start_tsc;
|
||||
#if _VMD_EXT
|
||||
(void) sysutime(UTIME_TIMEOFDAY, &end_time);
|
||||
real_time = (end_time.tv_sec - start_time.tv_sec) * CLOCKS_PER_SEC
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include <minix/procfs.h>
|
||||
|
||||
#define TIMECYCLEKEY 't'
|
||||
#define ORDERKEY 'o'
|
||||
|
||||
#define ORDER_CPU 0
|
||||
#define ORDER_MEMORY 1
|
||||
|
@ -169,7 +170,7 @@ void parse_file(pid_t pid)
|
|||
&cycles_hi, &cycles_lo) == 2) {
|
||||
p->p_cpucycles[i] = make64(cycles_lo, cycles_hi);
|
||||
} else {
|
||||
p->p_cpucycles[i] = make64(0, 0);
|
||||
p->p_cpucycles[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -294,7 +295,6 @@ struct tp {
|
|||
|
||||
int cmp_procs(const void *v1, const void *v2)
|
||||
{
|
||||
int c;
|
||||
struct tp *p1 = (struct tp *) v1, *p2 = (struct tp *) v2;
|
||||
int p1blocked, p2blocked;
|
||||
|
||||
|
@ -321,8 +321,9 @@ int cmp_procs(const void *v1, const void *v2)
|
|||
return -1;
|
||||
if(!p2blocked && p1blocked)
|
||||
return 1;
|
||||
} else if((c=cmp64(p1->ticks, p2->ticks)) != 0)
|
||||
return -c;
|
||||
} else if(p1->ticks != p2->ticks) {
|
||||
return (p2->ticks - p1->ticks);
|
||||
}
|
||||
|
||||
/* Process slot number is a tie breaker. */
|
||||
return (int) (p1->p - p2->p);
|
||||
|
@ -342,24 +343,14 @@ struct tp *lookup(endpoint_t who, struct tp *tptab, int np)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* since we don't have true div64(u64_t, u64_t) we scale the 64 bit counters to
|
||||
* 32. Since the samplig happens every ~1s and the counters count CPU cycles
|
||||
* during this period, unless we have extremely fast CPU, shifting the counters
|
||||
* by 12 make them 32bit counters which we can use for normal integer
|
||||
* arithmetics
|
||||
*/
|
||||
#define SCALE (1 << 12)
|
||||
|
||||
double ktotal = 0;
|
||||
|
||||
void print_proc(struct tp *tp, u32_t tcyc)
|
||||
void print_proc(struct tp *tp, u64_t total_ticks)
|
||||
{
|
||||
int euid = 0;
|
||||
static struct passwd *who = NULL;
|
||||
static int last_who = -1;
|
||||
char *name = "";
|
||||
unsigned long pcyc;
|
||||
int ticks;
|
||||
struct proc *pr = tp->p;
|
||||
|
||||
|
@ -385,9 +376,7 @@ void print_proc(struct tp *tp, u32_t tcyc)
|
|||
ticks = pr->p_user_time;
|
||||
printf(" %3u:%02u ", (ticks/system_hz/60), (ticks/system_hz)%60);
|
||||
|
||||
pcyc = div64u(tp->ticks, SCALE);
|
||||
|
||||
printf("%6.2f%% %s", 100.0*pcyc/tcyc, name);
|
||||
printf("%6.2f%% %s", 100.0 * tp->ticks / total_ticks, name);
|
||||
}
|
||||
|
||||
char *cputimemodename(int cputimemode)
|
||||
|
@ -412,32 +401,38 @@ char *cputimemodename(int cputimemode)
|
|||
u64_t cputicks(struct proc *p1, struct proc *p2, int timemode)
|
||||
{
|
||||
int i;
|
||||
u64_t t = make64(0, 0);
|
||||
u64_t t = 0;
|
||||
for(i = 0; i < CPUTIMENAMES; i++) {
|
||||
if(!CPUTIME(timemode, i))
|
||||
continue;
|
||||
if(p1->p_endpoint == p2->p_endpoint) {
|
||||
t = add64(t, sub64(p2->p_cpucycles[i],
|
||||
p1->p_cpucycles[i]));
|
||||
t = t + p2->p_cpucycles[i] - p1->p_cpucycles[i];
|
||||
} else {
|
||||
t = add64(t, p2->p_cpucycles[i]);
|
||||
t = t + p2->p_cpucycles[i];
|
||||
}
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
char *ordername(int orderno)
|
||||
{
|
||||
switch(orderno) {
|
||||
case ORDER_CPU: return "cpu";
|
||||
case ORDER_MEMORY: return "memory";
|
||||
}
|
||||
return "invalid order";
|
||||
}
|
||||
|
||||
void print_procs(int maxlines,
|
||||
struct proc *proc1, struct proc *proc2, int cputimemode)
|
||||
{
|
||||
int p, nprocs;
|
||||
u64_t idleticks = cvu64(0);
|
||||
u64_t kernelticks = cvu64(0);
|
||||
u64_t systemticks = cvu64(0);
|
||||
u64_t userticks = cvu64(0);
|
||||
u64_t total_ticks = cvu64(0);
|
||||
unsigned long tcyc;
|
||||
unsigned long tmp;
|
||||
u64_t idleticks = 0;
|
||||
u64_t kernelticks = 0;
|
||||
u64_t systemticks = 0;
|
||||
u64_t userticks = 0;
|
||||
u64_t total_ticks = 0;
|
||||
int blockedseen = 0;
|
||||
static struct tp *tick_procs = NULL;
|
||||
|
||||
|
@ -457,7 +452,7 @@ void print_procs(int maxlines,
|
|||
tick_procs[nprocs].p = proc2 + p;
|
||||
tick_procs[nprocs].ticks = cputicks(&proc1[p], &proc2[p], cputimemode);
|
||||
uticks = cputicks(&proc1[p], &proc2[p], 1);
|
||||
total_ticks = add64(total_ticks, uticks);
|
||||
total_ticks = total_ticks + uticks;
|
||||
if(p-NR_TASKS == IDLE) {
|
||||
idleticks = uticks;
|
||||
continue;
|
||||
|
@ -467,40 +462,30 @@ void print_procs(int maxlines,
|
|||
}
|
||||
if(!(proc2[p].p_flags & IS_TASK)) {
|
||||
if(proc2[p].p_flags & IS_SYSTEM)
|
||||
systemticks = add64(systemticks,
|
||||
tick_procs[nprocs].ticks);
|
||||
systemticks = systemticks + tick_procs[nprocs].ticks;
|
||||
else
|
||||
userticks = add64(userticks,
|
||||
tick_procs[nprocs].ticks);
|
||||
userticks = userticks + tick_procs[nprocs].ticks;
|
||||
}
|
||||
|
||||
nprocs++;
|
||||
}
|
||||
|
||||
if (!cmp64u(total_ticks, 0))
|
||||
if (total_ticks == 0)
|
||||
return;
|
||||
|
||||
qsort(tick_procs, nprocs, sizeof(tick_procs[0]), cmp_procs);
|
||||
|
||||
tcyc = div64u(total_ticks, SCALE);
|
||||
|
||||
tmp = div64u(userticks, SCALE);
|
||||
printf("CPU states: %6.2f%% user, ", 100.0*(tmp)/tcyc);
|
||||
|
||||
tmp = div64u(systemticks, SCALE);
|
||||
printf("%6.2f%% system, ", 100.0*tmp/tcyc);
|
||||
|
||||
tmp = div64u(kernelticks, SCALE);
|
||||
printf("%6.2f%% kernel, ", 100.0*tmp/tcyc);
|
||||
|
||||
tmp = div64u(idleticks, SCALE);
|
||||
printf("%6.2f%% idle", 100.0*tmp/tcyc);
|
||||
printf("CPU states: %6.2f%% user, ", 100.0 * userticks / total_ticks);
|
||||
printf("%6.2f%% system, ", 100.0 * systemticks / total_ticks);
|
||||
printf("%6.2f%% kernel, ", 100.0 * kernelticks/ total_ticks);
|
||||
printf("%6.2f%% idle", 100.0 * idleticks / total_ticks);
|
||||
|
||||
#define NEWLINE do { printf("\n"); if(--maxlines <= 0) { return; } } while(0)
|
||||
NEWLINE;
|
||||
|
||||
printf("CPU time displayed (press '%c' to cycle): %s",
|
||||
printf("CPU time displayed ('%c' to cycle): %s; ",
|
||||
TIMECYCLEKEY, cputimemodename(cputimemode));
|
||||
printf(" sort order ('%c' to cycle): %s", ORDERKEY, ordername(order));
|
||||
NEWLINE;
|
||||
|
||||
NEWLINE;
|
||||
|
@ -528,7 +513,7 @@ void print_procs(int maxlines,
|
|||
blockedseen = 1;
|
||||
}
|
||||
|
||||
print_proc(&tick_procs[p], tcyc);
|
||||
print_proc(&tick_procs[p], total_ticks);
|
||||
NEWLINE;
|
||||
|
||||
if(!blockedverbose)
|
||||
|
@ -552,7 +537,7 @@ void print_procs(int maxlines,
|
|||
tpdep = lookup(dep, tick_procs, nprocs);
|
||||
pr = tpdep->p;
|
||||
printf("%*s> ", level, "");
|
||||
print_proc(tpdep, tcyc);
|
||||
print_proc(tpdep, total_ticks);
|
||||
NEWLINE;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue