Skip to content

Commit

Permalink
Ubuntu doens't have a CPU governor.
Browse files Browse the repository at this point in the history
  • Loading branch information
rerdavies committed Nov 12, 2024
1 parent bd99403 commit 64062fb
Show file tree
Hide file tree
Showing 17 changed files with 160 additions and 87 deletions.
59 changes: 31 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ project(pipedal
DESCRIPTION "PiPedal Guitar Effect Pedal For Raspberry Pi"
HOMEPAGE_URL "https://rerdavies.github.io/pipedal"
)

EXECUTE_PROCESS( COMMAND dpkg --print-architecture COMMAND tr -d '\n' OUTPUT_VARIABLE DEBIAN_ARCHITECTURE )

set (DISPLAY_VERSION "PiPedal v1.3.66-Release")
set (PACKAGE_ARCHITECTURE "arm64")
set (PACKAGE_ARCHITECTURE ${DEBIAN_ARCHITECTURE})
set (CMAKE_INSTALL_PREFIX "/usr/")

include(CTest)
Expand All @@ -28,16 +31,6 @@ add_subdirectory("src")
# install (TARGETS pipedal_nm_p2pd DESTINATION ${CMAKE_INSTALL_PREFIX}/sbin
# )

# select LV2 source directory for the current build architecture

message(STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}")
set(LV2_SOURCE_DIRECTORY ${PROJECT_SOURCE_DIR}/lv2/${CMAKE_SYSTEM_PROCESSOR}/ToobAmp.lv2)

if (NOT EXISTS ${LV2_SOURCE_DIRECTORY})
message(FATAL_ERROR "Lv2 Binaries for architecture '${CMAKE_SYSTEM_PROCESSOR}' have not been provisioned. See lv2/Readme.md")
endif()
# add_subdirectory("test")

# add_test(NAME Test COMMAND piddletest)

set (REACT_BUILD_DIRECTORY ${PROJECT_SOURCE_DIR}/build/react/build/)
Expand Down Expand Up @@ -73,22 +66,34 @@ install (
DESTINATION /etc/pipedal/config
)

