Skip to content

armgit / PS5LM

Public Imported from GitHub
0

llama.cpp on a jailbroken PS5: run any GGUF model natively on the console, starting with Qwen 3.8

OnionHEN black screen (#23, #32), download check progress (#30), times in app.log (#40) (#42)

Mert Cobanov8ce87d09dd20
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5a2069a..650b8c4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -71,6 +71,8 @@ v0.1.x are the upstream payload releases by cobanov.
the 12 GiB pool it plans 64k again. Not yet measured on a console: `app.log` now records the pool
and the flexible memory at start (`memory at start`) and once the model serves (`memory when
ready`).
+- Every line the app writes to `app.log` starts with the console's local time, as
+ `22:56:01 ps5lm-app: start` (#40). Lines from the graphics stack keep their own form.
### Added
- **A PC's GPU as a fleet worker.** `PS5LM_FLEET_GPU=metal` (or `cuda`, `vulkan`)
@@ -83,6 +85,10 @@ v0.1.x are the upstream payload releases by cobanov.
### Fixed
- A download that meets a full drive anyway stops at once, "Failed: App storage is full", instead
of retrying twenty times.
+- At the end of a download, Models > Downloads said "starting" for the minutes the SHA-256 check
+ takes, so it looked hung (#30). It now says "Checking the SHA-256, 45%". The queue is saved
+ before the check, so a restart during it checks the file again but no longer fetches the last
+ piece first.
## [0.10.0] - 2026-11-01
diff --git a/ps5/app/display.cpp b/ps5/app/display.cpp
index bdbd85d..7833e8e 100644
--- a/ps5/app/display.cpp
+++ b/ps5/app/display.cpp
@@ -5,6 +5,7 @@
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include "display.hpp"
+#include "log.hpp"
#include "gfx/renderer.hpp"
@@ -66,7 +67,7 @@ EGLSurface g_surface = EGL_NO_SURFACE;
EGLContext g_context = EGL_NO_CONTEXT;
bool fail(const char * what) {
- std::printf("ps5lm-app: display: %s failed (egl 0x%04x)\n", what, (unsigned) eglGetError());
+ ps5lm::log_line("display: %s failed (egl 0x%04x)\n", what, (unsigned) eglGetError());
return false;
}
@@ -106,8 +107,8 @@ bool Display::open(int width, int height) {
eglQuerySurface(g_display, g_surface, EGL_WIDTH, &width_);
eglQuerySurface(g_display, g_surface, EGL_HEIGHT, &height_);
eglSwapInterval(g_display, 1);
- std::printf("ps5lm-app: display: egl %d.%d, %dx%d, %s\n", major, minor, width_, height_,
- (const char *) glGetString(GL_RENDERER));
+ ps5lm::log_line("display: egl %d.%d, %dx%d, %s\n", major, minor, width_, height_,
+ (const char *) glGetString(GL_RENDERER));
return true;
}
diff --git a/ps5/app/ftp_writer.cpp b/ps5/app/ftp_writer.cpp
index 1d008f8..c0b8c09 100644
--- a/ps5/app/ftp_writer.cpp
+++ b/ps5/app/ftp_writer.cpp
@@ -3,6 +3,7 @@
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include "ftp_writer.hpp"
+#include "log.hpp"
#include "stats.hpp"
@@ -352,10 +353,10 @@ bool user_ftpsrv_works(FtpWriter & ftp, std::string & error) {
works = ftp.write_at(kFtpCheckFile, 0, "x", 1, check_error) ? 1 : 0;
::unlink(kFtpCheckFile);
if (works) {
- std::printf("ps5lm-app: ftpsrv: the one on %d works\n", kFtpsrvPort);
+ ps5lm::log_line("ftpsrv: the one on %d works\n", kFtpsrvPort);
} else {
error = check_error;
- std::printf("ps5lm-app: ftpsrv: the one on %d cannot write for PS5LM (%s); using PS5LM's own copy on %d\n",
+ ps5lm::log_line("ftpsrv: the one on %d cannot write for PS5LM (%s); using PS5LM's own copy on %d\n",
kFtpsrvPort, check_error.c_str(), kOwnFtpsrvPort);
}
}
@@ -399,20 +400,20 @@ bool connect_ftp_writer(FtpWriter & ftp, std::string & error) {
sent = true;
// The ELF loader runs what it read once the connection ends.
if (!send_payload(kOwnFtpsrvElf, kElfLoaderPort)) {
- std::printf("ps5lm-app: ftpsrv: could not send %s to elfldr on %d\n", kOwnFtpsrvElf, kElfLoaderPort);
+ ps5lm::log_line("ftpsrv: could not send %s to elfldr on %d\n", kOwnFtpsrvElf, kElfLoaderPort);
return none(error_2123 + "; not started: no elfldr on " + std::to_string(kElfLoaderPort) + " took it");
}
- std::printf("ps5lm-app: ftpsrv: sent %s to the ELF loader on %d\n", kOwnFtpsrvElf, kElfLoaderPort);
+ ps5lm::log_line("ftpsrv: sent %s to the ELF loader on %d\n", kOwnFtpsrvElf, kElfLoaderPort);
const auto t0 = std::chrono::steady_clock::now();
for (int i = 0; i < 25; i++) {
std::this_thread::sleep_for(std::chrono::milliseconds(200));
if (ftp.connect(error_2123)) {
- std::printf("ps5lm-app: ftpsrv: PS5LM's own copy answers on %d after %.1f s\n", kOwnFtpsrvPort,
+ ps5lm::log_line("ftpsrv: PS5LM's own copy answers on %d after %.1f s\n", kOwnFtpsrvPort,
std::chrono::duration<double>(std::chrono::steady_clock::now() - t0).count());
return true;
}
}
- std::printf("ps5lm-app: ftpsrv: PS5LM's own copy does not answer on %d: %s\n", kOwnFtpsrvPort, error_2123.c_str());
+ ps5lm::log_line("ftpsrv: PS5LM's own copy does not answer on %d: %s\n", kOwnFtpsrvPort, error_2123.c_str());
return none(error_2123 + "; sent to the ELF loader, but it did not start within 5 s");
}
diff --git a/ps5/app/log.hpp b/ps5/app/log.hpp
new file mode 100644
index 0000000..78dc3f1
--- /dev/null
+++ b/ps5/app/log.hpp
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+#pragma once
+
+#include <cstdarg>
+#include <cstdio>
+#include <ctime>
+#include <string>
+
+namespace ps5lm {
+
+// One app.log line: the console's local time, "ps5lm-app: " and the text, as
+// "22:56:01 ps5lm-app: start" (#40). Formatted first and written with one call,
+// so another thread's line cannot land between the time and the text.
+inline void log_line(const char * fmt, ...) __attribute__((format(printf, 1, 2)));
+inline void log_line(const char * fmt, ...) {
+ const std::time_t now = std::time(nullptr);
+ std::tm tm = {};
+ char when[16] = "--:--:--";
+ if (localtime_r(&now, &tm)) {
+ std::strftime(when, sizeof(when), "%H:%M:%S", &tm);
+ }
+ va_list ap, ap2;
+ va_start(ap, fmt);
+ va_copy(ap2, ap);
+ const int n = std::vsnprintf(nullptr, 0, fmt, ap);
+ va_end(ap);
+ std::string text(n > 0 ? (size_t) n : 0, '\0');
+ if (n > 0) {
+ std::vsnprintf(&text[0], text.size() + 1, fmt, ap2);
+ }
+ va_end(ap2);
+ std::printf("%s ps5lm-app: %s", when, text.c_str());
+}
+
+} // namespace ps5lm
diff --git a/ps5/app/main.cpp b/ps5/app/main.cpp
index d07fde7..99bc890 100644
--- a/ps5/app/main.cpp
+++ b/ps5/app/main.cpp
@@ -46,6 +46,7 @@
#include <GL/glcorearb.h>
#include "dashboard.hpp"
+#include "log.hpp"
#include "fetch.hpp"
#include "fleet_worker.hpp"
#include "market.hpp"
@@ -129,8 +130,10 @@ constexpr const char * kAssets = "/app0/assets";
constexpr int kPort = 8081;
// Both homes' models are listed: a model saved to the app's storage still
// loads once full storage opens.
-const std::vector<std::string> kModelDirs = { "/data/PS5LM/models", "/download0/PS5LM/models", "/mnt/ext0/PS5LM/models",
- "/mnt/usb0/PS5LM/models", "/mnt/usb1/PS5LM/models", "/mnt/usb0", "/mnt/usb1" };
+std::vector<std::string> model_dirs() {
+ return { "/data/PS5LM/models", sandbox_path("/download0/PS5LM/models"), "/mnt/ext0/PS5LM/models",
+ "/mnt/usb0/PS5LM/models", "/mnt/usb1/PS5LM/models", "/mnt/usb0", "/mnt/usb1" };
+}
// The last lines of a log, up to about 64 KiB of it, oldest first.
std::vector<std::string> tail_lines(const std::string & path) {
@@ -189,10 +192,11 @@ bool data_open() {
// How /data ended up, for the log. A refusal is remembered in /download0:
// the next starts (one per model change) still ask, but wait 2 s, not 10.
-std::string open_data() {
+std::string open_data(const std::string & title) {
constexpr const char * kRefused = "/download0/PS5LM/data-closed";
if (data_open()) {
- unlink(kRefused);
+ find_sandbox(title);
+ unlink(sandbox_path(kRefused).c_str());
return "open";
}
const int err = errno;
@@ -202,7 +206,8 @@ std::string open_data() {
for (int i = 1; i <= (again ? 8 : 40); i++) { // OnionHEN answered in about 3 s
sceKernelUsleep(250000);
if (data_open()) {
- unlink(kRefused);
+ find_sandbox(title); // OnionHEN's answer also leaves the sandbox
+ unlink(sandbox_path(kRefused).c_str());
return "opened by the HEN after " + std::to_string(i / 4.0).substr(0, 4) + " s";
}
}
@@ -219,7 +224,7 @@ void quit_if_asked() {
return;
}
unlink(g_files.quit.c_str());
- std::printf("ps5lm-app: quit requested\n");
+ ps5lm::log_line("quit requested\n");
std::fflush(nullptr);
sceSystemServiceLoadExec("exit", nullptr);
}
@@ -290,9 +295,9 @@ void log_memory(const char * when, bool devices = true) {
sceKernelAvailableFlexibleMemorySize(&flex_free);
struct ps5_heap_stats heap = {};
ps5_heap_stats(&heap);
- std::printf("ps5lm-app: memory %s: pool %.4f GiB, pool free %.2f GiB, flexible %zu MiB (%zu free), cpu heap %.2f GiB "
- "(peak %.2f)", when, pool / 1073741824.0, avail / 1073741824.0, flex >> 20, flex_free >> 20,
- heap.mapped_bytes / 1073741824.0, heap.peak_bytes / 1073741824.0);
+ ps5lm::log_line("memory %s: pool %.4f GiB, pool free %.2f GiB, flexible %zu MiB (%zu free), cpu heap %.2f GiB "
+ "(peak %.2f)", when, pool / 1073741824.0, avail / 1073741824.0, flex >> 20, flex_free >> 20,
+ heap.mapped_bytes / 1073741824.0, heap.peak_bytes / 1073741824.0);
for (size_t i = 0; devices && i < ggml_backend_dev_count(); i++) {
size_t free = 0, total = 0;
ggml_backend_dev_memory(ggml_backend_dev_get(i), &free, &total);
@@ -544,7 +549,7 @@ void write_report(ReportJob job) {
std::snprintf(status, sizeof(status), "Failed: cannot write %s%s", path.c_str(),
usb.empty() ? "" : ("; saved to " + usb + "/PS5LM-debug-report.txt").c_str());
}
- std::printf("ps5lm-app: debug report: %s\n", status);
+ ps5lm::log_line("debug report: %s\n", status);
notify((std::string("PS5LM: debug report ") + (ok ? "saved to " + path : status)).c_str());
std::lock_guard<std::mutex> lock(g_report_mutex);
g_report_status = status;
@@ -567,11 +572,11 @@ void * run_server(void *) {
try {
rc = llama_server((int) argv.size() - 1, argv.data());
} catch (const std::exception & e) {
- std::printf("ps5lm-app: exception: %s\n", e.what());
+ ps5lm::log_line("exception: %s\n", e.what());
} catch (...) {
- std::printf("ps5lm-app: unknown exception\n");
+ ps5lm::log_line("unknown exception\n");
}
- std::printf("ps5lm-app: llama_server returned %d\n", rc);
+ ps5lm::log_line("llama_server returned %d\n", rc);
std::fflush(nullptr);
g_server_rc = rc == 0 ? 0 : 1;
return nullptr;
@@ -640,7 +645,7 @@ struct Models {
const char * kv = settings.kv_type == "auto" ? nullptr : settings.kv_type.c_str();
// Also every folder the downloads can go to: the M.2 slot or a USB drive is
// not always ext0, usb0 or usb1 (#43).
- std::vector<std::string> dirs = kModelDirs;
+ std::vector<std::string> dirs = model_dirs();
std::vector<std::string> saves = { settings.download_dir };
for (const auto & d : mounted_drives()) {
saves.push_back(d.models);
@@ -671,7 +676,7 @@ struct Models {
row.decision = m.decision;
row.current = path == running;
rows.push_back(row);
- std::printf("ps5lm-app: model %s (%s): %s\n", m.file_name.c_str(), m.arch.c_str(), p.why.c_str());
+ ps5lm::log_line("model %s (%s): %s\n", m.file_name.c_str(), m.arch.c_str(), p.why.c_str());
}
return rows;
}
@@ -720,7 +725,7 @@ struct Models {
args.insert(args.end(), { "--tools", kTools });
}
for (const auto & a : args) {
- std::printf("ps5lm-app: arg %s\n", a.c_str());
+ ps5lm::log_line("arg %s\n", a.c_str());
}
g_server_args = args;
g_server_rc = -1;
@@ -750,7 +755,7 @@ struct Models {
if (g_server_rc >= 0) {
pthread_join(server, nullptr);
} else {
- std::printf("ps5lm-app: llama_server did not return in 10 s; restarting anyway\n");
+ ps5lm::log_line("llama_server did not return in 10 s; restarting anyway\n");
}
server_started = false;
running.clear();
@@ -773,9 +778,9 @@ pthread_t start_thread(std::function<void()> & fn) {
bool load_font(hui::gfx::Renderer & renderer, const char * name, hui::gfx::Font * font, hui::ui::FontRef * ref) {
std::string data;
- const std::string path = std::string(kAssets) + "/fonts/" + name;
+ const std::string path = sandbox_path(kAssets) + "/fonts/" + name;
if (!hui::save::read_file(path, &data) || !font->load(data)) {
- std::printf("ps5lm-app: font %s failed\n", name);
+ ps5lm::log_line("font %s failed\n", name);
return false;
}
ref->font = font;
@@ -788,21 +793,32 @@ bool load_font(hui::gfx::Renderer & renderer, const char * name, hui::gfx::Font
int main(int, char **) {
// /data first: the log, the settings and the models live there when the
// HEN opens it, else in the app's own storage, /download0/PS5LM.
- const std::string data = open_data();
+ const std::string title = title_id();
+ const std::string data = open_data(title);
const bool full = data.rfind("closed", 0) != 0;
set_data_root(full ? kFullRoot : kAppRoot);
g_files = Files(data_root());
mkdir(data_root().c_str(), 0777);
- // stdout and stderr to a file the PC can fetch over FTP.
- if (std::freopen(g_files.log.c_str(), "w", stdout) != nullptr) {
+ // stdout and stderr to a file the PC can fetch over FTP. Both append: with
+ // stdout at its own offset ("w"), each of its lines overwrote the stderr
+ // lines appended before it, so nothing from stderr survived in app.log.
+ if (std::FILE * f = std::fopen(g_files.log.c_str(), "w")) {
+ std::fclose(f);
+ }
+ if (std::freopen(g_files.log.c_str(), "a", stdout) != nullptr) {
setvbuf(stdout, nullptr, _IOLBF, 0);
}
if (std::freopen(g_files.log.c_str(), "a", stderr) != nullptr) {
setvbuf(stderr, nullptr, _IONBF, 0);
}
- std::printf("ps5lm-app: version " PS5LM_VERSION "\n");
- std::printf("ps5lm-app: /data %s\n", data.c_str());
- std::printf("ps5lm-app: files in %s\n", storage_line(data).c_str());
+ ps5lm::log_line("version " PS5LM_VERSION "\n");
+ ps5lm::log_line("/data %s\n", data.c_str());
+ ps5lm::log_line("files in %s\n", storage_line(data).c_str());
+ if (!sandbox_path("").empty()) {
+ ps5lm::log_line("the HEN moved the app out of its sandbox; /app0 is %s\n", sandbox_path("/app0").c_str());
+ } else if (access("/app0/eboot.bin", F_OK) != 0) {
+ ps5lm::log_line("/app0 is not visible, and no /mnt/sandbox/%s_* holds the app\n", title.c_str());
+ }
// The first start without full storage asks on the screen what to do;
// the notification is for a screen that does not come up.
if (!full && storage_choice().empty()) {
@@ -826,10 +842,10 @@ int main(int, char **) {
if (known) {
setenv(name.c_str(), line.c_str() + eq + 1, 1);
}
- std::printf("ps5lm-app: env %s%s\n", line.c_str(), known ? "" : " (ignored)");
+ ps5lm::log_line("env %s%s\n", line.c_str(), known ? "" : " (ignored)");
}
mkdir(g_files.models.c_str(), 0777);
- std::printf("ps5lm-app: start\n");
+ ps5lm::log_line("start\n");
// What the system gave the title, before the screen and the GPU take any
// of it: the pool size follows sce_sys/param.json.
log_memory("at start", false);
@@ -837,7 +853,7 @@ int main(int, char **) {
// The screen first: it takes from the same memory as the model.
Display display;
if (!display.open(1920, 1080)) {
- std::printf("ps5lm-app: no display\n");
+ ps5lm::log_line("no display\n");
}
hui::gfx::Renderer renderer;
hui::gfx::Font regular, semibold, headline, mono;
@@ -848,7 +864,7 @@ int main(int, char **) {
load_font(renderer, "dejavu-sans-mono.huifont", &mono, &fonts.mono);
fonts.pixel = fonts.mono;
fonts.hand = fonts.regular;
- std::printf("ps5lm-app: dashboard %s\n", ui_ok ? "ready" : "failed");
+ ps5lm::log_line("dashboard %s\n", ui_ok ? "ready" : "failed");
Dashboard dash(fonts);
DashboardFrame frame;
@@ -974,8 +990,8 @@ int main(int, char **) {
ggml_backend_dev_t dev = ggml_backend_dev_get(i);
size_t free = 0, total = 0;
ggml_backend_dev_memory(dev, &free, &total);
- std::printf("ps5lm-app: device %zu %s (%s): %.2f / %.2f GiB free\n", i, ggml_backend_dev_name(dev),
- ggml_backend_dev_description(dev), free / 1073741824.0, total / 1073741824.0);
+ ps5lm::log_line("device %zu %s (%s): %.2f / %.2f GiB free\n", i, ggml_backend_dev_name(dev),
+ ggml_backend_dev_description(dev), free / 1073741824.0, total / 1073741824.0);
// The PS5 is an APU: ggml calls its GPU integrated.
const auto type = ggml_backend_dev_type(dev);
if (type == GGML_BACKEND_DEVICE_TYPE_GPU || type == GGML_BACKEND_DEVICE_TYPE_IGPU) {
@@ -1001,7 +1017,7 @@ int main(int, char **) {
model_part.model_gib = info.file_bytes / 1073741824.0;
model_part.model_file = path;
model_part.args = args;
- std::printf("ps5lm-app: app-args.txt overrides the planner\n");
+ ps5lm::log_line("app-args.txt overrides the planner\n");
} else {
auto chosen = read_lines(g_files.choice);
unlink(g_files.choice.c_str());
@@ -1023,7 +1039,7 @@ int main(int, char **) {
unlink(g_files.text_only.c_str());
const auto mm = std::find(args.begin(), args.end(), "--mmproj");
if (mm != args.end()) {
- std::printf("ps5lm-app: loading without %s\n", mm + 1 != args.end() ? (mm + 1)->c_str() : "the projector");
+ ps5lm::log_line("loading without %s\n", mm + 1 != args.end() ? (mm + 1)->c_str() : "the projector");
args.erase(mm, std::min(mm + 2, args.end()));
model_part.args = args;
}
@@ -1076,7 +1092,7 @@ int main(int, char **) {
hui::ps5::AudioOut audio_out;
audio_out.start(mixer);
hui::audio::SoundBank sounds;
- sounds.load(std::string(kAssets) + "/audio/sfx");
+ sounds.load(sandbox_path(kAssets) + "/audio/sfx");
dash.set_busy("");
Market market;
@@ -1187,7 +1203,7 @@ int main(int, char **) {
char text[128];
std::snprintf(text, sizeof(text), "PS5LM: the chat's scratch folder holds %.1f GiB; clear it in Settings", gib);
notify(text);
- std::printf("ps5lm-app: %s\n", text + 7);
+ ps5lm::log_line("%s\n", text + 7);
}
scratch_warned = over;
}
@@ -1235,12 +1251,12 @@ int main(int, char **) {
if (was.ctx_cap != models.settings.ctx_cap || was.kv_type != models.settings.kv_type) {
models.rescan(stats);
}
- std::printf("ps5lm-app: settings saved\n");
+ ps5lm::log_line("settings saved\n");
// The server reads LLAMA_INTROSPECT only when it starts: restart with the
// same model, so that the switch never says something the server does not do.
if (was.introspect != models.settings.introspect && !models.running.empty() && restart_at == 0) {
std::ofstream(g_files.choice) << models.running << "\n";
- std::printf("ps5lm-app: restarting %s with the introspection API %s\n", models.running.c_str(),
+ ps5lm::log_line("restarting %s with the introspection API %s\n", models.running.c_str(),
models.settings.introspect ? "on" : "off");
dash.set_busy(std::string(models.settings.introspect ? "Opening" : "Closing") + " the logits and activations API",
"The app restarts with " + base_name(models.running));
@@ -1285,7 +1301,7 @@ int main(int, char **) {
if (market.job(req.repo, req.file, req.path.empty() ? models.settings.download_dir : req.path, &job) &&
market.enqueue(job, free_gib(job.dir))) {
std::ofstream(g_files.choice) << "none\n";
- std::printf("ps5lm-app: restarting to download %s/%s without a model\n", job.repo.c_str(), job.file.c_str());
+ ps5lm::log_line("restarting to download %s/%s without a model\n", job.repo.c_str(), job.file.c_str());
dash.set_busy("Unloading " + base_name(models.running), "The app restarts without it, then the download starts");
restart_at = n + 3;
}
@@ -1300,18 +1316,18 @@ int main(int, char **) {
}
stats.set_scratch(folder_bytes(g_files.scratch) / 1073741824.0);
notify("PS5LM: scratch folder cleared");
- std::printf("ps5lm-app: scratch folder cleared\n");
+ ps5lm::log_line("scratch folder cleared\n");
}
// Full storage closed: the app's own storage is the answer from now on,
// or a fresh start asks the HEN again.
if (req.kind == Dashboard::Request::storage_app) {
set_storage_choice("app");
- std::printf("ps5lm-app: the app's own storage, chosen\n");
+ ps5lm::log_line("the app's own storage, chosen\n");
} else if (req.kind == Dashboard::Request::restart) {
if (!models.running.empty()) {
std::ofstream(g_files.choice) << models.running << "\n";
}
- std::printf("ps5lm-app: restarting to ask for /data again\n");
+ ps5lm::log_line("restarting to ask for /data again\n");
dash.set_busy("Starting again", "PS5LM asks the HEN for full storage once more");
restart_at = n + 3;
}
@@ -1365,7 +1381,7 @@ int main(int, char **) {
if (req.kind == Dashboard::Request::load) {
unlink(g_files.args.c_str()); // the library's choice replaces a manual override
}
- std::printf("ps5lm-app: restarting for %s\n", req.kind == Dashboard::Request::load ? req.path.c_str() : "no model");
+ ps5lm::log_line("restarting for %s\n", req.kind == Dashboard::Request::load ? req.path.c_str() : "no model");
const bool loaded = !models.running.empty();
if (req.kind == Dashboard::Request::load) {
dash.set_busy(loaded ? "Switching models" : "Loading " + base_name(req.path),
@@ -1381,7 +1397,7 @@ int main(int, char **) {
render();
if (n % 60 == 45 && !take_request_file(data_path("screenshot")).empty()) {
const bool ok = save_screen(data_path("screen.bmp").c_str(), display.width(), display.height());
- std::printf("ps5lm-app: screenshot %s\n", ok ? "saved" : "failed");
+ ps5lm::log_line("screenshot %s\n", ok ? "saved" : "failed");
}
}
display.swap();
diff --git a/ps5/app/market.cpp b/ps5/app/market.cpp
index f4f230e..f8741fd 100644
--- a/ps5/app/market.cpp
+++ b/ps5/app/market.cpp
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#include "market.hpp"
+#include "log.hpp"
#include "fetch.hpp"
#include "ftp_writer.hpp"
@@ -339,7 +340,7 @@ bool Market::enqueue(const std::vector<MarketJob> & jobs, double free) {
jobs[0].file.c_str(), jobs.size() > 1 ? " and its image projector" : "", need, drive_name(dir).c_str(),
std::max(0.0, free - queued), queued > 0 ? " after the downloads queued there" : "");
view_.note = text;
- std::printf("ps5lm-app: download %s/%s: %s\n", jobs[0].repo.c_str(), jobs[0].file.c_str(), text);
+ ps5lm::log_line("download %s/%s: %s\n", jobs[0].repo.c_str(), jobs[0].file.c_str(), text);
return false;
}
for (const auto & job : jobs) {
@@ -494,7 +495,7 @@ bool Market::fetch(Download & d) {
const bool via_ftp = !own_storage && connect_ftp_writer(ftp, ftp_error);
const std::string direct_note = via_ftp ? "" : "written without ftpsrv, slower after about 2 GB";
if (!via_ftp) {
- std::printf("ps5lm-app: download %s: the app writes the file itself, which gets slow after about 2.2 GB (%s)\n",
+ ps5lm::log_line("download %s: the app writes the file itself, which gets slow after about 2.2 GB (%s)\n",
d.file.c_str(), ftp_error.c_str());
}
const int fd = open(part.c_str(), O_WRONLY | O_CREAT, 0666);
@@ -537,7 +538,7 @@ bool Market::fetch(Download & d) {
if (ftp_disk_full(error)) {
return false;
}
- std::printf("ps5lm-app: download %s: piece at %llu: %s, writing it again\n", d.file.c_str(),
+ ps5lm::log_line("download %s: piece at %llu: %s, writing it again\n", d.file.c_str(),
(unsigned long long) off, error.c_str());
error.clear();
return ftp.write_at(part, off, buf.data(), buf.size(), error);
@@ -605,8 +606,8 @@ bool Market::fetch(Download & d) {
}
last_error = text;
const int f = ++failures;
- std::printf("ps5lm-app: download %s: piece at %llu stopped after %llu bytes: %s\n", d.file.c_str(),
- (unsigned long long) off, (unsigned long long) got, text);
+ ps5lm::log_line("download %s: piece at %llu stopped after %llu bytes: %s\n", d.file.c_str(),
+ (unsigned long long) off, (unsigned long long) got, text);
const int werr = write_errno;
if (werr == ENOSPC || werr == EDQUOT || werr == EFBIG) {
last_error = drive_name(d.dir) + " is full";
@@ -727,7 +728,7 @@ bool Market::fetch(Download & d) {
d.state = DownloadState::done;
d.note = "Saved to " + to;
}
- std::printf("ps5lm-app: download %s/%s: %s\n", d.repo.c_str(), d.file.c_str(), d.note.c_str());
+ ps5lm::log_line("download %s/%s: %s\n", d.repo.c_str(), d.file.c_str(), d.note.c_str());
publish(true);
return d.state == DownloadState::done;
}
diff --git a/ps5/app/preview_main.cpp b/ps5/app/preview_main.cpp
index 07514f9..002a0d3 100644
--- a/ps5/app/preview_main.cpp
+++ b/ps5/app/preview_main.cpp
@@ -263,10 +263,10 @@ int main(int argc, char ** argv) {
std::vector<std::string> app_log, llama_log;
for (int i = 0; i < 60; ++i) {
app_log.push_back("[ps5-present-perf] calls=2500 failures=0 warmup_frames=30 idle_ms=0.000898 flip_ms=0.000889");
- app_log.push_back("ps5lm-app: model Qwen3.8-27B-UD-IQ2_XXS.gguf (qwen35): 64k context, q8_0 cache: 9.9 of 11.0 GiB");
+ app_log.push_back("22:56:01 ps5lm-app: model Qwen3.8-27B-UD-IQ2_XXS.gguf (qwen35): 64k context, q8_0 cache: 9.9 of 11.0 GiB");
llama_log.push_back("7.15.902.312 I slot print_timing: id 0 | task 646 | n_gen = 162, tg = 20.44 t/s");
}
- app_log.push_back("ps5lm-app: accept failed, errno 53");
+ app_log.push_back("22:58:14 ps5lm-app: accept failed, errno 53");
app_log.push_back("W srv stop: cancel task, id_task = 22182");
dash.set_logs(app_log, llama_log);
ps5lm::MarketView mv;
diff --git a/ps5/app/probes.cpp b/ps5/app/probes.cpp
index b5fd4ea..f93bd54 100644
--- a/ps5/app/probes.cpp
+++ b/ps5/app/probes.cpp
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#include "probes.hpp"
+#include "log.hpp"
#include "fetch.hpp"
#include "storage.hpp"
@@ -34,9 +35,9 @@ void probe_fetch(std::string url) {
if (out) {
std::fclose(out);
}
- std::printf("ps5lm-app: fetch %s: status %d, length %lld, %llu bytes in %.1f s (%.2f MB/s)%s%s\n", url.c_str(),
- r.status, (long long) r.length, (unsigned long long) r.bytes, r.seconds,
- r.seconds > 0 ? r.bytes / 1e6 / r.seconds : 0.0, r.error.empty() ? "" : ", ", r.error.c_str());
+ ps5lm::log_line("fetch %s: status %d, length %lld, %llu bytes in %.1f s (%.2f MB/s)%s%s\n", url.c_str(),
+ r.status, (long long) r.length, (unsigned long long) r.bytes, r.seconds,
+ r.seconds > 0 ? r.bytes / 1e6 / r.seconds : 0.0, r.error.empty() ? "" : ", ", r.error.c_str());
}
// Probe: how fast the app can write, by method and place, fsync included
@@ -84,12 +85,12 @@ void probe_write() {
}
}
const double s = std::chrono::duration<double>(std::chrono::steady_clock::now() - t0).count();
- std::printf("ps5lm-app: write-bench %s %s: %s, %.1f MB/s\n", dir.c_str(), m.name, ok ? "ok" : strerror(errno),
- ok ? total / 1e6 / s : 0.0);
+ ps5lm::log_line("write-bench %s %s: %s, %.1f MB/s\n", dir.c_str(), m.name, ok ? "ok" : strerror(errno),
+ ok ? total / 1e6 / s : 0.0);
unlink(path.c_str());
}
}
- std::printf("ps5lm-app: write-bench done\n");
+ ps5lm::log_line("write-bench done\n");
}
// The read probe's pieces, on one thread or several: random offsets in the
@@ -149,12 +150,12 @@ ReadResult read_random(int fd, uint64_t size, size_t piece, int threads, double
void probe_read(std::string path) {
struct stat st = {};
if (stat(path.c_str(), &st) != 0 || st.st_size < (256ll << 20)) {
- std::printf("ps5lm-app: read-bench %s: %s\n", path.c_str(),
- st.st_size ? "under 256 MiB; give it a model of several GiB" : strerror(errno));
+ ps5lm::log_line("read-bench %s: %s\n", path.c_str(),
+ st.st_size ? "under 256 MiB; give it a model of several GiB" : strerror(errno));
return;
}
const uint64_t size = (uint64_t) st.st_size;
- std::printf("ps5lm-app: read-bench %s, %.2f GiB (%s)\n", path.c_str(), size / 1073741824.0, drive_name(path).c_str());
+ ps5lm::log_line("read-bench %s, %.2f GiB (%s)\n", path.c_str(), size / 1073741824.0, drive_name(path).c_str());
// Sequentially, 8 MiB at a time, up to 2 GiB from the start.
{
const int fd = open(path.c_str(), O_RDONLY);
@@ -170,8 +171,8 @@ void probe_read(std::string path) {
done += (uint64_t) got;
}
const double s = std::chrono::duration<double>(std::chrono::steady_clock::now() - t0).count();
- std::printf("ps5lm-app: read-bench sequential 8 MiB: %.2f GiB in %.1f s, %.0f MB/s\n", done / 1073741824.0, s,
- s > 0 ? done / 1e6 / s : 0.0);
+ ps5lm::log_line("read-bench sequential 8 MiB: %.2f GiB in %.1f s, %.0f MB/s\n", done / 1073741824.0, s,
+ s > 0 ? done / 1e6 / s : 0.0);
if (fd >= 0) {
close(fd);
}
@@ -181,22 +182,22 @@ void probe_read(std::string path) {
for (const bool direct : { false, true }) {
const int fd = open(path.c_str(), O_RDONLY | (direct ? O_DIRECT : 0));
if (fd < 0) {
- std::printf("ps5lm-app: read-bench %s: cannot open (%s)\n", direct ? "O_DIRECT" : "cached", strerror(errno));
+ ps5lm::log_line("read-bench %s: cannot open (%s)\n", direct ? "O_DIRECT" : "cached", strerror(errno));
continue;
}
for (const size_t piece : { (size_t) 64 << 10, (size_t) 256 << 10, (size_t) 1 << 20, (size_t) 4 << 20 }) {
for (const int threads : { 1, 4 }) {
const ReadResult r = read_random(fd, size, piece, threads, 3.0);
const size_t n = r.ms.size();
- std::printf("ps5lm-app: read-bench random %s %4zu KiB x%d: %.0f MB/s, %.0f reads/s, %.2f ms median, %.2f ms p99%s%s\n",
- direct ? "O_DIRECT" : "cached ", piece >> 10, threads, r.seconds > 0 ? r.bytes / 1e6 / r.seconds : 0.0,
- r.seconds > 0 ? n / r.seconds : 0.0, n ? r.ms[n / 2] : 0.0, n ? r.ms[std::min(n - 1, n * 99 / 100)] : 0.0,
- r.err ? ", stopped: " : "", r.err ? strerror(r.err) : "");
+ ps5lm::log_line("read-bench random %s %4zu KiB x%d: %.0f MB/s, %.0f reads/s, %.2f ms median, %.2f ms p99%s%s\n",
+ direct ? "O_DIRECT" : "cached ", piece >> 10, threads, r.seconds > 0 ? r.bytes / 1e6 / r.seconds : 0.0,
+ r.seconds > 0 ? n / r.seconds : 0.0, n ? r.ms[n / 2] : 0.0, n ? r.ms[std::min(n - 1, n * 99 / 100)] : 0.0,
+ r.err ? ", stopped: " : "", r.err ? strerror(r.err) : "");
}
}
close(fd);
}
- std::printf("ps5lm-app: read-bench done\n");
+ ps5lm::log_line("read-bench done\n");
}
void probe_memory(bool model_loaded) {
@@ -207,12 +208,12 @@ void probe_memory(bool model_loaded) {
sceKernelAvailableDirectMemorySize(0, pool, 2u << 20, &start, &largest);
sceKernelConfiguredFlexibleMemorySize(&flex);
sceKernelAvailableFlexibleMemorySize(&flex_free);
- std::printf("ps5lm-app: memory-probe: direct pool %.4f GiB (the system keeps %.4f GiB of a nominal 12), largest free "
- "block %.2f GiB at 0x%llx; flexible %zu MiB, %zu MiB free\n",
- pool / 1073741824.0, 12.0 - pool / 1073741824.0, largest / 1073741824.0, (unsigned long long) start,
- flex >> 20, flex_free >> 20);
+ ps5lm::log_line("memory-probe: direct pool %.4f GiB (the system keeps %.4f GiB of a nominal 12), largest free "
+ "block %.2f GiB at 0x%llx; flexible %zu MiB, %zu MiB free\n",
+ pool / 1073741824.0, 12.0 - pool / 1073741824.0, largest / 1073741824.0, (unsigned long long) start,
+ flex >> 20, flex_free >> 20);
if (model_loaded) {
- std::printf("ps5lm-app: memory-probe: a model is loaded; not allocating (unload it to measure the usable block)\n");
+ ps5lm::log_line("memory-probe: a model is loaded; not allocating (unload it to measure the usable block)\n");
return;
}
// The largest block that really allocates and maps, in 64 MiB steps down
@@ -232,11 +233,11 @@ void probe_memory(bool model_loaded) {
sceKernelMunmap(addr, len);
}
sceKernelReleaseDirectMemory(phys, len);
- std::printf("ps5lm-app: memory-probe: allocated %.2f GiB in one block%s\n", len / 1073741824.0,
- mapped == 0 ? ", mapped and touched" : ", but mapping it failed");
+ ps5lm::log_line("memory-probe: allocated %.2f GiB in one block%s\n", len / 1073741824.0,
+ mapped == 0 ? ", mapped and touched" : ", but mapping it failed");
return;
}
- std::printf("ps5lm-app: memory-probe: no 64 MiB block allocates\n");
+ ps5lm::log_line("memory-probe: no 64 MiB block allocates\n");
#else
(void) model_loaded;
#endif
diff --git a/ps5/app/report_test.cpp b/ps5/app/report_test.cpp
index 1986af9..8cdd8cb 100644
--- a/ps5/app/report_test.cpp
+++ b/ps5/app/report_test.cpp
@@ -32,6 +32,9 @@ int main() {
expect("-m model.gguf --api-key=abc --port 8081", "-m model.gguf --api-key=[removed] --port 8081");
expect("ps5lm-app: arg --api-key\nps5lm-app: arg hunter2\nps5lm-app: arg --port",
"ps5lm-app: arg --api-key\nps5lm-app: arg [removed]\nps5lm-app: arg --port");
+ // The same with the time app.log puts in front of every line (#40).
+ expect("22:56:01 ps5lm-app: arg --api-key\n22:56:01 ps5lm-app: arg hunter2\n22:56:01 ps5lm-app: arg --port",
+ "22:56:01 ps5lm-app: arg --api-key\n22:56:01 ps5lm-app: arg [removed]\n22:56:01 ps5lm-app: arg --port");
expect("--hf-token\nhf_abcdefghijklmnopqrstuvwxyz0123456789\n-m\nx.gguf", "--hf-token\n[removed]\n-m\nx.gguf");
expect("--api-key-file /data/PS5LM/key.txt", "--api-key-file [removed]");
diff --git a/ps5/app/stats.cpp b/ps5/app/stats.cpp
index eeb2add..9ce8725 100644
--- a/ps5/app/stats.cpp
+++ b/ps5/app/stats.cpp
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#include "stats.hpp"
+#include "log.hpp"
+#include "storage.hpp"
#include <arpa/inet.h>
#include <netinet/in.h>
@@ -394,8 +396,8 @@ void StatsCollector::run() {
logged = true;
int t0 = -1000, t1 = -1000;
const int r0 = sceKernelGetSocSensorTemperature(0, &t0), r1 = sceKernelGetCpuTemperature(&t1);
- std::printf("ps5lm-app: sensors: soc rc 0x%x t %d, cpu rc 0x%x t %d, power raw %llu, cpu hz %ld\n", r0, t0,
- r1, t1, (unsigned long long) raw[0], hz);
+ ps5lm::log_line("sensors: soc rc 0x%x t %d, cpu rc 0x%x t %d, power raw %llu, cpu hz %ld\n", r0, t0,
+ r1, t1, (unsigned long long) raw[0], hz);
}
#endif
// A title may not read the sensors (0x80020002); a payload may.
@@ -409,9 +411,9 @@ void StatsCollector::run() {
// Not running: hand the bundled copy to elfldr, at start and then
// once a minute (elfldr may come later).
if (p.empty() && (long) (wall - start) % 60 == 1) {
- const bool sent = send_payload("/app0/payloads/ps5-exporter.elf", 9021);
- std::printf("ps5lm-app: ps5-exporter not running; %s\n",
- sent ? "sent the bundled copy to elfldr" : "no elfldr on 9021 to load it");
+ const bool sent = send_payload(sandbox_path("/app0/payloads/ps5-exporter.elf").c_str(), 9021);
+ ps5lm::log_line("ps5-exporter not running; %s\n",
+ sent ? "sent the bundled copy to elfldr" : "no elfldr on 9021 to load it");
}
if (!p.empty()) {
from_exporter = true;
diff --git a/ps5/app/storage.cpp b/ps5/app/storage.cpp
index c1ad08d..9a7ae36 100644
--- a/ps5/app/storage.cpp
+++ b/ps5/app/storage.cpp
@@ -2,23 +2,59 @@
#include "storage.hpp"
#include <algorithm>
+#include <cstdio>
#include <cstdlib>
#include <filesystem>
#include <fstream>
#include <sstream>
+#include <unistd.h>
namespace ps5lm {
namespace {
std::string g_root = kFullRoot;
+std::string g_sandbox; // "" in the sandbox, else "/mnt/sandbox/<title id>_<slot>"
constexpr const char * kParam = "/app0/sce_sys/param.json";
constexpr const char * kChoice = "/download0/PS5LM/storage-choice";
constexpr uint64_t kDefaultSize = 16ull << 30;
+std::string read_param() {
+ std::stringstream text;
+ text << std::ifstream(g_sandbox + kParam).rdbuf();
+ return text.str();
+}
+
} // namespace
+std::string title_id() {
+ // "titleId": "PPSA99575"
+ const std::string json = read_param();
+ const size_t key = json.find("\"titleId\"");
+ const size_t colon = key == std::string::npos ? key : json.find(':', key);
+ const size_t open = colon == std::string::npos ? colon : json.find('"', colon);
+ const size_t close = open == std::string::npos ? open : json.find('"', open + 1);
+ return close == std::string::npos ? "PPSA99575" : json.substr(open + 1, close - open - 1);
+}
+
+void find_sandbox(const std::string & title) {
+ g_sandbox.clear();
+ if (access("/app0/eboot.bin", F_OK) == 0) {
+ return;
+ }
+ for (int slot = 0; slot <= 50; ++slot) {
+ char root[96];
+ std::snprintf(root, sizeof(root), "/mnt/sandbox/%s_%03d", title.c_str(), slot);
+ if (access((std::string(root) + "/app0/eboot.bin").c_str(), F_OK) == 0) {
+ g_sandbox = root;
+ return;
+ }
+ }
+}
+
+std::string sandbox_path(const std::string & path) { return g_sandbox + path; }
+
void set_data_root(const std::string & root) { g_root = root; }
const std::string & data_root() { return g_root; }
@@ -42,9 +78,7 @@ uint64_t folder_bytes(const std::string & path) {
uint64_t app_storage_size() {
// "downloadDataSize": 16384, in MiB.
static const uint64_t size = [] {
- std::stringstream text;
- text << std::ifstream(kParam).rdbuf();
- const std::string json = text.str();
+ const std::string json = read_param();
const size_t key = json.find("\"downloadDataSize\"");
const size_t colon = key == std::string::npos ? key : json.find(':', key);
const uint64_t mib = colon == std::string::npos ? 0 : std::strtoull(json.c_str() + colon + 1, nullptr, 10);
@@ -54,7 +88,7 @@ uint64_t app_storage_size() {
}
// Everything in /download0 counts, the HEN's request file and the app's notes included.
-uint64_t app_storage_used() { return folder_bytes("/download0"); }
+uint64_t app_storage_used() { return folder_bytes(sandbox_path("/download0")); }
double app_storage_free_gib() {
const uint64_t size = app_storage_size(), used = app_storage_used();
@@ -63,19 +97,19 @@ double app_storage_free_gib() {
std::string drive_name(const std::string & path) {
return path.rfind("/mnt/ext", 0) == 0 ? "M.2 drive" : path.rfind("/mnt/usb", 0) == 0 ? "USB drive"
- : path.rfind("/download0", 0) == 0 ? "App storage" : "Internal storage";
+ : path.rfind("/download0", 0) == 0 || path.rfind("/mnt/sandbox/", 0) == 0 ? "App storage" : "Internal storage";
}
std::string storage_choice() {
std::string choice;
- std::ifstream(kChoice) >> choice;
+ std::ifstream(sandbox_path(kChoice)) >> choice;
return choice;
}
void set_storage_choice(const std::string & choice) {
std::error_code ec;
- std::filesystem::create_directories(kAppRoot, ec);
- std::ofstream(kChoice) << choice << "\n";
+ std::filesystem::create_directories(sandbox_path(kAppRoot), ec);
+ std::ofstream(sandbox_path(kChoice)) << choice << "\n";
}
} // namespace ps5lm
diff --git a/ps5/app/storage.hpp b/ps5/app/storage.hpp
index 714f73e..bea2304 100644
--- a/ps5/app/storage.hpp
+++ b/ps5/app/storage.hpp
@@ -20,6 +20,16 @@ namespace ps5lm {
constexpr const char * kFullRoot = "/data/PS5LM";
constexpr const char * kAppRoot = "/download0/PS5LM";
+// The title's own folders as this process sees them. In the sandbox they are
+// /app0 (the app as installed) and /download0. OnionHEN answers the request
+// for /data with a full app jailbreak that also moves the process to the real
+// root (kernel_set_proc_rootdir in its daemon_jailbreak.cpp), where they are
+// /mnt/sandbox/<title id>_<slot>/app0 and .../download0. Before this the
+// fonts did not load there and the screen stayed black (#23, #32).
+std::string title_id(); // from sce_sys/param.json: read it in the sandbox
+void find_sandbox(const std::string & title); // once /data is open, before any thread starts
+std::string sandbox_path(const std::string & path); // "/app0/assets", in the sandbox or out of it
+
// The folder in use, chosen once at start (main.cpp) before any thread reads it.
void set_data_root(const std::string & root);
const std::string & data_root();
diff --git a/scripts/bench-ubatch.py b/scripts/bench-ubatch.py
index 9d73a72..b0255a9 100755
--- a/scripts/bench-ubatch.py
+++ b/scripts/bench-ubatch.py
@@ -100,7 +100,7 @@ def wait_ready(started_after, timeout=1200):
def planner_args(run):
- args = [l.split("ps5lm-app: arg ", 1)[1] for l in run.splitlines() if l.startswith("ps5lm-app: arg ")]
+ args = [l.split("ps5lm-app: arg ", 1)[1] for l in run.splitlines() if "ps5lm-app: arg " in l] # lines start with the time (#40)
out, skip = [], False
for a in args: # what the app adds itself
if skip: