Пример #1
0
void
check_signal()
    /* check if a signal has been received and handle it */
{

    /* we reinstall the signal handler functions here and not directly in the handlers,
     * as it is not supported on some systems (HP-UX) and makes fcron crash */

    if (sig_chld > 0) {
        wait_chld();
        sig_chld = 0;
#ifdef HAVE_SIGNAL
        (void)signal(SIGCHLD, sigchild_handler);
        siginterrupt(SIGCHLD, 0);
#endif
    }
    if (sig_conf > 0) {

        if (sig_conf == 1) {
            /* update configuration */
            synchronize_dir(".", 0);
            sig_conf = 0;
#ifdef HAVE_SIGNAL
            signal(SIGHUP, sighup_handler);
            siginterrupt(SIGHUP, 0);
#endif
        }
        else {
            /* reload all configuration */
            reload_all(".");
            sig_conf = 0;
#ifdef HAVE_SIGNAL
            signal(SIGUSR1, sigusr1_handler);
            siginterrupt(SIGUSR1, 0);
#endif
        }

    }
    if (sig_debug > 0) {
        print_schedule();
        debug_opt = (debug_opt > 0) ? 0 : 1;
        explain("debug_opt = %d", debug_opt);
        sig_debug = 0;
#ifdef HAVE_SIGNAL
        signal(SIGUSR2, sigusr2_handler);
        siginterrupt(SIGUSR2, 0);
#endif
    }

}
Пример #2
0
/*
 * The worst case solver assigns all tasks to one processor.
 */
int
worstcase_solver(char *stg_filename, char *ssf_filename)
{
    int malloced;
    int freed;

    struct stg *tg;
    struct ssf_status *status;
    struct ssf *schedule;

    int ok;
        int tlist[] = { 2, 3, 4};

    printf("** Worst Case Solver\n");

        /* Allocate data structures. */
    malloced = 0;
    freed = 0;
        tg = new_task_graph_from_file(stg_filename, &malloced);
    status = new_status(&malloced);
    strncpy(status->name, "YASA worstcase", 20);
    schedule = new_schedule(tg, &malloced);
    printf("malloced %d bytes\n", malloced);

    /* Solve. */
    print_task_graph(tg);
    printf("twiddle. twiddle, crunch, crunch..\n");

        ok = is_tinsert_ok(tg, 1, 0, tlist);
    printf("is_tinsert_ok = %u\n", ok);

    print_schedule(schedule);
    write_schedule_to_file(ssf_filename, schedule, status);

    /* Free data structures. */
    free_schedule(schedule, &freed);
    free_status(status, &freed);
    free_task_graph(tg, &freed);
    printf("freed %d bytes => ", freed);
    if (malloced == freed)
        printf("OK.\n");
    else {
        printf("Error: malloced != freed!\n");
        return (1);
    }

    return (0);
}
Пример #3
0
void active_schedule_start(active_schedule_t *schedule)
{
    for (active_schedule_t *s = schedule; s; s = s->next) {
        if (debug) {
            print_schedule(s);
        }
        if (s->pre_function) {
            s->pre_function(s->pre_data);
        }
        if (s->direction == ACTIVE_SCHEDULE_SEND) {
            MPI_Isend(s->addr, s->count, s->type, s->peer, 0, s->comm, &s->req);
        } else if (s->direction == ACTIVE_SCHEDULE_RECV) {
            MPI_Irecv(s->addr, s->count, s->type, s->peer, 0, s->comm, &s->req);
        } else {
            perror("unknown direction in communication schedule");
        }
    }
}
Пример #4
0
int main()
{


  print_schedule();
  pthread_t a = intercept_pthread_create((void*)f, (void*)1);
  pthread_t b = intercept_pthread_create((void*)f, (void*)2);
  pthread_t c = intercept_pthread_create((void*)f, (void*)3);
  pthread_t d = intercept_pthread_create((void*)f, (void*)4);

  /*sleep(4);*/

  intercept_pthread_join(a,1);
  intercept_pthread_join(b,2);
  intercept_pthread_join(c,3);
  intercept_pthread_join(d,4);


  printf("Step: %d \n", step);

  return 0;

}
int sys_Send (TD *td_caller, Request *req){
#ifdef DEBUG_SYS
	kprintf("sys_Send starts. Caller's tid: %d\n\r", td_caller->tid);
#endif
	// tid of receiver
	int tid = (int)(req->params)[0];
	// Sender and receiver
	TD *sender = td_caller;
	TD *receiver = (req->tds)+tid;
	// If tid is invalid (out of range) return error code
	if (tid > (NUM_TASKS - 1)) {
#ifdef DEBUG_SYS
		kprintf("sys_Send returns. tid: %d\n\r", tid);
#endif
		return -1;
	}
	// If receiver does not exist(exited or not created) return error code
	if ((receiver->state == ST_ZOMBIE) || (receiver->state == ST_UNUSED)){
#ifdef DEBUG_SYS
		kprintf("sys_Send returns. receiver->state: %d\n\r", (int)receiver->state);
#endif
		return -2;
	}
	void *msg = (void*)(req->params)[1];
	int msglen = (int)(req->params)[2];
	void *reply = (void*)(req->params)[3];
	int replylen = (int)(req->params)[4];
	// If the send-receive-reply transaction is incomplete then return error code
	if (!msg || !reply || !msglen || !replylen){
#ifdef DEBUG_SYS
		kprintf("sys_Send returns. '!msg || !reply || !msglen || !replylen' is true\n\r");
		kprintf("msg = 0x%x\treply = 0x%x\tmsglen = %d\treplylen = %d\n\r", msg, reply, msglen, replylen);
#endif
		return -3;
	}
#ifdef DEBUG_SYS
	kprintf("removing taskid %d\n\r", sender->tid);
	print_schedule(&req->RDY_Queue);
#endif
	schedulerRemoveActive (&req->RDY_Queue, sender->priority);
#ifdef DEBUG_SYS
	kprintf("After removal.\n\r");
	print_schedule(&req->RDY_Queue);
#endif
	if (receiver->state == ST_SEND_BL){	// receiver has already called Receive() and is waiting for message
		// copy the message to the buffer of receiver
#ifdef DEBUG_SYS
		kprintf("sys_Send: Receiver is Send blocked\n\r");
		kprintf ("its tid: %d\n\r", receiver->tid);
#endif
		int rcv_len = (req->tds[tid].rcv_len);						
		void *rcv_buff = (void*)(req->tds[tid].rcv_buff_addr);
		int memcpy_len = (msglen < rcv_len) ? msglen : rcv_len;
		memcpy(rcv_buff, msg, (unsigned)memcpy_len);
		// save the senders tid in request's array for receiver
		*(receiver->rcv_tid) = sender->tid;							
		// change receiver's state to ready and add to the ready queue to reschedule
		receiver->state = ST_READY;
		schedulerAddTask (&req->RDY_Queue, receiver, receiver->priority);
		// sender is waiting for reply (reply blocked)
		sender->state = ST_REPLY_BL;
		// receiver returns from Receive(). Set its return value.
		*((int *)(receiver->sp)) = msglen;
	}
	else {	// receiver has not called Receive(). Push message into the send queue.
#ifdef DEBUG_SYS
		kprintf("sys_Send: Receiver is not Send blocked\n\r");
#endif
		int err = taskQueue_push((int)sender->tid, (void*)msg, (int)msglen, &receiver->sendQ);
		if (err){
#ifdef DEBUG_SYS
		kprintf("sys_Send returns. Push has failed\n\r");
#endif
			return -3;
		}
		
		sender->state = ST_RECEIVE_BL;
	}
	sender->reply_buff = reply;							
	sender->reply_len = replylen;						
#ifdef DEBUG_SYS
	kprintf("sys_Send returns\n\r");
#endif
	return msglen;
}
Пример #6
0
/*
 * Sequential version.
 */
