├── .clang-format ├── .gitignore ├── Documentation ├── CodingStyle ├── IRQ-affinity.txt ├── IRQ-domain.txt ├── IRQ.txt ├── LegoOS-OSDI-Slides.key ├── boot.txt ├── configs │ ├── 1P-1M-1S-Memory │ ├── 1P-1M-1S-Processor │ ├── 1P-1M-1S-fit_config.h │ ├── 1P-1M-Memory │ ├── 1P-1M-Processor │ └── 1P-1M-Processor-Output ├── console_codes ├── counters.md ├── exception-tables.txt ├── google-trace.md ├── kernel-stacks ├── logo.png ├── mc-config.md ├── memory-barrier.txt ├── mm.txt ├── parameters.rst ├── parameters.txt ├── pcache │ └── smp-design-consideration.md ├── printk-formats.txt ├── profile.md ├── scheduler │ └── completion.txt ├── strace.md ├── timers │ ├── NO_HZ.txt │ ├── hpet.txt │ ├── timekeeping.txt │ └── timers-howto.txt ├── trampoline.txt └── vm │ └── split_page_table_lock ├── Kbuild ├── Kconfig ├── LICENSE ├── Makefile ├── README.md ├── arch └── x86 │ ├── Kconfig │ ├── Makefile │ ├── boot │ ├── Makefile │ ├── a20.c │ ├── bioscall.S │ ├── boot.h │ ├── cmdline.c │ ├── code16gcc.h │ ├── compressed │ │ ├── .gitignore │ │ ├── Makefile │ │ ├── head_64.S │ │ ├── mkpiggy.c │ │ └── vmImage.lds.S │ ├── copy.S │ ├── early_serial_console.c │ ├── header.S │ ├── install.sh │ ├── main.c │ ├── memory.c │ ├── pm.c │ ├── pmjump.S │ ├── printf.c │ ├── regs.c │ ├── setup.ld │ ├── stdarg.h │ ├── string.c │ ├── string.h │ ├── tools │ │ ├── .gitignore │ │ └── build.c │ ├── tty.c │ ├── version.c │ ├── vesa.h │ ├── video-bios.c │ ├── video-mode.c │ ├── video-vesa.c │ ├── video-vga.c │ ├── video.c │ └── video.h │ ├── configs │ └── x86_64_defconfig │ ├── entry │ ├── Makefile │ ├── abi.h │ ├── common.c │ ├── entry_64.S │ ├── entry_64_compat.S │ ├── strace.c │ ├── syscall_64.c │ ├── syscalls │ │ ├── Makefile │ │ ├── syscall_64.tbl │ │ ├── syscallhdr.sh │ │ └── syscalltbl.sh │ └── vsyscall │ │ ├── Makefile │ │ ├── vsyscall_64.c │ │ └── vsyscall_emu_64.S │ ├── include │ └── asm │ │ ├── alternative-asm.h │ │ ├── alternative.h │ │ ├── apic.h │ │ ├── apic_types.h │ │ ├── asm.h │ │ ├── atomic-long.h │ │ ├── atomic.h │ │ ├── atomic64.h │ │ ├── auxvec.h │ │ ├── barrier-generic.h │ │ ├── barrier.h │ │ ├── bitops.h │ │ ├── boot.h │ │ ├── bootparam.h │ │ ├── byteorder.h │ │ ├── cache.h │ │ ├── checksum.h │ │ ├── cmpxchg.h │ │ ├── compat.h │ │ ├── current.h │ │ ├── delay.h │ │ ├── desc.h │ │ ├── div64.h │ │ ├── dma-mapping.h │ │ ├── dma.h │ │ ├── e820.h │ │ ├── elf.h │ │ ├── extable.h │ │ ├── fixmap.h │ │ ├── fpu │ │ ├── api.h │ │ ├── internal.h │ │ ├── regset.h │ │ ├── signal.h │ │ ├── types.h │ │ └── xstate.h │ │ ├── frame.h │ │ ├── futex.h │ │ ├── hpet.h │ │ ├── hw_irq.h │ │ ├── i8259.h │ │ ├── ia32.h │ │ ├── intel-family.h │ │ ├── io.h │ │ ├── io_apic.h │ │ ├── ipi.h │ │ ├── irq.h │ │ ├── irq_regs.h │ │ ├── irq_vectors.h │ │ ├── kdebug.h │ │ ├── linkage.h │ │ ├── mc146818rtc.h │ │ ├── msi.h │ │ ├── msr.h │ │ ├── mutex.h │ │ ├── nops.h │ │ ├── numa.h │ │ ├── page.h │ │ ├── page_types.h │ │ ├── pci.h │ │ ├── percpu.h │ │ ├── pgalloc.h │ │ ├── pgtable.h │ │ ├── pgtable_types.h │ │ ├── prctl.h │ │ ├── processor-features-flags.h │ │ ├── processor-features.h │ │ ├── processor-flags.h │ │ ├── processor.h │ │ ├── ptrace.h │ │ ├── rmwcc.h │ │ ├── rwsem.h │ │ ├── segment.h │ │ ├── setup.h │ │ ├── sigcontext.h │ │ ├── sigframe.h │ │ ├── signal.h │ │ ├── smp.h │ │ ├── sparsemem.h │ │ ├── spinlock.h │ │ ├── stacktrace.h │ │ ├── stat.h │ │ ├── string.h │ │ ├── string_64.h │ │ ├── switch_to.h │ │ ├── syscalls.h │ │ ├── thread_info.h │ │ ├── time.h │ │ ├── timex.h │ │ ├── tlbflush.h │ │ ├── trampoline.h │ │ ├── traps.h │ │ ├── tsc.h │ │ ├── tss.h │ │ ├── types.h │ │ ├── uaccess.h │ │ ├── uaccess_64.h │ │ ├── ucontext.h │ │ ├── unwind.h │ │ ├── user.h │ │ ├── user32.h │ │ ├── user_64.h │ │ ├── vsyscall.h │ │ └── word-at-a-time.h │ ├── kernel │ ├── .gitignore │ ├── Makefile │ ├── acpi │ │ ├── Makefile │ │ ├── boot.c │ │ └── numa.c │ ├── alternative.c │ ├── apic │ │ ├── Makefile │ │ ├── apic.c │ │ ├── apic_flat.c │ │ ├── io_apic.c │ │ ├── ipi.c │ │ ├── msi.c │ │ └── vector.c │ ├── asm-offsets.c │ ├── cpu │ │ ├── .gitignore │ │ ├── Makefile │ │ ├── common.c │ │ ├── intel.c │ │ ├── mkcapflags.sh │ │ ├── powerflags.c │ │ ├── scattered.c │ │ └── topology.c │ ├── dumpstack.c │ ├── e820.c │ ├── fpu │ │ ├── Makefile │ │ ├── core.c │ │ ├── init.c │ │ ├── regset.c │ │ ├── signal.c │ │ └── xstate.c │ ├── head64.c │ ├── head_64.S │ ├── hpet.c │ ├── i8253.c │ ├── i8259.c │ ├── irq.c │ ├── irqinit.c │ ├── pci-dma.c │ ├── pci-nommu.c │ ├── percpu.c │ ├── process.c │ ├── ptrace.c │ ├── rtc.c │ ├── setup.c │ ├── signal.c │ ├── smp.c │ ├── smpboot.c │ ├── time.c │ ├── traps.c │ ├── tsc.c │ ├── unwind_frame.c │ ├── unwind_guess.c │ └── vmImage.lds.S │ ├── lib │ ├── Makefile │ ├── csum-partial_64.c │ ├── delay.c │ ├── getuser.S │ ├── memcpy_64.S │ ├── memmove_64.S │ ├── memset_64.S │ ├── putuser.S │ ├── rwsem.S │ ├── uaccess.S │ └── usercopy.c │ ├── mm │ ├── Makefile │ ├── debug.c │ ├── dumppgtable.c │ ├── extable.c │ ├── fault.c │ ├── init.c │ ├── ioremap.c │ ├── numa.c │ ├── pgtable.c │ └── tlb.c │ ├── pci │ ├── Makefile │ ├── bus_numa.c │ ├── bus_numa.h │ ├── common.c │ ├── direct.c │ ├── early.c │ ├── irq.c │ ├── mmconfig-shared.c │ └── mmconfig_64.c │ └── realmode │ ├── Makefile │ ├── piggy.S │ └── rm │ ├── .gitignore │ ├── Makefile │ ├── ld.lds.S │ └── trampoline.S ├── drivers ├── Kconfig ├── Makefile ├── acpi │ ├── Makefile │ ├── fadt.c │ ├── internal.h │ ├── madt.c │ ├── numa.c │ ├── table.c │ └── table_install.c ├── base │ ├── Makefile │ └── core.c ├── eth │ ├── Kconfig │ ├── Makefile │ ├── e1000.c │ ├── tg3.c │ └── tg3.h ├── infiniband │ ├── Kconfig │ ├── Makefile │ ├── core │ │ ├── Makefile │ │ ├── agent.c │ │ ├── agent.h │ │ ├── cache.c │ │ ├── cm.c │ │ ├── cm_msgs.h │ │ ├── core_priv.h │ │ ├── device.c │ │ ├── iwcm.c │ │ ├── iwcm.h │ │ ├── mad.c │ │ ├── mad_priv.h │ │ ├── mad_rmpp.c │ │ ├── mad_rmpp.h │ │ ├── multicast.c │ │ ├── packer.c │ │ ├── sa.h │ │ ├── sa_query.c │ │ ├── smi.c │ │ ├── smi.h │ │ ├── ud_header.c │ │ ├── uverbs.h │ │ └── verbs.c │ ├── hw │ │ ├── Makefile │ │ ├── mlx4 │ │ │ ├── Kconfig │ │ │ ├── Makefile │ │ │ ├── ah.c │ │ │ ├── cm.c │ │ │ ├── cq.c │ │ │ ├── doorbell.c │ │ │ ├── mad.c │ │ │ ├── main.c │ │ │ ├── mlx4_ib.h │ │ │ ├── mr.c │ │ │ ├── qp.c │ │ │ ├── srq.c │ │ │ └── user.h │ │ └── mlx4en │ │ │ ├── Kconfig │ │ │ ├── Makefile │ │ │ ├── alloc.c │ │ │ ├── catas.c │ │ │ ├── cmd.c │ │ │ ├── cq.c │ │ │ ├── eq.c │ │ │ ├── fw.c │ │ │ ├── fw.h │ │ │ ├── icm.c │ │ │ ├── icm.h │ │ │ ├── intf.c │ │ │ ├── main.c │ │ │ ├── mcg.c │ │ │ ├── mlx4.h │ │ │ ├── mr.c │ │ │ ├── pd.c │ │ │ ├── port.c │ │ │ ├── profile.c │ │ │ ├── qp.c │ │ │ ├── reset.c │ │ │ ├── sense.c │ │ │ └── srq.c │ └── ulp │ │ ├── Makefile │ │ └── ipoib │ │ ├── Kconfig │ │ ├── Makefile │ │ ├── ipoib.h │ │ ├── ipoib_cm.c │ │ ├── ipoib_ethtool.c │ │ ├── ipoib_ib.c │ │ ├── ipoib_main.c │ │ ├── ipoib_multicast.c │ │ ├── ipoib_verbs.c │ │ └── ipoib_vlan.c ├── pci │ ├── Makefile │ ├── access.c │ ├── bus.c │ ├── driver.c │ ├── host-bridge.c │ ├── msi.c │ ├── pci.c │ ├── pci.h │ ├── probe.c │ └── search.c └── tty │ ├── Kconfig │ ├── Makefile │ ├── n_tty.c │ ├── serial │ ├── Makefile │ └── serial.c │ ├── tty_io.c │ └── vt │ ├── Makefile │ ├── dummycon.c │ ├── vga.h │ ├── vgacon.c │ └── vt.c ├── include ├── lego │ ├── acpi.h │ ├── atomic.h │ ├── auxvec.h │ ├── bcd.h │ ├── bitmap.h │ ├── bitops.h │ ├── bug.h │ ├── byteorder.h │ ├── checkpoint.h │ ├── checksum.h │ ├── clockevent.h │ ├── clocksource.h │ ├── comp_common.h │ ├── comp_memory.h │ ├── comp_storage.h │ ├── compat.h │ ├── compiler.h │ ├── completion.h │ ├── console.h │ ├── const.h │ ├── cpumask.h │ ├── cputime.h │ ├── cred.h │ ├── ctype.h │ ├── debug_locks.h │ ├── delay.h │ ├── device.h │ ├── distvm.h │ ├── dma-attrs.h │ ├── dma-mapping.h │ ├── dmapool.h │ ├── early_ioremap.h │ ├── err.h │ ├── errno.h │ ├── extable.h │ ├── fcntl.h │ ├── fdtable.h │ ├── files.h │ ├── fit_ibapi.h │ ├── futex.h │ ├── getcpu.h │ ├── gfp.h │ ├── hash.h │ ├── hashtable.h │ ├── hweight.h │ ├── init.h │ ├── irq.h │ ├── irqchip.h │ ├── irqdesc.h │ ├── irqdomain.h │ ├── jhash.h │ ├── jiffies.h │ ├── kallsyms.h │ ├── kbuild.h │ ├── kconfig.h │ ├── kernel.h │ ├── kernel_stat.h │ ├── kref.h │ ├── kthread.h │ ├── ktime.h │ ├── linkage.h │ ├── list.h │ ├── llist.h │ ├── log2.h │ ├── magic.h │ ├── math64.h │ ├── memblock.h │ ├── memory.h │ ├── memory_model.h │ ├── mlx4 │ │ ├── cmd.h │ │ ├── cq.h │ │ ├── device.h │ │ ├── doorbell.h │ │ ├── driver.h │ │ ├── qp.h │ │ └── srq.h │ ├── mm.h │ ├── mm_debug.h │ ├── mm_types.h │ ├── mm_zone.h │ ├── mmap.h │ ├── module.h │ ├── msi.h │ ├── mutex.h │ ├── net.h │ ├── netmacro.h │ ├── nodemask.h │ ├── numa.h │ ├── page-flags-layout.h │ ├── page-flags.h │ ├── panic.h │ ├── pci.h │ ├── pci_ids.h │ ├── pci_regs.h │ ├── percpu.h │ ├── pfn.h │ ├── pgfault.h │ ├── pid.h │ ├── plist.h │ ├── preempt.h │ ├── printk.h │ ├── profile.h │ ├── profile_point.h │ ├── ptrace.h │ ├── radixtree.h │ ├── random.h │ ├── range.h │ ├── ratelimit.h │ ├── rbtree.h │ ├── rcupdate.h │ ├── regset.h │ ├── resource.h │ ├── rlimit.h │ ├── rpc │ │ ├── opcode.h │ │ ├── struct_common.h │ │ ├── struct_m2m.h │ │ ├── struct_m2s.h │ │ ├── struct_p2gm.h │ │ ├── struct_p2m.h │ │ └── struct_p2s.h │ ├── rwsem.h │ ├── scatterlist.h │ ├── sched.h │ ├── sched_prio.h │ ├── sched_rt.h │ ├── screen_info.h │ ├── sections.h │ ├── semaphore.h │ ├── seq_file.h │ ├── seqlock.h │ ├── siginfo.h │ ├── signal.h │ ├── signalfd.h │ ├── sizes.h │ ├── slab.h │ ├── smp.h │ ├── smpboot.h │ ├── socket.h │ ├── spinlock.h │ ├── stat.h │ ├── stddef.h │ ├── stop_machine.h │ ├── strace.h │ ├── string.h │ ├── stringify.h │ ├── swab.h │ ├── syscalls.h │ ├── sysinfo.h │ ├── termios.h │ ├── time.h │ ├── timekeeping.h │ ├── timer.h │ ├── timex.h │ ├── tracepoint.h │ ├── tty.h │ ├── typecheck.h │ ├── types.h │ ├── uaccess.h │ ├── utsname.h │ ├── vmImage.lds.h │ ├── vmalloc.h │ ├── vmstat.h │ ├── wait.h │ ├── waitpid.h │ └── workqueue.h ├── memory │ ├── distvm.h │ ├── elf.h │ ├── file_ops.h │ ├── file_types.h │ ├── loader.h │ ├── mm.h │ ├── pgcache.h │ ├── pid.h │ ├── ramfs.h │ ├── replica.h │ ├── replica_types.h │ ├── stat.h │ ├── task.h │ ├── thread_pool.h │ ├── vm-pgtable.h │ └── vm.h ├── monitor │ ├── common.h │ ├── gmm_handler.h │ └── gpm_handler.h ├── net │ ├── arch │ │ ├── cc.h │ │ ├── perf.h │ │ ├── perror.h │ │ ├── queue.h │ │ ├── setjmp.h │ │ ├── sys_arch.h │ │ ├── thread.h │ │ └── threadq.h │ ├── e1000.h │ ├── ipv6 │ │ └── lwip │ │ │ ├── icmp.h │ │ │ ├── inet.h │ │ │ ├── ip.h │ │ │ └── ip_addr.h │ ├── lwip │ │ ├── api.h │ │ ├── api_msg.h │ │ ├── arch.h │ │ ├── autoip.h │ │ ├── debug.h │ │ ├── def.h │ │ ├── dhcp.h │ │ ├── dns.h │ │ ├── err.h │ │ ├── icmp.h │ │ ├── igmp.h │ │ ├── inet.h │ │ ├── inet_chksum.h │ │ ├── init.h │ │ ├── ip.h │ │ ├── ip_addr.h │ │ ├── ip_frag.h │ │ ├── mem.h │ │ ├── memp.h │ │ ├── memp_std.h │ │ ├── netbuf.h │ │ ├── netdb.h │ │ ├── netif.h │ │ ├── netifapi.h │ │ ├── opt.h │ │ ├── pbuf.h │ │ ├── raw.h │ │ ├── sio.h │ │ ├── snmp.h │ │ ├── snmp_asn1.h │ │ ├── snmp_msg.h │ │ ├── snmp_structs.h │ │ ├── sockets.h │ │ ├── stats.h │ │ ├── sys.h │ │ ├── tcp.h │ │ ├── tcpip.h │ │ └── udp.h │ ├── lwipopts.h │ └── netif │ │ ├── etharp.h │ │ ├── loopif.h │ │ ├── ppp_oe.h │ │ └── slipif.h ├── processor │ ├── distvm.h │ ├── fs.h │ ├── node.h │ ├── pcache.h │ ├── pcache_config.h │ ├── pcache_debug.h │ ├── pcache_evict.h │ ├── pcache_stat.h │ ├── pcache_types.h │ ├── pcache_victim.h │ ├── pgtable.h │ ├── processor.h │ ├── processor_types.h │ ├── replication.h │ ├── statfs.h │ ├── vnode.h │ ├── vnode_types.h │ └── zerofill.h ├── rdma │ ├── ib_addr.h │ ├── ib_cache.h │ ├── ib_cm.h │ ├── ib_fmr_pool.h │ ├── ib_mad.h │ ├── ib_marshall.h │ ├── ib_pack.h │ ├── ib_pma.h │ ├── ib_sa.h │ ├── ib_smi.h │ ├── ib_verbs.h │ ├── iw_cm.h │ ├── rdma_cm.h │ └── rdma_cm_ib.h └── uapi │ ├── elf.h │ ├── fit.h │ ├── limits.h │ ├── prctl.h │ ├── processor │ └── pcache.h │ ├── rdma │ └── ib_user_verbs.h │ └── sysinfo.h ├── init ├── Kconfig ├── Makefile ├── calibrate.c ├── init_task.c ├── main.c └── version.c ├── kernel ├── Kconfig.hz ├── Kconfig.preempt ├── Makefile ├── bounds.c ├── coredump.c ├── cpu.c ├── exit.c ├── extable.c ├── fork.c ├── futex.c ├── irq │ ├── Kconfig │ ├── Makefile │ ├── chip.c │ ├── debug.h │ ├── dummychip.c │ ├── handle.c │ ├── irqaction.c │ ├── irqdesc.c │ ├── irqdomain.c │ └── msi.c ├── itimer.c ├── kallsyms.c ├── kthread.c ├── locking │ ├── Kconfig │ ├── Makefile │ ├── rwsem-xadd.c │ ├── rwsem.c │ ├── semaphore.c │ └── spinlock.c ├── madvise.c ├── mutex.c ├── panic.c ├── param.c ├── pid.c ├── printk.c ├── profile │ ├── Makefile │ ├── boot.c │ ├── heatmap.c │ └── point.c ├── resource.c ├── sched │ ├── Makefile │ ├── completion.c │ ├── core.c │ ├── cputime.c │ ├── debug.c │ ├── idle.c │ ├── sched.h │ ├── task_dl.c │ ├── task_fair.c │ ├── task_idle.c │ ├── task_rt.c │ ├── task_stop.c │ └── wait.c ├── signal.c ├── smp.c ├── smpboot.c ├── stop_machine.c ├── sys.c ├── time │ ├── Makefile │ ├── clockevents.c │ ├── clocksource.c │ ├── internal.h │ ├── jiffies.c │ ├── ntp.c │ ├── posix-timers.c │ ├── tick-common.c │ ├── tick-internal.h │ ├── time.c │ ├── timekeeping.c │ └── timer.c └── workqueue.c ├── lib ├── Makefile ├── bcd.c ├── bitmap.c ├── cmdline.c ├── cpumask.c ├── ctype.c ├── dump_remote_cpustack.c ├── dump_task_struct.c ├── find_bit.c ├── hexdump.c ├── hweight.c ├── kstrtox.c ├── plist.c ├── radix-tree.c ├── random.c ├── ratelimit.c ├── rbtree.c ├── scatterlist.c ├── sched.c ├── sort.c ├── string.c ├── strncpy_from_user.c ├── strnlen_user.c └── vsprintf.c ├── linux-modules ├── .gitignore ├── Makefile ├── fit │ ├── Makefile │ ├── fit.h │ ├── fit_config.h │ ├── fit_ibapi.c │ ├── fit_internal.c │ ├── fit_internal.h │ └── fit_machine.c ├── monitor │ ├── Makefile │ ├── gm_dispatcher │ │ ├── Makefile │ │ └── lego_gm_dispatcher.c │ ├── gmm │ │ ├── Makefile │ │ └── lego_gmm.c │ ├── gpm │ │ ├── Makefile │ │ └── lego_gpm.c │ ├── gsm │ │ ├── Makefile │ │ ├── core.c │ │ ├── handlers.c │ │ └── hlist.c │ ├── gum │ │ ├── Makefile │ │ └── lego_gum.c │ └── include │ │ ├── common.h │ │ ├── gmm.h │ │ ├── gpm.h │ │ ├── gsm.h │ │ ├── gum.h │ │ └── monitor_config.h └── storage │ ├── CONFIG_LEGO_STORAGE.h │ ├── Makefile │ ├── common.h │ ├── core.c │ ├── file_ops.c │ ├── handlers.c │ ├── metadata.c │ ├── permission.c │ ├── replica.c │ ├── replica.h │ ├── stat.c │ ├── stat.h │ └── storage.h ├── managers ├── Kconfig ├── Makefile ├── common.c ├── lib │ ├── Makefile │ └── dump_snapshot.c ├── memory │ ├── Kconfig │ ├── Makefile │ ├── core.c │ ├── file_ops.c │ ├── handle_checkpoint.c │ ├── handle_execve.c │ ├── handle_file.c │ ├── handle_fork.c │ ├── handle_mmap.c │ ├── handle_pcache │ │ ├── Makefile │ │ ├── fault.c │ │ ├── internal.h │ │ └── prefetch.c │ ├── loader │ │ ├── Makefile │ │ ├── core.c │ │ └── elf.c │ ├── m2s_read_write.c │ ├── missing_syscalls.c │ ├── monitor │ │ ├── Makefile │ │ └── gmm_handler.c │ ├── pgcache │ │ ├── Makefile │ │ ├── alloc.c │ │ ├── dirtylist.c │ │ ├── eviction.c │ │ ├── handle_special.c │ │ ├── hlist.c │ │ └── read_write.c │ ├── ramfs │ │ ├── Makefile │ │ ├── core.c │ │ └── piggy.S │ ├── replica │ │ ├── Makefile │ │ ├── memory_core.c │ │ ├── memory_debug.c │ │ ├── memory_flush.c │ │ └── vma.c │ ├── stat.c │ ├── task.c │ ├── test.c │ └── vm │ │ ├── Makefile │ │ ├── debug.c │ │ ├── dist_mmap.c │ │ ├── dist_mmap_dump.c │ │ ├── dist_mmap_test.c │ │ ├── fault.c │ │ ├── gup.c │ │ ├── mmap.c │ │ ├── pgtable.c │ │ └── uaccess.c ├── pin.c ├── processor │ ├── Kconfig │ ├── Makefile │ ├── checkpoint │ │ ├── Kconfig │ │ ├── Makefile │ │ ├── core.c │ │ ├── internal.h │ │ ├── restore.c │ │ └── save.c │ ├── core.c │ ├── exec.c │ ├── fork.c │ ├── fs │ │ ├── Kconfig │ │ ├── Makefile │ │ ├── default_f_ops.c │ │ ├── dev │ │ │ ├── Makefile │ │ │ ├── core.c │ │ │ ├── dev_null.c │ │ │ └── dev_random.c │ │ ├── drop_cache.c │ │ ├── fcntl.c │ │ ├── file_size.c │ │ ├── ioctl.c │ │ ├── lseek.c │ │ ├── namei.c │ │ ├── open.c │ │ ├── pipe.c │ │ ├── proc │ │ │ ├── Makefile │ │ │ ├── core.c │ │ │ ├── proc_cmdline.c │ │ │ ├── proc_cpuinfo.c │ │ │ ├── proc_meminfo.c │ │ │ ├── proc_processes.c │ │ │ ├── proc_stat.c │ │ │ ├── proc_sys_vm_overcommit.c │ │ │ ├── proc_version.c │ │ │ └── self │ │ │ │ ├── Makefile │ │ │ │ └── status.c │ │ ├── read_write.c │ │ ├── seq_file.c │ │ ├── stat.c │ │ ├── statfs.c │ │ ├── stdio.c │ │ ├── sys │ │ │ ├── Makefile │ │ │ ├── core.c │ │ │ └── sys_devices_system_cpu_online.c │ │ └── truncate.c │ ├── mmap │ │ ├── Makefile │ │ ├── dist_mmap.c │ │ ├── dist_mmap_test.c │ │ └── syscall.c │ ├── monitor │ │ ├── Makefile │ │ ├── gmm.c │ │ ├── gpm.c │ │ ├── gpm_handler.c │ │ └── gsm.c │ ├── pcache │ │ ├── Kconfig │ │ ├── Makefile │ │ ├── alloc.c │ │ ├── clflush.c │ │ ├── debug.c │ │ ├── evict.c │ │ ├── evict_fifo.c │ │ ├── evict_lru.c │ │ ├── evict_random.c │ │ ├── evict_sweep.c │ │ ├── fault.c │ │ ├── init.c │ │ ├── perset.c │ │ ├── piggyback.h │ │ ├── prefetch.c │ │ ├── rmap.c │ │ ├── stat.c │ │ ├── syscall.c │ │ ├── thread.c │ │ ├── victim.c │ │ ├── victim_debug.c │ │ └── victim_flush.c │ ├── pgtable.c │ ├── prctl.c │ ├── processor.h │ ├── replication.c │ ├── rpc_profile.c │ ├── strace │ │ ├── Makefile │ │ ├── core.c │ │ ├── fs.c │ │ ├── internal.h │ │ ├── lib.c │ │ ├── mm.c │ │ └── sched.c │ ├── vnode.c │ ├── wait.c │ └── zerofill_notify.c └── watchdog.c ├── mm ├── Kconfig ├── Makefile ├── debug.c ├── dmapool.c ├── early_ioremap.c ├── init-mm.c ├── maccess.c ├── mbind.c ├── memblock.c ├── memory.c ├── page_alloc.c ├── percpu-vm.c ├── percpu.c ├── slab_common.c ├── slob.c ├── sparse-vmemmap.c ├── sparse.c ├── vmalloc.c └── vmstat.c ├── net ├── Kconfig ├── Makefile ├── input.c ├── lego │ ├── Kconfig │ ├── Makefile │ ├── fit.h │ ├── fit_ibapi.c │ ├── fit_internal.c │ ├── fit_internal.h │ └── fit_machine.c ├── lwip │ ├── FILES │ ├── Makefile │ ├── api │ │ ├── Makefile │ │ ├── api_lib.c │ │ ├── api_msg.c │ │ ├── err.c │ │ ├── netbuf.c │ │ ├── netdb.c │ │ ├── netifapi.c │ │ ├── sockets.c │ │ └── tcpip.c │ ├── core │ │ ├── Makefile │ │ ├── dhcp.c │ │ ├── dns.c │ │ ├── init.c │ │ ├── ipv4 │ │ │ ├── Makefile │ │ │ ├── autoip.c │ │ │ ├── icmp.c │ │ │ ├── igmp.c │ │ │ ├── inet.c │ │ │ ├── inet_chksum.c │ │ │ ├── ip.c │ │ │ ├── ip_addr.c │ │ │ └── ip_frag.c │ │ ├── ipv6 │ │ │ ├── README │ │ │ ├── icmp6.c │ │ │ ├── inet6.c │ │ │ ├── ip6.c │ │ │ └── ip6_addr.c │ │ ├── mem.c │ │ ├── memp.c │ │ ├── netif.c │ │ ├── pbuf.c │ │ ├── raw.c │ │ ├── snmp │ │ │ ├── asn1_dec.c │ │ │ ├── asn1_enc.c │ │ │ ├── mib2.c │ │ │ ├── mib_structs.c │ │ │ ├── msg_in.c │ │ │ └── msg_out.c │ │ ├── stats.c │ │ ├── sys.c │ │ ├── tcp.c │ │ ├── tcp_in.c │ │ ├── tcp_out.c │ │ └── udp.c │ ├── lego │ │ ├── Makefile │ │ ├── arch │ │ │ ├── perror.c │ │ │ ├── sys_arch.c │ │ │ └── thread.c │ │ └── jif │ │ │ ├── jif.c │ │ │ └── jif.h │ └── netif │ │ ├── FILES │ │ ├── Makefile │ │ ├── etharp.c │ │ ├── ethernetif.c │ │ ├── loopif.c │ │ ├── ppp │ │ ├── auth.c │ │ ├── auth.h │ │ ├── chap.c │ │ ├── chap.h │ │ ├── chpms.c │ │ ├── chpms.h │ │ ├── fsm.c │ │ ├── fsm.h │ │ ├── ipcp.c │ │ ├── ipcp.h │ │ ├── lcp.c │ │ ├── lcp.h │ │ ├── magic.c │ │ ├── magic.h │ │ ├── md5.c │ │ ├── md5.h │ │ ├── pap.c │ │ ├── pap.h │ │ ├── ppp.c │ │ ├── ppp.h │ │ ├── ppp_oe.c │ │ ├── pppdebug.h │ │ ├── randm.c │ │ ├── randm.h │ │ ├── vj.c │ │ ├── vj.h │ │ └── vjbsdhdr.h │ │ └── slipif.c ├── ns.h ├── output.c ├── serv.c ├── socket │ ├── Makefile │ ├── epoll.c │ ├── poll.c │ └── sock.c ├── testinput.c ├── testoutput.c └── timer.c ├── scripts ├── Kbuild.include ├── Makefile ├── Makefile.build ├── Makefile.clean ├── Makefile.extrawarn ├── Makefile.host ├── Makefile.library ├── basic │ ├── .gitignore │ ├── Makefile │ ├── bin2c.c │ └── fixdep.c ├── checkincludes.pl ├── checkversion.pl ├── cleanfile ├── faddr2line ├── gcc-goto.sh ├── headerdep.pl ├── kallsyms.c ├── kconfig │ ├── .gitignore │ ├── Makefile │ ├── POTFILES.in │ ├── check.sh │ ├── conf.c │ ├── confdata.c │ ├── expr.c │ ├── expr.h │ ├── gconf.c │ ├── gconf.glade │ ├── images.c │ ├── kxgettext.c │ ├── list.h │ ├── lkc.h │ ├── lkc_proto.h │ ├── lxdialog │ │ ├── .gitignore │ │ ├── BIG.FAT.WARNING │ │ ├── check-lxdialog.sh │ │ ├── checklist.c │ │ ├── dialog.h │ │ ├── inputbox.c │ │ ├── menubox.c │ │ ├── textbox.c │ │ ├── util.c │ │ └── yesno.c │ ├── mconf.c │ ├── menu.c │ ├── merge_config.sh │ ├── nconf.c │ ├── nconf.gui.c │ ├── nconf.h │ ├── qconf.cc │ ├── qconf.h │ ├── streamline_config.pl │ ├── symbol.c │ ├── util.c │ ├── zconf.gperf │ ├── zconf.hash.c_shipped │ ├── zconf.l │ ├── zconf.lex.c_shipped │ ├── zconf.tab.c_shipped │ └── zconf.y ├── link-vmImage.sh ├── mkcompile_h ├── mkmakefile ├── run.sh ├── setlocalversion └── tags.sh └── usr ├── .gitignore ├── Makefile ├── README ├── checkpoint.c ├── client.c ├── exe.c ├── fork.c ├── general.c ├── gpm_test.c ├── includeme.h ├── iops.c ├── large_malloc.c ├── large_malloc_pthread.c ├── mojim_client_rc ├── mojim_server_rc ├── mremap.c ├── munmap.c ├── pcache_bw.c ├── pcache_conflict.c ├── pipe.c ├── posix └── pthread_join.c ├── pthread.c ├── seq.c ├── server.c ├── signal.c ├── stat.c ├── test_eviction-pthread.c ├── test_eviction.c ├── test_fill-pthread.c ├── ubench.c └── vma.c /.gitignore: -------------------------------------------------------------------------------- 1 | .* 2 | *.o 3 | *.i 4 | *.bin 5 | *.elf 6 | 7 | # 8 | # Generated include files 9 | # 10 | include/generated/ 11 | include/config 12 | arch/*/include/generated 13 | 14 | # 15 | # Generated by Kbuild 16 | # 17 | kernel/bounds.s 18 | 19 | arch/x86_64/ 20 | 21 | vmImage 22 | System.map 23 | bzImage 24 | 25 | tags 26 | tags-e 27 | 28 | scripts/kallsyms 29 | 30 | # 31 | # Usually I will mkdir build/ 32 | # make config O=build 33 | # make O=build 34 | # 35 | build/ 36 | 37 | !.gitignore 38 | !.mailmap 39 | !.clang-format 40 | 41 | # 42 | # These are serial output files from QEMU 43 | # 44 | output 45 | output_ttyS0 46 | output_ttyS1 47 | ttyS0 48 | ttyS1 49 | test-output/ 50 | 51 | # 52 | # Files Generated By Doxygen 53 | # 54 | DoxyHTML/ 55 | -------------------------------------------------------------------------------- /Documentation/IRQ.txt: -------------------------------------------------------------------------------- 1 | What is an IRQ? 2 | 3 | An IRQ is an interrupt request from a device. 4 | Currently they can come in over a pin, or over a packet. 5 | Several devices may be connected to the same pin thus 6 | sharing an IRQ. 7 | 8 | An IRQ number is a kernel identifier used to talk about a hardware 9 | interrupt source. Typically this is an index into the global irq_desc 10 | array, but except for what linux/interrupt.h implements the details 11 | are architecture specific. 12 | 13 | An IRQ number is an enumeration of the possible interrupt sources on a 14 | machine. Typically what is enumerated is the number of input pins on 15 | all of the interrupt controller in the system. In the case of ISA 16 | what is enumerated are the 16 input pins on the two i8259 interrupt 17 | controllers. 18 | 19 | Architectures can assign additional meaning to the IRQ numbers, and 20 | are encouraged to in the case where there is any manual configuration 21 | of the hardware involved. The ISA IRQs are a classic example of 22 | assigning this kind of additional meaning. 23 | -------------------------------------------------------------------------------- /Documentation/LegoOS-OSDI-Slides.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WukLab/LegoOS/1f4da8658c3bb20d7bd4088ec52237b8a617f0c7/Documentation/LegoOS-OSDI-Slides.key -------------------------------------------------------------------------------- /Documentation/configs/1P-1M-1S-fit_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LINUX_MODULE_FIT_CONFIG_H_ 11 | #define _LINUX_MODULE_FIT_CONFIG_H_ 12 | 13 | /* FIT module state */ 14 | #define FIT_MODULE_DOWN 0 15 | #define FIT_MODULE_UP 1 16 | 17 | /* Lego cluster config */ 18 | #define CONFIG_FIT_LOCAL_ID 2 19 | #define CONFIG_FIT_NR_NODES 3 20 | #define MAX_NODE CONFIG_FIT_NR_NODES 21 | 22 | /* 23 | * These configruations must match the numbers in P and M 24 | * Otherwise we will fail to connect. 25 | */ 26 | #define CONFIG_FIT_FIRST_QPN (80) 27 | #define CONFIG_FIT_NR_QPS_PER_PAIR (12) 28 | 29 | //#define CONFIG_SOCKET_O_IB 30 | 31 | #endif /* _LINUX_MODULE_FIT_CONFIG_H_ */ 32 | -------------------------------------------------------------------------------- /Documentation/console_codes: -------------------------------------------------------------------------------- 1 | LegoOS supports a subset of VT102 console escape and control sequences 2 | 3 | Check http://man7.org/linux/man-pages/man4/console_codes.4.html 4 | to see the usage. 5 | -------------------------------------------------------------------------------- /Documentation/google-trace.md: -------------------------------------------------------------------------------- 1 | # Google Trace 2 | 3 | This document describes how we leverage [Google Cluster Trace Data](https://github.com/google/cluster-data) to plot Figure 4(a) in the paper. 4 | 5 | The following description is contributed by [Yilun Chen](https://github.com/yilun0206). If you have any questions, please use Github issues. 6 | 7 | The Figure 4(a) was generated by these steps 8 | - (1) Divide the entire tracing period (29 days) to fixed length time slots (length = L). (e.g. we used 5 mins) 9 | - (2) Calculate available normalized memory from machine event table for each time slot. For example, initialize a vector with all 0, if machine A has memory M, that was added at time t0, removed at t1 (t(end) if not be removed), increment all elements that corresponding time slot falls into the range of [t0, t1) by M, and so on so forth. 10 | - (3) Calculate cumulative canonical memory usage of each time slot. For example, also initialize another vector with all 0, if there is a record that task A has memory usage M' between t2 and t3, then increment the element in the vector which corresponding time slot t2 falls into, by M' * ((t3-t2) / L). 11 | - (4) once the two vectors are finalized, use the vector get from step (3) to divide that one from step (2) to generate final vector and plot. -------------------------------------------------------------------------------- /Documentation/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WukLab/LegoOS/1f4da8658c3bb20d7bd4088ec52237b8a617f0c7/Documentation/logo.png -------------------------------------------------------------------------------- /Kconfig: -------------------------------------------------------------------------------- 1 | mainmenu "LegoOS/$ARCH $KERNELVERSION Kernel Configuration" 2 | 3 | config SRCARCH 4 | string 5 | option env="SRCARCH" 6 | 7 | source "arch/$SRCARCH/Kconfig" 8 | -------------------------------------------------------------------------------- /arch/x86/boot/code16gcc.h: -------------------------------------------------------------------------------- 1 | # 2 | # code16gcc.h 3 | # 4 | # This file is added to the assembler via -Wa when compiling 16-bit C code. 5 | # This is done this way instead via asm() to make sure gcc does not reorder 6 | # things around us. 7 | # 8 | # gcc 4.9+ has a real -m16 option so we can drop this hack long term. 9 | # 10 | 11 | .code16gcc 12 | -------------------------------------------------------------------------------- /arch/x86/boot/compressed/.gitignore: -------------------------------------------------------------------------------- 1 | vmImage.bin 2 | vmImage.lds 3 | mkpiggy 4 | piggy.S 5 | -------------------------------------------------------------------------------- /arch/x86/boot/compressed/Makefile: -------------------------------------------------------------------------------- 1 | KBUILD_CFLAGS := -m$(BITS) -D__KERNEL__ $(LEGO_INCLUDE) -O2 2 | KBUILD_CFLAGS += -fno-strict-aliasing 3 | cflags-$(CONFIG_X86_32) := -march=i386 4 | cflags-$(CONFIG_X86_64) := -mcmodel=small 5 | KBUILD_CFLAGS += $(cflags-y) 6 | KBUILD_CFLAGS += -mno-mmx -mno-sse 7 | KBUILD_CFLAGS += $(call cc-option,-ffreestanding) 8 | KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector) 9 | 10 | KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ 11 | 12 | LDFLAGS := -m elf_$(UTS_MACHINE) 13 | LDFLAGS_vmImage := -T 14 | 15 | hostprogs-y := mkpiggy 16 | 17 | VMIMAGE_OBJS = $(obj)/vmImage.lds $(obj)/head_64.o $(obj)/piggy.o 18 | 19 | targets := vmImage vmImage.bin 20 | targets += $(patsubst $(obj)/%,%,$(VMIMAGE_OBJS)) 21 | 22 | # 23 | # This vmImage has: 24 | # 1) head_$(BITS).o 25 | # 2) vmImage.bin, which is the stripped kernel 26 | # 27 | $(obj)/vmImage: $(VMIMAGE_OBJS) FORCE 28 | $(call if_changed,ld) 29 | 30 | # 31 | # Generate the original 32-bit or 64-bit stripped kernel 32 | # 33 | OBJCOPYFLAGS_vmImage.bin := -O binary -R .comment -R .note -S 34 | $(obj)/vmImage.bin: vmImage FORCE 35 | $(call if_changed,objcopy) 36 | 37 | quiet_cmd_mkpiggy = MKPIGGY $@ 38 | cmd_mkpiggy = $(obj)/mkpiggy $< > $@ || ( rm -f $@ ; false ) 39 | 40 | targets += piggy.S 41 | $(obj)/piggy.S: $(obj)/vmImage.bin $(obj)/mkpiggy FORCE 42 | $(call if_changed,mkpiggy) 43 | -------------------------------------------------------------------------------- /arch/x86/boot/compressed/mkpiggy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | if (argc < 2) { 9 | fprintf(stderr, "Usage: %s compressed_file\n", argv[0]); 10 | return 1; 11 | } 12 | 13 | printf(".section \".compressed_kernel\",\"a\",@progbits\n"); 14 | printf(".globl input_data, input_data_end\n"); 15 | printf("input_data:\n"); 16 | printf(".incbin \"%s\"\n", argv[1]); 17 | printf("input_data_end:\n"); 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /arch/x86/boot/compressed/vmImage.lds.S: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | */ 4 | 5 | OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT, CONFIG_OUTPUT_FORMAT, CONFIG_OUTPUT_FORMAT) 6 | 7 | #undef i386 8 | 9 | #include 10 | 11 | #ifdef CONFIG_X86_64 12 | OUTPUT_ARCH(i386:x86-64) 13 | ENTRY(startup_64) 14 | #else 15 | OUTPUT_ARCH(i386) 16 | ENTRY(startup_32) 17 | #endif 18 | 19 | SECTIONS 20 | { 21 | /* 22 | * Be careful parts of head_64.S assume startup_32 is at 23 | * address 0. 24 | */ 25 | . = 0; 26 | .head.text : { 27 | _head = .; 28 | *(.head.text) 29 | _ehead = .; 30 | } 31 | 32 | . = ALIGN(PAGE_SIZE); 33 | .compressed_kernel : { 34 | _kernel = .; 35 | *(.compressed_kernel) 36 | _ekernel = .; 37 | } 38 | . = ALIGN(PAGE_SIZE); 39 | 40 | .text : { 41 | _text = .; 42 | *(.text*) 43 | _etext = .; 44 | } 45 | 46 | .rodata : { 47 | _rodata = .; 48 | *(.rodata*) 49 | _erodata = .; 50 | } 51 | 52 | .data : { 53 | _data = .; 54 | *(.data*) 55 | _edata = .; 56 | } 57 | 58 | . = ALIGN(64); 59 | .bss : { 60 | _bss = .; 61 | *(.bss*) 62 | _ebss = .; 63 | } 64 | 65 | #ifdef CONFIG_X86_64 66 | . = ALIGN(PAGE_SIZE); 67 | .pgtable : { 68 | _pgtable = .; 69 | *(.pgtable) 70 | _epgtable = .; 71 | } 72 | #endif 73 | _end = .; 74 | } 75 | -------------------------------------------------------------------------------- /arch/x86/boot/copy.S: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * Memory copy routines 5 | */ 6 | 7 | #include 8 | 9 | .code16 10 | .text 11 | 12 | GLOBAL(memcpy) 13 | pushw %si 14 | pushw %di 15 | movw %ax, %di 16 | movw %dx, %si 17 | pushw %cx 18 | shrw $2, %cx 19 | rep; movsl 20 | popw %cx 21 | andw $3, %cx 22 | rep; movsb 23 | popw %di 24 | popw %si 25 | retl 26 | ENDPROC(memcpy) 27 | 28 | GLOBAL(memset) 29 | pushw %di 30 | movw %ax, %di 31 | movzbl %dl, %eax 32 | imull $0x01010101,%eax 33 | pushw %cx 34 | shrw $2, %cx 35 | rep; stosl 36 | popw %cx 37 | andw $3, %cx 38 | rep; stosb 39 | popw %di 40 | retl 41 | ENDPROC(memset) 42 | 43 | GLOBAL(copy_from_fs) 44 | pushw %ds 45 | pushw %fs 46 | popw %ds 47 | calll memcpy 48 | popw %ds 49 | retl 50 | ENDPROC(copy_from_fs) 51 | 52 | GLOBAL(copy_to_fs) 53 | pushw %es 54 | pushw %fs 55 | popw %es 56 | calll memcpy 57 | popw %es 58 | retl 59 | ENDPROC(copy_to_fs) 60 | 61 | #if 0 /* Not currently used, but can be enabled as needed */ 62 | GLOBAL(copy_from_gs) 63 | pushw %ds 64 | pushw %gs 65 | popw %ds 66 | calll memcpy 67 | popw %ds 68 | retl 69 | ENDPROC(copy_from_gs) 70 | 71 | GLOBAL(copy_to_gs) 72 | pushw %es 73 | pushw %gs 74 | popw %es 75 | calll memcpy 76 | popw %es 77 | retl 78 | ENDPROC(copy_to_gs) 79 | #endif 80 | -------------------------------------------------------------------------------- /arch/x86/boot/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Arguments: 4 | # $1 - kernel version 5 | # $2 - kernel image file 6 | # $3 - kernel map file 7 | # $4 - default install path (blank if root directory) 8 | 9 | verify () { 10 | if [ ! -f "$1" ]; then 11 | echo "" 1>&2 12 | echo " *** Missing file: $1" 1>&2 13 | echo ' *** You need to run "make" before "make install".' 1>&2 14 | echo "" 1>&2 15 | exit 1 16 | fi 17 | } 18 | 19 | # Make sure the files actually exist 20 | verify "$2" 21 | verify "$3" 22 | 23 | # User may have a custom install script 24 | 25 | if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi 26 | if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi 27 | 28 | # Default install - same as make zlilo 29 | 30 | if [ -f $4/vmImage-LegoOS ]; then 31 | mv $4/vmImage-LegoOS $4/vmImage-LegoOS.old 32 | fi 33 | 34 | if [ -f $4/System.map ]; then 35 | mv $4/System.map $4/System.old 36 | fi 37 | 38 | cat $2 > $4/vmImage-LegoOS 39 | cp $3 $4/System.map 40 | 41 | if [ -x /sbin/lilo ]; then 42 | /sbin/lilo 43 | elif [ -x /etc/lilo/install ]; then 44 | /etc/lilo/install 45 | else 46 | sync 47 | echo "Cannot find LILO." 48 | fi 49 | -------------------------------------------------------------------------------- /arch/x86/boot/regs.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * Simple helper function for initializing a register set. 5 | * Note that this sets EFLAGS_CF in the input register set; this 6 | * makes it easier to catch functions which do nothing but don't 7 | * explicitly set CF. 8 | */ 9 | 10 | #include "boot.h" 11 | #include "string.h" 12 | #include 13 | 14 | void initregs(struct biosregs *reg) 15 | { 16 | memset(reg, 0, sizeof *reg); 17 | reg->eflags |= X86_EFLAGS_CF; 18 | reg->ds = ds(); 19 | reg->es = ds(); 20 | reg->fs = fs(); 21 | reg->gs = gs(); 22 | } 23 | -------------------------------------------------------------------------------- /arch/x86/boot/setup.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * Linker script for the 16-bit kernel code. 5 | */ 6 | 7 | OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") 8 | OUTPUT_ARCH(i386) 9 | ENTRY(_start) 10 | 11 | SECTIONS 12 | { 13 | . = 0; 14 | .bstext : { *(.bstext) } 15 | .bsdata : { *(.bsdata) } 16 | 17 | . = 495; 18 | .header : { *(.header) } 19 | .entrytext : { *(.entrytext) } 20 | .inittext : { *(.inittext) } 21 | .initdata : { *(.inittext) } 22 | 23 | .text : { *(.text) } 24 | .text32 : { *(.text32) } 25 | 26 | . = ALIGN(16); 27 | .rodata : { *(.rodata*) } 28 | 29 | .videocards : { 30 | video_cards = .; 31 | *(.videocards) 32 | video_cards_end = .; 33 | } 34 | 35 | . = ALIGN(16); 36 | .data : { *(.data*) } 37 | 38 | .signature : { 39 | setup_sig = .; 40 | LONG(0x5a5aaa55) 41 | } 42 | 43 | . = ALIGN(16); 44 | .bss : { 45 | __bss_start = .; 46 | *(.bss*) 47 | __bss_end = .; 48 | } 49 | 50 | . = ALIGN(4096); 51 | .pgtable : { *(.pgtable) } 52 | 53 | . = ALIGN(16); 54 | __end = .; 55 | 56 | /DISCARD/ : { *(.note*) } 57 | /DISCARD/ : { *(.eh_frame) } 58 | /DISCARD/ : { *(.comment) } 59 | 60 | . = ASSERT(__end <= 0x8000, "Setup too big"); 61 | } 62 | -------------------------------------------------------------------------------- /arch/x86/boot/stdarg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | /* 11 | * Variable Argument Manipulation API 12 | */ 13 | 14 | #ifndef _BOOT_STDARG_H_ 15 | #define _BOOT_STDARG_H_ 16 | 17 | #include 18 | 19 | #define __STACK_ALIGN sizeof(long) 20 | #define __va_rounded_size(TYPE) \ 21 | (((sizeof(TYPE) + __STACK_ALIGN - 1) / __STACK_ALIGN) * __STACK_ALIGN) 22 | 23 | typedef char *va_list; 24 | 25 | #define va_arg(AP, TYPE) \ 26 | ({ \ 27 | TYPE __ret; \ 28 | __ret = *((TYPE *)(AP)); \ 29 | (AP) += __va_rounded_size(TYPE); \ 30 | __ret; \ 31 | }) 32 | 33 | #define va_start(AP, LAST) (AP) = ((va_list)&(LAST) + __va_rounded_size(LAST)) 34 | #define va_end(AP) (AP) = NULL 35 | #define va_copy(DEST, SRC) (DEST) = (SRC) 36 | 37 | #endif /* _BOOT_STDARG_H_ */ 38 | -------------------------------------------------------------------------------- /arch/x86/boot/string.h: -------------------------------------------------------------------------------- 1 | #ifndef _LEGO_BOOT_STRING_H_ 2 | #define _LEGO_BOOT_STRING_H_ 3 | 4 | /* 5 | * Access builtin version by default. If one needs to use optimized version, 6 | * do "undef memcpy" in .c file and link against right string.c 7 | */ 8 | #define memcpy(d,s,l) __builtin_memcpy(d,s,l) 9 | #define memset(d,c,l) __builtin_memset(d,c,l) 10 | #define memcmp __builtin_memcmp 11 | 12 | #endif /* _LEGO_BOOT_STRING_H_ */ 13 | -------------------------------------------------------------------------------- /arch/x86/boot/tools/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /arch/x86/boot/version.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | */ 4 | 5 | #include "boot.h" 6 | #include 7 | #include 8 | 9 | const char kernel_version[] = 10 | UTS_RELEASE " (" LEGO_COMPILE_BY "@" LEGO_COMPILE_HOST ") " 11 | UTS_VERSION; 12 | -------------------------------------------------------------------------------- /arch/x86/entry/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Kernel Entry Points 3 | # 4 | 5 | obj-y := entry_$(BITS).o syscall_$(BITS).o 6 | obj-y += common.o 7 | obj-y += vsyscall/ 8 | 9 | obj-$(CONFIG_IA32_EMULATION) += entry_64_compat.o 10 | -------------------------------------------------------------------------------- /arch/x86/entry/syscall_64.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | /* System call table for x86-64 Lego */ 11 | 12 | #include 13 | 14 | /* for __NR_syscall_max */ 15 | #include 16 | 17 | #define __SYSCALL_64_QUAL_(sym) sym 18 | #define __SYSCALL_64_QUAL_ptregs(sym) ptregs_##sym 19 | 20 | #define __SYSCALL_64(nr, sym, qual) asmlinkage long __SYSCALL_64_QUAL_##qual(sym)(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long); 21 | #include 22 | #undef __SYSCALL_64 23 | 24 | #define __SYSCALL_64(nr, sym, qual) [nr] = __SYSCALL_64_QUAL_##qual(sym), 25 | 26 | long sys_ni_syscall(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long); 27 | 28 | asmlinkage const sys_call_ptr_t sys_call_table[__NR_syscall_max+1] = { 29 | /* 30 | * Smells like a compiler bug -- it doesn't work 31 | * when the & below is removed. 32 | */ 33 | [0 ... __NR_syscall_max] = &sys_ni_syscall, 34 | #include 35 | }; 36 | -------------------------------------------------------------------------------- /arch/x86/entry/syscalls/syscallhdr.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | in="$1" 4 | out="$2" 5 | my_abis=`echo "($3)" | tr ',' '|'` 6 | prefix="$4" 7 | offset="$5" 8 | 9 | fileguard=_ASM_X86_`basename "$out" | sed \ 10 | -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' \ 11 | -e 's/[^A-Z0-9_]/_/g' -e 's/__/_/g'` 12 | grep -E "^[0-9A-Fa-fXx]+[[:space:]]+${my_abis}" "$in" | sort -n | ( 13 | echo "#ifndef ${fileguard}" 14 | echo "#define ${fileguard} 1" 15 | echo "" 16 | 17 | while read nr abi name entry ; do 18 | if [ -z "$offset" ]; then 19 | echo "#define __NR_${prefix}${name} $nr" 20 | else 21 | echo "#define __NR_${prefix}${name} ($offset + $nr)" 22 | fi 23 | done 24 | 25 | echo "" 26 | echo "#endif /* ${fileguard} */" 27 | ) > "$out" 28 | -------------------------------------------------------------------------------- /arch/x86/entry/vsyscall/Makefile: -------------------------------------------------------------------------------- 1 | obj-y := vsyscall_64.o vsyscall_emu_64.o 2 | -------------------------------------------------------------------------------- /arch/x86/entry/vsyscall/vsyscall_emu_64.S: -------------------------------------------------------------------------------- 1 | /* 2 | * vsyscall_emu_64.S: Vsyscall emulation page 3 | * 4 | * Copyright (c) 2011 Andy Lutomirski 5 | * 6 | * Subject to the GNU General Public License, version 2 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | .section ".data..page_aligned", "aw" 15 | .globl __vsyscall_page 16 | .balign PAGE_SIZE, 0xcc 17 | .type __vsyscall_page, @object 18 | __vsyscall_page: 19 | 20 | mov $__NR_gettimeofday, %rax 21 | syscall 22 | ret 23 | 24 | .balign 1024, 0xcc 25 | mov $__NR_time, %rax 26 | syscall 27 | ret 28 | 29 | .balign 1024, 0xcc 30 | mov $__NR_getcpu, %rax 31 | syscall 32 | ret 33 | 34 | .balign 4096, 0xcc 35 | 36 | .size __vsyscall_page, 4096 37 | 38 | -------------------------------------------------------------------------------- /arch/x86/include/asm/boot.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Parameters used by boot setup code 10 | */ 11 | 12 | #ifndef _ASM_X86_BOOT_H_ 13 | #define _ASM_X86_BOOT_H_ 14 | 15 | /* Internal svga startup constants */ 16 | #define NORMAL_VGA 0xffff /* 80x25 mode */ 17 | #define EXTENDED_VGA 0xfffe /* 80x50 mode */ 18 | #define ASK_VGA 0xfffd /* ask for it at bootup */ 19 | 20 | /* Physical address where kernel should be loaded: */ 21 | #define LOAD_PHYSICAL_ADDR \ 22 | (CONFIG_PHYSICAL_START + CONFIG_PHYSICAL_ALIGN - 1) \ 23 | & ~(CONFIG_PHYSICAL_ALIGN - 1) 24 | 25 | #endif /* _ASM_X86_BOOT_H_ */ 26 | -------------------------------------------------------------------------------- /arch/x86/include/asm/cache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _ASM_X86_CACHE_H_ 11 | #define _ASM_X86_CACHE_H_ 12 | 13 | /* L1 cache line size */ 14 | #define L1_CACHE_SHIFT (6) 15 | #define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT) 16 | 17 | #endif /* _ASM_X86_CACHE_H_ */ 18 | -------------------------------------------------------------------------------- /arch/x86/include/asm/current.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Parameters used by boot setup code 10 | */ 11 | 12 | #ifndef _ASM_X86_CURRENT_H_ 13 | #define _ASM_X86_CURRENT_H_ 14 | 15 | #include 16 | #include 17 | 18 | struct task_struct; 19 | 20 | DECLARE_PER_CPU(struct task_struct *, current_task); 21 | 22 | static __always_inline struct task_struct *get_current(void) 23 | { 24 | return this_cpu_read_stable(current_task); 25 | } 26 | 27 | #define current get_current() 28 | 29 | #endif /* _ASM_X86_CURRENT_H_ */ 30 | -------------------------------------------------------------------------------- /arch/x86/include/asm/delay.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _ASM_X86_DELAY_H_ 11 | #define _ASM_X86_DELAY_H_ 12 | 13 | void use_tsc_delay(void); 14 | 15 | #endif /* _ASM_X86_DELAY_H_ */ 16 | -------------------------------------------------------------------------------- /arch/x86/include/asm/div64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _ASM_X86_DIV64_H_ 11 | #define _ASM_X86_DIV64_H_ 12 | 13 | #define do_div(n,base) ({ \ 14 | uint32_t __base = (base); \ 15 | uint32_t __rem; \ 16 | __rem = ((uint64_t)(n)) % __base; \ 17 | (n) = ((uint64_t)(n)) / __base; \ 18 | __rem; \ 19 | }) 20 | 21 | #endif /* _ASM_X86_DIV64_H_ */ 22 | -------------------------------------------------------------------------------- /arch/x86/include/asm/fpu/regset.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | /* 11 | * FPU regset handling methods: 12 | */ 13 | 14 | #ifndef _ASM_X86_FPU_REGSET_H_ 15 | #define _ASM_X86_FPU_REGSET_H_ 16 | 17 | #include 18 | 19 | extern user_regset_active_fn regset_fpregs_active, regset_xregset_fpregs_active; 20 | extern user_regset_get_fn fpregs_get, xfpregs_get, fpregs_soft_get, 21 | xstateregs_get; 22 | extern user_regset_set_fn fpregs_set, xfpregs_set, fpregs_soft_set, 23 | xstateregs_set; 24 | 25 | /* 26 | * xstateregs_active == regset_fpregs_active. Please refer to the comment 27 | * at the definition of regset_fpregs_active. 28 | */ 29 | #define xstateregs_active regset_fpregs_active 30 | 31 | #endif /* _ASM_X86_FPU_REGSET_H_ */ 32 | -------------------------------------------------------------------------------- /arch/x86/include/asm/frame.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _ASM_X86_FRAME_H_ 11 | #define _ASM_X86_FRAME_H_ 12 | 13 | #include 14 | 15 | /* 16 | * These are stack frame creation macros. They should be used by every 17 | * callable non-leaf asm function to make kernel stack traces more reliable. 18 | */ 19 | 20 | #ifdef CONFIG_FRAME_POINTER 21 | 22 | #ifdef __ASSEMBLY__ 23 | 24 | .macro FRAME_BEGIN 25 | push %_ASM_BP 26 | _ASM_MOV %_ASM_SP, %_ASM_BP 27 | .endm 28 | 29 | .macro FRAME_END 30 | pop %_ASM_BP 31 | .endm 32 | 33 | #else /* !__ASSEMBLY__ */ 34 | 35 | #define FRAME_BEGIN \ 36 | "push %" _ASM_BP "\n" \ 37 | _ASM_MOV "%" _ASM_SP ", %" _ASM_BP "\n" 38 | 39 | #define FRAME_END "pop %" _ASM_BP "\n" 40 | 41 | #endif /* __ASSEMBLY__ */ 42 | 43 | #define FRAME_OFFSET __ASM_SEL(4, 8) 44 | 45 | #else /* !CONFIG_FRAME_POINTER */ 46 | 47 | #define FRAME_BEGIN 48 | #define FRAME_END 49 | #define FRAME_OFFSET 0 50 | 51 | #endif /* CONFIG_FRAME_POINTER */ 52 | 53 | #endif /* _ASM_X86_FRAME_H */ 54 | -------------------------------------------------------------------------------- /arch/x86/include/asm/irq_regs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | /* 11 | * Per-cpu current frame pointer - the location of the last exception frame on 12 | * the stack, stored in the per-cpu area. 13 | * 14 | * Jeremy Fitzhardinge 15 | */ 16 | #ifndef _ASM_X86_IRQ_REGS_H_ 17 | #define _ASM_X86_IRQ_REGS_H_ 18 | 19 | #include 20 | 21 | DECLARE_PER_CPU(struct pt_regs *, irq_regs); 22 | 23 | static inline struct pt_regs *get_irq_regs(void) 24 | { 25 | return this_cpu_read(irq_regs); 26 | } 27 | 28 | static inline struct pt_regs *set_irq_regs(struct pt_regs *new_regs) 29 | { 30 | struct pt_regs *old_regs; 31 | 32 | old_regs = get_irq_regs(); 33 | this_cpu_write(irq_regs, new_regs); 34 | 35 | return old_regs; 36 | } 37 | 38 | #endif /* _ASM_X86_IRQ_REGS_H_ */ 39 | -------------------------------------------------------------------------------- /arch/x86/include/asm/kdebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _ASM_X86_KDEBUG_H_ 11 | #define _ASM_X86_KDEBUG_H_ 12 | 13 | extern void die(const char *, struct pt_regs *,long); 14 | extern int __die(const char *, struct pt_regs *, long); 15 | 16 | #endif /* _ASM_X86_KDEBUG_H_ */ 17 | -------------------------------------------------------------------------------- /arch/x86/include/asm/linkage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _ASM_X86_LINKAGE_H_ 11 | #define _ASM_X86_LINKAGE_H_ 12 | 13 | #include 14 | 15 | #ifdef CONFIG_X86_32 16 | #define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0))) 17 | #endif 18 | 19 | #ifdef __ASSEMBLY__ 20 | 21 | #define GLOBAL(name) \ 22 | .globl name; \ 23 | name: 24 | 25 | #if defined(CONFIG_X86_64) || defined(CONFIG_X86_ALIGNMENT_16) 26 | #define __ALIGN .p2align 4, 0x90 27 | #define __ALIGN_STR __stringify(__ALIGN) 28 | #endif 29 | 30 | #endif /* __ASSEMBLY__ */ 31 | 32 | #endif /* _ASM_X86_LINKAGE_H_ */ 33 | -------------------------------------------------------------------------------- /arch/x86/include/asm/prctl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _ASM_X86_PRCTL_H_ 11 | #define _ASM_X86_PRCTL_H_ 12 | 13 | #define ARCH_SET_GS 0x1001 14 | #define ARCH_SET_FS 0x1002 15 | #define ARCH_GET_FS 0x1003 16 | #define ARCH_GET_GS 0x1004 17 | 18 | #define ARCH_MAP_VDSO_X32 0x2001 19 | #define ARCH_MAP_VDSO_32 0x2002 20 | #define ARCH_MAP_VDSO_64 0x2003 21 | 22 | #endif /* _ASM_X86_PRCTL_H_ */ 23 | -------------------------------------------------------------------------------- /arch/x86/include/asm/sigframe.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _ASM_X86_SIGFRAME_H_ 11 | #define _ASM_X86_SIGFRAME_H_ 12 | 13 | #include 14 | #include 15 | 16 | struct siginfo; 17 | 18 | struct rt_sigframe { 19 | char __user *pretcode; 20 | struct ucontext uc; 21 | struct siginfo info; 22 | /* fp state follows here */ 23 | }; 24 | 25 | #endif /* _ASM_X86_SIGFRAME_H_ */ 26 | -------------------------------------------------------------------------------- /arch/x86/include/asm/signal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _ASM_X86_SIGNAL_H_ 11 | #define _ASM_X86_SIGNAL_H_ 12 | 13 | #define _NSIG 64 14 | #define _NSIG_BPW 64 15 | #define _NSIG_WORDS (_NSIG / _NSIG_BPW) 16 | 17 | typedef struct { 18 | unsigned long sig[_NSIG_WORDS]; 19 | } sigset_t; 20 | 21 | /* non-uapi in-kernel SA_FLAGS for those indicates ABI for a signal frame */ 22 | #define SA_IA32_ABI 0x02000000u 23 | #define SA_X32_ABI 0x01000000u 24 | 25 | #ifndef CONFIG_COMPAT 26 | typedef sigset_t compat_sigset_t; 27 | #endif 28 | 29 | #define __ARCH_HAS_SA_RESTORER 30 | 31 | extern void do_signal(struct pt_regs *regs); 32 | 33 | #endif /* _ASM_X86_SIGNAL_H_ */ 34 | -------------------------------------------------------------------------------- /arch/x86/include/asm/sparsemem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _ASM_X86_SPARSEMEM_H_ 11 | #define _ASM_X86_SPARSEMEM_H_ 12 | 13 | #ifdef CONFIG_SPARSEMEM 14 | /* 15 | * generic non-linear memory support: 16 | * 17 | * 1) we will not split memory into more chunks than will fit into the flags 18 | * field of the struct page 19 | * 20 | * SECTION_SIZE_BITS 2^n: size of each section 21 | * MAX_PHYSADDR_BITS 2^n: max size of physical address space 22 | * MAX_PHYSMEM_BITS 2^n: how much memory we can have in that space 23 | * 24 | */ 25 | 26 | #ifdef CONFIG_X86_32 27 | # ifdef CONFIG_X86_PAE 28 | # define SECTION_SIZE_BITS 29 29 | # define MAX_PHYSADDR_BITS 36 30 | # define MAX_PHYSMEM_BITS 36 31 | # else 32 | # define SECTION_SIZE_BITS 26 33 | # define MAX_PHYSADDR_BITS 32 34 | # define MAX_PHYSMEM_BITS 32 35 | # endif 36 | #else /* CONFIG_X86_32 */ 37 | # define SECTION_SIZE_BITS 27 /* matt - 128 is convenient right now */ 38 | # define MAX_PHYSADDR_BITS 44 39 | # define MAX_PHYSMEM_BITS 46 40 | #endif 41 | 42 | #endif /* CONFIG_SPARSEMEM */ 43 | #endif /* _ASM_X86_SPARSEMEM_H_ */ 44 | -------------------------------------------------------------------------------- /arch/x86/include/asm/stat.h: -------------------------------------------------------------------------------- 1 | #ifndef _ASM_X86_STAT_H_ 2 | #define _ASM_X86_STAT_H_ 3 | 4 | #include 5 | 6 | struct stat { 7 | unsigned long st_dev; 8 | unsigned long st_ino; 9 | unsigned long st_nlink; 10 | 11 | unsigned int st_mode; 12 | unsigned int st_uid; 13 | unsigned int st_gid; 14 | unsigned int __pad0; 15 | unsigned long st_rdev; 16 | long st_size; 17 | long st_blksize; 18 | long st_blocks; /* Number 512-byte blocks allocated. */ 19 | 20 | unsigned long st_atime; 21 | unsigned long st_atime_nsec; 22 | unsigned long st_mtime; 23 | unsigned long st_mtime_nsec; 24 | unsigned long st_ctime; 25 | unsigned long st_ctime_nsec; 26 | long ____unused[3]; 27 | }; 28 | 29 | /* We don't need to memset the whole thing just to initialize the padding */ 30 | #define INIT_STRUCT_STAT_PADDING(st) do { \ 31 | st.__pad0 = 0; \ 32 | st.____unused[0] = 0; \ 33 | st.____unused[1] = 0; \ 34 | st.____unused[2] = 0; \ 35 | } while (0) 36 | 37 | #endif /* _ASM_X86_STAT_H_ */ 38 | -------------------------------------------------------------------------------- /arch/x86/include/asm/string.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _ASM_X86_STRING_H_ 11 | #define _ASM_X86_STRING_H_ 12 | 13 | #ifdef CONFIG_X86_32 14 | # error " needed" 15 | #else 16 | # include 17 | #endif 18 | 19 | #endif /* _ASM_X86_STRING_H_ */ 20 | -------------------------------------------------------------------------------- /arch/x86/include/asm/time.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _ASM_X86_TIME_H_ 11 | #define _ASM_X86_TIME_H_ 12 | 13 | extern void __init setup_pit_timer(void); 14 | 15 | extern struct clock_event_device *global_clock_event; 16 | 17 | #endif /* _ASM_X86_TIME_H_ */ 18 | -------------------------------------------------------------------------------- /arch/x86/include/asm/timex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_TIMX_H_ 11 | #define _LEGO_TIMX_H_ 12 | 13 | /* The clock frequency of the i8253/i8254 PIT */ 14 | #define PIT_TICK_RATE 1193182ul 15 | 16 | /* Assume we use the PIT time source for the clock tick */ 17 | #define CLOCK_TICK_RATE PIT_TICK_RATE 18 | 19 | #endif /* _LEGO_TIMX_H_ */ 20 | -------------------------------------------------------------------------------- /arch/x86/include/asm/trampoline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _ASM_X86_TRAMPOLINE_H_ 11 | #define _ASM_X86_TRAMPOLINE_H_ 12 | 13 | void __init copy_trampoline_code(void); 14 | 15 | extern unsigned int trampoline_start; 16 | extern unsigned int trampoline_end; 17 | 18 | #endif /* _ASM_X86_TRAMPOLINE_H_ */ 19 | -------------------------------------------------------------------------------- /arch/x86/include/asm/tsc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _ASM_X86_TSC_H_ 11 | #define _ASM_X86_TSC_H_ 12 | 13 | extern unsigned int cpu_khz; 14 | extern unsigned int tsc_khz; 15 | 16 | void __init tsc_init(void); 17 | 18 | #endif /* _ASM_X86_TSC_H_ */ 19 | -------------------------------------------------------------------------------- /arch/x86/include/asm/vsyscall.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _ASM_X86_VSYSCALL_H_ 11 | #define _ASM_X86_VSYSCALL_H_ 12 | 13 | #include 14 | 15 | enum vsyscall_num { 16 | __NR_vgettimeofday, 17 | __NR_vtime, 18 | __NR_vgetcpu, 19 | }; 20 | 21 | #define VSYSCALL_ADDR (-10UL << 20) 22 | 23 | #ifdef CONFIG_X86_VSYSCALL_EMULATION 24 | void map_vsyscall(void); 25 | 26 | /* 27 | * Called on instruction fetch fault in vsyscall page. 28 | * Returns true if handled. 29 | */ 30 | bool emulate_vsyscall(struct pt_regs *regs, unsigned long address); 31 | #else 32 | static inline void map_vsyscall(void) {} 33 | static inline bool emulate_vsyscall(struct pt_regs *regs, unsigned long address) 34 | { 35 | return false; 36 | } 37 | #endif 38 | 39 | #endif /* _ASM_X86_VSYSCALL_H_ */ 40 | -------------------------------------------------------------------------------- /arch/x86/kernel/.gitignore: -------------------------------------------------------------------------------- 1 | vmImage.lds 2 | asm-offsets.s 3 | -------------------------------------------------------------------------------- /arch/x86/kernel/Makefile: -------------------------------------------------------------------------------- 1 | extra-y += vmImage.lds 2 | 3 | obj-y := head_64.o head64.o 4 | obj-y += process.o 5 | obj-y += dumpstack.o 6 | obj-y += setup.o 7 | obj-y += e820.o 8 | obj-y += pci-dma.o 9 | obj-y += pci-nommu.o 10 | obj-y += cpu/ 11 | 12 | obj-y += percpu.o 13 | obj-y += smp.o smpboot.o 14 | obj-y += time.o rtc.o 15 | obj-y += hpet.o i8253.o tsc.o 16 | obj-y += traps.o irq.o irqinit.o i8259.o 17 | obj-y += acpi/ apic/ 18 | obj-y += fpu/ 19 | obj-y += alternative.o 20 | obj-y += signal.o 21 | obj-y += ptrace.o 22 | 23 | # Enable CONFIG_FRAME_POINTER to get precise kernel stack dumpinfo 24 | ifdef CONFIG_FRAME_POINTER 25 | obj-y += unwind_frame.o 26 | else 27 | obj-y += unwind_guess.o 28 | endif 29 | -------------------------------------------------------------------------------- /arch/x86/kernel/acpi/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # ACPI architecture-specific boot-time hook 3 | # 4 | 5 | obj-y := boot.o 6 | obj-y += numa.o 7 | -------------------------------------------------------------------------------- /arch/x86/kernel/apic/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Advanced Programmable Interrupt Controller 3 | # All for x86-64 4 | # 5 | 6 | obj-y := apic.o 7 | obj-y += io_apic.o 8 | obj-y += ipi.o 9 | obj-y += apic_flat.o 10 | obj-y += vector.o 11 | obj-y += msi.o 12 | -------------------------------------------------------------------------------- /arch/x86/kernel/cpu/.gitignore: -------------------------------------------------------------------------------- 1 | capflags.c 2 | -------------------------------------------------------------------------------- /arch/x86/kernel/cpu/Makefile: -------------------------------------------------------------------------------- 1 | obj-y := common.o intel.o 2 | obj-y += scattered.o 3 | obj-$(CONFIG_X86_FEATURE_NAMES) += capflags.o powerflags.o 4 | obj-y += topology.o 5 | 6 | ifdef CONFIG_X86_FEATURE_NAMES 7 | quiet_cmd_mkcapflags = MKCAP $@ 8 | cmd_mkcapflags = $(CONFIG_SHELL) $(srctree)/$(src)/mkcapflags.sh $< $@ 9 | 10 | cpufeature = $(src)/../../include/asm/processor-features-flags.h 11 | 12 | targets += capflags.c 13 | $(obj)/capflags.c: $(cpufeature) $(src)/mkcapflags.sh FORCE 14 | $(call if_changed,mkcapflags) 15 | endif 16 | clean-files += capflags.c 17 | -------------------------------------------------------------------------------- /arch/x86/kernel/cpu/powerflags.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | /* 11 | * Strings for the various x86 power flags 12 | * 13 | * This file must not contain any executable code. 14 | */ 15 | 16 | #include 17 | 18 | const char *const x86_power_flags[32] = { 19 | "ts", /* temperature sensor */ 20 | "fid", /* frequency id control */ 21 | "vid", /* voltage id control */ 22 | "ttp", /* thermal trip */ 23 | "tm", /* hardware thermal control */ 24 | "stc", /* software thermal control */ 25 | "100mhzsteps", /* 100 MHz multiplier control */ 26 | "hwpstate", /* hardware P-state control */ 27 | "", /* tsc invariant mapped to constant_tsc */ 28 | "cpb", /* core performance boost */ 29 | "eff_freq_ro", /* Readonly aperf/mperf */ 30 | "proc_feedback", /* processor feedback interface */ 31 | "acc_power", /* accumulated power mechanism */ 32 | }; 33 | 34 | -------------------------------------------------------------------------------- /arch/x86/kernel/fpu/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # x86/fpu subsystem 3 | # Barely no one is willing to touch it 4 | # 5 | 6 | obj-y := init.o 7 | obj-y += core.o 8 | obj-y += xstate.o 9 | obj-y += signal.o 10 | obj-y += regset.o 11 | -------------------------------------------------------------------------------- /arch/x86/lib/Makefile: -------------------------------------------------------------------------------- 1 | obj-y := delay.o 2 | obj-y += usercopy.o 3 | obj-y += getuser.o 4 | obj-y += putuser.o 5 | obj-y += uaccess.o 6 | obj-y += rwsem.o 7 | obj-y += memset_64.o 8 | obj-y += memcpy_64.o 9 | obj-y += memmove_64.o 10 | obj-y += csum-partial_64.o 11 | -------------------------------------------------------------------------------- /arch/x86/mm/Makefile: -------------------------------------------------------------------------------- 1 | obj-y := init.o 2 | obj-y += fault.o 3 | obj-y += ioremap.o 4 | obj-y += numa.o 5 | obj-y += pgtable.o 6 | obj-y += tlb.o 7 | obj-y += extable.o 8 | obj-y += debug.o 9 | obj-y += dumppgtable.o 10 | -------------------------------------------------------------------------------- /arch/x86/pci/Makefile: -------------------------------------------------------------------------------- 1 | obj-y := common.o 2 | obj-y += direct.o 3 | obj-y += irq.o 4 | obj-y += mmconfig-shared.o mmconfig_64.o 5 | obj-y += bus_numa.o 6 | -------------------------------------------------------------------------------- /arch/x86/pci/bus_numa.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef __BUS_NUMA_H 11 | #define __BUS_NUMA_H 12 | 13 | #include 14 | #include 15 | 16 | /* 17 | * sub bus (transparent) will use entres from 3 to store extra from 18 | * root, so need to make sure we have enough slot there. 19 | */ 20 | struct pci_root_res { 21 | struct list_head list; 22 | struct resource res; 23 | }; 24 | 25 | struct pci_root_info { 26 | struct list_head list; 27 | char name[12]; 28 | struct list_head resources; 29 | struct resource busn; 30 | int node; 31 | int link; 32 | }; 33 | 34 | extern struct list_head pci_root_infos; 35 | struct pci_root_info *alloc_pci_root_info(int bus_min, int bus_max, 36 | int node, int link); 37 | extern void update_res(struct pci_root_info *info, resource_size_t start, 38 | resource_size_t end, unsigned long flags, int merge); 39 | 40 | void x86_pci_root_bus_resources(int bus, struct list_head *resources); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /arch/x86/realmode/Makefile: -------------------------------------------------------------------------------- 1 | # Need this to let make clean work 2 | subdir- := rm/ 3 | 4 | obj-y := piggy.o 5 | 6 | $(obj)/piggy.o : $(obj)/rm/trampoline.bin 7 | 8 | $(obj)/rm/trampoline.bin: FORCE 9 | $(Q)$(MAKE) $(build)=$(obj)/rm $@ 10 | -------------------------------------------------------------------------------- /arch/x86/realmode/piggy.S: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | /* 11 | * :-) 12 | * piggyback the realmode trampoline code 13 | */ 14 | 15 | #include 16 | 17 | .section ".init.trampoline","ax" 18 | GLOBAL(trampoline_start) 19 | .incbin "arch/x86/realmode/rm/trampoline.bin" 20 | GLOBAL(trampoline_end) 21 | -------------------------------------------------------------------------------- /arch/x86/realmode/rm/.gitignore: -------------------------------------------------------------------------------- 1 | ld.lds 2 | trampoline 3 | -------------------------------------------------------------------------------- /arch/x86/realmode/rm/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Trampoline code for booting secondary cpus 3 | # 4 | 5 | KBUILD_CFLAGS := $(REALMODE_CFLAGS) 6 | KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ 7 | 8 | LDFLAGS := -m elf_$(UTS_MACHINE) 9 | LDFLAGS_trampoline.elf := -T 10 | 11 | TRAMPOLINE_OBJS = $(obj)/ld.lds $(obj)/trampoline.o 12 | 13 | targets := $(patsubst $(obj)/%,%,$(TRAMPOLINE_OBJS)) 14 | targets += trampoline.bin trampoline.elf 15 | 16 | # This is the linked trampoline object 17 | $(obj)/trampoline.elf: $(TRAMPOLINE_OBJS) FORCE 18 | $(call if_changed,ld) 19 | 20 | # This is the binary will be embedded into kernel 21 | OBJCOPYFLAGS_trampoline.bin := -O binary -R .comment -R .note -S 22 | $(obj)/trampoline.bin: $(obj)/trampoline.elf FORCE 23 | $(call if_changed,objcopy) 24 | -------------------------------------------------------------------------------- /arch/x86/realmode/rm/ld.lds.S: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include 11 | 12 | #undef i386 13 | 14 | OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") 15 | OUTPUT_ARCH(i386) 16 | ENTRY(_start) 17 | 18 | SECTIONS 19 | { 20 | . = 0; 21 | .text : { 22 | *(.text) 23 | } 24 | 25 | . = ALIGN(64); 26 | .text32 : { 27 | *(.text32*) 28 | } 29 | 30 | . = ALIGN(64); 31 | .text64 : { 32 | *(.text64*) 33 | } 34 | 35 | . = ALIGN(64); 36 | .rodata : { 37 | *(.rodata*) 38 | } 39 | 40 | . = ALIGN(64); 41 | .data : { 42 | *(.data*) 43 | } 44 | 45 | .signature : { 46 | trampoline_signature = .; 47 | LONG(0x5a5aaa55) 48 | } 49 | 50 | . = ALIGN(64); 51 | .bss : { 52 | _bss = .; 53 | *(.bss*) 54 | _ebss = .; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /drivers/Kconfig: -------------------------------------------------------------------------------- 1 | menu "Lego Device Drivers" 2 | 3 | source "drivers/tty/Kconfig" 4 | source "drivers/infiniband/Kconfig" 5 | source "drivers/eth/Kconfig" 6 | 7 | endmenu 8 | -------------------------------------------------------------------------------- /drivers/Makefile: -------------------------------------------------------------------------------- 1 | obj-y := tty/ 2 | obj-y += base/ 3 | obj-y += acpi/ 4 | obj-y += pci/ 5 | obj-y += infiniband/ 6 | obj-y += eth/ 7 | -------------------------------------------------------------------------------- /drivers/acpi/Makefile: -------------------------------------------------------------------------------- 1 | obj-y := table.o 2 | obj-y += table_install.o 3 | obj-y += numa.o 4 | obj-y += madt.o 5 | obj-y += fadt.o 6 | -------------------------------------------------------------------------------- /drivers/base/Makefile: -------------------------------------------------------------------------------- 1 | obj-y := core.o 2 | -------------------------------------------------------------------------------- /drivers/eth/Kconfig: -------------------------------------------------------------------------------- 1 | menu "Ethernet" 2 | 3 | menuconfig E1000 4 | tristate "e1000 driver" 5 | ---help--- 6 | Driver for Intel E1000. 7 | 8 | menuconfig TG3 9 | tristate "tg3 driver" 10 | ---help--- 11 | Driver for Broadcom tg3. 12 | 13 | endmenu 14 | -------------------------------------------------------------------------------- /drivers/eth/Makefile: -------------------------------------------------------------------------------- 1 | obj-$(CONFIG_E1000) := e1000.o 2 | obj-$(CONFIG_TG3) := tg3.o 3 | -------------------------------------------------------------------------------- /drivers/infiniband/Makefile: -------------------------------------------------------------------------------- 1 | obj-$(CONFIG_INFINIBAND) += hw/ 2 | obj-$(CONFIG_INFINIBAND) += core/ 3 | #obj-$(CONFIG_INFINIBAND) += ulp/ 4 | #obj-$(CONFIG_INFINIBAND) += sw/ 5 | -------------------------------------------------------------------------------- /drivers/infiniband/core/Makefile: -------------------------------------------------------------------------------- 1 | infiniband-$(CONFIG_INFINIBAND_ADDR_TRANS) := ib_addr.o rdma_cm.o 2 | user_access-$(CONFIG_INFINIBAND_ADDR_TRANS) := rdma_ucm.o 3 | 4 | obj-$(CONFIG_INFINIBAND) += ib_core.o ib_mad.o ib_cm.o ib_sa.o 5 | #iw_cm.o $(infiniband-y) 6 | obj-$(CONFIG_INFINIBAND_USER_MAD) += ib_umad.o 7 | obj-$(CONFIG_INFINIBAND_USER_ACCESS) += ib_uverbs.o ib_ucm.o \ 8 | $(user_access-y) 9 | 10 | ib_core-y := ud_header.o 11 | ib_core-y += packer.o 12 | ib_core-y += verbs.o 13 | ib_core-y += device.o 14 | ib_core-y += cache.o 15 | #ib_core-y += fmr_pool.o 16 | 17 | ib_core-$(CONFIG_INFINIBAND_USER_MEM) += umem.o 18 | 19 | ib_mad-y := mad.o smi.o agent.o mad_rmpp.o 20 | 21 | ib_sa-y := sa_query.o # multicast.o 22 | 23 | ib_cm-y := cm.o 24 | 25 | iw_cm-y := iwcm.o 26 | 27 | rdma_cm-y := cma.o 28 | 29 | rdma_ucm-y := ucma.o 30 | 31 | ib_addr-y := addr.o 32 | 33 | ib_umad-y := user_mad.o 34 | 35 | ib_ucm-y := ucm.o 36 | 37 | ib_uverbs-y := uverbs_main.o uverbs_cmd.o uverbs_marshall.o 38 | -------------------------------------------------------------------------------- /drivers/infiniband/hw/Makefile: -------------------------------------------------------------------------------- 1 | obj-$(CONFIG_INFINIBAND) += mlx4en/ 2 | obj-$(CONFIG_INFINIBAND) += mlx4/ 3 | 4 | -------------------------------------------------------------------------------- /drivers/infiniband/hw/mlx4/Kconfig: -------------------------------------------------------------------------------- 1 | config MLX4_INFINIBAND 2 | tristate "Mellanox ConnectX HCA support" 3 | depends on NETDEVICES && ETHERNET && PCI && INET 4 | depends on MAY_USE_DEVLINK 5 | select NET_VENDOR_MELLANOX 6 | select MLX4_CORE 7 | ---help--- 8 | This driver provides low-level InfiniBand support for 9 | Mellanox ConnectX PCI Express host channel adapters (HCAs). 10 | This is required to use InfiniBand protocols such as 11 | IP-over-IB or SRP with these devices. 12 | -------------------------------------------------------------------------------- /drivers/infiniband/hw/mlx4/Makefile: -------------------------------------------------------------------------------- 1 | obj-$(CONFIG_INFINIBAND) += mlx4_ib.o 2 | 3 | mlx4_ib-y := cq.o 4 | mlx4_ib-y += main.o 5 | mlx4_ib-y += mr.o 6 | mlx4_ib-y += qp.o 7 | mlx4_ib-y += mad.o 8 | mlx4_ib-y += ah.o 9 | mlx4_ib-y += srq.o 10 | -------------------------------------------------------------------------------- /drivers/infiniband/hw/mlx4en/Kconfig: -------------------------------------------------------------------------------- 1 | # 2 | # Mellanox driver configuration 3 | # 4 | 5 | config MLX4_CORE 6 | tristate 7 | depends on PCI 8 | default n 9 | 10 | config MLX4_DEBUG 11 | bool "Verbose debugging output" if (MLX4_CORE && EXPERT) 12 | depends on MLX4_CORE 13 | default y 14 | ---help--- 15 | This option causes debugging code to be compiled into the 16 | mlx4_core driver. The output can be turned on via the 17 | debug_level module parameter (which can also be set after 18 | the driver is loaded through sysfs). 19 | -------------------------------------------------------------------------------- /drivers/infiniband/hw/mlx4en/Makefile: -------------------------------------------------------------------------------- 1 | obj-$(CONFIG_INFINIBAND) += mlx4_core.o 2 | 3 | mlx4_core-y := alloc.o 4 | #mlx4_core-y += catas.o 5 | mlx4_core-y += cmd.o 6 | mlx4_core-y += cq.o 7 | mlx4_core-y += intf.o 8 | mlx4_core-y += eq.o 9 | mlx4_core-y += fw.o 10 | mlx4_core-y += icm.o 11 | mlx4_core-y += main.o 12 | mlx4_core-y += mcg.o 13 | mlx4_core-y += mr.o 14 | mlx4_core-y += pd.o 15 | mlx4_core-y += port.o 16 | mlx4_core-y += profile.o 17 | mlx4_core-y += qp.o 18 | mlx4_core-y += reset.o 19 | mlx4_core-y += sense.o 20 | #mlx4_core-y += srq.o 21 | -------------------------------------------------------------------------------- /drivers/infiniband/ulp/Makefile: -------------------------------------------------------------------------------- 1 | obj-$(CONFIG_INFINIBAND_IPOIB) += ipoib/ 2 | #obj-$(CONFIG_INFINIBAND_SRP) += srp/ 3 | #obj-$(CONFIG_INFINIBAND_SRPT) += srpt/ 4 | #obj-$(CONFIG_INFINIBAND_ISER) += iser/ 5 | #obj-$(CONFIG_INFINIBAND_ISERT) += isert/ 6 | -------------------------------------------------------------------------------- /drivers/infiniband/ulp/ipoib/Makefile: -------------------------------------------------------------------------------- 1 | obj-$(CONFIG_INFINIBAND_IPOIB) += ib_ipoib.o 2 | 3 | ib_ipoib-y := ipoib_main.o 4 | ib_ipoib-y += ipoib_ib.o 5 | #ib_ipoib-y += ipoib_multicast.o 6 | ib_ipoib-y += ipoib_verbs.o 7 | #ib_ipoib-y += ipoib_vlan.o 8 | # ipoib_ethtool.o 9 | # ipoib_netlink.o 10 | ib_ipoib-$(CONFIG_INFINIBAND_IPOIB_CM) += ipoib_cm.o 11 | -------------------------------------------------------------------------------- /drivers/pci/Makefile: -------------------------------------------------------------------------------- 1 | obj-y := access.o 2 | obj-y += bus.o 3 | obj-y += probe.o 4 | obj-y += search.o 5 | obj-y += host-bridge.o 6 | obj-y += driver.o 7 | obj-y += pci.o 8 | obj-y += msi.o 9 | -------------------------------------------------------------------------------- /drivers/pci/pci.h: -------------------------------------------------------------------------------- 1 | #ifndef _PCI_PCI_H_ 2 | #define _PCI_PCI_H_ 3 | 4 | enum pci_bar_type { 5 | pci_bar_unknown, /* Standard PCI BAR probe */ 6 | pci_bar_io, /* An io port BAR */ 7 | pci_bar_mem32, /* A 32-bit memory BAR */ 8 | pci_bar_mem64, /* A 64-bit memory BAR */ 9 | }; 10 | 11 | static inline int pci_no_d1d2(struct pci_dev *dev) 12 | { 13 | unsigned int parent_dstates = 0; 14 | 15 | if (dev->bus->self) 16 | parent_dstates = dev->bus->self->no_d1d2; 17 | return (dev->no_d1d2 || parent_dstates); 18 | 19 | } 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /drivers/tty/Kconfig: -------------------------------------------------------------------------------- 1 | menu "TTY Layer Configurations" 2 | 3 | config TTY_VT 4 | bool "Virtual Terminal Output" 5 | default n 6 | help 7 | If you say Y here, the printk() function will emit the formatted 8 | string to Virtual Terminal (VT) layer. It may slightly slow the 9 | printk() function call. If you are running this in a monitor-less 10 | machine, say N. 11 | 12 | Currently, the VT layer only supports VGA device. 13 | 14 | config TTY_SERIAL 15 | bool "Serial Output" 16 | default y 17 | help 18 | If you say Y here, the printk() function will emit the formatted 19 | string to Serial layer. If you are debugging Lego via serial port, 20 | you must say Y here. 21 | 22 | choice 23 | prompt "TTY Port" 24 | depends on TTY_SERIAL 25 | default TTY_SERIAL_TTYS1 26 | 27 | config TTY_SERIAL_TTYS0 28 | bool "ttyS0" 29 | 30 | config TTY_SERIAL_TTYS1 31 | bool "ttyS1" 32 | 33 | endchoice 34 | 35 | choice 36 | prompt "TTY Baud Rate" 37 | depends on TTY_SERIAL 38 | default TTY_SERIAL_BAUD115200 39 | 40 | config TTY_SERIAL_BAUD9600 41 | bool "Baud 9600" 42 | 43 | config TTY_SERIAL_BAUD115200 44 | bool "Baud 115200" 45 | 46 | endchoice 47 | 48 | endmenu 49 | -------------------------------------------------------------------------------- /drivers/tty/Makefile: -------------------------------------------------------------------------------- 1 | obj-y := tty_io.o n_tty.o 2 | obj-y += serial/ 3 | obj-y += vt/ 4 | -------------------------------------------------------------------------------- /drivers/tty/serial/Makefile: -------------------------------------------------------------------------------- 1 | obj-y := serial.o 2 | -------------------------------------------------------------------------------- /drivers/tty/vt/Makefile: -------------------------------------------------------------------------------- 1 | obj-y := vt.o 2 | 3 | obj-y += vgacon.o 4 | obj-y += dummycon.o 5 | -------------------------------------------------------------------------------- /drivers/tty/vt/dummycon.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /include/lego/bcd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_BCD_H_ 11 | #define _LEGO_BCD_H_ 12 | 13 | #include 14 | 15 | #define bcd2bin(x) \ 16 | (__builtin_constant_p((u8 )(x)) ? \ 17 | const_bcd2bin(x) : \ 18 | _bcd2bin(x)) 19 | 20 | #define bin2bcd(x) \ 21 | (__builtin_constant_p((u8 )(x)) ? \ 22 | const_bin2bcd(x) : \ 23 | _bin2bcd(x)) 24 | 25 | #define const_bcd2bin(x) (((x) & 0x0f) + ((x) >> 4) * 10) 26 | #define const_bin2bcd(x) ((((x) / 10) << 4) + (x) % 10) 27 | 28 | unsigned _bcd2bin(unsigned char val) __attribute_const__; 29 | unsigned char _bin2bcd(unsigned val) __attribute_const__; 30 | 31 | #endif /* _LEGO_BCD_H_ */ 32 | -------------------------------------------------------------------------------- /include/lego/byteorder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_BYTEORDER_H_ 11 | #define _LEGO_BYTEORDER_H_ 12 | 13 | #include 14 | 15 | #endif /* _LEGO_BYTEORDER_H_ */ 16 | -------------------------------------------------------------------------------- /include/lego/checksum.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_CHECKSUM_H_ 11 | #define _LEGO_CHECKSUM_H_ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | #ifndef HAVE_ARCH_CSUM_ADD 18 | static inline __wsum csum_add(__wsum csum, __wsum addend) 19 | { 20 | u32 res = (__force u32)csum; 21 | res += (__force u32)addend; 22 | return (__force __wsum)(res + (res < (__force u32)addend)); 23 | } 24 | #endif 25 | 26 | static inline __wsum csum_sub(__wsum csum, __wsum addend) 27 | { 28 | return csum_add(csum, ~addend); 29 | } 30 | 31 | static inline __sum16 csum16_add(__sum16 csum, __be16 addend) 32 | { 33 | u16 res = (__force u16)csum; 34 | 35 | res += (__force u16)addend; 36 | return (__force __sum16)(res + (res < (__force u16)addend)); 37 | } 38 | 39 | static inline __sum16 csum16_sub(__sum16 csum, __be16 addend) 40 | { 41 | return csum16_add(csum, ~addend); 42 | } 43 | 44 | #endif /* _LEGO_CHECKSUM_H_ */ 45 | -------------------------------------------------------------------------------- /include/lego/comp_memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_COMP_MEMORY_H_ 11 | #define _LEGO_COMP_MEMORY_H_ 12 | 13 | #ifdef CONFIG_COMP_MEMORY 14 | void __init memory_manager_early_init(void); 15 | void __init memory_component_init(void); 16 | #else 17 | static inline void memory_manager_early_init(void) { } 18 | static inline void memory_component_init(void) { } 19 | #endif 20 | 21 | #endif /* _LEGO_COMP_MEMORY_H_ */ 22 | -------------------------------------------------------------------------------- /include/lego/comp_storage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | /* 11 | * Things shared by both processor-component and storage-component 12 | */ 13 | 14 | #ifndef _LEGO_COMP_STORAGE_H_ 15 | #define _LEGO_COMP_STORAGE_H_ 16 | 17 | #include 18 | 19 | #define DEBUG_STORAGE 20 | 21 | #define O_CREAT 00000100 22 | #define O_WRONLY 00000001 23 | #define O_RDONLY 00000000 24 | #define O_RDWR 00000002 25 | 26 | #define PREFETCH_ORDER 7 /* prefetching 128 pages a time */ 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /include/lego/const.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * Macros for dealing with constants. 5 | */ 6 | 7 | #ifndef _LEGO_CONST_H_ 8 | #define _LEGO_CONST_H_ 9 | 10 | /* 11 | * Some constant macros are used in both assembler and 12 | * C code. Therefore we cannot annotate them always with 13 | * 'UL' and other type specifiers unilaterally. We use 14 | * the following macros to deal with this. 15 | * 16 | * Similarly, _AT() will cast an expression with a type in C, but 17 | * leave it unchanged in asm. 18 | */ 19 | 20 | #ifdef __ASSEMBLY__ 21 | #define _AC(X,Y) X 22 | #define _AT(T,X) X 23 | #else 24 | #define __AC(X,Y) (X##Y) 25 | #define _AC(X,Y) __AC(X,Y) 26 | #define _AT(T,X) ((T)(X)) 27 | #endif 28 | 29 | #define _BITUL(x) (_AC(1,UL) << (x)) 30 | #define _BITULL(x) (_AC(1,ULL) << (x)) 31 | 32 | #endif /* _LEGO_CONST_H_ */ 33 | -------------------------------------------------------------------------------- /include/lego/debug_locks.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | /* 11 | * This is the feature I want the most in Lego. 12 | * Check if any locks are still held during thread exit. 13 | */ 14 | 15 | #ifndef _LEGO_DEBUG_LOCKS_H_ 16 | #define _LEGO_DEBUG_LOCKS_H_ 17 | 18 | #ifdef CONFIG_LOCKDEP 19 | void debug_check_no_locks_held(void); 20 | #else 21 | static inline void 22 | debug_check_no_locks_held(void) 23 | { 24 | } 25 | #endif 26 | 27 | #endif /* _LEGO_DEBUG_LOCKS_H_ */ 28 | -------------------------------------------------------------------------------- /include/lego/dmapool.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_DMAPOOL_H_ 11 | #define _LEGO_DMAPOOL_H_ 12 | 13 | #include 14 | #include 15 | 16 | struct dma_pool *dma_pool_create(const char *name, struct device *dev, 17 | size_t size, size_t align, size_t boundary); 18 | 19 | void dma_pool_destroy(struct dma_pool *pool); 20 | 21 | void *dma_pool_alloc(struct dma_pool *pool, gfp_t mem_flags, 22 | dma_addr_t *handle); 23 | 24 | void dma_pool_free(struct dma_pool *pool, void *vaddr, dma_addr_t addr); 25 | 26 | #endif /* _LEGO_DMAPOOL_H_ */ 27 | -------------------------------------------------------------------------------- /include/lego/early_ioremap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_EARLY_IOREMAP_H_ 11 | #define _LEGO_EARLY_IOREMAP_H_ 12 | 13 | #include 14 | 15 | /* 16 | * early_ioremap() and early_iounmap() are for temporary early boot-time 17 | * mappings, before the real ioremap() is functional. 18 | */ 19 | void *early_ioremap(resource_size_t phys_addr, unsigned long size); 20 | void *early_memremap(resource_size_t phys_addr, unsigned long size); 21 | void early_iounmap(void *addr, unsigned long size); 22 | void early_memunmap(void *addr, unsigned long size); 23 | 24 | /* Arch-specific initialization */ 25 | void early_ioremap_init(void); 26 | 27 | /* Generic initialization called by architecture code */ 28 | void early_ioremap_setup(void); 29 | 30 | /* Early copy from unmapped memory to kernel mapped memory */ 31 | void copy_from_early_mem(void *dest, phys_addr_t src, unsigned long size); 32 | 33 | extern int early_ioremap_debug; 34 | 35 | #endif /* _LEGO_EARLY_IOREMAP_H_ */ 36 | -------------------------------------------------------------------------------- /include/lego/extable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_EXTABLE_H_ 11 | #define _LEGO_EXTABLE_H_ 12 | 13 | #include 14 | 15 | const struct exception_table_entry * 16 | search_extable(const struct exception_table_entry *first, 17 | const struct exception_table_entry *last, 18 | unsigned long value); 19 | void sort_extable(struct exception_table_entry *start, 20 | struct exception_table_entry *finish); 21 | void sort_main_extable(void); 22 | 23 | /* Given an address, look for it in the exception tables */ 24 | const struct exception_table_entry *search_exception_tables(unsigned long addr); 25 | 26 | #endif /* _LEGO_EXTABLE_H_ */ 27 | -------------------------------------------------------------------------------- /include/lego/getcpu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | /* 11 | * For sys_getcpu 12 | */ 13 | 14 | #ifndef _LEGO_GETCPU_H_ 15 | #define _LEGO_GETCPU_H_ 16 | 17 | /* Cache for getcpu() to speed it up. Results might be a short time 18 | out of date, but will be faster. 19 | 20 | User programs should not refer to the contents of this structure. 21 | I repeat they should not refer to it. If they do they will break 22 | in future kernels. 23 | 24 | It is only a private cache for vgetcpu(). It will change in future kernels. 25 | The user program must store this information per thread (__thread) 26 | If you want 100% accurate information pass NULL instead. */ 27 | struct getcpu_cache { 28 | unsigned long blob[128 / sizeof(long)]; 29 | }; 30 | 31 | #endif /* _LEGO_GETCPU_H_ */ 32 | -------------------------------------------------------------------------------- /include/lego/kbuild.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_KBUILD_H_ 11 | #define _LEGO_KBUILD_H_ 12 | 13 | #define DEFINE(sym, val) \ 14 | asm volatile("\n->" #sym " %0 " #val : : "i" (val)) 15 | 16 | #define BLANK() asm volatile("\n->" : : ) 17 | 18 | #define OFFSET(sym, str, mem) \ 19 | DEFINE(sym, offsetof(struct str, mem)) 20 | 21 | #define COMMENT(x) \ 22 | asm volatile("\n->#" x) 23 | 24 | #endif /* _LEGO_KBUILD_H_ */ 25 | -------------------------------------------------------------------------------- /include/lego/kref.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_KREF_H_ 11 | #define _LEGO_KREF_H_ 12 | 13 | #include 14 | 15 | struct kref { 16 | atomic_t refcount; 17 | }; 18 | 19 | #endif /* _LEGO_KREF_H_ */ 20 | -------------------------------------------------------------------------------- /include/lego/magic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_MAGIC_H_ 11 | #define _LEGO_MAGIC_H_ 12 | 13 | #define STACK_END_MAGIC 0x57AC6E9D 14 | 15 | #endif /* _LEGO_MAGIC_H_ */ 16 | -------------------------------------------------------------------------------- /include/lego/memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #ifdef CONFIG_MEMCOMPONENT 15 | void memcomponent_init(void); 16 | void memory_cleanup(void); 17 | void mem_handle_fault(struct task_struct *task, unsigned long address); 18 | #else 19 | static inline void memcomponent_init(void) { } 20 | static inline void memcomponent_cleanup(void) { } 21 | static inline void mem_handle_fault(struct task_struct *task, unsigned long address) { } 22 | #endif 23 | 24 | -------------------------------------------------------------------------------- /include/lego/mm_debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_MM_DEBUG_H_ 11 | #define _LEGO_MM_DEBUG_H_ 12 | 13 | #include 14 | #include 15 | 16 | void dump_page(struct page *, const char *); 17 | extern const struct trace_print_flags pageflag_names[]; 18 | 19 | void dump_pte(pte_t *, const char *); 20 | extern const struct trace_print_flags pteflag_names[]; 21 | 22 | /* 23 | * MM Debug Related 24 | */ 25 | #define VM_WARN_ON(cond) WARN_ON(cond) 26 | #define VM_WARN_ON_ONCE(cond) WARN_ON_ONCE(cond) 27 | #define VM_BUG_ON(cond) BUG_ON(cond) 28 | #define VM_BUG_ON_PAGE(cond, page) \ 29 | do { \ 30 | if (unlikely(cond)) { \ 31 | dump_page(page, "VM_BUG_ON_PAGE(" __stringify(cond)")");\ 32 | BUG(); \ 33 | } \ 34 | } while (0) 35 | 36 | #endif /* _LEGO_MM_DEBUG_H_ */ 37 | -------------------------------------------------------------------------------- /include/lego/module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_MODULE_H_ 11 | #define _LEGO_MODULE_H_ 12 | 13 | #define MODULE_PARM_DESC(_parm, desc) 14 | 15 | #endif /* _LEGO_MODULE_H_ */ 16 | -------------------------------------------------------------------------------- /include/lego/netmacro.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | enum NET_REUEST_OPS { 11 | 12 | /* commands sent to memory */ 13 | OP_ALLOC, 14 | OP_FREE, 15 | OP_MMAP, 16 | OP_MUNMAP, 17 | OP_MSYNC, 18 | OP_LOAD, 19 | OP_STORE, 20 | 21 | /* commands sent to storage */ 22 | OP_OPEN, 23 | OP_CLOSE, 24 | OP_READ, 25 | OP_WRITE, 26 | 27 | __NR_NET_REQUEST_OPS 28 | }; 29 | 30 | enum NET_REPLY_STATUS { 31 | REPLY_SUCCESS, 32 | REPLY_INVALID_OP, 33 | REPLY_ENOMEM, 34 | REPLY_EINVAL, 35 | REPLY_EBUSY, 36 | 37 | __NR_NET_REPLY_STATUS 38 | }; 39 | -------------------------------------------------------------------------------- /include/lego/numa.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_NUMA_H_ 11 | #define _LEGO_NUMA_H_ 12 | 13 | #ifdef CONFIG_NODES_SHIFT 14 | #define NODES_SHIFT CONFIG_NODES_SHIFT 15 | #else 16 | #define NODES_SHIFT 0 17 | #endif 18 | 19 | #define MAX_NUMNODES (1 << NODES_SHIFT) 20 | 21 | #define NUMA_NO_NODE (-1) 22 | 23 | #endif /* _LEGO_NUMA_H_ */ 24 | -------------------------------------------------------------------------------- /include/lego/panic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_PANIC_H_ 11 | #define _LEGO_PANIC_H_ 12 | 13 | #include 14 | 15 | __printf(1, 2) void panic(const char *fmt, ...) __cold; 16 | 17 | #endif /* _LEGO_PANIC_H_ */ 18 | -------------------------------------------------------------------------------- /include/lego/pfn.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_PFN_H_ 11 | #define _LEGO_PFN_H_ 12 | 13 | #include 14 | #include 15 | 16 | #define PFN_ALIGN(x) (((unsigned long)(x) + (PAGE_SIZE - 1)) & PAGE_MASK) 17 | #define PFN_UP(x) (((x) + PAGE_SIZE-1) >> PAGE_SHIFT) 18 | #define PFN_DOWN(x) ((x) >> PAGE_SHIFT) 19 | #define PFN_PHYS(x) ((phys_addr_t)(x) << PAGE_SHIFT) 20 | #define PHYS_PFN(x) ((unsigned long)((x) >> PAGE_SHIFT)) 21 | 22 | #endif /* _LEGO_PFN_H_ */ 23 | -------------------------------------------------------------------------------- /include/lego/pgfault.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_PGFAULT_H_ 11 | #define _LEGO_PGFAULT_H_ 12 | 13 | /* 14 | * Different kinds of faults, used by P's pgfault handler 15 | * and M's pcache handler. 16 | */ 17 | #define VM_FAULT_OOM 0x0001 18 | #define VM_FAULT_SIGBUS 0x0002 19 | #define VM_FAULT_MAJOR 0x0004 20 | #define VM_FAULT_WRITE 0x0008 /* Special case for get_user_pages */ 21 | #define VM_FAULT_HWPOISON 0x0010 /* Hit poisoned small page */ 22 | #define VM_FAULT_SIGSEGV 0x0040 23 | #define VM_FAULT_NOPAGE 0x0100 /* ->fault installed pte, not return page */ 24 | #define VM_FAULT_LOCKED 0x0200 /* ->fault locked the returned page */ 25 | #define VM_FAULT_RETRY 0x0400 /* ->fault blocked, must retry */ 26 | 27 | #define VM_FAULT_ERROR (VM_FAULT_OOM | VM_FAULT_SIGBUS | VM_FAULT_SIGSEGV | \ 28 | VM_FAULT_HWPOISON ) 29 | 30 | #endif /* _LEGO_PGFAULT_H_ */ 31 | -------------------------------------------------------------------------------- /include/lego/pid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_PID_H_ 11 | #define _LEGO_PID_H_ 12 | 13 | #include 14 | 15 | /* 16 | * XXX: 17 | * 18 | * Currently in Lego, we don't support pgid 19 | * thus pid == pgid 20 | */ 21 | enum pid_type 22 | { 23 | PIDTYPE_PID, 24 | PIDTYPE_PGID, 25 | PIDTYPE_SID, 26 | PIDTYPE_MAX, 27 | 28 | /* only valid to __task_pid_nr_ns() */ 29 | __PIDTYPE_TGID 30 | }; 31 | 32 | pid_t alloc_pid(struct task_struct *p); 33 | void free_pid(pid_t pid); 34 | 35 | struct task_struct *find_task_by_pid(pid_t pid); 36 | 37 | void __init pid_init(void); 38 | 39 | #endif /* _LEGO_PID_H_ */ 40 | -------------------------------------------------------------------------------- /include/lego/ptrace.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_PTRACE_H_ 11 | #define _LEGO_PTRACE_H_ 12 | 13 | #include 14 | #include 15 | 16 | #ifndef current_pt_regs 17 | #define current_pt_regs() task_pt_regs(current) 18 | #endif 19 | 20 | static inline int ptrace_reparented(struct task_struct *child) 21 | { 22 | return !same_thread_group(child->real_parent, child->parent); 23 | } 24 | 25 | #endif /* _LEGO_PTRACE_H_ */ 26 | -------------------------------------------------------------------------------- /include/lego/random.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | /* Random Number Generator (RNG) */ 11 | 12 | #ifndef _LEGO_RANDOM_H_ 13 | #define _LEGO_RANDOM_H_ 14 | 15 | void get_random_bytes(void *buf, int nbytes); 16 | 17 | #endif /* _LEGO_RANDOM_H_ */ 18 | -------------------------------------------------------------------------------- /include/lego/range.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_RANGE_H_ 11 | #define _LEGO_RANGE_H_ 12 | 13 | struct range { 14 | u64 start; 15 | u64 end; 16 | }; 17 | 18 | #define MAX_RESOURCE ((resource_size_t)~0) 19 | 20 | #endif /* _LEGO_RANGE_H_ */ 21 | -------------------------------------------------------------------------------- /include/lego/rpc/struct_m2s.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_RPC_STRUCT_M2S_H_ 11 | #define _LEGO_RPC_STRUCT_M2S_H_ 12 | 13 | #include 14 | #include 15 | 16 | /* 17 | * BIG FAT NOTE: 18 | * Storage recevier only expect the opcode at top. 19 | * No struct common_header should be used here. 20 | * 21 | * It is not consistent with the rest of system, 22 | * should be changed! 23 | */ 24 | 25 | /* M2S_READ */ 26 | /* M2S_WRITE */ 27 | struct m2s_read_write_payload { 28 | int uid; 29 | char filename[MAX_FILENAME_LENGTH]; 30 | int flags; 31 | size_t len; 32 | loff_t offset; 33 | }; 34 | 35 | struct m2s_lseek_struct { 36 | char filename[MAX_FILENAME_LENGTH]; 37 | }; 38 | 39 | /* M2S_REPLICA_FLUSH */ 40 | struct m2s_replica_flush_msg { 41 | unsigned int opcode; 42 | unsigned int nr_log; 43 | 44 | /* variable length buffer */ 45 | char log[0]; 46 | }; 47 | 48 | /* M2S_REPLICA_VMA */ 49 | struct m2s_replica_vma_msg { 50 | unsigned int opcode; 51 | struct replica_vma_log log; 52 | }; 53 | 54 | #endif /* _LEGO_RPC_STRUCT_M2S_H_ */ 55 | -------------------------------------------------------------------------------- /include/lego/rpc/struct_p2gm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_RPC_STRUCT_P2GM_H_ 11 | #define _LEGO_RPC_STRUCT_P2GM_H_ 12 | 13 | struct gsm2p_ret_struct { 14 | int mid; 15 | int sid; 16 | }; 17 | 18 | #endif /* _LEGO_RPC_STRUCT_P2GM_H_ */ 19 | -------------------------------------------------------------------------------- /include/lego/signalfd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_SIGNALFD_H_ 11 | #define _LEGO_SIGNALFD_H_ 12 | 13 | #include 14 | 15 | /* 16 | * TODO: signalfd SYSCALL 17 | */ 18 | 19 | #ifdef CONFIG_SIGNALFD 20 | /* 21 | * Deliver the signal to listening signalfd. 22 | */ 23 | static inline void signalfd_notify(struct task_struct *tsk, int sig) 24 | { 25 | BUG(); 26 | } 27 | void signalfd_cleanup(struct sighand_struct *sighand); 28 | #else 29 | static inline void signalfd_notify(struct task_struct *tsk, int sig) { } 30 | static inline void signalfd_cleanup(struct sighand_struct *sighand) { } 31 | #endif 32 | 33 | #endif /* _LEGO_SIGNALFD_H_ */ 34 | -------------------------------------------------------------------------------- /include/lego/stddef.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_STDDEF_H_ 11 | #define _LEGO_STDDEF_H_ 12 | 13 | #include 14 | 15 | #undef NULL 16 | #define NULL ((void *)0) 17 | 18 | enum { 19 | false = 0, 20 | true = 1 21 | }; 22 | 23 | #undef offsetof 24 | #ifdef __compiler_offsetof 25 | #define offsetof(TYPE, MEMBER) __compiler_offsetof(TYPE, MEMBER) 26 | #else 27 | #define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER) 28 | #endif 29 | 30 | /** 31 | * offsetofend(TYPE, MEMBER) 32 | * 33 | * @TYPE: The type of the structure 34 | * @MEMBER: The member within the structure to get the end offset of 35 | */ 36 | #define offsetofend(TYPE, MEMBER) \ 37 | (offsetof(TYPE, MEMBER) + sizeof(((TYPE *)0)->MEMBER)) 38 | 39 | #endif /* _LEGO_STDDEF_H_ */ 40 | -------------------------------------------------------------------------------- /include/lego/strace.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_STRACE_H_ 11 | #define _LEGO_STRACE_H_ 12 | 13 | #include 14 | #include 15 | 16 | struct pt_regs; 17 | 18 | #ifdef CONFIG_STRACE 19 | void strace_syscall_enter(struct pt_regs *regs); 20 | void strace_syscall_exit(struct pt_regs *regs); 21 | 22 | /* Hook for fork() and exit() */ 23 | int __fork_processor_strace(struct task_struct *p); 24 | int fork_processor_strace(struct task_struct *p); 25 | void exit_processor_strace(struct task_struct *p); 26 | #else 27 | static inline void strace_syscall_enter(struct pt_regs *regs) { } 28 | static inline void strace_syscall_exit(struct pt_regs *regs) { } 29 | 30 | static inline int __fork_processor_strace(struct task_struct *p) 31 | { 32 | return 0; 33 | } 34 | 35 | static inline int fork_processor_strace(struct task_struct *p) 36 | { 37 | return 0; 38 | } 39 | 40 | static inline void exit_processor_strace(struct task_struct *p) 41 | { 42 | 43 | } 44 | #endif /* CONFIG_STRACE */ 45 | 46 | #endif /* _LEGO_STRACE_H_ */ 47 | -------------------------------------------------------------------------------- /include/lego/stringify.h: -------------------------------------------------------------------------------- 1 | #ifndef _LEGO_STRINGIFY_H_ 2 | #define _LEGO_STRINGIFY_H_ 3 | 4 | /* 5 | * Indirect stringification. Doing two levels allows the parameter to be a 6 | * macro itself. For example, compile with -DFOO=bar, __stringify(FOO) 7 | * converts to "bar". 8 | */ 9 | 10 | #define __stringify_1(x...) #x 11 | #define __stringify(x...) __stringify_1(x) 12 | 13 | #endif /* _LEGO_STRINGIFY_H_ */ 14 | -------------------------------------------------------------------------------- /include/lego/sysinfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | /* 11 | * lego_sysinfo is used to report the per-manager resource usage 12 | * This is different from `struct sysinfo`, which is used by sysinfo syscall. 13 | * That one should report the free memory info within user's subscription. 14 | */ 15 | 16 | #ifndef _LEGO_SYSINFO_H_ 17 | #define _LEGO_SYSINFO_H_ 18 | 19 | #include 20 | 21 | struct manager_sysinfo { 22 | long uptime; /* Seconds since boot */ 23 | unsigned long loads[3]; /* 1, 5, and 15 minute load averages */ 24 | unsigned long totalram; /* Total usable main memory size */ 25 | unsigned long freeram; /* Available memory size */ 26 | __u16 procs; /* Number of current processes */ 27 | __u32 mem_unit; /* Memory unit size in bytes */ 28 | }; 29 | 30 | void manager_meminfo(struct manager_sysinfo *val); 31 | 32 | #endif /* _LEGO_SYSINFO_H_ */ 33 | -------------------------------------------------------------------------------- /include/lego/tracepoint.h: -------------------------------------------------------------------------------- 1 | #ifndef _LEGO_TRACEPOINT_H_ 2 | #define _LEGO_TRACEPOINT_H_ 3 | 4 | struct trace_print_flags { 5 | unsigned long mask; 6 | const char *name; 7 | }; 8 | 9 | struct tracepoint_func { 10 | void *func; 11 | void *data; 12 | int prio; 13 | }; 14 | 15 | struct tracepoint { 16 | const char *name; /* Tracepoint name */ 17 | void (*regfunc)(void); 18 | void (*unregfunc)(void); 19 | struct tracepoint_func *funcs; 20 | }; 21 | 22 | #endif /* _LEGO_TRACEPOINT_H_ */ 23 | -------------------------------------------------------------------------------- /include/lego/typecheck.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_TYPECHECK_H_ 11 | #define _LEGO_TYPECHECK_H_ 12 | 13 | /* 14 | * Check at compile time that something is of a particular type. 15 | * Compiler will give you a warning. 16 | */ 17 | #define typecheck(type, x) \ 18 | ({ \ 19 | type __dummy; \ 20 | typeof(x) __dummy2; \ 21 | (void)(&__dummy == & __dummy2); \ 22 | 1; \ 23 | }) 24 | 25 | /* 26 | * Check at compile time that 'function' is a certain type, or is a pointer 27 | * to that type (needs to use typedef for the function type.) 28 | */ 29 | #define typecheck_fn(type,function) \ 30 | ({ \ 31 | typeof(type) __tmp = function; \ 32 | (void)__tmp; \ 33 | }) 34 | 35 | #endif /* _LEGO_TYPECHECK_H_ */ 36 | -------------------------------------------------------------------------------- /include/lego/utsname.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_UTSNAME_H_ 11 | #define _LEGO_UTSNAME_H_ 12 | 13 | /* 14 | * Defines for what uname() should return 15 | */ 16 | 17 | #define UTS_SYSNAME "LegoOS" 18 | 19 | #define UTS_NODENAME CONFIG_DEFAULT_HOSTNAME /* set by sethostname() */ 20 | 21 | #define UTS_DOMAINNAME "(none)" /* set by setdomainname() */ 22 | 23 | #define UTS_LEN 64 24 | 25 | struct utsname { 26 | char sysname[UTS_LEN + 1]; 27 | char nodename[UTS_LEN + 1]; 28 | char release[UTS_LEN + 1]; 29 | char version[UTS_LEN + 1]; 30 | char machine[UTS_LEN + 1]; 31 | char domainname[UTS_LEN + 1]; 32 | }; 33 | 34 | extern struct utsname utsname; 35 | 36 | #endif /* _LEGO_UTSNAME_H_ */ 37 | -------------------------------------------------------------------------------- /include/memory/elf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_MEMORY_ELF_H_ 11 | #define _LEGO_MEMORY_ELF_H_ 12 | 13 | #include 14 | 15 | #endif /* _LEGO_MEMORY_ELF_H_ */ 16 | -------------------------------------------------------------------------------- /include/memory/pid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_MEMORY_PID_H_ 11 | #define _LEGO_MEMORY_PID_H_ 12 | 13 | #include 14 | 15 | void free_lego_task(struct lego_task_struct *tsk); 16 | 17 | int __must_check ht_insert_lego_task(struct lego_task_struct *tsk); 18 | 19 | struct lego_task_struct * 20 | find_lego_task_by_pid(unsigned int node, unsigned int pid); 21 | 22 | #endif /* _LEGO_MEMORY_PID_H_ */ 23 | -------------------------------------------------------------------------------- /include/memory/ramfs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_MEMORY_RAMFS_H_ 11 | #define _LEGO_MEMORY_RAMFS_H_ 12 | 13 | #endif /* _LEGO_MEMORY_RAMFS_H_ */ 14 | -------------------------------------------------------------------------------- /include/monitor/gmm_handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _GMM_HANDLER_H 11 | #define _GMM_HANDLER_H 12 | 13 | #ifdef CONFIG_GMM 14 | void __init gmm_init(void); 15 | #else 16 | static inline void gmm_init(void) { } 17 | #endif 18 | 19 | #endif /* _GMM_HANDLER_H */ 20 | -------------------------------------------------------------------------------- /include/monitor/gpm_handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _GPM_HANDLER_H 11 | #define _GPM_HANDLER_H 12 | 13 | #define MAX_RXBUF_SIZE (PAGE_SIZE * 20) 14 | 15 | #ifdef CONFIG_GPM 16 | 17 | void gpm_handler_init(void); 18 | void report_proc_exit(int ret_val); 19 | 20 | #else 21 | 22 | static inline void gpm_handler_init(void) {} 23 | static inline void report_proc_exit(int ret_val) {} 24 | 25 | #endif 26 | 27 | #endif /* _GPM_HANDLER_H */ 28 | -------------------------------------------------------------------------------- /include/net/arch/cc.h: -------------------------------------------------------------------------------- 1 | #ifndef LWIP_ARCH_CC_H 2 | #define LWIP_ARCH_CC_H 3 | 4 | #include 5 | #include 6 | #include 7 | //#include 8 | 9 | typedef u32 u32_t; 10 | typedef s32 s32_t; 11 | 12 | typedef u64 u64_t; 13 | typedef s64 s64_t; 14 | 15 | typedef u16 u16_t; 16 | typedef s16 s16_t; 17 | 18 | typedef u8 u8_t; 19 | typedef s8 s8_t; 20 | 21 | typedef uintptr_t mem_ptr_t; 22 | 23 | #define PACK_STRUCT_FIELD(x) x 24 | #define PACK_STRUCT_STRUCT 25 | #define PACK_STRUCT_BEGIN 26 | #define PACK_STRUCT_END 27 | 28 | #define S16_F "d" 29 | #define U16_F "u" 30 | #define X16_F "x" 31 | 32 | #define S32_F "d" 33 | #define U32_F "u" 34 | #define X32_F "x" 35 | 36 | #define LWIP_PLATFORM_DIAG(x) //pr_debug(x) 37 | #define LWIP_PLATFORM_ASSERT(x) panic(x) 38 | 39 | #ifndef BYTE_ORDER 40 | #define BYTE_ORDER LITTLE_ENDIAN 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /include/net/arch/perf.h: -------------------------------------------------------------------------------- 1 | #ifndef LWIP_ARCH_PERF_H 2 | #define LWIP_ARCH_PERF_H 3 | 4 | #define PERF_START 5 | #define PERF_STOP(x) 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /include/net/arch/perror.h: -------------------------------------------------------------------------------- 1 | #ifndef LEGO_INC_PERROR_H 2 | #define LEGO_INC_PERROR_H 3 | 4 | void perror(const char *s); 5 | const char *e2s(int e); 6 | 7 | #endif /* !LEGO_INC_PERROR_H */ 8 | -------------------------------------------------------------------------------- /include/net/arch/setjmp.h: -------------------------------------------------------------------------------- 1 | #ifndef LEGO_INC_SETJMP_H 2 | #define LEGO_INC_SETJMP_H 3 | 4 | #include 5 | 6 | #define LEGO_LONGJMP_GCCATTR regparm(2) 7 | 8 | struct lego_jmp_buf { 9 | u64 jb_rip; 10 | u64 jb_rsp; 11 | u64 jb_rbp; 12 | u64 jb_rbx; 13 | u64 jb_rsi; 14 | u64 jb_rdi; 15 | u64 jb_r15; 16 | u64 jb_r14; 17 | u64 jb_r13; 18 | u64 jb_r12; 19 | u64 jb_r11; 20 | u64 jb_r10; 21 | u64 jb_r9; 22 | u64 jb_r8; 23 | }; 24 | 25 | int lego_setjmp(volatile struct lego_jmp_buf *buf); 26 | void lego_longjmp(volatile struct lego_jmp_buf *buf, int val) 27 | __attribute__((__noreturn__, LEGO_LONGJMP_GCCATTR)); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /include/net/arch/sys_arch.h: -------------------------------------------------------------------------------- 1 | #ifndef LWIP_ARCH_SYS_ARCH_H 2 | #define LWIP_ARCH_SYS_ARCH_H 3 | 4 | #include 5 | 6 | typedef int sys_sem_t; 7 | typedef int sys_mbox_t; 8 | typedef int sys_thread_t; 9 | 10 | #define SYS_MBOX_NULL (-1) 11 | #define SYS_SEM_NULL (-1) 12 | 13 | void lwip_core_lock(void); 14 | void lwip_core_unlock(void); 15 | void lwip_core_init(void); 16 | 17 | #define SYS_ARCH_DECL_PROTECT(lev) 18 | #define SYS_ARCH_PROTECT(lev) 19 | #define SYS_ARCH_UNPROTECT(lev) 20 | 21 | #define SYS_ARCH_NOWAIT 0xfffffffe 22 | 23 | #include 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /include/net/arch/thread.h: -------------------------------------------------------------------------------- 1 | #ifndef LWIP_ARCH_THREAD_H 2 | #define LWIP_ARCH_THREAD_H 3 | 4 | #include 5 | 6 | typedef u32 thread_id_t; 7 | 8 | void thread_init(void); 9 | thread_id_t thread_id(void); 10 | void thread_wakeup(volatile u32 *addr); 11 | void thread_wait(volatile u32 *addr, u32 val, u32 msec); 12 | int thread_wakeups_pending(void); 13 | int thread_onhalt(void (*fun)(thread_id_t)); 14 | int thread_create(thread_id_t *tid, const char *name, 15 | void (*entry)(u64), u64 arg); 16 | void thread_yield(void); 17 | void thread_halt(void); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /include/processor/pcache_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_PROCESSOR_PCACHE_CONFIG_H_ 11 | #define _LEGO_PROCESSOR_PCACHE_CONFIG_H_ 12 | 13 | #include 14 | 15 | /* 16 | * This file should only be included by Processor and Memory managers. 17 | */ 18 | 19 | #ifdef CONFIG_PCACHE_LINE_SIZE_SHIFT 20 | # define PCACHE_LINE_SIZE_SHIFT (CONFIG_PCACHE_LINE_SIZE_SHIFT) 21 | #else 22 | # define PCACHE_LINE_SIZE_SHIFT (12) 23 | #endif 24 | 25 | #ifdef CONFIG_PCACHE_ASSOCIATIVITY_SHIFT 26 | # define PCACHE_ASSOCIATIVITY_SHIFT (CONFIG_PCACHE_ASSOCIATIVITY_SHIFT) 27 | #else 28 | # define PCACHE_ASSOCIATIVITY_SHIFT (3) 29 | #endif 30 | 31 | #define PCACHE_LINE_SIZE (_AC(1,UL) << PCACHE_LINE_SIZE_SHIFT) 32 | #define PCACHE_LINE_MASK (~(PCACHE_LINE_SIZE-1)) 33 | #define PCACHE_ASSOCIATIVITY (_AC(1,UL) << PCACHE_ASSOCIATIVITY_SHIFT) 34 | 35 | #define PCACHE_LINE_NR_PAGES (PCACHE_LINE_SIZE / PAGE_SIZE) 36 | 37 | #endif /* _LEGO_PROCESSOR_PCACHE_CONFIG_H_ */ 38 | -------------------------------------------------------------------------------- /include/processor/replication.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_PROCESSOR_REPLICATION_H_ 11 | #define _LEGO_PROCESSOR_REPLICATION_H_ 12 | 13 | #ifdef CONFIG_REPLICATION_MEMORY 14 | void replicate(pid_t tgid, unsigned long user_va, 15 | unsigned int m_nid, unsigned int rep_nid, void *cache_addr); 16 | #else 17 | static inline void replicate(pid_t tgid, unsigned long user_va, 18 | unsigned int m_nid, unsigned int rep_nid, void *cache_addr) { } 19 | #endif 20 | 21 | #endif /* _LEGO_PROCESSOR_REPLICATION_H_ */ 22 | -------------------------------------------------------------------------------- /include/processor/statfs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_PROCESSOR_STATFS_H_ 11 | #define _LEGO_PROCESSOR_STATFS_H_ 12 | 13 | /* 14 | * struct kstatfs; 15 | * Add lego_ prefix to avoid redefition, because this file 16 | * is include by storage linux module as well. 17 | */ 18 | 19 | struct lego_kstatfs { 20 | long f_type; 21 | long f_bsize; 22 | u64 f_blocks; 23 | u64 f_bfree; 24 | u64 f_bavail; 25 | u64 f_files; 26 | u64 f_ffree; 27 | __kernel_fsid_t f_fsid; 28 | long f_namelen; 29 | long f_frsize; 30 | long f_flags; 31 | long f_spare[4]; 32 | }; 33 | 34 | #endif /* _LEGO_PROCESSOR_STATFS_H_ */ 35 | -------------------------------------------------------------------------------- /include/processor/vnode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_PROCESSOR_VNODE_H_ 11 | #define _LEGO_PROCESSOR_VNODE_H_ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #ifdef CONFIG_VNODE 20 | 21 | inline bool vnode_exist(int vid); 22 | 23 | struct vnode_struct *ip_find_vnode(int ip); 24 | inline struct vnode_struct *vid_find_vnode(int vid); 25 | 26 | int p2pm_request_vnode(void); 27 | void handle_pm2p_broadcast_vnode(struct pm2p_broadcast_vnode_struct *vnode, u64 desc); 28 | 29 | #else 30 | static inline bool vnode_exist(int vid) { return false; } 31 | static inline struct vnode_struct *ip_find_vnode(int ip) { return NULL; } 32 | static inline struct vnode_struct *vid_find_vnode(int vid) { return NULL; } 33 | static inline int p2pm_request_vnode(void) { return -EPERM; } 34 | static inline void 35 | handle_pm2p_broadcast_vnode(struct pm2p_broadcast_vnode_struct *vnode, u64 desc) {} 36 | #endif /* CONFIG_VNODE */ 37 | 38 | #endif /* _LEGO_PROCESSOR_VNODE_H_ */ 39 | -------------------------------------------------------------------------------- /include/processor/vnode_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_PROCESSOR_VNODE_TYPES_H_ 11 | #define _LEGO_PROCESSOR_VNODE_TYPES_H_ 12 | 13 | #include 14 | 15 | struct vnode_struct { 16 | int p_nid; 17 | int vid; 18 | int ip; 19 | struct hlist_node node; 20 | } __attribute__((packed)) __attribute__((aligned(64))); 21 | 22 | #endif /* _LEGO_PROCESSOR_VNODE_TYPES_H_ */ 23 | -------------------------------------------------------------------------------- /include/uapi/fit.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_UAPI_FIT_H_ 11 | #define _LEGO_UAPI_FIT_H_ 12 | 13 | enum lego_manager_type{ 14 | LEGO_PROCESSOR, 15 | LEGO_MEMORY, 16 | LEGO_STORAGE, 17 | }; 18 | 19 | #define FIT_HOSTNAME_MAX 16 20 | 21 | struct fit_machine_info { 22 | const char hostname[FIT_HOSTNAME_MAX]; 23 | unsigned long lid; 24 | unsigned int first_qpn; 25 | enum lego_manager_type type; 26 | }; 27 | 28 | /* 29 | * Maximum timeout for a ibapi_send_reply_timeout call 30 | */ 31 | #define FIT_MAX_TIMEOUT_SEC CONFIG_FIT_MAX_RPC_TIMEOUT_SEC 32 | 33 | #endif /* _LEGO_UAPI_FIT_H_ */ 34 | -------------------------------------------------------------------------------- /include/uapi/limits.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_UAPI_LIMITS_H_ 11 | #define _LEGO_UAPI_LIMITS_H_ 12 | 13 | #define NR_OPEN 1024 14 | 15 | #define NGROUPS_MAX 65536 /* supplemental group IDs are available */ 16 | #define ARG_MAX 131072 /* # bytes of args + environ for exec() */ 17 | #define LINK_MAX 127 /* # links a file may have */ 18 | #define MAX_CANON 255 /* size of the canonical input queue */ 19 | #define MAX_INPUT 255 /* size of the type-ahead buffer */ 20 | #define NAME_MAX 255 /* # chars in a file name */ 21 | #define PATH_MAX 4096 /* # chars in a path name including nul */ 22 | #define PIPE_BUF 4096 /* # bytes in atomic write to a pipe */ 23 | #define XATTR_NAME_MAX 255 /* # chars in an extended attribute name */ 24 | #define XATTR_SIZE_MAX 65536 /* size of an extended attribute value (64k) */ 25 | #define XATTR_LIST_MAX 65536 /* size of extended attribute namelist (64k) */ 26 | 27 | #define RTSIG_MAX 32 28 | 29 | #endif /* _LEGO_UAPI_LIMITS_H_ */ 30 | -------------------------------------------------------------------------------- /include/uapi/processor/pcache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_UAPI_PROCESSOR_PCACHE_H_ 11 | #define _LEGO_UAPI_PROCESSOR_PCACHE_H_ 12 | 13 | struct pcache_stat { 14 | /* 15 | * nr_cachelines = nr_cachesets * associativity; 16 | * way_stride = nr_cachesets * cacheline_size; 17 | */ 18 | unsigned long nr_cachelines; 19 | unsigned long nr_cachesets; 20 | unsigned long associativity; 21 | unsigned long cacheline_size; 22 | unsigned long way_stride; 23 | 24 | /* 25 | * Pcache Runtime Stats 26 | */ 27 | unsigned long nr_pgfault; 28 | unsigned long nr_pgfault_code; 29 | unsigned long nr_flush; 30 | unsigned long nr_eviction; 31 | }; 32 | 33 | #endif /* _LEGO_UAPI_PROCESSOR_PCACHE_H_ */ 34 | -------------------------------------------------------------------------------- /include/uapi/sysinfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_UAPI_SYSINFO_H_ 11 | #define _LEGO_UAPI_SYSINFO_H_ 12 | 13 | #include 14 | 15 | struct sysinfo { 16 | long uptime; /* Seconds since boot */ 17 | unsigned long loads[3]; /* 1, 5, and 15 minute load averages */ 18 | unsigned long totalram; /* Total usable main memory size */ 19 | unsigned long freeram; /* Available memory size */ 20 | unsigned long sharedram; /* Amount of shared memory */ 21 | unsigned long bufferram; /* Memory used by buffers */ 22 | unsigned long totalswap; /* Total swap space size */ 23 | unsigned long freeswap; /* swap space still available */ 24 | __u16 procs; /* Number of current processes */ 25 | __u16 pad; /* Explicit padding for m68k */ 26 | unsigned long totalhigh; /* Total high memory size */ 27 | unsigned long freehigh; /* Available high memory size */ 28 | __u32 mem_unit; /* Memory unit size in bytes */ 29 | char _f[20-2*sizeof(unsigned long)-sizeof(__u32)]; /* Padding: libc5 uses this.. */ 30 | }; 31 | 32 | #endif /* _LEGO_UAPI_SYSINFO_H_ */ 33 | -------------------------------------------------------------------------------- /init/Makefile: -------------------------------------------------------------------------------- 1 | obj-y := main.o version.o init_task.o 2 | obj-y += calibrate.o 3 | 4 | # dependencies on generated files need to be listed explicitly 5 | $(obj)/version.o: include/generated/compile.h 6 | 7 | # compile.h changes depending on hostname, generation number, etc, 8 | # so we regenerate it always. 9 | # mkcompile_h will make sure to only update the 10 | # actual file if its content has changed. 11 | 12 | chk_compile.h = : 13 | quiet_chk_compile.h = echo ' CHK $@' 14 | silent_chk_compile.h = : 15 | include/generated/compile.h: FORCE 16 | @$($(quiet)chk_compile.h) 17 | $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkcompile_h $@ \ 18 | "$(UTS_MACHINE)" "$(CONFIG_SMP)" "$(CONFIG_PREEMPT)" "$(CC) $(KBUILD_CFLAGS)" 19 | -------------------------------------------------------------------------------- /init/calibrate.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | unsigned long lpj_fine; 15 | 16 | /* 17 | * This should be approx 2 Bo*oMips to start (note initial shift), and will 18 | * still work even if initially too large, it will just take slightly longer 19 | */ 20 | unsigned long loops_per_jiffy = (1<<12); 21 | 22 | void __init calibrate_delay(void) 23 | { 24 | unsigned long lpj; 25 | 26 | if (lpj_fine) { 27 | lpj = lpj_fine; 28 | pr_info("Calibrating delay loop (skipped), " 29 | "value calculated using timer frequency.. \n"); 30 | } else { 31 | pr_warn("We do not have any real calibration code\n"); 32 | } 33 | 34 | pr_info("%lu.%02lu BogoMIPS (lpj=%lu)\n", 35 | lpj/(500000/HZ), 36 | (lpj/(5000/HZ)) % 100, lpj); 37 | 38 | loops_per_jiffy = lpj; 39 | } 40 | -------------------------------------------------------------------------------- /init/version.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | struct utsname utsname = { 15 | .sysname = UTS_SYSNAME, 16 | .nodename = UTS_NODENAME, 17 | .release = UTS_RELEASE, 18 | .version = UTS_VERSION, 19 | .machine = UTS_MACHINE, 20 | .domainname = UTS_DOMAINNAME, 21 | }; 22 | 23 | /* FIXED STRINGS! Don't touch! */ 24 | const char lego_banner[] = 25 | "LegoOS version " UTS_RELEASE " (" LEGO_COMPILE_BY "@" 26 | LEGO_COMPILE_HOST ") (" LEGO_COMPILER ") " UTS_VERSION "\n"; 27 | 28 | const char lego_proc_banner[] = 29 | "%s version %s" 30 | " (" LEGO_COMPILE_BY "@" LEGO_COMPILE_HOST ")" 31 | " (" LEGO_COMPILER ") %s\n"; 32 | -------------------------------------------------------------------------------- /kernel/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Lego core functionalities 3 | # 4 | 5 | obj-y := panic.o 6 | obj-y += printk.o 7 | obj-y += kallsyms.o 8 | obj-y += cpu.o 9 | obj-y += resource.o 10 | obj-y += smp.o 11 | obj-y += param.o 12 | obj-y += time/ 13 | obj-y += irq/ 14 | obj-y += sched/ 15 | obj-y += locking/ 16 | obj-y += fork.o 17 | obj-y += pid.o 18 | obj-y += exit.o 19 | obj-y += mutex.o 20 | obj-y += sys.o 21 | obj-y += kthread.o 22 | obj-y += extable.o 23 | obj-y += signal.o 24 | obj-y += coredump.o 25 | obj-y += madvise.o 26 | obj-y += stop_machine.o 27 | obj-y += smpboot.o 28 | obj-y += itimer.o 29 | 30 | obj-$(CONFIG_FUTEX) += futex.o 31 | obj-$(CONFIG_WORK_QUEUE) += workqueue.o 32 | obj-$(CONFIG_PROFILING) += profile/ 33 | -------------------------------------------------------------------------------- /kernel/bounds.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | /* 11 | * Generate definitions needed by the preprocessor. 12 | * This code generates raw asm output which is post-processed 13 | * to extract and format the required data. 14 | */ 15 | 16 | #define __GENERATING_BOUNDS_H 17 | 18 | #include 19 | 20 | /* Include headers that define the enum constants of interest */ 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | void wuklabisawesome(void) 28 | { 29 | /* The enum constants to put into include/generated/bounds.h */ 30 | DEFINE(MAX_NR_ZONES, __MAX_NR_ZONES); 31 | DEFINE(NR_PAGEFLAGS, __NR_PAGEFLAGS); 32 | #ifdef CONFIG_SMP 33 | DEFINE(NR_CPU_BITS, ilog2(CONFIG_NR_CPUS)); 34 | #endif 35 | DEFINE(SPINLOCK_SIZE, sizeof(spinlock_t)); 36 | DEFINE(STRUCT_PAGE_SIZE, sizeof(struct page)); 37 | } 38 | -------------------------------------------------------------------------------- /kernel/coredump.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | /* 11 | * TODO: coredump 12 | * Useful for debugging 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | void do_coredump(const siginfo_t *siginfo) 24 | { 25 | } 26 | -------------------------------------------------------------------------------- /kernel/irq/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Lego Interrupt ReQuest (IRQ) subsystem 3 | # 4 | 5 | obj-y := handle.o 6 | obj-y += dummychip.o 7 | obj-y += chip.o 8 | obj-y += irqdesc.o 9 | obj-y += irqaction.o 10 | obj-y += irqdomain.o 11 | obj-y += msi.o 12 | -------------------------------------------------------------------------------- /kernel/irq/irqaction.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include 11 | 12 | -------------------------------------------------------------------------------- /kernel/locking/Kconfig: -------------------------------------------------------------------------------- 1 | config DEBUG_SPINLOCK 2 | bool "Spinlock debugging" 3 | depends on DEBUG_KERNEL 4 | help 5 | Say Y here and have some very costly checking against possible deadlock. 6 | We don't have nice NMI watchdog. So, just some basic software checking. 7 | 8 | If unsure, please say N. 9 | -------------------------------------------------------------------------------- /kernel/locking/Makefile: -------------------------------------------------------------------------------- 1 | obj-y := rwsem.o rwsem-xadd.o 2 | obj-y += semaphore.o 3 | obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock.o 4 | -------------------------------------------------------------------------------- /kernel/profile/Makefile: -------------------------------------------------------------------------------- 1 | obj-$(CONFIG_PROFILING_BOOT) += boot.o 2 | obj-$(CONFIG_PROFILING_KERNEL_HEATMAP) += heatmap.o 3 | obj-$(CONFIG_PROFILING_POINTS) += point.o 4 | -------------------------------------------------------------------------------- /kernel/profile/boot.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | void boot_time_profile(void) 15 | { 16 | /* smp must be initalized first */ 17 | WARN_ON(system_state != SYSTEM_RUNNING); 18 | 19 | profile_tlb_shootdown(); 20 | } 21 | -------------------------------------------------------------------------------- /kernel/sched/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Lego Scheduler 3 | # 4 | 5 | obj-y := core.o 6 | obj-y += wait.o 7 | obj-y += idle.o 8 | obj-y += completion.o 9 | obj-y += cputime.o 10 | obj-y += debug.o 11 | obj-y += task_stop.o task_rt.o task_dl.o task_fair.o task_idle.o 12 | -------------------------------------------------------------------------------- /kernel/sched/idle.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | /* 11 | * CPU idle with: 12 | * Preempt disabled 13 | * Interrupt enabled 14 | */ 15 | 16 | #include 17 | #include 18 | 19 | #include "sched.h" 20 | 21 | /* Weak implementations for optional arch specific functions */ 22 | void __weak arch_cpu_idle_enter(void) { } 23 | void __weak arch_cpu_idle(void) { } 24 | 25 | void cpu_idle(void) 26 | { 27 | while (1) { 28 | while (!need_resched()) { 29 | /* NOTE: no locks or semaphores should be used here */ 30 | arch_safe_halt(); 31 | } 32 | 33 | schedule_preempt_disabled(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /kernel/sched/task_dl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | 11 | #include 12 | #include "sched.h" 13 | 14 | void init_dl_rq(struct dl_rq *dl_rq) 15 | { 16 | 17 | } 18 | 19 | const struct sched_class dl_sched_class = { 20 | .next = &rt_sched_class, 21 | }; 22 | -------------------------------------------------------------------------------- /kernel/time/Makefile: -------------------------------------------------------------------------------- 1 | # General Clockevent Infrastructure 2 | obj-y := clocksource.o 3 | obj-y += clockevents.o 4 | 5 | obj-y += jiffies.o 6 | obj-y += time.o 7 | obj-y += timekeeping.o 8 | obj-y += timer.o 9 | obj-y += posix-timers.o 10 | obj-y += ntp.o 11 | 12 | # Genetic Timer Interrupt Handler 13 | obj-y += tick-common.o 14 | -------------------------------------------------------------------------------- /kernel/time/internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _KERNEL_TIME_INTERNAL_H_ 11 | #define _KERNEL_TIME_INTERNAL_H_ 12 | 13 | u64 ntp_tick_length(void); 14 | int second_overflow(time_t secs); 15 | int __weak update_persistent_clock(struct timespec now); 16 | int ntp_validate_timex(struct timex *txc); 17 | ktime_t ntp_get_next_leap(void); 18 | void ntp_clear(void); 19 | void __init ntp_init(void); 20 | 21 | #endif /* _KERNEL_TIME_INTERNAL_H_ */ 22 | -------------------------------------------------------------------------------- /kernel/time/tick-internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _TICK_INTERNAL_H_ 11 | #define _TICK_INTERNAL_H_ 12 | 13 | enum tick_device_mode { 14 | TICKDEV_MODE_PERIODIC, 15 | TICKDEV_MODE_ONESHOT, 16 | }; 17 | 18 | struct tick_device { 19 | struct clock_event_device *evtdev; 20 | enum tick_device_mode mode; 21 | }; 22 | 23 | void tick_check_new_device(struct clock_event_device *newdev); 24 | 25 | /* Check, if the device is functional or a dummy for broadcast */ 26 | static inline int tick_device_is_functional(struct clock_event_device *dev) 27 | { 28 | return !(dev->features & CLOCK_EVT_FEAT_DUMMY); 29 | } 30 | 31 | int clockevents_program_event(struct clock_event_device *dev, ktime_t expires, 32 | bool force); 33 | 34 | #endif /* _TICK_INTERNAL_H_ */ 35 | -------------------------------------------------------------------------------- /lib/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Libraries: used by core-kernel 3 | # 4 | 5 | obj-y := vsprintf.o 6 | obj-y += ctype.o 7 | obj-y += hexdump.o 8 | obj-y += string.o 9 | obj-y += sort.o 10 | obj-y += find_bit.o 11 | obj-y += bitmap.o 12 | obj-y += hweight.o 13 | obj-y += rbtree.o 14 | obj-y += scatterlist.o 15 | obj-y += bcd.o 16 | obj-y += cpumask.o 17 | obj-y += cmdline.o 18 | obj-y += strncpy_from_user.o 19 | obj-y += strnlen_user.o 20 | obj-y += plist.o 21 | obj-y += dump_task_struct.o 22 | obj-y += ratelimit.o 23 | obj-y += kstrtox.o 24 | obj-y += random.o 25 | obj-y += sched.o 26 | obj-y += dump_remote_cpustack.o 27 | obj-y += radix-tree.o 28 | -------------------------------------------------------------------------------- /lib/bcd.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include 11 | 12 | unsigned _bcd2bin(unsigned char val) 13 | { 14 | return (val & 0x0f) + (val >> 4) * 10; 15 | } 16 | 17 | unsigned char _bin2bcd(unsigned val) 18 | { 19 | return ((val / 10) << 4) + val % 10; 20 | } 21 | -------------------------------------------------------------------------------- /lib/cpumask.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include 11 | 12 | /** 13 | * cpumask_next_and - get the next cpu in *src1p & *src2p 14 | * @n: the cpu prior to the place to search (ie. return will be > @n) 15 | * @src1p: the first cpumask pointer 16 | * @src2p: the second cpumask pointer 17 | * 18 | * Returns >= nr_cpu_ids if no further cpus set in both. 19 | */ 20 | int cpumask_next_and(int n, const struct cpumask *src1p, 21 | const struct cpumask *src2p) 22 | { 23 | while ((n = cpumask_next(n, src1p)) < nr_cpu_ids) 24 | if (cpumask_test_cpu(n, src2p)) 25 | break; 26 | return n; 27 | } 28 | 29 | /** 30 | * cpumask_any_but - return a "random" in a cpumask, but not this one. 31 | * @mask: the cpumask to search 32 | * @cpu: the cpu to ignore. 33 | * 34 | * Often used to find any cpu but smp_processor_id() in a mask. 35 | * Returns >= nr_cpu_ids if no cpus set. 36 | */ 37 | int cpumask_any_but(const struct cpumask *mask, unsigned int cpu) 38 | { 39 | unsigned int i; 40 | 41 | for_each_cpu(i, mask) 42 | if (i != cpu) 43 | break; 44 | return i; 45 | } 46 | -------------------------------------------------------------------------------- /lib/dump_remote_cpustack.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | /* 15 | * This is only valid if DEBUG_KERNEL is ON. 16 | * Because by default call_function handler will not save pt_regs. 17 | */ 18 | static void cpu_dumpstack_func(void *info) 19 | { 20 | struct pt_regs *regs = get_irq_regs(); 21 | show_regs(regs); 22 | } 23 | 24 | void cpu_dumpstack(int cpu) 25 | { 26 | smp_call_function_single(cpu, cpu_dumpstack_func, NULL, 1); 27 | } 28 | -------------------------------------------------------------------------------- /lib/random.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | static inline char __get_random_byte(void) 15 | { 16 | return (char)sched_clock(); 17 | } 18 | 19 | void get_random_bytes(void *buf, int nbytes) 20 | { 21 | int i; 22 | char *s = buf; 23 | 24 | if (WARN_ON(!nbytes)) 25 | return; 26 | 27 | for (i = 0; i < nbytes; i++) 28 | s[i] = __get_random_byte(); 29 | } 30 | -------------------------------------------------------------------------------- /lib/sched.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | /* 14 | * Helpers for scheduler related information 15 | */ 16 | 17 | void print_nr_cpus_allowd(int line) 18 | { 19 | char buf[64]; 20 | 21 | scnprintf(buf, 64, "%*pbl", NR_CPUS, ¤t->cpus_allowed); 22 | pr_info("Current: %d %s, nr_allowd: %d, %s (info: %d)\n", 23 | current->pid, current->comm, current->nr_cpus_allowed, buf, line); 24 | } 25 | -------------------------------------------------------------------------------- /linux-modules/.gitignore: -------------------------------------------------------------------------------- 1 | *.ko 2 | *.mod.c 3 | *.symtypes 4 | *.lst 5 | *.order 6 | modules.builtin 7 | Module.symvers 8 | *.c.[012]*.* 9 | -------------------------------------------------------------------------------- /linux-modules/Makefile: -------------------------------------------------------------------------------- 1 | # target modules 2 | MODULES := fit 3 | MODULES += storage 4 | MODULES += monitor 5 | 6 | # rules 7 | SUBDIRS := $(addprefix $(shell pwd)/, $(MODULES)) 8 | CLEAN_SUBDIRS := $(addsuffix .clean, $(SUBDIRS)) 9 | 10 | all: $(SUBDIRS) 11 | $(SUBDIRS): 12 | $(MAKE) -C $@ 13 | 14 | clean: $(CLEAN_SUBDIRS) 15 | $(CLEAN_SUBDIRS): 16 | $(MAKE) -C $(basename $@) clean 17 | 18 | fit_install: 19 | insmod $(shell pwd)/fit/fit.ko 20 | 21 | storage_install: 22 | insmod $(shell pwd)/storage/storage.ko 23 | 24 | monitor_install: 25 | $(MAKE) -C $(filter %monitor,$(SUBDIRS)) install 26 | 27 | help: 28 | @echo 'Targets compilation:' 29 | @echo ' default - Compile all linux modules' 30 | @echo ' clean - remove all generated files' 31 | @echo '' 32 | @echo 'Modules install:' 33 | @echo ' fit_install - insert fit module' 34 | @echo ' storage_install - insert storage module' 35 | @echo ' monitor_install - insert all monitor modules, including' 36 | @echo ' gpm, gmm, gum, and gm_dispatcher' 37 | 38 | .PHONY: all $(SUBDIRS) $(CLEAN_SUBDIRS) fit_install \ 39 | storage_install monitor_install help 40 | -------------------------------------------------------------------------------- /linux-modules/fit/Makefile: -------------------------------------------------------------------------------- 1 | obj-m := fit.o 2 | 3 | fit-y := fit_ibapi.o 4 | fit-y += fit_internal.o 5 | fit-y += fit_machine.o 6 | 7 | cflags += -g 8 | EXTRA_CFLAGS += -g 9 | 10 | all: 11 | make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules 12 | @echo -e "\e[00;31m****" 13 | @echo "**** WARNING" 14 | @echo "**** Compiled with -g option" 15 | @echo -e "****\e[00m" 16 | 17 | clean: 18 | make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) clean 19 | -------------------------------------------------------------------------------- /linux-modules/fit/fit_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LINUX_MODULE_FIT_CONFIG_H_ 11 | #define _LINUX_MODULE_FIT_CONFIG_H_ 12 | 13 | /* FIT module state */ 14 | #define FIT_MODULE_DOWN 0 15 | #define FIT_MODULE_UP 1 16 | 17 | /* Lego cluster config */ 18 | #define CONFIG_FIT_LOCAL_ID 2 19 | #define CONFIG_FIT_NR_NODES 3 20 | #define MAX_NODE CONFIG_FIT_NR_NODES 21 | 22 | /* 23 | * These configruations must match the numbers in P and M 24 | * Otherwise we will fail to connect. 25 | */ 26 | #define CONFIG_FIT_FIRST_QPN (80) 27 | #define CONFIG_FIT_NR_QPS_PER_PAIR (12) 28 | 29 | //#define CONFIG_SOCKET_O_IB 30 | 31 | #endif /* _LINUX_MODULE_FIT_CONFIG_H_ */ 32 | -------------------------------------------------------------------------------- /linux-modules/monitor/Makefile: -------------------------------------------------------------------------------- 1 | # target monitor modules 2 | MONITORS := gmm 3 | MONITORS += gpm 4 | MONITORS += gum 5 | MONITORS += gsm 6 | MONITORS += gm_dispatcher 7 | 8 | # rules 9 | SUBDIRS := $(addprefix $(shell pwd)/, $(MONITORS)) 10 | CLEAN_SUBDIRS := $(addsuffix .clean, $(SUBDIRS)) 11 | 12 | all: $(SUBDIRS) 13 | $(SUBDIRS): 14 | $(MAKE) -C $@ 15 | 16 | clean: $(CLEAN_SUBDIRS) 17 | $(CLEAN_SUBDIRS): 18 | $(MAKE) -C $(basename $@) clean 19 | 20 | install: 21 | insmod $(shell pwd)/gmm/lego_gmm.ko && \ 22 | insmod $(shell pwd)/gpm/lego_gpm.ko && \ 23 | insmod $(shell pwd)/gum/lego_gum.ko && \ 24 | insmod $(shell pwd)/gsm/lego_gsm.ko && \ 25 | insmod $(shell pwd)/gm_dispatcher/lego_gm_dispatcher.ko 26 | 27 | .PHONY: all $(SUBDIRS) $(CLEAN_SUBDIRS) install 28 | -------------------------------------------------------------------------------- /linux-modules/monitor/gm_dispatcher/Makefile: -------------------------------------------------------------------------------- 1 | obj-m := lego_gm_dispatcher.o 2 | 3 | ccflags-y := -I$(src)/../include 4 | ccflags-y += -I$(src)/../../../include 5 | 6 | KBUILD_EXTRA_SYMBOLS += $(shell pwd)/../../fit/Module.symvers 7 | KBUILD_EXTRA_SYMBOLS += $(shell pwd)/../gpm/Module.symvers 8 | KBUILD_EXTRA_SYMBOLS += $(shell pwd)/../gmm/Module.symvers 9 | KBUILD_EXTRA_SYMBOLS += $(shell pwd)/../gsm/Module.symvers 10 | export KBUILD_EXTRA_SYMBOLS 11 | 12 | # Targets 13 | all: 14 | make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules 15 | clean: 16 | make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) clean 17 | help: 18 | make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) help 19 | -------------------------------------------------------------------------------- /linux-modules/monitor/gmm/Makefile: -------------------------------------------------------------------------------- 1 | obj-m := lego_gmm.o 2 | 3 | ccflags-y := -I$(src)/../include 4 | ccflags-y += -I$(src)/../../../include 5 | 6 | KBUILD_EXTRA_SYMBOLS += $(shell pwd)/../../fit/Module.symvers 7 | export KBUILD_EXTRA_SYMBOLS 8 | 9 | # Targets 10 | all: 11 | make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules 12 | clean: 13 | make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) clean 14 | help: 15 | make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) help 16 | -------------------------------------------------------------------------------- /linux-modules/monitor/gpm/Makefile: -------------------------------------------------------------------------------- 1 | obj-m := lego_gpm.o 2 | 3 | ccflags-y := -I$(src)/../include 4 | ccflags-y += -I$(src)/../../../include 5 | 6 | KBUILD_EXTRA_SYMBOLS += $(shell pwd)/../../fit/Module.symvers 7 | KBUILD_EXTRA_SYMBOLS += $(shell pwd)/../gmm/Module.symvers 8 | export KBUILD_EXTRA_SYMBOLS 9 | 10 | # Targets 11 | all: 12 | make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules 13 | clean: 14 | make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) clean 15 | help: 16 | make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) help 17 | -------------------------------------------------------------------------------- /linux-modules/monitor/gsm/Makefile: -------------------------------------------------------------------------------- 1 | obj-m := lego_gsm.o 2 | lego_gsm-y := core.o hlist.o handlers.o 3 | 4 | ccflags-y := -I$(src)/../include 5 | ccflags-y += -I$(src)/../../../include 6 | 7 | cflags += -g 8 | EXTRA_CFLAGS += -g 9 | KBUILD_EXTRA_SYMBOLS += $(shell pwd)/../../fit/Module.symvers 10 | export KBUILD_EXTRA_SYMBOLS 11 | 12 | all: 13 | make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules 14 | clean: 15 | rm -rf *.o *.ko *.mod.c .*.cmd *.markers *.order *.symvers .tmp_versions *~ 16 | -------------------------------------------------------------------------------- /linux-modules/monitor/gsm/handlers.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include "gsm.h" 11 | 12 | int handle_p2sm_alloc_nodes(int *payload, uintptr_t desc) 13 | { 14 | int vid = *payload; 15 | struct lego_vnode_struct *mm_vnode; 16 | struct gsm2p_ret_struct res; 17 | int ret = 0; 18 | 19 | res.mid = -1; 20 | res.sid = -1; 21 | 22 | mm_vnode = ht_find_lego_vnode(vid); 23 | if (!mm_vnode) { 24 | mm_vnode = alloc_lego_vnode(vid, alloc_sid(vid)); 25 | if (unlikely(!mm_vnode)) { 26 | ret = -ENOMEM; 27 | goto reply; 28 | } 29 | 30 | ht_insert_lego_vnode(mm_vnode); 31 | } 32 | 33 | res.sid = mm_vnode->storage_node_id; 34 | 35 | if (mm_vnode->pgcache_node_id == -1) { 36 | /* TODO: 37 | * should be determined by GMM 38 | * now always let mem node DEFAULT_MEM_HOMENODE as page cache node 39 | */ 40 | mm_vnode->pgcache_node_id = DEFAULT_MEM_HOMENODE; 41 | } 42 | res.mid = mm_vnode->pgcache_node_id; 43 | reply: 44 | ibapi_reply_message(&res, sizeof(res), desc); 45 | return ret; 46 | } 47 | EXPORT_SYMBOL(handle_p2sm_alloc_nodes); 48 | -------------------------------------------------------------------------------- /linux-modules/monitor/gum/Makefile: -------------------------------------------------------------------------------- 1 | obj-m := lego_gum.o 2 | 3 | ccflags-y := -I$(src)/../include 4 | ccflags-y += -I$(src)/../../../include 5 | 6 | KBUILD_EXTRA_SYMBOLS += $(shell pwd)/../gpm/Module.symvers 7 | export KBUILD_EXTRA_SYMBOLS 8 | 9 | # Targets 10 | all: 11 | make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules 12 | clean: 13 | make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) clean 14 | help: 15 | make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) help 16 | -------------------------------------------------------------------------------- /linux-modules/monitor/include/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_COMMON_H 11 | #define _LEGO_COMMON_H 12 | 13 | #include "../../fit/fit_config.h" 14 | #include 15 | #include 16 | #include 17 | 18 | /* 19 | * IB layer network API 20 | */ 21 | extern int ibapi_send_reply_imm(int target_node, void *addr, int size, 22 | void *ret_addr, int max_ret_size, 23 | int if_use_ret_phys_addr); 24 | extern int ibapi_receive_message(unsigned int designed_port, void *ret_addr, 25 | int receive_size, uintptr_t *descriptor); 26 | extern int ibapi_reply_message(void *addr, int size, uintptr_t descriptor); 27 | 28 | #endif /* _LEGO_COMMON_H */ 29 | -------------------------------------------------------------------------------- /linux-modules/monitor/include/gmm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_GMM_H 11 | #define _LEGO_GMM_H 12 | 13 | /* information of each memory component */ 14 | struct mnode_struct { 15 | __u32 nid; 16 | unsigned long totalram; 17 | unsigned long freeram; 18 | unsigned long nr_request; 19 | struct list_head list; 20 | }; 21 | 22 | int choose_node(void); 23 | int handle_m2mm_consult(struct consult_info *, u64, struct common_header *); 24 | void handle_m2mm_status_report(struct m2mm_status_report *payload, u64 desc); 25 | 26 | #endif /* _LEGO_GMM_H */ 27 | -------------------------------------------------------------------------------- /linux-modules/monitor/include/gum.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_GUM_H 11 | #define _LEGO_GUM_H 12 | 13 | #include 14 | 15 | int create_lego_proc_file(void); 16 | void remove_lego_proc_file(void); 17 | 18 | #endif /* _LEGO_GUM_H */ 19 | -------------------------------------------------------------------------------- /linux-modules/storage/CONFIG_LEGO_STORAGE.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | /* 11 | * This file serves as the .config file of Lego storage manager 12 | */ 13 | 14 | #ifndef _LEGO_STORAGE_CONFIG_STORAGE_ 15 | #define _LEGO_STORAGE_CONFIG_STORAGE_ 16 | 17 | #define STORAGE_DEBUG_CORE 18 | #define STORAGE_DEBUG_OPEN 19 | #define STORAGE_DEBUG_STAT 20 | #define STORAGE_DEBUG_ACCESS 21 | #define STORAGE_DEBUG_READ_WRITE 22 | 23 | /* 24 | * If STORAGE_BYPASS_PAGE_CACHE is enabled, we need to have the user 25 | * context to do mmap. That means we have use the current insmod thread 26 | * to do so. That further means the insmod thread will never return... 27 | * 28 | * For non-storage-intensive workload, you can disable this. 29 | */ 30 | #if 0 31 | # define STORAGE_BYPASS_PAGE_CACHE 32 | #endif 33 | 34 | #endif /* _LEGO_STORAGE_CONFIG_STORAGE_ */ 35 | -------------------------------------------------------------------------------- /linux-modules/storage/Makefile: -------------------------------------------------------------------------------- 1 | obj-m := storage.o 2 | storage-y := core.o handlers.o file_ops.o replica.o stat.o 3 | 4 | LEGO_INCLUDE := -I$(M)/../../include 5 | 6 | EXTRA_CFLAGS += -g $(LEGO_INCLUDE) -D_LEGO_STORAGE_SOURCE_ 7 | KBUILD_EXTRA_SYMBOLS += $(shell pwd)/../fit/Module.symvers 8 | export KBUILD_EXTRA_SYMBOLS 9 | 10 | all: 11 | make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules 12 | clean: 13 | rm -rf *.o *.ko *.mod.c .*.cmd *.markers *.order *.symvers .tmp_versions *~ 14 | -------------------------------------------------------------------------------- /linux-modules/storage/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_STORAGE_COMMON_H_ 11 | #define _LEGO_STORAGE_COMMON_H_ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #define BLK_SIZE (5 * 4096) 24 | 25 | /* fit module */ 26 | int ibapi_send_reply_imm(int target_node, void *addr, int size, void *ret_addr, 27 | int max_ret_size, int if_use_ret_phys_addr); 28 | int ibapi_receive_message(unsigned int designed_port, void *ret_addr, 29 | int receive_size, uintptr_t *descriptor); 30 | int ibapi_reply_message(void *addr, int size, uintptr_t descriptor); 31 | 32 | /* getdents */ 33 | struct linux_dirent { 34 | unsigned long d_ino; 35 | unsigned long d_off; 36 | unsigned short d_reclen; 37 | char d_name[1]; 38 | }; 39 | 40 | #endif /* _LEGO_STORAGE_COMMON_H_ */ 41 | -------------------------------------------------------------------------------- /linux-modules/storage/stat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include "../fit/fit_config.h" 20 | #include "storage.h" 21 | #include "common.h" 22 | #include "replica.h" 23 | #include "stat.h" 24 | 25 | struct storage_manager_stat storage_manager_stats; 26 | 27 | static const char *const storage_manager_stat_text[] = { 28 | "handle_replica_flush", 29 | "handle_replica_vma", 30 | "handle_replica_read", 31 | "handle_replica_write", 32 | }; 33 | 34 | void print_storage_manager_stats(void) 35 | { 36 | int i; 37 | 38 | BUILD_BUG_ON(NR_STORAGE_MANAGER_STAT_ITEMS != ARRAY_SIZE(storage_manager_stat_text)); 39 | 40 | for (i = 0; i < NR_STORAGE_MANAGER_STAT_ITEMS; i++) { 41 | pr_crit("%s: %lu\n", storage_manager_stat_text[i], 42 | atomic_long_read(&storage_manager_stats.stat[i])); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /linux-modules/storage/stat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _LEGO_STORAGE_STAT_H_ 11 | #define _LEGO_STORAGE_STAT_H_ 12 | 13 | enum storage_manager_stat_item { 14 | HANDLE_REPLICA_FLUSH, 15 | HANDLE_REPLICA_VMA, 16 | HANDLE_REPLICA_READ, 17 | HANDLE_REPLICA_WRITE, 18 | 19 | NR_STORAGE_MANAGER_STAT_ITEMS, 20 | }; 21 | 22 | struct storage_manager_stat { 23 | atomic_long_t stat[NR_STORAGE_MANAGER_STAT_ITEMS]; 24 | }; 25 | 26 | extern struct storage_manager_stat storage_manager_stats; 27 | 28 | static inline void inc_storage_stat(enum storage_manager_stat_item i) 29 | { 30 | atomic_long_inc(&storage_manager_stats.stat[i]); 31 | } 32 | 33 | void print_storage_manager_stats(void); 34 | 35 | #endif /* _LEGO_STORAGE_STAT_H_ */ 36 | -------------------------------------------------------------------------------- /managers/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Lego Managers 3 | # Keep it complex then hide it? 4 | # Keep it simple stupid? 5 | # 6 | 7 | obj-$(CONFIG_COMP_PROCESSOR) := processor/ 8 | obj-$(CONFIG_COMP_MEMORY) += memory/ 9 | 10 | # Library tools used by both processor and memory managers 11 | obj-y += lib/ 12 | 13 | obj-y += common.o 14 | obj-y += pin.o 15 | obj-$(CONFIG_SOFT_WATCHDOG) += watchdog.o 16 | -------------------------------------------------------------------------------- /managers/lib/Makefile: -------------------------------------------------------------------------------- 1 | obj-y := dump_snapshot.o 2 | -------------------------------------------------------------------------------- /managers/memory/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Lego Memory Component 3 | # 4 | 5 | obj-y := core.o 6 | obj-y += task.o 7 | obj-y += handle_fork.o 8 | obj-y += handle_execve.o 9 | obj-y += handle_mmap.o 10 | obj-y += handle_file.o 11 | obj-y += handle_checkpoint.o 12 | obj-y += file_ops.o 13 | obj-y += missing_syscalls.o 14 | obj-y += m2s_read_write.o 15 | obj-y += stat.o 16 | obj-y += test.o 17 | 18 | # Pcache 19 | obj-y += handle_pcache/ 20 | 21 | # Replication 22 | obj-y += replica/ 23 | 24 | # Virtual Memory Subsystem 25 | obj-y += vm/ 26 | 27 | # Loader 28 | obj-y += loader/ 29 | 30 | # Lego Page Cache 31 | obj-$(CONFIG_MEM_PAGE_CACHE) += pgcache/ 32 | 33 | obj-y += ramfs/ 34 | 35 | # Monitor 36 | obj-y += monitor/ 37 | -------------------------------------------------------------------------------- /managers/memory/handle_checkpoint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | int handle_p2m_checkpint(void *payload, u64 desc, 14 | struct common_header *hdr) 15 | { 16 | WARN_ON(1); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /managers/memory/handle_pcache/Makefile: -------------------------------------------------------------------------------- 1 | obj-y := fault.o 2 | obj-y += prefetch.o 3 | -------------------------------------------------------------------------------- /managers/memory/handle_pcache/internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | /* 11 | * Internal header file of memory pcache handling subsystem 12 | */ 13 | 14 | #ifndef _MEMORY_PCACHE_INTERNAL_H_ 15 | #define _MEMORY_PCACHE_INTERNAL_H_ 16 | 17 | void do_mmap_prefetch(struct lego_task_struct *p, u64 vaddr, 18 | u32 flags, u32 nr_pages); 19 | 20 | #endif /* _MEMORY_PCACHE_INTERNAL_H_ */ 21 | -------------------------------------------------------------------------------- /managers/memory/loader/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Loader Subsystem in Lego Memory-Component 3 | # 4 | 5 | obj-y := core.o 6 | obj-y += elf.o 7 | -------------------------------------------------------------------------------- /managers/memory/monitor/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Lego Memory Component, global monitor relevant 3 | # 4 | 5 | obj-$(CONFIG_GMM) := gmm_handler.o 6 | -------------------------------------------------------------------------------- /managers/memory/pgcache/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Page Cache Subsystem in Lego Memory-Component 3 | # 4 | 5 | obj-y := read_write.o 6 | obj-y += alloc.o 7 | obj-y += hlist.o 8 | obj-y += dirtylist.o 9 | obj-y += eviction.o 10 | obj-y += handle_special.o 11 | -------------------------------------------------------------------------------- /managers/memory/ramfs/Makefile: -------------------------------------------------------------------------------- 1 | obj-y := piggy.o 2 | obj-y += core.o 3 | 4 | # 5 | # Add dependency, so it can compile if .config changes 6 | # 7 | 8 | $(CONFIG_RAMFS_OBJECT_FILE): 9 | 10 | $(obj)/piggy.o: $(CONFIG_RAMFS_OBJECT_FILE) 11 | -------------------------------------------------------------------------------- /managers/memory/ramfs/piggy.S: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include 11 | 12 | .section ".ramfs","ax" 13 | GLOBAL(ramfs_start) 14 | #ifdef CONFIG_USE_RAMFS 15 | .incbin CONFIG_RAMFS_OBJECT_FILE 16 | #endif 17 | GLOBAL(ramfs_end) 18 | -------------------------------------------------------------------------------- /managers/memory/replica/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # We always have the handlers for P side replication requests. 3 | # This reduce the Kconfig chore... 4 | # 5 | 6 | obj-y := memory_core.o memory_flush.o memory_debug.o 7 | obj-$(CONFIG_REPLICATION_VMA) += vma.o 8 | -------------------------------------------------------------------------------- /managers/memory/stat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | 14 | struct memory_manager_stat memory_manager_stats; 15 | 16 | static const char *const memory_manager_stat_text[] = { 17 | /* Handler group */ 18 | "handle_pcache_miss", 19 | "handle_pcache_flush", 20 | "handle_pcache_replica", 21 | "handle_p2m_mmap", 22 | "handle_p2m_munmap", 23 | "handle_p2m_brk", 24 | "handle_m2m_mmap", 25 | "handle_m2m_munmap", 26 | 27 | /* fs related */ 28 | "handle_read", 29 | "handle_write", 30 | 31 | /* replication */ 32 | "nr_batched_log_flush" 33 | }; 34 | 35 | #ifdef CONFIG_COUNTER_MEMORY_HANDLER 36 | void print_memory_manager_stats(void) 37 | { 38 | int i; 39 | 40 | BUILD_BUG_ON(NR_MEMORY_MANAGER_STAT_ITEMS != ARRAY_SIZE(memory_manager_stat_text)); 41 | 42 | for (i = 0; i < NR_MEMORY_MANAGER_STAT_ITEMS; i++) { 43 | pr_info("%s: %lu\n", memory_manager_stat_text[i], 44 | atomic_long_read(&memory_manager_stats.stat[i])); 45 | } 46 | } 47 | #endif 48 | -------------------------------------------------------------------------------- /managers/memory/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | void handle_p2m_test(struct p2m_test_msg *msg, struct thpool_buffer *tb) 34 | { 35 | tb_set_tx_size(tb, msg->reply_len); 36 | } 37 | 38 | void handle_p2m_test_noreply(struct p2m_test_msg *msg, struct thpool_buffer *tb) 39 | { 40 | tb_set_tx_size(tb, msg->reply_len); 41 | } 42 | -------------------------------------------------------------------------------- /managers/memory/vm/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Process Virtual Memroy Subsystem in Lego memory-component 3 | # 4 | 5 | obj-y := mmap.o 6 | obj-y += fault.o 7 | obj-y += pgtable.o 8 | obj-y += uaccess.o 9 | obj-y += gup.o 10 | obj-y += debug.o 11 | obj-$(CONFIG_DISTRIBUTED_VMA_MEMORY) += distvm.o 12 | 13 | distvm-y := dist_mmap.o 14 | distvm-$(CONFIG_DEBUG_VMA) += dist_mmap_dump.o 15 | distvm-$(CONFIG_VMA_MEMORY_UNITTEST) += dist_mmap_test.o 16 | -------------------------------------------------------------------------------- /managers/processor/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Lego processor-component manager 3 | # 4 | 5 | obj-y := core.o 6 | obj-y += fork.o 7 | obj-y += exec.o 8 | obj-y += pgtable.o 9 | obj-y += wait.o 10 | obj-y += prctl.o 11 | obj-y += mmap/ 12 | obj-y += fs/ 13 | obj-y += monitor/ 14 | obj-$(CONFIG_PROFILING_BOOT_RPC) += rpc_profile.o 15 | 16 | obj-$(CONFIG_VNODE) += vnode.o 17 | obj-$(CONFIG_REPLICATION_MEMORY) += replication.o 18 | obj-$(CONFIG_CHECKPOINT) += checkpoint/ 19 | obj-$(CONFIG_STRACE) += strace/ 20 | 21 | # 22 | # Extended Processor Cache Subsystem 23 | # 24 | obj-y += pcache/ 25 | obj-$(CONFIG_PCACHE_ZEROFILL_NOTIFY_MEMORY) += zerofill_notify.o 26 | -------------------------------------------------------------------------------- /managers/processor/checkpoint/Kconfig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WukLab/LegoOS/1f4da8658c3bb20d7bd4088ec52237b8a617f0c7/managers/processor/checkpoint/Kconfig -------------------------------------------------------------------------------- /managers/processor/checkpoint/Makefile: -------------------------------------------------------------------------------- 1 | obj-y := core.o 2 | obj-y += save.o 3 | obj-y += restore.o 4 | -------------------------------------------------------------------------------- /managers/processor/checkpoint/internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _CHECKPOINT_INTERNAL_H_ 11 | #define _CHECKPOINT_INTERNAL_H_ 12 | 13 | #ifdef CONFIG_DEBUG_CHECKPOINT 14 | #define chk_debug(fmt,...) \ 15 | pr_debug("%s(): "fmt "\n", __func__, __VA_ARGS__) 16 | #else 17 | static inline void chk_debug(const char *fmt, ...) { } 18 | #endif 19 | 20 | /* Save */ 21 | int save_open_files(struct task_struct *, struct process_snapshot *); 22 | int save_signals(struct task_struct *, struct process_snapshot *); 23 | 24 | void save_thread_regs(struct task_struct *, struct ss_task_struct *); 25 | 26 | void revert_save_open_files(struct task_struct *, struct process_snapshot *); 27 | 28 | /* Restore */ 29 | 30 | #endif /* _CHECKPOINT_INTERNAL_H_ */ 31 | -------------------------------------------------------------------------------- /managers/processor/fs/Kconfig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WukLab/LegoOS/1f4da8658c3bb20d7bd4088ec52237b8a617f0c7/managers/processor/fs/Kconfig -------------------------------------------------------------------------------- /managers/processor/fs/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Filesystem Interfaces in Lego Processor Manager 3 | # 4 | 5 | obj-y := read_write.o 6 | obj-y += open.o 7 | obj-y += stat.o 8 | obj-y += fcntl.o 9 | obj-y += ioctl.o 10 | obj-y += stdio.o 11 | obj-y += truncate.o 12 | obj-y += namei.o 13 | obj-$(CONFIG_MEM_PAGE_CACHE) += file_size.o 14 | obj-y += statfs.o 15 | obj-y += pipe.o 16 | obj-y += lseek.o 17 | obj-y += default_f_ops.o 18 | obj-y += drop_cache.o 19 | 20 | # 21 | # To maintain compability with linux 22 | # 23 | obj-y += seq_file.o 24 | obj-y += proc/ 25 | obj-y += sys/ 26 | obj-y += dev/ 27 | -------------------------------------------------------------------------------- /managers/processor/fs/dev/Makefile: -------------------------------------------------------------------------------- 1 | obj-y := core.o 2 | obj-y += dev_random.o 3 | obj-y += dev_null.o 4 | -------------------------------------------------------------------------------- /managers/processor/fs/dev/dev_null.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | static int null_open(struct file *f) 15 | { 16 | /* Always present */ 17 | return 0; 18 | } 19 | 20 | static ssize_t null_read(struct file *f, char __user *buf, 21 | size_t count, loff_t *off) 22 | { 23 | /* Always return 0 */ 24 | return 0; 25 | } 26 | 27 | static ssize_t null_write(struct file *f, const char __user *buf, 28 | size_t count, loff_t *off) 29 | { 30 | /* Do nothing, always return count */ 31 | return count; 32 | } 33 | 34 | struct file_operations null_file_ops = { 35 | .llseek = dev_llseek, 36 | .open = null_open, 37 | .read = null_read, 38 | .write = null_write, 39 | }; 40 | -------------------------------------------------------------------------------- /managers/processor/fs/drop_cache.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | /* 16 | * Send a request to memory node to let it drop the page cache 17 | * Similar effect to "echo 3 > /proc/sys/vm/drop_caches" 18 | */ 19 | static int do_drop_page_cache(void) 20 | { 21 | int retval, retlen; 22 | struct common_header hdr; 23 | int mem_node = current_pgcache_home_node(); 24 | 25 | hdr.opcode = P2M_DROP_CACHE; 26 | hdr.src_nid = LEGO_LOCAL_NID; 27 | 28 | retlen = ibapi_send_reply_imm(mem_node, &hdr, sizeof(hdr), 29 | &retval, sizeof(retval), false); 30 | 31 | if (unlikely(retlen != sizeof(retval))) { 32 | WARN_ON_ONCE(1); 33 | return -EIO; 34 | } 35 | return 0; 36 | } 37 | 38 | SYSCALL_DEFINE0(drop_page_cache) 39 | { 40 | return do_drop_page_cache(); 41 | } 42 | -------------------------------------------------------------------------------- /managers/processor/fs/proc/Makefile: -------------------------------------------------------------------------------- 1 | obj-y += core.o 2 | obj-y += proc_stat.o 3 | obj-y += proc_meminfo.o 4 | obj-y += proc_cpuinfo.o 5 | obj-y += proc_cmdline.o 6 | obj-y += proc_processes.o 7 | obj-y += proc_version.o 8 | obj-y += proc_sys_vm_overcommit.o 9 | obj-y += self/ 10 | -------------------------------------------------------------------------------- /managers/processor/fs/proc/proc_cmdline.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | static int cmdline_show(struct seq_file *m, void *v) 15 | { 16 | seq_printf(m, "%s\n", boot_command_line); 17 | return 0; 18 | } 19 | 20 | static int cmdline_open(struct file *file) 21 | { 22 | return single_open(file, cmdline_show, NULL); 23 | } 24 | 25 | static ssize_t cmdline_write(struct file *f, const char __user *buf, 26 | size_t count, loff_t *off) 27 | { 28 | return -EFAULT; 29 | } 30 | 31 | struct file_operations proc_cmdline_ops = { 32 | .open = cmdline_open, 33 | .read = seq_read, 34 | .write = cmdline_write, 35 | .release = single_release, 36 | }; 37 | -------------------------------------------------------------------------------- /managers/processor/fs/proc/proc_processes.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | static int processes_show(struct seq_file *m, void *v) 15 | { 16 | struct task_struct *p, *t; 17 | 18 | spin_lock(&tasklist_lock); 19 | for_each_process(p) { 20 | seq_printf(m, "PID: %d, COMM: %s\n", 21 | p->pid, p->comm); 22 | for_each_thread(p, t) { 23 | if (p == t) 24 | continue; 25 | seq_printf(m, " PID: %d, TGID: %d\n", 26 | t->pid, t->tgid); 27 | } 28 | } 29 | spin_unlock(&tasklist_lock); 30 | 31 | return 0; 32 | } 33 | 34 | static int processes_open(struct file *file) 35 | { 36 | return single_open(file, processes_show, NULL); 37 | } 38 | 39 | static ssize_t processes_write(struct file *f, const char __user *buf, 40 | size_t count, loff_t *off) 41 | { 42 | return -EFAULT; 43 | } 44 | 45 | struct file_operations proc_processes_ops = { 46 | .open = processes_open, 47 | .read = seq_read, 48 | .write = processes_write, 49 | .release = single_release, 50 | }; 51 | -------------------------------------------------------------------------------- /managers/processor/fs/proc/proc_version.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | static int version_show(struct seq_file *m, void *v) 15 | { 16 | seq_printf(m, lego_proc_banner, 17 | utsname.sysname, 18 | utsname.release, 19 | utsname.version); 20 | return 0; 21 | } 22 | 23 | static int version_open(struct file *file) 24 | { 25 | return single_open(file, version_show, NULL); 26 | } 27 | 28 | static ssize_t version_write(struct file *f, const char __user *buf, 29 | size_t count, loff_t *off) 30 | { 31 | return -EFAULT; 32 | } 33 | 34 | struct file_operations proc_version_ops = { 35 | .open = version_open, 36 | .read = seq_read, 37 | .write = version_write, 38 | .release = single_release, 39 | }; 40 | -------------------------------------------------------------------------------- /managers/processor/fs/proc/self/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # /proc/self/* files 3 | # 4 | 5 | obj-y := status.o 6 | -------------------------------------------------------------------------------- /managers/processor/fs/proc/self/status.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WukLab/LegoOS/1f4da8658c3bb20d7bd4088ec52237b8a617f0c7/managers/processor/fs/proc/self/status.c -------------------------------------------------------------------------------- /managers/processor/fs/sys/Makefile: -------------------------------------------------------------------------------- 1 | obj-y := core.o 2 | obj-y += sys_devices_system_cpu_online.o 3 | -------------------------------------------------------------------------------- /managers/processor/fs/sys/core.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | extern struct file_operations sys_devices_system_cpu_online_ops; 20 | 21 | struct sys_file_struct { 22 | char f_name[FILENAME_LEN_DEFAULT]; 23 | const struct file_operations *f_op; 24 | }; 25 | 26 | static struct sys_file_struct sys_files[] = { 27 | { 28 | .f_name = "/sys/devices/system/cpu/online", 29 | .f_op = &sys_devices_system_cpu_online_ops, 30 | }, 31 | }; 32 | 33 | int sys_file_open(struct file *f, char *f_name) 34 | { 35 | struct sys_file_struct *sys_file; 36 | int i, ret; 37 | 38 | ret = -EBADF; 39 | for (i = 0; i < ARRAY_SIZE(sys_files); i++) { 40 | sys_file = &sys_files[i]; 41 | if (f_name_equal(f_name, sys_file->f_name)) { 42 | f->f_op = sys_file->f_op; 43 | ret = 0; 44 | break; 45 | } 46 | } 47 | 48 | return ret; 49 | } 50 | -------------------------------------------------------------------------------- /managers/processor/mmap/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Processor mmap range management 3 | # 4 | 5 | obj-y := syscall.o 6 | obj-$(CONFIG_DISTRIBUTED_VMA_PROCESSOR) += distvm.o 7 | 8 | distvm-y := dist_mmap.o 9 | distvm-$(CONFIG_VMA_PROCESSOR_UNITTEST) += dist_mmap_test.o 10 | -------------------------------------------------------------------------------- /managers/processor/monitor/Makefile: -------------------------------------------------------------------------------- 1 | obj-$(CONFIG_GPM) += gpm_handler.o 2 | obj-$(CONFIG_MONITOR_GMM) += gmm.o 3 | obj-$(CONFIG_GSM) += gsm.o 4 | obj-$(CONFIG_MONITOR_GSM) += gpm.o 5 | -------------------------------------------------------------------------------- /managers/processor/monitor/gmm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | 11 | -------------------------------------------------------------------------------- /managers/processor/monitor/gpm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /managers/processor/pcache/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Processor DRAM Cache Subsystem 3 | # 4 | 5 | obj-y := fault.o 6 | obj-y += init.o 7 | obj-y += alloc.o 8 | obj-y += clflush.o 9 | obj-y += rmap.o 10 | obj-y += debug.o 11 | obj-y += evict.o 12 | obj-y += stat.o 13 | obj-y += syscall.o 14 | obj-y += thread.o 15 | obj-$(CONFIG_PCACHE_PREFETCH) += prefetch.o 16 | 17 | # 18 | # Eviction Algorithm 19 | # 20 | obj-$(CONFIG_PCACHE_EVICT_LRU) += evict_lru.o 21 | obj-$(CONFIG_PCACHE_EVICT_FIFO) += evict_fifo.o 22 | obj-$(CONFIG_PCACHE_EVICT_RANDOM) += evict_random.o 23 | 24 | # 25 | # Eviction Mechanisms 26 | # 27 | obj-$(CONFIG_PCACHE_EVICTION_VICTIM) += victim.o victim_flush.o victim_debug.o 28 | obj-$(CONFIG_PCACHE_EVICTION_PERSET_LIST) += perset.o 29 | 30 | # Sweep threads for certain eviction algorithms 31 | obj-$(CONFIG_PCACHE_EVICT_GENERIC_SWEEP) += evict_sweep.o 32 | -------------------------------------------------------------------------------- /managers/processor/pcache/evict_fifo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | struct pcache_meta *evict_find_line_fifo(struct pcache_set *pset) 17 | { 18 | panic("pcache/eviction: FIFO not implemented!"); 19 | return NULL; 20 | } 21 | -------------------------------------------------------------------------------- /managers/processor/pcache/evict_sweep.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | /* 11 | * Background sweep threads for eviction selection 12 | * Dirty work is done by the algorithm-specific callback. 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | static struct task_struct *sweep_thread; 29 | 30 | static int kevict_sweepd(void *unused) 31 | { 32 | if (pin_current_thread()) 33 | panic("Fail to pin evict sweepd"); 34 | 35 | kevict_sweepd_lru(); 36 | return 0; 37 | } 38 | 39 | int __init evict_sweep_init(void) 40 | { 41 | sweep_thread = kthread_run(kevict_sweepd, NULL, "kevict_sweepd"); 42 | if (IS_ERR(sweep_thread)) 43 | return PTR_ERR(sweep_thread); 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /managers/processor/pcache/piggyback.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #ifndef _PROCESSOR_PCACHE_PIGGYBACK_H_ 11 | #define _PROCESSOR_PCACHE_PIGGYBACK_H_ 12 | 13 | extern DEFINE_PER_CPU(struct pcache_meta *, piggybacker); 14 | 15 | static inline void set_per_cpu_piggybacker(struct pcache_meta *pcm) 16 | { 17 | struct pcache_meta *old; 18 | 19 | old = this_cpu_read(piggybacker); 20 | if (likely(!old)) { 21 | this_cpu_write(piggybacker, pcm); 22 | SetPcachePiggybackCached(pcm); 23 | return; 24 | } 25 | 26 | /* 27 | * One cpu is only allowed to set once. 28 | * The one who evicted this must have pcache miss on remote. 29 | */ 30 | dump_pcache_meta(old, "override"); 31 | BUG(); 32 | } 33 | 34 | /* If we grabbed one, the per-cpu array entry will be reset */ 35 | static inline struct pcache_meta *get_per_cpu_piggybacker(void) 36 | { 37 | struct pcache_meta *pcm; 38 | 39 | pcm = this_cpu_read(piggybacker); 40 | if (pcm) 41 | this_cpu_write(piggybacker, NULL); 42 | return pcm; 43 | } 44 | 45 | #endif /* _PROCESSOR_PCACHE_PIGGYBACK_H_ */ 46 | -------------------------------------------------------------------------------- /managers/processor/pcache/prefetch.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | /* 11 | * Prefetch facilities 12 | */ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | -------------------------------------------------------------------------------- /managers/processor/pcache/syscall.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | 21 | SYSCALL_DEFINE1(pcache_stat, struct pcache_stat __user *, statbuf) 22 | { 23 | struct pcache_stat kstat; 24 | 25 | /* General info */ 26 | kstat.nr_cachelines = nr_cachelines; 27 | kstat.nr_cachesets = nr_cachesets; 28 | kstat.associativity = PCACHE_ASSOCIATIVITY; 29 | kstat.cacheline_size = PCACHE_LINE_SIZE; 30 | kstat.way_stride = pcache_way_cache_stride; 31 | 32 | /* Runtime stats */ 33 | kstat.nr_pgfault = pcache_event(PCACHE_FAULT); 34 | kstat.nr_pgfault_code = pcache_event(PCACHE_FAULT_CODE); 35 | kstat.nr_flush = pcache_event(PCACHE_CLFLUSH); 36 | kstat.nr_eviction = pcache_event(PCACHE_EVICTION_SUCCEED); 37 | 38 | if (copy_to_user(statbuf, &kstat, sizeof(kstat))) 39 | return -EFAULT; 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /managers/processor/prctl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, 16 | unsigned long, arg4, unsigned long, arg5) 17 | { 18 | struct task_struct *me = current; 19 | unsigned char comm[sizeof(me->comm)]; 20 | long error; 21 | 22 | error = 0; 23 | switch (option) { 24 | case PR_SET_NAME: 25 | comm[sizeof(me->comm) - 1] = 0; 26 | if (strncpy_from_user(comm, (char __user *)arg2, 27 | sizeof(me->comm) - 1) < 0) 28 | return -EFAULT; 29 | set_task_comm(me, comm); 30 | break; 31 | case PR_GET_NAME: 32 | get_task_comm(comm, me); 33 | if (copy_to_user((char __user *)arg2, comm, sizeof(comm))) 34 | return -EFAULT; 35 | break; 36 | default: 37 | error = -EINVAL; 38 | break; 39 | } 40 | return error; 41 | } 42 | -------------------------------------------------------------------------------- /managers/processor/processor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | /* Processor manager internal header file */ 11 | 12 | #ifndef _PROCESSOR_COMPONENT_PROCESSOR_H_ 13 | #define _PROCESSOR_COMPONENT_PROCESSOR_H_ 14 | 15 | #include 16 | 17 | void __init pcache_early_init(void); 18 | void __init pcache_post_init(void); 19 | 20 | #endif /* _PROCESSOR_COMPONENT_PROCESSOR_H_ */ 21 | -------------------------------------------------------------------------------- /managers/processor/strace/Makefile: -------------------------------------------------------------------------------- 1 | obj-y := core.o lib.o 2 | obj-y += sched.o 3 | obj-y += mm.o 4 | obj-y += fs.o 5 | -------------------------------------------------------------------------------- /managers/processor/strace/lib.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "internal.h" 24 | 25 | void strace_printflags(struct strace_flag *sf, unsigned long flags, unsigned char *buf) 26 | { 27 | int n = 0; 28 | int offset; 29 | 30 | if (WARN_ON(!sf || !buf)) 31 | return; 32 | 33 | for (; (flags || !n) && sf->str; ++sf) { 34 | if ((flags == sf->val) || 35 | (sf->val && (flags & sf->val) == sf->val)) { 36 | offset = sprintf(buf, "%s%s", (n++ ? "|" : ""), sf->str); 37 | buf += offset; 38 | 39 | flags &= ~sf->val; 40 | } 41 | if (!flags) 42 | break; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /managers/watchdog.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | /* 11 | * Self heartbeat printing 12 | * 13 | * We will create a daemon thread, which is _pinned_ a to core. 14 | * This thread will do nothing but print some critical information 15 | * that is useful for debugging. 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | extern void watchdog_print(void); 24 | 25 | static long watchdog_interval_sec = CONFIG_SOFT_WATCHDOG_INTERVAL_SEC; 26 | 27 | static int watchdog(void *_unused) 28 | { 29 | if (pin_current_thread()) 30 | pr_err("Fail to pin self_hb.\n"); 31 | 32 | while (1) { 33 | watchdog_print(); 34 | set_current_state(TASK_UNINTERRUPTIBLE); 35 | schedule_timeout(watchdog_interval_sec * HZ); 36 | 37 | if (kthread_should_stop()) 38 | break; 39 | } 40 | return 0; 41 | } 42 | 43 | void __init soft_watchdog_init(void) 44 | { 45 | struct task_struct *ret; 46 | 47 | ret = kthread_run(watchdog, NULL, "watchdog"); 48 | if (IS_ERR(ret)) { 49 | pr_info("Fail to create self_hb.\n"); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /mm/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # LegoOS Physical Memory Managment 3 | # 4 | 5 | obj-y := debug.o 6 | obj-y += memory.o 7 | obj-y += init-mm.o 8 | obj-y += vmalloc.o 9 | obj-y += dmapool.o 10 | obj-y += memblock.o 11 | obj-y += page_alloc.o 12 | obj-y += early_ioremap.o 13 | obj-y += percpu.o 14 | obj-y += maccess.o 15 | obj-y += mbind.o 16 | obj-y += vmstat.o 17 | 18 | obj-y += slab_common.o 19 | obj-$(CONFIG_SLOB) += slob.o 20 | 21 | obj-$(CONFIG_SPARSEMEM) += sparse.o 22 | obj-$(CONFIG_SPARSEMEM_VMEMMAP) += sparse-vmemmap.o 23 | -------------------------------------------------------------------------------- /mm/debug.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #define __def_pageflag_names \ 15 | {1UL << PG_locked, "locked" }, \ 16 | {1UL << PG_referenced, "referenced" }, \ 17 | {1UL << PG_dirty, "dirty" }, \ 18 | {1UL << PG_lru, "lru" }, \ 19 | {1UL << PG_active, "active" }, \ 20 | {1UL << PG_reserved, "reserved" }, \ 21 | {1UL << PG_private, "private" }, \ 22 | {1UL << PG_unevictable, "unevictable" }, \ 23 | {1UL << PG_slab, "slab" }, \ 24 | {1UL << PG_slob_free, "slob_free" } 25 | 26 | const struct trace_print_flags pageflag_names[] = { 27 | __def_pageflag_names, 28 | {0, NULL} 29 | }; 30 | 31 | void dump_page(struct page *page, const char *reason) 32 | { 33 | pr_emerg("page:%p count:%d mapcount:%d\n", 34 | page, page_ref_count(page), atomic_read(&page->_mapcount)); 35 | 36 | BUILD_BUG_ON(ARRAY_SIZE(pageflag_names) != __NR_PAGEFLAGS + 1); 37 | 38 | pr_emerg("flags: %#lx(%pGp)\n", page->flags, &page->flags); 39 | 40 | if (reason) 41 | pr_alert("page dumped because: %s\n", reason); 42 | } 43 | -------------------------------------------------------------------------------- /mm/init-mm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | struct mm_struct init_mm = { 17 | .pgd = swapper_pg_dir, 18 | .mm_users = ATOMIC_INIT(1), 19 | .mm_count = ATOMIC_INIT(1), 20 | .mmap_sem = __RWSEM_INITIALIZER(init_mm.mmap_sem), 21 | .page_table_lock = __SPIN_LOCK_UNLOCKED(init_mm.page_table_lock), 22 | .mmlist = LIST_HEAD_INIT(init_mm.mmlist), 23 | }; 24 | -------------------------------------------------------------------------------- /mm/mbind.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | /* 14 | * set NUMA allocation policy 15 | */ 16 | SYSCALL_DEFINE6(mbind, unsigned long, start, unsigned long, len, 17 | unsigned long, mode, const unsigned long __user *, nmask, 18 | unsigned long, maxnode, unsigned, flags) 19 | { 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /mm/slab_common.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | /* 14 | * Code shared by all different allocators. 15 | */ 16 | 17 | /* 18 | * To avoid unnecessary overhead, we pass through large allocation requests 19 | * directly to the page allocator. We use __GFP_COMP, because we will need to 20 | * know the allocation order to free the pages properly in kfree. 21 | */ 22 | void *kmalloc_order(size_t size, gfp_t flags, unsigned int order) 23 | { 24 | void *ret = NULL; 25 | struct page *page; 26 | 27 | page = alloc_pages(flags, order); 28 | if (likely(page)) { 29 | set_page_private(page, order); 30 | ret = page_address(page); 31 | } 32 | return ret; 33 | } 34 | -------------------------------------------------------------------------------- /mm/vmstat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Wuklab, Purdue University. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | */ 9 | 10 | /* 11 | * Lowest-level physical memory or VM usage counting. 12 | * Used by all kinds of managers. 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | /* 20 | * Manage combined zone based / global counters 21 | * 22 | * vm_stat contains the global counters 23 | */ 24 | atomic_long_t vm_zone_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp; 25 | atomic_long_t vm_node_stat[NR_VM_NODE_STAT_ITEMS] __cacheline_aligned_in_smp; 26 | -------------------------------------------------------------------------------- /net/Makefile: -------------------------------------------------------------------------------- 1 | obj-$(CONFIG_LWIP) := lwip/ 2 | obj-$(CONFIG_LWIP) += serv.o 3 | obj-$(CONFIG_INFINIBAND) := lego/ 4 | obj-$(CONFIG_SOCKET_O_IB) += socket/ 5 | -------------------------------------------------------------------------------- /net/input.c: -------------------------------------------------------------------------------- 1 | #include "ns.h" 2 | 3 | extern union Nsipc nsipcbuf; 4 | 5 | #define debug 0 6 | 7 | void 8 | input(envid_t ns_envid) 9 | { 10 | binaryname = "ns_input"; 11 | 12 | // LAB 6: Your code here: 13 | // - read a packet from the device driver 14 | // - send it to the network server 15 | // Hint: When you IPC a page to the network server, it will be 16 | // reading from it for a while, so don't immediately receive 17 | // another packet in to the same physical page. 18 | 19 | int length = 0; 20 | int type = NSREQ_INPUT; 21 | int result = 0; 22 | //Allocate page for data transfer 23 | //cprintf("Addresses %x %x\n", &nsipcbuf.pkt, &nsipcbuf); 24 | 25 | 26 | while(1) 27 | { 28 | 29 | if ((result = sys_page_alloc(0, &nsipcbuf.pkt, PTE_P|PTE_U|PTE_W)) < 0) 30 | panic("sys_page_alloc: %e", result); 31 | 32 | //read a packet from the device driver 33 | while((length = sys_net_rx(&nsipcbuf.pkt.jp_data)) <= 0) 34 | { 35 | sys_yield(); 36 | } 37 | nsipcbuf.pkt.jp_len = length; 38 | 39 | if (debug) 40 | cprintf("[%08x] nsipc %d %08x\n", thisenv->env_id, type, *(uint32_t *)&nsipcbuf); 41 | 42 | //send it to the network server 43 | ipc_send(ns_envid, type, &nsipcbuf.pkt, PTE_P | PTE_W | PTE_U); 44 | 45 | //Let server process this 46 | sys_yield(); 47 | 48 | //If allocating new page each time 49 | sys_page_unmap(0, &nsipcbuf.pkt.jp_data); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /net/lego/Kconfig: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /net/lego/Makefile: -------------------------------------------------------------------------------- 1 | obj-$(CONFIG_FIT) := fit_ibapi.o fit_internal.o fit_machine.o 2 | 3 | CFLAGS_fit_ibapi.o = -Wno-format 4 | CFLAGS_fit_internal.o = -Wno-format 5 | -------------------------------------------------------------------------------- /net/lwip/FILES: -------------------------------------------------------------------------------- 1 | api/ - The code for the high-level wrapper API. Not needed if 2 | you use the lowel-level call-back/raw API. 3 | 4 | core/ - The core of the TPC/IP stack; protocol implementations, 5 | memory and buffer management, and the low-level raw API. 6 | 7 | include/ - lwIP include files. 8 | 9 | netif/ - Generic network interface device drivers are kept here, 10 | as well as the ARP module. 11 | 12 | For more information on the various subdirectories, check the FILES 13 | file in each directory. 14 | -------------------------------------------------------------------------------- /net/lwip/Makefile: -------------------------------------------------------------------------------- 1 | obj-y := api/ 2 | obj-y += core/ 3 | obj-y += lego/ 4 | obj-y += netif/ 5 | -------------------------------------------------------------------------------- /net/lwip/api/Makefile: -------------------------------------------------------------------------------- 1 | obj-y := api_lib.o api_msg.o err.o sockets.o tcpip.o netbuf.o netdb.o 2 | -------------------------------------------------------------------------------- /net/lwip/core/Makefile: -------------------------------------------------------------------------------- 1 | obj-y := init.o tcp_in.o dhcp.o mem.o memp.o netif.o pbuf.o raw.o stats.o sys.o tcp.o tcp_out.o udp.o dns.o 2 | obj-y += ipv4/ 3 | -------------------------------------------------------------------------------- /net/lwip/core/ipv4/Makefile: -------------------------------------------------------------------------------- 1 | obj-y := ip_addr.o icmp.o ip.o ip_frag.o inet_chksum.o inet.o 2 | -------------------------------------------------------------------------------- /net/lwip/core/ipv6/README: -------------------------------------------------------------------------------- 1 | IPv6 support in lwIP is very experimental. 2 | -------------------------------------------------------------------------------- /net/lwip/lego/Makefile: -------------------------------------------------------------------------------- 1 | #obj-y := arch/sys_arch.o arch/thread.o arch/perror.o 2 | obj-y := jif/jif.o 3 | -------------------------------------------------------------------------------- /net/lwip/lego/jif/jif.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct jif_pkt { 4 | int jp_len; 5 | char *jp_data; 6 | }; 7 | 8 | void jif_input(struct netif *netif, void *va); 9 | err_t jif_init(struct netif *netif); 10 | -------------------------------------------------------------------------------- /net/lwip/netif/FILES: -------------------------------------------------------------------------------- 1 | This directory contains generic network interface device drivers that 2 | do not contain any hardware or architecture specific code. The files 3 | are: 4 | 5 | etharp.c 6 | Implements the ARP (Address Resolution Protocol) over 7 | Ethernet. The code in this file should be used together with 8 | Ethernet device drivers. Note that this module has been 9 | largely made Ethernet independent so you should be able to 10 | adapt this for other link layers (such as Firewire). 11 | 12 | ethernetif.c 13 | An example of how an Ethernet device driver could look. This 14 | file can be used as a "skeleton" for developing new Ethernet 15 | network device drivers. It uses the etharp.c ARP code. 16 | 17 | loopif.c 18 | A "loopback" network interface driver. It requires configuration 19 | through the define LWIP_LOOPIF_MULTITHREADING (see opt.h). 20 | 21 | slipif.c 22 | A generic implementation of the SLIP (Serial Line IP) 23 | protocol. It requires a sio (serial I/O) module to work. 24 | 25 | ppp/ Point-to-Point Protocol stack 26 | -------------------------------------------------------------------------------- /net/lwip/netif/Makefile: -------------------------------------------------------------------------------- 1 | obj-y := etharp.o loopif.o 2 | -------------------------------------------------------------------------------- /net/ns.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define IP "10.0.2.15" 5 | #define MASK "255.255.255.0" 6 | #define DEFAULT "10.0.2.2" 7 | 8 | #define TIMER_INTERVAL 250 9 | 10 | // Virtual address at which to receive page mappings containing client requests. 11 | #define QUEUE_SIZE 20 12 | #define REQVA (0x0ffff000 - QUEUE_SIZE * PGSIZE) 13 | 14 | /* timer.c */ 15 | void timer(envid_t ns_envid, uint32_t initial_to); 16 | 17 | /* input.c */ 18 | void input(envid_t ns_envid); 19 | 20 | /* output.c */ 21 | void output(envid_t ns_envid); 22 | 23 | -------------------------------------------------------------------------------- /net/socket/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Lego socket layer 3 | # 4 | 5 | obj-$(CONFIG_SOCKET_SYSCALL) := sock.o poll.o 6 | 7 | obj-$(CONFIG_EPOLL) += epoll.o 8 | -------------------------------------------------------------------------------- /net/testoutput.c: -------------------------------------------------------------------------------- 1 | #include "ns.h" 2 | 3 | #ifndef TESTOUTPUT_COUNT 4 | #define TESTOUTPUT_COUNT 10 5 | #endif 6 | 7 | static envid_t output_envid; 8 | 9 | static struct jif_pkt *pkt = (struct jif_pkt*)REQVA; 10 | 11 | 12 | void 13 | umain(int argc, char **argv) 14 | { 15 | envid_t ns_envid = sys_getenvid(); 16 | int i, r; 17 | 18 | binaryname = "testoutput"; 19 | 20 | output_envid = fork(); 21 | if (output_envid < 0) 22 | panic("error forking"); 23 | else if (output_envid == 0) { 24 | cprintf("output enviornment %d",thisenv->env_id); 25 | output(ns_envid); 26 | return; 27 | } 28 | 29 | for (i = 0; i < TESTOUTPUT_COUNT; i++) { 30 | if ((r = sys_page_alloc(0, pkt, PTE_P|PTE_U|PTE_W)) < 0) 31 | panic("sys_page_alloc: %e", r); 32 | pkt->jp_len = snprintf(pkt->jp_data, 33 | PGSIZE - sizeof(pkt->jp_len), 34 | "Packet %02d", i); 35 | cprintf("Transmitting packet %d\n", i); 36 | ipc_send(output_envid, NSREQ_OUTPUT, pkt, PTE_P|PTE_W|PTE_U); 37 | sys_page_unmap(0, pkt); 38 | } 39 | 40 | // Spin for a while, just in case IPC's or packets need to be flushed 41 | for (i = 0; i < TESTOUTPUT_COUNT*2; i++) 42 | sys_yield(); 43 | } 44 | -------------------------------------------------------------------------------- /net/timer.c: -------------------------------------------------------------------------------- 1 | #include "ns.h" 2 | 3 | void 4 | timer(envid_t ns_envid, uint32_t initial_to) { 5 | int r; 6 | uint32_t stop = sys_time_msec() + initial_to; 7 | 8 | binaryname = "ns_timer"; 9 | 10 | while (1) { 11 | while((r = sys_time_msec()) < stop && r >= 0) { 12 | sys_yield(); 13 | } 14 | if (r < 0) 15 | panic("sys_time_msec: %e", r); 16 | 17 | ipc_send(ns_envid, NSREQ_TIMER, 0, 0); 18 | 19 | while (1) { 20 | uint32_t to, whom; 21 | to = ipc_recv((int32_t *) &whom, 0, 0); 22 | 23 | if (whom != ns_envid) { 24 | cprintf("NS TIMER: timer thread got IPC message from env %x not NS\n", whom); 25 | continue; 26 | } 27 | 28 | stop = sys_time_msec() + to; 29 | break; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /scripts/Makefile: -------------------------------------------------------------------------------- 1 | # Let clean desend into subdirs 2 | subdir- += basic kconfig 3 | 4 | hostprogs-$(CONFIG_KALLSYMS) := kallsyms 5 | 6 | always := $(hostprogs-y) 7 | -------------------------------------------------------------------------------- /scripts/basic/.gitignore: -------------------------------------------------------------------------------- 1 | fixdep 2 | bin2c 3 | -------------------------------------------------------------------------------- /scripts/basic/Makefile: -------------------------------------------------------------------------------- 1 | ### 2 | # Makefile.basic lists the most basic programs used during the build process. 3 | # The programs listed herein are what are needed to do the basic stuff, 4 | # such as fix file dependencies. 5 | # This initial step is needed to avoid files to be recompiled 6 | # when kernel configuration changes (which is what happens when 7 | # .config is included by main Makefile. 8 | # --------------------------------------------------------------------------- 9 | # fixdep: Used to generate dependency information during build process 10 | 11 | hostprogs-y := fixdep 12 | hostprogs-$(CONFIG_BUILD_BIN2C) += bin2c 13 | always := $(hostprogs-y) 14 | 15 | # fixdep is needed to compile other host programs 16 | $(addprefix $(obj)/,$(filter-out fixdep,$(always))): $(obj)/fixdep 17 | -------------------------------------------------------------------------------- /scripts/basic/bin2c.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Unloved program to convert a binary on stdin to a C include on stdout 3 | * 4 | * Jan 1999 Matt Mackall 5 | * 6 | * This software may be used and distributed according to the terms 7 | * of the GNU General Public License, incorporated herein by reference. 8 | */ 9 | 10 | #include 11 | 12 | int main(int argc, char *argv[]) 13 | { 14 | int ch, total = 0; 15 | 16 | if (argc > 1) 17 | printf("const char %s[] %s=\n", 18 | argv[1], argc > 2 ? argv[2] : ""); 19 | 20 | do { 21 | printf("\t\""); 22 | while ((ch = getchar()) != EOF) { 23 | total++; 24 | printf("\\x%02x", ch); 25 | if (total % 16 == 0) 26 | break; 27 | } 28 | printf("\"\n"); 29 | } while (ch != EOF); 30 | 31 | if (argc > 1) 32 | printf("\t;\n\n#include \n\nconst size_t %s_size = %d;\n", 33 | argv[1], total); 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /scripts/gcc-goto.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Test for gcc 'asm goto' support 3 | # Copyright (C) 2010, Jason Baron 4 | 5 | cat << "END" | $@ -x c - -c -o /dev/null >/dev/null 2>&1 && echo "y" 6 | int main(void) 7 | { 8 | #if defined(__arm__) || defined(__aarch64__) 9 | /* 10 | * Not related to asm goto, but used by jump label 11 | * and broken on some ARM GCC versions (see GCC Bug 48637). 12 | */ 13 | static struct { int dummy; int state; } tp; 14 | asm (".long %c0" :: "i" (&tp.state)); 15 | #endif 16 | 17 | entry: 18 | asm goto ("" :::: entry); 19 | return 0; 20 | } 21 | END 22 | -------------------------------------------------------------------------------- /scripts/kconfig/.gitignore: -------------------------------------------------------------------------------- 1 | # 2 | # Generated files 3 | # 4 | config* 5 | *.lex.c 6 | *.tab.c 7 | *.tab.h 8 | zconf.hash.c 9 | *.moc 10 | gconf.glade.h 11 | *.pot 12 | *.mo 13 | 14 | # 15 | # configuration programs 16 | # 17 | conf 18 | mconf 19 | nconf 20 | qconf 21 | gconf 22 | kxgettext 23 | -------------------------------------------------------------------------------- /scripts/kconfig/POTFILES.in: -------------------------------------------------------------------------------- 1 | scripts/kconfig/lxdialog/checklist.c 2 | scripts/kconfig/lxdialog/inputbox.c 3 | scripts/kconfig/lxdialog/menubox.c 4 | scripts/kconfig/lxdialog/textbox.c 5 | scripts/kconfig/lxdialog/util.c 6 | scripts/kconfig/lxdialog/yesno.c 7 | scripts/kconfig/mconf.c 8 | scripts/kconfig/conf.c 9 | scripts/kconfig/confdata.c 10 | scripts/kconfig/gconf.c 11 | scripts/kconfig/gconf.glade.h 12 | scripts/kconfig/qconf.cc 13 | -------------------------------------------------------------------------------- /scripts/kconfig/check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Needed for systems without gettext 3 | $* -x c -o /dev/null - > /dev/null 2>&1 << EOF 4 | #include 5 | int main() 6 | { 7 | gettext(""); 8 | return 0; 9 | } 10 | EOF 11 | if [ ! "$?" -eq "0" ]; then 12 | echo -DKBUILD_NO_NLS; 13 | fi 14 | -------------------------------------------------------------------------------- /scripts/kconfig/lxdialog/.gitignore: -------------------------------------------------------------------------------- 1 | # 2 | # Generated files 3 | # 4 | lxdialog 5 | -------------------------------------------------------------------------------- /scripts/kconfig/lxdialog/BIG.FAT.WARNING: -------------------------------------------------------------------------------- 1 | This is NOT the official version of dialog. This version has been 2 | significantly modified from the original. It is for use by the Linux 3 | kernel configuration script. Please do not bother Savio Lam with 4 | questions about this program. 5 | -------------------------------------------------------------------------------- /scripts/mkmakefile: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Generates a small Makefile used in the root of the output 3 | # directory, to allow make to be started from there. 4 | # The Makefile also allow for more convinient build of external modules 5 | 6 | # Usage 7 | # $1 - Kernel src directory 8 | # $2 - Output directory 9 | # $3 - version 10 | # $4 - patchlevel 11 | 12 | 13 | test ! -r $2/Makefile -o -O $2/Makefile || exit 0 14 | # Only overwrite automatically generated Makefiles 15 | # (so we do not overwrite kernel Makefile) 16 | if test -e $2/Makefile && ! grep -q Automatically $2/Makefile 17 | then 18 | exit 0 19 | fi 20 | if [ "${quiet}" != "silent_" ]; then 21 | echo " GEN $2/Makefile" 22 | fi 23 | 24 | cat << EOF > $2/Makefile 25 | # Automatically generated by $0: don't edit 26 | 27 | VERSION = $3 28 | PATCHLEVEL = $4 29 | 30 | lastword = \$(word \$(words \$(1)),\$(1)) 31 | makedir := \$(dir \$(call lastword,\$(MAKEFILE_LIST))) 32 | 33 | ifeq ("\$(origin V)", "command line") 34 | VERBOSE := \$(V) 35 | endif 36 | ifneq (\$(VERBOSE),1) 37 | Q := @ 38 | endif 39 | 40 | MAKEARGS := -C $1 41 | MAKEARGS += O=\$(if \$(patsubst /%,,\$(makedir)),\$(CURDIR)/)\$(patsubst %/,%,\$(makedir)) 42 | 43 | MAKEFLAGS += --no-print-directory 44 | 45 | .PHONY: __sub-make \$(MAKECMDGOALS) 46 | 47 | __sub-make: 48 | \$(Q)\$(MAKE) \$(MAKEARGS) \$(MAKECMDGOALS) 49 | 50 | \$(filter-out __sub-make, \$(MAKECMDGOALS)): __sub-make 51 | @: 52 | EOF 53 | -------------------------------------------------------------------------------- /scripts/run.sh: -------------------------------------------------------------------------------- 1 | # 2 | # Simple command to test the standalone kernel 3 | # 4 | 5 | set -e 6 | 7 | # 8 | # Create a new directory to store the serial output 9 | # from printk(). 10 | # 11 | OUTPUT_DIR="test-output" 12 | if [ -e $OUTPUT_DIR ]; then 13 | if [ -f $OUTPUT_DIR ]; then 14 | echo "ERROR: $MOUNT_POINT is not a directly" 15 | exit 1 16 | fi 17 | else 18 | mkdir -p $OUTPUT_DIR 19 | fi 20 | 21 | LEGO_KERNEL="arch/x86/boot/bzImage" 22 | LINUX_KERNEL="/boot/vmlinuz-3.10.0-327.el7.x86_64" 23 | KERNEL_PARAM="console=ttyS0 earlyprintk=serial,ttyS0,115200 memmap=2G\$4G" 24 | 25 | LEGO_SERIAL="-serial file:$OUTPUT_DIR/ttyS0 -serial file:$OUTPUT_DIR/ttyS1" 26 | LINUX_SERIAL="-serial stdio" 27 | 28 | KERNEL=$LEGO_KERNEL 29 | SERIAL=$LEGO_SERIAL 30 | 31 | # $ ./run linux 32 | if [ "$1" == "linux" ]; then 33 | KERNEL=$LINUX_KERNEL 34 | SERIAL=$LINUX_SERIAL 35 | fi 36 | 37 | qemu-system-x86_64 -s \ 38 | -kernel $KERNEL -append "$KERNEL_PARAM" \ 39 | -no-reboot \ 40 | -d int,cpu_reset -D $OUTPUT_DIR/qemu.log \ 41 | $SERIAL \ 42 | -cpu Haswell,+tsc,+sse,+xsave,+aes,+avx,+erms,+pdpe1gb \ 43 | -m 16G \ 44 | -monitor stdio \ 45 | -smp cpus=24,cores=12,threads=2,sockets=2 \ 46 | -numa node,cpus=0-11,mem=8G,nodeid=0 \ 47 | -numa node,cpus=12-23,mem=8G,nodeid=1 48 | -------------------------------------------------------------------------------- /usr/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | a.out 3 | -------------------------------------------------------------------------------- /usr/Makefile: -------------------------------------------------------------------------------- 1 | srctree := ../ 2 | objtree := ../ 3 | SRCARCH := x86 4 | LEGO_INCLUDE := -I$(srctree)/arch/$(SRCARCH)/include \ 5 | -I$(objtree)/arch/$(SRCARCH)/include/generated \ 6 | -I$(objtree)/arch/$(SRCARCH)/include/generated/uapi \ 7 | -I$(objtree)/include 8 | 9 | CFLAGS := -static 10 | 11 | SRCS := $(wildcard *.c posix/*.c) 12 | OBJS := $(SRCS:.c=.o) 13 | 14 | all: $(OBJS) 15 | 16 | clean: 17 | rm -f *.o 18 | 19 | %.o: %.c includeme.h 20 | gcc -g -o $@ $(CFLAGS) $(LEGO_INCLUDE) $< -lm -pthread 21 | -------------------------------------------------------------------------------- /usr/README: -------------------------------------------------------------------------------- 1 | Issue make here to compile all syscall test code. 2 | To include the test within Lego, open managers/memory/ramfs/piggy.S: 3 | change the incbin to include the file you wanna test. Then compile lego again. 4 | 5 | Note that only one file can be included at one time. 6 | -------------------------------------------------------------------------------- /usr/exe.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Test execv() SYSCALL 3 | */ 4 | #include 5 | #include 6 | 7 | int main(void) 8 | { 9 | char *fname = "/usr/bin/python"; 10 | char * const argv[] = { 11 | fname, 12 | "/root/yutong/model/models-1.4.0/official/mnist/mnist.py", 13 | "--train_epochs", 14 | "1", 15 | NULL, 16 | }; 17 | 18 | setbuf(stdout, NULL); 19 | printf("Before execv\n"); 20 | 21 | if (!fork()){ 22 | execv(fname, argv); 23 | printf("BUG!\n"); 24 | return 0; 25 | } else 26 | wait(NULL); 27 | 28 | printf("After execv\n"); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /usr/general.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | static void lego_uname(void) 9 | { 10 | struct utsname foo; 11 | 12 | uname(&foo); 13 | printf("uname(): \n" 14 | "\t sysname: %s\n" 15 | "\t nodename: %s\n" 16 | "\t release: %s\n" 17 | "\t version: %s\n" 18 | "\t machine: %s\n", 19 | foo.sysname, foo.nodename, foo.release, foo.version, foo.machine); 20 | } 21 | 22 | static void lego_getrlimit(void) 23 | { 24 | struct rlimit l; 25 | 26 | getrlimit(RLIMIT_STACK, &l); 27 | printf("getrlimit(): RLIMIT_STACK, cur: %lld, max: %lld\n", 28 | l.rlim_cur, l.rlim_max); 29 | } 30 | 31 | static void lego_time(void) 32 | { 33 | struct timeval tv; 34 | time_t t; 35 | 36 | gettimeofday(&tv, NULL); 37 | printf("gettimeofday(): tv_sec: %lld, tv_usec: %lld\n", 38 | tv.tv_sec, tv.tv_usec); 39 | 40 | t = time(NULL); 41 | printf("time(NULL): %lld\n", t); 42 | } 43 | 44 | static void lego_set_tid_address(void) 45 | { 46 | pid_t tgid; 47 | int dummy; 48 | 49 | tgid = syscall(218, &dummy); 50 | printf("set_tid_address(): return tgid: %u\n", tgid); 51 | } 52 | 53 | int main(void) 54 | { 55 | printf("pid: %d\n", getpid()); 56 | lego_time(); 57 | 58 | lego_uname(); 59 | lego_getrlimit(); 60 | lego_set_tid_address(); 61 | 62 | lego_time(); 63 | } 64 | -------------------------------------------------------------------------------- /usr/gpm_test.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char** argv) { 4 | int i; 5 | printf("program start successfully\n"); 6 | for (i = 0; i < argc; i++) 7 | printf("args[%d]: %s\n", i, argv[i]); 8 | printf("test program ends\n"); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /usr/large_malloc.c: -------------------------------------------------------------------------------- 1 | #include "includeme.h" 2 | 3 | int oneg(void) 4 | { 5 | void *foo; 6 | long nr_size, i, nr_pages; 7 | struct timeval ts, te, result; 8 | 9 | fprintf(stderr, "One gig:\n"); 10 | 11 | nr_size = 1024*1024*1024*1; 12 | foo = malloc(nr_size); 13 | if (!foo) 14 | die("fail to malloc"); 15 | 16 | nr_pages = nr_size / PAGE_SIZE; 17 | fprintf(stderr, " Range: [%#lx - %#lx]\n", foo, foo + nr_pages * PAGE_SIZE); 18 | 19 | gettimeofday(&ts, NULL); 20 | for (i = 0; i < nr_pages; i++) { 21 | int *bar, cut; 22 | 23 | bar = foo + PAGE_SIZE * i; 24 | cut = *bar; 25 | } 26 | gettimeofday(&te, NULL); 27 | timeval_sub(&result, &te, &ts); 28 | 29 | printf(" Runtime: %ld.%ld s\n", 30 | result.tv_sec, result.tv_usec/1000); 31 | return 0; 32 | } 33 | 34 | int main(void) 35 | { 36 | oneg(); 37 | oneg(); 38 | oneg(); 39 | } 40 | -------------------------------------------------------------------------------- /usr/munmap.c: -------------------------------------------------------------------------------- 1 | #include "includeme.h" 2 | 3 | int main(void) 4 | { 5 | unsigned long base; 6 | int i, j; 7 | 8 | base = (unsigned long)malloc(PAGE_SIZE*256); 9 | 10 | base = (base + PAGE_SIZE) & ~(PAGE_SIZE-1); 11 | printf("base: %#lx\n", base); 12 | for (i = 0; i < 16; i++) { 13 | j = *(int *)(base+i*PAGE_SIZE); 14 | } 15 | 16 | munmap((void *)base, PAGE_SIZE*8); 17 | 18 | *(int *)(base + 0x60) = 66; 19 | 20 | printf("Lego munmap() BUG! Should not reach here!\n"); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /usr/posix/pthread_join.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../includeme.h" 3 | 4 | static void *thread_func(void *unused) 5 | { 6 | int tid = gettid(); 7 | 8 | printf(" thread %d is running\n", tid); 9 | sleep(3); 10 | sleep(3); 11 | sleep(3); 12 | } 13 | 14 | int main(void) 15 | { 16 | pthread_t tid; 17 | pthread_attr_t attr; 18 | int ret; 19 | 20 | pthread_attr_init(&attr); 21 | pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); 22 | ret = pthread_create(&tid, &attr, thread_func, NULL); 23 | if (ret) 24 | die("Unable to create thread"); 25 | 26 | printf("Before Join. Time: %d\n", time(NULL)); 27 | pthread_join(tid, NULL); 28 | printf("After Join. Time: %d\n", time(NULL)); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /usr/pthread.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Test: 3 | * pthread_create -> clone 4 | * gettid 5 | * getcpu 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | static pid_t gettid(void) 17 | { 18 | syscall(SYS_gettid); 19 | } 20 | 21 | void getcpu(int *cpu, int *node) 22 | { 23 | int ret; 24 | 25 | ret = syscall(SYS_getcpu, cpu, node, NULL); 26 | perror(""); 27 | } 28 | 29 | static void *thread_1(void *arg) 30 | { 31 | int cpu, node; 32 | 33 | getcpu(&cpu, &node); 34 | printf("In %s(), pid: %d, tid: %d CPU:%d NODE:%d\n", 35 | __func__, getpid(), gettid(), cpu, node); 36 | } 37 | 38 | int main(void) 39 | { 40 | int ret; 41 | pthread_t tid; 42 | int cpu, node; 43 | 44 | setbuf(stdout, NULL); 45 | 46 | getcpu(&cpu, &node); 47 | printf("In %s(), pid: %d, tid: %d CPU:%d NODE:%d\n", 48 | __func__, getpid(), gettid(), cpu, node); 49 | 50 | ret = pthread_create(&tid, NULL, thread_1, NULL); 51 | if (ret) { 52 | printf("pthread_create failed\n"); 53 | exit(-1); 54 | } 55 | pthread_join(tid, NULL); 56 | printf("new thread id is: %u\n", tid); 57 | } 58 | -------------------------------------------------------------------------------- /usr/seq.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Test all /proc and /sys file output 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 10 | 11 | static char *files[] = { 12 | "/proc/stat", 13 | "/proc/meminfo", 14 | "/proc/cmdline", 15 | "/proc/version", 16 | "/proc/processes", 17 | "/sys/devices/system/cpu/online", 18 | }; 19 | 20 | static char buf[8192]; 21 | static void dumpit(char *f_name) 22 | { 23 | int fd; 24 | 25 | fd = open(f_name, 0); 26 | if (fd < 0) { 27 | perror("open"); 28 | printf("Fail to open: %s\n", f_name); 29 | return; 30 | } 31 | 32 | memset(buf, 0, 8192); 33 | read(fd, buf, 8192); 34 | printf("%s\n", f_name); 35 | printf("%s\n", buf); 36 | 37 | close(fd); 38 | } 39 | 40 | int main() 41 | { 42 | int i, fd; 43 | 44 | fd = open("/dev/tty", 0, 0); 45 | if (fd < 0) { 46 | perror("open /dev/tty"); 47 | return; 48 | } 49 | printf("/dev/tty new fd: %d\n", fd); 50 | write(fd, "nihao", 5); 51 | 52 | for (i = 0; i < ARRAY_SIZE(files); i++) 53 | dumpit(files[i]); 54 | 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /usr/signal.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | static void hdl(int sig, siginfo_t *siginfo, void *context) 6 | { 7 | printf(" Handler: sig: %d\n", sig); 8 | printf(" Handler: Sending PID: %ld, UID: %ld\n", 9 | (long)siginfo->si_pid, (long)siginfo->si_uid); 10 | 11 | printf(" Handler: Current-PID: %d\n", getpid()); 12 | } 13 | 14 | int main() 15 | { 16 | struct sigaction act; 17 | 18 | memset(&act, 0, sizeof(act)); 19 | 20 | act.sa_sigaction = &hdl; 21 | 22 | act.sa_flags = SA_SIGINFO; 23 | 24 | if (sigaction(SIGINT, &act, NULL) < 0) { 25 | perror("sigaction"); 26 | return -1; 27 | } 28 | 29 | fprintf(stderr, "Before sending signal\n"); 30 | kill(getpid(), SIGINT); 31 | fprintf(stderr, "After sending signal\n"); 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /usr/test_eviction-pthread.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define NR_BITS 12 6 | #define SET_MASK ((1ULL << 28) - 1) 7 | 8 | #define PAGE_SIZE 4096 9 | 10 | unsigned long addr2set(unsigned long addr) 11 | { 12 | return (addr & SET_MASK) >> NR_BITS; 13 | } 14 | 15 | unsigned long addr2vfn(unsigned long addr) 16 | { 17 | return (addr >> NR_BITS) << NR_BITS; 18 | } 19 | 20 | void one_gig(char c, int thread) 21 | { 22 | char *mm, *end; 23 | unsigned long nr_size = 1024*1024*1024; 24 | mm = malloc(nr_size); 25 | end = mm + nr_size; 26 | mm = (char *) addr2vfn((unsigned long)mm); 27 | 28 | while (mm < end) { 29 | if (addr2set((unsigned long)mm) == 0) { 30 | printf("thread: %d addr in 0 set is %lx\n",thread, mm); 31 | (*mm) = c; 32 | } 33 | mm += PAGE_SIZE; 34 | } 35 | } 36 | 37 | void thread1() 38 | { 39 | one_gig('y', 1); 40 | one_gig('i', 1); 41 | one_gig('l', 1); 42 | } 43 | 44 | void thread2() 45 | { 46 | one_gig('c', 2); 47 | one_gig('h', 2); 48 | one_gig('e', 2); 49 | } 50 | 51 | void main() 52 | { 53 | pthread_t tid1, tid2; 54 | pthread_create(&tid1, NULL, thread1, NULL); 55 | pthread_create(&tid2, NULL, thread2, NULL); 56 | 57 | pthread_join(tid1, NULL); 58 | pthread_join(tid2, NULL); 59 | return; 60 | } 61 | -------------------------------------------------------------------------------- /usr/test_eviction.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | #define NR_BITS 12 6 | #define SET_MASK ((1ULL << 28) - 1) 7 | 8 | #define PAGE_SIZE 4096 9 | 10 | unsigned long addr2set(unsigned long addr) 11 | { 12 | return (addr & SET_MASK) >> NR_BITS; 13 | } 14 | 15 | unsigned long addr2vfn(unsigned long addr) 16 | { 17 | return (addr >> NR_BITS) << NR_BITS; 18 | } 19 | 20 | void one_gig(char c) 21 | { 22 | char *mm, *end; 23 | unsigned long nr_size = 1024*1024*1024; 24 | mm = malloc(nr_size); 25 | end = mm + nr_size; 26 | mm = (char *) addr2vfn((unsigned long)mm); 27 | 28 | while (mm < end) { 29 | if (addr2set((unsigned long)mm) == 0) { 30 | printf("addr in 0 set is %lx\n", mm); 31 | (*mm) = c; 32 | } 33 | mm += PAGE_SIZE; 34 | } 35 | } 36 | 37 | void main() 38 | { 39 | one_gig('y'); 40 | one_gig('i'); 41 | one_gig('l'); 42 | } 43 | -------------------------------------------------------------------------------- /usr/vma.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Compile: 3 | * gcc -static -Os getpid.c -o getpid 4 | */ 5 | #include 6 | #include 7 | int main(int argc, char **argv) 8 | { 9 | int *ptr; 10 | int *newptr; 11 | printf("program starts\n"); 12 | ptr = malloc(sizeof(int) * 3000000); 13 | newptr = realloc(ptr, sizeof(int) * 4000000); 14 | free(newptr); 15 | printf("looks good\n"); 16 | return 0; 17 | } 18 | --------------------------------------------------------------------------------