예제 #1
0
/*
 * call-seq:
 *   unbound_proc.bind(Binding) => Proc
 *
 * Bind an UnboundProc to a Binding.  Returns a Proc that has been bound
 * to the given binding.
 */
static VALUE unboundproc_bind(VALUE self, VALUE binding)
{
#ifdef RUBY_VM
  rb_proc_t * p;
  GetProcPtr(self, p);
  return create_proc(rb_cProc, binding, p->block.iseq);
#else
  struct BLOCK * b;
  Data_Get_Struct(self, struct BLOCK, b);
  /* create_proc will do a security check */
  return create_proc(rb_cProc, binding, b->body, b->var);
#endif
}
예제 #2
0
/*
 * call-seq:
 *   proc.unbind => UnboundProc
 *
 * Create an UnboundProc from a Proc.
 */
static VALUE proc_unbind(VALUE self)
{
#ifdef RUBY_VM
  rb_proc_t * p;
  GetProcPtr(self, p);
  return create_proc(rb_cUnboundProc, Qnil, p->block.iseq);
#else
  struct BLOCK * b;
  Data_Get_Struct(self, struct BLOCK, b);
  /* no need for a security check to unbind a proc -- though without the
   * ability to bind, this doesn't seem very useful.
   */
  return create_proc(rb_cUnboundProc, Qnil, b->body, b->var);
#endif
}
예제 #3
0
static int DIVA_INIT_FUNCTION divadidd_init(void)
{
	char tmprev[32];
	int ret = 0;

	printk(KERN_INFO "%s\n", DRIVERNAME);
	printk(KERN_INFO "%s: Rel:%s  Rev:", DRIVERLNAME, DRIVERRELEASE_DIDD);
	strcpy(tmprev, main_revision);
	printk("%s  Build:%s(%s)\n", getrev(tmprev),
	       diva_didd_common_code_build, DIVA_BUILD);

	if (!create_proc()) {
		printk(KERN_ERR "%s: could not create proc entry\n",
		       DRIVERLNAME);
		ret = -EIO;
		goto out;
	}

	if (!diddfunc_init()) {
		printk(KERN_ERR "%s: failed to connect to DIDD.\n",
		       DRIVERLNAME);
#ifdef MODULE
		remove_proc();
#endif
		ret = -EIO;
		goto out;
	}

      out:
	return (ret);
}
예제 #4
0
static bool create_service(file_tmpl& tmpl)
{
	printf("choose master_service type:\r\n");
	printf("	t: for master_threads\r\n"
		"	f: for master_fiber\r\n"
		"	p: for master_proc\r\n");
	printf(">");
	fflush(stdout);

	char  buf[256];
	int   n = acl_vstream_gets_nonl(ACL_VSTREAM_IN, buf, sizeof(buf));
	if (n == ACL_VSTREAM_EOF)
		return false;
	else if (strcasecmp(buf, "t") == 0)
		create_threads(tmpl);
	else if (strcasecmp(buf, "p") == 0)
		create_proc(tmpl);
	else if (strcasecmp(buf, "f") == 0)
		create_fiber(tmpl);
	else
	{
		printf("invalid: %s\r\n", buf);
		return false;
	}

	return true;
}
예제 #5
0
int
main (int ac, char *av[])
{
  SQLRETURN rc;

  if (ac < 3)
    {
      err_printf ("***FAILED: usage : %s dsn uid pwd\n", av[0]);
      return (-1);
    }
  dsn = av[1];
  uid = av[2];
  pwd = av[3];
  rc = SQLAllocHandle (SQL_HANDLE_ENV, SQL_NULL_HANDLE, (SQLHANDLE *) & henv);
  if (rc != SQL_SUCCESS)
    {
      err_printf ("SQLAllocHandle() failed.\n");
      return 1;
    }

  rc = SQLSetEnvAttr (henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3,
      SQL_IS_INTEGER);
  if (rc != SQL_SUCCESS)
    {
      err_printf ("SQLSetEnvAttr() failed.\n");
      return 1;
    }

  rc = SQLAllocHandle (SQL_HANDLE_DBC, (SQLHANDLE) henv,
      (SQLHANDLE *) & hdbc);
  if (rc != SQL_SUCCESS)
    {
      err_printf ("SQLAllocHandle() failed.\n");
      return 1;
    }

  rc = SQLConnect (hdbc, dsn, SQL_NTS, uid, SQL_NTS, pwd, SQL_NTS);
  if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO)
    {
      err_printf ("SQLConnect() failed.\n");
      error (SQL_HANDLE_DBC, (SQLHANDLE) hdbc);
      return 1;
    }
  rc = SQLSetConnectOption (hdbc, SQL_AUTOCOMMIT, 0);
  if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO)
    {
      err_printf ("autocommit off() failed.\n");
      error (SQL_HANDLE_DBC, (SQLHANDLE) hdbc);
      return 1;
    }

  create_proc ();

  printf ("=====================================================\n");
  printf ("starting test\n");
  test ();
  printf ("test1 done\n");
  printf ("=====================================================\n");
  return 0;
}
예제 #6
0
파일: proc.c 프로젝트: dxywx/puzzleOS
void proc_init() {
	kprintf("Initializing process manager...\n");
	procs_list = kmalloc(sizeof(list_t));
	idle_proc = create_proc((uint32)idle);
	strcpy(idle_proc->name, "sysidle");
	idle_proc->state = PS_IDLE;
	//current_proc = idle_proc;
	shedule();
}
예제 #7
0
int main(int argc, char **argv)
{
    if (argc == 1) {
        print("parent\n");
        create_proc(argv[0], "child");
        print("parent exiting\n");
    } else if (argc == 2 && strcmp(argv[1], "child") == 0) {
        print("child\n");
    }
}
예제 #8
0
/*
 * call-seq:
 *   Proc.load(str) => UnboundProc
 *
 * Load a Proc from a String.  When it is loaded, it will be an
 * UnboundProc, until it is bound to a Binding with UnboundProc#bind.
 */
