9front - general discussion about 9front
 help / color / mirror / Atom feed
* Re: [9front] time v2
@ 2018-08-12  5:39 Alex Musolino
  2018-08-12 18:21 ` [9front] time v4 BurnZeZ
  0 siblings, 1 reply; 4+ messages in thread
From: Alex Musolino @ 2018-08-12  5:39 UTC (permalink / raw)
  To: 9front

What's the point of the segattach?  Can you not just add RFMEM to the
rfork flags?

Also, you probably ought to be setting t0 again before the second call
to exec.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9front] time v4
  2018-08-12  5:39 [9front] time v2 Alex Musolino
@ 2018-08-12 18:21 ` BurnZeZ
  0 siblings, 0 replies; 4+ messages in thread
From: BurnZeZ @ 2018-08-12 18:21 UTC (permalink / raw)
  To: 9front

[-- Attachment #1: Type: text/plain, Size: 687 bytes --]

On Sun Aug 12 05:40:12 GMT 2018, alex@musolino.id.au wrote:
> What's the point of the segattach?  Can you not just add RFMEM to the
> rfork flags?
char	output[4096];
output would be shared, and the child process uses it for the exec
path stuff.
I thought about using RFMEM at first, but it ended up being simpler
this way.

> Also, you probably ought to be setting t0 again before the second call
> to exec.
You would miss out on accounting for 9p latency for the first exec()
attempt, but I think you’re right, since the fact that t0 is set
after the fork() indicates we’re not worried about absolute time
from the parent process’ perspective.

Attached diff contains that change.

[-- Attachment #2: Type: text/plain, Size: 1129 bytes --]

diff -r 5c5acc9ab7a5 sys/src/cmd/time.c
--- a/sys/src/cmd/time.c	Sat Aug 11 16:19:32 2018 +0200
+++ b/sys/src/cmd/time.c	Sun Aug 12 18:17:11 2018 +0000
@@ -14,20 +14,27 @@
 	long l;
 	char *p;
 	char err[ERRMAX];
+	vlong *t0, t1;
+	enum { SEC = 1000000000ULL };
 
 	if(argc <= 1){
 		fprint(2, "usage: time command\n");
 		exits("usage");
 	}
 
+	if((t0 = segattach(SG_CEXEC, "shared", nil, sizeof(*t0))) == (void*)-1)
+		sysfatal("segattach: %r");
+	*t0 = 0;
 	switch(fork()){
 	case -1:
 		error("fork");
 	case 0:
+		*t0 = nsec();
 		exec(argv[1], &argv[1]);
 		if(argv[1][0] != '/' && strncmp(argv[1], "./", 2) &&
 		   strncmp(argv[1], "../", 3)){
 			sprint(output, "/bin/%s", argv[1]);
+			*t0 = nsec();
 			exec(output, &argv[1]);
 		}
 		error(argv[1]);
@@ -43,12 +50,14 @@
 			goto loop;
 		error("wait");
 	}
+	t1 = nsec();
 	l = w->time[0];
 	add("%ld.%.2ldu", l/1000, (l%1000)/10);
 	l = w->time[1];
 	add("%ld.%.2lds", l/1000, (l%1000)/10);
 	l = w->time[2];
 	add("%ld.%.2ldr", l/1000, (l%1000)/10);
+	add("%lld.%.9lldt", (t1-*t0)/SEC, (t1-*t0)%SEC);
 	add("\t");
 	for(i=1; i<argc; i++){
 		add("%s", argv[i], 0);

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9front] time v2
  2018-08-11 20:47 [9front] time v2 Kurt H Maier
@ 2018-08-11 21:09 ` BurnZeZ
  0 siblings, 0 replies; 4+ messages in thread
From: BurnZeZ @ 2018-08-11 21:09 UTC (permalink / raw)
  To: 9front

[-- Attachment #1: Type: text/plain, Size: 185 bytes --]

Clearly written by an idiot.
Comparing segattach to -1 will break on architectures where pointers
require more than 32-bits.
(possibly other situations too(?))

Corrected diff attached.

[-- Attachment #2: Type: text/plain, Size: 1019 bytes --]

diff -r 5c5acc9ab7a5 sys/src/cmd/time.c
--- a/sys/src/cmd/time.c	Sat Aug 11 16:19:32 2018 +0200
+++ b/sys/src/cmd/time.c	Sat Aug 11 21:02:13 2018 +0000
@@ -14,16 +14,22 @@
 	long l;
 	char *p;
 	char err[ERRMAX];
+	vlong *t0, t1;
+	enum { SEC = 1000000000ULL };
 
 	if(argc <= 1){
 		fprint(2, "usage: time command\n");
 		exits("usage");
 	}
 
+	if((t0 = segattach(SG_CEXEC, "shared", nil, sizeof(*t0))) == (void*)-1)
+		sysfatal("segattach: %r");
+	*t0 = 0;
 	switch(fork()){
 	case -1:
 		error("fork");
 	case 0:
+		*t0 = nsec();
 		exec(argv[1], &argv[1]);
 		if(argv[1][0] != '/' && strncmp(argv[1], "./", 2) &&
 		   strncmp(argv[1], "../", 3)){
@@ -43,12 +49,14 @@
 			goto loop;
 		error("wait");
 	}
+	t1 = nsec();
 	l = w->time[0];
 	add("%ld.%.2ldu", l/1000, (l%1000)/10);
 	l = w->time[1];
 	add("%ld.%.2lds", l/1000, (l%1000)/10);
 	l = w->time[2];
 	add("%ld.%.2ldr", l/1000, (l%1000)/10);
+	add("%lld.%.9lldt", (t1-*t0)/SEC, (t1-*t0)%SEC);
 	add("\t");
 	for(i=1; i<argc; i++){
 		add("%s", argv[i], 0);

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9front] time v2
@ 2018-08-11 20:47 Kurt H Maier
  2018-08-11 21:09 ` BurnZeZ
  0 siblings, 1 reply; 4+ messages in thread
From: Kurt H Maier @ 2018-08-11 20:47 UTC (permalink / raw)
  To: 9front

Revised patch follows, fixing the return check on segattach.

diff -r 5c5acc9ab7a5 sys/src/cmd/time.c
--- a/sys/src/cmd/time.c	Sat Aug 11 16:19:32 2018 +0200
+++ b/sys/src/cmd/time.c	Sat Aug 11 20:40:06 2018 +0000
@@ -14,16 +14,22 @@
 	long l;
 	char *p;
 	char err[ERRMAX];
+	vlong *t0, t1;
+	enum { SEC = 1000000000ULL };
 
 	if(argc <= 1){
 		fprint(2, "usage: time command\n");
 		exits("usage");
 	}
 
+	if((t0 = segattach(SG_CEXEC, "shared", nil, sizeof(*t0))) == -1)
+		sysfatal("segattach: %r");
+	*t0 = 0;
 	switch(fork()){
 	case -1:
 		error("fork");
 	case 0:
+		*t0 = nsec();
 		exec(argv[1], &argv[1]);
 		if(argv[1][0] != '/' && strncmp(argv[1], "./", 2) &&
 		   strncmp(argv[1], "../", 3)){
@@ -43,12 +49,14 @@
 			goto loop;
 		error("wait");
 	}
+	t1 = nsec();
 	l = w->time[0];
 	add("%ld.%.2ldu", l/1000, (l%1000)/10);
 	l = w->time[1];
 	add("%ld.%.2lds", l/1000, (l%1000)/10);
 	l = w->time[2];
 	add("%ld.%.2ldr", l/1000, (l%1000)/10);
+	add("%lld.%.9lldt", (t1-*t0)/SEC, (t1-*t0)%SEC);
 	add("\t");
 	for(i=1; i<argc; i++){
 		add("%s", argv[i], 0);



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-08-12 18:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-12  5:39 [9front] time v2 Alex Musolino
2018-08-12 18:21 ` [9front] time v4 BurnZeZ
  -- strict thread matches above, loose matches on Subject: below --
2018-08-11 20:47 [9front] time v2 Kurt H Maier
2018-08-11 21:09 ` BurnZeZ

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).