void Jcmd_apic_test(void *arg1,void *arg2){ int duration=TICKS_PER_SECOND; if (getcpuid() != 0) { set_local_apic_timer(LOCAL_TIMER_CPU_IRQ_VEC, duration); ut_printf(" increased timer by 10 times : durastion:%d \n",duration); }else{ ut_printf(" cpu is boot cpu duration:%d \n",duration); } }
void Jcmd_arp_print(void) { ut_printf(" Arp Table: \n"); for(i = 0; i < UIP_ARPTAB_SIZE; ++i) { if (arp_table[i].ipaddr[0]==0 && arp_table[i].ipaddr[1]==0) continue; ut_printf("%d ipaddr: %x:%x time:%x mac:%x \n",i,arp_table[i].ipaddr[0],arp_table[i].ipaddr[1],arp_table[i].time,arp_table[i].ethaddr.addr[5]); } }
void virtio_memb_interrupt(registers_t regs) { /* reset the irq by resetting the status */ unsigned char isr; //isr = inb(memb_dev->pci_ioaddr + VIRTIO_PCI_ISR); ut_printf("GOT MEM BALLOON interrupt\n"); unsigned long config_addr; config_addr = memb_dev->pci_ioaddr + 20; balloon_config.num_pages= inl(config_addr); balloon_config.actual= inl(config_addr+4); ut_printf("config value: numpages:%x(%d) actual:%x(%d) \n",balloon_config.num_pages,balloon_config.num_pages,balloon_config.actual,balloon_config.actual); }
static void lwip_network_status(unsigned char *arg1,unsigned char *arg2){ struct netif *netif; netif = the_interface; if (netif ==0) return; ut_printf(" ip:%x gw:%x mask:%x \n",netif->ip_addr, netif->gw, netif->netmask); ut_printf("mac_addr : %x:%x:%x:%x:%x:%x \n",netif->hwaddr[0],netif->hwaddr[1],netif->hwaddr[2],netif->hwaddr[3],netif->hwaddr[4],netif->hwaddr[5]); ut_printf(" mem Errors: %d send mem errors:%d\n",error_mem,error_send_mem); #if LWIP_SNMP ut_printf("in_bytes:%d out_bytes:%d inpkts:%d outpkts:%d \n",netif->ifinoctets,netif->ifoutoctets,netif->ifinucastpkts,netif->ifoutucastpkts); #endif ut_printf(" link: Tx:%d Rx:%d drop:%d\n IP: Tx:%d Rx:%d drop:%d\nUDP: Tx:%d Rx:%d drop:%d\n",lwip_stats.link.xmit,lwip_stats.link.recv,lwip_stats.link.drop,lwip_stats.ip.xmit,lwip_stats.ip.recv,lwip_stats.ip.drop,lwip_stats.udp.xmit,lwip_stats.udp.recv,lwip_stats.udp.drop); }
static void host_shm_interrupt(registers_t regs) { uint32_t i, *p, ret; p = (unsigned char *) HOST_SHM_CTL_ADDR + 4; *p = 0; /* reset the irq by resetting the status */ ret = sc_wakeUp(&g_hfs_waitqueue); /* wake all the waiting processes */ ut_printf(" GOT HOST SHM INTERRUPT :%x: wakedup :%d \n", p, ret); }
int Jcmd_pci_stat(char *arg1 , char *arg2){ int i; for (i=0; i<bar_count; i++){ if (pci_bars[i].addr==0 ) return; ut_printf("name:%s addr:%x len:%d\n",pci_bars[i].name,pci_bars[i].addr,pci_bars[i].len); } return 1; }
/** * Dump a message taken from the ring buffer. * * \param[in] idx Index in the ring buffer * \param[in] msg Message * \param[in] size Message size * \param[in] mid Message id * * Use this function as follows: * examsgRngDump(r, (ExaRingDumpMsgFn)&dump_message); * where r is the ring buffer to dump. */ static void dump_message(int idx, const char *msg, size_t size, const ExamsgMID *mid) { /* Size chosen so that we can print even a message as big as the ring * buffer */ char str[RNG_SIZE + 1]; memcpy(str, msg, size); str[size] = '\0'; ut_printf("%d: msg='%s' size=%"PRIzu, idx, str, size); }
static void ut_print_test_beginning_plain(const test_t *test) { char begin_str[128]; unsigned attr_count = 0; strcpy(begin_str, "("); /* XXX strcat() is unsafe but it will do for now since we only have * three attributes to consider */ if (!__ut_must_fork) { strcat(begin_str, "notforked"); attr_count++; } if (test->lengthy) { if (attr_count > 0) strcat(begin_str, ", "); strcat(begin_str, "lengthy"); attr_count++; } if (test->timeout > 0) { char timeout_str[32]; _ut_snprintf(timeout_str, sizeof(timeout_str), "%us timeout", test->timeout); if (attr_count > 0) strcat(begin_str, ", "); strcat(begin_str, timeout_str); attr_count++; } if (test->expected_signal > 0) { char signal_str[32]; _ut_snprintf(signal_str, sizeof(signal_str), "signal %d expected", test->expected_signal); if (attr_count > 0) strcat(begin_str, ", "); strcat(begin_str, signal_str); attr_count++; } strcat(begin_str, ")"); if (attr_count > 0) ut_printf(__ut_test_report_str, test->name, begin_str); }
int Jcmd_testmem(char *arg1, char *arg2){ int i; int size=40000; if (arg1){ size=ut_atoi(arg1,FORMAT_DECIMAL); } for (i=0; i<size; i++){ mm_getFreePages(0, 0); } ut_printf(" Test created (size=%d): %dM \n",size,size*PAGE_SIZE/(1024*1024)); Jcmd_mem(0,0); return 1; }
/* * Show free area list (used inside shift_scroll-lock stuff) * We also calculate the percentage fragmentation. We do this by counting the * memory on each free list with the exception of the first item on the list. */ int Jcmd_mem(char *arg1, char *arg2) { unsigned long order, flags; unsigned long total = 0; spin_lock_irqsave(&free_area_lock, flags); for (order = 0; order < NR_MEM_LISTS; order++) { struct page * tmp; unsigned long nr = 0; for (tmp = free_mem_area[order].next; tmp != memory_head(free_mem_area+order); tmp = tmp->next) { nr++; } total += nr << order; ut_printf("%d(%d): count:%d static count:%d total:%d (%dM)\n", order,1<<order, nr, free_mem_area[order].stat_count, (nr << order), ((nr << order)*PAGE_SIZE)/(1024*1024)); } spin_unlock_irqrestore(&free_area_lock, flags); ut_printf("total Free pages = %d (%dM) Actual pages: %d (%dM) pagecachesize: %dM , freepages:%d\n", total, (total * 4) / 1024,g_stat_mem_size/PAGE_SIZE,g_stat_mem_size/(1024*1024),g_pagecache_size/(1024*1024),g_nr_free_pages); int slab=0; int referenced=0; int reserved=0; int dma=0; unsigned long va_end=(unsigned long)__va(g_phy_mem_size); page_struct_t *p; p = g_mem_map + MAP_NR(va_end); do { --p; if (PageReserved(p)) reserved++; if (PageDMA(p)) dma++; if (PageReferenced(p))referenced++; if (PageSlab(p)) slab++; } while (p > g_mem_map); ut_printf(" reserved :%d(%dM) referenced:%d dma:%d slab:%d stat_allocs:%d stat_frees: %d\n\n",reserved,(reserved*PAGE_SIZE)/(1024*1024),referenced,dma,slab,stat_allocs,stat_frees); if ((arg1 != 0) && (ut_strcmp(arg1,"all")==0)) Jcmd_jslab(0,0); return 1; }
static void help_text_print(const char *text, unsigned int nb_items) { unsigned int i; const char *curr = text; for (i = 0; i < nb_items; i++) { unsigned int current_size = strlen(curr) + 1; ut_printf(" item %d: '%s'", i, curr); curr += current_size; } }
err_t netif_netfront_init(struct netif *netif) { unsigned char *mac = netif->state; ut_printf("LWIP: netfront init called \n "); #if LWIP_SNMP /* ifType ethernetCsmacd(6) @see RFC1213 */ netif->link_type = 6; /* your link speed here */ //netif->link_speed =; netif->ts = 0; netif->ifinoctets = 0; netif->ifinucastpkts = 0; netif->ifinnucastpkts = 0; netif->ifindiscards = 0; netif->ifoutoctets = 0; netif->ifoutucastpkts = 0; netif->ifoutnucastpkts = 0; netif->ifoutdiscards = 0; #endif netif->name[0] = IFNAME0; netif->name[1] = IFNAME1; netif->output = netfront_output; netif->linkoutput = low_level_output; the_interface = netif; /* set MAC hardware address */ netif->hwaddr_len = 6; netif->hwaddr[0] = mac[0]; netif->hwaddr[1] = mac[1]; netif->hwaddr[2] = mac[2]; netif->hwaddr[3] = mac[3]; netif->hwaddr[4] = mac[4]; netif->hwaddr[5] = mac[5]; /* No interesting per-interface state */ netif->state = NULL; /* maximum transfer unit */ netif->mtu = 1500; /* broadcast capability */ netif->flags = NETIF_FLAG_BROADCAST; etharp_init(); sys_timeout(ARP_TMR_INTERVAL, arp_timer, NULL); return ERR_OK; }
static int check_name(names_to_check_t* names) { char test_conf[1024]; char error_msg[EXA_MAXSIZE_LINE + 1]; int res; putenv("EXANODES_NODE_CONF_DIR=" OS_FILE_SEP "does_not_exist"); adm_cluster_cleanup(); os_snprintf(test_conf, sizeof(test_conf), test_conf_format, EXA_VERSION, names->cluster_name, names->node_name, names->host_name, names->disk_path, adm_hostname()); res = adm_deserialize_from_memory(test_conf, strlen(test_conf), error_msg, true); if (res != EXA_SUCCESS) ut_printf("check_name(cluster:\"%s\", node:\"%s\", host:\"%s\", disk:\"%s\") failed: %s", names->cluster_name, names->node_name, names->host_name, names->disk_path, error_msg); return res; }
static unsigned long setup_userstack(unsigned char **argv, unsigned char **env, unsigned long *stack_len, unsigned long *t_argc, unsigned long *t_argv, unsigned long *p_aux, unsigned char *elf_interp) { int i, len, total_args = 0; int total_envs =0; unsigned char *p, *stack; unsigned long real_stack, addr; unsigned char **target_argv; unsigned char **target_env; int max_stack_len=MAX_USERSPACE_STACK_TEMPLEN; int max_list_len=(PAGE_SIZE/sizeof(void *))-1; unsigned long ret=0; if (argv == 0 && env == 0) { ut_printf(" ERROR in setuo_userstack argv:0\n"); return 0; } target_argv = (unsigned char **) alloc_page(MEM_CLEAR); target_env = (unsigned char **) alloc_page(MEM_CLEAR); if (target_argv==0 || target_env==0){ BUG(); } stack = (unsigned char *) vmalloc(MAX_USERSPACE_STACK_TEMPLEN,MEM_CLEAR); if (stack ==0){ goto error; } ret = stack; p = stack + max_stack_len; len = 0; real_stack = USERSTACK_ADDR + USERSTACK_LEN; if (elf_interp != 0){ //BUG(); len = ut_strlen(elf_interp); p = p - len - 1; real_stack = real_stack - len - 1; ut_strcpy(p, elf_interp); target_argv[total_args] = (unsigned char *)real_stack; total_args++; } for (i = 0; argv[i] != 0 && i < max_list_len; i++) { len = ut_strlen(argv[i]); if ((p - len - 1) > stack) { p = p - len - 1; real_stack = real_stack - len - 1; DEBUG(" argument :%d address:%x \n",i,real_stack); ut_strcpy(p, argv[i]); target_argv[total_args] = (unsigned char *)real_stack; total_args++; } else { ret=0 ; goto error; } } target_argv[total_args] = 0; for (i = 0; env[i] != 0 && i < max_list_len; i++) { total_envs++; len = ut_strlen(env[i]); if ((p - len - 1) > stack) { p = p - len - 1; real_stack = real_stack - len - 1; DEBUG(" envs :%d address:%x \n",i,real_stack); ut_strcpy(p, env[i]); target_env[i] = (unsigned char *)real_stack; } else { ret=0 ; goto error; } } target_env[i] = 0; addr = (unsigned long)p; addr = (unsigned long)((addr / 8) * 8); p = (unsigned char *)addr; p = p - (MAX_AUX_VEC_ENTRIES * 16); real_stack = USERSTACK_ADDR + USERSTACK_LEN + p - (stack + max_stack_len); *p_aux = (unsigned long)p; len = (1+total_args + 1 + total_envs+1) * 8; /* total_args+args+0+envs+0 */ if ((p - len - 1) > stack) { unsigned long *t; p = p - (total_envs+1)*8; ut_memcpy(p, (unsigned char *)target_env, (total_envs+1)*8); p = p - (1+total_args+1)*8; ut_memcpy(p+8, (unsigned char *)target_argv, (total_args+1)*8); t = (unsigned long *)p; *t = total_args; /* store argc at the top of stack */ DEBUG("Target ARG arg0:%x arg1:%x arg2:%x len:%d \n",target_argv[0],target_argv[1],target_argv[2],len); DEBUG("Target ENV arg0:%x arg1:%x arg2:%x len:%d \n",target_env[0],target_env[1],target_env[2],len); real_stack = real_stack - len; } else { ret=0; goto error; } *stack_len = max_stack_len - (p - stack); *t_argc = total_args; *t_argv = real_stack; error: if (ret ==0 ){ ut_log(" Error: user stack creation failed :%s:\n",g_current_task->name); vfree((unsigned long)stack); } mm_putFreePages((unsigned long)target_argv, 0); mm_putFreePages((unsigned long)target_env, 0); return ret; }
static void ut_run_test(section_t *suite, test_t *test) { __ut_test_index = test->index; if (test->lengthy && __ut_skip_lengthy) { __ut_test_result = __UT_RESULT_SKIPPED; if (! __ut_test_quiet) ut_print_test_beginning(test); goto done; } if (!__ut_must_fork) { if (suite->setup != NULL) ut_run_setup(suite->setup); #ifdef __cplusplus try { #endif __ut_currently_in = __UT_IN_TEST; __ut_test_result = __UT_RESULT_PASSED; if (! __ut_test_quiet) ut_print_test_beginning(test); ut_do_test(test); #ifdef __cplusplus } catch(std::exception & exc) { std::cout << "Exception: " << exc.what() << std::endl; ut_end(__UT_RESULT_FAILED); } #endif if (suite->cleanup != NULL) ut_run_cleanup(suite->cleanup); } else { #ifdef WIN32 char cmdline[256]; STARTUPINFO si; PROCESS_INFORMATION pi; DWORD ret; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); ZeroMemory(&pi, sizeof(pi)); if (! __ut_test_quiet) ut_print_test_beginning(test); _ut_snprintf(cmdline, sizeof(cmdline), "%s -d -q -n %d%s%s%s", __ut_argv0, test->index + 1, __ut_output_xml ? " -x" : "", __ut_skip_lengthy ? " -s" : "", __ut_test_verbose ? " -v" : ""); if (! CreateProcess(NULL, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) { ut_printf("Failed to create process"); ut_end(__UT_RESULT_FAILED); } ret = WaitForSingleObject(pi.hProcess, test->timeout != 0 ? 1000 * test->timeout : INFINITE); if (ret != WAIT_OBJECT_0) { ut_printf("Test case timed out"); __ut_test_result = __UT_RESULT_FAILED; CloseHandle(pi.hProcess); goto done; } if (! GetExitCodeProcess(pi.hProcess, &ret)) { ut_printf("Failed to get exit code"); __ut_test_result = __UT_RESULT_FAILED; CloseHandle(pi.hProcess); goto done; } CloseHandle(pi.hProcess); __ut_test_result = (ret == 0) ? __UT_RESULT_PASSED : __UT_RESULT_FAILED; #else /* WIN32 */ pid_t pid; int child_status; pid = fork(); if (pid == 0) { if (suite->setup != NULL) ut_run_setup(suite->setup); #ifdef __cplusplus try { #endif __ut_currently_in = __UT_IN_TEST; if (! __ut_test_quiet) ut_print_test_beginning(test); ut_do_test(test); #ifdef __cplusplus } catch(std::exception & exc) { std::cout << "Exception: " << exc.what() << std::endl; ut_end(__UT_RESULT_FAILED); } catch(...) { std::cout << "Unknown error" << std::endl; ut_end(__UT_RESULT_FAILED); } #endif if (suite->cleanup != NULL) ut_run_cleanup(suite->cleanup); ut_end(__UT_RESULT_PASSED); } else if (pid > 0) { bool timed_out = false; pid_t died_pid = 0; if (test->timeout == 0) died_pid = wait(&child_status); else { unsigned long time_left = 1000000 * test->timeout; /* Polling: can't use SIGCHLD because the testee may have * its own SIGCHLD handler */ while (time_left > 0) { died_pid = waitpid(pid, &child_status, WNOHANG); if (died_pid > 0) break; /* 1/10th of a second */ usleep(100000); time_left -= 100000; } timed_out = (died_pid <= 0); } if (timed_out) { int _status; kill(pid, SIGKILL); waitpid(pid, &_status, 0); ut_printf("Test case timed out"); __ut_test_result = __UT_RESULT_FAILED; } else if (died_pid <= 0 || child_status != 0) { __ut_test_result = __UT_RESULT_FAILED; if (WIFSIGNALED(child_status)) { int sig = WTERMSIG(child_status); if (test->expected_signal > 0) { if (sig == test->expected_signal) __ut_test_result = __UT_RESULT_PASSED; else ut_printf("Expected signal %d, got %d", test->expected_signal, sig); } else ut_printf("Test case died unexpectedly (signal %d).", sig); } } else { if (test->expected_signal > 0) { ut_printf("Expected signal %d, got none", test->expected_signal); __ut_test_result = __UT_RESULT_FAILED; } else __ut_test_result = __UT_RESULT_PASSED; } } else ut_printf("Failed forking"); #endif /* WIN32 */ } done: __ut_currently_in = __UT_IN_TEST; if (! __ut_test_quiet) ut_print_test_end(test, __ut_test_result); switch (__ut_test_result) { case __UT_RESULT_FAILED: break; case __UT_RESULT_PASSED: __ut_pass_count++; break; case __UT_RESULT_SKIPPED: __ut_skip_count++; break; } }
static void ut_print_test_end_plain(const test_t *test, ut_result_t result) { ut_printf(__ut_test_report_str, test->name, ut_result_str(result)); }
int Jcmd_dmesg(unsigned char *arg1){ ut_printf("Size/Max : %d / %d \n",g_dmesg_index,MAX_DMESG_LOG); g_dmesg[MAX_DMESG_LOG]=0; ut_printf("%s\n",g_dmesg); return 0; }
int init_host_shm(pci_dev_header_t *pci_hdr, pci_bar_t bars[], uint32_t len, int *msi_vector) { uint32_t i, *p; long ret; host_shm_pci_hdr = *pci_hdr; ut_printf(" Initialising HOST SHM .. \n"); for (i = 0; i < len && i < 4; i++) { host_shm_pci_bar[i] = bars[i]; ut_printf("Host_shm bar addr :%x len: %x \n", host_shm_pci_bar[i].addr, host_shm_pci_bar[i].len); } if (bars[0].addr != 0) { if ((ret = vm_mmap(0, HOST_SHM_CTL_ADDR, 0x1000, PROT_WRITE, MAP_FIXED, bars[0].addr)) == 0) { ut_printf( "ERROR : mmap fails for Host_ctl addr :%x len:%x ret:%x \n", bars[0].addr, bars[0].len, ret); return 0; } else { p = (unsigned char *) HOST_SHM_CTL_ADDR; *p = 0xffffffff; /* set the proper mask */ // g_hostShmLen=bars[0].len; } } if (bars[2].addr == 0) i=1; /* No MSI */ else i=2; /* MSI present in bar-1 */ if (bars[i].addr != 0) { if ((ret = vm_mmap(0, HOST_SHM_ADDR, bars[i].len, PROT_WRITE, MAP_FIXED, bars[i].addr)) == 0) { ut_printf( "ERROR : mmap fails for Host_shm addr :%x len:%x ret:%x \n", bars[i].addr, bars[i].len, ret); return 0; } else { g_hostShmPhyAddr = bars[i].addr; g_hostShmLen = bars[i].len; } }else{ return 0; } sc_register_waitqueue(&g_hfs_waitqueue,"Hfs"); if (pci_hdr->interrupt_line > 0) { int k; #if 1 p = HOST_SHM_CTL_ADDR; *p=0xffffffff; p=p+1; k=*p; #endif ut_printf(" Interrupt NUMBER : %i k:%d \n", pci_hdr->interrupt_line,k); ar_registerInterrupt(32 + pci_hdr->interrupt_line, host_shm_interrupt, "host_shm"); } init_HostFs(); if (*msi_vector > 0) { ar_registerInterrupt(*msi_vector , host_shm_interrupt,"hostshm_msi"); } return 1; }
uint8_t apic_get_task_priority() { ut_printf(" prio: %x register :%x cpuid:%d \n,",local_apic->tpr.reg ,local_apic->tpr.priority,getcpuid()); return local_apic->tpr.priority ; }
int mm_putFreePages(unsigned long addr, unsigned long order) { unsigned long map_nr = MAP_NR(addr); int ret = 0; int page_order = order; unsigned long flags; stat_frees++; #ifdef MEMLEAK_TOOL memleakHook_free(addr,0); #endif spin_lock_irqsave(&free_area_lock, flags); if (map_nr < g_max_mapnr) { page_struct_t * map = g_mem_map + map_nr; if (PageReserved(map)) { BUG(); } if (PageNetBuf(map)){ BUG(); } #ifdef MEMORY_DEBUG if (map->option_data != 0){ BUG(); } #endif if (atomic_dec_and_test(&map->count)) { if (PageSwapCache(map)){ ut_log("PANIC Freeing swap cache pages"); BUG(); } // map->flags &= ~(1 << PG_referenced); _free_pages_ok(map_nr, order); if (init_done == 1) { DEBUG(" Freeing memory addr:%x order:%d \n", addr, order); }else{ // BUG(); } ret = 1; } }else{ BUG(); } last: if (ret){ unsigned long i = (1 << page_order); struct page *page = virt_to_page(addr); while (i--) { #ifdef MEMORY_DEBUG if (!PageReferenced(page)){ ut_printf("Page Backtrace in Free Page :\n"); ut_printBackTrace(page->bt_addr_list,MAX_BACKTRACE_LENGTH); } #endif assert(PageReferenced(page)); PageClearReferenced(page); #ifdef MEMORY_DEBUG ut_storeBackTrace(page->bt_addr_list,MAX_BACKTRACE_LENGTH); #endif page++; } }else{ BUG(); } spin_unlock_irqrestore(&free_area_lock, flags); return ret; }