static VALUE proc_load(VALUE klass, VALUE str)
{
#ifdef RUBY_VM
  VALUE iseq = marshal_load(str);
  return create_proc(rb_cUnboundProc, Qnil, iseq_check(iseq));
#else
  VALUE arr = marshal_load(str);
  NODE * body, * var;

  if(   rb_safe_level() >= 4
     || (rb_safe_level() >= 1 && OBJ_TAINTED(str)))
  {
    /* no playing with knives in the sandbox */
    rb_raise(rb_eSecurityError, "Insecure: can't load proc");
  }

  Check_Type(arr, T_ARRAY);
  body = unwrap_node(RARRAY_PTR(arr)[0]);
  var = unwrap_node(RARRAY_PTR(arr)[1]);
  return create_proc(rb_cUnboundProc, Qnil, body, var);
#endif
}
예제 #9
0
/*
 * If we haven't done so already, receive the modex info for the
 * specified opal_proc.  Search that proc's modex info; if we can find
 * matching address info, then create an endpoint.
 *
 * If we don't find a match, it's not an error: just return "not
 * found".
 *
 * This routine transfers ownership of an object reference to the caller, who
 * is eventually responsible for transferring or releasing that reference.
 *
 * There is a one-to-one correspondence between a opal_proc_t and a
 * opal_btl_usnic_proc_t instance.  We cache additional data on the
 * opal_btl_usnic_proc_t: specifically, the list of
 * opal_btl_usnic_endpoint_t instances, and published addresses/modex
 * info.
 */
int opal_btl_usnic_proc_match(opal_proc_t *opal_proc,
                              opal_btl_usnic_module_t *module,
                              opal_btl_usnic_proc_t **proc)
{
    /* Check if we have already created a proc structure for this peer
       ompi process */
    *proc = opal_btl_usnic_proc_lookup_ompi(opal_proc);
    if (*proc != NULL) {
        OBJ_RETAIN(*proc);
        return OPAL_SUCCESS;
    } else {
        /* If not, go make one */
        return create_proc(opal_proc, proc);
    }
}
예제 #10
0
파일: btl_usnic_proc.c 프로젝트: IanYXXL/A1
/*
 * If we haven't done so already, receive the modex info for the
 * specified ompi_proc.  Search that proc's modex info; if we can find
 * matching address info, then create an endpoint.
 *
 * If we don't find a match, it's not an error: just return "not
 * found".
 *
 * This routine transfers ownership of an object reference to the caller, who
 * is eventually responsible for transferring or releasing that reference.
 *
 * There is a one-to-one correspondence between a ompi_proc_t and a
 * ompi_btl_usnic_proc_t instance.  We cache additional data on the
 * ompi_btl_usnic_proc_t: specifically, the list of
 * ompi_btl_usnic_endpoint_t instances, and published addresses/modex
 * info.
 */
