示例#1
0
int
pedirSegmento(int * error, int tamanio, int pid)
{
  int tam = tamanio;

  t_datosEnviar * paquete;
  void * pedidoSegmentoUMV = malloc(3 * sizeof(int));
  memcpy(pedidoSegmentoUMV, &pid, sizeof(int));
  memcpy(pedidoSegmentoUMV + sizeof(int), &tam, sizeof(int));

  paquete = pedirPaquete(pedidoSegmentoUMV, KERNEL_PEDIR_SEGMENTO_UMV, //Pedir Segmento
      2 * sizeof(int));
  common_send(socketUMV, paquete, NULL );

  free(paquete->data);

  paquete = common_receive(socketUMV, NULL );

  if (paquete->codigo_Operacion == ERROR_NO_CREO_SEGMENTO)
    {
      *error = 1;
    }
  memcpy(&tam, paquete->data, sizeof(int));
  destruirPaquete(paquete);
  free(pedidoSegmentoUMV);
  return tam; //Guardado la base
}
示例#2
0
void *
threadPLP(void* vacio)
{
  int PIDActual = 0;
  setvbuf(stdout, NULL, _IONBF, 0);
  log_info(log_kernel,"Se inicio el PLP");



  pthread_t hilo_PLP_destruccion;
  pthread_create(&hilo_PLP_destruccion, NULL, hiloDestruccion, NULL );

  int socketEscucha;
  socketEscucha = setup_listen(configuration.ipKernel,configuration.puertoProg);
  log_info(log_kernel,"El PLP escucha en el socket %d",socketEscucha);
  while (1)
    {
      t_datosEnviar * paquete;
      listen(socketEscucha, 1000);
      struct sockaddr_in addr;
      socklen_t addrlen = sizeof(addr);
      int socketCliente;
      socketCliente = accept(socketEscucha, (struct sockaddr *) &addr,
          &addrlen);

      log_info(log_kernel,"Se recibio una script nueva en el socket %d",socketCliente);

      paquete = common_receive(socketCliente, NULL );
      atenderProgramaEntrante(paquete, socketCliente, &PIDActual);

    }
  pthread_join(hilo_PLP_destruccion, NULL );
  return NULL ;

}
示例#3
0
void doHandshakeUMV() {
	t_datosEnviar* paquete = pedirPaquete("a", HANDSHAKE_UMV, 2);
	common_send(umvSocket, paquete, destroyOnConnectionFailure);
	destruirPaquete(paquete);
	paquete = common_receive(umvSocket, NULL );
	if (paquete->codigo_Operacion != UMV_CONTESTA_CPU_EXITO) {
		log_debug(logger, "Failure handshaking umv");
		destruirPaquete(paquete);
		destroyOnConnectionFailure();
	}
	log_debug(logger, "Successful handshake with UMV");
	destruirPaquete(paquete);
}
示例#4
0
void
startCommunicationWithUMV()
{
  t_datosEnviar *mensaje = pedirPaquete("OK", UMV_ACEPTA_KERNEL, 3);
  socketUMV = connect_to(configuration.ipUMV, configuration.puertoUMV);
  common_send(socketUMV, mensaje, NULL );
  mensaje = common_receive(socketUMV, NULL );
  if (mensaje->codigo_Operacion != UMV_ACEPTA_KERNEL)
    {
      shutdownKernel();
      log_error(log_kernel,
          "No se pudo conectar con la UMV, cerrando el Kernel");
    }
  log_info(log_kernel, "Se conecto exitosamente con la UMV");
}
示例#5
0
t_pcb* onWaitGetProcessFromCPU(int socket)
{
	t_datosEnviar* respuesta = common_receive(socket, NULL );
	if (respuesta->codigo_Operacion == CPU_PCP_PROCESS_WAITING)
	{
		debugTrackPCP("Received PCB, proceeding to update...");
		t_pcb* nuevo = unserializePCB(respuesta);
		debugTrackPCP("DEBUG DEBUG DEBUG PROCESS ID %d",nuevo->pid);
		destruirPaquete(respuesta);
		return nuevo;
	}
	debugTrackPCP(
			"Received an incorrect Operation Code from PCB at waitRequest");
	destruirPaquete(respuesta);
	return NULL ;
}
示例#6
0
t_datos_kernel doHandshakeKernel() {
	int pidCPU = getpid();
	t_datosEnviar* paquete = pedirPaquete(&pidCPU, HANDSHAKE, sizeof(int));
	common_send(pcpSocket, paquete, destroyOnConnectionFailure);
	destruirPaquete(paquete);
	paquete = common_receive(pcpSocket, NULL );
	if (paquete->codigo_Operacion != PCP_CPU_OK) {
		log_debug(logger, "Failure handshaking kernel");
		destruirPaquete(paquete);
		destroyOnConnectionFailure();
	}
	log_debug(logger, "Successful handshake with Kernel");
	t_datos_kernel kernelData = getKernelData(paquete->data);
	destruirPaquete(paquete);
	return kernelData;

}
示例#7
0
void *
threadPLP(void* vacio)
{
  int PIDActual = 0;
  setvbuf(stdout, NULL, _IONBF, 0);
  puts("[KERNEL] - [PLP] - ESCUCHANDO\n");

  pthread_t hilo_PLP_destruccion;
  pthread_t hilo_PLP_multiprogramacion;

  pthread_create(&hilo_PLP_destruccion, NULL, hiloDestruccion, NULL );
  pthread_create(&hilo_PLP_multiprogramacion, NULL, hiloMultiprogramacion,
      NULL );

  int socketEscucha;
  socketEscucha = setup_listen(configuration.puertoProg);
  while (1)
    {
      setvbuf(stdout, NULL, _IONBF, 0);
      t_datosEnviar * paquete;
      listen(socketEscucha, 1000);
      struct sockaddr_in addr;
      socklen_t addrlen = sizeof(addr);
      int socketCliente;
      socketCliente = accept(socketEscucha, (struct sockaddr *) &addr,
          &addrlen);


      paquete = common_receive(socketCliente, NULL );
      atenderProgramaEntrante(paquete, socketCliente, &PIDActual);

    }
  pthread_join(hilo_PLP_destruccion, NULL );
  pthread_join(hilo_PLP_multiprogramacion, NULL );
  return NULL ;

}
示例#8
0
void
atenderProgramaEntrante(t_datosEnviar* paquete, int socketCliente,
    int * PIDActual)
{
  if (paquete->codigo_Operacion == HANDSHAKE)
    {
      destruirPaquete(paquete);
      t_datosEnviar *paqueteEscribir;
      void *dataGenerica;
      paquete = pedirPaquete("K", PLP_PROGRAMA_CONFIRMAR_CONECCION, 2);
      common_send(socketCliente, paquete, NULL );
      destruirPaquete(paquete);
      paquete = common_receive(socketCliente, NULL );
      if (paquete->codigo_Operacion == ENVIAR_SCRIPT)
        {

          debugTrackPLP(
              "[Achievement] Programa autenticado, recibiendo script");
          char* programa = malloc(paquete->data_size);
          memcpy(programa, paquete->data, paquete->data_size);

          t_metadata_program * metadataDelPrograma;
          metadataDelPrograma = metadata_desde_literal((const char*) programa);
          int peso;
          peso = metadataDelPrograma->cantidad_de_funciones * 3
              + metadataDelPrograma->cantidad_de_etiquetas * 5
              + metadataDelPrograma->instrucciones_size;

          int error = 0;
          t_pcb * pcbNuevo = malloc(sizeof(t_pcb));

          pcbNuevo->pid = generarPid(PIDActual);

          int direccionStack, direccionCodigo, direccionIndiceEtiquetas,
              direccionIndiceCodigo;

          destruirPaquete(paquete);
          error = 0;

          debugTrackPLP("[Accion] Pidiendo segmentos en a la UMV");

          direccionCodigo = pedirSegmento(&error, strlen(programa) + 1,
              pcbNuevo->pid);
          direccionStack = pedirSegmento(&error, configuration.tamanio_pila,
              pcbNuevo->pid);
          direccionIndiceEtiquetas = pedirSegmento(&error,
              metadataDelPrograma->etiquetas_size, pcbNuevo->pid);
          direccionIndiceCodigo = pedirSegmento(&error,
              metadataDelPrograma->instrucciones_size * sizeof(t_intructions),
              pcbNuevo->pid);

          if (error == 1)
            {
              debugTrackPLP(
                  "[Error] No se pudo crear la totalidad de segmentos");
              paquete = pedirPaquete("A", PLP_PROGRAMA_NO_SE_PUDO_CREAR, 2);
              common_send(socketCliente, paquete, NULL );
              destruirPaquete(paquete);
              void * pidMomentaneo = malloc(sizeof(int));
              memcpy(pidMomentaneo, &(pcbNuevo->pid), sizeof(int));
              paquete = pedirPaquete(pidMomentaneo,
                  KERNEL_DESTRUIR_SEGMENTOS_PROGRAMA, sizeof(int));
              common_send(socketUMV, paquete, NULL );
              debugTrackPLP(
                  "[Accion] Eliminando el resto de los segmentos pedidos");
              PIDActual--;
              destruirPaquete(paquete);
              free(pidMomentaneo);
            }
          else
            {
              debugTrackPLP(
                  "[PID:%d]-[Achievement] Se pudo alocar todos los segmentos para el proceso ",
                  pcbNuevo->pid);
              pcbNuevo->codeIndex = direccionIndiceCodigo;
              pcbNuevo->codeSegment = direccionCodigo;
              pcbNuevo->indiceEtiquetas = direccionIndiceEtiquetas;
              pcbNuevo->programCounter =
                  metadataDelPrograma->instruccion_inicio;
              pcbNuevo->tamanioIndiceEtiquetas =
                  metadataDelPrograma->etiquetas_size;
              pcbNuevo->currentStack.base = direccionStack;
              pcbNuevo->currentStack.contextSize = 0;
              pcbNuevo->currentStack.size = configuration.tamanio_pila;
              pcbNuevo->currentStack.stack_pointer = direccionStack;

              if (pcbNuevo->codeSegment != -1)
                {
                  debugTrackPLP(
                      "[PID:%d]-[Achievement] Alocado segmento de codigo en la direccion virtual %d",
                      pcbNuevo->pid, pcbNuevo->codeSegment);

                  dataGenerica = malloc(
                      3 * sizeof(uint32_t) + strlen(programa) + 1);
                  int tamanioData = strlen(programa) + 1;

                  memcpy(dataGenerica, &(pcbNuevo->pid), sizeof(uint32_t));
                  memcpy(dataGenerica + sizeof(uint32_t), &tamanioData,
                      sizeof(uint32_t));
                  memcpy(dataGenerica + 2 * sizeof(uint32_t),
                      &(pcbNuevo->codeSegment), sizeof(uint32_t));
                  memcpy(dataGenerica + 3 * sizeof(uint32_t), programa,
                      tamanioData);

                  paqueteEscribir = pedirPaquete(dataGenerica,
                      KERNEL_ESCRIBIR_SEGMENTO_UMV,
                      3 * sizeof(uint32_t) + strlen(programa) + 1);
                  common_send(socketUMV, paqueteEscribir, NULL );
                  destruirPaquete(paqueteEscribir);
                  paqueteEscribir = common_receive(socketUMV, NULL );
                  free(dataGenerica);
                  destruirPaquete(paqueteEscribir);

                }
              if (pcbNuevo->codeIndex != -1)
                {
                  debugTrackPLP(
                      "[PID:%d]-[Achievement] Alocado segmento de indice de codigo en la direccion virtual %d",
                      pcbNuevo->pid, pcbNuevo->codeIndex);
                  int tamanioData = metadataDelPrograma->instrucciones_size
                      * sizeof(t_intructions);
                  paqueteEscribir = pedirPaquete(&(pcbNuevo->pid),
                      KERNEL_ESCRIBIR_SEGMENTO_UMV, sizeof(int));
                  aniadirAlPaquete(paqueteEscribir, &(tamanioData),
                      sizeof(int));
                  aniadirAlPaquete(paqueteEscribir, &(pcbNuevo->codeIndex),
                      sizeof(int));
                  aniadirAlPaquete(paqueteEscribir,
                      metadataDelPrograma->instrucciones_serializado,
                      tamanioData);
                  common_send(socketUMV, paqueteEscribir, NULL );
                  destruirPaquete(paqueteEscribir);
                  paqueteEscribir = common_receive(socketUMV, NULL );
                  destruirPaquete(paqueteEscribir);

                }
              if (pcbNuevo->indiceEtiquetas != -1)
                {

                  debugTrackPLP(
                      "[PID:%d]-[Achievement] Alocado segmento de indice de etiquetas en la direccion virtual %d",
                      pcbNuevo->pid, pcbNuevo->indiceEtiquetas);

                  int tamanioData = metadataDelPrograma->etiquetas_size;
                  dataGenerica = malloc(
                      (tamanioData + 1) * sizeof(char) + 3 * sizeof(int));
                  memcpy(dataGenerica, &(pcbNuevo->pid), sizeof(int));
                  memcpy(dataGenerica + sizeof(int), &tamanioData, sizeof(int));
                  memcpy(dataGenerica + 2 * sizeof(int),
                      &(pcbNuevo->indiceEtiquetas), sizeof(int));
                  memcpy(dataGenerica + 3 * sizeof(int),
                      metadataDelPrograma->etiquetas, tamanioData);
                  paqueteEscribir = pedirPaquete(dataGenerica,
                      KERNEL_ESCRIBIR_SEGMENTO_UMV, (tamanioData + 1) * sizeof(char) + 3 * sizeof(int));
                  common_send(socketUMV, paqueteEscribir, NULL );
                  destruirPaquete(paqueteEscribir);
                  paqueteEscribir = common_receive(socketUMV, NULL );
                  destruirPaquete(paqueteEscribir);
                  free(dataGenerica);

                }

              debugTrackPLP("[PID:%d]-[Achievement] PCB listo para encolarse",
                  pcbNuevo->pid);

              paquete = pedirPaquete("A", PLP_PROGRAMA_ENCOLADO, 2);
              common_send(socketCliente, paquete, NULL );
              free(programa);
              encolarPCB(pcbNuevo, peso, socketCliente);

            }
        }

      else
        {
          destruirPaquete(paquete);
          pedirPaquete("NK", PROGRAMA_CERRAR, 3);
          puts("No Validado");
          common_send(socketCliente, paquete, NULL );
          destruirPaquete(paquete);
        }
    }

}
示例#9
0
	pcpSocket = connect_to(IPKernel, puertoKernel);
	if (pcpSocket == -1) {
		log_debug(logger, "Failure connecting to Kernel");
		destroyOnConnectionFailure();
	}
	return doHandshakeKernel();
}

t_datos_kernel setupConnections() {
	connectToUMV();
	return connectToKernel();
}

t_pcb* getNewPCB() {
	t_pcb* new = conitos_malloc(sizeof(t_pcb));
	t_datosEnviar* recepcion_PCB = common_receive(pcpSocket, NULL );
	if (recepcion_PCB->codigo_Operacion != PCP_CPU_PROGRAM_TO_EXECUTE) {
		log_debug(logger, "Failure delivering PCB...");
		estado = END_PROCESS;
		return NULL ;
	}
	*new = *(t_pcb*) recepcion_PCB->data;
	destruirPaquete(recepcion_PCB);
	log_debug(logger, "PCB Received correctly. Starting to execute process %d",
			new->pid);
	return new;
}

void resetContextFrom0() {
	recreate_variable_dictionary();
	traer_segmento_etiquetas();