Example #1
0
File: hpux9.c Project: rra/lbcd
/*
 * Get the system uptime and return it in the boottime parameter.  Returns 0
 * on success and -1 on failure.
 */
int
kernel_getboottime(time_t *boottime)
{
    struct timeval boot;

    if (!kernel_init)
        kernel_open();
    if (nl[1].n_type == 0)
        return -1;
    kernel_read(nl[1].n_value, (void *) &boot, sizeof(boot));
    *boottime = boot.tv_sec;
    return 0;
}
Example #2
0
File: hpux9.c Project: rra/lbcd
/*
 * Get the current load average from the kernel and return the one minute,
 * five minute, and fifteen minute averages in the given parameters.  Returns
 * 0 on success and -1 on failure.
 */
int
kernel_getload(double *l1, double *l5, double *l15)
{
    double load[3];

    if (!kernel_init)
        kernel_open();
    if (nl[0].n_type == 0)
        return -1;
    kernel_read(nl[0].n_value, (void *) load, sizeof(load));
    *l1  = kern_avenrun[0];
    *l5  = kern_avenrun[1];
    *l15 = kern_avenrun[2];
    return 0;
}
Example #3
0
File: irix.c Project: rra/lbcd
/*
 * Get the current load average from the kernel and return the one minute,
 * five minute, and fifteen minute averages in the given parameters.  Returns
 * 0 on success and -1 on failure.
 */
int
kernel_getload(double *load1, double *load5, double *load15)
{
    int status, load[3];
    static long offset = -1;

    if (!kernel_init)
        kernel_open();
    if (lseek(kmem_fd, offset, 0) < 0)
        sysdie("cannot lseek in /dev/kmem");
    status = read(kmem_fd, (void *) load, sizeof(load));
    if (status != sizeof(load))
        sysdie("kernel read failed");
    *load1  = (double) load[0] / 1000.0;
    *load5  = (double) load[1] / 1000.0;
    *load15 = (double) load[2] / 1000.0;
    return 0;
}
Example #4
0
/* Init task - the job of this task is to initialise all
 * installed drivers, mount the root filesystem and
 * bootstrap the system */
int init_task(void *priv)
{
	uint32_t ret;
	struct file *file;
	char buf[20];
	int rval;

	/* Initialise kernel subsystems */
	blk_init();
	vfs_init();
	pci_init();

	do_initcalls();

	/* Mount the root filesystem etc.. */
	if ( vfs_mount_root("ext2", "floppy0") ) {
		panic("Unable to mount root filesystem\n");
	}

	file = kernel_open("/test.txt", 0);
	if ( NULL == file ) {
		printk("init_task: open failed, returned %u\n", -1);
	} else {
		rval = kernel_read(file, buf, 16);
		if ( rval < 0 )
			printk("read error: %d\n", rval);
		else if ( rval == 0 )
			printk("read returned EOF\n");
		else {
			buf[rval] = '\0';
			printk("read: %s.\n", buf);
		}
		rval = kernel_write(file, buf, 16);
		kernel_close(file);
	}

	ret = _kernel_exec("/bin/bash");
	ret = _kernel_exec("/sbin/init");
	ret = _kernel_exec("/bin/cat");
	printk("exec: /sbin/init: %i\n", (int)ret);

	return ret;
}
Example #5
0
File: proc.c Project: yonatana/OS
void swapIn(struct proc* p){
//   cprintf("swapIN\n");
  //create flie
  char id_as_str[3]; // need to pre determine number of digits in p->pid
  itoa(p->pid,id_as_str);
  char path[strlen(id_as_str) + 5];
  path[6] = '\0';
//   path[0] = '/';
  strcat(path,0,id_as_str,".swap");
  //cprintf("swapIn - passed strcat path: %s\n",path);
  release(&ptable.lock);
  int test;
  p->swapped_file = kernel_open(path,O_RDONLY);
//   p->swapped_file = p->ofile[p->swapped_file_fd];
//   cprintf("swapIn - passed open pid %d p->sz %d\n",p->pid,p->sz);
  p->pgdir = setupkvm();
  test = allocuvm(p->pgdir,0,p->sz); //changed from KERNBASE
//   cprintf("swapIn - passed allocuvm pid %d returned %d\n",p->pid,test);
//   cprintf("swapFile ip: %d\n",p->swapped_file->ip->size);
  test = loaduvm(p->pgdir,0,p->swapped_file->ip,0,p->sz);
//   cprintf("swapIn - passed loaduvm pid %d returned %d\n",p->pid,test);
  test++;
  int fd;
  for(fd = 0; fd < NOFILE; fd++){
    if(p->ofile[fd] && p->ofile[fd] == p->swapped_file){
     fileclose(p->ofile[fd]);
     p->ofile[fd] = 0;
     break;
    }
  }
  p->swapped_file = 0;
//   cprintf("swapIn - passed fileclose pid %d\n",p->pid);
  test = kernel_unlink(path);
  //test++;
//   cprintf("swapIn - passed kernel_unlink pid %d returned %d\n",p->pid,test);
  acquire(&ptable.lock);
}
Example #6
0
File: proc.c Project: yonatana/OS
void swapOut(struct proc* p){
  //create flie
  char id_as_str[3]; // need to pre determine number of digits in p->pid
  itoa(p->pid,id_as_str);
  char path[strlen(id_as_str) + 5];
  strcat(path,0,id_as_str,".swap");
  p->swapped_file = kernel_open(path,O_CREATE | O_WRONLY);
  
  pte_t *pte;
  int i;
  uint pa;
  for(i = 0; i < p->sz; i += PGSIZE){
    if((pte = walkpgdir(p->pgdir, (void *) i, 0)) == 0)
      panic("copyuvm: pte should exist");
    if(!(*pte & PTE_P))
      panic("copyuvm: page not present");
    pa = PTE_ADDR(*pte);
    //cprintf("p->swapped_file %d\n",p->swapped_file);
    if(filewrite(p->swapped_file,p2v(pa),PGSIZE) < 0)
      panic("filewrite: error in swapOut");
  }
      
  int fd;
  for(fd = 0; fd < NOFILE; fd++){
    if(p->ofile[fd] && p->ofile[fd] == p->swapped_file){
     fileclose(p->ofile[fd]);
     p->ofile[fd] = 0;
     break;
    }
  }
  p->swapped_file = 0;
  p->swapped = 1;
  
  deallocuvm(p->pgdir,p->sz,0);
  p->state = SLEEPING_SUSPENDED;
  
}