install (DIRECTORY ${LV2_SOURCE_DIRECTORY}
DESTINATION /usr/lib/lv2
)
install(CODE
[[
file(GET_RUNTIME_DEPENDENCIES
EXECUTABLES
${CMAKE_INSTALL_PREFIX}/sbin/pipedaladmind
${CMAKE_INSTALL_PREFIX}/sbin/pipedald
${CMAKE_INSTALL_PREFIX}/sbin/pipedal_update
#${CMAKE_INSTALL_PREFIX}/sbin/pipedal_nm_p2pd
#${CMAKE_INSTALL_PREFIX}/sbin/pipedal_p2pd
${CMAKE_INSTALL_PREFIX}/bin/pipedalconfig
message(STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}")


if ("${DEBIAN_ARCHITECTURE}" MATCHES "arm64")

# select LV2 source directory for the current build architecture

set(LV2_SOURCE_DIRECTORY ${PROJECT_SOURCE_DIR}/build/lv2/${CMAKE_SYSTEM_PROCESSOR}/ToobAmp.lv2)

install (DIRECTORY ${LV2_SOURCE_DIRECTORY}
DESTINATION /usr/lib/lv2
)
]]
)
elseif("${DEBIAN_ARCHITECTURE}" MATCHES "amd64")

add_custom_target(extract_toobamp_lv2_files ALL
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/lv2/x86_64/unpackArtifact.sh
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Extracting x64 ToobAmp components"
)

set(LV2_SOURCE_DIRECTORY ${PROJECT_SOURCE_DIR}/build/lv2_x64/pkg/usr/lib/lv2/ToobAmp.lv2)

install (DIRECTORY ${LV2_SOURCE_DIRECTORY}
DESTINATION /usr/lib/lv2
)
else()
message(FATAL_ERROR "Unknown/unsupported build architecture: ${DEBIAN_ARCHITECTURE}")
endif()


set(CPACK_GENERATOR "DEB")
Expand All @@ -99,9 +104,7 @@ set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "IoT guitar effect pedal for Raspberry Pi"
set(CPACK_DEBIAN_PACKAGE_SECTION sound)
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set(CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION TRUE)
#set(CPACK_DEBIAN_PACKAGE_DEPENDS "jackd2, hostapd, dhcpcd, dnsmasq" )
set(CPACK_DEBIAN_PACKAGE_DEPENDS "lv2-dev, authbind, gpg" )
#set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "arm64")
set(CPACK_PACKAGING_INSTALL_PREFIX /usr)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
Expand Down
9 changes: 9 additions & 0 deletions lv2/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@ This folder contains pre-built binaries for an initial bundle of Lv2 plugins.
This arrangment is temporary, and is expected to go away, once a reliable distribution
of this project and the ToobAmp project via apt can be arranged.

To update the arm64 binaries for ToobAmp, build the ToobAmp project, run `./install.sh` in the ToobAmp project directory,
and then run `./provisionLv2` in the pipedal root directory. This copies the ToobAmp binaries into the pipedal source tree.

The x86_64 binaries are, instead built from an artifact provided by the github CMake build action. Currently, these
binaries are built on an Ubuntu 24.04 LTS build runner. PiPedals's build runner should run on the same build runner
configuration. The CMake build process will unpack the artifact, and extract ToobAmp LV2 binaries into the build directory
where the debian package can pick them up.


Binary file not shown.
7 changes: 7 additions & 0 deletions lv2/x86_64/unpackArtifact.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/bash

rm -rf build/lv2_x64
mkdir build/lv2_x64

mkdir build/lv2_x64/pkg
dpkg-deb -x lv2/x86_64/toobamp_*_amd64.deb build/lv2_x64/pkg
2 changes: 2 additions & 0 deletions react/src/GovernorSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

export default class GovernorSettings {
deserialize(input: any) : GovernorSettings{
this.hasGovernor = input.hasGovernor;
this.governors = input.governors;
this.governor = input.governor;
return this;
Expand All @@ -29,6 +30,7 @@ export default class GovernorSettings {
{
return new GovernorSettings().deserialize(this);
}
hasGovernor: boolean = true;
governors: string[] = ["ondemand","performance"];
governor: string = "performance";

Expand Down
58 changes: 29 additions & 29 deletions react/src/JackHostStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

import React from 'react';
import Typography from '@mui/material/Typography';
import {isDarkMode} from './DarkMode';
import { isDarkMode } from './DarkMode';

const RED_COLOR = isDarkMode()? "#F88":"#C00";
const GREEN_COLOR = isDarkMode()? "rgba(255,255,255,0.7)": "#666";
const RED_COLOR = isDarkMode() ? "#F88" : "#C00";
const GREEN_COLOR = isDarkMode() ? "rgba(255,255,255,0.7)" : "#666";



Expand All @@ -33,23 +33,18 @@ function cpuDisplay(cpu: number): string {
return cpu.toFixed(1) + "%";
}

function fmtCpuFreq(freq: number): string
{
if (freq >= 100000000)
{
return (freq/1000000).toFixed(1) + " GHz";
function fmtCpuFreq(freq: number): string {
if (freq >= 100000000) {
return (freq / 1000000).toFixed(1) + " GHz";
}
if (freq >= 10000000)
{
return (freq/1000000).toFixed(2) + " GHz";
if (freq >= 10000000) {
return (freq / 1000000).toFixed(2) + " GHz";
}
if (freq >= 1000000)
{
return (freq/1000000).toFixed(3) + " GHz";
if (freq >= 1000000) {
return (freq / 1000000).toFixed(3) + " GHz";
}
if (freq >= 1000)
{
return (freq/1000).toFixed(3) + " MHz";
if (freq >= 1000) {
return (freq / 1000).toFixed(3) + " MHz";
}
return freq + " KHz";
}
Expand All @@ -65,6 +60,7 @@ export default class JackHostStatus {
this.temperaturemC = input.temperaturemC;
this.cpuFreqMax = input.cpuFreqMax;
this.cpuFreqMin = input.cpuFreqMin;
this.hasCpuGovernor = input.hasCpuGovernor;
this.governor = input.governor;
return this;
}
Expand All @@ -80,6 +76,7 @@ export default class JackHostStatus {
temperaturemC: number = -1000000;
cpuFreqMax: number = 0;
cpuFreqMin: number = 0;
hasCpuGovernor: boolean = false;
governor: string = "";

static getCpuInfo(label: string, status?: JackHostStatus): React.ReactNode {
Expand All @@ -91,18 +88,21 @@ export default class JackHostStatus {
}
return (<div style={{ whiteSpace: "nowrap" }}>
<Typography variant="caption" color="inherit">{label}</Typography>
<Typography variant="caption" color="inherit">
{
(status.cpuFreqMax === status.cpuFreqMin)?
(
<span> {status.governor} {fmtCpuFreq(status.cpuFreqMax)} </span>
)
:(
<span> {status.governor} {fmtCpuFreq(status.cpuFreqMax)}-{fmtCpuFreq(status.cpuFreqMax)} </span>

)
}
</Typography>
{(status.cpuFreqMin != 0 || status.cpuFreqMax != 0) &&
(
<Typography variant="caption" color="inherit">
{
(status.cpuFreqMax === status.cpuFreqMin) ?
(
<span> {status.governor} {fmtCpuFreq(status.cpuFreqMax)} </span>
)
: (
<span> {status.governor} {fmtCpuFreq(status.cpuFreqMax)}-{fmtCpuFreq(status.cpuFreqMax)} </span>

)
}
</Typography>
)}
</div>);


Expand Down
13 changes: 13 additions & 0 deletions src/AdminClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <sys/types.h>
#include <ifaddrs.h>
#include "Ipv6Helpers.hpp"
#include "CpuGovernor.hpp"

using namespace pipedal;

Expand Down Expand Up @@ -143,6 +144,10 @@ void AdminClient::SetGovernorSettings(const std::string &settings)
{
throw PiPedalException("Can't use AdminClient when running interactively.");
}
if (!HasCpuGovernor())
{
return;
}
std::stringstream cmd;
cmd << "GovernorSettings ";
json_writer writer(cmd, true);
Expand All @@ -161,6 +166,10 @@ void AdminClient::MonitorGovernor(const std::string &governor)
{
return;
}
if (!HasCpuGovernor())
{
return;
}
std::stringstream cmd;
cmd << "MonitorGovernor ";
json_writer writer(cmd, true);
Expand All @@ -178,6 +187,10 @@ void AdminClient::UnmonitorGovernor()
{
return;
}
if (!HasCpuGovernor())
{
return;
}
std::stringstream cmd;
cmd << "UnmonitorGovernor";
cmd << '\n';
Expand Down
8 changes: 4 additions & 4 deletions src/AdminInstallUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ static int exec(const std::string &command)
if ((pid = fork()) == 0)
{
execv(argv[0], (char *const *)argv.data());
write(1,"!\n",2);
auto _ = write(1,"!\n",2);
exit(EXIT_FAILURE);
}
else
{

if (pid == -1)
{
write(1,"*",1);
auto _ = write(1,"*",1);
perror("execv");
return EXIT_FAILURE;
}
Expand All @@ -99,8 +99,8 @@ static int exec(const std::string &command)

void updateLog(const std::string &message)
{
write(1,message.c_str(),message.length());
write(1,"\n",1);
auto _ = write(1,message.c_str(),message.length());
_ = write(1,"\n",1);
}


Expand Down
17 changes: 16 additions & 1 deletion src/AdminMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ class GovernorMonitorThread
void Start(std::string governor)
{
std::unique_lock<std::mutex> lock(mutex);
if (!HasCpuGovernor())
{
return;
}
if (!pThread)
{
this->governor = governor;
Expand All @@ -81,6 +85,10 @@ class GovernorMonitorThread
}
void Stop()
{
if (!HasCpuGovernor())
{
return;
}
std::unique_lock<std::mutex> lock(mutex);
if (pThread)
{
Expand Down Expand Up @@ -109,6 +117,10 @@ class GovernorMonitorThread
std::string savedGovernor;
void ServiceProc()
{
if (!HasCpuGovernor())
{
return;
}
savedGovernor = pipedal::GetCpuGovernor();
pipedal::SetCpuGovernor(this->governor);
while (true)
Expand Down Expand Up @@ -303,7 +315,10 @@ class AdminServer
{
throw PiPedalArgumentException("Invalid arguments.");
}
governorMonitorThread.SetGovernor(governor);
if (HasCpuGovernor())
{
governorMonitorThread.SetGovernor(governor);
}
result = 0;
}
else if (command == "WifiConfigSettings")
Expand Down
13 changes: 10 additions & 3 deletions src/AudioHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ static void GetCpuFrequency(uint64_t *freqMin, uint64_t *freqMax)
catch (const std::exception &)
{
}
if (fMin == 0)
fMax = 0;
if (fMax == 0)
fMin = 0;
*freqMin = fMin;
*freqMax = fMax;
}
Expand Down Expand Up @@ -2091,7 +2091,13 @@ class AudioHostImpl : public AudioHost, private AudioDriverHost, private IPatchW
result.cpuUsage_ = audioDriver->CpuUse();
}
GetCpuFrequency(&result.cpuFreqMax_, &result.cpuFreqMin_);
result.governor_ = GetGovernor();
result.hasCpuGovernor_ = HasCpuGovernor();
if (result.hasCpuGovernor_)
{
result.governor_ = GetGovernor();
} else {
result.governor_ = "";
}

return result;
}
Expand Down Expand Up @@ -2278,5 +2284,6 @@ JSON_MAP_REFERENCE(JackHostStatus, msSinceLastUnderrun)
JSON_MAP_REFERENCE(JackHostStatus, temperaturemC)
JSON_MAP_REFERENCE(JackHostStatus, cpuFreqMin)
JSON_MAP_REFERENCE(JackHostStatus, cpuFreqMax)
JSON_MAP_REFERENCE(JackHostStatus, hasCpuGovernor)
JSON_MAP_REFERENCE(JackHostStatus, governor)
JSON_MAP_END()
1 change: 1 addition & 0 deletions src/AudioHost.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ namespace pipedal
int32_t temperaturemC_ = -100000;
uint64_t cpuFreqMax_ = 0;
uint64_t cpuFreqMin_ = 0;
bool hasCpuGovernor_ = true;
std::string governor_;

DECLARE_JSON_MAP(JackHostStatus);
Expand Down
6 changes: 4 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -737,14 +737,16 @@ set (DEBIAN_COPYRIGHT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../debian/copyright)

# generate Copyright section of settings page.
# warning: there may be multiple versions. Pick the latest.
if(EXISTS "/usr/share/doc/libboost1.74-dev")
if(EXISTS "/usr/share/doc/libboost1.83-dev")
set (BOOST_COPYRIGHT_DIR "libboost1.83-dev")
elseif(EXISTS "/usr/share/doc/libboost1.74-dev")
set (BOOST_COPYRIGHT_DIR "libboost1.74-dev")
elseif(EXISTS "/usr/share/doc/libboost1.71-dev")
set (BOOST_COPYRIGHT_DIR "libboost1.71-dev")
elseif(EXISTS "/usr/share/doc/libboost1.67-dev")
set (BOOST_COPYRIGHT_DIR "libboost1.67-dev")
else()
message(ERROR "Boost libary version has changed. Please update me.")
message(FATAL_ERROR "Boost libary version has changed. Please update me.")
endif()


Expand Down
Loading

0 comments on commit 64062fb

Please sign in to comment.