--- freem/src/global_bltin.c 2025/04/09 00:43:07 1.12
+++ freem/src/global_bltin.c 2025/04/09 19:52:02 1.14
@@ -1,5 +1,5 @@
/*
- * $Id: global_bltin.c,v 1.12 2025/04/09 00:43:07 snw Exp $
+ * $Id: global_bltin.c,v 1.14 2025/04/09 19:52:02 snw Exp $
* freem database engine
*
*
@@ -24,6 +24,12 @@
* along with FreeM. If not, see .
*
* $Log: global_bltin.c,v $
+ * Revision 1.14 2025/04/09 19:52:02 snw
+ * Eliminate as many warnings as possible while building with -Wall
+ *
+ * Revision 1.13 2025/04/09 14:34:30 snw
+ * Further work on global_bltin.c refactor
+ *
* Revision 1.12 2025/04/09 00:43:07 snw
* Exit with fatal error if a header mismatch found
*
@@ -69,6 +75,8 @@
#include "global_bltin.h"
global_handle *global_handles_head;
+unsigned long gbl_cache_misses = 0;
+unsigned long gbl_cache_hits = 0;
static void b_free (short filedes, unsigned long blknbr);
static void splitp (global_handle *g, char *block, long *addr, long *offs, unsigned long *blknbr);
@@ -129,19 +137,14 @@ static void panic (void);
inline long gbl_path(char *key, char *buf)
{
long savj;
- long savch; /* saved j and ch for multiple pathes */
register long int i;
register long int j;
register long int k;
register long int ch;
- long pathscan; /* flag for repeated scan of pathlist setting an undef global */
/* construct full UNIX filename */
savj = 0;
- savch = ch = EOL;
- pathscan = TRUE;
-nextpath:
k = 0;
j = savj;
@@ -165,8 +168,6 @@ nextpath:
}
}
-
- if (savj == 0 && ch == EOL) pathscan = FALSE; /* one path only: inhibit search */
if (k > 0) {
@@ -179,7 +180,6 @@ nextpath:
}
- savch = ch;
savj = j;
i = 0;
j = 0;
@@ -212,6 +212,19 @@ nextpath:
return i;
} /* gbl_path() */
+void gbl_cache_hit(global_handle *g)
+{
+ g->cache_hits++;
+ gbl_cache_hits++;
+} /* gbl_cache_hit() */
+
+void gbl_cache_miss(global_handle *g)
+{
+ g->fast_path = 0;
+ g->cache_misses++;
+ gbl_cache_misses++;
+} /* gbl_cache_miss() */
+
int gbl_lock(global_handle *g, int type)
{
if (g->locked == TRUE || lonelyflag == TRUE) {
@@ -220,6 +233,8 @@ int gbl_lock(global_handle *g, int type)
locking (g->fd, type, 0L);
g->locked = TRUE;
+
+ return TRUE;
} /* gbl_lock() */
int gbl_unlock(global_handle *g)
@@ -230,6 +245,8 @@ int gbl_unlock(global_handle *g)
locking (g->fd, 0, 0L);
g->locked = FALSE;
+
+ return TRUE;
} /* gbl_unlock() */
void gbl_close(global_handle *g)
@@ -379,7 +396,8 @@ int gbl_create(global_handle *g)
g->age = time (0L);
g->last_block = 0;
g->use_count = 1;
-
+ g->fast_path = 0;
+
gbl_write_initial_header (g);
return OK;
@@ -390,6 +408,7 @@ short gbl_open(global_handle *g, short a
int result;
if (g->opened == FALSE) {
+ gbl_cache_miss (g);
while (1) {
errno = 0;
g->fd = open (g->global_path, 2);
@@ -455,8 +474,6 @@ global_handle *gbl_handle(char *key)
global_handle *g;
char global_name[256];
int i;
- long path_len;
- char block[BLOCKLEN];
struct stat dinf;
i = 0;
@@ -497,6 +514,8 @@ global_handle *gbl_handle(char *key)
g->opened = FALSE;
g->fd = 0;
g->fast_path = -1;
+ g->cache_misses = 0;
+ g->cache_hits = 0;
strcpy (g->global_name, global_name);
gbl_path (key, g->global_path);
@@ -591,7 +610,6 @@ void global_bltin (short action, char *k
unsigned long hdr_offset;
/* these must be static variables */
- static short filedes; /* filedescr for global access */
static char filnam[256]; /* name of global/unix file */
/* the following vars may be */
@@ -620,15 +638,10 @@ void global_bltin (short action, char *k
int iresult;
- struct stat dinf; /* get modification date */
-
- long savj;
- long savch; /* saved j and ch for multiple pathes */
register long int i;
register long int j;
register long int k;
register long int ch;
- long pathscan; /* flag for repeated scan of pathlist setting an undef global */
hdr_offset = sizeof (global_header);
@@ -1042,13 +1055,16 @@ reopen:
/* odd numbered actions get read access (get_sym,data,fra_order) 3 */
/* even ones read/write access (set_sym,kill_sym) 1 */
+/* temporarily disabled
lock:
+*/
if (action == get_sym) {
tfast0:
gbl_lock (g, 3);
- if (tryfast) goto tfast1; /* try again last block */
+
+ if (g->fast_path > 0) goto tfast1; /* try again last block */
blknbr = g->last_block = ROOT; /* start with ROOT block */
@@ -1060,9 +1076,9 @@ tfast1:
lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);
read (g->fd, block, BLOCKLEN);
-
+/* temporarily disabled
tfast2:
-
+*/
if ((typ = block[BTYP]) == DATA) { /* scan data block: here we test for equality only */
offset = UNSIGN (block[OFFS]) * 256 +
@@ -1079,20 +1095,10 @@ tfast2:
j = UNSIGN (block[i++]); /* length of key - offset */
k = UNSIGN (block[i++]); /* offset into previous entry */
-#ifdef VERSNEW
-
- stcpy0 (&key0[k], &block[i], j);
- i += j;
- j += k;
-
-#else
-
j += k;
while (k < j) key1[k++] = block[i++]; /* get key */
-#endif /* VERSNEW */
-
if (j != ch) { /* keys have different length */
i += UNSIGN (block[i]);
@@ -1126,7 +1132,7 @@ tfast2:
/* fast access failed. try normal path */
if (tryfast) {
- tryfast = FALSE;
+ gbl_cache_miss (g);
goto tfast0;
}
@@ -1137,8 +1143,8 @@ tfast2:
}
else {
- if (tryfast) {
- tryfast = FALSE;
+ if (g->fast_path > 0) {
+ gbl_cache_miss (g);
goto tfast0;
}
@@ -1168,6 +1174,7 @@ tfast2:
addr += PLEN; /* skip data */
g->last_block = blknbr;
+ g->fast_path = 1;
if (merr () == INRPT) goto quit;
@@ -1246,6 +1253,7 @@ k_again: /* entry point for repeated
addr += PLEN; /* skip data */
g->last_block = blknbr;
+ g->fast_path = 1;
}
traceadr[trx] = addr;
@@ -3729,14 +3737,37 @@ static void panic (void)
void gbl_dump_stat(void)
{
global_handle *g;
+ int ct;
+ int miss_pct;
+ int hit_pct;
+ unsigned long access_total;
+ unsigned long hit_total;
- printf ("FreeM Global Statistics [PID %d]\r\n", pid);
+ printf ("\r\nFreeM Global Statistics [PID %d]\r\n\r\n", pid);
- printf ("%-20s%-10s%-20s%-10s%s\r\n", "GLOBAL", "USECT", "AGE", "LAST BLK", "FILE");
- printf ("%-20s%-10s%-20s%-10s%s\r\n", "======", "=====", "===", "========", "====");
-
+ printf ("%-20s%-10s%-12s%-20s%-10s%s\r\n", "GLOBAL", "USECT", "SLOW PTHCT", "AGE", "LAST BLK", "FILE");
+ printf ("%-20s%-10s%-12s%-20s%-10s%s\r\n", "======", "=====", "==========", "===", "========", "====");
+
+ access_total = 0;
+ ct = 0;
for (g = global_handles_head; g != NULL; g = g->next) {
- printf ("%-20s%-10d%-20d%-10d%s\r\n", g->global_name, g->use_count, g->age, g->last_block, g->global_path);
- }
-
+ printf ("%-20s%-10ld%-12ld%-20ld%-10ld%s\r\n",
+ g->global_name,
+ g->use_count,
+ g->cache_misses,
+ g->age,
+ g->last_block,
+ g->global_path);
+ ct++;
+ access_total += g->use_count;
+ }
+ if (!ct) printf ("\r\n");
+
+ hit_total = access_total - gbl_cache_misses;
+ miss_pct = (gbl_cache_misses * 100) / access_total;
+ hit_pct = (hit_total * 100) / access_total;
+
+ printf ("\r\nTotal accesses: %ld\r\n", access_total);
+ printf ("Fast path hits %ld\t(%d%%)\r\n", hit_total, hit_pct);
+ printf ("Fast path misses: %ld\t(%d%%)\r\n", gbl_cache_misses, miss_pct);
}