-
Notifications
You must be signed in to change notification settings - Fork 3
/
makertaikernel.sh
executable file
·5410 lines (4933 loc) · 160 KB
/
makertaikernel.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
###########################################################################
# you should modify the following parameter according to your needs:
: ${KERNEL_PATH:=/usr/src} # where to put and compile the kernel (set with -s)
: ${LINUX_KERNEL:="4.4.115"} # linux vanilla kernel version (set with -k)
: ${KERNEL_SOURCE_NAME:="rtai"} # name for kernel source directory to be appended to LINUX_KERNEL
: ${KERNEL_NUM:="-1"} # name of the linux kernel is $LINUX_KERNEL-$RTAI_DIR$KERNEL_NUM
# (set with -n)
: ${LOCAL_SRC_PATH:=/usr/local/src} # directory for downloading and building
# rtai, newlib and comedi
: ${RTAI_DIR="rtai-5.2"} # name of the rtai source directory (set with -r):
# official relases for download (www.rtai.org):
# - rtai-5.2: rtai release version 5.2
# - rtai-5.1: rtai release version 5.1
# - rtai-x.x: rtai release version x.x
# from cvs (http://cvs.gna.org/cvsweb/?cvsroot=rtai):
# - magma: current development version
# - vulcano: stable development version
# Shahbaz Youssefi's RTAI clone on github:
# - RTAI: clone https://github.com/ShabbyX/RTAI.git
: ${RTAI_PATCH:="hal-linux-4.4.115-x86-10.patch"} # rtai patch to be used (set with -p)
# can be "none" if no patch should be applied
: ${KERNEL_CONFIG:="old"} # whether and how to initialize the kernel configuration
# (set with -c)
# - "old" for oldconfig from the running kernel,
# - "def" for the defconfig target,
# - "mod" for the localmodconfig target, (even if kernel do not match)
# - "backup" for the backed up kernel configuration from the last test batch.
# - a kernel config file.
# afterwards, the localmodconfig target is executed,
# if the running kernel matches LINUX_KERNEL.
: ${RUN_LOCALMOD:=true} # run make localmodconf after selecting a kernel configuration (disable with -l)
: ${KERNEL_MENU:="menuconfig"} # the menu for editing the kernel configuration
# (menuconfig, gconfig, xconfig)
: ${KERNEL_PARAM:="idle=poll"} # kernel parameter to be passed to grub
: ${KERNEL_PARAM_DESCR:="poll"} # one-word description of KERNEL_PARAM
# used for naming test resutls
: ${BATCH_KERNEL_PARAM:="oops=panic nmi_watchdog=panic softlockup_panic=1 unknown_nmi_panic panic=-1"} # additional kernel parameter passed to grub for test batch - we want to reboot in any case!
: ${KERNEL_CONFIG_BACKUP:="config-backup"} # stores initial kernel configuration for test batches
: ${NEWLIB_TAR:=newlib-3.1.0.tar.gz} # tar file of current newlib version
# at ftp://sourceware.org/pub/newlib/index.html
# in case git does not work
: ${MUSL_TAR:=musl-1.1.22.tar.gz} # tar file of current musl version
# at https://git.musl-libc.org/cgit/musl
# in case git does not work
: ${MAKE_NEWLIB:=true} # for automatic targets make newlib library
: ${MAKE_MUSL:=false} # for automatic targets make musl library
: ${MAKE_RTAI:=true} # for automatic targets make rtai library
: ${MAKE_COMEDI:=true} # for automatic targets make comedi library
: ${RTAI_HAL_PARAM:=""} # parameter for the rtai_hal module used for testing
: ${RTAI_SCHED_PARAM:=""} # parameter for the rtai_sched module used for testing
: ${TEST_TIME_DEFAULT:="600"} # default time in seconds used for latency test
: ${STARTUP_TIME:=300} # time to wait after boot to run a batch test in seconds
: ${COMPILE_TIME:=800} # time needed for building a kernel with reconfigure
# (this is only used for estimating the duration of a test batch)
: ${SHOWROOM_DIR:=showroom} # target directory for rtai-showrom in ${LOCAL_SRC_PATH}
# columns to be hidden in the test results table:
HIDE_COLUMNS=(
tests:test_details
tests:link
)
###########################################################################
# some global variables:
FULL_COMMAND_LINE="$@"
MAKE_RTAI_KERNEL="${0##*/}"
MAKE_RTAI_CONFIG="${MAKE_RTAI_KERNEL%.*}.cfg"
LOG_FILE="${PWD}/${MAKE_RTAI_KERNEL%.*}.log"
VERSION_STRING="${MAKE_RTAI_KERNEL} version 4.2 by Jan Benda, June 2019"
DRYRUN=false # only show what is being done (set with -d)
RECONFIGURE_KERNEL=false
NEW_KERNEL_CONFIG=false
DEFAULT_RTAI_DIR="$RTAI_DIR"
RTAI_DIR_CHANGED=false
RTAI_PATCH_CHANGED=false
LINUX_KERNEL_CHANGED=false
RTAI_MENU=false # enter RTAI configuration menu (set with -m)
NEW_KERNEL=false
NEW_RTAI=false
NEW_NEWLIB=false
NEW_MUSL=false
NEW_COMEDI=false
CURRENT_KERNEL=$(uname -r)
MACHINE=$(uname -m)
RTAI_MACHINE=$MACHINE
if test "x$RTAI_MACHINE" = "xx86_64"; then
RTAI_MACHINE="x86"
elif test "x$RTAI_MACHINE" = "xi686"; then
RTAI_MACHINE="x86"
fi
CPU_NUM=$(grep -c "^processor" /proc/cpuinfo)
KERNEL_NAME=${LINUX_KERNEL}-${RTAI_DIR}${KERNEL_NUM}
KERNEL_ALT_NAME=${LINUX_KERNEL}.0-${RTAI_DIR}${KERNEL_NUM}
REALTIME_DIR="/usr/realtime"
# this will be reset after reading in command line parameter!
###########################################################################
# general functions:
function set_variables {
test -n "$KERNEL_NUM" && test "x${KERNEL_NUM:0:1}" != "x-" && KERNEL_NUM="-$KERNEL_NUM"
KERNEL_NAME=${LINUX_KERNEL}-${RTAI_DIR}${KERNEL_NUM}
KERNEL_ALT_NAME=${LINUX_KERNEL}.0-${RTAI_DIR}${KERNEL_NUM}
REALTIME_DIR="/usr/realtime/${KERNEL_NAME}"
}
function echo_log {
echo "$(date +%T) $@" >> "$LOG_FILE"
echo "$@"
}
function echo_kmsg {
# this is for dmesg:
echo "#### MAKERTAIKERNEL.SH: $@" > /dev/kmsg
# this goes into the logger files:
# (on some systems kmsg does not end up in logger files)
logger -p user.info "#### MAKERTAIKERNEL.SH: $@"
}
function indent {
awk '{print " " $0}'
}
function print_version {
echo $VERSION_STRING
}
function help_kernel_options {
cat <<EOF
-d : dry run - only print out what the script would do, but do not execute any command
-k xxx: use linux kernel version xxx (LINUX_KERNEL=${LINUX_KERNEL})
-r xxx: the rtai source (RTAI_DIR=${RTAI_DIR}), one of
magma: current rtai development version from cvs
vulcano: stable rtai development version from cvs
rtai-5.1: rtai release version 5.1 from www.rtai.org
rtai-4.1: rtai release version 4.1 from www.rtai.org, or any other
rtai-x.x: rtai release version x.x from www.rtai.org
RTAI: snapshot from Shahbaz Youssefi's RTAI clone on github
-n xxx: append xxx to the name of the linux kernel (KERNEL_NUM=${KERNEL_NUM})
EOF
}
function help_info {
cat <<EOF
$VERSION_STRING
Print some information about your system.
Usage:
sudo ${MAKE_RTAI_KERNEL} info [rtai|kernel|cpu|interrupts|grub|settings|setup|log|configs [<FILE>]]
sudo ${MAKE_RTAI_KERNEL} [-c xxx] info menu
info : display properties of rtai patches, loaded kernel modules, kernel, machine,
and grub menu (configs and menu targets are excluded)
info rtai : list all available patches and suggest the one fitting to the kernel
info kernel : show name and kernel parameter of the currently running kernel
info cpu : show properties of your CPUs.
Information about C-states is not always available - better check the i7z programm.
info interrupts : show /proc/interrupts
info menu : show kernel configuration menu of the specified (-c) kernel configuration
info grub : show grub boot menu entries
info settings : show all configuration variables and their values
info setup : show modifications of your system made by ${MAKE_RTAI_KERNEL} (run as root)
info log : show content of log file - useful after test batch
info configs : show available kernel configurations in all config-* files
info configs <FILES> : show kernel configurations contained in <FILES>
info configs > <FILE>: save kernel configurations contained in <FILES>
to file <FILE> usable as a test batch file.
-c xxx: specify a kernel configuration xxx:
- old: use the kernel configuration of the currently running kernel
- def: generate a kernel configuration using make defconfig
- mod: simplify existing kernel configuration using make localmodconfig
even if kernel do not match
- backup: use the backed up kernel configuration from the last test batch.
- <config-file>: provide a particular configuration file.
After setting the configuration (except for mod), make localmodconfig
is executed to deselect compilation of unused modules, but only if the
runnig kernel matches the selected kernel version (major.minor only).
EOF
}
function help_setup {
cat <<EOF
$VERSION_STRING
Setup and restore syslog daemon, grub menu, and kernel parameter.
Usage:
sudo ${MAKE_RTAI_KERNEL} setup [messages|grub|comedi|kernel|rtai <cpus>]
sudo ${MAKE_RTAI_KERNEL} restore [messages|grub|comedi|kernel|rtai|testbatch]
setup : setup messages, grub, comedi, and kernel
setup messages : enable /var/log/messages needed for RTAI tests in rsyslog settings
setup grub : configure the grub boot menu (not hidden, no submenus,
extra RTAI kernel parameter, user can reboot and set rtai kernel parameter)
setup comedi : create "iocard" group and assign comedi devices to this group
setup kernel : set kernel parameter for the grub boot menu to "$KERNEL_PARAM"
setup rtai <cpus>: rebuild and install rtai testsuite to run the tests on the specified cpus
(comma-separated list of cpu ids)
restore : restore the original system settings (messages, grub, comedi, kernel, and testbatch)
restore messages : restore the original rsyslog settings
restore grub : restore the original grub boot menu settings and user access
restore comedi : do not assign comedi devices to the iocard group
restore kernel : restore default kernel parameter for the grub boot menu
restore rtai : restore, build, and install the original RTAI testsuite files
restore testbatch: uninstall the automatic test script from crontab and
remove variables from the grub environment (see help test)
EOF
}
function help_reboot {
cat <<EOF
$VERSION_STRING
Reboot and set kernel parameter.
Usage:
${MAKE_RTAI_KERNEL} [-d] [-n xxx] [-r xxx] [-k xxx] reboot [keep|none|<XXX>|<FILE>|<N>|default]
EOF
help_kernel_options
cat <<EOF
reboot : reboot into the rtai kernel ${MAKE_RTAI_KERNEL} is configured for
with kernel parameter as specified by KERNEL_PARAM
(currently set to "$KERNEL_PARAM")
reboot XXX : reboot into rtai kernel ${MAKE_RTAI_KERNEL} is configured for
with XXX passed on as kernel parameter
reboot FILE : reboot into rtai kernel ${MAKE_RTAI_KERNEL} is configured for
with kernel parameter taken from test results file FILE
reboot keep : reboot into rtai kernel ${MAKE_RTAI_KERNEL} is configured for
and keep previously set kernel parameter
reboot none : reboot into rtai kernel ${MAKE_RTAI_KERNEL} is configured for
without any additional kernel parameter
reboot N : reboot into a kernel as specified by grub menu entry index N
without additional kernel parameter,
see "${MAKE_RTAI_KERNEL} info grub" for the grub menu.
reboot default: reboot into the default kernel of the grub menu.
Rebooting as a regular user (without sudo) has the advantage to store
the session of your window manager. With the grub environment available
(/boot/grub/grubenv) this should be possible (after an "setup grub").
EOF
}
function help_test {
cat <<EOF
$VERSION_STRING
Test the performance of the rtai-patched linux kernel.
Usage:
sudo ${MAKE_RTAI_KERNEL} [-d] [-n xxx] [-r xxx] [-k xxx] test [[hal|sched|math|comedi] [calib]
[kern|kthreads|user|all|none] [cpu|io|mem|net|full]
[cpu=<CPUIDS>] [latency|cpulatency|cpulatencyall] [performance]
[<NNN>] [auto <XXX> | batch basics|cstates|acpi|isolcpus|dma|poll|<FILE>]]
EOF
help_kernel_options
cat <<EOF
Tests are performed only if the running kernel matches the one
${MAKE_RTAI_KERNEL} is configured for.
Test resluts are saved in latencies-* files in the current working
directory. The corresponding kernel configuration is saved in the
respective config-* files.
First, loading and unloading of rtai and comedi modules is tested.
This can be controlled by the following key-words of which one can be specified:
hal : test loading and unloading of rtai_hal kernel module only
sched : test loading and unloading of rtai_hal and rtai_sched kernel modules
math : test loading and unloading of rtai_hal, rtai_sched, and rtai_math kernel module
comedi : test loading and unloading of rtai and comedi kernel modules
Additionally, you may specify:
calib : force calibration of scheduling latencies (default is no calibration)
Then the rtai tests (latency, switch, and preempt) are executed. You can
select what to test by specifying one or more of the following key-words:
kern : run the kern tests (default)
kthreads : run the kthreads tests
user : run the user tests
all : run the kernel, kthreads, and user tests
none : test loading and unloading of kernel modules and do not run any tests
You may want to run some load on you system to really test the RTAI
performance. This can be controlled by the following key-words:
cpu : run heavy computations on each core
io : do some heavy file reading and writing
mem : do some heavy memory access
net : produce network traffic
full : all of the above
Further options specify further conditions for running the tests:
cpu=<CPUIDS> : run tests on CPU with ids <CPUIDS>. <CPUIDS> is a comma separated
list of CPUs. The first CPU is 0. For example, cpu=2 runs the tests
on the third CPU.
latency : Keep all CPUs in C0 state by writing a zero to the file /dev/cpu_dma_latency .
cpulatency : Using PM QoS request to keep CPUs in C0 state. If a CPU was specified for
running the tests (cpu=<CPUIDS> parameter), only that CPU is put into C0,
if possible. Uses the cpulatency kernel module.
cpulatencyall: Using PM QoS request to keep all CPUs in C0 state.
Uses the cpulatency kernel module.
performance : Sets the cpu freq scaling governor to performance, i.e. to the maximum frequency.
The rtai tests need to be terminated by pressing ^C and a string
describing the test scenario needs to be provided. This can be
automized by the following two options:
NNN : the number of seconds after which the latency test is automatically aborted,
the preempt test will be aborted after 10 seconds.
auto XXX : a one-word description of the kernel configuration (no user interaction)
For a completely automized series of tests of various kernel parameters and kernel configurations
under different loads you may add as the last arguments:
batch FILE : automatically run tests with various kernel parameter and configurations as specified in FILE
batch basics : write a default batch file with basic kernel parameters to be tested
batch isolcpus : write a default batch file with load settings and isolcpus kernel parameters to be tested
batch nohzrcu : write a default batch file with more isolcpus kernel parameters to be tested
batch dma : write a default batch file with io load, dma, and isolcpus kernel parameters to be tested
batch poll : write a default batch file for testing run-time alternatives to idle=poll
batch cstates : write a default batch file with c-states related kernel parameters to be tested
batch acpi : write a default batch file with acpi related kernel parameters to be tested
batch apic : write a default batch file with apic related kernel parameters to be tested
This successively reboots into the RTAI kernel with the kernel parameter
set to the ones specified by the KERNEL_PARAM variable and as specified in FILE,
and runs the tests as specified by the previous commands (without the "auto" command).
Special lines in FILE cause reboots into the default kernel and building an RTAI-patched kernel
with a new configuration.
In a batch FILE
- everything behind a hash ('#') is a comment that is completely ignored
- empty lines are ignored
- a line of the format
<descr> : <specs> : <params>
describes a configuration to be tested:
<descr> is a one-word string describing the kernel parameter
(a description of the load settings is added automatically to the description)
<specs> defines the load processes to be
started before testing (cpu io mem net full, see above), the CPU
on which the test should be run (cpu=<CPUIDS>, see above),
whether CPUs should be kept in C0 state (latency, cpulatency, or cpulatencyall, see above),
and/or whether the CPU frequency should be maximized (performance, see above).
<param> is a list of kernel parameter to be used.
- a line of the format
<descr> : CONFIG : <file>
specifies a new kernel configuration stored in <file>,
that is compiled after booting into the default kernel.
<descr> describes the kernel configuration; it is used for naming successive tests.
Actually, <file> can be everything the -c otion is accepting, in particular
<descr> : CONFIG : backup
compiles a kernel with the configuration of the kernel at the beginning of the tests.
This is particularly usefull as the last line of a batch file.
- the first line of the batch file can be just
<descr> : CONFIG :
this sets <descr> as the description of the already existing RTAI kernel for the following tests.
Use
${MAKE_RTAI_KERNEL} prepare
to generate a file with various kernel configurations.
Example lines:
lowlatency : CONFIG :
pollnohz : : idle=poll nohz=off
nohz : latency : nohz=off
nodyntics : CONFIG : config-nodyntics
pollisol : cpu io : idle=poll isolcpus=0,1
isol2 : io cpu=2 : isolcpus=2
See the file written by "batch default" for suggestions, and the file
$KERNEL_PATH/linux-${LINUX_KERNEL}-${KERNEL_SOURCE_NAME}/Documentation/kernel-parameters.txt
for a documentation of all kernel parameter.
EOF
}
function help_report {
cat <<EOF
$VERSION_STRING
Generate summary tables of test results.
Usage:
${MAKE_RTAI_KERNEL} report [avg|max] [<FILES>]
The summary is written to standard out. For example, redirect the
output into a file to save the summary:
${MAKE_RTAI_KERNEL} report > testsummary.dat
or pipe it into less to view the results:
${MAKE_RTAI_KERNEL} report | less -S
The tests can be sorted by providing the avg or max key-word:
report : do not sort
report avg : sort the tests according to the avgmax field of the kern latency test
report max : sort the tests according to the ovlmax field of the kern latency test
The remaining arguments specify files to be included in the summary,
or a directory containing latency-* files. If no file is specified,
all latency-* files in the current directory are used.
EOF
}
function help_usage {
cat <<EOF
$VERSION_STRING
Download, build, install and test everything needed for an rtai-patched linux kernel with math and comedi support.
usage:
sudo ${MAKE_RTAI_KERNEL} [-d] [-s xxx] [-n xxx] [-r xxx] [-p xxx] [-k xxx] [-c xxx] [-l] [-D] [-m]
[action [target1 [target2 ... ]]]
EOF
help_kernel_options
cat <<EOF
-s xxx: use xxx as the base directory where to put the kernel sources (KERNEL_PATH=${KERNEL_PATH})
-p xxx: use rtai patch file xxx (RTAI_PATCH=${RTAI_PATCH})
set to "none" if no patch should be applied
-c xxx: generate a new kernel configuration (KERNEL_CONFIG=${KERNEL_CONFIG}):
- old: use the kernel configuration of the currently running kernel
- def: generate a kernel configuration using make defconfig
- mod: simplify existing kernel configuration using make localmodconfig
even if kernel do not match
- backup: use the backed up kernel configuration from the last test batch.
- <config-file>: provide a particular configuration file
After setting the configuration (except for mod), make localmodconfig
is executed to deselect compilation of unused modules, but only if the
runnig kernel matches the selected kernel version (major.minor only).
-l : disable call to make localmodconf after a kernel configuration
has been selected via the -c switch (RUN_LOCALMOD=${RUN_LOCALMOD})
-m : enter the RTAI configuration menu
Note: for running test batches, settings provided via the command line are lost after rebooting.
You can modify the settings by editing "$MAKE_RTAI_KERNEL" directly.
Alternatively, you can provide settings by listing them in a configuration file
in the current working directory called "$MAKE_RTAI_CONFIG". Create a configuration
file by means of the "config" action (see below).
If no action is specified, a full download and build is performed for all targets (except showroom).
For the targets one or more of:
packages : required packages (install only)
kernel : rtai-patched linux kernel
newlib : newlib library, needed for math support in kernel
musl : musl library, needed for math support in kernel
rtai : rtai modules
showroom : rtai showroom examples (supports only download, build, clean, remove)
comedi : comedi data acquisition driver modules
comedilib : comedi data acquisition user space library
comedicalib: comedi data acquisition calibration tools
action can be one of:
download : download missing sources of the specified targets
update : update sources of the specified targets (not for kernel target)
patch : clean, unpack, and patch the linux kernel with the rtai patch (no target required)
build : compile and install the specified targets and the depending ones if needed
buildplain : compile and install the kernel without the rtai patch (no target required)
clean : clean the source trees of the specified targets
install : install the specified targets
uninstall : uninstall the specified targets
remove : remove the complete source trees of the specified targets.
If no target is specified, all targets are made (except showroom).
Action can be also one of
help : display this help message
help XXX : display help message for action XXX
info : display properties of rtai patches, loaded kernel modules,
kernel, cpus, machine, log file, and grub menu
(run "${MAKE_RTAI_KERNEL} help info" for details)
config : write the configuration file \"${MAKE_RTAI_CONFIG}\"
that you can edit according to your needs
init : should be executed the first time you use ${MAKE_RTAI_KERNEL} -
equivalent to install packages, setup, download rtai, info rtai.
reconfigure: reconfigure the kernel and make a full build of all targets (without target)
reboot : reboot and set kernel parameter
(run "${MAKE_RTAI_KERNEL} help reboot" for details)
setup : setup some basic configurations of your (debian based) system
(run "${MAKE_RTAI_KERNEL} help setup" for details)
restore : restore the original system settings
(run "${MAKE_RTAI_KERNEL} help restore" for details)
prepare : prepare kernel configurations for a test batch (no target required)
test : test the current kernel and write reports to the current working directory
(run "${MAKE_RTAI_KERNEL} help test" for details)
report : summarize test results from latencies* files given in FILES
(run "${MAKE_RTAI_KERNEL} help report" for details)
Common use cases:
Start with installing required packages, setting up /var/log/messages, the grub boot menu,
and downloading an rtai source (-r option or RTAI_DIR variable):
$ sudo ${MAKE_RTAI_KERNEL} init
Select a Linux kernel and a RTAI patch from the displayed list and set
the LINUX_KERNEL and RTAI_PATCH variables in the makertaikernel.sh
script accordingly.
Check again for available patches:
$ sudo ${MAKE_RTAI_KERNEL} info rtai
Once you have decided on a patch and you have set LINUX_KERNEL and
RTAI_PATCH variables accrdingly run
$ sudo ${MAKE_RTAI_KERNEL}
to download and build all targets. A new configuration for the kernel is generated.
$ sudo ${MAKE_RTAI_KERNEL} test
manually test the currently running kernel.
$ sudo ${MAKE_RTAI_KERNEL} test 30 auto basic
automaticlly test the currently running kernel for 30 seconds and name it "basic".
$ sudo ${MAKE_RTAI_KERNEL} test ${TEST_TIME_DEFAULT} batch testbasics.mrk
automaticlly test all the kernel parameter and kernel configurations specified in the file testbasics.mrk.
$ ${MAKE_RTAI_KERNEL} report avg | less -S
view test results sorted with respect to the averaged maximum latency.
$ sudo ${MAKE_RTAI_KERNEL} reconfigure
build all targets using the existing configuration of the kernel.
$ sudo ${MAKE_RTAI_KERNEL} uninstall
uninstall all targets.
EOF
}
function check_root {
if test "x$(id -u)" != "x0"; then
echo "You need to be root to run this script!"
echo "Try:"
echo " sudo $0 ${FULL_COMMAND_LINE}"
exit 1
fi
}
function print_setup {
check_root
echo
echo "System modifications made by ${MAKE_RTAI_KERNEL}:"
echo
# messages:
if test -f /etc/rsyslog.d/50-default.conf.origmrk; then
echo "messages : /etc/rsyslog.d/50-default.conf is modified"
echo " run \"${MAKE_RTAI_KERNEL} restore messages\" to restore"
elif test -f /etc/rsyslog.d/50-default.conf; then
echo "messages : /etc/rsyslog.d/50-default.conf is not modified"
echo " run \"${MAKE_RTAI_KERNEL} setup messages\" for setting up"
fi
# grub:
if test -f /etc/default/grub.origmrk; then
echo "grub : /etc/default/grub is modified"
echo " run \"${MAKE_RTAI_KERNEL} restore grub\" to restore"
else
echo "grub : /etc/default/grub is not modified"
echo " run \"${MAKE_RTAI_KERNEL} setup grub\" for setting up"
fi
if test -f /etc/grub.d/10_linux.origmrk; then
echo "grub : /etc/grub.d/10_linux is modified"
echo " run \"${MAKE_RTAI_KERNEL} restore grub\" to restore"
else
echo "grub : /etc/grub.d/10_linux is not modified"
echo " run \"${MAKE_RTAI_KERNEL} setup grub\" for setting up"
fi
# kernel parameter:
if test -f /boot/grub/grubenv; then
if grub-editenv - list | grep -q "rtai_cmdline"; then
echo "kernel : /boot/grub/grubenv is modified ($(grub-editenv - list | grep "rtai_cmdline"))"
echo " run \"${MAKE_RTAI_KERNEL} restore kernel\" to restore"
else
echo "kernel : /boot/grub/grubenv is not modified"
echo " run \"${MAKE_RTAI_KERNEL} setup kernel\" for setting up RTAI kernel parameter"
fi
else
if test -f /etc/default/grub.origkp; then
echo "kernel : /etc/default/grub is modified"
echo " run \"${MAKE_RTAI_KERNEL} restore kernel\" to restore"
else
echo "kernel : /etc/default/grub is not modified"
echo " run \"${MAKE_RTAI_KERNEL} setup kernel\" for setting up default RTAI kernel parameter"
fi
fi
# rtai:
if test -f ${LOCAL_SRC_PATH}/$RTAI_DIR/testsuite/kern/latency/latency-module.c.mrk; then
echo "rtai : testsuite is modified"
echo " run \"${MAKE_RTAI_KERNEL} restore rtai\" to restore"
else
echo "rtai : testsuite is not modified"
echo " run \"${MAKE_RTAI_KERNEL} setup rtai <cpumask>\" for setting a CPU mask for the tests"
fi
# test batch:
if crontab -l 2> /dev/null | grep -q "${MAKE_RTAI_KERNEL}"; then
echo "testbatch: crontab is modified"
echo " run \"${MAKE_RTAI_KERNEL} restore testbatch\" to restore"
else
echo "testbatch: crontab is not modified"
fi
echo
}
function print_log {
if test -r "${LOG_FILE}"; then
echo "Content of the log-file \"${LOG_FILE}\":"
cat "$LOG_FILE"
else
echo "Log-file \"${LOG_FILE}\" not available."
fi
}
function print_kernel_configs {
KCF=""
test -z "$1" && KCF="config-*"
if [ -t 1 ]; then
echo "Available kernel configurations - add them to a test batch file."
echo "Configurations identical with the current one are marked by an asterisk."
echo
for FILE in "$@" $KCF; do
SAME=" "
diff -q "$FILE" $KERNEL_PATH/linux-${LINUX_KERNEL}-${KERNEL_SOURCE_NAME}/.config> /dev/null && SAME="* "
echo "${SAME}${FILE##*config-} : CONFIG : $FILE"
done
else
for FILE in "$@" $KCF; do
echo "${FILE##*config-} : CONFIG : $FILE"
done
fi
}
function print_grub {
if test "x$1" = "xenv" && test -r /boot/grub/grubenv; then
echo "Grub environment:"
grub-editenv - list | indent
echo
fi
echo "Grub menu entries:"
IFSORG="$IFS"
IFS=$'\n'
N=0
for gm in $(grep '^\s*menuentry ' /boot/grub/grub.cfg | cut -d "'" -f 2); do
echo " $N) $gm"
let N+=1
done
IFS="$IFSORG"
echo
}
function print_versions {
echo "Versions:"
echo " kernel : ${LINUX_KERNEL}"
echo " gcc : $(gcc --version | head -n 1)"
if test -r ${LOCAL_SRC_PATH}/${RTAI_DIR}/revision.txt; then
echo " rtai : ${RTAI_DIR} from $(cat ${LOCAL_SRC_PATH}/${RTAI_DIR}/revision.txt)"
echo " patch : ${RTAI_PATCH}"
elif test -d ${LOCAL_SRC_PATH}/${RTAI_DIR}; then
echo " rtai : ${RTAI_DIR} revision not available"
echo " patch : ${RTAI_PATCH}"
else
echo " rtai : not available"
fi
if test -r ${LOCAL_SRC_PATH}/newlib/src/revision.txt; then
echo " newlib : git from $(cat ${LOCAL_SRC_PATH}/newlib/src/revision.txt)"
elif test -r ${LOCAL_SRC_PATH}/newlib/revision.txt; then
echo " newlib : git from $(cat ${LOCAL_SRC_PATH}/newlib/revision.txt)"
elif test -d ${LOCAL_SRC_PATH}/newlib; then
echo " newlib : revision not available"
else
echo " newlib : not available"
fi
if test -r ${LOCAL_SRC_PATH}/musl/revision.txt; then
echo " musl : git from $(cat ${LOCAL_SRC_PATH}/musl/revision.txt)"
elif test -d ${LOCAL_SRC_PATH}/musl; then
echo " musl : revision not available"
else
echo " musl : not available"
fi
if test -r ${LOCAL_SRC_PATH}/comedi/revision.txt; then
echo " comedi : git from $(cat ${LOCAL_SRC_PATH}/comedi/revision.txt)"
elif test -d ${LOCAL_SRC_PATH}/comedi; then
echo " comedi : revision not available"
else
echo " comedi : not available"
fi
if test -r ${LOCAL_SRC_PATH}/comedilib/revision.txt; then
echo " comedilib : git from $(cat ${LOCAL_SRC_PATH}/comedilib/revision.txt)"
elif test -d ${LOCAL_SRC_PATH}/comedilib; then
echo " comedilib : revision not available"
else
echo " comedilib : not available"
fi
if test -r ${LOCAL_SRC_PATH}/comedicalib/revision.txt; then
echo " comedicalib: git from $(cat ${LOCAL_SRC_PATH}/comedicalib/revision.txt)"
elif test -d ${LOCAL_SRC_PATH}/comedicalib; then
echo " comedicalib: revision not available"
else
echo " comedicalib: not available"
fi
echo
}
function print_interrupts {
echo "Interrupts (/proc/interrupts):"
cat /proc/interrupts | indent
echo
}
function print_kernel {
echo "Hostname: $(hostname)"
echo
echo "Running kernel (uname -r): $(uname -r)"
echo
echo "Kernel parameter (/proc/cmdline):"
for param in $(cat /proc/cmdline); do
echo " $param"
done
echo
}
function print_environment {
CPU_ID=$1
echo "Environment:"
echo " tests run on cpu : ${CPU_ID}"
# /dev/cpu_dma_latency:
if test "x$(id -u)" == "x0"; then
# if we are root we can show /dev/cpu_dma_latency:
if test -c /dev/cpu_dma_latency; then
echo " /dev/cpu_dma_latency: $(hexdump -e '"%d\n"' /dev/cpu_dma_latency)"
else
echo " /dev/cpu_dma_latency: -"
fi
fi
# cpulatency kernel module:
if lsmod | grep -q cpulatency; then
CPU_LAT_ID=$(grep -a cpulatency /var/log/messages | tail -n 1 | sed -e 's/^.*CPU=//')
echo " cpulatency on cpu : $CPU_LAT_ID"
else
echo " cpulatency : not loaded"
fi
# frequency scaling:
CPU=/sys/devices/system/cpu/cpu${CPU_ID}
CPUFREQGOVERNOR="-"
test -r $CPU/cpufreq/scaling_governor && CPUFREQGOVERNOR=$(cat $CPU/cpufreq/scaling_governor)
echo " governor : $CPUFREQGOVERNOR"
CPUFREQ=$(grep 'cpu MHz' /proc/cpuinfo | awk -F ': ' "NR==$(($CPU_ID+1)) {printf \"%.3f\", 0.001*\$2}")
test -r $CPU/cpufreq/scaling_cur_freq && CPUFREQ=$(echo "scale=3;" $(cat $CPU/cpufreq/scaling_cur_freq)/1000000.0 | bc)
echo " cpu frequency : $CPUFREQ GHz"
if test -r $CPU/cpufreq/scaling_max_freq; then
CPUFREQ=$(echo "scale=3;" $(cat $CPU/cpufreq/scaling_max_freq)/1000000.0 | bc)
echo " max cpu frequency : $CPUFREQ GHz"
fi
if test -r $CPU/cpufreq/scaling_min_freq; then
CPUFREQ=$(echo "scale=3;" $(cat $CPU/cpufreq/scaling_min_freq)/1000000.0 | bc)
echo " min cpu frequency : $CPUFREQ GHz"
fi
echo
}
function store_cpus {
rm -f results-cpufreq${1}.dat results-cpuidle${1}.dat
# frequency statistics needs CONFIG_CPU_FREQ_STAT:
if test -r /sys/devices/system/cpu/cpu0/cpufreq/stats/total_trans; then
for CPU in /sys/devices/system/cpu/cpu[0-9]*; do
cat $CPU/cpufreq/stats/total_trans
done > results-cpufreq${1}.dat
fi
CSTATEUSAGE="time" # "usage" or "time"
if test -r /sys/devices/system/cpu/cpu0/cpuidle/state0/name; then
for CPU in /sys/devices/system/cpu/cpu[0-9]*; do
for CSTATE in $CPU/cpuidle/state*; do
echo -n "$(cat $CSTATE/$CSTATEUSAGE) "
done
echo
done > results-cpuidle${1}.dat
fi
}
function print_cpus {
echo "CPU topology, frequencies, and idle states (/sys/devices/system/cpu/*):"
# first header line:
printf "CPU topology CPU frequency scaling "
test -r /sys/devices/system/cpu/cpu0/cpuidle/state0/name && printf " CPU idle states (disabled time-fraction%%)"
printf "\n"
# second header line:
printf "logical socket core online freq/GHz governor transitions"
if test -r /sys/devices/system/cpu/cpu0/cpuidle/state0/name; then
for CSTATE in /sys/devices/system/cpu/cpu0/cpuidle/state*/name; do
printf " %-7s" $(cat $CSTATE)
done
fi
printf "\n"
# data:
store_cpus 1
CPU_NO=0
for CPU in /sys/devices/system/cpu/cpu[0-9]*; do
let CPU_NO+=1
CPUT="$CPU/topology"
LC_NUMERIC="en_US.UTF-8"
ONLINE=1
test -r $CPU/online && ONLINE=$(cat $CPU/online)
CPUFREQ=$(grep 'cpu MHz' /proc/cpuinfo | awk -F ': ' "NR==$CPU_NO {printf \"%.3f\", 0.001*\$2}")
test -r $CPU/cpufreq/scaling_cur_freq && CPUFREQ=$(echo "scale=3;" $(cat $CPU/cpufreq/scaling_cur_freq)/1000000.0 | bc)
CPUFREQGOVERNOR="-"
test -r $CPU/cpufreq/scaling_governor && CPUFREQGOVERNOR=$(cat $CPU/cpufreq/scaling_governor)
CPUFREQTRANS="n.a."
if test -r results-cpufreq1.dat; then
CPUFREQTRANS=$(sed -n -e "${CPU_NO}p" results-cpufreq1.dat)
if test -r results-cpufreq0.dat; then
CF0=$(sed -n -e "${CPU_NO}p" results-cpufreq0.dat)
let CPUFREQTRANS-=$CF0
fi
fi
printf " cpu%-2d %6d %4d %6d %8.3f %12s %11s" ${CPU#/sys/devices/system/cpu/cpu} $(cat $CPUT/physical_package_id) $(cat $CPUT/core_id) $ONLINE $CPUFREQ $CPUFREQGOVERNOR $CPUFREQTRANS
if test -r results-cpuidle1.dat; then
CPUIDLETRANS=($(sed -n -e "${CPU_NO}p" results-cpuidle1.dat))
if test -r results-cpuidle0.dat; then
CI0=($(sed -n -e "${CPU_NO}p" results-cpuidle0.dat))
for (( i=0; i<${#CPUIDLETRANS[@]}; ++i )); do
let CPUIDLETRANS[$i]-=${CI0[$i]}
done
fi
SUM=0
for CS in ${CPUIDLETRANS[*]}; do
let SUM+=$CS
done
CS=0
for CSTATE in $CPU/cpuidle/state*; do
printf " %1s %4.1f%%" $(cat $CSTATE/disable) $(echo "scale=1; 100.0*${CPUIDLETRANS[$CS]}/$SUM" | bc)
let CS+=1
done
fi
printf "\n"
done
echo
echo "CPU frequency scaling, idle, and boost (/sys/devices/system/cpu/{cpuidle,cpufreq}):"
CPU_FREQ="no"
if test -r /sys/devices/system/cpu/cpu0/cpufreq/scaling_driver; then
CPU_FREQ="$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_driver)"
fi
CPU_IDLE="no"
if test -r /sys/devices/system/cpu/cpuidle/current_driver; then
CPU_IDLE="$(cat /sys/devices/system/cpu/cpuidle/current_driver)"
fi
CPU_BOOST="no"
if test -r /sys/devices/system/cpu/cpufreq/boost; then
CPU_BOOST="$(cat /sys/devices/system/cpu/cpufreq/boost)"
fi
echo " scaling driver : $CPU_FREQ"
echo " cpuidle driver : $CPU_IDLE"
echo " boost : $CPU_BOOST"
echo
echo "CPU core temperatures (sensors):"
if sensors &> /dev/null; then
if test "$(sensors | grep Core | wc -l)" -ge 1; then
sensors | grep Core | indent
else
sensors | grep temp | indent
fi
echo
else
echo " sensors not available or appropriate kernel module missing - check sensors and sensors-detect manually."
echo
fi
MAXCPUFREQ="n.a."
test -r $CPU/cpufreq/cpuinfo_max_freq && MAXCPUFREQ=$(echo "scale=3;" $(cat $CPU/cpufreq/cpuinfo_max_freq)/1000000.0 | bc)
test -r $CPU/cpufreq/scaling_max_freq && MAXCPUFREQ=$(echo "scale=3;" $(cat $CPU/cpufreq/scaling_max_freq)/1000000.0 | bc)
echo "CPU (/proc/cpuinfo):"
echo " $(grep "model name" /proc/cpuinfo | awk -F '\t:[ ]*' 'NR==1 { printf "%-17s : %s", $1, $2}')"
echo " number of CPUs : $CPU_NO"
test "MAXCPUFREQ" != "n.a." && echo " max CPU frequency : $MAXCPUFREQ GHz"
echo " CPU family : $(grep "cpu family" /proc/cpuinfo | awk 'NR==1 { print $4}')"
echo " machine (uname -m): $MACHINE"
echo " memory (free -h) : $(free -h | grep Mem | awk '{print $2}') RAM"
echo
}
function print_distribution {
if lsb_release &> /dev/null; then
echo "Distribution (lsb_release -a):"
lsb_release -a 2> /dev/null | awk -F ':[ \t]*' '{printf("%-15s: %s\n", $1, $2)}' | indent
else
echo "Distribution: unknown"
fi
echo
}
function print_settings {
echo "Settings of ${VERSION_STRING}:"
echo " KERNEL_PATH (-s) = $KERNEL_PATH"
echo " LINUX_KERNEL (-k) = $LINUX_KERNEL"
echo " KERNEL_SOURCE_NAME = $KERNEL_SOURCE_NAME"
echo " KERNEL_NUM (-n) = $KERNEL_NUM"
echo " KERNEL_CONFIG (-c) = $KERNEL_CONFIG"
echo " KERNEL_MENU = $KERNEL_MENU"
echo " RUN_LOCALMOD (-l) = $RUN_LOCALMOD"
echo " KERNEL_PARAM = $KERNEL_PARAM"
echo " KERNEL_PARAM_DESCR = $KERNEL_PARAM_DESCR"
echo " BATCH_KERNEL_PARAM = $BATCH_KERNEL_PARAM"
echo " KERNEL_CONFIG_BACKUP = $KERNEL_CONFIG_BACKUP"
echo " TEST_TIME_DEFAULT = $TEST_TIME_DEFAULT"
echo " STARTUP_TIME = $STARTUP_TIME"
echo " COMPILE_TIME = $COMPILE_TIME"
echo " LOCAL_SRC_PATH = $LOCAL_SRC_PATH"
echo " RTAI_DIR (-r) = $RTAI_DIR"
echo " RTAI_PATCH (-p) = $RTAI_PATCH"
echo " RTAI_MENU (-m) = $RTAI_MENU"
echo " RTAI_HAL_PARAM = $RTAI_HAL_PARAM"
echo " RTAI_SCHED_PARAM = $RTAI_SCHED_PARAM"
echo " SHOWROOM_DIR = $SHOWROOM_DIR"
echo " NEWLIB_TAR = $NEWLIB_TAR"
echo " MUSL_TAR = $MUSL_TAR"
echo " MAKE_NEWLIB = $MAKE_NEWLIB"
echo " MAKE_MUSL = $MAKE_MUSL"
echo " MAKE_RTAI = $MAKE_RTAI"
echo " MAKE_COMEDI = $MAKE_COMEDI"
echo
}
function print_config {
cat <<EOF
# settings for ${MAKE_RTAI_KERNEL}:
# Path for the kernel archive and sources:
KERNEL_PATH="$KERNEL_PATH"
# Version of linux kernel:
LINUX_KERNEL="$LINUX_KERNEL"
# Name for kernel source directory to be appended to LINUX_KERNEL:
KERNEL_SOURCE_NAME="$KERNEL_SOURCE_NAME"
# Name for RTAI patched linux kernel to be appended to kernel and RTAI version:
KERNEL_NUM="$KERNEL_NUM"
# The kernel configuration to be used:
# "old" for oldconfig from the running (or already configured kernel) kernel,
# "def" for the defconfig target,
# "mod" for the localmodconfig target, (even if kernel versions do not match)
# "backup" for the backed up kernel configuration from the last test batch.
# or a full path to a config file.
KERNEL_CONFIG="$KERNEL_CONFIG"
# Menu for editing the kernel configuration (menuconfig, gconfig, xconfig):
KERNEL_MENU="$KERNEL_MENU"
# Run localmodconfig on the kernel configuration to deselect
# all kernel modules that are not currently used.
RUN_LOCALMOD=$RUN_LOCALMOD
# Default kernel parameter to be used when booting into the RTAI patched kernel:
KERNEL_PARAM="$KERNEL_PARAM"
# One-word description of the KERNEL_PARAM that is added to the test description:
KERNEL_PARAM_DESCR="$KERNEL_PARAM_DESCR"
# Kernel parameter to be added when running test batches:
BATCH_KERNEL_PARAM="$BATCH_KERNEL_PARAM"