int ompi_btl_usnic_proc_match(ompi_proc_t *ompi_proc,
                              ompi_btl_usnic_module_t *module,
                              ompi_btl_usnic_proc_t **proc)
{
    /* Check if we have already created a proc structure for this peer
       ompi process */
    *proc = ompi_btl_usnic_proc_lookup_ompi(ompi_proc);
    if (*proc != NULL) {
        OBJ_RETAIN(*proc);
    } else {
        /* If not, go make one */
        *proc = create_proc(ompi_proc);
        if (NULL == *proc) {
            return OMPI_ERR_NOT_FOUND;
        }
    }
    return OMPI_SUCCESS;
}
예제 #11
0
SkGlobals::Rec* SkGlobals::Find(uint32_t tag, Rec* (*create_proc)())
{
    SkGlobals::BootStrap&   bootstrap = SkGlobals::GetBootStrap();

    Rec* rec = bootstrap.fHead;
    while (rec)
    {
        if (rec->fTag == tag)
            return rec;
        rec = rec->fNext;
    }

    if (create_proc == NULL) // no create proc, just return not found
        return NULL;

    // if we get here, we may need to create one. First grab the mutex, and
    // search again, creating one if its not found the 2nd time.

    bootstrap.fMutex.acquire();

    // search again, now that we have the mutex. Odds are it won't be there, but we check again
    // just in case it was added by another thread before we grabbed the mutex

    Rec*& head = bootstrap.fHead;
    rec = head;
    while (rec)
    {
        if (rec->fTag == tag)
            break;
        rec = rec->fNext;
    }

    if (rec == NULL && (rec = create_proc()) != NULL)
    {
        rec->fTag = tag;
        rec->fNext = head;
        bootstrap.fHead = rec;
    }

    bootstrap.fMutex.release();
    return rec;
}
예제 #12
0
void execute() {
    int time_elapse = 0;
    while (1) {
        time_elapse += 1;
        printf("now time: %d\n", time_elapse);
        if (current) {
            current->relative_deadline --;
            current->execute_time --;
            current->elapse_time ++;
            printf("proc: %d -- exe %d need %d relative_deadline %d\n", current->id, current->elapse_time, current->execute_time, current->relative_deadline);
            if (current->execute_time == 0) {
                printf("proc %d finish -- elapse_time is %d relative_deadline is %d\n", current->id, current->elapse_time, current->relative_deadline);
                current->id = -1;
                schedule();
                continue;
            }
            if (current->relative_deadline == 0) {
                printf("boom!!!!!!!!!!!! proc %d miss it deadline\n", current->id);
                break;
            }
        } else {
            printf("idle execute\n");
            schedule();
        }
        if (rand() % 3 == 0) {
            if (!create_proc()) {
                int i;
                bool found = false;
                for (i = 0; i < MAXPROC; ++i) {
                    if (procs[i].id != -1) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    printf("all proc has finished\n");
                    break;
                }
            }
        }
    }
}
예제 #13
0
/* This is the entry point to the bulk of the kernel.
 * @mb is a pointer to a <multiboot_info> structure which has important
 * information about the layout of memory which is passed along from the
 * bootloader.
 * First, the kernel sets up the <gdt> or Global Descriptor Table which
 * describes the layout of memory.
 * Next, it installs the <idt> or interrupt descriptor table, which declares
 * which interrupts are available, and whether they can be accessed from user
 * mode.
 * After the basic CPU state has been initialized, logging and the VGA terminal
 * are initialized, and the kernel heap is installed. Next, the physical memory
 * allocator and the keyboard drivers are initialized. Note that the kernel
 * heap must be initialized before the physical memory allocator since certain
 * parts of the allocator live on the heap. Finally the init process page table
 * is created, and multi-processing is initialized.
 * @return this function should never return.
*/
void kernel_main(struct multiboot_info *mb) {
    gdt_install();
    idt_install();
    terminal_initialize();
    initialize_klog();
    kheap_install((struct kheap_metadata*)KHEAP_PHYS_ROOT, PAGE_SIZE);
    physical_allocator_init(mb->mem_upper + mb->mem_lower);
    keyboard_install();
    char *hi = "Hello kernel!\n";
    void *testing = kmalloc(16);
    memcpy(testing, hi, 16);
    kputs(testing);
    klog(testing);
    kfree(testing);
    (void)kernel_page_table_install(mb);

    proc_init();
    struct process *worker_proc = create_proc(worker);
    schedule_proc(worker_proc);

    while (1) {
        klog("kernel\n");
    }
}
예제 #14
0
파일: connect.c 프로젝트: tbrand/MobileCUDA
void _CONNECT(int sd,proc_data* data){

  printf("CONNECT(%d) (QUEUESIZE   :%d)\n",sd,queue_size());
  printf("            (NUM OF PROCS:%d)\n",dem.procCounter);

  proc* p;
  int i;
  
  if(data->pos == -1){

    dem.procCounter++;
    
    p = create_proc(sd);
    
    add_proc(p);

    p->data = (proc_data*)malloc(sizeof(proc_data));
    memcpy(p->data,data,sizeof(proc_data));

    if(dem.procCounter > MAXPROC){
      
      if(!(p->data->flag&CANMIG)){

	dem.staying_procs ++;
	
	p->queued = STAYED_QUEUED;
	
      }else{

	p->queued = QUEUED;
	
      }

      return;

    }

  }else{

    p = get_proc(sd);
    memcpy(p->data,data,sizeof(proc_data));

  }

  printf("\tPID : %d\n",p->data->pid);

  size_t _mem;
  size_t _req;
  size_t _sym;
  nvmlReturn_t res;
  nvmlMemory_t mem;
  
  for(i = 0 ; i < dem.ndev ; i ++){
    
    if(!(p->data->flag&CANMIG))
      if(dem.flags[i].stayed)
	continue;

    _mem = p->data->mem;
    _req = p->data->req;
    _sym = p->data->sym;

    res = nvmlDeviceGetMemoryInfo(dem.devs[i],&mem);

#if 0
    printf("mem.free : %lu\n",mem.free);
    printf("reserved : %lu\n",dem.flags[i].reserved);
    printf("_mem     : %lu\n",_mem);
    printf("_req     : %lu\n",_req);
#endif

    if(p->data->pos == i){

      if(mem.free > _req + dem.flags[i].reserved + M64){

	printf("\tGOAHEAD(%d)\n",i);

	if(!(p->data->flag&CANMIG))
	  dem.flags[i].stayed = 1;
	
	dem.flags[i].reserved += _req;
	
	MSEND(sd,CONNECT,0,0,i,0,0);

	return ;
	
      }
      
    }else{
      
      if(mem.free > _mem + dem.flags[i].reserved + M64){
	
	printf("\tGOAHEAD(%d)*\n",i);
	
	if(!(p->data->flag&CANMIG))
	  dem.flags[i].stayed = 1;

	dem.flags[p->data->pos].reserved -= ( _mem - _req );
	dem.flags[i].reserved += _mem;

	p->data->pos = i;

	MSEND(sd,CONNECT,0,0,i,0,0);

	return ;
	
      }
    }
  }

  printf("\tOOPS\n");
  printf("mem.free : %lu\n",mem.free);
  printf("_req     : %lu\n",_req);

  if(!(p->data->flag&CANMIG)){

    dem.staying_procs ++;
    
    p->queued = STAYED_QUEUED;
    
    printf("Queued staying procs[%d]\n",dem.staying_procs);
    
  }else{

    p->queued = QUEUED;

    dem.flags[p->data->pos].reserved -= ( _mem -_req );
    
  }
}
예제 #15
0
/**
 * Call by the exeption to handle the syscall
 * \private
 */
