给ubuntu18.04系统内核升级rt-patch补丁

下载原料:

内核:https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/linux-5.4.138.tar.xz

补丁:https://mirrors.edge.kernel.org/pub/linux/kernel/projects/rt/5.4/patch-5.4.138-rt62.patch.gz

解压,打补丁:

将内核和补丁解压,解压后的patch-5.4.138-rt62.patch文件拷贝到内核目录下,执行如命令给内核打上RT补丁,打补丁的LOG如下:

patch -p1 < ./patch-5.4.138-rt62.patch
caozilong@caozilong-Vostro-3268:~/Workspace/linux-rt/linux-5.4.138$ patch -p1 < ./patch-5.4.138-rt62.patch 
patching file Documentation/RCU/Design/Expedited-Grace-Periods/Expedited-Grace-Periods.html
patching file Documentation/RCU/Design/Requirements/Requirements.html
patching file Documentation/RCU/checklist.txt
patching file Documentation/RCU/rcubarrier.txt
patching file Documentation/RCU/stallwarn.txt
patching file Documentation/RCU/whatisRCU.txt
patching file Documentation/admin-guide/sysctl/vm.rst
patching file Documentation/printk-ringbuffer.txt
patching file Documentation/trace/ftrace-uses.rst
patching file arch/Kconfig
patching file arch/alpha/include/asm/spinlock_types.h
patching file arch/arc/kernel/entry.S
patching file arch/arm/Kconfig
patching file arch/arm/include/asm/irq.h
patching file arch/arm/include/asm/spinlock_types.h
patching file arch/arm/include/asm/switch_to.h
patching file arch/arm/include/asm/thread_info.h
patching file arch/arm/kernel/asm-offsets.c
patching file arch/arm/kernel/entry-armv.S
patching file arch/arm/kernel/entry-common.S
patching file arch/arm/kernel/signal.c
patching file arch/arm/kernel/smp.c
patching file arch/arm/kernel/traps.c
patching file arch/arm/mm/cache-v7.S
patching file arch/arm/mm/cache-v7m.S
patching file arch/arm/mm/fault.c
patching file arch/arm/mm/highmem.c
patching file arch/arm64/Kconfig
patching file arch/arm64/crypto/sha256-glue.c
patching file arch/arm64/include/asm/assembler.h
patching file arch/arm64/include/asm/kvm_mmu.h
patching file arch/arm64/include/asm/preempt.h
patching file arch/arm64/include/asm/spinlock_types.h
patching file arch/arm64/include/asm/thread_info.h
patching file arch/arm64/kernel/asm-offsets.c
patching file arch/arm64/kernel/entry.S
patching file arch/arm64/kernel/fpsimd.c
patching file arch/arm64/kernel/signal.c
patching file arch/arm64/kernel/smp.c
patching file arch/arm64/kernel/traps.c
patching file arch/arm64/kvm/va_layout.c
patching file arch/c6x/kernel/entry.S
patching file arch/csky/kernel/entry.S
patching file arch/h8300/kernel/entry.S
patching file arch/hexagon/include/asm/spinlock_types.h
patching file arch/hexagon/kernel/vm_entry.S
patching file arch/ia64/include/asm/spinlock_types.h
patching file arch/ia64/kernel/entry.S
patching file arch/ia64/kernel/kprobes.c
patching file arch/m68k/coldfire/entry.S
patching file arch/microblaze/kernel/entry.S
patching file arch/mips/Kconfig
patching file arch/mips/include/asm/asmmacro.h
patching file arch/mips/kernel/entry.S
patching file arch/nds32/Kconfig
patching file arch/nds32/kernel/ex-exit.S
patching file arch/nios2/kernel/entry.S
patching file arch/parisc/Kconfig
patching file arch/parisc/kernel/entry.S
patching file arch/powerpc/Kconfig
patching file arch/powerpc/include/asm/spinlock_types.h
patching file arch/powerpc/include/asm/stackprotector.h
patching file arch/powerpc/include/asm/thread_info.h
patching file arch/powerpc/kernel/asm-offsets.c
patching file arch/powerpc/kernel/entry_32.S
patching file arch/powerpc/kernel/entry_64.S
patching file arch/powerpc/kernel/irq.c
patching file arch/powerpc/kernel/misc_32.S
patching file arch/powerpc/kernel/misc_64.S
patching file arch/powerpc/kernel/traps.c
patching file arch/powerpc/kernel/watchdog.c
patching file arch/powerpc/kvm/Kconfig
patching file arch/powerpc/platforms/ps3/device-init.c
patching file arch/powerpc/platforms/pseries/iommu.c
patching file arch/riscv/kernel/entry.S
patching file arch/s390/Kconfig
patching file arch/s390/include/asm/preempt.h
patching file arch/s390/include/asm/spinlock_types.h
patching file arch/s390/kernel/dumpstack.c
patching file arch/s390/kernel/entry.S
patching file arch/sh/Kconfig
patching file arch/sh/include/asm/spinlock_types.h
patching file arch/sh/kernel/cpu/sh5/entry.S
patching file arch/sh/kernel/entry-common.S
patching file arch/sh/kernel/irq.c
patching file arch/sparc/Kconfig
patching file arch/sparc/kernel/irq_64.c
patching file arch/sparc/kernel/rtrap_64.S
patching file arch/x86/Kconfig
patching file arch/x86/crypto/aesni-intel_glue.c
patching file arch/x86/crypto/cast5_avx_glue.c
patching file arch/x86/crypto/chacha_glue.c
patching file arch/x86/crypto/glue_helper.c
patching file arch/x86/entry/common.c
patching file arch/x86/entry/entry_32.S
patching file arch/x86/entry/entry_64.S
patching file arch/x86/include/asm/fpu/api.h
patching file arch/x86/include/asm/preempt.h
patching file arch/x86/include/asm/signal.h
patching file arch/x86/include/asm/stackprotector.h
patching file arch/x86/include/asm/thread_info.h
patching file arch/x86/kernel/apic/io_apic.c
patching file arch/x86/kernel/asm-offsets.c
patching file arch/x86/kernel/cpu/mshyperv.c
patching file arch/x86/kernel/fpu/core.c
patching file arch/x86/kernel/irq_32.c
patching file arch/x86/kernel/process_32.c
patching file arch/x86/kvm/x86.c
patching file arch/x86/mm/highmem_32.c
patching file arch/x86/mm/iomap_32.c
patching file arch/x86/mm/tlb.c
patching file arch/xtensa/include/asm/spinlock_types.h
patching file arch/xtensa/kernel/entry.S
patching file arch/xtensa/kernel/traps.c
patching file block/blk-ioc.c
patching file block/blk-mq.c
patching file block/blk-softirq.c
patching file crypto/cryptd.c
patching file drivers/block/zram/zcomp.c
patching file drivers/block/zram/zcomp.h
patching file drivers/block/zram/zram_drv.c
patching file drivers/block/zram/zram_drv.h
patching file drivers/char/random.c
patching file drivers/char/tpm/tpm-dev-common.c
patching file drivers/char/tpm/tpm_tis.c
patching file drivers/clocksource/Kconfig
patching file drivers/clocksource/timer-atmel-tcb.c
patching file drivers/connector/cn_proc.c
patching file drivers/dma-buf/dma-buf.c
patching file drivers/dma-buf/dma-resv.c
patching file drivers/firmware/efi/efi.c
patching file drivers/gpu/drm/Kconfig
patching file drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
patching file drivers/gpu/drm/i915/display/intel_sprite.c
patching file drivers/gpu/drm/i915/gem/i915_gem_busy.c
patching file drivers/gpu/drm/i915/gt/intel_breadcrumbs.c
patching file drivers/gpu/drm/i915/gt/intel_engine.h
patching file drivers/gpu/drm/i915/gt/intel_engine_pm.c
patching file drivers/gpu/drm/i915/gt/intel_hangcheck.c
patching file drivers/gpu/drm/i915/gt/intel_reset.c
patching file drivers/gpu/drm/i915/i915_irq.c
patching file drivers/gpu/drm/i915/i915_request.c
patching file drivers/gpu/drm/i915/i915_trace.h
patching file drivers/gpu/drm/radeon/radeon_display.c
patching file drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
patching file drivers/hv/hyperv_vmbus.h
patching file drivers/hv/vmbus_drv.c
patching file drivers/leds/trigger/Kconfig
patching file drivers/md/bcache/Kconfig
patching file drivers/md/raid5.c
patching file drivers/md/raid5.h
patching file drivers/media/platform/Kconfig
patching file drivers/net/phy/fixed_phy.c
patching file drivers/net/wireless/intersil/orinoco/orinoco_usb.c
patching file drivers/of/base.c
patching file drivers/of/dynamic.c
patching file drivers/of/of_private.h
patching file drivers/of/overlay.c
patching file drivers/pci/switch/switchtec.c
patching file drivers/scsi/fcoe/fcoe.c
patching file drivers/scsi/fcoe/fcoe_ctlr.c
patching file drivers/scsi/libfc/fc_exch.c
patching file drivers/thermal/intel/x86_pkg_temp_thermal.c
patching file drivers/tty/serial/8250/8250.h
patching file drivers/tty/serial/8250/8250_core.c
patching file drivers/tty/serial/8250/8250_fsl.c
patching file drivers/tty/serial/8250/8250_ingenic.c
patching file drivers/tty/serial/8250/8250_mtk.c
patching file drivers/tty/serial/8250/8250_port.c
patching file drivers/tty/serial/amba-pl011.c
patching file drivers/tty/serial/omap-serial.c
patching file drivers/usb/gadget/function/f_fs.c
patching file drivers/usb/gadget/legacy/inode.c
patching file drivers/video/backlight/Kconfig
patching file drivers/xen/preempt.c
patching file fs/afs/dir_silly.c
patching file fs/btrfs/volumes.h
patching file fs/buffer.c
patching file fs/cifs/readdir.c
patching file fs/dcache.c
patching file fs/eventpoll.c
patching file fs/ext4/page-io.c
patching file fs/fscache/cookie.c
patching file fs/fscache/main.c
patching file fs/fuse/readdir.c
patching file fs/inode.c
patching file fs/jbd2/commit.c
patching file fs/jbd2/journal.c
patching file fs/jbd2/transaction.c
patching file fs/namei.c
patching file fs/namespace.c
patching file fs/nfs/delegation.c
patching file fs/nfs/dir.c
patching file fs/nfs/inode.c
patching file fs/nfs/nfs4_fs.h
patching file fs/nfs/nfs4proc.c
patching file fs/nfs/nfs4state.c
patching file fs/nfs/unlink.c
patching file fs/ntfs/aops.c
patching file fs/ocfs2/suballoc.c
patching file fs/proc/base.c
patching file fs/proc/kmsg.c
patching file fs/proc/proc_sysctl.c
patching file fs/squashfs/decompressor_multi_percpu.c
patching file fs/stack.c
patching file fs/userfaultfd.c
patching file include/linux/bottom_half.h
patching file include/linux/bpf.h
patching file include/linux/buffer_head.h
patching file include/linux/cgroup-defs.h
patching file include/linux/cgroup.h
patching file include/linux/completion.h
patching file include/linux/console.h
patching file include/linux/dcache.h
patching file include/linux/delay.h
patching file include/linux/dma-resv.h
patching file include/linux/filter.h
patching file include/linux/fs.h
patching file include/linux/fscache.h
patching file include/linux/genhd.h
patching file include/linux/hardirq.h
patching file include/linux/highmem.h
patching file include/linux/idr.h
patching file include/linux/interrupt.h
patching file include/linux/irq_work.h
patching file include/linux/irqdesc.h
patching file include/linux/irqflags.h
patching file include/linux/jbd2.h
patching file include/linux/journal-head.h
patching file include/linux/kernel.h
patching file include/linux/kmsg_dump.h
patching file include/linux/list_bl.h
patching file include/linux/locallock.h
patching file include/linux/mm_types.h
patching file include/linux/mutex.h
patching file include/linux/mutex_rt.h
patching file include/linux/netdevice.h
patching file include/linux/nfs_fs.h
patching file include/linux/nfs_xdr.h
patching file include/linux/percpu-refcount.h
patching file include/linux/percpu-rwsem.h
patching file include/linux/percpu.h
patching file include/linux/pid.h
patching file include/linux/posix-timers.h
patching file include/linux/preempt.h
patching file include/linux/printk.h
patching file include/linux/printk_ringbuffer.h
patching file include/linux/radix-tree.h
patching file include/linux/random.h
patching file include/linux/ratelimit.h
patching file include/linux/rbtree.h
patching file include/linux/rcu_assign_pointer.h
patching file include/linux/rcupdate.h
patching file include/linux/rtmutex.h
patching file include/linux/rwlock_rt.h
patching file include/linux/rwlock_types.h
patching file include/linux/rwlock_types_rt.h
patching file include/linux/rwsem-rt.h
patching file include/linux/rwsem.h
patching file include/linux/sched.h
patching file include/linux/sched/mm.h
patching file include/linux/sched/wake_q.h
patching file include/linux/seqlock.h
patching file include/linux/serial_8250.h
patching file include/linux/signal.h
patching file include/linux/skbuff.h
patching file include/linux/smp.h
patching file include/linux/spinlock.h
patching file include/linux/spinlock_api_smp.h
patching file include/linux/spinlock_rt.h
patching file include/linux/spinlock_types.h
patching file include/linux/spinlock_types_nort.h
patching file include/linux/spinlock_types_raw.h
patching file include/linux/spinlock_types_rt.h
patching file include/linux/spinlock_types_up.h
patching file include/linux/stop_machine.h
patching file include/linux/swait.h
patching file include/linux/swap.h
patching file include/linux/thread_info.h
patching file include/linux/trace_events.h
patching file include/linux/uaccess.h
patching file include/linux/vmstat.h
patching file include/linux/wait.h
patching file include/net/gen_stats.h
patching file include/net/neighbour.h
patching file include/net/net_seq_lock.h
patching file include/net/sch_generic.h
patching file include/xen/xen-ops.h
patching file init/Kconfig
patching file init/init_task.c
patching file kernel/Kconfig.locks
patching file kernel/Kconfig.preempt
patching file kernel/bpf/hashtab.c
patching file kernel/bpf/lpm_trie.c
patching file kernel/bpf/percpu_freelist.c
patching file kernel/bpf/stackmap.c
patching file kernel/bpf/syscall.c
patching file kernel/bpf/verifier.c
patching file kernel/cgroup/cgroup.c
patching file kernel/cgroup/cpuset.c
patching file kernel/cgroup/rstat.c
patching file kernel/cpu.c
patching file kernel/events/core.c
patching file kernel/exit.c
patching file kernel/fork.c
patching file kernel/futex.c
patching file kernel/irq/handle.c
patching file kernel/irq/manage.c
patching file kernel/irq/spurious.c
patching file kernel/irq_work.c
patching file kernel/kexec_core.c
patching file kernel/ksysfs.c
patching file kernel/locking/Makefile
patching file kernel/locking/lockdep.c
patching file kernel/locking/locktorture.c
patching file kernel/locking/mutex-rt.c
patching file kernel/locking/percpu-rwsem.c
patching file kernel/locking/rtmutex.c
patching file kernel/locking/rtmutex_common.h
patching file kernel/locking/rwlock-rt.c
patching file kernel/locking/rwsem-rt.c
patching file kernel/locking/rwsem.c
patching file kernel/locking/rwsem.h
patching file kernel/locking/spinlock.c
patching file kernel/locking/spinlock_debug.c
patching file kernel/panic.c
patching file kernel/printk/Makefile
patching file kernel/printk/internal.h
patching file kernel/printk/printk.c
patching file kernel/printk/printk_safe.c
patching file kernel/ptrace.c
patching file kernel/rcu/Kconfig
patching file kernel/rcu/rcutorture.c
patching file kernel/rcu/srcutiny.c
patching file kernel/rcu/srcutree.c
patching file kernel/rcu/tree.c
patching file kernel/rcu/tree_exp.h
patching file kernel/rcu/tree_plugin.h
patching file kernel/rcu/update.c
patching file kernel/sched/completion.c
patching file kernel/sched/core.c
patching file kernel/sched/debug.c
patching file kernel/sched/fair.c
patching file kernel/sched/features.h
patching file kernel/sched/sched.h
patching file kernel/sched/swait.c
patching file kernel/sched/topology.c
patching file kernel/seccomp.c
patching file kernel/signal.c
patching file kernel/smp.c
patching file kernel/softirq.c
patching file kernel/stop_machine.c
patching file kernel/sysctl.c
patching file kernel/time/hrtimer.c
patching file kernel/time/jiffies.c
patching file kernel/time/posix-cpu-timers.c
patching file kernel/time/tick-common.c
patching file kernel/time/tick-sched.c
patching file kernel/time/timekeeping.c
patching file kernel/time/timekeeping.h
patching file kernel/time/timer.c
patching file kernel/trace/bpf_trace.c
patching file kernel/trace/trace.c
patching file kernel/trace/trace.h
patching file kernel/trace/trace_events.c
patching file kernel/trace/trace_output.c
patching file kernel/trace/trace_uprobe.c
patching file kernel/up.c
patching file kernel/workqueue.c
patching file lib/Kconfig.debug
patching file lib/Makefile
patching file lib/bust_spinlocks.c
patching file lib/debugobjects.c
patching file lib/irq_poll.c
patching file lib/locking-selftest.c
patching file lib/nmi_backtrace.c
patching file lib/printk_ringbuffer.c
patching file lib/radix-tree.c
patching file lib/scatterlist.c
patching file lib/smp_processor_id.c
patching file lib/test_bpf.c
patching file localversion-rt
patching file mm/Kconfig
patching file mm/compaction.c
patching file mm/highmem.c
patching file mm/kmemleak.c
patching file mm/memcontrol.c
patching file mm/memory.c
patching file mm/page_alloc.c
patching file mm/slab.c
patching file mm/slab.h
patching file mm/slub.c
patching file mm/swap.c
patching file mm/vmalloc.c
patching file mm/vmstat.c
patching file mm/workingset.c
patching file mm/zsmalloc.c
patching file mm/zswap.c
patching file net/Kconfig
patching file net/bluetooth/rfcomm/sock.c
patching file net/bpf/test_run.c
patching file net/core/dev.c
patching file net/core/flow_dissector.c
patching file net/core/gen_estimator.c
patching file net/core/gen_stats.c
patching file net/core/skmsg.c
patching file net/kcm/kcmsock.c
patching file net/packet/af_packet.c
patching file net/sched/sch_api.c
patching file net/sched/sch_generic.c
patching file net/sunrpc/svc_xprt.c
patching file security/apparmor/include/path.h
patching file security/apparmor/lsm.c
patching file virt/kvm/arm/arch_timer.c
patching file virt/kvm/arm/arm.c
caozilong@caozilong-Vostro-3268:~/Workspace/linux-rt/linux-5.4.138$ 

