-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added systemd support to rpi3-ondemand-cpufreq #36
Open
Hecatron
wants to merge
4
commits into
sakaki-:master
Choose a base branch
from
Hecatron-Forks:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/bash | ||
# Copyright (c) 2018 sakaki <sakaki@deciban.com> | ||
# License: GPL v3+ | ||
# NO WARRANTY | ||
|
||
#description="Work around RPi3B+ Ethernet performance issues" | ||
#depend() { | ||
# after net | ||
#} | ||
|
||
# Gentoo functions for ebegin etc | ||
source /lib/gentoo/functions.sh | ||
|
||
_tweak_eth0_if_necessary() { | ||
# check if we are running on an RPi3B+, and, if so, attempt to | ||
# address some Ethernet stability concerns | ||
if grep -q "Raspberry Pi 3 Model B Plus" /proc/device-tree/model; then | ||
# may fix some Samba issues, see e.g. | ||
# https://www.raspberrypi.org/forums/viewtopic.php?p=1324321#p1324321 | ||
ewarn "RPi3 model B+ detected" | ||
ewarn "Turning off eth0 offloading, for stability" | ||
ethtool --offload eth0 rx off tx off | ||
# per https://www.raspberrypi.org/forums/viewtopic.php?p=1294790#p1294790 | ||
# we could also do this: | ||
# ethtool -s eth0 speed 100 duplex full autoneg on | ||
# but hold off on that for now | ||
fi | ||
|
||
return 0 | ||
} | ||
|
||
start() { | ||
ebegin "Starting ${SVCNAME}" | ||
_tweak_eth0_if_necessary | ||
return $? | ||
} | ||
|
||
case "$1" in | ||
|
||
start) | ||
start | ||
eend $? | ||
;; | ||
|
||
*) | ||
einfo "Usage: $0 {start}" | ||
eend 1 | ||
;; | ||
|
||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[Unit] | ||
Description=Work around RPi3B+ Ethernet performance issues | ||
After=network.target | ||
|
||
[Service] | ||
ExecStart=/usr/lib/rpi-scripts/bin/rpi3-ethfix start | ||
Type=oneshot | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright (c) 2018 sakaki <sakaki@deciban.com> | ||
# License: GPL v3+ | ||
# NO WARRANTY | ||
|
||
EAPI=6 | ||
inherit systemd | ||
|
||
KEYWORDS="~arm64" | ||
|
||
DESCRIPTION="Turn off display compositing for high RPi3 pixel clock values" | ||
HOMEPAGE="https://github.com/sakaki-/gentoo-on-rpi3-64bit" | ||
SRC_URI="" | ||
LICENSE="GPL-3+" | ||
SLOT="0" | ||
IUSE="systemd" | ||
RESTRICT="mirror" | ||
|
||
# required by Portage, as we have no SRC_URI... | ||
S="${WORKDIR}" | ||
|
||
DEPEND="" | ||
RDEPEND="${DEPEND} | ||
>=sys-apps/ethtool-4.16 | ||
systemd? ( >=sys-apps/systemd-242-r6 ) | ||
!systemd? ( >=sys-apps/openrc-0.41 ) | ||
>=app-shells/bash-4.0" | ||
|
||
src_install() { | ||
newinitd "${FILESDIR}/init.d_${PN}-2" "${PN}" | ||
systemd_dounit "${FILESDIR}/1.0.1/rpi3-ethfix.service" | ||
|
||
dodir "/usr/lib/rpi-scripts/bin" | ||
into "/usr/lib/rpi-scripts" | ||
dobin "${FILESDIR}/1.0.1/rpi3-ethfix" | ||
} | ||
|
||
pkg_postinst() { | ||
if use systemd; then | ||
systemctl daemon-reload | ||
systemctl enable "${PN}.service" | ||
else | ||
rc-update add "${PN}" default | ||
fi | ||
elog "The ${PN} service has been added to your default runlevel." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/bin/bash | ||
# Start up integrated bluetooth on Raspberry Pi 3 | ||
# Adapted from https://aur.archlinux.org/packages/pi-bluetooth/ | ||
# Copyright (c) 2017 sakaki <sakaki@deciban.com> | ||
# License: GPL v3+ | ||
# NO WARRANTY | ||
|
||
# Gentoo functions for ebegin etc | ||
source /lib/gentoo/functions.sh | ||
|
||
# only match on common part of attach command | ||
HCMD="/usr/bin/hciattach /dev/ttyAMA0 bcm43xx" | ||
|
||
start() { | ||
ebegin "Starting ${SVCNAME}" | ||
if ! [ -d /proc/device-tree/soc/gpio@7e200000/bt_pins ]; then | ||
eend 1 "Bluetooth not found" | ||
return 1 | ||
fi | ||
declare -i I | ||
# attach process is unreliable, so we do it this way | ||
# rather than via start-stop-daemon | ||
nohup /usr/sbin/rpi3-attach-bluetooth &>/dev/null& | ||
return $? | ||
} | ||
|
||
stop() { | ||
ebegin "Shutting down ${SVCNAME}" | ||
pkill -f "${HCMD}" | ||
return $? | ||
} | ||
|
||
|
||
case "$1" in | ||
|
||
start) | ||
start | ||
eend $? | ||
;; | ||
|
||
stop) | ||
stop | ||
eend $? | ||
;; | ||
|
||
*) | ||
einfo "Usage: $0 {start,stop}" | ||
eend 1 | ||
;; | ||
|
||
esac |
11 changes: 11 additions & 0 deletions
11
net-wireless/rpi3-bluetooth/files/1.2/rpi3-bluetooth.service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[Unit] | ||
Description=Starts up integrated bluetooth on the RPi3" | ||
After=bluetooth.service | ||
|
||
[Service] | ||
ExecStart=/usr/lib/rpi-scripts/bin/rpi3-bluetooth start | ||
ExecStop=/usr/lib/rpi-scripts/bin/rpi3-bluetooth stop | ||
Type=forking | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Copyright (c) 2017 sakaki <sakaki@deciban.com> | ||
# License: GPL v3+ | ||
# NO WARRANTY | ||
|
||
EAPI=6 | ||
inherit git-r3 systemd | ||
|
||
KEYWORDS="~arm ~arm64" | ||
|
||
DESCRIPTION="Service and udev rule for integrated bluetooth on the Raspberry Pi 3" | ||
HOMEPAGE="https://aur.archlinux.org/packages/pi-bluetooth/" | ||
SRC_URI="" | ||
LICENSE="GPL-3+" | ||
SLOT="0" | ||
IUSE="systemd" | ||
RESTRICT="mirror" | ||
|
||
EGIT_REPO_URI="https://aur.archlinux.org/pi-bluetooth.git" | ||
EGIT_BRANCH="master" | ||
# following is commit for release 1-1 of the archlinux pi-bluetooth package | ||
EGIT_COMMIT="a439f892bf549ddfefa9ba7ad1999cc515f233bf" | ||
|
||
DEPEND="" | ||
RDEPEND=" | ||
${DEPEND} | ||
~sys-firmware/bcm4340a1-firmware-1.1 | ||
systemd? ( >=sys-apps/systemd-242-r6 ) | ||
!systemd? ( >=sys-apps/openrc-0.41 ) | ||
|| ( ~net-wireless/bluez-5.43 | ||
>=net-wireless/bluez-5.44[deprecated] ) | ||
>=virtual/udev-215 | ||
>=app-shells/bash-4.0" | ||
|
||
src_prepare() { | ||
sed -i -e "s#/bin#/usr/bin#g" 50-bluetooth-hci-auto-poweron.rules | ||
default | ||
} | ||
|
||
src_install() { | ||
insinto "/lib/udev/rules.d" | ||
doins 50-bluetooth-hci-auto-poweron.rules | ||
newinitd "${FILESDIR}/init.d_${PN}-5" "${PN}" | ||
systemd_dounit "${FILESDIR}/1.2/rpi3-bluetooth.service" | ||
newsbin "${FILESDIR}/rpi3-attach-bluetooth-3" "rpi3-attach-bluetooth" | ||
|
||
dodir "/usr/lib/rpi-scripts/bin" | ||
into "/usr/lib/rpi-scripts" | ||
dobin "${FILESDIR}/1.2/rpi3-bluetooth" | ||
} | ||
|
||
pkg_postinst() { | ||
elog "To start the service and enable on bootup" | ||
if use systemd; then | ||
elog " systemctl daemon-reload" | ||
elog " systemctl start ${PN}.service" | ||
elog " systemctl enable ${PN}.service" | ||
else | ||
elog " /etc/init.d/${PN} start " | ||
elog " rc-update add ${PN} sysinit " | ||
fi | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/bash | ||
# Set on-demand frequency scaling in early boot | ||
# Copyright (c) 2017 sakaki <sakaki@deciban.com> | ||
# License: GPL v3+ | ||
# NO WARRANTY | ||
|
||
# Gentoo functions for ebegin etc | ||
source /lib/gentoo/functions.sh | ||
|
||
SCPU=/sys/devices/system/cpu | ||
SCPU_GOV=${SCPU}/cpu0/cpufreq/scaling_governor | ||
SCPU_OD=${SCPU}/cpufreq/ondemand | ||
|
||
_activate_ondemand() { | ||
if [ -e "${SCPU_GOV}" ]; then | ||
echo "ondemand" > "${SCPU_GOV}" | ||
echo 50 > ${SCPU_OD}/up_threshold | ||
echo 100000 > ${SCPU_OD}/sampling_rate | ||
echo 50 > ${SCPU_OD}/sampling_down_factor | ||
echo 1 > ${SCPU_OD}/io_is_busy | ||
einfo "On-demand CPU frequency scaling is active" | ||
return 0 | ||
else | ||
eerror "Unable to set on-demand CPU frequency scaling!" | ||
return 1 | ||
fi | ||
} | ||
|
||
|
||
case "$1" in | ||
|
||
start) | ||
_activate_ondemand | ||
eend $? | ||
;; | ||
|
||
*) | ||
einfo "Usage: $0 {start}" | ||
eend 1 | ||
;; | ||
|
||
esac |
10 changes: 10 additions & 0 deletions
10
sys-apps/rpi3-ondemand-cpufreq/files/1.1.2/rpi3-ondemand-cpufreq.service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[Unit] | ||
Description=Switches RPi3 to on-demand CPU frequency scaling | ||
After=local-fs.target | ||
|
||
[Service] | ||
ExecStart=/usr/lib/rpi-scripts/bin/rpi3-ondemand start | ||
Type=oneshot | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
46 changes: 46 additions & 0 deletions
46
sys-apps/rpi3-ondemand-cpufreq/rpi3-ondemand-cpufreq-1.1.2.ebuild
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Copyright (c) 2017 sakaki <sakaki@deciban.com> | ||
# License: GPL v3+ | ||
# NO WARRANTY | ||
|
||
EAPI=7 | ||
inherit systemd | ||
|
||
KEYWORDS="~arm ~arm64" | ||
|
||
DESCRIPTION="Startup script to enable on-demand CPU frequency scaling on RPi3" | ||
HOMEPAGE="https://github.com/sakaki-/gentoo-on-rpi3-64bit" | ||
SRC_URI="" | ||
LICENSE="GPL-3+" | ||
SLOT="0" | ||
IUSE="systemd" | ||
RESTRICT="mirror" | ||
|
||
# required by Portage, as we have no SRC_URI... | ||
S="${WORKDIR}" | ||
|
||
DEPEND="" | ||
RDEPEND="${DEPEND} | ||
systemd? ( >=sys-apps/systemd-242-r6 ) | ||
!systemd? ( >=sys-apps/openrc-0.41 ) | ||
>=app-shells/bash-4.0" | ||
|
||
src_install() { | ||
newinitd "${FILESDIR}/init.d_rpi3-ondemand-2" "rpi3-ondemand" | ||
systemd_dounit "${FILESDIR}/1.1.2/rpi3-ondemand-cpufreq.service" | ||
dodir "/usr/lib/rpi-scripts/bin" | ||
into "/usr/lib/rpi-scripts" | ||
dobin "${FILESDIR}/1.1.2/rpi3-ondemand" | ||
} | ||
|
||
pkg_postinst() { | ||
elog "To start the service and enable on bootup" | ||
if use systemd; then | ||
elog " systemctl daemon-reload" | ||
elog " systemctl start ${PN}.service" | ||
elog " systemctl enable ${PN}.service" | ||
else | ||
elog " /etc/init.d/rpi3-ondemand start " | ||
elog " rc-update add rpi3-ondemand sysinit " | ||
fi | ||
elog "to enable on-demand CPU frequency scaling" | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend against using the "Type=forking" model of systemd services.
Specifically in this service the only reason to use "forking" is because the actual service is started by "nohup".
Instead of calling the rpi3-bluetooth script, just call /usr/sbin/rpi3-attach-bluetooth directly.
Systemd also directly supports requiring specific paths to exist in sysfs or proc before starting a service, so you can prevent this service from starting if /proc/device-tree/soc/gpio@7e200000/bt_pins isn't found.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Part of the reason I did it that way was so that the same script could be used from openrc or systemd.
The idea being that it would be more likely to be accepted if it could be more easily maintained.