long test1c() { unsigned char *pages; size_t page_size = PAGE_SIZE; size_t addr_size = page_size * PAGE_NUM; int wcount[PAGE_NUM], ret; bzero(wcount, PAGE_NUM * sizeof(int)); pages = mmap(ADDR_START, addr_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); if (pages == MAP_FAILED) return -errno; fprintf(stderr, "pages = %lx\n", (unsigned long)pages); ret = start_trace((unsigned long)pages, addr_size); if (ret) { fprintf(stderr, "start_trace failed: %s\n", strerror(errno)); return -errno; } fprintf(stderr, "start_trace\n"); ret = start_trace((unsigned long)pages, addr_size); if (!ret || errno != EINVAL) { fprintf(stderr, "the 2nd start_trace should fail\n"); return -1; } ret = get_trace(getpid(), wcount); if (ret) { fprintf(stderr, "get_trace failed: %s\n", strerror(errno)); return -errno; } fprintf(stderr, "get_trace\n"); ret = stop_trace(); if (ret) { fprintf(stderr, "stop_trace failed: %s\n", strerror(errno)); return -errno; } fprintf(stderr, "stop_trace\n"); ret = stop_trace(); if (!ret || errno != EINVAL) { fprintf(stderr, "the 2nd stop_trace should fail\n"); return -1; } ret = get_trace(getpid(), wcount); if (!ret || errno != EINVAL) { fprintf(stderr, "the 2nd get_trace should fail\n"); return -1; } return 0; }
int main(void) { int rc; L=lua_open(0); lua_baselibopen(L); lua_iolibopen(L); lua_strlibopen(L); lua_mathlibopen(L); lua_dblibopen(L); start_trace(stderr); rc=lua_dofile(L,0); stop_trace(); return rc; }
int trace_vsx(pid_t child) { unsigned long vsx[VSX_MAX]; unsigned long vmx[VMX_MAX + 2][2]; FAIL_IF(start_trace(child)); FAIL_IF(show_vsx(child, vsx)); FAIL_IF(validate_vsx(vsx, fp_load)); FAIL_IF(show_vmx(child, vmx)); FAIL_IF(validate_vmx(vmx, fp_load)); memset(vsx, 0, sizeof(vsx)); memset(vmx, 0, sizeof(vmx)); load_vsx_vmx(fp_load_new, vsx, vmx); FAIL_IF(write_vsx(child, vsx)); FAIL_IF(write_vmx(child, vmx)); FAIL_IF(stop_trace(child)); return TEST_PASS; }
long test2b() { unsigned char *pages; size_t page_size = PAGE_SIZE; size_t addr_size = page_size; int wcount[1], wcount2[1], i, ret; void *args[2]; pthread_t thread; bzero(wcount, sizeof(int)); bzero(wcount2, sizeof(int)); pages = mmap(ADDR_START, addr_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); if (pages == MAP_FAILED) return -errno; fprintf(stderr, "pages = %lx\n", (unsigned long)pages); bzero(pages, addr_size); ret = start_trace((unsigned long)pages, addr_size); if (ret) { fprintf(stderr, "start_trace failed: %s\n", strerror(errno)); return -errno; } fprintf(stderr, "start_trace\n"); args[0] = pages; args[1] = wcount2; pthread_create(&thread, NULL, thread2b, args); usleep(1); for (i = 0 ; i < 10 ; i++) { pages[0]++; usleep(20); } pthread_join(thread, NULL); ret = get_trace(gettid(), wcount); if (ret) { fprintf(stderr, "get_trace failed: %s\n", strerror(errno)); return -errno; } fprintf(stderr, "get_trace\n"); printf("wcount[0]=%02d, wcount2[0]=%02d, page[0]=%d\n", wcount[0], wcount2[0], pages[0]); ret = stop_trace(); if (ret) { fprintf(stderr, "stop_trace failed: %s\n", strerror(errno)); return -errno; } fprintf(stderr, "stop_trace\n"); if (wcount[0] < 9 || wcount2[0] > 0) return -1; return 0; }
long test2a() { unsigned char *pages; size_t page_size = PAGE_SIZE; size_t addr_size = page_size * PAGE_NUM; int wcount[PAGE_NUM], ret, i, stat; unsigned long addr; pid_t pid; bzero(wcount, PAGE_NUM * sizeof(int)); pages = mmap(ADDR_START, addr_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); if (pages == MAP_FAILED) return -errno; fprintf(stderr, "pages = %lx\n", (unsigned long)pages); ret = start_trace((unsigned long)pages, addr_size); if (ret) { fprintf(stderr, "start_trace failed: %s\n", strerror(errno)); return -errno; } fprintf(stderr, "start_trace\n"); pid = fork(); if (pid < 0) { fprintf(stderr, "fork failed: %s\n", strerror(errno)); return -errno; } if (pid == 0) { for (i = 0 ; i < 10 ; i++) { for (addr = 0 ; addr < addr_size ; addr += page_size) pages[addr]++; usleep(20); } exit(0); } wait(&stat); for (i = 0 ; i < 10 ; i++) { for (addr = 0 ; addr < addr_size ; addr += page_size) pages[addr]++; usleep(20); } ret = get_trace(getpid(), wcount); if (ret) { fprintf(stderr, "get_trace failed: %s\n", strerror(errno)); return -errno; } fprintf(stderr, "get_trace\n"); for (i = 0 ; i < PAGE_NUM ; i++) printf("wcount[%d] = %d, page[%04X] = %d\n", i, wcount[i], i * page_size, pages[i * page_size]); ret = stop_trace(); if (ret) { fprintf(stderr, "stop_trace failed: %s\n", strerror(errno)); return -errno; } fprintf(stderr, "stop_trace\n"); for (i = 0 ; i < PAGE_NUM ; i++) if (pages[i * page_size] != 10) return -1; return 0; }
long test1a() { unsigned char *pages; size_t page_size = PAGE_SIZE; size_t addr_size = page_size * PAGE_NUM; unsigned long addr; int wcount[PAGE_NUM], i, ret; bzero(wcount, PAGE_NUM * sizeof(int)); pages = mmap(ADDR_START, addr_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); if (pages == MAP_FAILED) return -errno; fprintf(stderr, "pages = %lx\n", (unsigned long)pages); for (i = 0 ; i < 1000 ; i++) { for (addr = 0 ; addr < addr_size ; addr += page_size) pages[addr] = 0; usleep(1); } fprintf(stderr, "write each page 1000 times\n"); ret = start_trace((unsigned long)pages, addr_size); if (ret) { fprintf(stderr, "start_trace failed: %s\n", strerror(errno)); return -errno; } fprintf(stderr, "start_trace\n"); for (i = 0 ; i < 1000 ; i++) { for (addr = 0 ; addr < addr_size ; addr += page_size) pages[addr] = 0; usleep(1); } fprintf(stderr, "write each page 1000 times\n"); ret = get_trace(getpid(), wcount); if (ret) { fprintf(stderr, "get_trace failed: %s\n", strerror(errno)); return -errno; } fprintf(stderr, "get_trace\n"); for (i = 0 ; i < PAGE_NUM ; i++) printf("wcount[%d] = %d\n", i, wcount[i]); ret = stop_trace(); if (ret) { fprintf(stderr, "stop_trace failed: %s\n", strerror(errno)); return -errno; } fprintf(stderr, "stop_trace\n"); for (i = 0 ; i < PAGE_NUM ; i++) if (wcount[i] < 900) return -1; return 0; }
long test1b() { unsigned char *pages; size_t page_size = PAGE_SIZE; size_t addr_size = page_size * PAGE_NUM; unsigned long addr; int wcount[PAGE_NUM], wcount2[PAGE_NUM], i, ret; void *args[2]; pthread_t thread; bzero(wcount, PAGE_NUM * sizeof(int)); bzero(wcount2, PAGE_NUM * sizeof(int)); pages = mmap(ADDR_START, addr_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); if (pages == MAP_FAILED) return -errno; fprintf(stderr, "pages = %lx\n", (unsigned long)pages); bzero(pages, addr_size); ret = start_trace((unsigned long)pages, addr_size); if (ret) { fprintf(stderr, "start_trace failed: %s\n", strerror(errno)); return -errno; } fprintf(stderr, "start_trace\n"); args[0] = pages; args[1] = wcount2; pthread_create(&thread, NULL, thread1b, args); pthread_join(thread, NULL); usleep(10); for (i = 0 ; i < 10 ; i++) { for (addr = 0 ; addr < addr_size ; addr += page_size) pages[addr]++; usleep(20); } ret = get_trace(gettid(), wcount); if (ret) { fprintf(stderr, "get_trace failed: %s\n", strerror(errno)); return -errno; } fprintf(stderr, "get_trace\n"); for (i = 0 ; i < PAGE_NUM ; i++) printf("wcount[%d]=%02d, wcount2[%d]=%02d, page[%04X]=%d\n", i, wcount[i], i, wcount2[i], i * page_size, pages[i * page_size]); ret = stop_trace(); if (ret) { fprintf(stderr, "stop_trace failed: %s\n", strerror(errno)); return -errno; } fprintf(stderr, "stop_trace\n"); for (i = 0 ; i < PAGE_NUM ; i++) if (wcount[i] < 9 || wcount[i] > 10 || wcount2[i] < 9 || wcount[i] > 10) return -1; return 0; }
void trace_stack (int argc, char **argv) { enum stack_type trace_type = STACK_REPORT; int c; if (argc < 2) usage(argv); if (strcmp(argv[1], "stack") != 0) usage(argv); for (;;) { int option_index = 0; static struct option long_options[] = { {"start", no_argument, NULL, OPT_start}, {"stop", no_argument, NULL, OPT_stop}, {"reset", no_argument, NULL, OPT_reset}, {"help", no_argument, NULL, '?'}, {NULL, 0, NULL, 0} }; c = getopt_long (argc-1, argv+1, "+h?", long_options, &option_index); if (c == -1) break; switch (c) { case 'h': usage(argv); break; case OPT_start: trace_type = STACK_START; break; case OPT_stop: trace_type = STACK_STOP; break; case OPT_reset: trace_type = STACK_RESET; break; default: usage(argv); } } test_available(); switch (trace_type) { case STACK_START: start_trace(); break; case STACK_STOP: stop_trace(); break; case STACK_RESET: reset_trace(); break; default: read_trace(); break; } return; }
asmlinkage void __init start_kernel(void) { char * command_line; extern struct kernel_param __start___param[], __stop___param[]; smp_setup_processor_id(); /* * Need to run as early as possible, to initialize the * lockdep hash: */ lockdep_init(); start_trace(); local_irq_disable(); early_boot_irqs_off(); early_init_irq_lock_class(); /* * Interrupts are still disabled. Do necessary setups, then * enable them */ lock_kernel(); boot_cpu_init(); page_address_init(); printk(KERN_NOTICE); printk(linux_banner); setup_arch(&command_line); setup_per_cpu_areas(); smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */ /* * Set up the scheduler prior starting any interrupts (such as the * timer interrupt). Full topology setup happens at smp_init() * time - but meanwhile we still have a functioning scheduler. */ sched_init(); /* * Disable preemption - early bootup scheduling is extremely * fragile until we cpu_idle() for the first time. */ preempt_disable(); build_all_zonelists(); page_alloc_init(); early_init_hardirqs(); printk(KERN_NOTICE "Kernel command line: %s\n", saved_command_line); parse_early_param(); parse_args("Booting kernel", command_line, __start___param, __stop___param - __start___param, &unknown_bootoption); sort_main_extable(); unwind_init(); trap_init(); rcu_init(); init_IRQ(); pidhash_init(); clockevents_init(); init_timers(); hrtimers_init(); softirq_init(); timekeeping_init(); time_init(); profile_init(); if (!irqs_disabled()) printk("start_kernel(): bug: interrupts were enabled early\n"); early_boot_irqs_on(); local_irq_enable(); /* * HACK ALERT! This is early. We're enabling the console before * we've done PCI setups etc, and console_init() must be aware of * this. But we do want output early, in case something goes wrong. */ console_init(); if (panic_later) panic(panic_later, panic_param); lockdep_info(); /* * Need to run this when irqs are enabled, because it wants * to self-test [hard/soft]-irqs on/off lock inversion bugs * too: */ locking_selftest(); #ifdef CONFIG_BLK_DEV_INITRD if (initrd_start && !initrd_below_start_ok && initrd_start < min_low_pfn << PAGE_SHIFT) { printk(KERN_CRIT "initrd overwritten (0x%08lx < 0x%08lx) - " "disabling it.\n",initrd_start,min_low_pfn << PAGE_SHIFT); initrd_start = 0; } #endif vfs_caches_init_early(); cpuset_init_early(); mem_init(); kmem_cache_init(); setup_per_cpu_pageset(); numa_policy_init(); if (late_time_init) late_time_init(); calibrate_delay(); pidmap_init(); pgtable_cache_init(); prio_tree_init(); anon_vma_init(); #ifdef CONFIG_X86 if (efi_enabled) efi_enter_virtual_mode(); #endif fork_init(num_physpages); proc_caches_init(); buffer_init(); unnamed_dev_init(); key_init(); security_init(); vfs_caches_init(num_physpages); radix_tree_init(); signals_init(); /* rootfs populating might need page-writeback */ page_writeback_init(); #ifdef CONFIG_PROC_FS proc_root_init(); #endif cpuset_init(); taskstats_init_early(); delayacct_init(); check_bugs(); acpi_early_init(); /* before LAPIC and SMP init */ #ifdef CONFIG_PREEMPT_RT WARN_ON(irqs_disabled()); #endif /* Do the rest non-__init'ed, we're now alive */ rest_init(); }