配置:

执行 make menuconfig

开启CONFIG_EXPERT

给ubuntu18.04系统内核升级rt-patch补丁_第1张图片

然后开启 CONFIG_PREEMPT_RT给ubuntu18.04系统内核升级rt-patch补丁_第2张图片

编译:

执行

make -j4
sudo make modules_install
sudo make headers_install
sudo make install

完成内核编译,安装,之后重启系统。

给ubuntu18.04系统内核升级rt-patch补丁_第3张图片

验证新内核:

重启后,执行命令  cat /proc/version查看新的内核:


测试实时性能:

安装rt-tests测试集

sudo apt-get install rt-tests
caozilong@caozilong-Vostro-3268:~/Workspace/linux-rt/linux-5.4.138$ sudo apt-get install rt-tests
[sudo] caozilong 的密码: 
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
下列软件包是自动安装的并且现在不需要了:
  libegl1-mesa libfwup1 libjpeg62 libllvm9 linux-hwe-5.4-headers-5.4.0-77 linux-hwe-5.4-headers-5.4.0-80 python-kerberos
使用'sudo apt autoremove'来卸载它(它们)。
下列【新】软件包将被安装:
  rt-tests
升级了 0 个软件包,新安装了 1 个软件包,要卸载 0 个软件包,有 32 个软件包未被升级。
需要下载 88.0 kB 的归档。
解压缩后会消耗 351 kB 的额外空间。
获取:1 http://cn.archive.ubuntu.com/ubuntu bionic/universe amd64 rt-tests amd64 1.0-3 [88.0 kB]
已下载 88.0 kB,耗时 1秒 (86.4 kB/s)
正在选中未选择的软件包 rt-tests。
(正在读取数据库 ... 系统当前共安装有 295933 个文件和目录。)
正准备解包 .../rt-tests_1.0-3_amd64.deb  ...
正在解包 rt-tests (1.0-3) ...
正在设置 rt-tests (1.0-3) ...
正在处理用于 man-db (2.8.3-2ubuntu0.1) 的触发器 ...
caozilong@caozilong-Vostro-3268:~/Workspace/linux-rt/linux-5.4.138$ 

此时,我们用的就是打了实时补丁的Linux内核驱动的Ubuntu系统了。

运行五个线程,线程优先级为80,无限循环

sudo cyclictest -t 5 -p 80 -n

给ubuntu18.04系统内核升级rt-patch补丁_第4张图片

cyclictest运行结果详解

P: 0 线程优先级为80. I: 1000 时间间隔为1000微秒(us)

Min: 最小延时(us).   Act: 最近一次的延时(us)

Avg:平均延时(us). Max: 最大延时(us)

在不加rt patch的virtualbox虚拟机上,跑的效果如下,还是比较差的:

给ubuntu18.04系统内核升级rt-patch补丁_第5张图片

真机上没有添加补丁的情况下:

给ubuntu18.04系统内核升级rt-patch补丁_第6张图片

经过一段时间后,可以看到,最大的DELAY有明显增长。

给ubuntu18.04系统内核升级rt-patch补丁_第7张图片

结束!

你可能感兴趣的:(嵌入式系统,Linux,linux)