From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 20566 invoked from network); 21 Oct 2022 18:54:06 -0000 Received: from 9front.inri.net (168.235.81.73) by inbox.vuxu.org with ESMTPUTF8; 21 Oct 2022 18:54:06 -0000 Received: from mimir.eigenstate.org ([206.124.132.107]) by 9front; Fri Oct 21 14:52:41 -0400 2022 Received: from abbatoir (pool-108-27-53-161.nycmny.fios.verizon.net [108.27.53.161]) by mimir.eigenstate.org (OpenSMTPD) with ESMTPSA id 63b93f9b (TLSv1.2:ECDHE-RSA-AES256-SHA:256:NO); Fri, 21 Oct 2022 11:52:40 -0700 (PDT) Message-ID: To: 9front@9front.org, droyo@aqwari.net Date: Fri, 21 Oct 2022 14:52:38 -0400 From: ori@eigenstate.org In-Reply-To: <756d04ac6e8424de@orthanc.ca> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: distributed map/reduce proxy hosting-aware database Subject: Re: [9front] Speeding up snoopy(8) Reply-To: 9front@9front.org Precedence: bulk Quoth Lyndon Nerenberg (VE7TFX/VE6BBM) : > 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