/** * detector_init - Standard module initialization code */ static int detector_init(void) { int ret = -ENOMEM; printk(KERN_INFO BANNER "version %s\n", VERSION); ret = init_stats(); if (0 != ret) goto out; ret = init_debugfs(); if (0 != ret) goto err_stats; if (enabled) ret = start_kthread(); goto out; err_stats: ring_buffer_free(ring_buffer); out: return ret; }
void kmain(struct multiboot_info *mbt) { vga_init(); gdt_install(); idt_install(); isr_install(); irq_install(); syscalls_install(); puts_c(__kernel_name " kernel v" __kernel_version_str "\n\n", COLOR_LIGHT_BLUE, COLOR_DEFAULT_BG); uint64_t mem; get_multiboot_info(mbt, &mem); extern uint32_t _kernel_memory_end[]; kprintf("End of kernel's memory: 0x%x\n", (uint64_t) (uint32_t) _kernel_memory_end); kprintf("Memory:\n%l B\n%l KB\n%l MB\n%l GB\n", mem, mem / 1024, mem / 1024 / 1024, mem / 1024 / 1024 / 1024); init_paging(); map_page(0xFD7FF000, 0x60000, 3); int *p = (int *) 0xFD7FF000; *p = 12; kprintf("*(0x%x) = %i\n", (uint64_t) (uint32_t) p, *p); map_page(0x10000000, 0x60000, 3); int *p2 = (int *) 0x10000000; kprintf("*(0x%x) = %i\n", (uint64_t) (uint32_t) p2, *p2); print_next_available_page(); uint32_t ap = allocate_page(203); map_page(ap, 0x60000, 3); int *p3 = (int *) ap; kprintf("*(0x%x) = %i\n", (uint64_t) ap, *p3); print_next_available_page(); ap = allocate_page(203); kprintf("ap = 0x%x\n", (uint32_t) ap); struct kthread thread; create_kthread(thread_test, &thread); start_kthread(&thread); kprintf("Returned from thread.\n"); _asm_print_test(); return; }
/** * debug_enable_fwrite - Write function for "enable" debugfs interface * @filp: The active open file structure for the debugfs "file" * @ubuf: The user buffer that contains the value to write * @cnt: The maximum number of bytes to write to "file" * @ppos: The current position in the debugfs "file" * * This function provides a write implementation for the "enable" debugfs * interface to the hardware latency detector. Can be used to enable or * disable the detector, which will have the side-effect of possibly * also resetting the global stats and kicking off the measuring * kthread (on an enable) or the converse (upon a disable). */ static ssize_t debug_enable_fwrite(struct file *filp, const char __user *ubuf, size_t cnt, loff_t *ppos) { char buf[4]; int csize = min(cnt, sizeof(buf)); long val = 0; int err = 0; memset(buf, '\0', sizeof(buf)); if (copy_from_user(buf, ubuf, csize)) return -EFAULT; buf[sizeof(buf)-1] = '\0'; /* just in case */ err = strict_strtoul(buf, 10, &val); if (0 != err) return -EINVAL; if (val) { if (enabled) goto unlock; enabled = 1; __reset_stats(); if (start_kthread()) return -EFAULT; } else { if (!enabled) goto unlock; enabled = 0; err = stop_kthread(); if (err) { printk(KERN_ERR BANNER "cannot stop kthread\n"); return -EFAULT; } wake_up(&data.wq); /* reader(s) should return */ } unlock: return csize; }