编辑:现在有一个未解决的错误这。
编辑2:此问题的解决方法是使用chrt
下面指出的方法。
编辑3:现在已通过 v252 修复此问题https://github.com/systemd/systemd/commit/40c05a34595ed769ce676206f3c5de874f9a9234
在嵌入式系统上运行带有 PREEMT_RT 补丁的 5.4.91 的 debian buster。systemd
版本是247。
尝试将进程设置为实时优先级。我无法从 systemd.service 单元本地设置进程的实时优先级。
那里有几个链接,其中一个标题很恰当我的服务无法实时!这似乎指向正确的方向,但我无法让它发挥作用。
这是我的服务文件中的内容:
[Service]
RestrictRealtime=false
LimitRTPRIO=infinity
CPUSchedulingPriority=99
CPUSchedulingPolicy=rr
IOSchedulingClass=realtime
IOSchedulingPriority=3
ExecStart=/usr/bin/local/foo.bar
Type=notify
....
令人烦恼的是,如果我设置
[Service]
LimitRTPRIO=infinity
ExecStart=/usr/bin/chrt --rr 99 /usr/bin/local/foo.bar
我得到了想要的结果 - 即使对于非 root 用户也是如此。
为什么 systemd 本身不允许我这样做?
编辑systemctl show
:按要求转储:
Type=notify
Restart=always
NotifyAccess=main
RestartUSec=3s
TimeoutStartUSec=3s
TimeoutStopUSec=2s
TimeoutAbortUSec=2s
TimeoutStartFailureMode=terminate
TimeoutStopFailureMode=terminate
RuntimeMaxUSec=infinity
WatchdogUSec=3s
WatchdogTimestamp=Thu 2021-01-28 18:42:01 UTC
WatchdogTimestampMonotonic=426381837441
RootDirectoryStartOnly=no
RemainAfterExit=no
GuessMainPID=yes
MainPID=4758
ControlPID=0
FileDescriptorStoreMax=0
NFileDescriptorStore=0
StatusErrno=0
Result=success
ReloadResult=success
CleanResult=success
UID=107
GID=113
NRestarts=0
OOMPolicy=stop
ExecMainStartTimestamp=Thu 2021-01-28 18:40:40 UTC
ExecMainStartTimestampMonotonic=426300331189
ExecMainExitTimestampMonotonic=0
ExecMainPID=4758
ExecMainCode=0
ExecMainStatus=0
ExecStart={ path=/usr/local/bin/foo.bar ; argv[]=/usr/local/bin/foo.bar --daemonize ; ignore_errors=no ; start_time=[Thu 2021-01-28 18:40:40 UTC] ; stop_time=[n/a] ; pid=4758 ; code=(null) ; status=0/0 }
ExecStartEx={ path=/usr/local/bin/foo.bar; argv[]=/usr/local/bin/foo.bar --daemonize ; flags= ; start_time=[Thu 2021-01-28 18:40:40 UTC] ; stop_time=[n/a] ; pid=4758 ; code=(null) ; status=0/0 }
ExecReload={ path=/bin/kill ; argv[]=/bin/kill -HUP $MAINPID ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }
ExecReloadEx={ path=/bin/kill ; argv[]=/bin/kill -HUP $MAINPID ; flags= ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }
Slice=system.slice
ControlGroup=/system.slice/foo.bar.service
MemoryCurrent=1081344
CPUUsageNSec=6725421000
EffectiveCPUs=
EffectiveMemoryNodes=
TasksCurrent=5
IPIngressBytes=[no data]
IPIngressPackets=[no data]
IPEgressBytes=[no data]
IPEgressPackets=[no data]
IOReadBytes=18446744073709551615
IOReadOperations=18446744073709551615
IOWriteBytes=18446744073709551615
IOWriteOperations=18446744073709551615
Delegate=no
CPUAccounting=yes
CPUWeight=[not set]
StartupCPUWeight=[not set]
CPUShares=[not set]
StartupCPUShares=[not set]
CPUQuotaPerSecUSec=infinity
CPUQuotaPeriodUSec=infinity
AllowedCPUs=
AllowedMemoryNodes=
IOAccounting=no
IOWeight=[not set]
StartupIOWeight=[not set]
BlockIOAccounting=no
BlockIOWeight=[not set]
StartupBlockIOWeight=[not set]
MemoryAccounting=yes
DefaultMemoryLow=0
DefaultMemoryMin=0
MemoryMin=0
MemoryLow=0
MemoryHigh=infinity
MemoryMax=infinity
MemorySwapMax=infinity
MemoryLimit=infinity
DevicePolicy=auto
TasksAccounting=yes
TasksMax=1061
IPAccounting=no
ManagedOOMSwap=auto
ManagedOOMMemoryPressure=auto
ManagedOOMMemoryPressureLimitPercent=0%
Environment=PATH=/usr/local/bin:/usr/bin:/bin
EnvironmentFiles=/etc/environment (ignore_errors=no)
UMask=0022
LimitCPU=infinity
LimitCPUSoft=infinity
LimitFSIZE=infinity
LimitFSIZESoft=infinity
LimitDATA=infinity
LimitDATASoft=infinity
LimitSTACK=infinity
LimitSTACKSoft=8388608
LimitCORE=infinity
LimitCORESoft=0
LimitRSS=infinity
LimitRSSSoft=infinity
LimitNOFILE=524288
LimitNOFILESoft=1024
LimitAS=infinity
LimitASSoft=infinity
LimitNPROC=3539
LimitNPROCSoft=3539
LimitMEMLOCK=65536
LimitMEMLOCKSoft=65536
LimitLOCKS=infinity
LimitLOCKSSoft=infinity
LimitSIGPENDING=3539
LimitSIGPENDINGSoft=3539
LimitMSGQUEUE=819200
LimitMSGQUEUESoft=819200
LimitNICE=0
LimitNICESoft=0
LimitRTPRIO=infinity
LimitRTPRIOSoft=infinity
LimitRTTIME=infinity
LimitRTTIMESoft=infinity
WorkingDirectory=/opt/foo
RootHashSignature=
OOMScoreAdjust=0
CoredumpFilter=0x33
Nice=0
IOSchedulingClass=1
IOSchedulingPriority=3
CPUSchedulingPolicy=0
CPUSchedulingPriority=0
CPUAffinity=
CPUAffinityFromNUMA=no
NUMAPolicy=n/a
NUMAMask=
TimerSlackNSec=50000
CPUSchedulingResetOnFork=no
NonBlocking=no
StandardInput=null
StandardInputData=
StandardOutput=journal
StandardError=journal
TTYReset=no
TTYVHangup=no
TTYVTDisallocate=no
SyslogPriority=30
SyslogLevelPrefix=yes
SyslogLevel=6
SyslogFacility=3
LogLevelMax=-1
LogRateLimitIntervalUSec=0
LogRateLimitBurst=0
SecureBits=0
CapabilityBoundingSet=cap_chown cap_dac_override cap_dac_read_search cap_fowner cap_fsetid cap_kill cap_setgid cap_setuid cap_setpcap cap_linux_immutable cap_net_bind_service cap_net_broadcast cap_net_admin cap_net_raw cap_ipc_lock cap_ipc_owner cap_sys_module cap_sys_rawio cap_sys_chroot cap_sys_ptrace cap_sys_pacct cap_sys_admin cap_sys_boot cap_sys_nice cap_sys_resource cap_sys_time cap_sys_tty_config cap_mknod cap_lease cap_audit_write cap_audit_control cap_setfcap
AmbientCapabilities=
User=foo
Group=foo
DynamicUser=no
RemoveIPC=no
MountFlags=
PrivateTmp=yes
PrivateDevices=no
ProtectClock=no
ProtectKernelTunables=no
ProtectKernelModules=no
ProtectKernelLogs=no
ProtectControlGroups=no
PrivateNetwork=no
PrivateUsers=no
PrivateMounts=no
ProtectHome=read-only
ProtectSystem=full
SameProcessGroup=no
UtmpMode=init
IgnoreSIGPIPE=yes
NoNewPrivileges=no
SystemCallErrorNumber=2147483646
LockPersonality=no
RuntimeDirectoryPreserve=no
RuntimeDirectoryMode=0755
RuntimeDirectory=foo
StateDirectoryMode=0755
CacheDirectoryMode=0755
LogsDirectoryMode=0755
LogsDirectory=foo
ConfigurationDirectoryMode=0755
TimeoutCleanUSec=infinity
MemoryDenyWriteExecute=no
RestrictRealtime=no
RestrictSUIDSGID=no
RestrictNamespaces=no
MountAPIVFS=no
KeyringMode=private
ProtectProc=default
ProcSubset=all
ProtectHostname=no
KillMode=mixed
KillSignal=15
RestartKillSignal=15
FinalKillSignal=9
SendSIGKILL=yes
SendSIGHUP=no
WatchdogSignal=6
Id=foo.bar.service
Names=foo.bar.service
Requires=sysinit.target var.mount system.slice -.mount tmp.mount
PartOf=foo.service
Conflicts=shutdown.target
Before=shutdown.target
After=systemd-journald.socket sysinit.target var.mount -.mount systemd-remount-fs.service tmp.mount sys-subsystem-net-devices-can1.device systemd-tmpfiles-setup.service sys-subsystem-net-devices-eth0.2.device system.slice basic.target
RequiresMountsFor=/run/foo /var/log/foo /opt/foo /tmp /var/tmp
Description=foo bar
LoadState=loaded
ActiveState=active
FreezerState=running
SubState=running
FragmentPath=/lib/systemd/system/foo.bar.service
UnitFileState=disabled
UnitFilePreset=enabled
StateChangeTimestamp=Thu 2021-01-28 18:40:40 UTC
StateChangeTimestampMonotonic=426300816780
InactiveExitTimestamp=Thu 2021-01-28 18:40:40 UTC
InactiveExitTimestampMonotonic=426300357891
ActiveEnterTimestamp=Thu 2021-01-28 18:40:40 UTC
ActiveEnterTimestampMonotonic=426300816780
ActiveExitTimestamp=Thu 2021-01-28 18:40:39 UTC
ActiveExitTimestampMonotonic=426300199732
InactiveEnterTimestamp=Thu 2021-01-28 18:40:40 UTC
InactiveEnterTimestampMonotonic=426300244778
CanStart=yes
CanStop=yes
CanReload=yes
CanIsolate=no
CanClean=runtime logs
CanFreeze=yes
StopWhenUnneeded=no
RefuseManualStart=no
RefuseManualStop=no
AllowIsolate=no
DefaultDependencies=yes
OnFailureJobMode=replace
IgnoreOnIsolate=no
NeedDaemonReload=no
JobTimeoutUSec=infinity
JobRunningTimeoutUSec=infinity
JobTimeoutAction=none
ConditionResult=yes
AssertResult=yes
ConditionTimestamp=Thu 2021-01-28 18:40:40 UTC
ConditionTimestampMonotonic=426300306353
AssertTimestamp=Thu 2021-01-28 18:40:40 UTC
AssertTimestampMonotonic=426300306377
Transient=no
Perpetual=no
StartLimitIntervalUSec=1s
StartLimitBurst=3
StartLimitAction=none
FailureAction=none
SuccessAction=none
InvocationID=3250e79f3cdc43268f1de989ad58b14b
CollectMode=inactive