Lines Matching +full:default +full:- +full:trigger

1 #!/bin/sh -eu
2 # SPDX-License-Identifier: GPL-2.0
6 # Copyright (C) Wolfram Sang <wsa@sang-engineering.com>
14 ladirname='gpio-sloppy-logic-analyzer'
29 $progname - helper script for the Linux Kernel Sloppy GPIO Logic Analyzer
31 -c|--cpu <n>: which CPU to isolate for sampling. Only needed once. Default <1>.
34 -d|--duration-us <SI-n>: number of microseconds to sample. Overrides -n, no default value.
35 -h|--help: print this help
36 -i|--instance <str>: name of the logic analyzer in case you have multiple instances. Default
38 -k|--kernel-debug-dir <str>: path to the kernel debugfs mountpoint. Default: <$debugdir>
39 -l|--list-instances: list all available instances
40 -n|--num_samples <SI-n>: number of samples to acquire. Default <$numsamples>
41 -o|--output-dir <str>: directory to put the result files. Default: current dir
42 -s|--sample_freq <SI-n>: desired sampling frequency. Might be capped if too large.
43 Default: <1000000>
44 -t|--trigger <str>: pattern to use as trigger. <str> consists of two-char pairs. First
45 char is channel number starting at "1". Second char is trigger level:
46 "L" - low; "H" - high; "R" - rising; "F" - falling
51 first trigger has been met.
52 Trigger data will only be used for the next capture and then be erased.
54 <SI-n> is an integer value where SI units "T", "G", "M", "K" are recognized, e.g. '1M500K' is 1500000.
61 '$progname -d 50 -s 2M -t "2F"'
63 Note that the process exits after checking all parameters but a sub-process still works in
64 the background. The result is only available once the sub-process finishes.
68 The filename is the logic analyzer instance name plus a since-epoch timestamp.
85 for f in $(find "$1" -iname "$2"); do echo "$newmask" > "$f" 2>/dev/null || true; done
92 [ -d "$lacpusetdir" ] || mkdir "$lacpusetdir"
96 [ -z "$cur_cpu" ] || fail "CPU$isol_cpu requested but CPU$cur_cpu already isolated"
109 for p in $(ps -o pid | tail -n +2); do
110 mask=$(taskset -p "$p") || continue
113 taskset -p "$newmask" "$p" || continue
116 # Big hammer! Working with 'rcu_momentary_eqs()' for a more fine-grained solution
117 # still printed warnings. Same for re-enabling the stall detector after sampling.
121 [ -w "$cpufreqgov" ] && echo 'performance' > "$cpufreqgov" || true
133 [ "$chan" != "$elem" ] && [ "$chan" -le $max_chans ] || fail "Trigger syntax error: $elem"
134 bit=$((1 << (chan - 1)))
143 [ $val1 -ne $val2 ] && trigger_bindat="$trigger_bindat$(printf '\\%o\\%o' $mask $val2)"
152 srtmp=$(mktemp -d)
154 cp "$lasysfsdir"/sample_data "$srtmp"/logic-1-1
160 capturefile=logic-1
161 total probes=$(wc -l < "$lasysfsdir"/meta_data)
167 zipname="$outputdir/${lasysfsdir##*/}-$(date +%s).sr"
168 zip -jq "$zipname" "$srtmp"/*
169 rm -rf "$srtmp"
171 [ "$delay_ack" -eq 0 ] && delay_ack=1
176 rep=$(getopt -a -l cpu:,duration-us:,help,instance:,list-instances,kernel-debug-dir:,num_samples:,output-dir:,sample_freq:,trigger: -o c:d:hi:k:ln:o:s:t: -- "$@") || exit 1
177 eval set -- "$rep"
180 -c|--cpu) initcpu="$2"; shift;;
181 -d|--duration-us) parse_si $2; duration=$si_val; shift;;
182 -h|--help) print_help; exit 0;;
183 -i|--instance) lainstance="$2"; shift;;
184 -k|--kernel-debug-dir) debugdir="$2"; shift;;
185 -l|--list-instances) listinstances=1;;
186 -n|--num_samples) parse_si $2; numsamples=$si_val; shift;;
187 -o|--output-dir) outputdir="$2"; shift;;
188 -s|--sample_freq) parse_si $2; samplefreq=$si_val; shift;;
189 -t|--trigger) triggerdat="$2"; shift;;
190 --) break;;
197 command -v "$f" >/dev/null || fail "Command '$f' not found"
202 if [ -z "$cpusetdir" ]; then
204 [ -d $cpusetdir ] || mkdir $cpusetdir
205 mount -t cgroup -o cpuset none $cpusetdir || fail "Couldn't mount cpusets. Not in kernel or already in use?"
212 [ "$samplefreq" -ne 0 ] || fail "Invalid sample frequency"
214 [ -d "$sysfsdir" ] || fail "Could not find logic analyzer root dir '$sysfsdir'. Module loaded?"
215 [ -x "$sysfsdir" ] || fail "Could not access logic analyzer root dir '$sysfsdir'. Need root?"
217 [ $listinstances -gt 0 ] && find "$sysfsdir" -mindepth 1 -type d | sed 's|.*/||' && exit 0
219 if [ -n "$lainstance" ]; then
222 lasysfsdir=$(find "$sysfsdir" -mindepth 1 -type d -print -quit)
224 [ -d "$lasysfsdir" ] || fail "Logic analyzer directory '$lasysfsdir' not found!"
225 [ -d "$outputdir" ] || fail "Output directory '$outputdir' not found!"
227 [ -n "$initcpu" ] && init_cpu "$initcpu"
228 [ -d "$lacpusetdir" ] || { echo "Auto-Isolating CPU1"; init_cpu 1; }
233 [ -n "$duration" ] && numsamples=$((samplefreq * duration / 1000000))
236 if [ -n "$triggerdat" ]; then
238 printf "$trigger_bindat" > "$lasysfsdir"/trigger 2>/dev/null || fail "Trigger data '$triggerdat' rejected"
242 [ -n "$workcpu" ] || fail "No isolated CPU found"
245 echo "Setting up '$instance': $numsamples samples at ${samplefreq}Hz with ${triggerdat:-no} trigger using CPU$workcpu"