summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSean Kurtz <seankurtz75@gmail.com>2026-11-25 22:12:07 -0600
committerSean Kurtz <seankurtz75@gmail.com>2026-11-25 22:12:07 -0600
commitcef8eb44791f24b3d50006690960dce84779cfea (patch)
treef42128872eb35cda4f861ece179ef649aae9f36b
parent9742cd9ab2d7cbc579b349da59717d0ef4c85cc2 (diff)
downloadztop-cef8eb44791f24b3d50006690960dce84779cfea.tar.gz
ztop: system IPL and storage, a paging view, a 10 second refresh
-rw-r--r--.gitignore1
-rw-r--r--Makefile4
-rw-r--r--compile_flags.txt1
-rw-r--r--src/sys.c80
-rw-r--r--src/sys.h58
-rw-r--r--src/ztop.c106
-rw-r--r--tests/test_sys.c37
7 files changed, 265 insertions, 22 deletions
diff --git a/.gitignore b/.gitignore
index a363abd..f2ed478 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,4 @@ tui/demo
CEEDUMP.*
*.lst
compile_commands.json
+tests/test_sys
diff --git a/Makefile b/Makefile
index 54d300c..b8ddc54 100644
--- a/Makefile
+++ b/Makefile
@@ -65,9 +65,11 @@ check: ztop
./ztop -a pvt
./ztop -j
-test: tests/test_vsm.c src/vsm.c tui/test_tui.c tui/tui.c
+test: tests/test_vsm.c tests/test_sys.c src/vsm.c src/sys.c tui/test_tui.c tui/tui.c
$(TESTCC) $(TESTFLAGS) -o tests/test_vsm tests/test_vsm.c src/vsm.c
./tests/test_vsm
+ $(TESTCC) $(TESTFLAGS) -Isrc -o tests/test_sys tests/test_sys.c src/sys.c
+ ./tests/test_sys
$(TESTCC) $(TESTFLAGS) -Itui -o tui/test_tui tui/test_tui.c tui/tui.c
./tui/test_tui
diff --git a/compile_flags.txt b/compile_flags.txt
index a064bfc..77b66bc 100644
--- a/compile_flags.txt
+++ b/compile_flags.txt
@@ -2,3 +2,4 @@
-std=c23
-D_XOPEN_SOURCE=500
-D_POSIX_C_SOURCE=200112L
+-Isrc
diff --git a/src/sys.c b/src/sys.c
index 086da2d..6618841 100644
--- a/src/sys.c
+++ b/src/sys.c
@@ -32,6 +32,11 @@ static uint16_t rd16(uintptr_t a) {
return v;
}
+/** @brief Read one byte from an absolute address. */
+static unsigned char rd8(uintptr_t a) {
+ return *(const unsigned char *)a;
+}
+
/** @brief Copy an EBCDIC field and trim its blanks.
*
* The program runs in EBCDIC mode, and the terminal converts on output,
@@ -50,6 +55,47 @@ static void ebcdic(char *dst, size_t dstlen, const void *src, size_t srclen) {
}
#endif
+/** @brief One nibble of a packed-decimal field. */
+static unsigned int nib(uint32_t v, unsigned int shift) {
+ return (v >> shift) & 0xFu;
+}
+
+bool zipl_decode(uint32_t date, uint32_t hundredths, struct zipl *out) {
+ static const unsigned int mdays[12] = {
+ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
+ };
+ unsigned int century = nib(date, 24);
+ unsigned int yy = nib(date, 20) * 10 + nib(date, 16);
+ unsigned int ddd = nib(date, 12) * 100 + nib(date, 8) * 10 + nib(date, 4);
+ unsigned int year, leap, secs, month = 0, day;
+
+ if (century > 1 || ddd == 0 || ddd > 366)
+ return false;
+ year = (century == 1 ? 2000u : 1900u) + yy;
+ leap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) ? 1u : 0u;
+ if (ddd > 365 + leap)
+ return false;
+ secs = hundredths / 100;
+ if (hundredths % 100 > 99 || secs >= 24 * 3600)
+ return false;
+
+ day = ddd;
+ for (month = 0; month < 12; month++) {
+ unsigned int len = mdays[month] + (month == 1 ? leap : 0);
+
+ if (day <= len)
+ break;
+ day -= len;
+ }
+ out->year = year;
+ out->month = month + 1;
+ out->day = day;
+ out->hour = secs / 3600;
+ out->minute = (secs / 60) % 60;
+ out->second = secs % 60;
+ return true;
+}
+
bool zsys_read(struct zsys *z) {
#ifdef __MVS__
uintptr_t cvt, asvt;
@@ -81,9 +127,43 @@ bool zsys_read(struct zsys *z) {
if (j->name[0] != '\0')
z->njobs++;
}
+ z->cvt = (uint32_t)cvt;
+ z->smca = rd32(cvt + 0xC4);
+ z->real_k = rd32(cvt + 0x358);
+ if (z->smca != 0)
+ z->ipl_ok = zipl_decode(rd32((uintptr_t)z->smca + 340),
+ rd32((uintptr_t)z->smca + 336), &z->ipl);
return true;
#else
(void)z;
return false;
#endif
}
+
+bool zpage_read(struct zpage *p) {
+#ifdef __MVS__
+ uintptr_t cvt = rd32(0x10);
+ uintptr_t asmvt;
+
+ memset(p, 0, sizeof *p);
+ if (cvt == 0)
+ return false;
+ asmvt = rd32(cvt + 0x2C0);
+ if (asmvt == 0)
+ return false;
+ p->asmvt = (uint32_t)asmvt;
+ p->common_pds = (rd8(asmvt) & 0x80u) != 0;
+ p->local_paging = (rd8(asmvt) & 0x20u) == 0;
+ p->plpa_pds = (rd8(asmvt) & 0x08u) != 0;
+ p->plpa_full = (rd8(asmvt) & 0x04u) != 0;
+ p->common_full = (rd8(asmvt) & 0x02u) != 0;
+ p->quick_start = (rd8(asmvt + 1) & 0x10u) != 0;
+ p->warm_start = (rd8(asmvt + 1) & 0x08u) != 0;
+ p->vio_journaling = (rd8(asmvt + 0xB8) & 0x10u) != 0;
+ p->vio_ci = rd32(asmvt + 0x8C);
+ return true;
+#else
+ (void)p;
+ return false;
+#endif
+}
diff --git a/src/sys.h b/src/sys.h
index e55c195..c52ee42 100644
--- a/src/sys.h
+++ b/src/sys.h
@@ -1,11 +1,12 @@
/**
* @file sys.h
- * @brief The system's name and its address spaces, from the CVT and ASVT.
+ * @brief The system's identity, its IPL, its storage and its address spaces.
*
- * Both are documented programming interfaces: CVTASVT at CVT+0x22C, the
- * ASVT with ASVTMAXU at +0x204 and ASVTENTY at +0x210, and the ASCB
- * fields ASCBASID, ASCBJBNS. Reading them needs only problem state, so
- * this is the jobs view without an authorized service.
+ * Everything here is a documented programming interface reached from the
+ * CVT at PSA+0x10: CVTSNAME, CVTSMCA, CVTRLSTG, CVTASMVT and CVTASVT, the
+ * ASVT/ASCB chain, and the SMCA and ASMVT control blocks behind them.
+ * Reading them needs only problem state, so none of this needs an
+ * authorized service.
*/
#ifndef ZTOP_SYS_H
#define ZTOP_SYS_H
@@ -22,6 +23,16 @@ struct zjob {
char name[9];
};
+/** @brief The IPL date and time, decoded from the SMCA. */
+struct zipl {
+ unsigned int year;
+ unsigned int month;
+ unsigned int day; /**< day of month */
+ unsigned int hour;
+ unsigned int minute;
+ unsigned int second;
+};
+
/** @brief What the system view shows. */
struct zsys {
char sysname[9];
@@ -31,13 +42,48 @@ struct zsys {
unsigned int slots; /**< ASVT entries, used or free */
int njobs;
struct zjob job[ZJOB_MAX];
+ bool ipl_ok;
+ struct zipl ipl;
+ uint64_t real_k; /**< real storage online at IPL, in K */
+ uint32_t cvt;
+ uint32_t smca;
};
/**
- * @brief Fill @p z from the CVT and the ASVT.
+ * @brief Decode SMCAIDTE (0CYYDDDF, packed) and SMCAITME (hundredths).
+ * @param date SMCAIDTE as read.
+ * @param hundredths SMCAITME as read.
+ * @param out Where to write.
+ * @return false when the fields do not describe a real date and time.
+ */
+bool zipl_decode(uint32_t date, uint32_t hundredths, struct zipl *out);
+
+/**
+ * @brief Fill @p z from the CVT, the SMCA and the ASVT.
* @param z Where to write.
* @return false when this is not z/OS, with @c z untouched.
*/
bool zsys_read(struct zsys *z);
+/** @brief Auxiliary storage state, from the ASMVT. */
+struct zpage {
+ bool common_pds; /**< a common page data set exists */
+ bool common_full;
+ bool plpa_pds;
+ bool plpa_full;
+ bool local_paging; /**< local page data sets are in use */
+ bool vio_journaling;
+ bool quick_start;
+ bool warm_start;
+ unsigned int vio_ci; /**< control intervals in the VIO journal */
+ uint32_t asmvt;
+};
+
+/**
+ * @brief Fill @p p from the ASMVT.
+ * @param p Where to write.
+ * @return false when this is not z/OS or there is no ASMVT.
+ */
+bool zpage_read(struct zpage *p);
+
#endif
diff --git a/src/ztop.c b/src/ztop.c
index b49b3ac..14263c4 100644
--- a/src/ztop.c
+++ b/src/ztop.c
@@ -245,6 +245,20 @@ static void print_system(const struct zsys *z) {
(void)printf(
"system %s host %s os %s machine %s address spaces %d/%u\n",
z->sysname, z->host, z->os, z->machine, z->njobs, z->slots);
+ if (z->ipl_ok)
+ (void)printf("ipl %04u-%02u-%02u %02u:%02u:%02u real storage %llu K\n",
+ z->ipl.year, z->ipl.month, z->ipl.day, z->ipl.hour,
+ z->ipl.minute, z->ipl.second,
+ (unsigned long long)z->real_k);
+}
+
+static void print_page(const struct zpage *p) {
+ (void)printf("aux storage common %s%s plpa %s%s local %s vio %s"
+ ", journal %u\n",
+ p->common_pds ? "yes" : "no", p->common_full ? " full" : "",
+ p->plpa_pds ? "yes" : "no", p->plpa_full ? " full" : "",
+ p->local_paging ? "on" : "off",
+ p->vio_journaling ? "on" : "off", p->vio_ci);
}
static void print_jobs(const struct zsys *z) {
@@ -263,6 +277,9 @@ struct app {
struct zsys sys;
bool have_sys;
char sys_err[160];
+ struct zpage page;
+ bool have_page;
+ char page_err[160];
int interval;
int collect_ms;
bool paused;
@@ -470,6 +487,10 @@ static void collect(struct app *a) {
}
}
sys_read(a);
+ a->have_page = zpage_read(&a->page);
+ if (!a->have_page)
+ (void)snprintf(a->page_err, sizeof a->page_err,
+ "ASMVT is only available on z/OS");
(void)clock_gettime(CLOCK_MONOTONIC, &t1);
a->collect_ms = (int)((t1.tv_sec - t0.tv_sec) * 1000 +
(t1.tv_nsec - t0.tv_nsec) / 1000000);
@@ -490,8 +511,9 @@ static void draw_header(struct tui *t, const struct app *a) {
}
static void draw_tabs(struct tui *t, const struct app *a) {
- static const char *const labels[3] = {"1 STORAGE", "2 SYSTEM", "3 JOBS"};
- int x = tui_tabs_draw(t, 0, 1, labels, 3, a->tab);
+ static const char *const labels[4] = {"1 STORAGE", "2 SYSTEM", "3 JOBS",
+ "4 PAGING"};
+ int x = tui_tabs_draw(t, 0, 1, labels, 4, a->tab);
tui_printf(t, x + 1, 1, t->w - x - 2, TUI_LABEL, "refresh %ds +/-",
a->interval);
@@ -572,14 +594,47 @@ static void draw_system(struct tui *t, const struct app *a) {
tui_printf(t, 1, 7, t->w - 2, TUI_PLAIN, "machine %s", z->machine);
tui_printf(t, 1, 8, t->w - 2, TUI_PLAIN, "spaces %d used, %u slots",
z->njobs, z->slots);
+ if (z->ipl_ok)
+ tui_printf(t, 1, 9, t->w - 2, TUI_PLAIN,
+ "ipl %04u-%02u-%02u %02u:%02u:%02u", z->ipl.year,
+ z->ipl.month, z->ipl.day, z->ipl.hour, z->ipl.minute,
+ z->ipl.second);
+ tui_printf(t, 1, 10, t->w - 2, TUI_PLAIN, "real %llu K online at IPL",
+ (unsigned long long)z->real_k);
tui_printf(
- t, 1, 10, t->w - 2, TUI_LABEL,
+ t, 1, 12, t->w - 2, TUI_LABEL,
"storage CSA %llu unallocated, PVT %llu",
(unsigned long long)(a->info[0].unalloc_valid ? a->info[0].unalloc : 0),
(unsigned long long)(a->info[3].unalloc_valid ? a->info[3].unalloc
: 0));
}
+static void draw_paging(struct tui *t, const struct app *a) {
+ const struct zpage *p = &a->page;
+
+ if (!a->have_page) {
+ tui_printf(t, 1, 4, t->w - 2, TUI_BAD, "%s", a->page_err);
+ return;
+ }
+ tui_printf(t, 1, 4, t->w - 2, TUI_LABEL, "aux storage ASMVT %08X",
+ (unsigned int)p->asmvt);
+ tui_printf(t, 1, 6, t->w - 2, p->common_pds ? TUI_GOOD : TUI_WARN,
+ "common data set %-3s %s", p->common_pds ? "yes" : "no",
+ p->common_full ? "full" : "");
+ tui_printf(t, 1, 7, t->w - 2, p->plpa_pds ? TUI_GOOD : TUI_WARN,
+ "plpa data set %-3s %s", p->plpa_pds ? "yes" : "no",
+ p->plpa_full ? "full" : "");
+ tui_printf(t, 1, 8, t->w - 2, TUI_PLAIN, "local paging %s",
+ p->local_paging ? "on" : "off");
+ tui_printf(t, 1, 9, t->w - 2,
+ p->quick_start || p->warm_start ? TUI_WARN : TUI_PLAIN,
+ "start %s%s", p->quick_start ? "quick" : "cold",
+ p->warm_start ? ", warm VIO" : "");
+ tui_printf(t, 1, 10, t->w - 2, TUI_PLAIN,
+ "vio journal %s, %u control intervals",
+ p->vio_journaling ? "active" : "off", p->vio_ci);
+}
+
static void draw_jobs(struct tui *t, struct app *a) {
tui_rect r = {0, 3, t->w, t->h - 5};
char head[24];
@@ -722,8 +777,10 @@ static void view(void *model, struct tui *t) {
draw_storage(t, a);
} else if (a->tab == 1) {
draw_system(t, a);
- } else {
+ } else if (a->tab == 2) {
draw_jobs(t, a);
+ } else {
+ draw_paging(t, a);
}
if (a->popup)
draw_subpool(t, a);
@@ -733,7 +790,8 @@ static void view(void *model, struct tui *t) {
tui_statusbar(t,
a->tab == 0 ? "TAB view 1-4 area j/k move s sort ? help"
: a->tab == 1 ? "TAB view r refresh ? help"
- : "TAB view j/k move s sort ? help",
+ : a->tab == 2 ? "TAB view j/k move s sort ? help"
+ : "TAB view r refresh ? help",
right);
}
@@ -766,10 +824,12 @@ static bool parse_areas(const char *s, unsigned int *mask) {
static void usage(FILE *f) {
(void)fprintf(
f,
- "usage: ztop [-a csa|sqa|lsqa|pvt|all] [-s] [-j] [-x] [-d [seconds]]\n"
+ "usage: ztop [-a csa|sqa|lsqa|pvt|all] [-s] [-j] [-p] [-x] [-d "
+ "[seconds]]\n"
" -a storage areas to report (default csa); comma-separate or all\n"
- " -s system name, host, release and address-space count\n"
+ " -s system name, host, release, IPL and address-space count\n"
" -j one line per address space\n"
+ " -p auxiliary storage: page data sets, local paging, VIO journal\n"
" -x dump the VSMLIST work and data areas (one-shot only)\n"
" -d force the interactive view (the default on a terminal)\n"
" -h this text\n");
@@ -889,11 +949,11 @@ static bool update(struct tui_app *app, const struct tui_msg *m) {
return true;
}
if (m->key == TUI_KEY_TAB) {
- a->tab = (a->tab + 1) % 3;
+ a->tab = (a->tab + 1) % 4;
return true;
}
if (m->key == TUI_KEY_BACKTAB) {
- a->tab = (a->tab + 2) % 3;
+ a->tab = (a->tab + 3) % 4;
return true;
}
if (a->tab == 0 && m->key >= '1' && m->key <= '4') {
@@ -975,7 +1035,7 @@ static void run_tui(int interval) {
}
static void run_oneshot(unsigned mask, bool want_sys, bool want_jobs,
- bool dump) {
+ bool want_page, bool dump) {
char host[65];
bool printed = false;
int rc = 0;
@@ -996,6 +1056,19 @@ static void run_oneshot(unsigned mask, bool want_sys, bool want_jobs,
print_area(&v);
printed = true;
}
+ if (want_page) {
+ struct zpage p;
+
+ if (!zpage_read(&p)) {
+ (void)fprintf(stderr, "ztop: paging is only available on z/OS\n");
+ rc = 1;
+ } else {
+ if (printed)
+ (void)printf("\n");
+ print_page(&p);
+ printed = true;
+ }
+ }
if (want_sys || want_jobs) {
struct zsys z;
@@ -1028,6 +1101,7 @@ int main(int argc, char **argv) {
bool interactive = false;
bool want_sys = false;
bool want_jobs = false;
+ bool want_page = false;
int interval = 0;
int i;
@@ -1041,6 +1115,8 @@ int main(int argc, char **argv) {
want_sys = true;
} else if (strcmp(argv[i], "-j") == 0) {
want_jobs = true;
+ } else if (strcmp(argv[i], "-p") == 0) {
+ want_page = true;
} else if (strcmp(argv[i], "-a") == 0) {
if (i + 1 >= argc || !parse_areas(argv[++i], &mask)) {
usage(stderr);
@@ -1067,22 +1143,22 @@ int main(int argc, char **argv) {
/* A bare `ztop` on a terminal is the full-screen view; anything that
* selects a report, or a pipe, keeps the one-shot output. */
- if (!interactive && !dump && !want_sys && !want_jobs && mask == 0 &&
- isatty(STDOUT_FILENO))
+ if (!interactive && !dump && !want_sys && !want_jobs && !want_page &&
+ mask == 0 && isatty(STDOUT_FILENO))
interactive = true;
if (interactive) {
if (dump)
(void)fprintf(stderr, "ztop: -x is ignored with -d\n");
if (interval < 1)
- interval = 2;
+ interval = 10;
if (interval > 60)
interval = 60;
run_tui(interval);
} else {
- if (mask == 0 && !want_sys && !want_jobs)
+ if (mask == 0 && !want_sys && !want_jobs && !want_page)
mask = 1u;
- run_oneshot(mask, want_sys, want_jobs, dump);
+ run_oneshot(mask, want_sys, want_jobs, want_page, dump);
}
return 0;
}
diff --git a/tests/test_sys.c b/tests/test_sys.c
new file mode 100644
index 0000000..b807859
--- /dev/null
+++ b/tests/test_sys.c
@@ -0,0 +1,37 @@
+/**
+ * @file test_sys.c
+ * @brief The IPL decoder, against values read from a live SMCA.
+ */
+#include <assert.h>
+#include <stdio.h>
+
+#include "sys.h"
+
+int main(void) {
+ struct zipl z;
+
+ /* CBT, IPLed at 17:02:47 on 21 September 2026 (day 264). */
+ assert(zipl_decode(0x0126264Fu, 6136760u, &z));
+ assert(z.year == 2026 && z.month == 9 && z.day == 21);
+ assert(z.hour == 17 && z.minute == 2 && z.second == 47);
+
+ /* 1926, day 260 (17 September), and 2024, day 260 (16 September):
+ * the century nibble and the leap year both move the answer. */
+ assert(zipl_decode(0x0026260Fu, 0u, &z));
+ assert(z.year == 1926 && z.month == 9 && z.day == 17);
+ assert(zipl_decode(0x0124260Fu, 0u, &z));
+ assert(z.year == 2024 && z.month == 9 && z.day == 16);
+
+ /* 23:59:59.99 is the last second of the day. */
+ assert(zipl_decode(0x0126264Fu, 8639999u, &z));
+ assert(z.hour == 23 && z.minute == 59 && z.second == 59);
+
+ /* Out of range: century 2, day 0, day 366 in a common year, 24:00. */
+ assert(!zipl_decode(0x0226264Fu, 0u, &z));
+ assert(!zipl_decode(0x0126000Fu, 0u, &z));
+ assert(!zipl_decode(0x0126366Fu, 0u, &z));
+ assert(!zipl_decode(0x0126264Fu, 8640000u, &z));
+
+ (void)printf("test_sys: ok\n");
+ return 0;
+}