9front - general discussion about 9front
 help / color / mirror / Atom feed
From: ori@eigenstate.org
To: 9front@9front.org, droyo@aqwari.net
Subject: Re: [9front] Speeding up snoopy(8)
Date: Fri, 21 Oct 2022 14:52:38 -0400	[thread overview]
Message-ID: <EBE5F7949AF2DC5CBA636D2DD1B1A4A1@eigenstate.org> (raw)
In-Reply-To: <756d04ac6e8424de@orthanc.ca>

Quoth Lyndon Nerenberg (VE7TFX/VE6BBM) <lyndon@orthanc.ca>:
> This is coming completely out of left field, but ...
> 
> On machines that support atomic 64-bit read/write, would
> it be possible to map a single hardwired non-cacheable
> page into every process's address space and store the
> tick counter there?
> 
> --lyndon

I'm imagining something like (completely untested, just a sketch,
and almost certainly missing some places where the counters need
to be updated):

diff dfee08d50df674cd76f74320bc9c8bc6a4a95f1e uncommitted
--- a//sys/include/tos.h
+++ b//sys/include/tos.h
@@ -17,7 +17,10 @@
 	vlong	kcycles;	/* cycles spent in kernel */
 	vlong	pcycles;	/* cycles spent in process (kernel + user) */
 	ulong	pid;		/* might as well put the pid here */
-	ulong	clock;
+	ulong	clock;		/* profiling clock */
+	vlong	cycles;		/* cycles at last context switch */
+	vlong	tmono;		/* monotonic nsecs since arbitrary start time */
+	vlong	tadj;		/* timesync-adjusted nsecs since epoch */
 	/* top of stack is here */
 };
 
--- a//sys/src/libc/9sys/nsec.c
+++ b//sys/src/libc/9sys/nsec.c
@@ -24,7 +24,25 @@
 	return fd >= 0 && fd2path(fd, buf, sizeof(buf)) == 0 && strcmp(buf, name) == 0;
 }
 
+static vlong
+nsecfast()
+{
+	uvlong t;
+
+	cycles(&t);
+	return tos->tadj + (tos->cycles/tos->cyclefreq);
+}
+
 vlong
+nsecmono()
+{
+	uvlong t;
+
+	cycles(&t);
+	return tos->tmono + (tos->cycles/tos->cyclefreq);
+}
+
+vlong
 nsec(void)
 {
 	static char name[] = "/dev/bintime";
@@ -33,6 +51,8 @@
 	vlong t;
 	int f;
 
+	if(tos->cyclefreq != 0)
+		return nsecfast();
 	if(pidp != nil && *pidp == _tos->pid)
 		f = *fdp;
 	else{
--- a/sys/src/9/port/proc.c
+++ b/sys/src/9/port/proc.c
@@ -132,6 +132,8 @@
 	tos->kcycles += t - up->kentry;
 	tos->pcycles = t + up->pcycles;
 	tos->pid = up->pid;
+	tos->tmono = fastticks2ns(fastticks(nil));
+	tos->tadj = todget();
 }
 
 static void

  reply	other threads:[~2022-10-21 18:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-18  4:57 droyo
2022-10-20 15:55 ` David Arroyo
2022-10-20 16:03   ` Sigrid Solveig Haflínudóttir
2022-10-21 15:38     ` David Arroyo
2022-10-21 16:04       ` ori
2022-10-21 16:54         ` David Arroyo
2022-10-21 17:10           ` ori
2022-10-21 17:40       ` Lyndon Nerenberg (VE7TFX/VE6BBM)
2022-10-21 18:52         ` ori [this message]
2022-10-21 19:23           ` ori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=EBE5F7949AF2DC5CBA636D2DD1B1A4A1@eigenstate.org \
    --to=ori@eigenstate.org \
    --cc=9front@9front.org \
    --cc=droyo@aqwari.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).