Use systemd unit to create AMD uprof device
This commit is contained in:
@@ -22,23 +22,28 @@
|
|||||||
# Make the userspace tools available in $PATH.
|
# Make the userspace tools available in $PATH.
|
||||||
environment.systemPackages = with pkgs; [ amd-uprof ];
|
environment.systemPackages = with pkgs; [ amd-uprof ];
|
||||||
|
|
||||||
# Add extra udev rules to setup the /dev/AMDPowerProfiler device. They
|
# The AMDPowerProfiler module doesn't create the /dev device nor it emits
|
||||||
# forgot to add these.
|
# any uevents, so we cannot use udev rules to automatically create the
|
||||||
services.udev.extraRules = let
|
# device. Instead, we run a systemd unit that does it after loading the
|
||||||
# To create the device node we need to read the device number from the
|
# modules.
|
||||||
# /proc directory, so the module must have been loaded first.
|
systemd.services.amd-uprof-device = {
|
||||||
addDevice = pkgs.writeShellScript "add-amd-uprof-dev.sh" ''
|
description = "Create /dev/AMDPowerProfiler device";
|
||||||
set -x
|
after = [ "systemd-modules-load.service" ];
|
||||||
echo date > /tmp/uprof.log
|
wantedBy = [ "multi-user.target" ];
|
||||||
mknod /dev/AMDPowerProfiler -m 666 c $(< /proc/AMDPowerProfiler/device) 0
|
unitConfig.ConditionPathExists = [
|
||||||
'';
|
"/proc/AMDPowerProfiler/device"
|
||||||
removeDevice = pkgs.writeShellScript "remove-amd-uprof-dev.sh" ''
|
"!/dev/AMDPowerProfiler"
|
||||||
rm /dev/AMDPowerProfiler
|
];
|
||||||
'';
|
serviceConfig = {
|
||||||
in
|
Type = "oneshot";
|
||||||
''
|
RemainAfterExit = true;
|
||||||
KERNEL=="AMDPowerProfiler", SUBSYSTEM=="module", ACTION=="add", RUN+="${addDevice}"
|
ExecStart = pkgs.writeShellScript "add-amd-uprof-dev.sh" ''
|
||||||
KERNEL=="AMDPowerProfiler", SUBSYSTEM=="module", ACTION=="remove", RUN+="${removeDevice}"
|
mknod /dev/AMDPowerProfiler -m 666 c $(< /proc/AMDPowerProfiler/device) 0
|
||||||
'';
|
'';
|
||||||
|
ExecStop = pkgs.writeShellScript "remove-amd-uprof-dev.sh" ''
|
||||||
|
rm -f /dev/AMDPowerProfiler
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user