make getsysinfo() a system-land call
This commit is contained in:
@@ -20,7 +20,6 @@ SRCS+= \
|
||||
_getpprocnr.c \
|
||||
_getprocnr.c \
|
||||
_getsigset.c \
|
||||
_getsysinfo.c \
|
||||
_lseek64.c \
|
||||
_mapdriver.c \
|
||||
_mcontext.c \
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
|
||||
#include <lib.h>
|
||||
#include <unistd.h>
|
||||
#include <timers.h>
|
||||
#include <minix/endpoint.h>
|
||||
#define getsysinfo _getsysinfo
|
||||
#define getsysinfo_up _getsysinfo_up
|
||||
#include <minix/sysinfo.h>
|
||||
#include <minix/const.h>
|
||||
|
||||
#include <minix/ipc.h>
|
||||
#include <minix/com.h>
|
||||
#include <minix/sysinfo.h>
|
||||
#include <minix/config.h>
|
||||
#include <minix/type.h>
|
||||
#include <minix/const.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <machine/archtypes.h>
|
||||
#include "../../../kernel/proc.h"
|
||||
|
||||
PUBLIC int getsysinfo(who, what, where)
|
||||
endpoint_t who; /* from whom to request info */
|
||||
int what; /* what information is requested */
|
||||
void *where; /* where to put it */
|
||||
{
|
||||
message m;
|
||||
m.m1_i1 = what;
|
||||
m.m1_p1 = where;
|
||||
if (_syscall(who, GETSYSINFO, &m) < 0) return(-1);
|
||||
return(0);
|
||||
}
|
||||
|
||||
PUBLIC int minix_getkproctab(void *vpr, int nprocs, int assert)
|
||||
{
|
||||
int r, i, fail = 0;
|
||||
struct proc *pr = vpr;
|
||||
|
||||
if((r=getsysinfo(PM_PROC_NR, SI_KPROC_TAB, pr)) < 0)
|
||||
return r;
|
||||
|
||||
for(i = 0; i < nprocs; i++) {
|
||||
if(pr[i].p_magic != PMAGIC) {
|
||||
fail = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!fail)
|
||||
return 0;
|
||||
|
||||
if(assert) {
|
||||
fprintf(stderr, "%s: process table failed sanity check.\n", getprogname());
|
||||
fprintf(stderr, "is kernel out of sync?\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
errno = ENOSYS;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Unprivileged variant of getsysinfo. */
|
||||
PUBLIC ssize_t getsysinfo_up(who, what, size, where)
|
||||
endpoint_t who; /* from whom to request info */
|
||||
int what; /* what information is requested */
|
||||
size_t size; /* input and output size */
|
||||
void *where; /* where to put it */
|
||||
{
|
||||
message m;
|
||||
m.SIU_WHAT = what;
|
||||
m.SIU_WHERE = where;
|
||||
m.SIU_LEN = size;
|
||||
return _syscall(who, GETSYSINFO_UP, &m);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,6 @@ SRCS+= \
|
||||
getpprocnr.S \
|
||||
getprocnr.S \
|
||||
getsigset.S \
|
||||
getsysinfo.S \
|
||||
getuid.S \
|
||||
ioctl.S \
|
||||
isatty.S \
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
#include <machine/asm.h>
|
||||
|
||||
IMPORT(_getsysinfo)
|
||||
ENTRY(getsysinfo)
|
||||
jmp _C_LABEL(_getsysinfo)
|
||||
|
||||
IMPORT(_getsysinfo_up)
|
||||
ENTRY(getsysinfo_up)
|
||||
jmp _C_LABEL(_getsysinfo_up)
|
||||
|
||||
@@ -5,6 +5,7 @@ LIB= sys
|
||||
SRCS= \
|
||||
alloc_util.c \
|
||||
assert.c \
|
||||
getsysinfo.c \
|
||||
kernel_call.c \
|
||||
panic.c \
|
||||
pci_attr_r16.c \
|
||||
|
||||
@@ -6,21 +6,19 @@
|
||||
* getidle();
|
||||
* ...
|
||||
* idleperc = getidle();
|
||||
* printf("CPU usage: %lg%%\n", 100.0 - idleperc);
|
||||
* if (idleperc >= 0.0)
|
||||
* printf("CPU usage: %lg%%\n", 100.0 - idleperc);
|
||||
*
|
||||
* This routine goes through PM to get the idle time, rather than making the
|
||||
* sys_getinfo() call to the kernel directly. This means that it can be used
|
||||
* by non-system processes as well, but it will incur some extra overhead in
|
||||
* the system case. The overhead does not end up being measured, because the
|
||||
* system is clearly not idle while the system calls are being made. In any
|
||||
* case, for this reason, only one getidle() run is allowed at a time.
|
||||
* Notes:
|
||||
* - This functionality can only be used by system processes.
|
||||
* - The kernel has to be compiled with CONFIG_IDLE_TSC support.
|
||||
* - Only one getidle() run is allowed per process at a time.
|
||||
*
|
||||
* Note that the kernel has to be compiled with CONFIG_IDLE_TSC support.
|
||||
*/
|
||||
|
||||
#define _MINIX 1
|
||||
#define _SYSTEM 1
|
||||
#include <minix/sysinfo.h>
|
||||
#include <lib.h>
|
||||
#include <minix/u64.h>
|
||||
#include <minix/sysutil.h>
|
||||
|
||||
@@ -52,8 +50,7 @@ double getidle(void)
|
||||
int r;
|
||||
|
||||
if (!running) {
|
||||
r = getsysinfo_up(PM_PROC_NR, SIU_IDLETSC, sizeof(idle), &idle);
|
||||
if (r != sizeof(idle))
|
||||
if ((r = sys_getidletsc(&idle)) != OK)
|
||||
return -1.0;
|
||||
|
||||
running = 1;
|
||||
@@ -67,8 +64,7 @@ double getidle(void)
|
||||
|
||||
running = 0;
|
||||
|
||||
r = getsysinfo_up(PM_PROC_NR, SIU_IDLETSC, sizeof(idle2), &idle2);
|
||||
if (r != sizeof(idle2))
|
||||
if ((r = sys_getidletsc(&idle2)) != OK)
|
||||
return -1.0;
|
||||
|
||||
idelta = sub64(idle2, idle);
|
||||
|
||||
16
lib/libsys/getsysinfo.c
Normal file
16
lib/libsys/getsysinfo.c
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
#include <lib.h>
|
||||
#include <minix/sysinfo.h>
|
||||
#include <minix/com.h>
|
||||
|
||||
PUBLIC int getsysinfo(who, what, where)
|
||||
endpoint_t who; /* from whom to request info */
|
||||
int what; /* what information is requested */
|
||||
void *where; /* where to put it */
|
||||
{
|
||||
message m;
|
||||
m.SI_WHAT = what;
|
||||
m.SI_WHERE = where;
|
||||
if (_syscall(who, COMMON_GETSYSINFO, &m) < 0) return(-1);
|
||||
return(0);
|
||||
}
|
||||
@@ -11,7 +11,7 @@ pci_dev_name.c
|
||||
*===========================================================================*/
|
||||
PUBLIC char *pci_dev_name(u16_t vid, u16_t did)
|
||||
{
|
||||
static char name[PCIINFO_ENTRY_SIZE]; /* We need a better interface for this */
|
||||
static char name[80]; /* We need a better interface for this */
|
||||
|
||||
int r;
|
||||
cp_grant_id_t gid;
|
||||
|
||||
Reference in New Issue
Block a user