int timer_config(timer_config_s *config) { u32 init_counter; if (config == 0) { tw_printf("config timer: config is NULL\n"); return -1; } if (config->mode == TIMER_MODE_TSC) { tw_printf("config timer: mode tsc not supported yet\n"); return -1; } u32 v = lapic_read_reg(_LAPIC_TIMER_OFFSET); v &= ~(3 << 17); // default is one-shot mode if (config->mode == TIMER_MODE_PERIODIC) { v |= (1 << 17); } lapic_write_reg(_LAPIC_TIMER_OFFSET, v); init_counter = (hz/1000) * (config->time_ms); lapic_write_reg(_LAPIC_IC_OFFSET, init_counter); return 0; }
int register_irq(u8 irq, intr_handler_s *handler) { if (handler == 0) { tw_printf("register irq(%d) failed: handler is NULL\n", irq); return -1; } if (handler->callback == 0) { tw_printf("register irq(%d) failed: callback is NULL\n", irq); return -1; } if (handlers[irq].callback != 0) { tw_printf("register irq(%d) failed: already registered\n", irq); return -1; } tw_memcpy(&(handlers[irq]), handler, sizeof(intr_handler_s)); return 0; }
void default_handler(u32 irq, u32 error_code, u32 eip, u32 cs, u32 eflag) { tw_printf("recv irq(%d): error_code(0x%x), eip(0x%x), cs(0x%x), eflag(0x%x)\n", irq, error_code, eip, cs, eflag); if (handlers[irq].callback != 0) { handlers[irq].callback(handlers[irq].arg); } if (irq >= 0x20) { apic_eoi(irq); } }
void timer_init() { intr_handler_s th; th.callback = timer_cb; register_irq(TIMER_IRQ, &th); hz = get_hz(); tw_printf("hz is 0x%x\n", hz); // timer use ivt 0x20 lapic_write_reg(_LAPIC_TIMER_OFFSET, TIMER_IRQ); }
/* this may replace root, which is why we pass * in a AvlTree * */ void avlInsert(AvlTree *t, tw_event *key) { /* insertion procedure */ if (*t == AVL_EMPTY) { /* new t */ *t = avl_alloc(); if (*t == NULL) { tw_error(TW_LOC, "Out of AVL tree nodes!"); } (*t)->child[0] = AVL_EMPTY; (*t)->child[1] = AVL_EMPTY; (*t)->key = key; (*t)->height = 1; /* done */ return; } if (key->recv_ts == (*t)->key->recv_ts) { // We have a timestamp tie, check the event ID if (key->event_id == (*t)->key->event_id) { // We have a event ID tie, check the send_pe if (key->send_pe == (*t)->key->send_pe) { // This shouldn't happen but we'll allow it tw_printf(TW_LOC, "The events are identical!!!\n"); } avlInsert(&(*t)->child[key->send_pe > (*t)->key->send_pe], key); avlRebalance(t); } else { // Event IDs are different avlInsert(&(*t)->child[key->event_id > (*t)->key->event_id], key); avlRebalance(t); } return; } else { // Timestamps are different avlInsert(&(*t)->child[key->recv_ts > (*t)->key->recv_ts], key); avlRebalance(t); } }
static void early_sanity_check(void) { #if ROSS_MEMORY if(0 == g_tw_memory_nqueues) { tw_error(TW_LOC, "ROSS memory library enabled!"); } #endif if (!g_tw_npe) { tw_error(TW_LOC, "need at least one PE"); } if (!g_tw_nlp) { tw_error(TW_LOC, "need at least one LP"); } if (!nkp_per_pe) { tw_printf(TW_LOC, "number of KPs (%u) must be >= PEs (%u), adjusting.", g_tw_nkp, g_tw_npe); g_tw_nkp = g_tw_npe; } }
/* * epi_setup_options - parse the command line arguments */ void epi_setup_options(int argc, char ** argv) { int c; int cnt = 0; g_epi_nsick = 0; g_epi_ic_fn = tw_vector_create(sizeof(char), 255); g_epi_position_fn = tw_vector_create(sizeof(char), 255); printf("\nEpi User Specified Input Parameters: \n\n"); opterr = 0; optind = 0; while(-1 != (c = getopt(argc, argv, "-W:T:D:S:I:M:2:"))) { cnt = 1; switch(c) { case 'I': strcpy(g_epi_ic_fn, optarg); printf("\t%-50s %11s\n", "IC File", g_epi_ic_fn); break; case 'S': g_epi_psick = atof(optarg); printf("\t%-50s %11f\n", "Probability Agents are Sick", g_epi_psick); break; case 'M': g_epi_position_fn = tw_vector_create(sizeof(char), 255); strcpy(g_epi_position_fn, optarg); printf("\t%-50s %11s\n", "Position (Agent Moves) File", g_epi_position_fn); g_epi_position_f = fopen(g_epi_position_fn, "w"); if (!g_epi_position_f) tw_printf(TW_LOC, "Unable to create output file: %s \n", g_epi_position_fn); break; case 'W': g_epi_worried_well_rate = atof(optarg); printf("\t%-50s %11f\n", "Probability of being Worried Well", g_epi_worried_well_rate); break; case 'T': g_epi_worried_well_threshold = atof(optarg); printf("\t%-50s %11f\n", "Worried Well threshold", g_epi_worried_well_threshold); break; case 'D': g_epi_worried_well_duration = atoi(optarg); printf("\t%-50s %11d\n", "Worried Well duration", g_epi_worried_well_duration); break; case '2': g_epi_work_while_sick_p = atof(optarg); printf("\t%-50s %11f\n", "Probability agent will go to work while sick", g_epi_work_while_sick_p); break; case '?': default: ; } } if(!cnt) printf("\t%-50s\n", "Using default variables"); if(0 == strcmp(g_epi_ic_fn, "")) sprintf(g_epi_ic_fn, "tools/%s/ic.txt", g_rn_tools_dir); /* * Fix-up vars */ printf("\n"); }
static void timer_cb(void *arg) { tw_printf("in timer interrupt callback\n"); }