Lines Matching +full:monitor +full:- +full:script +full:- +full:pid
13 # This is an utility script to manage Intel GPU frequencies.
24 # - gt_max_freq_mhz (enforced maximum freq)
25 # - gt_min_freq_mhz (enforced minimum freq)
26 # - gt_boost_freq_mhz (enforced boost freq)
30 # - gt_RP0_freq_mhz (supported maximum freq)
31 # - gt_RPn_freq_mhz (supported minimum freq)
32 # - gt_RP1_freq_mhz (most efficient freq)
35 # - gt_act_freq_mhz (the actual GPU freq)
36 # - gt_cur_freq_mhz (the last requested freq)
38 # Also note that in addition to GPU management, the script offers the
46 # SPDX-License-Identifier: MIT
59 THROTT_DETECT_PID_FILE_PATH=/tmp/thrott-detect.pid
99 printf ${DRM_FREQ_SYSFS_PATTERN} "${2:-${INTEL_DRM_CARD_INDEX}}" "$1"
108 while [ ${i} -lt 16 ]; do
109 [ -c "/dev/dri/card$i" ] || {
117 [ -r "${path}" ] && read vendor < "${path}" && \
139 while [ $# -gt 0 ]; do
145 [ -r ${path} ] && read ${var} < ${path} || {
151 [ -n "${var}" ] || {
157 [ ${print} -eq 1 ] && {
172 [ -n "${GET_CAP_FREQ}" ] && {
178 [ -n "${GET_ENF_FREQ}" ] && {
184 [ -n "${GET_ACT_FREQ}" ] && {
192 # Helper to print frequency value as requested by user via '-s, --set' option.
202 -)
210 *[!0-9]*)
235 [ ${SET_MAX_FREQ} -gt ${FREQ_RP0} ] && {
241 [ ${SET_MAX_FREQ} -lt ${FREQ_RPn} ] && {
247 [ ${SET_MAX_FREQ} -lt ${FREQ_min} ] && {
253 [ -z "${DRY_RUN}" ] || return 0
271 [ ${SET_MIN_FREQ} -gt ${FREQ_max} ] && {
277 [ ${SET_MIN_FREQ} -lt ${FREQ_RPn} ] && {
283 [ -z "${DRY_RUN}" ] || return 0
299 [ -z "${SET_MAX_FREQ}" ] || {
301 [ -z "${SET_MAX_FREQ}" ] && return 1
304 [ -z "${SET_MIN_FREQ}" ] || {
306 [ -z "${SET_MIN_FREQ}" ] && return 1
320 if [ -n "${SET_MAX_FREQ}" ] && [ -n "${SET_MIN_FREQ}" ]; then
321 [ ${SET_MAX_FREQ} -lt ${SET_MIN_FREQ} ] && {
328 if [ ${SET_MAX_FREQ} -lt ${FREQ_min} ]; then
335 elif [ -n "${SET_MAX_FREQ}" ]; then
337 elif [ -n "${SET_MIN_FREQ}" ]; then
349 [ -e ${THROTT_DETECT_PID_FILE_PATH} ] || return 0
351 local pid
352 read pid < ${THROTT_DETECT_PID_FILE_PATH} || {
353 log ERROR "Failed to read pid from: %s" "${THROTT_DETECT_PID_FILE_PATH}"
357 local proc_path=/proc/${pid:-invalid}/cmdline
358 [ -r ${proc_path} ] && grep -qs "${0##*/}" ${proc_path} && {
359 printf "%s" "${pid}"
363 # Remove orphaned PID file
364 rm -rf ${THROTT_DETECT_PID_FILE_PATH}
370 # arg1: start - run throttle detector in background
371 # stop - stop throttle detector process, if any
372 # status - verify if throttle detector is running
375 local pid
376 pid=$(get_thrott_detect_pid)
381 [ -z "${pid}" ] && printf "not running\n" && return 0
382 printf "running (pid=%s)\n" ${pid}
386 [ -z "${pid}" ] && return 0
388 log INFO "Stopping throttling detector (pid=%s)" "${pid}"
389 kill ${pid}; sleep 1; kill -0 ${pid} 2>/dev/null && kill -9 ${pid}
390 rm -rf ${THROTT_DETECT_PID_FILE_PATH}
394 [ -n "${pid}" ] && {
395 log WARN "Throttling detector is already running (pid=%s)" ${pid}
411 [ ${FREQ_act} -lt ${FREQ_min} ] && \
412 [ ${FREQ_act} -gt ${FREQ_RPn} ] && \
413 [ ${FREQ_cur} -ge ${FREQ_min} ] && \
419 pid=$!
420 log INFO "Started GPU throttling detector (pid=%s)" ${pid}
422 printf "%s\n" ${pid} > ${THROTT_DETECT_PID_FILE_PATH} || \
423 log WARN "Failed to write throttle detector PID file"
466 while [ $# -gt 0 ]; do
472 [ -r ${path} ] && read ${var} < ${path} || {
478 [ -n "${var}" ] || {
484 [ ${print} -eq 1 ] && {
494 # Helper to print freq. value as requested by user via '--cpu-set-max' option.
504 -)
510 *[!0-9]*)
519 log ERROR "Cannot set CPU freq to custom value; use +, -, or % instead"
536 -)
549 [ -e "${pstate_info}" ] && {
564 [ -z "${target_freq}" ] && { res=$tf_res; continue; }
567 [ -n "${DRY_RUN}" ] && continue
586 A script to manage Intel GPU frequencies. Can be used for debugging performance
592 -g, --get [act|enf|cap|all]
596 -s, --set [{min|max}=]{FREQUENCY[%]|+|-}
599 Use '+' or '-' to set frequency to hardware max or min.
602 -r, --reset Reset frequencies to hardware defaults.
604 -m, --monitor [act|enf|cap|all]
605 Monitor the indicated frequencies via 'watch' utility.
606 See '-g, --get' option for more details.
608 -d|--detect-thrott [start|stop|status]
613 --cpu-set-max [FREQUENCY%|+|-}
615 Use '+' or '-' to set frequency to hardware max or min.
617 -r, --reset Reset frequencies to hardware defaults.
619 --dry-run See what the script will do without applying any
622 -h, --help Display this help text and exit.
627 # Parse user input for '-g, --get' option.
638 -*|"")
653 # Validate user input for '-s, --set' option.
659 +|-|[0-9]%|[0-9][0-9]%)
662 *[!0-9]*|"")
668 [ -z "$2" ] || { print_usage; exit 1; }
672 # Parse script arguments.
674 [ $# -eq 0 ] && { print_usage; exit 1; }
676 while [ $# -gt 0 ]; do
678 -g|--get)
682 -s|--set)
701 -r|--reset)
703 SET_MIN_FREQ="-"
707 -m|--monitor)
712 -d|--detect-thrott)
722 --cpu-set-max)
728 --dry-run)
732 -h|--help)
756 [ -n "${SET_MIN_FREQ}${SET_MAX_FREQ}" ] && { set_freq || RET=$?; }
759 [ -n "${DETECT_THROTT}" ] && detect_throttling ${DETECT_THROTT}
761 [ -n "${CPU_SET_MAX_FREQ}" ] && { set_cpu_freq_max || RET=$?; }
763 [ -n "${MONITOR_FREQ}" ] && {
766 exec watch -d -n 1 "$0" -g "${MONITOR_FREQ}"