void
syscall_handler(registers_t * regs)
{
  int32_t         res = 0;
  int32_t         syscall = regs->v_reg[0];     // code of the syscall

  switch (syscall)
  {
  case FOURCHETTE:
    res =
      create_proc(get_arg((char **) regs->a_reg[2], 0), regs->a_reg[0],
                  regs->a_reg[1], (char **) regs->a_reg[2]);
    break;
  case PRINT:
    res = print_string((char *) regs->a_reg[0]);
    return;                     /* We save the good return value in the pcb */
  case READ:
    res = read_string((char *) regs->a_reg[0], regs->a_reg[1]);
    return;                     /* We save the good return value in the pcb */
  case FPRINT:
    if (regs->a_reg[0] == CONSOLE)
      kprint((char *) regs->a_reg[1]);
    else
      kmaltaprint8((char *) regs->a_reg[1]);
    break;
  case SLEEP:
    res = go_to_sleep(regs->a_reg[0]);
    break;
  case BLOCK:
    res = kblock(regs->a_reg[0], BLOCKED);
    break;
  case UNBLOCK:
    kwakeup(regs->a_reg[0]);
    break;
  case WAIT:
    res = waitfor(regs->a_reg[0], (int32_t *) regs->a_reg[1]);
    break;
  case SEND:
    res =
      send_msg(pcb_get_pid(get_current_pcb()), (msg_arg *) regs->a_reg[0]);
    break;
  case RECV:
    res =
      recv_msg(pcb_get_pid(get_current_pcb()), (msg_arg *) regs->a_reg[0]);
    if (res == NOTFOUND)
      go_to_sleep(((msg_arg *) regs->a_reg[0])->timeout);
    break;
  case PERROR:
    kperror((char *) regs->a_reg[0]);
    break;
  case GERROR:
    res = kgerror();
    break;
  case SERROR:
    kserror(regs->a_reg[0]);
    break;
  case GETPINFO:
    res = get_pinfo(regs->a_reg[0], (pcbinfo *) regs->a_reg[1]);
    break;
  case GETPID:
    res = pcb_get_pid(get_current_pcb());
    break;
  case GETALLPID:
    res = get_all_pid((int *) regs->a_reg[0]);
    break;
  case CHGPPRI:
    res = chg_ppri(regs->a_reg[0], regs->a_reg[1]);
    break;
  case KILL:
    res = kkill(regs->a_reg[0]);
    break;
  case EXIT:
    kexit(regs->a_reg[0]);
    break;
  default:
    kprintln("ERROR: Unknown syscall");
    break;
  }

  // saves the return code
  regs->v_reg[0] = res;

  return;
}
예제 #16
0
int main(int argc,char* argv[]){

  /**Initialize signal**/

  signal(SIGINT ,_end_server);
  signal(SIGUSR1,_end_server);

  /**Initialize struct proc**/
  init_proc();

  /**Process becomes dem**/
  pid_t process_id = 0;
  pid_t sid = 0;

  if(argc >= 2){

    process_id = fork();

    if(process_id < 0){
      printf("fork failed ..\n");
      exit(1);
    }

    if(process_id > 0){
      exit(0);
    }

    umask(0);

    sid = setsid();

    if(sid < 0){
      exit(1);
    }

    close(STDIN_FILENO);
    close(STDOUT_FILENO);
    close(STDERR_FILENO);

  }else{
    sid = getpid();
  }

  /**Setup the log file**/

  char log[32];

  sprintf(log,"log.%u",sid);

  fp = fopen(log,"w+");

  //  printf("Start constructing deamon for Mobile CUDA processes\n");

  /**Start Initialize nvidia management library from Here!!**/

  nvmlReturn_t nres;
  int i;
  
  nres = nvmlInit();

  if(nres != NVML_SUCCESS){
    perror("Failed to initialize Nvidia Managerment Library...\n");
    exit(-1);
  }

  nres = nvmlDeviceGetCount(&dem.ndev);

  if(nres != NVML_SUCCESS){
    perror("Failed to get num of device...\n");
    exit(-1);
  }

  dem.devs = (nvmlDevice_t*)malloc(sizeof(nvmlDevice_t)*dem.ndev);
  dem.flags = (dflag*)malloc(sizeof(dflag)*dem.ndev);

  for(i = 0 ; i < dem.ndev ; i ++){

    nres = nvmlDeviceGetHandleByIndex(i,&dem.devs[i]);

    if(nres != NVML_SUCCESS){
      perror("Failed to get device handle\n");
      exit(-1);
    }

    dem.flags[i].sd = -1;
    dem.flags[i].flag = 0;
  }

  dem.procCounter = 0;

  //  printf("Success to get handle of each device (num of dev == %d)\n",dem.ndev);

  /**Setup the socket**/

  int len,rc,on = 1;
  int listen_sd,max_sd,new_sd;
  int desc_ready;
  int close_conn;

  struct sockaddr_un addr;
  struct timeval timeout;
  fd_set master_set,working_set;

  listen_sd = socket(AF_UNIX,SOCK_STREAM,0);

  if(listen_sd < 0){
    perror("socket() failed\n");
    exit(-1);
  }

  rc = setsockopt(listen_sd, SOL_SOCKET, SO_REUSEADDR, (char*)&on,sizeof(on));

  if(rc < 0){
    perror("setsockopt() failed\n");
    exit(-1);
  }

  unlink("mocu_server");

  memset(&addr,0,sizeof(addr));

  addr.sun_family = AF_UNIX;
  strcpy(addr.sun_path,"mocu_server");

  rc = bind(listen_sd,(struct sockaddr*)&addr,sizeof(addr));

  if(rc < 0){
    perror("bind() failed");
    close(listen_sd);
    exit(-1);
  }

  rc = listen(listen_sd,10);

  if(rc < 0){
    perror("listen() failed");
    close(listen_sd);
    exit(-1);
  }

  FD_ZERO(&master_set);
  max_sd = listen_sd;
  FD_SET(listen_sd,&master_set);

  timeout.tv_sec = 3*60;
  timeout.tv_usec = 0;

  //  printf("Success to construct deamon, Entering loop...\n");

  //  printf("SOMAXCONN : %d\n",SOMAXCONN);

  long counter = 0;

  /**Entering main loop**/

  do{

    //    printf("[Loop(%u)]\n",++counter);

    memcpy(&working_set,&master_set,sizeof(master_set));

    rc = select(max_sd+1, &working_set, NULL, NULL, NULL);

    if(rc < 0){
      perror("select() failed\n");
      break;
    }

    if(rc == 0){
      printf("select() time out. End program.\n");
      break;
    }

    desc_ready = rc;

    for(i = 0 ; i < max_sd+1 && desc_ready > 0 ; ++i){
      
      if(FD_ISSET(i,&working_set)){

	//	printf("%d tried to connect to me!!\n",i);

	desc_ready = -1;

	if(i == listen_sd){

	  //	  printf("Listening socket is readable\n");

	  new_sd = accept(listen_sd,NULL,NULL);

	  if(new_sd < 0){
	    printf("accept() failed");
	    end_server = TRUE;
	  }

	  FD_SET(new_sd,&master_set);

	  if(new_sd > max_sd){
	    max_sd = new_sd;
	  }

	  proc* p = create_proc(new_sd);

	  add_proc(p);

	}else{

	  proc_data* receivedProc = (proc_data*)malloc(sizeof(proc_data));

	  rc = recv(i,receivedProc,sizeof(proc_data),0);

	  if(rc <= 0){

	    FD_CLR(i,&master_set);

	    _FIN(i);

	  }else{

	    if(receivedProc->REQUEST == CONNECT){

	      _CONNECT(i);

	    }else if(receivedProc->REQUEST == RENEW){

	      _RENEW(i,receivedProc);
	      
	    }else if(receivedProc->REQUEST == MIGDONE){

	      _MIGDONE(i,receivedProc);
	      
	    }else if(receivedProc->REQUEST == CANRECEIVE){

	      _CANRECEIVE(i,receivedProc);
	      
	    }else if(receivedProc->REQUEST == FAILEDTOGET){

	      _FAILEDTOGET(i,receivedProc);
	      
	    }else if(receivedProc->REQUEST == CUDAMALLOC){

	      _CUDAMALLOC(i,receivedProc);

	    }
	  }
	}
      }
    }

    mocu_check();

  }while(end_server == FALSE);

  int closed = 0;

  for(i = 0 ; i < max_sd ; i ++){
    if(FD_ISSET(i,&master_set)){
      close(i);
      closed = 1;
    }
  }

  fclose(fp);

  if(!closed){
    semctl(sem_id,0,IPC_RMID);
  }

  return 0;
}