summaryrefslogtreecommitdiffstats
path: root/sys/dev/syscons/snake
diff options
context:
space:
mode:
authorivoras <ivoras@FreeBSD.org>2010-02-23 15:12:41 +0000
committerivoras <ivoras@FreeBSD.org>2010-02-23 15:12:41 +0000
commitb36002aea70441a1b270a3b2e3fa8bd02bca2838 (patch)
tree4a5e16f3cdea8d19363ff6527ec42f9d1f5bb136 /sys/dev/syscons/snake
parent876d9ec051a15fa648bba75e6ef5380da35930b5 (diff)
downloadFreeBSD-src-b36002aea70441a1b270a3b2e3fa8bd02bca2838.zip
FreeBSD-src-b36002aea70441a1b270a3b2e3fa8bd02bca2838.tar.gz
Upgrade the "snake" syscons screensaver to the new, multimedia version!
Now, with color! And system load averages! Amused by it: gnn
Diffstat (limited to 'sys/dev/syscons/snake')
-rw-r--r--sys/dev/syscons/snake/snake_saver.c55
1 files changed, 49 insertions, 6 deletions
diff --git a/sys/dev/syscons/snake/snake_saver.c b/sys/dev/syscons/snake/snake_saver.c
index bbdcda3..502058f 100644
--- a/sys/dev/syscons/snake/snake_saver.c
+++ b/sys/dev/syscons/snake/snake_saver.c
@@ -36,6 +36,8 @@
#include <sys/sysctl.h>
#include <sys/consio.h>
#include <sys/fbio.h>
+#include <sys/resourcevar.h>
+#include <sys/smp.h>
#include <machine/pc/display.h>
@@ -48,11 +50,22 @@ static int *messagep;
static int messagelen;
static int blanked;
+#define MSGBUF_LEN 70
+
+static int nofancy = 0;
+TUNABLE_INT("hw.syscons.saver_snake_nofancy", &nofancy);
+
+#define FANCY_SNAKE (!nofancy)
+#define LOAD_HIGH(ld) (((ld * 100 + FSCALE / 2) >> FSHIFT) / 100)
+#define LOAD_LOW(ld) (((ld * 100 + FSCALE / 2) >> FSHIFT) % 100)
+
+static inline void update_msg(void);
+
static int
snake_saver(video_adapter_t *adp, int blank)
{
static int dirx, diry;
- int f;
+ int f, color, load;
sc_softc_t *sc;
scr_stat *scp;
@@ -99,22 +112,52 @@ snake_saver(video_adapter_t *adp, int blank)
(random() % 20) == 0)
diry = -diry;
savs[0] += dirx + diry;
+ if (FANCY_SNAKE) {
+ update_msg();
+ load = LOAD_HIGH(averunnable.ldavg[0]) * 100;
+ if (load == 0)
+ color = FG_LIGHTGREY | BG_BLACK;
+ else if (load / mp_ncpus <= 50)
+ color = FG_LIGHTGREEN | BG_BLACK;
+ else if (load / mp_ncpus <= 75)
+ color = FG_YELLOW | BG_BLACK;
+ else if (load / mp_ncpus <= 99)
+ color = FG_LIGHTRED | BG_BLACK;
+ else
+ color = FG_RED | FG_BLINK | BG_BLACK;
+ } else
+ color = FG_LIGHTGREY | BG_BLACK;
+
for (f=messagelen-1; f>=0; f--)
sc_vtb_putc(&scp->scr, savs[f], sc->scr_map[save[f]],
- (FG_LIGHTGREY | BG_BLACK) << 8);
+ color << 8);
} else
blanked = 0;
return 0;
}
+static inline void
+update_msg(void)
+{
+ if (!FANCY_SNAKE) {
+ messagelen = sprintf(message, "%s %s", ostype, osrelease);
+ return;
+ }
+ messagelen = snprintf(message, MSGBUF_LEN,
+ "%s %s (%d.%02d %d.%02d, %d.%02d)",
+ ostype, osrelease,
+ LOAD_HIGH(averunnable.ldavg[0]), LOAD_LOW(averunnable.ldavg[0]),
+ LOAD_HIGH(averunnable.ldavg[1]), LOAD_LOW(averunnable.ldavg[1]),
+ LOAD_HIGH(averunnable.ldavg[2]), LOAD_LOW(averunnable.ldavg[2]));
+}
+
static int
snake_init(video_adapter_t *adp)
{
- messagelen = strlen(ostype) + 1 + strlen(osrelease);
- message = malloc(messagelen + 1, M_DEVBUF, M_WAITOK);
- sprintf(message, "%s %s", ostype, osrelease);
- messagep = malloc(messagelen * sizeof *messagep, M_DEVBUF, M_WAITOK);
+ message = malloc(MSGBUF_LEN, M_DEVBUF, M_WAITOK);
+ messagep = malloc(MSGBUF_LEN * sizeof *messagep, M_DEVBUF, M_WAITOK);
+ update_msg();
return 0;
}
OpenPOWER on IntegriCloud