int
seqsa_solver(char *stg_filename, char *ssf_filename)
{
    int malloced;
    int freed;

    int malloced_initial;
    int freed_initial;

    int malloced_select;
    int freed_select;

    struct stg *tg;
    struct ssf_status *status;
    struct ssf *schedule;

    double eps;
    unsigned seed;

    int i;
    double t0;
    double t;

    struct iss *alpha;  /* present solution */
    struct iss *beta;   /* neighbour solution of alpha */

    double cost_alpha;
    double cost_beta;

    double r;
    double bf;  /* Boltzmann Factor p(alpha -> beta) */


    printf("** Sequential Simulated Annealing Solver\n");

    /* Allocate data structures. */
    malloced = 0;
    freed = 0;
    tg = new_task_graph_from_file(stg_filename, &malloced);
    status = new_status(&malloced);
    strncpy(status->name, "YASA Sequential", 20);

    eps = 1e-3;
    seed = 0;
    t0 = 1000.0;

    alpha = NULL;
    beta = NULL;

    /* Solve. */
    srand(seed);
    print_task_graph(tg);

    malloced_initial = 0;
    freed_initial = 0;
    alpha = create_initial_solution(tg, &malloced_initial, &freed_initial);
    printf("malloced %d bytes for initial solution\n", malloced_initial);
    printf("freed %d bytes for initial solution\n", freed_initial);
    printf("difference: %d bytes\n", malloced_initial - freed_initial);

    cost_alpha = cost(tg, alpha);

    i = 0;
    t = t0;
    
    while (t > eps) {
        printf("i = %d, t = %f\n", i, t);

        malloced_select = 0;
        freed_select = 0;
        beta = select_neighbour(tg, alpha, &malloced_select, &freed_select);
        printf("malloced %d bytes for selection\n", malloced_select);
        printf("freed %d bytes for selection\n", freed_select);
        printf("difference: %d bytes\n", malloced_select - freed_select);
        cost_beta = cost(tg, beta);

        if (cost_beta <= cost_alpha) {
            /* TODO alpha := beta */
            cost_alpha = cost_beta;
        } else {
            r = get_random_r();  /* r from (0, 1) */
            bf = boltzmann_factor(t, cost_alpha, cost_beta);
            printf("r = %f, bf = %f\n", r, bf);
            if (r < bf) {
                /* TODO alpha := beta */
                cost_alpha = cost_beta;
            }
        }
        i++;
        t = new_temp(t, i);
    }
    printf("stopping at i = %d, t = %f.\n", i, t);

    /* alpha to schedule */
    //schedule = new_schedule(tg, alpha, &malloced);
    schedule = new_schedule(tg, &malloced);
    printf("malloced %d bytes\n", malloced);

    /* Display Results */
    print_schedule(schedule);
    write_schedule_to_file(ssf_filename, schedule, status);

    /* Free data structures. */
    free_schedule(schedule, &freed);
    // TODO free initial solution
    free_status(status, &freed);
    free_task_graph(tg, &freed);
    printf("freed %d bytes => ", freed);
    if (malloced == freed)
        printf("OK.\n");
    else {
        printf("Error: malloced != freed!\n");
        return (1);
    }

    return (0);
}